From 9bf5374643181176140d6948d67241c1c68e916f Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 17 Feb 2025 14:29:35 +0100 Subject: [PATCH 1/6] fix(yarn): only pass -W to yarn classic --- src/packageManager.ts | 18 ++++++++++++------ tests/baseFixtures.ts | 9 ++++++++- tests/integration.spec.ts | 5 +++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/packageManager.ts b/src/packageManager.ts index 03521e6..cee5928 100644 --- a/src/packageManager.ts +++ b/src/packageManager.ts @@ -50,9 +50,12 @@ class Yarn implements PackageManager { name = 'Yarn' cli = 'yarn' private workspace: boolean + private classic = false; - constructor(rootDir: string) { + constructor(rootDir: string, version?: string) { this.workspace = this.isWorkspace(rootDir); + if (version) + this.classic = version.startsWith('0') || version.startsWith('1'); } private isWorkspace(rootDir: string) { @@ -81,7 +84,7 @@ class Yarn implements PackageManager { } installDevDependency(name: string): string { - return `yarn add --dev ${this.workspace ? '-W ' : ''}${name}` + return `yarn add --dev ${(this.workspace && this.classic) ? '-W ' : ''}${name}` } runPlaywrightTest(args: string): string { @@ -132,10 +135,13 @@ class PNPM implements PackageManager { } export function determinePackageManager(rootDir: string): PackageManager { - if (process.env.npm_config_user_agent) { - if (process.env.npm_config_user_agent.includes('yarn')) - return new Yarn(rootDir); - if (process.env.npm_config_user_agent.includes('pnpm')) + const user_agent = process.env.npm_config_user_agent; + if (user_agent) { + if (user_agent.includes('yarn')) { + const yarnVersion = user_agent.match(/yarn\/(\d+\.\d+\.\d+)/)?.[1]; + return new Yarn(rootDir, yarnVersion); + } + if (user_agent.includes('pnpm')) return new PNPM(rootDir); } return new NPM(); diff --git a/tests/baseFixtures.ts b/tests/baseFixtures.ts index c43ad29..9b5515e 100644 --- a/tests/baseFixtures.ts +++ b/tests/baseFixtures.ts @@ -22,6 +22,13 @@ import type { PromptOptions } from '../src/generator'; export type PackageManager = 'npm' | 'pnpm' | 'yarn-classic' | 'yarn-berry'; +const userAgents: Record = { + 'yarn-classic': 'yarn/1.22.10', + 'yarn-berry': 'yarn/4.0.0', + pnpm: 'pnpm/0.0.0', + npm: undefined, +}; + export type TestFixtures = { packageManager: PackageManager; dir: string; @@ -82,7 +89,7 @@ export const test = base.extend({ cwd: dir, env: { ...process.env, - 'npm_config_user_agent': packageManager.startsWith('yarn') ? 'yarn' : packageManager === 'pnpm' ? 'pnpm/0.0.0' : undefined, + npm_config_user_agent: userAgents[packageManager], 'TEST_OPTIONS': JSON.stringify(options), }, }); diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index d1c251e..95d76b0 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -115,7 +115,7 @@ test('should generate in the root of pnpm workspace', async ({ run, packageManag }); test('should generate in the root of yarn workspaces', async ({ run, packageManager }) => { - test.skip(packageManager !== 'yarn-classic'); + test.skip(packageManager !== 'yarn-berry' && packageManager !== 'yarn-classic'); const dir = test.info().outputDir; fs.mkdirSync(dir, { recursive: true }); @@ -135,7 +135,8 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); assertLockFilesExist(dir, packageManager); expect(fs.existsSync(path.join(dir, 'tests/example.spec.ts'))).toBeTruthy(); - expect(fs.existsSync(path.join(dir, 'node_modules/playwright'))).toBeTruthy(); + const writesNodeModules = packageManager === 'yarn-classic'; + expect(fs.existsSync(path.join(dir, 'node_modules/playwright'))).toBe(writesNodeModules); expect(fs.existsSync(path.join(dir, 'playwright.config.ts'))).toBeTruthy(); }); From 9cd1cd9a4d67cf4f8c190782796c4f4ecdfea305 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 17 Feb 2025 14:36:29 +0100 Subject: [PATCH 2/6] add userAgent --- src/packageManager.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/packageManager.ts b/src/packageManager.ts index cee5928..01214d3 100644 --- a/src/packageManager.ts +++ b/src/packageManager.ts @@ -135,13 +135,13 @@ class PNPM implements PackageManager { } export function determinePackageManager(rootDir: string): PackageManager { - const user_agent = process.env.npm_config_user_agent; - if (user_agent) { - if (user_agent.includes('yarn')) { - const yarnVersion = user_agent.match(/yarn\/(\d+\.\d+\.\d+)/)?.[1]; + const userAgent = process.env.npm_config_user_agent; + if (userAgent) { + if (userAgent.includes('yarn')) { + const yarnVersion = userAgent.match(/yarn\/(\d+\.\d+\.\d+)/)?.[1]; return new Yarn(rootDir, yarnVersion); } - if (user_agent.includes('pnpm')) + if (userAgent.includes('pnpm')) return new PNPM(rootDir); } return new NPM(); From 0f755c91e45b914a867b9572b2935138c6733cc1 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 20 Feb 2025 16:53:12 +0100 Subject: [PATCH 3/6] loggy mc logface --- tests/integration.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 95d76b0..421c532 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -130,7 +130,7 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana fs.mkdirSync(packageDir, { recursive: true }); childProcess.execSync(`yarn init -y`, { cwd: packageDir }); } - childProcess.execSync(`yarn install`, { cwd: dir }); + childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit' }); await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); assertLockFilesExist(dir, packageManager); From d20cddb4a15d9eaa1e218a0f74f6f9b7568e9b1b Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 20 Feb 2025 17:05:07 +0100 Subject: [PATCH 4/6] disable hardened mode --- tests/integration.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index 421c532..a2a3168 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -130,7 +130,7 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana fs.mkdirSync(packageDir, { recursive: true }); childProcess.execSync(`yarn init -y`, { cwd: packageDir }); } - childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit' }); + childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit', env: { YARN_ENABLE_HARDENED_MODE: '0' } }); await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); assertLockFilesExist(dir, packageManager); From fab2a19dbe985d9bb37b73ec8c7e30f7d867c9ce Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 20 Feb 2025 17:17:15 +0100 Subject: [PATCH 5/6] dont swallow path --- tests/integration.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index a2a3168..cd73ed0 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -130,7 +130,7 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana fs.mkdirSync(packageDir, { recursive: true }); childProcess.execSync(`yarn init -y`, { cwd: packageDir }); } - childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit', env: { YARN_ENABLE_HARDENED_MODE: '0' } }); + childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit', env: { ...process.env, YARN_ENABLE_HARDENED_MODE: '0' } }); await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); assertLockFilesExist(dir, packageManager); From 398b9e4eac7c000d8994ddfd2016a2773d15ae32 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 20 Feb 2025 17:39:46 +0100 Subject: [PATCH 6/6] Update yarn install environment variables in tests --- tests/integration.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.spec.ts b/tests/integration.spec.ts index cd73ed0..e563b6c 100644 --- a/tests/integration.spec.ts +++ b/tests/integration.spec.ts @@ -130,7 +130,7 @@ test('should generate in the root of yarn workspaces', async ({ run, packageMana fs.mkdirSync(packageDir, { recursive: true }); childProcess.execSync(`yarn init -y`, { cwd: packageDir }); } - childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit', env: { ...process.env, YARN_ENABLE_HARDENED_MODE: '0' } }); + childProcess.execSync(`yarn install`, { cwd: dir, stdio: 'inherit', env: { ...process.env, YARN_ENABLE_IMMUTABLE_INSTALLS: 'false', YARN_ENABLE_HARDENED_MODE: '0' } }); await run([], { installGitHubActions: false, testDir: 'tests', language: 'TypeScript', installPlaywrightDependencies: false, installPlaywrightBrowsers: false }); assertLockFilesExist(dir, packageManager);