From a23f9762db4e7900a4f7ac9942dbeef3f860bc88 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Thu, 3 Oct 2024 20:02:30 +0530 Subject: [PATCH 1/9] Update link.ts --- .../sources/commands/link.ts | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/packages/plugin-essentials/sources/commands/link.ts b/packages/plugin-essentials/sources/commands/link.ts index 04aa0d20e8a1..e064156d161c 100644 --- a/packages/plugin-essentials/sources/commands/link.ts +++ b/packages/plugin-essentials/sources/commands/link.ts @@ -1,6 +1,6 @@ import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli'; -import {Cache, Configuration, Project, structUtils} from '@yarnpkg/core'; -import {npath, ppath} from '@yarnpkg/fslib'; +import {Cache, Configuration, Project, structUtils, report} from '@yarnpkg/core'; +import {npath, ppath, constants} from '@yarnpkg/fslib'; import {Command, Option, Usage, UsageError} from 'clipanion'; // eslint-disable-next-line arca/no-default-export @@ -87,20 +87,53 @@ export default class LinkCommand extends BaseCommand { } } - for (const workspace of linkedWorkspaces) { + const processWorkspace = async (workspace) => { const fullName = structUtils.stringifyIdent(workspace.anchoredLocator); - const target = this.relative + let target = this.relative ? ppath.relative(project.cwd, workspace.cwd) : workspace.cwd; - topLevelWorkspace.manifest.resolutions.push({ + // Windows-specific path handling + if (process.platform === 'win32') { + const windowsPath = npath.fromPortablePath(target); + + // Check if we need to use extended-length path syntax + if (windowsPath.length >= constants.MAX_PATH) { + // For virtual packages, try to shorten the path first + if (structUtils.isVirtualLocator(workspace.anchoredLocator)) { + const hash = structUtils.slugifyLocator(workspace.anchoredLocator).slice(0, 8); + const shortName = `${workspace.manifest.name.name}-${hash}`; + target = ppath.resolve(project.cwd, `node_modules/${shortName}` as any); + } + + // If still too long, use extended-length path syntax + const finalWindowsPath = npath.fromPortablePath(target); + if (finalWindowsPath.length >= constants.MAX_PATH) { + target = npath.toPortablePath(`\\\\?\\${finalWindowsPath}`); + } + } + } + + return { pattern: {descriptor: {fullName}}, reference: `portal:${target}`, - }); - } + }; + }; + + const resolutions = await Promise.all(linkedWorkspaces.map(processWorkspace)); + topLevelWorkspace.manifest.resolutions.push(...resolutions); return await project.installWithNewReport({ stdout: this.context.stdout, + reportFooter: () => { + const rows = resolutions.map(({pattern, reference}) => [ + structUtils.prettyIdent(configuration, pattern.descriptor), + reference, + ]); + + return report.reportInfo(null, `The following packages have been linked:`) + '\n' + + report.reportIndex(null, rows); + }, }, { cache, }); From ecb7ca3fa3bcceda2367782a6cd22babb2db4811 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Thu, 3 Oct 2024 20:03:31 +0530 Subject: [PATCH 2/9] Update link.ts --- packages/plugin-essentials/sources/commands/link.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/plugin-essentials/sources/commands/link.ts b/packages/plugin-essentials/sources/commands/link.ts index e064156d161c..8de4b979800b 100644 --- a/packages/plugin-essentials/sources/commands/link.ts +++ b/packages/plugin-essentials/sources/commands/link.ts @@ -93,11 +93,9 @@ export default class LinkCommand extends BaseCommand { ? ppath.relative(project.cwd, workspace.cwd) : workspace.cwd; - // Windows-specific path handling if (process.platform === 'win32') { const windowsPath = npath.fromPortablePath(target); - // Check if we need to use extended-length path syntax if (windowsPath.length >= constants.MAX_PATH) { // For virtual packages, try to shorten the path first if (structUtils.isVirtualLocator(workspace.anchoredLocator)) { @@ -106,7 +104,6 @@ export default class LinkCommand extends BaseCommand { target = ppath.resolve(project.cwd, `node_modules/${shortName}` as any); } - // If still too long, use extended-length path syntax const finalWindowsPath = npath.fromPortablePath(target); if (finalWindowsPath.length >= constants.MAX_PATH) { target = npath.toPortablePath(`\\\\?\\${finalWindowsPath}`); From 760f6b879fb722e06ec2e9016598c6270319a243 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Thu, 3 Oct 2024 20:05:06 +0530 Subject: [PATCH 3/9] Create Link.test.ts --- packages/yarnpkg-core/tests/Link.test.ts | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 packages/yarnpkg-core/tests/Link.test.ts diff --git a/packages/yarnpkg-core/tests/Link.test.ts b/packages/yarnpkg-core/tests/Link.test.ts new file mode 100644 index 000000000000..fc6b5ff5709e --- /dev/null +++ b/packages/yarnpkg-core/tests/Link.test.ts @@ -0,0 +1,45 @@ +import {generatePath} from '../sources/Link'; +import {structUtils} from '../sources/structUtils'; +import {ppath, npath, PortablePath, Filename, xfs} from '@yarnpkg/fslib'; + +describe('Link', () => { + describe('generatePath', () => { + it('handles Windows long paths correctly', async () => { + const originalPlatform = process.platform; + Object.defineProperty(process, 'platform', { + value: 'win32' + }); + + try { + const mockProject = { + cwd: npath.toPortablePath('C:\\very\\long\\path\\that\\exceeds\\windows\\limits\\project') as PortablePath, + }; + + const mockLocator = structUtils.makeLocator( + structUtils.makeIdent('firebase', 'app-check'), + 'virtual:1234567890abcdef' + ); + + const baseFs = new xfs.JailFS(mockProject.cwd); + + const result = await generatePath(mockLocator, { + baseFs, + project: mockProject as any, + isDependency: true, + }); + + if (npath.fromPortablePath(result).length >= 260) { + expect(npath.fromPortablePath(result)).toMatch(/^\\\\\?\\./); + } + + await expect(baseFs.mkdirPromise(ppath.dirname(result), { recursive: true })) + .resolves.not.toThrow(); + + } finally { + Object.defineProperty(process, 'platform', { + value: originalPlatform + }); + } + }); + }); +}); From 567dfa4c060e8e504289c6532ff871c1630d6a58 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Thu, 3 Oct 2024 17:59:38 +0000 Subject: [PATCH 4/9] some small changes --- .../sources/commands/link.ts | 18 +++++----- packages/yarnpkg-core/tests/Link.test.ts | 34 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/plugin-essentials/sources/commands/link.ts b/packages/plugin-essentials/sources/commands/link.ts index 8de4b979800b..dd1b77bd22a7 100644 --- a/packages/plugin-essentials/sources/commands/link.ts +++ b/packages/plugin-essentials/sources/commands/link.ts @@ -1,7 +1,7 @@ -import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli'; +import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli'; import {Cache, Configuration, Project, structUtils, report} from '@yarnpkg/core'; -import {npath, ppath, constants} from '@yarnpkg/fslib'; -import {Command, Option, Usage, UsageError} from 'clipanion'; +import {npath, ppath, constants} from '@yarnpkg/fslib'; +import {Command, Option, Usage, UsageError} from 'clipanion'; // eslint-disable-next-line arca/no-default-export export default class LinkCommand extends BaseCommand { @@ -87,15 +87,15 @@ export default class LinkCommand extends BaseCommand { } } - const processWorkspace = async (workspace) => { + const processWorkspace = async workspace => { const fullName = structUtils.stringifyIdent(workspace.anchoredLocator); let target = this.relative ? ppath.relative(project.cwd, workspace.cwd) : workspace.cwd; - if (process.platform === 'win32') { + if (process.platform === `win32`) { const windowsPath = npath.fromPortablePath(target); - + if (windowsPath.length >= constants.MAX_PATH) { // For virtual packages, try to shorten the path first if (structUtils.isVirtualLocator(workspace.anchoredLocator)) { @@ -103,7 +103,7 @@ export default class LinkCommand extends BaseCommand { const shortName = `${workspace.manifest.name.name}-${hash}`; target = ppath.resolve(project.cwd, `node_modules/${shortName}` as any); } - + const finalWindowsPath = npath.fromPortablePath(target); if (finalWindowsPath.length >= constants.MAX_PATH) { target = npath.toPortablePath(`\\\\?\\${finalWindowsPath}`); @@ -128,8 +128,8 @@ export default class LinkCommand extends BaseCommand { reference, ]); - return report.reportInfo(null, `The following packages have been linked:`) + '\n' + - report.reportIndex(null, rows); + return `${report.reportInfo(null, `The following packages have been linked:`)}\n${ + report.reportIndex(null, rows)}`; }, }, { cache, diff --git a/packages/yarnpkg-core/tests/Link.test.ts b/packages/yarnpkg-core/tests/Link.test.ts index fc6b5ff5709e..cd280e628a64 100644 --- a/packages/yarnpkg-core/tests/Link.test.ts +++ b/packages/yarnpkg-core/tests/Link.test.ts @@ -1,23 +1,24 @@ -import {generatePath} from '../sources/Link'; -import {structUtils} from '../sources/structUtils'; -import {ppath, npath, PortablePath, Filename, xfs} from '@yarnpkg/fslib'; +import {ppath, npath, PortablePath, Filename, xfs} from '@yarnpkg/fslib'; -describe('Link', () => { - describe('generatePath', () => { - it('handles Windows long paths correctly', async () => { +import {generatePath} from '../sources/commands/link'; +import {structUtils} from '../sources/structUtils'; + +describe(`Link`, () => { + describe(`generatePath`, () => { + it(`handles Windows long paths correctly`, async () => { const originalPlatform = process.platform; - Object.defineProperty(process, 'platform', { - value: 'win32' + Object.defineProperty(process, `platform`, { + value: `win32`, }); try { const mockProject = { - cwd: npath.toPortablePath('C:\\very\\long\\path\\that\\exceeds\\windows\\limits\\project') as PortablePath, + cwd: npath.toPortablePath(`C:\\very\\long\\path\\that\\exceeds\\windows\\limits\\project`) as PortablePath, }; const mockLocator = structUtils.makeLocator( - structUtils.makeIdent('firebase', 'app-check'), - 'virtual:1234567890abcdef' + structUtils.makeIdent(`firebase`, `app-check`), + `virtual:1234567890abcdef`, ); const baseFs = new xfs.JailFS(mockProject.cwd); @@ -28,16 +29,15 @@ describe('Link', () => { isDependency: true, }); - if (npath.fromPortablePath(result).length >= 260) { + if (npath.fromPortablePath(result).length >= 260) expect(npath.fromPortablePath(result)).toMatch(/^\\\\\?\\./); - } - await expect(baseFs.mkdirPromise(ppath.dirname(result), { recursive: true })) - .resolves.not.toThrow(); + await expect(baseFs.mkdirPromise(ppath.dirname(result), {recursive: true})) + .resolves.not.toThrow(); } finally { - Object.defineProperty(process, 'platform', { - value: originalPlatform + Object.defineProperty(process, `platform`, { + value: originalPlatform, }); } }); From 44cd4027593142cb975f2d589f922b720b3e73d7 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Thu, 3 Oct 2024 18:03:16 +0000 Subject: [PATCH 5/9] some minor changes --- packages/yarnpkg-core/tests/Link.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yarnpkg-core/tests/Link.test.ts b/packages/yarnpkg-core/tests/Link.test.ts index cd280e628a64..090b44a2be61 100644 --- a/packages/yarnpkg-core/tests/Link.test.ts +++ b/packages/yarnpkg-core/tests/Link.test.ts @@ -1,7 +1,7 @@ import {ppath, npath, PortablePath, Filename, xfs} from '@yarnpkg/fslib'; import {generatePath} from '../sources/commands/link'; -import {structUtils} from '../sources/structUtils'; +import {structUtils} from '@yarnpkg/core'; describe(`Link`, () => { describe(`generatePath`, () => { From ba6d72da90e0f0d0097f3b650bc3184bfcd71286 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Fri, 4 Oct 2024 05:52:56 +0000 Subject: [PATCH 6/9] some minor changes --- .../plugin-essentials/sources/commands/link.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/plugin-essentials/sources/commands/link.ts b/packages/plugin-essentials/sources/commands/link.ts index dd1b77bd22a7..e2c2048105e4 100644 --- a/packages/plugin-essentials/sources/commands/link.ts +++ b/packages/plugin-essentials/sources/commands/link.ts @@ -1,7 +1,8 @@ -import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli'; -import {Cache, Configuration, Project, structUtils, report} from '@yarnpkg/core'; -import {npath, ppath, constants} from '@yarnpkg/fslib'; -import {Command, Option, Usage, UsageError} from 'clipanion'; +import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli'; +import {Cache, Configuration, Project, structUtils} from '@yarnpkg/core'; +import {npath, ppath, constants} from '@yarnpkg/fslib'; +import {Command, Option, Usage, UsageError} from 'clipanion'; +import {Report} from '../../../yarnpkg-core/sources'; // eslint-disable-next-line arca/no-default-export export default class LinkCommand extends BaseCommand { @@ -128,11 +129,11 @@ export default class LinkCommand extends BaseCommand { reference, ]); - return `${report.reportInfo(null, `The following packages have been linked:`)}\n${ - report.reportIndex(null, rows)}`; + return `${Report.reportInfo(null, `The following packages have been linked:`)}\n${ + Report.reportIndex(null, rows)}`; }, }, { cache, }); } -} +} \ No newline at end of file From b25497b0722ba0f2fca2a4a0372402c94255a61d Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Fri, 4 Oct 2024 06:37:02 +0000 Subject: [PATCH 7/9] linting error fix --- .yarn/versions/67af515f.yml | 32 +++++++++++++++++++ .../sources/commands/link.ts | 11 ++++--- packages/yarnpkg-core/tests/Link.test.ts | 2 +- 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 .yarn/versions/67af515f.yml diff --git a/.yarn/versions/67af515f.yml b/.yarn/versions/67af515f.yml new file mode 100644 index 000000000000..11300a475dea --- /dev/null +++ b/.yarn/versions/67af515f.yml @@ -0,0 +1,32 @@ +releases: + "@yarnpkg/builder": patch + "@yarnpkg/cli": patch + "@yarnpkg/core": patch + "@yarnpkg/doctor": patch + "@yarnpkg/extensions": patch + "@yarnpkg/nm": patch + "@yarnpkg/plugin-compat": patch + "@yarnpkg/plugin-constraints": patch + "@yarnpkg/plugin-dlx": patch + "@yarnpkg/plugin-essentials": patch + "@yarnpkg/plugin-exec": patch + "@yarnpkg/plugin-file": patch + "@yarnpkg/plugin-git": patch + "@yarnpkg/plugin-github": patch + "@yarnpkg/plugin-http": patch + "@yarnpkg/plugin-init": patch + "@yarnpkg/plugin-interactive-tools": patch + "@yarnpkg/plugin-link": patch + "@yarnpkg/plugin-nm": patch + "@yarnpkg/plugin-npm": patch + "@yarnpkg/plugin-npm-cli": patch + "@yarnpkg/plugin-pack": patch + "@yarnpkg/plugin-patch": patch + "@yarnpkg/plugin-pnp": patch + "@yarnpkg/plugin-pnpm": patch + "@yarnpkg/plugin-stage": patch + "@yarnpkg/plugin-typescript": patch + "@yarnpkg/plugin-version": patch + "@yarnpkg/plugin-workspace-tools": patch + "@yarnpkg/pnpify": patch + "@yarnpkg/sdks": patch diff --git a/packages/plugin-essentials/sources/commands/link.ts b/packages/plugin-essentials/sources/commands/link.ts index e2c2048105e4..a1057f05e93f 100644 --- a/packages/plugin-essentials/sources/commands/link.ts +++ b/packages/plugin-essentials/sources/commands/link.ts @@ -1,8 +1,9 @@ -import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli'; +import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli'; import {Cache, Configuration, Project, structUtils} from '@yarnpkg/core'; -import {npath, ppath, constants} from '@yarnpkg/fslib'; -import {Command, Option, Usage, UsageError} from 'clipanion'; -import {Report} from '../../../yarnpkg-core/sources'; +import {npath, ppath, constants} from '@yarnpkg/fslib'; +import {Command, Option, Usage, UsageError} from 'clipanion'; + +import {Report} from '../../../yarnpkg-core/sources'; // eslint-disable-next-line arca/no-default-export export default class LinkCommand extends BaseCommand { @@ -136,4 +137,4 @@ export default class LinkCommand extends BaseCommand { cache, }); } -} \ No newline at end of file +} diff --git a/packages/yarnpkg-core/tests/Link.test.ts b/packages/yarnpkg-core/tests/Link.test.ts index 090b44a2be61..49a951b8b3ff 100644 --- a/packages/yarnpkg-core/tests/Link.test.ts +++ b/packages/yarnpkg-core/tests/Link.test.ts @@ -1,7 +1,7 @@ +import {structUtils} from '@yarnpkg/core'; import {ppath, npath, PortablePath, Filename, xfs} from '@yarnpkg/fslib'; import {generatePath} from '../sources/commands/link'; -import {structUtils} from '@yarnpkg/core'; describe(`Link`, () => { describe(`generatePath`, () => { From c6724d1372da54457e5d136c4d25085d61ccf757 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Fri, 4 Oct 2024 06:40:21 +0000 Subject: [PATCH 8/9] yarn cross spawn --- .pnp.cjs | 2 ++ package.json | 1 + yarn.lock | 1 + 3 files changed, 4 insertions(+) diff --git a/.pnp.cjs b/.pnp.cjs index 8963d147ef16..98f17a847705 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -268,6 +268,7 @@ const RAW_RUNTIME_STATE = ["@yarnpkg/types", "workspace:packages/yarnpkg-types"],\ ["chalk", "npm:3.0.0"],\ ["clipanion", "virtual:576bf3e379b293160348e4cadfbd6541796e6f78477b0875c4437065090cec6f78b6ec2281b8e15d1c870d61578dc7dee16a5ae49a65701fec83e592ce2ebdeb#npm:4.0.0-rc.2"],\ + ["cross-spawn", "npm:7.0.3"],\ ["esbuild", [\ "esbuild-wasm",\ "npm:0.23.0"\ @@ -9610,6 +9611,7 @@ const RAW_RUNTIME_STATE = ["@yarnpkg/types", "workspace:packages/yarnpkg-types"],\ ["chalk", "npm:3.0.0"],\ ["clipanion", "virtual:576bf3e379b293160348e4cadfbd6541796e6f78477b0875c4437065090cec6f78b6ec2281b8e15d1c870d61578dc7dee16a5ae49a65701fec83e592ce2ebdeb#npm:4.0.0-rc.2"],\ + ["cross-spawn", "npm:7.0.3"],\ ["esbuild", [\ "esbuild-wasm",\ "npm:0.23.0"\ diff --git a/package.json b/package.json index 8ae492bda1f5..6eca86a4a768 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "@iarna/toml": "^2.2.5", "@yarnpkg/types": "workspace:^", "chalk": "^3.0.0", + "cross-spawn": "^7.0.3", "micromatch": "^4.0.2", "semver": "^7.1.2" }, diff --git a/yarn.lock b/yarn.lock index 5363fc804cbf..f27910ef5ae1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5735,6 +5735,7 @@ __metadata: "@yarnpkg/types": "workspace:^" chalk: "npm:^3.0.0" clipanion: "npm:^4.0.0-rc.2" + cross-spawn: "npm:^7.0.3" esbuild: "npm:esbuild-wasm@^0.23.0" eslint: "npm:^8.57.0" jest: "npm:^29.2.1" From dcb3856d5da4fd2b7db85286306f1ead3aeb3033 Mon Sep 17 00:00:00 2001 From: Aditya Pandey Date: Fri, 4 Oct 2024 07:30:36 +0000 Subject: [PATCH 9/9] changes --- packages/plugin-essentials/sources/commands/link.ts | 4 ++-- packages/yarnpkg-core/tests/Link.test.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/plugin-essentials/sources/commands/link.ts b/packages/plugin-essentials/sources/commands/link.ts index a1057f05e93f..a47b7d174dfc 100644 --- a/packages/plugin-essentials/sources/commands/link.ts +++ b/packages/plugin-essentials/sources/commands/link.ts @@ -52,7 +52,7 @@ export default class LinkCommand extends BaseCommand { }); const topLevelWorkspace = project.topLevelWorkspace; - const linkedWorkspaces = []; + const linkedWorkspaces: Array = []; for (const destination of this.destinations) { const absoluteDestination = ppath.resolve(this.context.cwd, npath.toPortablePath(destination)); @@ -89,7 +89,7 @@ export default class LinkCommand extends BaseCommand { } } - const processWorkspace = async workspace => { + const processWorkspace = async (workspace: any) => { const fullName = structUtils.stringifyIdent(workspace.anchoredLocator); let target = this.relative ? ppath.relative(project.cwd, workspace.cwd) diff --git a/packages/yarnpkg-core/tests/Link.test.ts b/packages/yarnpkg-core/tests/Link.test.ts index 49a951b8b3ff..65cdfbfe80a3 100644 --- a/packages/yarnpkg-core/tests/Link.test.ts +++ b/packages/yarnpkg-core/tests/Link.test.ts @@ -1,7 +1,7 @@ -import {structUtils} from '@yarnpkg/core'; -import {ppath, npath, PortablePath, Filename, xfs} from '@yarnpkg/fslib'; +import {structUtils} from '@yarnpkg/core'; +import {ppath, npath, PortablePath, xfs} from '@yarnpkg/fslib'; -import {generatePath} from '../sources/commands/link'; +import {generatePath} from '../sources/commands/link'; describe(`Link`, () => { describe(`generatePath`, () => {