@pnpm/plugin-commands-env 1.0.9 → 1.2.1
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/env.js +26 -40
- package/lib/env.js.map +1 -1
- package/lib/node.d.ts +4 -2
- package/lib/node.js +14 -13
- package/lib/node.js.map +1 -1
- package/lib/resolveNodeVersion.d.ts +7 -0
- package/lib/resolveNodeVersion.js +60 -0
- package/lib/resolveNodeVersion.js.map +1 -0
- package/package.json +6 -5
package/lib/env.js
CHANGED
|
@@ -4,15 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.handler = exports.help = exports.commandNames = exports.cliOptionsTypes = exports.rcOptionsTypes = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const cli_utils_1 = require("@pnpm/cli-utils");
|
|
9
10
|
const error_1 = __importDefault(require("@pnpm/error"));
|
|
10
|
-
const fetch_1 = __importDefault(require("@pnpm/fetch"));
|
|
11
11
|
const cmd_shim_1 = __importDefault(require("@zkochan/cmd-shim"));
|
|
12
12
|
const render_help_1 = __importDefault(require("render-help"));
|
|
13
|
-
const semver_1 = __importDefault(require("semver"));
|
|
14
|
-
const version_selector_type_1 = __importDefault(require("version-selector-type"));
|
|
15
13
|
const node_1 = require("./node");
|
|
14
|
+
const resolveNodeVersion_1 = __importDefault(require("./resolveNodeVersion"));
|
|
16
15
|
function rcOptionsTypes() {
|
|
17
16
|
return {};
|
|
18
17
|
}
|
|
@@ -25,7 +24,7 @@ function cliOptionsTypes() {
|
|
|
25
24
|
exports.cliOptionsTypes = cliOptionsTypes;
|
|
26
25
|
exports.commandNames = ['env'];
|
|
27
26
|
function help() {
|
|
28
|
-
return render_help_1.default({
|
|
27
|
+
return (0, render_help_1.default)({
|
|
29
28
|
description: 'Install and use the specified version of Node.js. The npm CLI bundled with the given Node.js version gets installed as well.',
|
|
30
29
|
descriptionLists: [
|
|
31
30
|
{
|
|
@@ -39,12 +38,14 @@ function help() {
|
|
|
39
38
|
],
|
|
40
39
|
},
|
|
41
40
|
],
|
|
42
|
-
url: cli_utils_1.docsUrl('env'),
|
|
41
|
+
url: (0, cli_utils_1.docsUrl)('env'),
|
|
43
42
|
usages: [
|
|
44
43
|
'pnpm env use --global <version>',
|
|
45
44
|
'pnpm env use --global 16',
|
|
46
45
|
'pnpm env use --global lts',
|
|
47
46
|
'pnpm env use --global argon',
|
|
47
|
+
'pnpm env use --global latest',
|
|
48
|
+
'pnpm env use --global rc/16',
|
|
48
49
|
],
|
|
49
50
|
});
|
|
50
51
|
}
|
|
@@ -58,28 +59,39 @@ async function handler(opts, params) {
|
|
|
58
59
|
if (!opts.global) {
|
|
59
60
|
throw new error_1.default('NOT_IMPLEMENTED_YET', '"pnpm env use <version>" can only be used with the "--global" option currently');
|
|
60
61
|
}
|
|
61
|
-
const nodeVersion = await
|
|
62
|
+
const { version: nodeVersion, releaseDir } = await (0, resolveNodeVersion_1.default)(params[1]);
|
|
62
63
|
if (!nodeVersion) {
|
|
63
64
|
throw new error_1.default('COULD_NOT_RESOLVE_NODEJS', `Couldn't find Node.js version matching ${params[1]}`);
|
|
64
65
|
}
|
|
65
|
-
const nodeDir = await node_1.getNodeDir({
|
|
66
|
+
const nodeDir = await (0, node_1.getNodeDir)({
|
|
66
67
|
...opts,
|
|
67
68
|
useNodeVersion: nodeVersion,
|
|
69
|
+
releaseDir,
|
|
68
70
|
});
|
|
69
71
|
const src = path_1.default.join(nodeDir, process.platform === 'win32' ? 'node.exe' : 'bin/node');
|
|
70
|
-
const dest = path_1.default.join(opts.bin, 'node');
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const dest = path_1.default.join(opts.bin, process.platform === 'win32' ? 'node.exe' : 'node');
|
|
73
|
+
try {
|
|
74
|
+
await fs_1.promises.unlink(dest);
|
|
75
|
+
}
|
|
76
|
+
catch (err) { }
|
|
77
|
+
await fs_1.promises.symlink(src, dest, 'file');
|
|
73
78
|
try {
|
|
74
79
|
let npmDir = nodeDir;
|
|
75
80
|
if (process.platform !== 'win32') {
|
|
76
81
|
npmDir = path_1.default.join(npmDir, 'lib');
|
|
77
82
|
}
|
|
78
|
-
npmDir = path_1.default.join(npmDir, 'node_modules/npm
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
npmDir = path_1.default.join(npmDir, 'node_modules/npm');
|
|
84
|
+
if (opts.configDir) {
|
|
85
|
+
// We want the global npm settings to persist when Node.js or/and npm is changed to a different version,
|
|
86
|
+
// so we tell npm to read the global config from centralized place that is outside of npm's directory.
|
|
87
|
+
await fs_1.promises.writeFile(path_1.default.join(npmDir, 'npmrc'), `globalconfig=${path_1.default.join(opts.configDir, 'npmrc')}`, 'utf-8');
|
|
88
|
+
}
|
|
89
|
+
const npmBinDir = path_1.default.join(npmDir, 'bin');
|
|
90
|
+
const cmdShimOpts = { createPwshFile: false };
|
|
91
|
+
await (0, cmd_shim_1.default)(path_1.default.join(npmBinDir, 'npm-cli.js'), path_1.default.join(opts.bin, 'npm'), cmdShimOpts);
|
|
92
|
+
await (0, cmd_shim_1.default)(path_1.default.join(npmBinDir, 'npx-cli.js'), path_1.default.join(opts.bin, 'npx'), cmdShimOpts);
|
|
81
93
|
}
|
|
82
|
-
catch (err) {
|
|
94
|
+
catch (err) { // eslint-disable-line
|
|
83
95
|
// ignore
|
|
84
96
|
}
|
|
85
97
|
return `Node.js ${nodeVersion} is activated
|
|
@@ -91,30 +103,4 @@ async function handler(opts, params) {
|
|
|
91
103
|
}
|
|
92
104
|
}
|
|
93
105
|
exports.handler = handler;
|
|
94
|
-
async function resolveNodeVersion(rawVersionSelector) {
|
|
95
|
-
const response = await fetch_1.default('https://nodejs.org/download/release/index.json');
|
|
96
|
-
const allVersions = (await response.json());
|
|
97
|
-
const { versions, versionSelector } = filterVersions(allVersions, rawVersionSelector);
|
|
98
|
-
const pickedVersion = semver_1.default.maxSatisfying(versions.map(({ version }) => version), versionSelector);
|
|
99
|
-
if (!pickedVersion)
|
|
100
|
-
return null;
|
|
101
|
-
return pickedVersion.substring(1);
|
|
102
|
-
}
|
|
103
|
-
function filterVersions(versions, versionSelector) {
|
|
104
|
-
if (versionSelector === 'lts') {
|
|
105
|
-
return {
|
|
106
|
-
versions: versions.filter(({ lts }) => lts !== false),
|
|
107
|
-
versionSelector: '*',
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
const vst = version_selector_type_1.default(versionSelector);
|
|
111
|
-
if ((vst === null || vst === void 0 ? void 0 : vst.type) === 'tag') {
|
|
112
|
-
const wantedLtsVersion = vst.normalized.toLowerCase();
|
|
113
|
-
return {
|
|
114
|
-
versions: versions.filter(({ lts }) => typeof lts === 'string' && lts.toLowerCase() === wantedLtsVersion),
|
|
115
|
-
versionSelector: '*',
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return { versions, versionSelector };
|
|
119
|
-
}
|
|
120
106
|
//# sourceMappingURL=env.js.map
|
package/lib/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,+CAAyC;AACzC,wDAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAmC;AACnC,gDAAuB;AACvB,+CAAyC;AACzC,wDAAmC;AACnC,iEAAuC;AACvC,8DAAoC;AACpC,iCAA0D;AAC1D,8EAAqD;AAErD,SAAgB,cAAc;IAC5B,OAAO,EAAE,CAAA;AACX,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe;IAC7B,OAAO;QACL,MAAM,EAAE,OAAO;KAChB,CAAA;AACH,CAAC;AAJD,0CAIC;AAEY,QAAA,YAAY,GAAG,CAAC,KAAK,CAAC,CAAA;A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CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,CAAA;gBAC1F,MAAM,IAAA,kBAAO,EAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,CAAA;aAC3F;YAAC,OAAO,GAAQ,EAAE,EAAE,sBAAsB;gBACzC,SAAS;aACV;YACD,OAAO,WAAW,WAAW;IAC7B,IAAI,OAAO,GAAG,EAAE,CAAA;SACjB;QACD,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,eAAS,CAAC,wBAAwB,EAAE,8BAA8B,CAAC,CAAA;SAC9E;KACA;AACH,CAAC;AAjDD,0BAiDC"}
|
package/lib/node.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Config } from '@pnpm/config';
|
|
2
|
-
export declare type NvmNodeCommandOptions = Pick<Config, 'bin' | 'global' | 'rawConfig' | 'fetchRetries' | 'fetchRetryFactor' | 'fetchRetryMaxtimeout' | 'fetchRetryMintimeout' | 'fetchRetryMintimeout' | 'fetchTimeout' | 'userAgent' | 'ca' | 'cert' | 'httpProxy' | 'httpsProxy' | 'key' | 'localAddress' | 'noProxy' | 'strictSsl' | 'storeDir' | 'useNodeVersion' | 'pnpmHomeDir'
|
|
2
|
+
export declare type NvmNodeCommandOptions = Pick<Config, 'bin' | 'global' | 'rawConfig' | 'fetchRetries' | 'fetchRetryFactor' | 'fetchRetryMaxtimeout' | 'fetchRetryMintimeout' | 'fetchRetryMintimeout' | 'fetchTimeout' | 'userAgent' | 'ca' | 'cert' | 'httpProxy' | 'httpsProxy' | 'key' | 'localAddress' | 'noProxy' | 'strictSsl' | 'storeDir' | 'useNodeVersion' | 'pnpmHomeDir'> & Partial<Pick<Config, 'configDir'>>;
|
|
3
3
|
export declare function getNodeBinDir(opts: NvmNodeCommandOptions): Promise<string>;
|
|
4
|
-
export declare function getNodeDir(opts: NvmNodeCommandOptions
|
|
4
|
+
export declare function getNodeDir(opts: NvmNodeCommandOptions & {
|
|
5
|
+
releaseDir?: string;
|
|
6
|
+
}): Promise<string>;
|
package/lib/node.js
CHANGED
|
@@ -45,12 +45,12 @@ async function getNodeDir(opts) {
|
|
|
45
45
|
let wantedNodeVersion = (_a = opts.useNodeVersion) !== null && _a !== void 0 ? _a : (_b = (await readNodeVersionsManifest(nodesDir))) === null || _b === void 0 ? void 0 : _b.default;
|
|
46
46
|
await fs_1.default.promises.mkdir(nodesDir, { recursive: true });
|
|
47
47
|
if (wantedNodeVersion == null) {
|
|
48
|
-
const response = await fetch_1.default('https://registry.npmjs.org/node');
|
|
48
|
+
const response = await (0, fetch_1.default)('https://registry.npmjs.org/node');
|
|
49
49
|
wantedNodeVersion = (await response.json())['dist-tags'].lts; // eslint-disable-line
|
|
50
50
|
if (wantedNodeVersion == null) {
|
|
51
51
|
throw new Error('Could not resolve LTS version of Node.js');
|
|
52
52
|
}
|
|
53
|
-
await write_json_file_1.default(path_1.default.join(nodesDir, 'versions.json'), {
|
|
53
|
+
await (0, write_json_file_1.default)(path_1.default.join(nodesDir, 'versions.json'), {
|
|
54
54
|
default: wantedNodeVersion,
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -62,15 +62,16 @@ async function getNodeDir(opts) {
|
|
|
62
62
|
}
|
|
63
63
|
exports.getNodeDir = getNodeDir;
|
|
64
64
|
async function installNode(wantedNodeVersion, versionDir, opts) {
|
|
65
|
+
var _a;
|
|
65
66
|
await fs_1.default.promises.mkdir(versionDir, { recursive: true });
|
|
66
|
-
const { tarball, pkgName } = getNodeJSTarball(wantedNodeVersion);
|
|
67
|
-
const fetchFromRegistry = fetch_1.createFetchFromRegistry(opts);
|
|
67
|
+
const { tarball, pkgName } = getNodeJSTarball(wantedNodeVersion, (_a = opts.releaseDir) !== null && _a !== void 0 ? _a : 'release');
|
|
68
|
+
const fetchFromRegistry = (0, fetch_1.createFetchFromRegistry)(opts);
|
|
68
69
|
if (tarball.endsWith('.zip')) {
|
|
69
70
|
await downloadAndUnpackZip(fetchFromRegistry, tarball, versionDir, pkgName);
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
73
|
const getCredentials = () => ({ authHeaderValue: undefined, alwaysAuth: undefined });
|
|
73
|
-
const fetch = tarball_fetcher_1.default(fetchFromRegistry, getCredentials, {
|
|
74
|
+
const fetch = (0, tarball_fetcher_1.default)(fetchFromRegistry, getCredentials, {
|
|
74
75
|
retry: {
|
|
75
76
|
maxTimeout: opts.fetchRetryMaxtimeout,
|
|
76
77
|
minTimeout: opts.fetchRetryMintimeout,
|
|
@@ -79,15 +80,15 @@ async function installNode(wantedNodeVersion, versionDir, opts) {
|
|
|
79
80
|
},
|
|
80
81
|
timeout: opts.fetchTimeout,
|
|
81
82
|
});
|
|
82
|
-
const storeDir = await store_path_1.default(process.cwd(), opts.storeDir);
|
|
83
|
+
const storeDir = await (0, store_path_1.default)(process.cwd(), opts.storeDir);
|
|
83
84
|
const cafsDir = path_1.default.join(storeDir, 'files');
|
|
84
|
-
const cafs = package_store_1.createCafsStore(cafsDir);
|
|
85
|
+
const cafs = (0, package_store_1.createCafsStore)(cafsDir);
|
|
85
86
|
const { filesIndex } = await fetch.tarball(cafs, { tarball }, {
|
|
86
87
|
lockfileDir: process.cwd(),
|
|
87
88
|
});
|
|
88
89
|
await cafs.importPackage(versionDir, {
|
|
89
90
|
filesResponse: {
|
|
90
|
-
filesIndex: await tarball_fetcher_1.waitForFilesIndex(filesIndex),
|
|
91
|
+
filesIndex: await (0, tarball_fetcher_1.waitForFilesIndex)(filesIndex),
|
|
91
92
|
fromStore: false,
|
|
92
93
|
},
|
|
93
94
|
force: true,
|
|
@@ -103,24 +104,24 @@ async function downloadAndUnpackZip(fetchFromRegistry, zipUrl, targetDir, pkgNam
|
|
|
103
104
|
const zip = new adm_zip_1.default(tmp);
|
|
104
105
|
const nodeDir = path_1.default.dirname(targetDir);
|
|
105
106
|
zip.extractAllTo(nodeDir, true);
|
|
106
|
-
await rename_overwrite_1.default(path_1.default.join(nodeDir, pkgName), targetDir);
|
|
107
|
+
await (0, rename_overwrite_1.default)(path_1.default.join(nodeDir, pkgName), targetDir);
|
|
107
108
|
await fs_1.default.promises.unlink(tmp);
|
|
108
109
|
}
|
|
109
|
-
function getNodeJSTarball(nodeVersion) {
|
|
110
|
+
function getNodeJSTarball(nodeVersion, releaseDir) {
|
|
110
111
|
const platform = process.platform === 'win32' ? 'win' : process.platform;
|
|
111
112
|
const arch = platform === 'win' && process.arch === 'ia32' ? 'x86' : process.arch;
|
|
112
113
|
const extension = platform === 'win' ? 'zip' : 'tar.gz';
|
|
113
114
|
const pkgName = `node-v${nodeVersion}-${platform}-${arch}`;
|
|
114
115
|
return {
|
|
115
116
|
pkgName,
|
|
116
|
-
tarball: `https://nodejs.org/download/
|
|
117
|
+
tarball: `https://nodejs.org/download/${releaseDir}/v${nodeVersion}/${pkgName}.${extension}`,
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
120
|
async function readNodeVersionsManifest(nodesDir) {
|
|
120
121
|
try {
|
|
121
|
-
return await load_json_file_1.default(path_1.default.join(nodesDir, 'versions.json'));
|
|
122
|
+
return await (0, load_json_file_1.default)(path_1.default.join(nodesDir, 'versions.json'));
|
|
122
123
|
}
|
|
123
|
-
catch (err) {
|
|
124
|
+
catch (err) { // eslint-disable-line
|
|
124
125
|
if (err.code === 'ENOENT') {
|
|
125
126
|
return {};
|
|
126
127
|
}
|
package/lib/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AAEvB,qDAA+E;AAC/E,uDAAqD;AACrD,kEAAwC;AACxC,yEAAwE;AACxE,sDAA4B;AAC5B,wEAA8C;AAC9C,kDAAyB;AACzB,oEAAyC;A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AE,+BAA+B,UAAU,KAAK,WAAW,IAAI,OAAO,IAAI,SAAS,EAAE;KAC7F,CAAA;AACH,CAAC;AAED,KAAK,UAAU,wBAAwB,CAAE,QAAgB;IACvD,IAAI;QACF,OAAO,MAAM,IAAA,wBAAY,EAAuB,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAA;KACtF;IAAC,OAAO,GAAQ,EAAE,EAAE,sBAAsB;QACzC,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;YACzB,OAAO,EAAE,CAAA;SACV;QACD,MAAM,GAAG,CAAA;KACV;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fetch_1 = __importDefault(require("@pnpm/fetch"));
|
|
7
|
+
const semver_1 = __importDefault(require("semver"));
|
|
8
|
+
const version_selector_type_1 = __importDefault(require("version-selector-type"));
|
|
9
|
+
async function resolveNodeVersion(rawVersionSelector) {
|
|
10
|
+
const { releaseDir, version } = parseNodeVersionSelector(rawVersionSelector);
|
|
11
|
+
const response = await (0, fetch_1.default)(`https://nodejs.org/download/${releaseDir}/index.json`);
|
|
12
|
+
const allVersions = (await response.json());
|
|
13
|
+
if (version === 'latest') {
|
|
14
|
+
return {
|
|
15
|
+
version: allVersions[0].version.substring(1),
|
|
16
|
+
releaseDir,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const { versions, versionSelector } = filterVersions(allVersions, version);
|
|
20
|
+
const pickedVersion = semver_1.default.maxSatisfying(versions.map(({ version }) => version), versionSelector, { includePrerelease: true, loose: true });
|
|
21
|
+
if (!pickedVersion)
|
|
22
|
+
return { version: null, releaseDir };
|
|
23
|
+
return {
|
|
24
|
+
version: pickedVersion.substring(1),
|
|
25
|
+
releaseDir,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.default = resolveNodeVersion;
|
|
29
|
+
function parseNodeVersionSelector(rawVersionSelector) {
|
|
30
|
+
if (rawVersionSelector.includes('/')) {
|
|
31
|
+
const [releaseDir, version] = rawVersionSelector.split('/');
|
|
32
|
+
return { releaseDir, version };
|
|
33
|
+
}
|
|
34
|
+
const prereleaseMatch = rawVersionSelector.match(/-(nightly|rc|test|v8-canary)/);
|
|
35
|
+
if (prereleaseMatch != null) {
|
|
36
|
+
return { releaseDir: prereleaseMatch[1], version: rawVersionSelector };
|
|
37
|
+
}
|
|
38
|
+
if (['nightly', 'rc', 'test', 'release', 'v8-canary'].includes(rawVersionSelector)) {
|
|
39
|
+
return { releaseDir: rawVersionSelector, version: 'latest' };
|
|
40
|
+
}
|
|
41
|
+
return { releaseDir: 'release', version: rawVersionSelector };
|
|
42
|
+
}
|
|
43
|
+
function filterVersions(versions, versionSelector) {
|
|
44
|
+
if (versionSelector === 'lts') {
|
|
45
|
+
return {
|
|
46
|
+
versions: versions.filter(({ lts }) => lts !== false),
|
|
47
|
+
versionSelector: '*',
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const vst = (0, version_selector_type_1.default)(versionSelector);
|
|
51
|
+
if ((vst === null || vst === void 0 ? void 0 : vst.type) === 'tag') {
|
|
52
|
+
const wantedLtsVersion = vst.normalized.toLowerCase();
|
|
53
|
+
return {
|
|
54
|
+
versions: versions.filter(({ lts }) => typeof lts === 'string' && lts.toLowerCase() === wantedLtsVersion),
|
|
55
|
+
versionSelector: '*',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return { versions, versionSelector };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=resolveNodeVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveNodeVersion.js","sourceRoot":"","sources":["../src/resolveNodeVersion.ts"],"names":[],"mappings":";;;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|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/plugin-commands-env",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "pnpm commands for managing Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"repository": "https://github.com/pnpm/pnpm/blob/master/packages/plugin-commands-env",
|
|
15
15
|
"keywords": [
|
|
16
|
+
"pnpm6",
|
|
16
17
|
"pnpm",
|
|
17
18
|
"env"
|
|
18
19
|
],
|
|
@@ -22,10 +23,10 @@
|
|
|
22
23
|
},
|
|
23
24
|
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/plugin-commands-env#readme",
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@pnpm/cli-utils": "0.6.
|
|
26
|
-
"@pnpm/config": "13.
|
|
26
|
+
"@pnpm/cli-utils": "0.6.28",
|
|
27
|
+
"@pnpm/config": "13.4.0",
|
|
27
28
|
"@pnpm/error": "2.0.0",
|
|
28
|
-
"@pnpm/fetch": "4.1.
|
|
29
|
+
"@pnpm/fetch": "4.1.2",
|
|
29
30
|
"@pnpm/package-store": "12.0.15",
|
|
30
31
|
"@pnpm/store-path": "^5.0.0",
|
|
31
32
|
"@pnpm/tarball-fetcher": "9.3.7",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"path-name": "^1.0.0"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
|
-
"lint": "eslint
|
|
51
|
+
"lint": "eslint src/**/*.ts test/**/*.ts",
|
|
51
52
|
"_test": "jest",
|
|
52
53
|
"test": "pnpm run compile && pnpm run _test",
|
|
53
54
|
"compile": "rimraf lib tsconfig.tsbuildinfo && tsc --build && pnpm run lint -- --fix"
|