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

Yarn: Fix pnp package resolution on Windows #23274

Merged
merged 2 commits into from
Jul 5, 2023
Merged
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
4 changes: 2 additions & 2 deletions code/lib/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"@storybook/telemetry": "7.1.0-alpha.44",
"@storybook/types": "7.1.0-alpha.44",
"@types/semver": "^7.3.4",
"@yarnpkg/fslib": "^2.10.3",
"@yarnpkg/libzip": "^2.3.0",
"@yarnpkg/fslib": "^3.0.0-rc.48",
"@yarnpkg/libzip": "^3.0.0-rc.48",
"chalk": "^4.1.0",
"commander": "^6.2.1",
"cross-spawn": "^7.0.3",
Expand Down
24 changes: 12 additions & 12 deletions code/lib/cli/src/js-package-manager/Yarn2Proxy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dedent from 'ts-dedent';
import { sync as findUpSync, sync as syncFindUp } from 'find-up';
import fs, { existsSync, readFileSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { NodeFS, VirtualFS, ZipOpenFS } from '@yarnpkg/fslib';
import { getLibzipSync } from '@yarnpkg/libzip';
import { PosixFS } from '@yarnpkg/fslib';
import { getLibzipSync, ZipOpenFS } from '@yarnpkg/libzip';
import semver from 'semver';
import { createLogStream } from '../utils';
import { JsPackageManager } from './JsPackageManager';
Expand Down Expand Up @@ -138,20 +138,20 @@ export class Yarn2Proxy extends JsPackageManager {
const pkgLocator = pnpApi.findPackageLocator(resolvedPath);
const pkg = pnpApi.getPackageInformation(pkgLocator);

const localFs: typeof fs = { ...fs };
const nodeFs = new NodeFS(localFs);

const zipOpenFs = new ZipOpenFS({
libzip: getLibzipSync(),
baseFs: nodeFs,
readOnlyArchives: true,
});

const virtualFs = new VirtualFS({
baseFs: zipOpenFs,
});
const crossFs = new PosixFS(zipOpenFs);

// On Windows "crossFs.readJsonSync" does not resolve virtual paths. Unknown bug
if (process.platform === 'win32' && !!pnpApi.VERSIONS.resolveVirtual) {
const virtualPath = path.join(pkg.packageLocation, 'package.json');
const physicalPath = pnpApi.resolveVirtual(virtualPath);
return crossFs.readJsonSync(physicalPath);
}

return virtualFs.readJsonSync(path.join(pkg.packageLocation, 'package.json') as any);
return crossFs.readJsonSync(path.join(pkg.packageLocation, 'package.json') as any);
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
console.error('Error while fetching package version in Yarn PnP mode:', error);
Expand Down
30 changes: 16 additions & 14 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6000,8 +6000,8 @@ __metadata:
"@types/puppeteer-core": ^2.1.0
"@types/semver": ^7.3.4
"@types/util-deprecate": ^1.0.0
"@yarnpkg/fslib": ^2.10.3
"@yarnpkg/libzip": ^2.3.0
"@yarnpkg/fslib": ^3.0.0-rc.48
"@yarnpkg/libzip": ^3.0.0-rc.48
boxen: ^5.1.2
chalk: ^4.1.0
commander: ^6.2.1
Expand Down Expand Up @@ -9716,23 +9716,25 @@ __metadata:
languageName: node
linkType: hard

"@yarnpkg/fslib@npm:^2.10.3":
version: 2.10.3
resolution: "@yarnpkg/fslib@npm:2.10.3"
"@yarnpkg/fslib@npm:^3.0.0-rc.48":
version: 3.0.0-rc.48
resolution: "@yarnpkg/fslib@npm:3.0.0-rc.48"
dependencies:
"@yarnpkg/libzip": ^2.3.0
tslib: ^1.13.0
checksum: c4fbbed99e801f17c381204e9699d9ea4fb51b14e99968985f477bdbc7b02b61e026860173f3f46bd60d9f46ae6a06f420a3edb3c02c3a45ae83779095928094
tslib: ^2.4.0
checksum: e4c8f640f002047efe915e656537f7057f39de9276ccef602289c9968a5b257ba3f78e8face02f17a28e9e28f055c8c8b64f4f29558c9c6bc0318029cb8c027b
languageName: node
linkType: hard

"@yarnpkg/libzip@npm:^2.3.0":
version: 2.3.0
resolution: "@yarnpkg/libzip@npm:2.3.0"
"@yarnpkg/libzip@npm:^3.0.0-rc.48":
version: 3.0.0-rc.48
resolution: "@yarnpkg/libzip@npm:3.0.0-rc.48"
dependencies:
"@types/emscripten": ^1.39.6
tslib: ^1.13.0
checksum: 0c2361ccb002e28463ed98541f3bdaab54f52aad6a2080666c2a9ea605ebd9cdfb7b0340b1db6f105820d05bcb803cdfb3ce755a8f6034657298c291bf884f81
"@yarnpkg/fslib": ^3.0.0-rc.48
tslib: ^2.4.0
peerDependencies:
"@yarnpkg/fslib": ^3.0.0-rc.48
checksum: ec9930d8ef1d3faceae2e52aa500e87de4a6aeaef92cf65c3df51c60b7da3cbef539339e5b14ee2138e5e06b814393f28ab2ae52d7ea53288ae5e70c7fb9aab5
languageName: node
linkType: hard

Expand Down Expand Up @@ -29499,7 +29501,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^1.10.0, tslib@npm:^1.13.0, tslib@npm:^1.8.1, tslib@npm:^1.9.0, tslib@npm:^1.9.3":
"tslib@npm:^1.10.0, tslib@npm:^1.8.1, tslib@npm:^1.9.0, tslib@npm:^1.9.3":
version: 1.14.1
resolution: "tslib@npm:1.14.1"
checksum: 69ae09c49eea644bc5ebe1bca4fa4cc2c82b7b3e02f43b84bd891504edf66dbc6b2ec0eef31a957042de2269139e4acff911e6d186a258fb14069cd7f6febce2
Expand Down