@pnpm/plugin-commands-patching 0.0.0-20230605-20230605142810
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/LICENSE +22 -0
- package/README.md +13 -0
- package/lib/getPatchedDependency.d.ts +7 -0
- package/lib/getPatchedDependency.js +58 -0
- package/lib/getPatchedDependency.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +33 -0
- package/lib/index.js.map +1 -0
- package/lib/patch.d.ts +19 -0
- package/lib/patch.js +93 -0
- package/lib/patch.js.map +1 -0
- package/lib/patchCommit.d.ts +7 -0
- package/lib/patchCommit.js +129 -0
- package/lib/patchCommit.js.map +1 -0
- package/lib/patchRemove.d.ts +8 -0
- package/lib/patchRemove.js +74 -0
- package/lib/patchRemove.js.map +1 -0
- package/lib/writePackage.d.ts +5 -0
- package/lib/writePackage.js +25 -0
- package/lib/writePackage.js.map +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
|
|
4
|
+
Copyright (c) 2016-2023 Zoltan Kochan and other contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ParseWantedDependencyResult } from '@pnpm/parse-wanted-dependency';
|
|
2
|
+
import { type Config } from '@pnpm/config';
|
|
3
|
+
type GetPatchedDependencyOptions = {
|
|
4
|
+
lockfileDir: string;
|
|
5
|
+
} & Pick<Config, 'virtualStoreDir' | 'modulesDir'>;
|
|
6
|
+
export declare function getPatchedDependency(rawDependency: string, opts: GetPatchedDependencyOptions): Promise<ParseWantedDependencyResult>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
exports.getPatchedDependency = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const parse_wanted_dependency_1 = require("@pnpm/parse-wanted-dependency");
|
|
9
|
+
const enquirer_1 = require("enquirer");
|
|
10
|
+
const lockfile_file_1 = require("@pnpm/lockfile-file");
|
|
11
|
+
const lockfile_utils_1 = require("@pnpm/lockfile-utils");
|
|
12
|
+
const error_1 = require("@pnpm/error");
|
|
13
|
+
const constants_1 = require("@pnpm/constants");
|
|
14
|
+
const modules_yaml_1 = require("@pnpm/modules-yaml");
|
|
15
|
+
const realpath_missing_1 = __importDefault(require("realpath-missing"));
|
|
16
|
+
const semver_1 = __importDefault(require("semver"));
|
|
17
|
+
async function getPatchedDependency(rawDependency, opts) {
|
|
18
|
+
const dep = (0, parse_wanted_dependency_1.parseWantedDependency)(rawDependency);
|
|
19
|
+
const { versions, preferredVersions } = await getVersionsFromLockfile(dep, opts);
|
|
20
|
+
if (!preferredVersions.length) {
|
|
21
|
+
throw new error_1.PnpmError('PATCH_VERSION_NOT_FOUND', `Can not find ${rawDependency} in project ${opts.lockfileDir}, ${versions.length ? `you can specify currently installed version: ${versions.join(', ')}.` : `did you forget to install ${rawDependency}?`}`);
|
|
22
|
+
}
|
|
23
|
+
dep.alias = dep.alias ?? rawDependency;
|
|
24
|
+
if (preferredVersions.length > 1) {
|
|
25
|
+
const { version } = await (0, enquirer_1.prompt)({
|
|
26
|
+
type: 'select',
|
|
27
|
+
name: 'version',
|
|
28
|
+
message: 'Choose which version to patch',
|
|
29
|
+
choices: versions,
|
|
30
|
+
});
|
|
31
|
+
dep.pref = version;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
dep.pref = preferredVersions[0];
|
|
35
|
+
}
|
|
36
|
+
return dep;
|
|
37
|
+
}
|
|
38
|
+
exports.getPatchedDependency = getPatchedDependency;
|
|
39
|
+
async function getVersionsFromLockfile(dep, opts) {
|
|
40
|
+
const modulesDir = await (0, realpath_missing_1.default)(path_1.default.join(opts.lockfileDir, opts.modulesDir ?? 'node_modules'));
|
|
41
|
+
const modules = await (0, modules_yaml_1.readModulesManifest)(modulesDir);
|
|
42
|
+
const lockfile = (modules?.virtualStoreDir && await (0, lockfile_file_1.readCurrentLockfile)(modules.virtualStoreDir, {
|
|
43
|
+
ignoreIncompatible: true,
|
|
44
|
+
})) ?? null;
|
|
45
|
+
if (!lockfile) {
|
|
46
|
+
throw new error_1.PnpmError('PATCH_NO_LOCKFILE', `No ${constants_1.WANTED_LOCKFILE} found: Cannot patch without a lockfile`);
|
|
47
|
+
}
|
|
48
|
+
const pkgName = dep.alias && dep.pref ? dep.alias : (dep.pref ?? dep.alias);
|
|
49
|
+
const versions = Object.entries(lockfile.packages ?? {})
|
|
50
|
+
.map(([depPath, pkgSnapshot]) => (0, lockfile_utils_1.nameVerFromPkgSnapshot)(depPath, pkgSnapshot))
|
|
51
|
+
.filter(({ name }) => name === pkgName)
|
|
52
|
+
.map(({ version }) => version);
|
|
53
|
+
return {
|
|
54
|
+
versions,
|
|
55
|
+
preferredVersions: versions.filter(version => dep.alias && dep.pref ? semver_1.default.satisfies(version, dep.pref) : true),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=getPatchedDependency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPatchedDependency.js","sourceRoot":"","sources":["../src/getPatchedDependency.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,2EAAuG;AACvG,uCAAiC;AACjC,uDAAyD;AACzD,yDAA6D;AAC7D,uCAAuC;AACvC,+CAAiD;AACjD,qDAAwD;AACxD,wEAA8C;AAC9C,oDAA2B;AAOpB,KAAK,UAAU,oBAAoB,CAAE,aAAqB,EAAE,IAAiC;IAClG,MAAM,GAAG,GAAG,IAAA,+CAAqB,EAAC,aAAa,CAAC,CAAA;IAEhD,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,MAAM,uBAAuB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAEhF,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE;QAC7B,MAAM,IAAI,iBAAS,CACjB,yBAAyB,EACzB,gBAAgB,aAAa,eAAe,IAAI,CAAC,WAAW,KAAK,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,gDAAgD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,6BAA6B,aAAa,GAAG,EAAE,CAC5M,CAAA;KACF;IAED,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK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CAAC;SACrD,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,IAAA,uCAAsB,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;SAC7E,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC;SACtC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAA;IAEhC,OAAO;QACL,QAAQ;QACR,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;KAClH,CAAA;AACH,CAAC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.patchRemove = exports.patchCommit = exports.patch = void 0;
|
|
27
|
+
const patch = __importStar(require("./patch"));
|
|
28
|
+
exports.patch = patch;
|
|
29
|
+
const patchCommit = __importStar(require("./patchCommit"));
|
|
30
|
+
exports.patchCommit = patchCommit;
|
|
31
|
+
const patchRemove = __importStar(require("./patchRemove"));
|
|
32
|
+
exports.patchRemove = patchRemove;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAIvB,sBAAK;AAHd,2DAA4C;AAG5B,kCAAW;AAF3B,2DAA4C;AAEf,kCAAW"}
|
package/lib/patch.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Config } from '@pnpm/config';
|
|
2
|
+
import { type LogBase } from '@pnpm/logger';
|
|
3
|
+
import { type CreateStoreControllerOptions } from '@pnpm/store-connection-manager';
|
|
4
|
+
export declare function rcOptionsTypes(): Pick<any, never>;
|
|
5
|
+
export declare function cliOptionsTypes(): {
|
|
6
|
+
'edit-dir': StringConstructor;
|
|
7
|
+
'ignore-existing': BooleanConstructor;
|
|
8
|
+
};
|
|
9
|
+
export declare const shorthands: {
|
|
10
|
+
d: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const commandNames: string[];
|
|
13
|
+
export declare function help(): string;
|
|
14
|
+
export type PatchCommandOptions = Pick<Config, 'dir' | 'registries' | 'tag' | 'storeDir' | 'rootProjectManifest' | 'lockfileDir' | 'modulesDir' | 'virtualStoreDir'> & CreateStoreControllerOptions & {
|
|
15
|
+
editDir?: string;
|
|
16
|
+
reporter?: (logObj: LogBase) => void;
|
|
17
|
+
ignoreExisting?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function handler(opts: PatchCommandOptions, params: string[]): Promise<string>;
|
package/lib/patch.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
exports.handler = exports.help = exports.commandNames = exports.shorthands = exports.cliOptionsTypes = exports.rcOptionsTypes = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const patching_apply_patch_1 = require("@pnpm/patching.apply-patch");
|
|
10
|
+
const cli_utils_1 = require("@pnpm/cli-utils");
|
|
11
|
+
const config_1 = require("@pnpm/config");
|
|
12
|
+
const pick_1 = __importDefault(require("ramda/src/pick"));
|
|
13
|
+
const render_help_1 = __importDefault(require("render-help"));
|
|
14
|
+
const tempy_1 = __importDefault(require("tempy"));
|
|
15
|
+
const error_1 = require("@pnpm/error");
|
|
16
|
+
const writePackage_1 = require("./writePackage");
|
|
17
|
+
const getPatchedDependency_1 = require("./getPatchedDependency");
|
|
18
|
+
function rcOptionsTypes() {
|
|
19
|
+
return (0, pick_1.default)([], config_1.types);
|
|
20
|
+
}
|
|
21
|
+
exports.rcOptionsTypes = rcOptionsTypes;
|
|
22
|
+
function cliOptionsTypes() {
|
|
23
|
+
return { ...rcOptionsTypes(), 'edit-dir': String, 'ignore-existing': Boolean };
|
|
24
|
+
}
|
|
25
|
+
exports.cliOptionsTypes = cliOptionsTypes;
|
|
26
|
+
exports.shorthands = {
|
|
27
|
+
d: '--edit-dir',
|
|
28
|
+
};
|
|
29
|
+
exports.commandNames = ['patch'];
|
|
30
|
+
function help() {
|
|
31
|
+
return (0, render_help_1.default)({
|
|
32
|
+
description: 'Prepare a package for patching',
|
|
33
|
+
descriptionLists: [{
|
|
34
|
+
title: 'Options',
|
|
35
|
+
list: [
|
|
36
|
+
{
|
|
37
|
+
description: 'The package that needs to be modified will be extracted to this directory',
|
|
38
|
+
name: '--edit-dir',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
description: 'Ignore existing patch files when patching',
|
|
42
|
+
name: '--ignore-existing',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
}],
|
|
46
|
+
url: (0, cli_utils_1.docsUrl)('patch'),
|
|
47
|
+
usages: ['pnpm patch <pkg name>@<version>'],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.help = help;
|
|
51
|
+
async function handler(opts, params) {
|
|
52
|
+
if (opts.editDir && fs_1.default.existsSync(opts.editDir) && fs_1.default.readdirSync(opts.editDir).length > 0) {
|
|
53
|
+
throw new error_1.PnpmError('PATCH_EDIT_DIR_EXISTS', `The target directory already exists: '${opts.editDir}'`);
|
|
54
|
+
}
|
|
55
|
+
if (!params[0]) {
|
|
56
|
+
throw new error_1.PnpmError('MISSING_PACKAGE_NAME', '`pnpm patch` requires the package name');
|
|
57
|
+
}
|
|
58
|
+
const editDir = opts.editDir ?? tempy_1.default.directory();
|
|
59
|
+
const lockfileDir = opts.lockfileDir ?? opts.dir ?? process.cwd();
|
|
60
|
+
const patchedDep = await (0, getPatchedDependency_1.getPatchedDependency)(params[0], {
|
|
61
|
+
lockfileDir,
|
|
62
|
+
modulesDir: opts.modulesDir,
|
|
63
|
+
virtualStoreDir: opts.virtualStoreDir,
|
|
64
|
+
});
|
|
65
|
+
await (0, writePackage_1.writePackage)(patchedDep, editDir, opts);
|
|
66
|
+
if (!opts.ignoreExisting && opts.rootProjectManifest?.pnpm?.patchedDependencies) {
|
|
67
|
+
tryPatchWithExistingPatchFile({
|
|
68
|
+
patchedDep,
|
|
69
|
+
patchedDir: editDir,
|
|
70
|
+
patchedDependencies: opts.rootProjectManifest.pnpm.patchedDependencies,
|
|
71
|
+
lockfileDir,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return `You can now edit the following folder: ${editDir}
|
|
75
|
+
|
|
76
|
+
Once you're done with your changes, run "pnpm patch-commit ${editDir}"`;
|
|
77
|
+
}
|
|
78
|
+
exports.handler = handler;
|
|
79
|
+
function tryPatchWithExistingPatchFile({ patchedDep, patchedDir, patchedDependencies, lockfileDir, }) {
|
|
80
|
+
if (!patchedDep.alias || !patchedDep.pref) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const existingPatchFile = patchedDependencies[`${patchedDep.alias}@${patchedDep.pref}`];
|
|
84
|
+
if (!existingPatchFile) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const existingPatchFilePath = path_1.default.resolve(lockfileDir, existingPatchFile);
|
|
88
|
+
if (!fs_1.default.existsSync(existingPatchFilePath)) {
|
|
89
|
+
throw new error_1.PnpmError('PATCH_FILE_NOT_FOUND', `Unable to find patch file ${existingPatchFilePath}`);
|
|
90
|
+
}
|
|
91
|
+
(0, patching_apply_patch_1.applyPatchToDir)({ patchedDir, patchFilePath: existingPatchFilePath });
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=patch.js.map
|
package/lib/patch.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,qEAA4D;AAC5D,+CAAyC;AACzC,yCAA6D;AAK7D,0DAAiC;AACjC,8DAAoC;AACpC,kDAAyB;AACzB,uCAAuC;AAEvC,iDAA6C;AAC7C,iEAA6D;AAE7D,SAAgB,cAAc;IAC5B,OAAO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AAC,sBAAsB,EAAE,6BAA6B,qBAAqB,EAAE,CAAC,CAAA;KAClG;IACD,IAAA,sCAAe,EAAC,EAAE,UAAU,EAAE,aAAa,EAAE,qBAAqB,EAAE,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Config } from '@pnpm/config';
|
|
2
|
+
import { install } from '@pnpm/plugin-commands-installation';
|
|
3
|
+
export declare const rcOptionsTypes: typeof cliOptionsTypes;
|
|
4
|
+
export declare function cliOptionsTypes(): Pick<any, never>;
|
|
5
|
+
export declare const commandNames: string[];
|
|
6
|
+
export declare function help(): string;
|
|
7
|
+
export declare function handler(opts: install.InstallCommandOptions & Pick<Config, 'patchesDir' | 'rootProjectManifest'>, params: string[]): Promise<void>;
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
exports.handler = exports.help = exports.commandNames = exports.cliOptionsTypes = exports.rcOptionsTypes = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const cli_utils_1 = require("@pnpm/cli-utils");
|
|
10
|
+
const config_1 = require("@pnpm/config");
|
|
11
|
+
const plugin_commands_installation_1 = require("@pnpm/plugin-commands-installation");
|
|
12
|
+
const read_package_json_1 = require("@pnpm/read-package-json");
|
|
13
|
+
const read_project_manifest_1 = require("@pnpm/read-project-manifest");
|
|
14
|
+
const normalize_path_1 = __importDefault(require("normalize-path"));
|
|
15
|
+
const pick_1 = __importDefault(require("ramda/src/pick"));
|
|
16
|
+
const safe_execa_1 = __importDefault(require("safe-execa"));
|
|
17
|
+
const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
|
|
18
|
+
const render_help_1 = __importDefault(require("render-help"));
|
|
19
|
+
const tempy_1 = __importDefault(require("tempy"));
|
|
20
|
+
const writePackage_1 = require("./writePackage");
|
|
21
|
+
const parse_wanted_dependency_1 = require("@pnpm/parse-wanted-dependency");
|
|
22
|
+
exports.rcOptionsTypes = cliOptionsTypes;
|
|
23
|
+
function cliOptionsTypes() {
|
|
24
|
+
return (0, pick_1.default)(['patches-dir'], config_1.types);
|
|
25
|
+
}
|
|
26
|
+
exports.cliOptionsTypes = cliOptionsTypes;
|
|
27
|
+
exports.commandNames = ['patch-commit'];
|
|
28
|
+
function help() {
|
|
29
|
+
return (0, render_help_1.default)({
|
|
30
|
+
description: 'Generate a patch out of a directory',
|
|
31
|
+
descriptionLists: [{
|
|
32
|
+
title: 'Options',
|
|
33
|
+
list: [
|
|
34
|
+
{
|
|
35
|
+
description: 'The generated patch file will be saved to this directory',
|
|
36
|
+
name: '--patches-dir',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}],
|
|
40
|
+
url: (0, cli_utils_1.docsUrl)('patch-commit'),
|
|
41
|
+
usages: ['pnpm patch-commit <patchDir>'],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.help = help;
|
|
45
|
+
async function handler(opts, params) {
|
|
46
|
+
const userDir = params[0];
|
|
47
|
+
const lockfileDir = opts.lockfileDir ?? opts.dir ?? process.cwd();
|
|
48
|
+
const patchesDirName = (0, normalize_path_1.default)(path_1.default.normalize(opts.patchesDir ?? 'patches'));
|
|
49
|
+
const patchesDir = path_1.default.join(lockfileDir, patchesDirName);
|
|
50
|
+
await fs_1.default.promises.mkdir(patchesDir, { recursive: true });
|
|
51
|
+
const patchedPkgManifest = await (0, read_package_json_1.readPackageJsonFromDir)(userDir);
|
|
52
|
+
const pkgNameAndVersion = `${patchedPkgManifest.name}@${patchedPkgManifest.version}`;
|
|
53
|
+
const srcDir = tempy_1.default.directory();
|
|
54
|
+
await (0, writePackage_1.writePackage)((0, parse_wanted_dependency_1.parseWantedDependency)(pkgNameAndVersion), srcDir, opts);
|
|
55
|
+
const patchContent = await diffFolders(srcDir, userDir);
|
|
56
|
+
const patchFileName = pkgNameAndVersion.replace('/', '__');
|
|
57
|
+
await fs_1.default.promises.writeFile(path_1.default.join(patchesDir, `${patchFileName}.patch`), patchContent, 'utf8');
|
|
58
|
+
const { writeProjectManifest, manifest } = await (0, read_project_manifest_1.tryReadProjectManifest)(lockfileDir);
|
|
59
|
+
const rootProjectManifest = opts.rootProjectManifest ?? manifest ?? {};
|
|
60
|
+
if (!rootProjectManifest.pnpm) {
|
|
61
|
+
rootProjectManifest.pnpm = {
|
|
62
|
+
patchedDependencies: {},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else if (!rootProjectManifest.pnpm.patchedDependencies) {
|
|
66
|
+
rootProjectManifest.pnpm.patchedDependencies = {};
|
|
67
|
+
}
|
|
68
|
+
rootProjectManifest.pnpm.patchedDependencies[pkgNameAndVersion] = `${patchesDirName}/${patchFileName}.patch`;
|
|
69
|
+
await writeProjectManifest(rootProjectManifest);
|
|
70
|
+
if (opts?.selectedProjectsGraph?.[lockfileDir]) {
|
|
71
|
+
opts.selectedProjectsGraph[lockfileDir].package.manifest = rootProjectManifest;
|
|
72
|
+
}
|
|
73
|
+
if (opts?.allProjectsGraph?.[lockfileDir].package.manifest) {
|
|
74
|
+
opts.allProjectsGraph[lockfileDir].package.manifest = rootProjectManifest;
|
|
75
|
+
}
|
|
76
|
+
return plugin_commands_installation_1.install.handler({
|
|
77
|
+
...opts,
|
|
78
|
+
rawLocalConfig: {
|
|
79
|
+
...opts.rawLocalConfig,
|
|
80
|
+
'frozen-lockfile': false,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.handler = handler;
|
|
85
|
+
async function diffFolders(folderA, folderB) {
|
|
86
|
+
const folderAN = folderA.replace(/\\/g, '/');
|
|
87
|
+
const folderBN = folderB.replace(/\\/g, '/');
|
|
88
|
+
let stdout;
|
|
89
|
+
let stderr;
|
|
90
|
+
try {
|
|
91
|
+
const result = await (0, safe_execa_1.default)('git', ['-c', 'core.safecrlf=false', 'diff', '--src-prefix=a/', '--dst-prefix=b/', '--ignore-cr-at-eol', '--irreversible-delete', '--full-index', '--no-index', '--text', folderAN, folderBN], {
|
|
92
|
+
cwd: process.cwd(),
|
|
93
|
+
env: {
|
|
94
|
+
...process.env,
|
|
95
|
+
// #region Predictable output
|
|
96
|
+
// These variables aim to ignore the global git config so we get predictable output
|
|
97
|
+
// https://git-scm.com/docs/git#Documentation/git.txt-codeGITCONFIGNOSYSTEMcode
|
|
98
|
+
GIT_CONFIG_NOSYSTEM: '1',
|
|
99
|
+
HOME: '',
|
|
100
|
+
XDG_CONFIG_HOME: '',
|
|
101
|
+
USERPROFILE: '',
|
|
102
|
+
// #endregion
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
stdout = result.stdout;
|
|
106
|
+
stderr = result.stderr;
|
|
107
|
+
}
|
|
108
|
+
catch (err) { // eslint-disable-line
|
|
109
|
+
stdout = err.stdout;
|
|
110
|
+
stderr = err.stderr;
|
|
111
|
+
}
|
|
112
|
+
// we cannot rely on exit code, because --no-index implies --exit-code
|
|
113
|
+
// i.e. git diff will exit with 1 if there were differences
|
|
114
|
+
if (stderr.length > 0)
|
|
115
|
+
throw new Error(`Unable to diff directories. Make sure you have a recent version of 'git' available in PATH.\nThe following error was reported by 'git':\n${stderr}`);
|
|
116
|
+
return stdout
|
|
117
|
+
.replace(new RegExp(`(a|b)(${(0, escape_string_regexp_1.default)(`/${removeTrailingAndLeadingSlash(folderAN)}/`)})`, 'g'), '$1/')
|
|
118
|
+
.replace(new RegExp(`(a|b)${(0, escape_string_regexp_1.default)(`/${removeTrailingAndLeadingSlash(folderBN)}/`)}`, 'g'), '$1/')
|
|
119
|
+
.replace(new RegExp((0, escape_string_regexp_1.default)(`${folderAN}/`), 'g'), '')
|
|
120
|
+
.replace(new RegExp((0, escape_string_regexp_1.default)(`${folderBN}/`), 'g'), '')
|
|
121
|
+
.replace(/\n\$/, '');
|
|
122
|
+
}
|
|
123
|
+
function removeTrailingAndLeadingSlash(p) {
|
|
124
|
+
if (p.startsWith('/') || p.endsWith('/')) {
|
|
125
|
+
return p.replace(/^\/|\/$/g, '');
|
|
126
|
+
}
|
|
127
|
+
return p;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=patchCommit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patchCommit.js","sourceRoot":"","sources":["../src/patchCommit.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,+CAAyC;AACzC,yCAA6D;AAC7D,qFAA4D;AAC5D,+DAAgE;AAChE,uEAAoE;AACpE,oEAA0C;AAC1C,0DAAiC;AACjC,4DAA8B;AAC9B,gFAAqD;AACrD,8DAAoC;AACpC,kDAAyB;AACzB,iDAA6C;AAC7C,2EAAqE;AAExD,QAAA,cAAc,GAAG,eAAe,CAAA;AAE7C,SAAgB,eAAe;IAC7B,OAAO,IAAA,cAAI,EAAC,CAAC,aAAa,CAAC,EAAE,cAAQ,CAAC,CAAA;AACxC,CAAC;AAFD,0CAEC;AAEY,QAAA,YAAY,GAAG,CAAC,cAAc,CAAC,CAAA;AAE5C,SAAgB,IAAI;IAClB,OAAO,IAAA,qBAAU,EAAC;QAChB,WAAW,EAAE,qCAAqC;QAClD,gBAAgB,EAAE,CAAC;gBACjB,KAAK,EAAE,SAAS;gBAChB,IAAI,EAAE;oBACJ;wBACE,WAAW,EAAE,0DAA0D;wBACvE,IAAI,EAAE,eAAe;qBACtB;iBACF;aACF,CAAC;QACF,GAAG,EAAE,IAAA,mBAAO,EAAC,cAAc,CAAC;QAC5B,MAAM,EAAE,CAAC,8BAA8B,CAAC;KACzC,CAAC,CAAA;AACJ,CAAC;AAfD,oBAeC;AAEM,KAAK,UAAU,OAAO,CAAE,IAAwF,EAAE,MAAgB;IACvI,MAAM,OAAO,GAAG,MAA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,EAAE,EAAE,CAAC;SAChE,OAAO,CAAC,IAAI,MAAM,CAAC,IAAA,8BAAkB,EAAC,GAAG,QAAQ,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;SAChE,OAAO,CAAC,iCAAiC,EAAE,EAAE,CAAC,CAAA;AACnD,CAAC;AAED,SAAS,6BAA6B,CAAE,CAAS;IAC/C,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACxC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;KACjC;IACD,OAAO,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { install } from '@pnpm/plugin-commands-installation';
|
|
2
|
+
import { type Config } from '@pnpm/config';
|
|
3
|
+
export declare function rcOptionsTypes(): Pick<any, never>;
|
|
4
|
+
export declare function cliOptionsTypes(): {};
|
|
5
|
+
export declare const commandNames: string[];
|
|
6
|
+
export declare function help(): string;
|
|
7
|
+
export type PatchRemoveCommandOptions = install.InstallCommandOptions & Pick<Config, 'dir' | 'lockfileDir' | 'patchesDir' | 'rootProjectManifest'>;
|
|
8
|
+
export declare function handler(opts: PatchRemoveCommandOptions, params: string[]): Promise<void>;
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
exports.handler = exports.help = exports.commandNames = exports.cliOptionsTypes = exports.rcOptionsTypes = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const cli_utils_1 = require("@pnpm/cli-utils");
|
|
10
|
+
const plugin_commands_installation_1 = require("@pnpm/plugin-commands-installation");
|
|
11
|
+
const config_1 = require("@pnpm/config");
|
|
12
|
+
const read_project_manifest_1 = require("@pnpm/read-project-manifest");
|
|
13
|
+
const error_1 = require("@pnpm/error");
|
|
14
|
+
const render_help_1 = __importDefault(require("render-help"));
|
|
15
|
+
const enquirer_1 = require("enquirer");
|
|
16
|
+
const pick_1 = __importDefault(require("ramda/src/pick"));
|
|
17
|
+
function rcOptionsTypes() {
|
|
18
|
+
return (0, pick_1.default)([], config_1.types);
|
|
19
|
+
}
|
|
20
|
+
exports.rcOptionsTypes = rcOptionsTypes;
|
|
21
|
+
function cliOptionsTypes() {
|
|
22
|
+
return { ...rcOptionsTypes() };
|
|
23
|
+
}
|
|
24
|
+
exports.cliOptionsTypes = cliOptionsTypes;
|
|
25
|
+
exports.commandNames = ['patch-remove'];
|
|
26
|
+
function help() {
|
|
27
|
+
return (0, render_help_1.default)({
|
|
28
|
+
description: 'Remove existing patch files',
|
|
29
|
+
url: (0, cli_utils_1.docsUrl)('patch-remove'),
|
|
30
|
+
usages: ['pnpm patch-remove [pkg...]'],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.help = help;
|
|
34
|
+
async function handler(opts, params) {
|
|
35
|
+
let patchesToRemove = params;
|
|
36
|
+
const lockfileDir = opts.lockfileDir ?? opts.dir ?? process.cwd();
|
|
37
|
+
const { writeProjectManifest, manifest } = await (0, read_project_manifest_1.tryReadProjectManifest)(lockfileDir);
|
|
38
|
+
const rootProjectManifest = opts.rootProjectManifest ?? manifest ?? {};
|
|
39
|
+
const patchedDependencies = rootProjectManifest.pnpm?.patchedDependencies ?? {};
|
|
40
|
+
if (!params.length) {
|
|
41
|
+
const allPatches = Object.keys(patchedDependencies);
|
|
42
|
+
if (allPatches.length) {
|
|
43
|
+
({ patches: patchesToRemove } = await (0, enquirer_1.prompt)({
|
|
44
|
+
type: 'multiselect',
|
|
45
|
+
name: 'patches',
|
|
46
|
+
message: 'Select the patch to be removed',
|
|
47
|
+
choices: allPatches,
|
|
48
|
+
validate(value) {
|
|
49
|
+
return value.length === 0 ? 'Select at least one option.' : true;
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!patchesToRemove.length) {
|
|
55
|
+
throw new error_1.PnpmError('NO_PATCHES_TO_REMOVE', 'There are no patches that need to be removed');
|
|
56
|
+
}
|
|
57
|
+
await Promise.all(patchesToRemove.map(async (patch) => {
|
|
58
|
+
if (Object.prototype.hasOwnProperty.call(patchedDependencies, patch)) {
|
|
59
|
+
const patchFile = path_1.default.join(lockfileDir, patchedDependencies[patch]);
|
|
60
|
+
await promises_1.default.rm(patchFile, { force: true });
|
|
61
|
+
delete rootProjectManifest.pnpm.patchedDependencies[patch];
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
await writeProjectManifest(rootProjectManifest);
|
|
65
|
+
if (opts?.selectedProjectsGraph?.[lockfileDir]) {
|
|
66
|
+
opts.selectedProjectsGraph[lockfileDir].package.manifest = rootProjectManifest;
|
|
67
|
+
}
|
|
68
|
+
if (opts?.allProjectsGraph?.[lockfileDir].package.manifest) {
|
|
69
|
+
opts.allProjectsGraph[lockfileDir].package.manifest = rootProjectManifest;
|
|
70
|
+
}
|
|
71
|
+
return plugin_commands_installation_1.install.handler(opts);
|
|
72
|
+
}
|
|
73
|
+
exports.handler = handler;
|
|
74
|
+
//# sourceMappingURL=patchRemove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patchRemove.js","sourceRoot":"","sources":["../src/patchRemove.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,2DAA4B;AAC5B,+CAAyC;AACzC,qFAA4D;AAC5D,yCAA6D;AAC7D,uEAAoE;AACpE,uCAAuC;AACvC,8DAAoC;AACpC,uCAAiC;AACjC,0DAAiC;AAEjC,SAAgB,cAAc;IAC5B,OAAO,IAAA,cAAI,EAAC,EAAE,EAAE,cAAQ,CAAC,CAAA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
import { type CreateStoreControllerOptions } from '@pnpm/store-connection-manager';
|
|
3
|
+
import type { ParseWantedDependencyResult } from '@pnpm/parse-wanted-dependency';
|
|
4
|
+
export type WritePackageOptions = CreateStoreControllerOptions & Pick<Config, 'registries'>;
|
|
5
|
+
export declare function writePackage(dep: ParseWantedDependencyResult, dest: string, opts: WritePackageOptions): Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writePackage = void 0;
|
|
4
|
+
const store_connection_manager_1 = require("@pnpm/store-connection-manager");
|
|
5
|
+
const pick_registry_for_package_1 = require("@pnpm/pick-registry-for-package");
|
|
6
|
+
async function writePackage(dep, dest, opts) {
|
|
7
|
+
const store = await (0, store_connection_manager_1.createOrConnectStoreController)({
|
|
8
|
+
...opts,
|
|
9
|
+
packageImportMethod: 'clone-or-copy',
|
|
10
|
+
});
|
|
11
|
+
const pkgResponse = await store.ctrl.requestPackage(dep, {
|
|
12
|
+
downloadPriority: 1,
|
|
13
|
+
lockfileDir: opts.dir,
|
|
14
|
+
preferredVersions: {},
|
|
15
|
+
projectDir: opts.dir,
|
|
16
|
+
registry: (dep.alias && (0, pick_registry_for_package_1.pickRegistryForPackage)(opts.registries, dep.alias)) ?? opts.registries.default,
|
|
17
|
+
});
|
|
18
|
+
const filesResponse = await pkgResponse.files();
|
|
19
|
+
await store.ctrl.importPackage(dest, {
|
|
20
|
+
filesResponse,
|
|
21
|
+
force: true,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.writePackage = writePackage;
|
|
25
|
+
//# sourceMappingURL=writePackage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writePackage.js","sourceRoot":"","sources":["../src/writePackage.ts"],"names":[],"mappings":";;;AACA,6EAGuC;AACvC,+EAAwE;AAKjE,KAAK,UAAU,YAAY,CAAE,GAAgC,EAAE,IAAY,EAAE,IAAyB;IAC3G,MAAM,KAAK,GAAG,MAAM,IAAA,yDAA8B,EAAC;QACjD,GAAG,IAAI;QACP,mBAAmB,EAAE,eAAe;KACrC,CAAC,CAAA;IACF,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE;QACvD,gBAAgB,EAAE,CAAC;QACnB,WAAW,EAAE,IAAI,CAAC,GAAG;QACrB,iBAAiB,EAAE,EAAE;QACrB,UAAU,EAAE,IAAI,CAAC,GAAG;QACpB,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI,IAAA,kDAAsB,EAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO;KACvG,CAAC,CAAA;IACF,MAAM,aAAa,GAAG,MAAM,WAAW,CAAC,KAAM,EAAE,CAAA;IAChD,MAAM,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;QACnC,aAAa;QACb,KAAK,EAAE,IAAI;KACZ,CAAC,CAAA;AACJ,CAAC;AAjBD,oCAiBC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/plugin-commands-patching",
|
|
3
|
+
"version": "0.0.0-20230605-20230605142810",
|
|
4
|
+
"description": "Commands for creating patches",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"!*.map"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=16.14"
|
|
13
|
+
},
|
|
14
|
+
"repository": "https://github.com/pnpm/pnpm/blob/main/patching/plugin-commands-patching",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"pnpm8",
|
|
17
|
+
"pnpm",
|
|
18
|
+
"scripts"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/pnpm/pnpm/blob/main/patching/plugin-commands-patching#readme",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@pnpm/registry-mock": "3.8.0",
|
|
27
|
+
"@types/normalize-path": "^3.0.0",
|
|
28
|
+
"@types/ramda": "0.28.20",
|
|
29
|
+
"@types/semver": "7.3.13",
|
|
30
|
+
"write-yaml-file": "^5.0.0",
|
|
31
|
+
"@pnpm/filter-workspace-packages": "0.0.0-20230605-20230605142810",
|
|
32
|
+
"@pnpm/prepare": "0.0.0-20230605-20230605142810",
|
|
33
|
+
"@pnpm/plugin-commands-patching": "0.0.0-20230605-20230605142810",
|
|
34
|
+
"@pnpm/test-fixtures": "0.0.0-20230605-20230605142810"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"enquirer": "^2.3.6",
|
|
38
|
+
"escape-string-regexp": "^4.0.0",
|
|
39
|
+
"normalize-path": "^3.0.0",
|
|
40
|
+
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
41
|
+
"realpath-missing": "^1.1.0",
|
|
42
|
+
"render-help": "^1.0.3",
|
|
43
|
+
"safe-execa": "^0.1.3",
|
|
44
|
+
"semver": "^7.5.1",
|
|
45
|
+
"tempy": "^1.0.1",
|
|
46
|
+
"@pnpm/cli-utils": "0.0.0-20230605-20230605142810",
|
|
47
|
+
"@pnpm/config": "0.0.0-20230605-20230605142810",
|
|
48
|
+
"@pnpm/constants": "0.0.0-20230605-20230605142810",
|
|
49
|
+
"@pnpm/error": "0.0.0-20230605-20230605142810",
|
|
50
|
+
"@pnpm/lockfile-file": "0.0.0-20230605-20230605142810",
|
|
51
|
+
"@pnpm/lockfile-utils": "8.0.1",
|
|
52
|
+
"@pnpm/patching.apply-patch": "0.0.0-20230605-20230605142810",
|
|
53
|
+
"@pnpm/plugin-commands-installation": "0.0.0-20230605-20230605142810",
|
|
54
|
+
"@pnpm/pick-registry-for-package": "5.0.1",
|
|
55
|
+
"@pnpm/modules-yaml": "12.1.1",
|
|
56
|
+
"@pnpm/read-package-json": "0.0.0-20230605-20230605142810",
|
|
57
|
+
"@pnpm/store-connection-manager": "0.0.0-20230605-20230605142810",
|
|
58
|
+
"@pnpm/read-project-manifest": "0.0.0-20230605-20230605142810",
|
|
59
|
+
"@pnpm/parse-wanted-dependency": "5.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@pnpm/logger": "^5.0.0"
|
|
63
|
+
},
|
|
64
|
+
"funding": "https://opencollective.com/pnpm",
|
|
65
|
+
"exports": {
|
|
66
|
+
".": "./lib/index.js"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
70
|
+
"registry-mock": "registry-mock",
|
|
71
|
+
"test:jest": "jest",
|
|
72
|
+
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
|
|
73
|
+
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7772 pnpm run test:e2e",
|
|
74
|
+
"test": "pnpm run compile && pnpm run _test",
|
|
75
|
+
"compile": "tsc --build && pnpm run lint --fix"
|
|
76
|
+
}
|
|
77
|
+
}
|