Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Yarn doesn't want to Link Firebase #6536

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions .yarn/versions/67af515f.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
46 changes: 39 additions & 7 deletions packages/plugin-essentials/sources/commands/link.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Cache, Configuration, Project, structUtils} from '@yarnpkg/core';
import {npath, ppath} from '@yarnpkg/fslib';
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 {
static paths = [
Expand Down Expand Up @@ -50,7 +52,7 @@ export default class LinkCommand extends BaseCommand {
});

const topLevelWorkspace = project.topLevelWorkspace;
const linkedWorkspaces = [];
const linkedWorkspaces: Array<any> = [];

for (const destination of this.destinations) {
const absoluteDestination = ppath.resolve(this.context.cwd, npath.toPortablePath(destination));
Expand Down Expand Up @@ -87,20 +89,50 @@ export default class LinkCommand extends BaseCommand {
}
}

for (const workspace of linkedWorkspaces) {
const processWorkspace = async (workspace: any) => {
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({
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)) {
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);
}

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,
});
Expand Down
45 changes: 45 additions & 0 deletions packages/yarnpkg-core/tests/Link.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {structUtils} from '@yarnpkg/core';
import {ppath, npath, PortablePath, xfs} from '@yarnpkg/fslib';

import {generatePath} from '../sources/commands/link';

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,
});
}
});
});
});
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading