@yarnpkg/plugin-pnp 4.1.6 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +7 -0
- package/lib/index.js +41 -6
- package/package.json +6 -6
package/lib/index.d.ts
CHANGED
|
@@ -8,15 +8,22 @@ import * as pnpUtils from './pnpUtils';
|
|
|
8
8
|
export { UnplugCommand };
|
|
9
9
|
export { jsInstallUtils };
|
|
10
10
|
export { pnpUtils };
|
|
11
|
+
export declare enum NodePackageMapType {
|
|
12
|
+
STANDARD = "standard",
|
|
13
|
+
LOOSE = "loose"
|
|
14
|
+
}
|
|
11
15
|
export declare const getPnpPath: (project: Project) => {
|
|
12
16
|
cjs: PortablePath;
|
|
13
17
|
data: PortablePath;
|
|
14
18
|
esmLoader: PortablePath;
|
|
15
19
|
};
|
|
20
|
+
export declare const getPackageMapPath: (project: Project) => PortablePath;
|
|
16
21
|
export declare const quotePathIfNeeded: (path: string) => string;
|
|
17
22
|
declare module '@yarnpkg/core' {
|
|
18
23
|
interface ConfigurationValueMap {
|
|
19
24
|
nodeLinker: string;
|
|
25
|
+
nodeExperimentalPackageMap: boolean;
|
|
26
|
+
nodePackageMapType: string;
|
|
20
27
|
winLinkType: string;
|
|
21
28
|
pnpMode: string;
|
|
22
29
|
minizip: boolean;
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PnpLinker = exports.PnpInstaller = exports.quotePathIfNeeded = exports.getPnpPath = exports.pnpUtils = exports.jsInstallUtils = exports.UnplugCommand = void 0;
|
|
3
|
+
exports.PnpLinker = exports.PnpInstaller = exports.quotePathIfNeeded = exports.getPackageMapPath = exports.getPnpPath = exports.NodePackageMapType = exports.pnpUtils = exports.jsInstallUtils = exports.UnplugCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const core_1 = require("@yarnpkg/core");
|
|
6
6
|
const fslib_1 = require("@yarnpkg/fslib");
|
|
@@ -12,6 +12,11 @@ const jsInstallUtils = tslib_1.__importStar(require("./jsInstallUtils"));
|
|
|
12
12
|
exports.jsInstallUtils = jsInstallUtils;
|
|
13
13
|
const pnpUtils = tslib_1.__importStar(require("./pnpUtils"));
|
|
14
14
|
exports.pnpUtils = pnpUtils;
|
|
15
|
+
var NodePackageMapType;
|
|
16
|
+
(function (NodePackageMapType) {
|
|
17
|
+
NodePackageMapType["STANDARD"] = "standard";
|
|
18
|
+
NodePackageMapType["LOOSE"] = "loose";
|
|
19
|
+
})(NodePackageMapType || (exports.NodePackageMapType = NodePackageMapType = {}));
|
|
15
20
|
const getPnpPath = (project) => {
|
|
16
21
|
return {
|
|
17
22
|
cjs: fslib_1.ppath.join(project.cwd, fslib_1.Filename.pnpCjs),
|
|
@@ -20,6 +25,10 @@ const getPnpPath = (project) => {
|
|
|
20
25
|
};
|
|
21
26
|
};
|
|
22
27
|
exports.getPnpPath = getPnpPath;
|
|
28
|
+
const getPackageMapPath = (project) => {
|
|
29
|
+
return fslib_1.ppath.join(project.cwd, fslib_1.Filename.nodeModules, `.package-map.json`);
|
|
30
|
+
};
|
|
31
|
+
exports.getPackageMapPath = getPackageMapPath;
|
|
23
32
|
const quotePathIfNeeded = (path) => {
|
|
24
33
|
return /\s/.test(path) ? JSON.stringify(path) : path;
|
|
25
34
|
};
|
|
@@ -30,16 +39,27 @@ async function setupScriptEnvironment(project, env, makePathWrapper) {
|
|
|
30
39
|
// TODO: Support `-r` as an alias for `--require` (in all packages)
|
|
31
40
|
const pnpRegularExpression = /\s*--require\s+\S*\.pnp\.c?js\s*/g;
|
|
32
41
|
const esmLoaderExpression = /\s*--experimental-loader\s+\S*\.pnp\.loader\.mjs\s*/;
|
|
42
|
+
const packageMapExpression = /\s*--experimental-package-map(?:=|\s+)(?:"[^"]*"|'[^']*'|\S+)\s*/g;
|
|
33
43
|
const nodeOptions = (env.NODE_OPTIONS ?? ``)
|
|
34
44
|
.replace(pnpRegularExpression, ` `)
|
|
35
45
|
.replace(esmLoaderExpression, ` `)
|
|
46
|
+
.replace(packageMapExpression, ` `)
|
|
36
47
|
.trim();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
const nodeLinker = project.configuration.get(`nodeLinker`);
|
|
49
|
+
const extraNodeOptions = [];
|
|
50
|
+
const packageMapPath = (0, exports.getPackageMapPath)(project);
|
|
51
|
+
if (project.configuration.get(`nodeExperimentalPackageMap`) && nodeLinker !== `pnp` && fslib_1.xfs.existsSync(packageMapPath))
|
|
52
|
+
extraNodeOptions.push(`--experimental-package-map=${(0, exports.quotePathIfNeeded)(fslib_1.npath.fromPortablePath(packageMapPath))}`);
|
|
53
|
+
const applyNodeOptions = () => {
|
|
54
|
+
const effectiveNodeOptions = [...extraNodeOptions, nodeOptions].filter(Boolean).join(` `);
|
|
40
55
|
// When set to an empty string, some tools consider it as explicitly set
|
|
41
56
|
// to the empty value, and do not set their own value.
|
|
42
|
-
env.NODE_OPTIONS =
|
|
57
|
+
env.NODE_OPTIONS = effectiveNodeOptions ? effectiveNodeOptions : undefined;
|
|
58
|
+
};
|
|
59
|
+
// We remove the PnP hook from NODE_OPTIONS because the process can have
|
|
60
|
+
// NODE_OPTIONS set while changing linkers, which affects build scripts.
|
|
61
|
+
if (nodeLinker !== `pnp`) {
|
|
62
|
+
applyNodeOptions();
|
|
43
63
|
return;
|
|
44
64
|
}
|
|
45
65
|
const pnpPath = (0, exports.getPnpPath)(project);
|
|
@@ -47,7 +67,8 @@ async function setupScriptEnvironment(project, env, makePathWrapper) {
|
|
|
47
67
|
if (fslib_1.xfs.existsSync(pnpPath.esmLoader))
|
|
48
68
|
pnpRequire = `${pnpRequire} --experimental-loader ${(0, url_1.pathToFileURL)(fslib_1.npath.fromPortablePath(pnpPath.esmLoader)).href}`;
|
|
49
69
|
if (fslib_1.xfs.existsSync(pnpPath.cjs)) {
|
|
50
|
-
|
|
70
|
+
extraNodeOptions.unshift(pnpRequire);
|
|
71
|
+
applyNodeOptions();
|
|
51
72
|
}
|
|
52
73
|
}
|
|
53
74
|
async function populateYarnPaths(project, definePath) {
|
|
@@ -68,6 +89,20 @@ const plugin = {
|
|
|
68
89
|
type: core_1.SettingsType.STRING,
|
|
69
90
|
default: `pnp`,
|
|
70
91
|
},
|
|
92
|
+
nodeExperimentalPackageMap: {
|
|
93
|
+
description: `If true, Yarn will inject the experimental package map into Node.js processes when using the node-modules or pnpm linkers.`,
|
|
94
|
+
type: core_1.SettingsType.BOOLEAN,
|
|
95
|
+
default: false,
|
|
96
|
+
},
|
|
97
|
+
nodePackageMapType: {
|
|
98
|
+
description: `If 'standard', package maps will reflect the dependency graph. If 'loose', they will reflect the hoisted node_modules layout.`,
|
|
99
|
+
type: core_1.SettingsType.STRING,
|
|
100
|
+
values: [
|
|
101
|
+
NodePackageMapType.STANDARD,
|
|
102
|
+
NodePackageMapType.LOOSE,
|
|
103
|
+
],
|
|
104
|
+
default: NodePackageMapType.STANDARD,
|
|
105
|
+
},
|
|
71
106
|
minizip: {
|
|
72
107
|
description: `Whether Yarn should use minizip to extract archives`,
|
|
73
108
|
type: core_1.SettingsType.BOOLEAN,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarnpkg/plugin-pnp",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"license": "BSD-2-Clause",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@yarnpkg/fslib": "^3.1.5",
|
|
12
12
|
"@yarnpkg/plugin-stage": "^4.0.2",
|
|
13
|
-
"@yarnpkg/pnp": "^4.1.
|
|
13
|
+
"@yarnpkg/pnp": "^4.1.7",
|
|
14
14
|
"clipanion": "^4.0.0-rc.2",
|
|
15
15
|
"micromatch": "^4.0.2",
|
|
16
16
|
"tslib": "^2.4.0"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@yarnpkg/cli": "^4.
|
|
20
|
-
"@yarnpkg/core": "^4.
|
|
19
|
+
"@yarnpkg/cli": "^4.17.0",
|
|
20
|
+
"@yarnpkg/core": "^4.9.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/micromatch": "^4.0.1",
|
|
24
|
-
"@yarnpkg/cli": "^4.
|
|
25
|
-
"@yarnpkg/core": "^4.
|
|
24
|
+
"@yarnpkg/cli": "^4.17.0",
|
|
25
|
+
"@yarnpkg/core": "^4.9.0"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|