diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d399fae5..9f08aaea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,19 +44,12 @@ jobs: # waiting on a an api from vitest for querying # the list of tests ahead of time before running them. # + # https://github.com/vitest-dev/vitest/issues/2901 + # # It would be great if vitest had a flag to give us the JSON of all the tests, # so we could be sure we don't miss anything # and then generate this list from a previous C.I. job slow-test: - - defaults with npm - - defaults with yarn - - defaults with pnpm - - # TypeScript - - typescript with npm - - typescript with yarn - - typescript with pnpm - # flags - addon-location - test-app-location @@ -75,3 +68,49 @@ jobs: - run: pnpm add --global ember-cli yarn - run: pnpm vitest --testNamePattern "${{ matrix.slow-test }}" working-directory: tests + + + defaults_tests: + name: "ember-cli@${{ matrix.ember-cli }} : ${{ matrix.slow-test }}" + timeout-minutes: 5 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ember-cli: + - 5.4.1 + - 5.3.0 + + slow-test: + - defaults with npm + - defaults with yarn + - defaults with pnpm + steps: + - uses: actions/checkout@v3 + - uses: wyvox/action-setup-pnpm@v2 + - run: pnpm add --global ember-cli@${{ matrix.ember-cli }} yarn + - run: pnpm vitest --testNamePattern "${{ matrix.slow-test }}" + working-directory: tests + + typescript_tests: + name: "ember-cli@${{ matrix.ember-cli }} : ${{ matrix.slow-test }}" + timeout-minutes: 5 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ember-cli: + - 5.4.1 + # Not testing against 5.3.0, because it has non-passing typechecking + # - 5.3.0 + + slow-test: + - typescript with npm + - typescript with yarn + - typescript with pnpm + steps: + - uses: actions/checkout@v3 + - uses: wyvox/action-setup-pnpm@v2 + - run: pnpm add --global ember-cli@${{ matrix.ember-cli }} yarn + - run: pnpm vitest --testNamePattern "${{ matrix.slow-test }}" + working-directory: tests diff --git a/index.js b/index.js index 470564c3..13b96fa8 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ module.exports = { if (!options.addonOnly) { if (fs.existsSync(path.join('..', 'package.json'))) { options.ui.writeInfoLine( - "Existing monorepo detected! The blueprint will only create the addon and test-app folders, and omit any other files in the repo's root folder." + "Existing monorepo detected! The blueprint will only create the addon and test-app folders, and omit any other files in the repo's root folder.", ); this.isExistingMonorepo = true; @@ -80,10 +80,10 @@ module.exports = { } await fs.writeFile(packageJson, JSON.stringify(json, null, 2)); - })() + })(), ); - if (options.pnpm) { + if (isPnpm(options)) { tasks.push(pnpm.createWorkspacesFile(options.target, addonInfo, testAppInfo)); } @@ -98,7 +98,7 @@ module.exports = { await this.moveFilesForExistingMonorepo(options); this.ui.writeWarnLine( - `Make sure your workspaces are configured correctly to cover the newly created ${addonInfo.location} and ${testAppInfo.location} packages!` + `Make sure your workspaces are configured correctly to cover the newly created ${addonInfo.location} and ${testAppInfo.location} packages!`, ); } @@ -119,7 +119,7 @@ module.exports = { assert( !options.addonOnly, `When in --addon-only mode, we don't need to move files within an existing monorepo. ` + - `If you see this error, please open an issue at: https://github.com/embroider-build/addon-blueprint/issues` + `If you see this error, please open an issue at: https://github.com/embroider-build/addon-blueprint/issues`, ); let addonInfo = addonInfoFromOptions(options); @@ -152,7 +152,7 @@ module.exports = { assert( !options.addonOnly, `When in --addon-only mode, we don't create a test-app. ` + - `If you see this error, please open an issue at: https://github.com/embroider-build/addon-blueprint/issues` + `If you see this error, please open an issue at: https://github.com/embroider-build/addon-blueprint/issues`, ); const appBlueprint = this.lookupBlueprint('app'); @@ -179,7 +179,7 @@ module.exports = { await appBlueprint.install(appOptions); await Promise.all([ - this.updateTestAppPackageJson(path.join(testAppPath, 'package.json'), options.pnpm), + this.updateTestAppPackageJson(path.join(testAppPath, 'package.json'), isPnpm(options)), this.overrideTestAppFiles(testAppPath, path.join(options.target, 'test-app-overrides')), fs.unlink(path.join(testAppPath, '.travis.yml')), ]); @@ -191,11 +191,11 @@ module.exports = { if (lt(hasVersion, needsVersion)) { this.ui.writeWarnLine( - `Your version ${hasVersion} of Ember CLI does not support the --typescript flag yet. Please run \`ember install ember-cli-typescript\` in the ${testAppInfo.location} folder manually!` + `Your version ${hasVersion} of Ember CLI does not support the --typescript flag yet. Please run \`ember install ember-cli-typescript\` in the ${testAppInfo.location} folder manually!`, ); } else if (lt(hasVersion, recommendedVersion)) { this.ui.writeWarnLine( - `We recommend using Ember CLI >= ${recommendedVersion} for the best blueprint support when using TypeScript!` + `We recommend using Ember CLI >= ${recommendedVersion} for the best blueprint support when using TypeScript!`, ); } } @@ -272,21 +272,22 @@ module.exports = { addonNamespace: addonInfo.name.classified, blueprintVersion: require('./package.json').version, year: date.getFullYear(), - yarn: options.yarn, - pnpm: options.pnpm, - npm: options.npm, + packageManager: options.packageManager, + yarn: isYarn(options), + pnpm: isPnpm(options), + npm: isNpm(options), typescript: options.typescript, ext: options.typescript ? 'ts' : 'js', blueprint: 'addon', blueprintOptions: buildBlueprintOptions({ [`--addon-location=${options.addonLocation}`]: options.addonLocation, [`--ci-provider=${options.ciProvider}`]: options.ciProvider, - '--pnpm': options.pnpm, + '--pnpm': isPnpm(options), '--release-it': options.releaseIt, [`--test-app-location=${options.testAppLocation}`]: options.testAppLocation, [`--test-app-name=${options.testAppName}`]: options.testAppName, '--typescript': options.typescript, - '--yarn': options.yarn, + '--yarn': isYarn(options), }), ciProvider: options.ciProvider, pathFromAddonToRoot, @@ -310,7 +311,7 @@ module.exports = { let ignoredFiles = ['__addonLocation__/tsconfig.json']; files = files.filter( - (filename) => !filename.match(/.*\.ts$/) && !ignoredFiles.includes(filename) + (filename) => !filename.match(/.*\.ts$/) && !ignoredFiles.includes(filename), ); } @@ -323,10 +324,10 @@ module.exports = { files = files.filter((filename) => !filename.endsWith('.npmrc')); } - if (!this.yarn) { + if (!isYarn(options)) { let ignoredFiles = ['.yarnrc.yml']; - files = files.filter(filename => !ignoredFiles.includes(filename)); + files = files.filter((filename) => !ignoredFiles.includes(filename)); } return files; @@ -337,7 +338,7 @@ module.exports = { if (this.project.isEmberCLIProject() && !this.project.isEmberCLIAddon()) { throw new SilentError( - 'Generating an addon in an existing ember-cli project is not supported.' + 'Generating an addon in an existing ember-cli project is not supported.', ); } @@ -360,3 +361,20 @@ function buildBlueprintOptions(blueprintOptions) { return ''; } + +// These methods exist because in ember-cli 5.4, package manager handling +// had changed to solely use the packageManager key, however +// prior to ember-cli 5.4, pnpm, yarn, and npm, had their own booleans on +// the options object. +function isPnpm(options) { + return options.packageManager === 'pnpm' || options.pnpm; +} + +function isYarn(options) { + return options.packageManager === 'yarn' || options.yarn; +} + +function isNpm(options) { + return options.packageManager === 'npm' || options.npm; +} + diff --git a/tests/helpers/utils.ts b/tests/helpers/utils.ts index 3216c12a..81fcefb6 100644 --- a/tests/helpers/utils.ts +++ b/tests/helpers/utils.ts @@ -3,7 +3,7 @@ import os from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import { execa,type Options } from 'execa'; +import { execa, type Options } from 'execa'; const DEBUG = process.env.DEBUG === 'true'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -36,7 +36,7 @@ const ROLLUP_HASH = /[a-f0-9]{8}/ * a fairly narrow matcher to remove them. */ export function withoutHashes(names: string[]) { - return names.filter(name => !ROLLUP_HASH.test(name)); + return names.filter(name => !ROLLUP_HASH.test(name)); } /** @@ -52,7 +52,7 @@ export function withoutHashes(names: string[]) { * This a */ export function hashesOnly(names: string[]) { - return names.filter(name => ROLLUP_HASH.test(name)); + return names.filter(name => ROLLUP_HASH.test(name)); } export function splitHashedFiles(names: string[]) { @@ -77,33 +77,13 @@ export async function install({ if (packageManager === 'yarn') { await execa('yarn', ['install', '--non-interactive'], { cwd }); } else { - try { - let installOptions = []; - - if (packageManager === 'pnpm') { - installOptions.push('--no-frozen-lockfile'); - } - - await execa(packageManager, ['install', '--ignore-scripts', ...installOptions], { cwd }); - } catch (e) { - if (e instanceof Error) { - // ignore the `@babel/core` peer issue. - // this is dependent on ember-cli-babel doing a v8 release - // where it declares `@babel/core` as a peer, and removes it from - // dependencies - let isPeerError = e.message.includes('Peer dependencies that should be installed:'); - let isExpectedPeer = e.message.includes('@babel/core@">=7.0.0 <8.0.0"'); - - if (packageManager === 'pnpm' && isPeerError && isExpectedPeer) { - console.info('An error occurred. Are there still upstream issues to resolve?'); - console.error(e); - - return; - } - } - - throw e; + let installOptions = []; + + if (packageManager === 'pnpm') { + installOptions.push('--no-frozen-lockfile'); } + + await execa(packageManager, ['install', '--ignore-scripts', ...installOptions], { cwd }); } const pkg = await packageJsonAt(cwd); @@ -178,7 +158,6 @@ export async function createAddon({ let result = await execa('ember', emberCliArgs, { ...options, - env: { ...options.env, EMBER_CLI_PNPM: 'true' }, preferLocal: true, }); diff --git a/tests/smoke-tests/--addon-location.test.ts b/tests/smoke-tests/--addon-location.test.ts index 149a43fe..4fc299e7 100644 --- a/tests/smoke-tests/--addon-location.test.ts +++ b/tests/smoke-tests/--addon-location.test.ts @@ -20,7 +20,7 @@ describe('--addon-location', () => { tmpDir = await createTmp(); let { name } = await createAddon({ - args: [`--addon-location=${addonLocation}`, '--pnpm=true'], + args: [`--addon-location=${addonLocation}`, '--pnpm'], options: { cwd: tmpDir }, }); diff --git a/tests/smoke-tests/--test-app-location.test.ts b/tests/smoke-tests/--test-app-location.test.ts index 6551a3c0..a0897df9 100644 --- a/tests/smoke-tests/--test-app-location.test.ts +++ b/tests/smoke-tests/--test-app-location.test.ts @@ -20,7 +20,7 @@ describe('--test-app-location', () => { tmpDir = await createTmp(); let { name } = await createAddon({ - args: [`--test-app-location=${testAppLocation}`, '--pnpm=true'], + args: [`--test-app-location=${testAppLocation}`, '--pnpm'], options: { cwd: tmpDir }, }); diff --git a/tests/smoke-tests/within-existing-monorepo/defaults.test.ts b/tests/smoke-tests/within-existing-monorepo/defaults.test.ts index 85e447bc..763dd076 100644 --- a/tests/smoke-tests/within-existing-monorepo/defaults.test.ts +++ b/tests/smoke-tests/within-existing-monorepo/defaults.test.ts @@ -73,7 +73,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { } await createAddon({ - args: [`--${packageManager}=true`], + args: [`--${packageManager}`], options: { cwd: tmpDir }, });