Skip to content

Commit 242234c

Browse files
goloveychukarcanis
andauthored
Improve pnp loader speed and memory: jszip implementation (#6688)
## What's the problem this PR addresses? rework of #6671 TODO: - [ ] check security? - [x] tests - [ ] elaborate mixed compression logic - [ ] benchmarks? - [ ] hide exports and interfaces for external consumers? <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> ... ## How did you fix it? <!-- A detailed description of your implementation. --> ... ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [ ] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [ ] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Maël Nison <[email protected]>
1 parent e06bacd commit 242234c

File tree

197 files changed

+5583
-518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+5583
-518
lines changed

.pnp.cjs

+496-227
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/01575767.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/libzip": minor
4+
"@yarnpkg/plugin-pnp": minor
5+
"@yarnpkg/pnp": minor
6+
7+
declined:
8+
- "@yarnpkg/plugin-compat"
9+
- "@yarnpkg/plugin-constraints"
10+
- "@yarnpkg/plugin-dlx"
11+
- "@yarnpkg/plugin-essentials"
12+
- "@yarnpkg/plugin-file"
13+
- "@yarnpkg/plugin-init"
14+
- "@yarnpkg/plugin-interactive-tools"
15+
- "@yarnpkg/plugin-nm"
16+
- "@yarnpkg/plugin-npm-cli"
17+
- "@yarnpkg/plugin-pack"
18+
- "@yarnpkg/plugin-patch"
19+
- "@yarnpkg/plugin-pnpm"
20+
- "@yarnpkg/plugin-stage"
21+
- "@yarnpkg/plugin-typescript"
22+
- "@yarnpkg/plugin-version"
23+
- "@yarnpkg/plugin-workspace-tools"
24+
- vscode-zipfs
25+
- "@yarnpkg/builder"
26+
- "@yarnpkg/core"
27+
- "@yarnpkg/doctor"
28+
- "@yarnpkg/fslib"
29+
- "@yarnpkg/nm"
30+
- "@yarnpkg/pnpify"
31+
- "@yarnpkg/sdks"

.yarnrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ immutablePatterns:
1515

1616
initScope: yarnpkg
1717

18+
pnpZipBackend: js
19+
1820
npmPublishAccess: public
1921

2022
packageExtensions:

packages/acceptance-tests/pkg-tests-specs/sources/basic.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const {
55

66
const configs = [{
77
nodeLinker: `pnp`,
8+
}, {
9+
nodeLinker: `pnp`,
10+
pnpZipBackend: `js`,
811
}, {
912
nodeLinker: `pnpm`,
1013
}, {
@@ -13,7 +16,7 @@ const configs = [{
1316

1417
describe(`Basic tests`, () => {
1518
for (const config of configs) {
16-
describe(`w/ the ${config.nodeLinker} linker`, () => {
19+
describe(`w/ the ${config.nodeLinker} linker${config.pnpZipBackend ? ` and ${config.pnpZipBackend} zip backend` : ``}`, () => {
1720
test(
1821
`it should correctly handle browser fields in package.json`,
1922
makeTemporaryEnv(

packages/plugin-pnp/sources/PnpLinker.ts

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ export class PnpInstaller implements Installer {
267267
const ignorePattern = miscUtils.buildIgnorePattern([`.yarn/sdks/**`, ...this.opts.project.configuration.get(`pnpIgnorePatterns`)]);
268268
const packageRegistry = this.packageRegistry;
269269
const shebang = this.opts.project.configuration.get(`pnpShebang`);
270+
const pnpZipBackend = this.opts.project.configuration.get(`pnpZipBackend`);
270271

271272
if (pnpFallbackMode === `dependencies-only`)
272273
for (const pkg of this.opts.project.storedPackages.values())
@@ -281,6 +282,7 @@ export class PnpInstaller implements Installer {
281282
fallbackExclusionList,
282283
fallbackPool,
283284
ignorePattern,
285+
pnpZipBackend,
284286
packageRegistry,
285287
shebang,
286288
});

packages/plugin-pnp/sources/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Hooks as CoreHooks, Plugin, Project, SettingsType, WindowsLinkType} from '@yarnpkg/core';
22
import {Filename, PortablePath, npath, ppath, xfs} from '@yarnpkg/fslib';
33
import {Hooks as StageHooks} from '@yarnpkg/plugin-stage';
4+
import {PnpZipBackend} from '@yarnpkg/pnp';
45
import {pathToFileURL} from 'url';
56

67
import {PnpLinker} from './PnpLinker';
@@ -70,12 +71,14 @@ declare module '@yarnpkg/core' {
7071
nodeLinker: string;
7172
winLinkType: string;
7273
pnpMode: string;
74+
minizip: boolean;
7375
pnpShebang: string;
7476
pnpIgnorePatterns: Array<string>;
7577
pnpEnableEsmLoader: boolean;
7678
pnpEnableInlining: boolean;
7779
pnpFallbackMode: string;
7880
pnpUnpluggedFolder: PortablePath;
81+
pnpZipBackend: PnpZipBackend;
7982
}
8083
}
8184

@@ -90,6 +93,11 @@ const plugin: Plugin<CoreHooks & StageHooks> = {
9093
type: SettingsType.STRING,
9194
default: `pnp`,
9295
},
96+
minizip: {
97+
description: `Whether Yarn should use minizip to extract archives`,
98+
type: SettingsType.BOOLEAN,
99+
default: false,
100+
},
93101
winLinkType: {
94102
description: `Whether Yarn should use Windows Junctions or symlinks when creating links on Windows.`,
95103
type: SettingsType.STRING,
@@ -115,6 +123,15 @@ const plugin: Plugin<CoreHooks & StageHooks> = {
115123
default: [],
116124
isArray: true,
117125
},
126+
pnpZipBackend: {
127+
description: `Whether to use the experimental js implementation for the ZipFS`,
128+
type: SettingsType.STRING,
129+
values: [
130+
`libzip`,
131+
`js`,
132+
],
133+
default: `libzip`,
134+
},
118135
pnpEnableEsmLoader: {
119136
description: `If true, Yarn will generate an ESM loader (\`.pnp.loader.mjs\`). If this is not explicitly set Yarn tries to automatically detect whether ESM support is required.`,
120137
type: SettingsType.BOOLEAN,

packages/yarnpkg-libzip/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
},
3939
"devDependencies": {
4040
"@types/prettier": "1.19.0",
41+
"globby": "^11.0.1",
4142
"prettier": "^1.19.1"
4243
},
4344
"dependencies": {

0 commit comments

Comments
 (0)