From 508daca341b59dcd3937fd35100ea6732c496aa0 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:13:29 -0400 Subject: [PATCH 1/6] Use local ember-cli --- tests/default.test.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/default.test.mjs b/tests/default.test.mjs index 6f72a23..0408ed8 100644 --- a/tests/default.test.mjs +++ b/tests/default.test.mjs @@ -12,6 +12,8 @@ const appName = 'fancy-app-in-test'; describe('basic functionality', function () { let tmpDir; + let emberCli = join(__dirname, '../node_modules/ember-cli/bin/ember'); + beforeAll(async () => { tmpDir = await tmp.dir({ unsafeCleanup: true }); @@ -24,7 +26,7 @@ describe('basic functionality', function () { '--skip-git', ]; - await execa('ember', emberCliArgs, { + await execa(emberCli, emberCliArgs, { cwd: tmpDir.path, preferLocal: true, }); From f63554e29dfdb1954cec46fb8059dcc05c0493bf Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:12:41 -0400 Subject: [PATCH 2/6] Full tryhard --- package.json | 1 + pnpm-lock.yaml | 17 ++++++++++++ tests/helpers.mjs | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 tests/helpers.mjs diff --git a/package.json b/package.json index f629a39..74fcceb 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "ember-cli": "^5.11.0", "lodash": "^4.17.21", + "package-up": "^5.0.0", "walk-sync": "^3.0.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 540e3a4..9ff8057 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: lodash: specifier: ^4.17.21 version: 4.17.21 + package-up: + specifier: ^5.0.0 + version: 5.0.0 walk-sync: specifier: ^3.0.0 version: 3.0.0 @@ -1937,6 +1940,10 @@ packages: find-index@1.1.1: resolution: {integrity: sha512-XYKutXMrIK99YMUPf91KX5QVJoG31/OsgftD6YoTPAObfQIxM4ziA9f0J1AsqKhJmo+IeaIPP0CFopTD4bdUBw==} + find-up-simple@1.0.0: + resolution: {integrity: sha512-q7Us7kcjj2VMePAa02hDAF6d+MzsdsAWEwYyOpwUtlerRBkOEPBCRZrAV4XfcSN8fHAgaD0hP7miwoay6DCprw==} + engines: {node: '>=18'} + find-up@4.1.0: resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} engines: {node: '>=8'} @@ -3178,6 +3185,10 @@ packages: resolution: {integrity: sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==} engines: {node: '>=8'} + package-up@5.0.0: + resolution: {integrity: sha512-MQEgDUvXCa3sGvqHg3pzHO8e9gqTCMPVrWUko3vPQGntwegmFo52mZb2abIVTjFnUcW0BcPz0D93jV5Cas1DWA==} + engines: {node: '>=18'} + parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -6498,6 +6509,8 @@ snapshots: find-index@1.1.1: {} + find-up-simple@1.0.0: {} + find-up@4.1.0: dependencies: locate-path: 5.0.0 @@ -7846,6 +7859,10 @@ snapshots: registry-url: 5.1.0 semver: 6.3.1 + package-up@5.0.0: + dependencies: + find-up-simple: 1.0.0 + parent-module@1.0.1: dependencies: callsites: 3.1.0 diff --git a/tests/helpers.mjs b/tests/helpers.mjs new file mode 100644 index 0000000..6639840 --- /dev/null +++ b/tests/helpers.mjs @@ -0,0 +1,70 @@ +import { createRequire } from 'node:module'; +import { readFileSync } from 'node:fs'; +import { join, dirname } from 'node:path'; +import assert from 'node:assert'; + +import { packageUpSync } from 'package-up'; + +const require = createRequire(import.meta.url); + +/** + * require.resolve finds the *entrypoint* + * we then need to find the package directory, + * read the package.json + * see what the bin entries are, + * grab the path for the bin (by name), + * and then return that path (absolute path to that bin) + */ +export function resolveBin(packageName, binName = packageName) { + // NOTE: will fail if there is no '.' export. + // (or main) + let entrypoint = require.resolve(packageName); + + let manifestPath = packageUpSync({ cwd: entrypoint }); + let buffer = readFileSync(manifestPath); + let manifest = JSON.parse(buffer.toString()); + let packageDir = dirname(manifestPath); + + assert( + manifest.name === packageName, + `Found package manifest at ${manifestPath}, but it was not for ${packageName}. Cannot continue.`, + ); + + assert( + manifest.bin, + `The specified (and found) package, ${packageName}, does not specify a 'bin' entry in its package.json`, + ); + + let binPath; + + if (typeof manifest.bin === 'string') { + assert( + packageName === binName, + `The 'bin' entry for ${packageName} can only be the same as the packageName. The requested bin ${binName} is not availabel.`, + ); + + binPath = manifest.bin; + } + + if (!binPath) { + assert( + typeof manifest.bin === 'object' && + !Array.isArray(manifest.bin) && + manifest.bin !== null, + `The 'bin' entry for ${packageName} must be an object.`, + ); + + binPath = manifest.bin?.[binName]; + } + + assert( + binPath, + `Could not determine 'bin', ${binName}, for package: ${packageName}.`, + ); + + return join(packageDir, binPath); +} + +export function emberCLI() { + return resolveBin('ember-cli', 'ember'); +} From 17d4c2a573de0080252bf72c558ca2ea86f7ce10 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:39:13 -0400 Subject: [PATCH 3/6] Actually use the tryhard code. oops --- tests/default.test.mjs | 3 +-- tests/helpers.mjs | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/default.test.mjs b/tests/default.test.mjs index 0408ed8..d79d758 100644 --- a/tests/default.test.mjs +++ b/tests/default.test.mjs @@ -5,6 +5,7 @@ import { execa } from 'execa'; import copyWithTemplate from '../lib/copy-with-template'; import { existsSync, writeFileSync } from 'fs'; import stripAnsi from 'strip-ansi'; +import { emberCli } from './helpers.mjs'; const blueprintPath = join(__dirname, '..'); const appName = 'fancy-app-in-test'; @@ -12,8 +13,6 @@ const appName = 'fancy-app-in-test'; describe('basic functionality', function () { let tmpDir; - let emberCli = join(__dirname, '../node_modules/ember-cli/bin/ember'); - beforeAll(async () => { tmpDir = await tmp.dir({ unsafeCleanup: true }); diff --git a/tests/helpers.mjs b/tests/helpers.mjs index 6639840..3107c8f 100644 --- a/tests/helpers.mjs +++ b/tests/helpers.mjs @@ -65,6 +65,8 @@ export function resolveBin(packageName, binName = packageName) { return join(packageDir, binPath); } -export function emberCLI() { +function findEmber() { return resolveBin('ember-cli', 'ember'); } + +export const emberCli = findEmber(); From bf035f0e460aa05d1fef7730ce6b9735b324207e Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:44:43 -0400 Subject: [PATCH 4/6] Found a library --- package.json | 1 + pnpm-lock.yaml | 15 +++++++++++ tests/helpers.mjs | 69 ++--------------------------------------------- 3 files changed, 18 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index 74fcceb..06946ec 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "ember-cli": "^5.11.0", "lodash": "^4.17.21", "package-up": "^5.0.0", + "resolve-bin": "^1.0.1", "walk-sync": "^3.0.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ff8057..8a81cd9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: package-up: specifier: ^5.0.0 version: 5.0.0 + resolve-bin: + specifier: ^1.0.1 + version: 1.0.1 walk-sync: specifier: ^3.0.0 version: 3.0.0 @@ -1940,6 +1943,9 @@ packages: find-index@1.1.1: resolution: {integrity: sha512-XYKutXMrIK99YMUPf91KX5QVJoG31/OsgftD6YoTPAObfQIxM4ziA9f0J1AsqKhJmo+IeaIPP0CFopTD4bdUBw==} + find-parent-dir@0.3.1: + resolution: {integrity: sha512-o4UcykWV/XN9wm+jMEtWLPlV8RXCZnMhQI6F6OdHeSez7iiJWePw8ijOlskJZMsaQoGR/b7dH6lO02HhaTN7+A==} + find-up-simple@1.0.0: resolution: {integrity: sha512-q7Us7kcjj2VMePAa02hDAF6d+MzsdsAWEwYyOpwUtlerRBkOEPBCRZrAV4XfcSN8fHAgaD0hP7miwoay6DCprw==} engines: {node: '>=18'} @@ -3471,6 +3477,9 @@ packages: requires-port@1.0.0: resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} + resolve-bin@1.0.1: + resolution: {integrity: sha512-4G9C3udcDB1c9qaopB+9dygm2bMyF2LeJ2JHBIc24N7ob+UuSSwX3ID1hQwpDEQep9ZRNdhT//rgEd6xbWA/SA==} + resolve-dir@1.0.1: resolution: {integrity: sha512-R7uiTjECzvOsWSfdM0QKFNBVFcK27aHOUwdvK53BcW8zqnGdYp0Fbj82cy54+2A4P2tFM22J5kRfe1R+lM/1yg==} engines: {node: '>=0.10.0'} @@ -6509,6 +6518,8 @@ snapshots: find-index@1.1.1: {} + find-parent-dir@0.3.1: {} + find-up-simple@1.0.0: {} find-up@4.1.0: @@ -8133,6 +8144,10 @@ snapshots: requires-port@1.0.0: {} + resolve-bin@1.0.1: + dependencies: + find-parent-dir: 0.3.1 + resolve-dir@1.0.1: dependencies: expand-tilde: 2.0.2 diff --git a/tests/helpers.mjs b/tests/helpers.mjs index 3107c8f..412b4c9 100644 --- a/tests/helpers.mjs +++ b/tests/helpers.mjs @@ -1,72 +1,7 @@ -import { createRequire } from 'node:module'; -import { readFileSync } from 'node:fs'; -import { join, dirname } from 'node:path'; -import assert from 'node:assert'; - -import { packageUpSync } from 'package-up'; - -const require = createRequire(import.meta.url); - -/** - * require.resolve finds the *entrypoint* - * we then need to find the package directory, - * read the package.json - * see what the bin entries are, - * grab the path for the bin (by name), - * and then return that path (absolute path to that bin) - */ -export function resolveBin(packageName, binName = packageName) { - // NOTE: will fail if there is no '.' export. - // (or main) - let entrypoint = require.resolve(packageName); - - let manifestPath = packageUpSync({ cwd: entrypoint }); - let buffer = readFileSync(manifestPath); - let manifest = JSON.parse(buffer.toString()); - let packageDir = dirname(manifestPath); - - assert( - manifest.name === packageName, - `Found package manifest at ${manifestPath}, but it was not for ${packageName}. Cannot continue.`, - ); - - assert( - manifest.bin, - `The specified (and found) package, ${packageName}, does not specify a 'bin' entry in its package.json`, - ); - - let binPath; - - if (typeof manifest.bin === 'string') { - assert( - packageName === binName, - `The 'bin' entry for ${packageName} can only be the same as the packageName. The requested bin ${binName} is not availabel.`, - ); - - binPath = manifest.bin; - } - - if (!binPath) { - assert( - typeof manifest.bin === 'object' && - !Array.isArray(manifest.bin) && - manifest.bin !== null, - `The 'bin' entry for ${packageName} must be an object.`, - ); - - binPath = manifest.bin?.[binName]; - } - - assert( - binPath, - `Could not determine 'bin', ${binName}, for package: ${packageName}.`, - ); - - return join(packageDir, binPath); -} +import { sync as resolveBinSync } from 'resolve-bin'; function findEmber() { - return resolveBin('ember-cli', 'ember'); + return resolveBinSync('ember-cli', { executable: 'ember' }); } export const emberCli = findEmber(); From 9debda4321d7e5d050026207f57466d8583e16cb Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:45:02 -0400 Subject: [PATCH 5/6] package-up is no longer needed --- package.json | 1 - pnpm-lock.yaml | 17 ----------------- 2 files changed, 18 deletions(-) diff --git a/package.json b/package.json index 06946ec..b09903f 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "dependencies": { "ember-cli": "^5.11.0", "lodash": "^4.17.21", - "package-up": "^5.0.0", "resolve-bin": "^1.0.1", "walk-sync": "^3.0.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8a81cd9..3ea40ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,9 +14,6 @@ importers: lodash: specifier: ^4.17.21 version: 4.17.21 - package-up: - specifier: ^5.0.0 - version: 5.0.0 resolve-bin: specifier: ^1.0.1 version: 1.0.1 @@ -1946,10 +1943,6 @@ packages: find-parent-dir@0.3.1: resolution: {integrity: sha512-o4UcykWV/XN9wm+jMEtWLPlV8RXCZnMhQI6F6OdHeSez7iiJWePw8ijOlskJZMsaQoGR/b7dH6lO02HhaTN7+A==} - find-up-simple@1.0.0: - resolution: {integrity: sha512-q7Us7kcjj2VMePAa02hDAF6d+MzsdsAWEwYyOpwUtlerRBkOEPBCRZrAV4XfcSN8fHAgaD0hP7miwoay6DCprw==} - engines: {node: '>=18'} - find-up@4.1.0: resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} engines: {node: '>=8'} @@ -3191,10 +3184,6 @@ packages: resolution: {integrity: sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==} engines: {node: '>=8'} - package-up@5.0.0: - resolution: {integrity: sha512-MQEgDUvXCa3sGvqHg3pzHO8e9gqTCMPVrWUko3vPQGntwegmFo52mZb2abIVTjFnUcW0BcPz0D93jV5Cas1DWA==} - engines: {node: '>=18'} - parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -6520,8 +6509,6 @@ snapshots: find-parent-dir@0.3.1: {} - find-up-simple@1.0.0: {} - find-up@4.1.0: dependencies: locate-path: 5.0.0 @@ -7870,10 +7857,6 @@ snapshots: registry-url: 5.1.0 semver: 6.3.1 - package-up@5.0.0: - dependencies: - find-up-simple: 1.0.0 - parent-module@1.0.1: dependencies: callsites: 3.1.0 From 6fee3653b078b70996390f1fb785005b54f28cda Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:06:54 -0400 Subject: [PATCH 6/6] Move to devDeps --- package.json | 2 +- pnpm-lock.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b09903f..3abe921 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "dependencies": { "ember-cli": "^5.11.0", "lodash": "^4.17.21", - "resolve-bin": "^1.0.1", "walk-sync": "^3.0.0" }, "devDependencies": { @@ -32,6 +31,7 @@ "prettier": "^3.2.5", "prettier-plugin-ember-template-tag": "^2.0.2", "release-plan": "^0.9.0", + "resolve-bin": "^1.0.1", "strip-ansi": "^7.1.0", "tmp-promise": "^3.0.3", "vitest": "^1.6.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3ea40ec..c60f6c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,9 +14,6 @@ importers: lodash: specifier: ^4.17.21 version: 4.17.21 - resolve-bin: - specifier: ^1.0.1 - version: 1.0.1 walk-sync: specifier: ^3.0.0 version: 3.0.0 @@ -48,6 +45,9 @@ importers: release-plan: specifier: ^0.9.0 version: 0.9.0(encoding@0.1.13) + resolve-bin: + specifier: ^1.0.1 + version: 1.0.1 strip-ansi: specifier: ^7.1.0 version: 7.1.0