pastoralist 0.0.4 → 0.0.8

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import "./chunk-K3VYYVO7.js";
3
- import "./chunk-YUCCQ46M.js";
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ var program_1 = require("./program");
5
+ program_1.program;
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import { Options } from "./types";
4
+ export declare function action(options?: Options): Promise<void>;
5
+ export { program };
package/dist/program.js CHANGED
@@ -1,10 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- action,
4
- program_default
5
- } from "./chunk-K3VYYVO7.js";
6
- import "./chunk-YUCCQ46M.js";
7
- export {
8
- action,
9
- program_default as default
10
- };
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.program = exports.action = void 0;
5
+ var tslib_1 = require("tslib");
6
+ var commander_1 = require("commander");
7
+ Object.defineProperty(exports, "program", { enumerable: true, get: function () { return commander_1.program; } });
8
+ var scripts_1 = require("./scripts");
9
+ var version = "VERSION";
10
+ function action(options) {
11
+ if (options === void 0) { options = {}; }
12
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
13
+ return tslib_1.__generator(this, function (_a) {
14
+ try {
15
+ if (options === null || options === void 0 ? void 0 : options.isTestingCLI)
16
+ console.info({ options: options });
17
+ (0, scripts_1.update)(options);
18
+ }
19
+ catch (err) {
20
+ console.error(err);
21
+ }
22
+ return [2];
23
+ });
24
+ });
25
+ }
26
+ exports.action = action;
27
+ commander_1.program
28
+ .version(version)
29
+ .description("Pastoralist, a utility CLI to manage your dependency overrides")
30
+ .option("-t, --isTestingCLI", "enables CLI testing, no scripts are run")
31
+ .action(action)
32
+ .parse(process.argv);
@@ -0,0 +1,6 @@
1
+ import { Appendix, Options, OverridesType, PastoralistJSON, ResolveResolutionOptions, UpdateAppendixOptions, UpdatePackageJSONOptions } from "./types";
2
+ export declare function resolveJSON(path: string, debug?: boolean): PastoralistJSON | void;
3
+ export declare function resolveResolutions({ config: { overrides: npmOverrides, pnpm: { overrides: pnpmOverrides }, resolutions, }, options: { debug }, }: ResolveResolutionOptions): OverridesType;
4
+ export declare function updateAppendix({ dependencies, resolutions, name, version, appendix, }: UpdateAppendixOptions): Appendix;
5
+ export declare function updatePackageJSON({ appendix, path, config, resolutions, }: UpdatePackageJSONOptions): void;
6
+ export declare function update(options: Options): Appendix | void;
package/dist/scripts.js CHANGED
@@ -1,15 +1,111 @@
1
- #!/usr/bin/env node
2
- import {
3
- resolveJSON,
4
- resolveResolutions,
5
- update,
6
- updateAppendix,
7
- updatePackageJSON
8
- } from "./chunk-YUCCQ46M.js";
9
- export {
10
- resolveJSON,
11
- resolveResolutions,
12
- update,
13
- updateAppendix,
14
- updatePackageJSON
15
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.update = exports.updatePackageJSON = exports.updateAppendix = exports.resolveResolutions = exports.resolveJSON = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var path_1 = require("path");
6
+ var fs_1 = require("fs");
7
+ var fast_glob_1 = require("fast-glob");
8
+ var compare_versions_1 = require("compare-versions");
9
+ function resolveJSON(path, debug) {
10
+ if (debug === void 0) { debug = false; }
11
+ try {
12
+ var json = JSON.parse((0, fs_1.readFileSync)(path, "utf8"));
13
+ return json;
14
+ }
15
+ catch (err) {
16
+ if (debug)
17
+ console.log("\uD83D\uDC11 \uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF3E Pastoralist found invalid JSON at:\n".concat(path));
18
+ return;
19
+ }
20
+ }
21
+ exports.resolveJSON = resolveJSON;
22
+ function resolveResolutions(_a) {
23
+ var _b = _a.config, _c = _b === void 0 ? {} : _b, _d = _c.overrides, npmOverrides = _d === void 0 ? {} : _d, _e = _c.pnpm, _f = _e === void 0 ? {} : _e, _g = _f.overrides, pnpmOverrides = _g === void 0 ? {} : _g, _h = _c.resolutions, resolutions = _h === void 0 ? {} : _h, _j = _a.options, _k = _j === void 0 ? {} : _j, _l = _k.debug, debug = _l === void 0 ? false : _l;
24
+ var overridesItems = Object.keys(npmOverrides);
25
+ var hasOverrides = overridesItems.length > 0;
26
+ var hasComplexOverrides = hasOverrides &&
27
+ overridesItems.some(function (name) { return typeof npmOverrides[name] === "object"; });
28
+ if (hasComplexOverrides && debug) {
29
+ console.warn("🐑 👩🏽‍🌾 Pastoralist only supports simple overrides! Pastoralist is bypassing the specified complex overrides. 👌");
30
+ }
31
+ var overrides = hasOverrides
32
+ ? overridesItems
33
+ .filter(function (name) { return typeof npmOverrides[name] === "string"; })
34
+ .reduce(function (acc, name) {
35
+ var _a;
36
+ return (tslib_1.__assign(tslib_1.__assign({}, acc), (_a = {}, _a[name] = npmOverrides[name], _a)));
37
+ }, {})
38
+ : {};
39
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, overrides), pnpmOverrides), resolutions);
40
+ }
41
+ exports.resolveResolutions = resolveResolutions;
42
+ function updateAppendix(_a) {
43
+ var dependencies = _a.dependencies, resolutions = _a.resolutions, name = _a.name, version = _a.version, _b = _a.appendix, appendix = _b === void 0 ? {} : _b;
44
+ var dependencyList = Object.keys(dependencies);
45
+ var resolutionsList = Object.keys(resolutions);
46
+ return resolutionsList.reduce(function (acc, resolution) {
47
+ var _a, _b;
48
+ if (dependencyList.includes(resolution)) {
49
+ var hasResolutionOverride = (0, compare_versions_1.compare)(resolutions[resolution], dependencies[resolution], ">");
50
+ if (hasResolutionOverride) {
51
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, appendix), acc), (_a = {}, _a["".concat(resolution, "@").concat(resolutions[resolution])] = tslib_1.__assign(tslib_1.__assign({}, appendix[resolution]), (_b = {}, _b[name] = version, _b)), _a));
52
+ }
53
+ }
54
+ return acc || {};
55
+ }, {});
56
+ }
57
+ exports.updateAppendix = updateAppendix;
58
+ function updatePackageJSON(_a) {
59
+ var _b;
60
+ var appendix = _a.appendix, path = _a.path, config = _a.config, resolutions = _a.resolutions;
61
+ var jsonPath = (0, path_1.resolve)(path);
62
+ var pastoralist = (config === null || config === void 0 ? void 0 : config.pastoralist)
63
+ ? tslib_1.__assign(tslib_1.__assign({}, config.pastoralist), { appendix: appendix }) : { appendix: appendix };
64
+ var json = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, config), { pastoralist: pastoralist }), ((config === null || config === void 0 ? void 0 : config.resolutions)
65
+ ? { resolutions: resolutions }
66
+ : (config === null || config === void 0 ? void 0 : config.overrides)
67
+ ? { overrides: resolutions }
68
+ : ((_b = config === null || config === void 0 ? void 0 : config.pnpm) === null || _b === void 0 ? void 0 : _b.overrides)
69
+ ? { pnpm: tslib_1.__assign(tslib_1.__assign({}, config.pnpm), { overrides: resolutions }) }
70
+ : {}));
71
+ (0, fs_1.writeFile)(jsonPath, JSON.stringify(json, null, 2), function (err) {
72
+ return console.log("\uD83D\uDC11 \uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF3E Pastoralist had an issue updating overrides or resolutions in the package.json!".concat(err ? ", ".concat(err) : ""));
73
+ });
74
+ }
75
+ exports.updatePackageJSON = updatePackageJSON;
76
+ function update(options) {
77
+ var _a = options.debug, debug = _a === void 0 ? false : _a, _b = options.depPaths, depPaths = _b === void 0 ? ["node_modules/**/package.json"] : _b, _c = options.path, path = _c === void 0 ? "package.json" : _c, _d = options.isTesting, isTesting = _d === void 0 ? false : _d;
78
+ var config = resolveJSON(path, debug);
79
+ if (!config)
80
+ return;
81
+ var resolutions = resolveResolutions({ options: options, config: config });
82
+ var resolutionsList = Object.keys(resolutions);
83
+ var nodeModulePackageJSONs = (0, fast_glob_1.sync)(depPaths);
84
+ var appendix = nodeModulePackageJSONs.reduce(function (acc, packageJSON) {
85
+ var currentPackageJSON = resolveJSON(packageJSON, debug);
86
+ if (!currentPackageJSON)
87
+ return acc;
88
+ var _a = currentPackageJSON.dependencies, dependencies = _a === void 0 ? {} : _a, name = currentPackageJSON.name, version = currentPackageJSON.version;
89
+ var dependenciesList = Object.keys(dependencies);
90
+ if (!dependenciesList.length)
91
+ return acc;
92
+ var hasOverriddenDependencies = dependenciesList.some(function (dependencyItem) { return resolutionsList.includes(dependencyItem); });
93
+ if (!hasOverriddenDependencies)
94
+ return acc;
95
+ var appendixItem = updateAppendix(tslib_1.__assign({ dependencies: dependencies, name: name, resolutions: resolutions, version: version }, (options.appendix ? { appendix: options.appendix } : {})));
96
+ return tslib_1.__assign(tslib_1.__assign({}, acc), appendixItem);
97
+ }, {});
98
+ var appendixItems = Object.keys(appendix);
99
+ var updatedResolutions = appendixItems.length > 0 &&
100
+ appendixItems.filter(function (item) { return Object.keys(appendix[item]).length > 0; });
101
+ if (!isTesting) {
102
+ updatePackageJSON({
103
+ appendix: appendix,
104
+ path: path,
105
+ config: config,
106
+ resolutions: updatedResolutions,
107
+ });
108
+ }
109
+ return appendix;
110
+ }
111
+ exports.update = update;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare type PastoralistJSON = {
1
+ export declare type PastoralistJSON = {
2
2
  dependencies?: Record<string, string>;
3
3
  name: string;
4
4
  version: string;
@@ -11,8 +11,8 @@ declare type PastoralistJSON = {
11
11
  appendix?: Appendix;
12
12
  };
13
13
  };
14
- declare type Appendix = Record<string, Record<string, string> | string>;
15
- declare type ResolveResolutionOptions = {
14
+ export declare type Appendix = Record<string, Record<string, string>>;
15
+ export declare type ResolveResolutionOptions = {
16
16
  config?: {
17
17
  overrides?: Record<string, string> | undefined;
18
18
  pnpm?: {
@@ -22,26 +22,25 @@ declare type ResolveResolutionOptions = {
22
22
  };
23
23
  options?: Options;
24
24
  };
25
- declare type UpdateAppendixOptions = {
25
+ export declare type UpdateAppendixOptions = {
26
26
  appendix?: Appendix;
27
27
  dependencies: Record<string, string>;
28
28
  resolutions: Record<string, string>;
29
29
  name: string;
30
30
  version: string;
31
31
  };
32
- declare type Options = {
32
+ export declare type Options = {
33
33
  appendix?: Appendix;
34
34
  debug?: boolean;
35
35
  isTestingCLI?: boolean;
36
36
  path?: string;
37
37
  depPaths?: string[];
38
+ isTesting?: boolean;
38
39
  };
39
- declare type OverridesType = Record<string, string>;
40
- declare type UpdatePackageJSONOptions = {
40
+ export declare type OverridesType = Record<string, string>;
41
+ export declare type UpdatePackageJSONOptions = {
41
42
  appendix?: Appendix;
42
43
  path: string;
43
44
  config: PastoralistJSON;
44
45
  resolutions?: false | string[];
45
46
  };
46
-
47
- export { Appendix, Options, OverridesType, PastoralistJSON, ResolveResolutionOptions, UpdateAppendixOptions, UpdatePackageJSONOptions };
package/dist/types.js CHANGED
@@ -1,17 +1,2 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
-
15
- // src/types.ts
16
- var types_exports = {};
17
- module.exports = __toCommonJS(types_exports);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,17 +1,9 @@
1
1
  {
2
2
  "name": "pastoralist",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "description": "(WIP) a tool to watch over node module resolutions and overrides 🐑 👩🏽‍🌾",
5
- "type": "module",
6
5
  "main": "dist/index.js",
7
- "module": "dist/index.mjs",
8
- "types": "dist/types.d.ts",
9
- "exports": {
10
- ".": {
11
- "require": "./dist/index.js",
12
- "import": "./dist/index.mjs"
13
- }
14
- },
6
+ "types": "dist/index.d.ts",
15
7
  "files": [
16
8
  "dist"
17
9
  ],
@@ -19,7 +11,9 @@
19
11
  "pastoralist": "./dist/index.js"
20
12
  },
21
13
  "scripts": {
22
- "build": "tsup src/index.ts src/program.ts src/scripts.ts --format cjs,esm",
14
+ "build": "npm run clean && npm run dist",
15
+ "clean": "rm -rf dist",
16
+ "dist": "tsc",
23
17
  "test": "vitest run"
24
18
  },
25
19
  "repository": {
@@ -56,7 +50,6 @@
56
50
  "stdouttojson": "^0.3.1",
57
51
  "ts-node": "^10.7.0",
58
52
  "tslib": "^2.3.1",
59
- "tsup": "^5.12.6",
60
53
  "typescript": "^4.6.4",
61
54
  "vitest": "^0.12.1"
62
55
  }
@@ -1,130 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
21
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
22
- }) : x)(function(x) {
23
- if (typeof require !== "undefined")
24
- return require.apply(this, arguments);
25
- throw new Error('Dynamic require of "' + x + '" is not supported');
26
- });
27
-
28
- // src/scripts.ts
29
- import { resolve } from "path";
30
- import { writeFile } from "fs";
31
- import { sync } from "fast-glob";
32
- import { compare } from "compare-versions";
33
- function resolveJSON(path) {
34
- const jsonPath = resolve(path);
35
- return __require(jsonPath);
36
- }
37
- function resolveResolutions({
38
- config: {
39
- overrides: npmOverrides = {},
40
- pnpm: { overrides: pnpmOverrides = {} } = {},
41
- resolutions = {}
42
- } = {},
43
- options: { debug = false } = {}
44
- }) {
45
- const overridesItems = Object.keys(npmOverrides);
46
- const hasOverrides = overridesItems.length > 0;
47
- const hasComplexOverrides = hasOverrides && overridesItems.some((name) => typeof npmOverrides[name] === "object");
48
- if (hasComplexOverrides && debug) {
49
- console.warn("\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist only supports simple overrides! Pastoralist is bypassing the specified complex overrides. \u{1F44C}");
50
- }
51
- const overrides = hasOverrides ? overridesItems.filter((name) => typeof npmOverrides[name] === "string").reduce((acc, name) => __spreadProps(__spreadValues({}, acc), { [name]: npmOverrides[name] }), {}) : {};
52
- return __spreadValues(__spreadValues(__spreadValues({}, overrides), pnpmOverrides), resolutions);
53
- }
54
- function updateAppendix({
55
- dependencies,
56
- resolutions,
57
- name,
58
- version,
59
- appendix = {}
60
- }) {
61
- const dependencyList = Object.keys(dependencies);
62
- const resolutionsList = Object.keys(resolutions);
63
- return resolutionsList.reduce((acc, resolution) => {
64
- if (!dependencyList.includes(resolution)) {
65
- const hasResolutionOverride = compare(resolutions[resolution], dependencies[resolution], ">");
66
- if (hasResolutionOverride) {
67
- return __spreadProps(__spreadValues(__spreadValues({}, appendix), acc), {
68
- [`${resolution}@${resolutions[resolution]}`]: __spreadProps(__spreadValues({}, appendix[resolution]), {
69
- [name]: [version]
70
- })
71
- });
72
- }
73
- }
74
- return acc || {};
75
- }, {});
76
- }
77
- function updatePackageJSON({
78
- appendix,
79
- path,
80
- config,
81
- resolutions
82
- }) {
83
- var _a;
84
- const jsonPath = resolve(path);
85
- const pastoralist = (config == null ? void 0 : config.pastoralist) ? __spreadProps(__spreadValues({}, config.pastoralist), { appendix }) : { appendix };
86
- const json = __spreadValues(__spreadProps(__spreadValues({}, config), {
87
- pastoralist
88
- }), (config == null ? void 0 : config.resolutions) ? { resolutions } : (config == null ? void 0 : config.overrides) ? { overrides: resolutions } : ((_a = config == null ? void 0 : config.pnpm) == null ? void 0 : _a.overrides) ? { pnpm: __spreadProps(__spreadValues({}, config.pnpm), { overrides: resolutions }) } : {});
89
- writeFile(jsonPath, JSON.stringify(json, null, 2), (err) => console.log(`\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist had an issue updating overrides or resolutions in the package.json!${err ? `, ${err}` : ""}`));
90
- }
91
- function update(options) {
92
- const { depPaths = ["node_modules/**/package.json"], path = "package.json" } = options;
93
- const config = resolveJSON(path);
94
- const resolutions = resolveResolutions({ options, config });
95
- const resolutionsList = Object.keys(resolutions);
96
- const nodeModulePackageJSONs = sync(depPaths);
97
- const appendix = nodeModulePackageJSONs.reduce((acc, packageJSON) => {
98
- const { dependencies = {}, name, version } = resolveJSON(packageJSON);
99
- const dependenciesList = Object.keys(dependencies);
100
- if (!dependenciesList.length)
101
- return acc;
102
- const hasOverriddenDependencies = dependenciesList.some((dependencyItem) => resolutionsList.includes(dependencyItem));
103
- if (!hasOverriddenDependencies)
104
- return acc;
105
- const appendixItem = updateAppendix(__spreadValues({
106
- dependencies,
107
- name,
108
- resolutions,
109
- version
110
- }, options.appendix ? { appendix: options.appendix } : {}));
111
- return __spreadValues(__spreadValues({}, acc), appendixItem);
112
- }, {});
113
- const appendixItems = Object.keys(appendix);
114
- const updatedResolutions = appendixItems.length > 0 && appendixItems.filter((item) => Object.keys(appendix[item]).length > 0);
115
- updatePackageJSON({
116
- appendix,
117
- path,
118
- config,
119
- resolutions: updatedResolutions
120
- });
121
- return appendix;
122
- }
123
-
124
- export {
125
- resolveJSON,
126
- resolveResolutions,
127
- updateAppendix,
128
- updatePackageJSON,
129
- update
130
- };
@@ -1,23 +0,0 @@
1
- import {
2
- update
3
- } from "./chunk-AU3CJ5DF.mjs";
4
-
5
- // src/program.ts
6
- import { program } from "commander";
7
- var version = "VERSION";
8
- async function action(options = {}) {
9
- try {
10
- if (options == null ? void 0 : options.isTestingCLI)
11
- console.info({ options });
12
- update(options);
13
- } catch (err) {
14
- console.error(err);
15
- }
16
- }
17
- program.version(version).description("Pastoralist, a utility CLI to manage your dependency overrides").option("-p, --path <path>", "the path to the package.json file to manage").option("-d, --depPaths <depPaths>", "a path to dependency package.json files").option("-t, --isTestingCLI", "enables CLI testing, no scripts are run").parse(process.argv).action(action);
18
- var program_default = program;
19
-
20
- export {
21
- action,
22
- program_default
23
- };
@@ -1,23 +0,0 @@
1
- import {
2
- update
3
- } from "./chunk-YUCCQ46M.js";
4
-
5
- // src/program.ts
6
- import { program } from "commander";
7
- var version = "VERSION";
8
- async function action(options = {}) {
9
- try {
10
- if (options == null ? void 0 : options.isTestingCLI)
11
- console.info({ options });
12
- update(options);
13
- } catch (err) {
14
- console.error(err);
15
- }
16
- }
17
- program.version(version).description("Pastoralist, a utility CLI to manage your dependency overrides").option("-p, --path <path>", "the path to the package.json file to manage").option("-d, --depPaths <depPaths>", "a path to dependency package.json files").option("-t, --isTestingCLI", "enables CLI testing, no scripts are run").parse(process.argv).action(action);
18
- var program_default = program;
19
-
20
- export {
21
- action,
22
- program_default
23
- };
@@ -1,23 +0,0 @@
1
- import {
2
- update
3
- } from "./chunk-WXUCJGGF.mjs";
4
-
5
- // src/program.ts
6
- import { program } from "commander";
7
- var version = "VERSION";
8
- async function action(options = {}) {
9
- try {
10
- if (options == null ? void 0 : options.isTestingCLI)
11
- console.info({ options });
12
- update(options);
13
- } catch (err) {
14
- console.error(err);
15
- }
16
- }
17
- program.version(version).description("Pastoralist, a utility CLI to manage your dependency overrides").option("-p, --path <path>", "the path to the package.json file to manage").option("-d, --depPaths <depPaths>", "a path to dependency package.json files").option("-t, --isTestingCLI", "enables CLI testing, no scripts are run").parse(process.argv).action(action);
18
- var program_default = program;
19
-
20
- export {
21
- action,
22
- program_default
23
- };
@@ -1,130 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
21
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
22
- }) : x)(function(x) {
23
- if (typeof require !== "undefined")
24
- return require.apply(this, arguments);
25
- throw new Error('Dynamic require of "' + x + '" is not supported');
26
- });
27
-
28
- // src/scripts.ts
29
- import { resolve } from "path";
30
- import { writeFile } from "fs";
31
- import { sync } from "fast-glob";
32
- import { compare } from "compare-versions";
33
- function resolveJSON(path) {
34
- const jsonPath = resolve(path);
35
- return __require(jsonPath);
36
- }
37
- function resolveResolutions({
38
- config: {
39
- overrides: npmOverrides = {},
40
- pnpm: { overrides: pnpmOverrides = {} } = {},
41
- resolutions = {}
42
- } = {},
43
- options: { debug = false } = {}
44
- }) {
45
- const overridesItems = Object.keys(npmOverrides);
46
- const hasOverrides = overridesItems.length > 0;
47
- const hasComplexOverrides = hasOverrides && overridesItems.some((name) => typeof npmOverrides[name] === "object");
48
- if (hasComplexOverrides && debug) {
49
- console.warn("\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist only supports simple overrides! Pastoralist is bypassing the specified complex overrides. \u{1F44C}");
50
- }
51
- const overrides = hasOverrides ? overridesItems.filter((name) => typeof npmOverrides[name] === "string").reduce((acc, name) => __spreadProps(__spreadValues({}, acc), { [name]: npmOverrides[name] }), {}) : {};
52
- return __spreadValues(__spreadValues(__spreadValues({}, overrides), pnpmOverrides), resolutions);
53
- }
54
- function updateAppendix({
55
- dependencies,
56
- resolutions,
57
- name,
58
- version,
59
- appendix = {}
60
- }) {
61
- const dependencyList = Object.keys(dependencies);
62
- const resolutionsList = Object.keys(resolutions);
63
- return resolutionsList.reduce((acc, resolution) => {
64
- if (!dependencyList.includes(resolution)) {
65
- const hasResolutionOverride = compare(resolutions[resolution], dependencies[resolution], ">");
66
- if (hasResolutionOverride) {
67
- return __spreadProps(__spreadValues(__spreadValues({}, appendix), acc), {
68
- [`${resolution}@${resolutions[resolution]}`]: __spreadProps(__spreadValues({}, appendix[`${resolution}@${resolutions[resolution]}`]), {
69
- [name]: [version]
70
- })
71
- });
72
- }
73
- }
74
- return acc || {};
75
- }, {});
76
- }
77
- function updatePackageJSON({
78
- appendix,
79
- path,
80
- config,
81
- resolutions
82
- }) {
83
- var _a;
84
- const jsonPath = resolve(path);
85
- const pastoralist = (config == null ? void 0 : config.pastoralist) ? __spreadProps(__spreadValues({}, config.pastoralist), { appendix }) : { appendix };
86
- const json = __spreadValues(__spreadProps(__spreadValues({}, config), {
87
- pastoralist
88
- }), (config == null ? void 0 : config.resolutions) ? { resolutions } : (config == null ? void 0 : config.overrides) ? { overrides: resolutions } : ((_a = config == null ? void 0 : config.pnpm) == null ? void 0 : _a.overrides) ? { pnpm: __spreadProps(__spreadValues({}, config.pnpm), { overrides: resolutions }) } : {});
89
- writeFile(jsonPath, JSON.stringify(json, null, 2), (err) => console.log(`\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist had an issue updating overrides or resolutions in the package.json!${err ? `, ${err}` : ""}`));
90
- }
91
- function update(options) {
92
- const { depPaths = ["node_modules/**/package.json"], path = "package.json" } = options;
93
- const config = resolveJSON(path);
94
- const resolutions = resolveResolutions({ options, config });
95
- const resolutionsList = Object.keys(resolutions);
96
- const nodeModulePackageJSONs = sync(depPaths);
97
- const appendix = nodeModulePackageJSONs.reduce((acc, packageJSON) => {
98
- const { dependencies = {}, name, version } = resolveJSON(packageJSON);
99
- const dependenciesList = Object.keys(dependencies);
100
- if (!dependenciesList.length)
101
- return acc;
102
- const hasOverriddenDependencies = dependenciesList.some((dependencyItem) => resolutionsList.includes(dependencyItem));
103
- if (!hasOverriddenDependencies)
104
- return acc;
105
- const appendixItem = updateAppendix(__spreadValues({
106
- dependencies,
107
- name,
108
- resolutions,
109
- version
110
- }, options.appendix ? { appendix: options.appendix } : {}));
111
- return __spreadValues(__spreadValues({}, acc), appendixItem);
112
- }, {});
113
- const appendixItems = Object.keys(appendix);
114
- const updatedResolutions = appendixItems.length > 0 && appendixItems.filter((item) => Object.keys(appendix[item]).length > 0);
115
- updatePackageJSON({
116
- appendix,
117
- path,
118
- config,
119
- resolutions: updatedResolutions
120
- });
121
- return appendix;
122
- }
123
-
124
- export {
125
- resolveJSON,
126
- resolveResolutions,
127
- updateAppendix,
128
- updatePackageJSON,
129
- update
130
- };
@@ -1,130 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
21
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
22
- }) : x)(function(x) {
23
- if (typeof require !== "undefined")
24
- return require.apply(this, arguments);
25
- throw new Error('Dynamic require of "' + x + '" is not supported');
26
- });
27
-
28
- // src/scripts.ts
29
- import { resolve } from "path";
30
- import { writeFile } from "fs";
31
- import { sync } from "fast-glob";
32
- import { compare } from "compare-versions";
33
- function resolveJSON(path) {
34
- const jsonPath = resolve(path);
35
- return __require(jsonPath);
36
- }
37
- function resolveResolutions({
38
- config: {
39
- overrides: npmOverrides = {},
40
- pnpm: { overrides: pnpmOverrides = {} } = {},
41
- resolutions = {}
42
- } = {},
43
- options: { debug = false } = {}
44
- }) {
45
- const overridesItems = Object.keys(npmOverrides);
46
- const hasOverrides = overridesItems.length > 0;
47
- const hasComplexOverrides = hasOverrides && overridesItems.some((name) => typeof npmOverrides[name] === "object");
48
- if (hasComplexOverrides && debug) {
49
- console.warn("\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist only supports simple overrides! Pastoralist is bypassing the specified complex overrides. \u{1F44C}");
50
- }
51
- const overrides = hasOverrides ? overridesItems.filter((name) => typeof npmOverrides[name] === "string").reduce((acc, name) => __spreadProps(__spreadValues({}, acc), { [name]: npmOverrides[name] }), {}) : {};
52
- return __spreadValues(__spreadValues(__spreadValues({}, overrides), pnpmOverrides), resolutions);
53
- }
54
- function updateAppendix({
55
- dependencies,
56
- resolutions,
57
- name,
58
- version,
59
- appendix = {}
60
- }) {
61
- const dependencyList = Object.keys(dependencies);
62
- const resolutionsList = Object.keys(resolutions);
63
- return resolutionsList.reduce((acc, resolution) => {
64
- if (!dependencyList.includes(resolution)) {
65
- const hasResolutionOverride = compare(resolutions[resolution], dependencies[resolution], ">");
66
- if (hasResolutionOverride) {
67
- return __spreadProps(__spreadValues(__spreadValues({}, appendix), acc), {
68
- [`${resolution}@${resolutions[resolution]}`]: __spreadProps(__spreadValues({}, appendix[resolution]), {
69
- [name]: [version]
70
- })
71
- });
72
- }
73
- }
74
- return acc || {};
75
- }, {});
76
- }
77
- function updatePackageJSON({
78
- appendix,
79
- path,
80
- config,
81
- resolutions
82
- }) {
83
- var _a;
84
- const jsonPath = resolve(path);
85
- const pastoralist = (config == null ? void 0 : config.pastoralist) ? __spreadProps(__spreadValues({}, config.pastoralist), { appendix }) : { appendix };
86
- const json = __spreadValues(__spreadProps(__spreadValues({}, config), {
87
- pastoralist
88
- }), (config == null ? void 0 : config.resolutions) ? { resolutions } : (config == null ? void 0 : config.overrides) ? { overrides: resolutions } : ((_a = config == null ? void 0 : config.pnpm) == null ? void 0 : _a.overrides) ? { pnpm: __spreadProps(__spreadValues({}, config.pnpm), { overrides: resolutions }) } : {});
89
- writeFile(jsonPath, JSON.stringify(json, null, 2), (err) => console.log(`\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist had an issue updating overrides or resolutions in the package.json!${err ? `, ${err}` : ""}`));
90
- }
91
- function update(options) {
92
- const { depPaths = ["node_modules/**/package.json"], path = "package.json" } = options;
93
- const config = resolveJSON(path);
94
- const resolutions = resolveResolutions({ options, config });
95
- const resolutionsList = Object.keys(resolutions);
96
- const nodeModulePackageJSONs = sync(depPaths);
97
- const appendix = nodeModulePackageJSONs.reduce((acc, packageJSON) => {
98
- const { dependencies = {}, name, version } = resolveJSON(packageJSON);
99
- const dependenciesList = Object.keys(dependencies);
100
- if (!dependenciesList.length)
101
- return acc;
102
- const hasOverriddenDependencies = dependenciesList.some((dependencyItem) => resolutionsList.includes(dependencyItem));
103
- if (!hasOverriddenDependencies)
104
- return acc;
105
- const appendixItem = updateAppendix(__spreadValues({
106
- dependencies,
107
- name,
108
- resolutions,
109
- version
110
- }, options.appendix ? { appendix: options.appendix } : {}));
111
- return __spreadValues(__spreadValues({}, acc), appendixItem);
112
- }, {});
113
- const appendixItems = Object.keys(appendix);
114
- const updatedResolutions = appendixItems.length > 0 && appendixItems.filter((item) => Object.keys(appendix[item]).length > 0);
115
- updatePackageJSON({
116
- appendix,
117
- path,
118
- config,
119
- resolutions: updatedResolutions
120
- });
121
- return appendix;
122
- }
123
-
124
- export {
125
- resolveJSON,
126
- resolveResolutions,
127
- updateAppendix,
128
- updatePackageJSON,
129
- update
130
- };
package/dist/index.cjs DELETED
@@ -1,132 +0,0 @@
1
- #!/usr/bin/env node
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
-
22
- // src/program.ts
23
- var import_commander = require("commander");
24
-
25
- // src/scripts.ts
26
- var import_path = require("path");
27
- var import_fs = require("fs");
28
- var import_fast_glob = require("fast-glob");
29
- var import_compare_versions = require("compare-versions");
30
- function resolveJSON(path) {
31
- const jsonPath = (0, import_path.resolve)(path);
32
- return require(jsonPath);
33
- }
34
- function resolveResolutions({
35
- config: {
36
- overrides: npmOverrides = {},
37
- pnpm: { overrides: pnpmOverrides = {} } = {},
38
- resolutions = {}
39
- } = {},
40
- options: { debug = false } = {}
41
- }) {
42
- const overridesItems = Object.keys(npmOverrides);
43
- const hasOverrides = overridesItems.length > 0;
44
- const hasComplexOverrides = hasOverrides && overridesItems.some((name) => typeof npmOverrides[name] === "object");
45
- if (hasComplexOverrides && debug) {
46
- console.warn("\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist only supports simple overrides! Pastoralist is bypassing the specified complex overrides. \u{1F44C}");
47
- }
48
- const overrides = hasOverrides ? overridesItems.filter((name) => typeof npmOverrides[name] === "string").reduce((acc, name) => __spreadProps(__spreadValues({}, acc), { [name]: npmOverrides[name] }), {}) : {};
49
- return __spreadValues(__spreadValues(__spreadValues({}, overrides), pnpmOverrides), resolutions);
50
- }
51
- function updateAppendix({
52
- dependencies,
53
- resolutions,
54
- name,
55
- version: version2,
56
- appendix = {}
57
- }) {
58
- const dependencyList = Object.keys(dependencies);
59
- const resolutionsList = Object.keys(resolutions);
60
- return resolutionsList.reduce((acc, resolution) => {
61
- if (!dependencyList.includes(resolution)) {
62
- const hasResolutionOverride = (0, import_compare_versions.compare)(resolutions[resolution], dependencies[resolution], ">");
63
- if (hasResolutionOverride) {
64
- return __spreadProps(__spreadValues(__spreadValues({}, appendix), acc), {
65
- [`${resolution}@${resolutions[resolution]}`]: __spreadProps(__spreadValues({}, appendix[resolution]), {
66
- [name]: [version2]
67
- })
68
- });
69
- }
70
- }
71
- return acc || {};
72
- }, {});
73
- }
74
- function updatePackageJSON({
75
- appendix,
76
- path,
77
- config,
78
- resolutions
79
- }) {
80
- var _a;
81
- const jsonPath = (0, import_path.resolve)(path);
82
- const pastoralist = (config == null ? void 0 : config.pastoralist) ? __spreadProps(__spreadValues({}, config.pastoralist), { appendix }) : { appendix };
83
- const json = __spreadValues(__spreadProps(__spreadValues({}, config), {
84
- pastoralist
85
- }), (config == null ? void 0 : config.resolutions) ? { resolutions } : (config == null ? void 0 : config.overrides) ? { overrides: resolutions } : ((_a = config == null ? void 0 : config.pnpm) == null ? void 0 : _a.overrides) ? { pnpm: __spreadProps(__spreadValues({}, config.pnpm), { overrides: resolutions }) } : {});
86
- (0, import_fs.writeFile)(jsonPath, JSON.stringify(json, null, 2), (err) => console.log(`\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist had an issue updating overrides or resolutions in the package.json!${err ? `, ${err}` : ""}`));
87
- }
88
- function update(options) {
89
- const { depPaths = ["node_modules/**/package.json"], path = "package.json" } = options;
90
- const config = resolveJSON(path);
91
- const resolutions = resolveResolutions({ options, config });
92
- const resolutionsList = Object.keys(resolutions);
93
- const nodeModulePackageJSONs = (0, import_fast_glob.sync)(depPaths);
94
- const appendix = nodeModulePackageJSONs.reduce((acc, packageJSON) => {
95
- const { dependencies = {}, name, version: version2 } = resolveJSON(packageJSON);
96
- const dependenciesList = Object.keys(dependencies);
97
- if (!dependenciesList.length)
98
- return acc;
99
- const hasOverriddenDependencies = dependenciesList.some((dependencyItem) => resolutionsList.includes(dependencyItem));
100
- if (!hasOverriddenDependencies)
101
- return acc;
102
- const appendixItem = updateAppendix(__spreadValues({
103
- dependencies,
104
- name,
105
- resolutions,
106
- version: version2
107
- }, options.appendix ? { appendix: options.appendix } : {}));
108
- return __spreadValues(__spreadValues({}, acc), appendixItem);
109
- }, {});
110
- const appendixItems = Object.keys(appendix);
111
- const updatedResolutions = appendixItems.length > 0 && appendixItems.filter((item) => Object.keys(appendix[item]).length > 0);
112
- updatePackageJSON({
113
- appendix,
114
- path,
115
- config,
116
- resolutions: updatedResolutions
117
- });
118
- return appendix;
119
- }
120
-
121
- // src/program.ts
122
- var version = "VERSION";
123
- async function action(options = {}) {
124
- try {
125
- if (options == null ? void 0 : options.isTestingCLI)
126
- console.info({ options });
127
- update(options);
128
- } catch (err) {
129
- console.error(err);
130
- }
131
- }
132
- import_commander.program.version(version).description("Pastoralist, a utility CLI to manage your dependency overrides").option("-p, --path <path>", "the path to the package.json file to manage").option("-d, --depPaths <depPaths>", "a path to dependency package.json files").option("-t, --isTestingCLI", "enables CLI testing, no scripts are run").parse(process.argv).action(action);
package/dist/index.mjs DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import "./chunk-CU6RJLCN.mjs";
3
- import "./chunk-AU3CJ5DF.mjs";
package/dist/program.cjs DELETED
@@ -1,158 +0,0 @@
1
- #!/usr/bin/env node
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
- var __export = (target, all) => {
24
- for (var name in all)
25
- __defProp(target, name, { get: all[name], enumerable: true });
26
- };
27
- var __copyProps = (to, from, except, desc) => {
28
- if (from && typeof from === "object" || typeof from === "function") {
29
- for (let key of __getOwnPropNames(from))
30
- if (!__hasOwnProp.call(to, key) && key !== except)
31
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
- }
33
- return to;
34
- };
35
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
-
37
- // src/program.ts
38
- var program_exports = {};
39
- __export(program_exports, {
40
- action: () => action,
41
- default: () => program_default
42
- });
43
- module.exports = __toCommonJS(program_exports);
44
- var import_commander = require("commander");
45
-
46
- // src/scripts.ts
47
- var import_path = require("path");
48
- var import_fs = require("fs");
49
- var import_fast_glob = require("fast-glob");
50
- var import_compare_versions = require("compare-versions");
51
- function resolveJSON(path) {
52
- const jsonPath = (0, import_path.resolve)(path);
53
- return require(jsonPath);
54
- }
55
- function resolveResolutions({
56
- config: {
57
- overrides: npmOverrides = {},
58
- pnpm: { overrides: pnpmOverrides = {} } = {},
59
- resolutions = {}
60
- } = {},
61
- options: { debug = false } = {}
62
- }) {
63
- const overridesItems = Object.keys(npmOverrides);
64
- const hasOverrides = overridesItems.length > 0;
65
- const hasComplexOverrides = hasOverrides && overridesItems.some((name) => typeof npmOverrides[name] === "object");
66
- if (hasComplexOverrides && debug) {
67
- console.warn("\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist only supports simple overrides! Pastoralist is bypassing the specified complex overrides. \u{1F44C}");
68
- }
69
- const overrides = hasOverrides ? overridesItems.filter((name) => typeof npmOverrides[name] === "string").reduce((acc, name) => __spreadProps(__spreadValues({}, acc), { [name]: npmOverrides[name] }), {}) : {};
70
- return __spreadValues(__spreadValues(__spreadValues({}, overrides), pnpmOverrides), resolutions);
71
- }
72
- function updateAppendix({
73
- dependencies,
74
- resolutions,
75
- name,
76
- version: version2,
77
- appendix = {}
78
- }) {
79
- const dependencyList = Object.keys(dependencies);
80
- const resolutionsList = Object.keys(resolutions);
81
- return resolutionsList.reduce((acc, resolution) => {
82
- if (!dependencyList.includes(resolution)) {
83
- const hasResolutionOverride = (0, import_compare_versions.compare)(resolutions[resolution], dependencies[resolution], ">");
84
- if (hasResolutionOverride) {
85
- return __spreadProps(__spreadValues(__spreadValues({}, appendix), acc), {
86
- [`${resolution}@${resolutions[resolution]}`]: __spreadProps(__spreadValues({}, appendix[resolution]), {
87
- [name]: [version2]
88
- })
89
- });
90
- }
91
- }
92
- return acc || {};
93
- }, {});
94
- }
95
- function updatePackageJSON({
96
- appendix,
97
- path,
98
- config,
99
- resolutions
100
- }) {
101
- var _a;
102
- const jsonPath = (0, import_path.resolve)(path);
103
- const pastoralist = (config == null ? void 0 : config.pastoralist) ? __spreadProps(__spreadValues({}, config.pastoralist), { appendix }) : { appendix };
104
- const json = __spreadValues(__spreadProps(__spreadValues({}, config), {
105
- pastoralist
106
- }), (config == null ? void 0 : config.resolutions) ? { resolutions } : (config == null ? void 0 : config.overrides) ? { overrides: resolutions } : ((_a = config == null ? void 0 : config.pnpm) == null ? void 0 : _a.overrides) ? { pnpm: __spreadProps(__spreadValues({}, config.pnpm), { overrides: resolutions }) } : {});
107
- (0, import_fs.writeFile)(jsonPath, JSON.stringify(json, null, 2), (err) => console.log(`\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist had an issue updating overrides or resolutions in the package.json!${err ? `, ${err}` : ""}`));
108
- }
109
- function update(options) {
110
- const { depPaths = ["node_modules/**/package.json"], path = "package.json" } = options;
111
- const config = resolveJSON(path);
112
- const resolutions = resolveResolutions({ options, config });
113
- const resolutionsList = Object.keys(resolutions);
114
- const nodeModulePackageJSONs = (0, import_fast_glob.sync)(depPaths);
115
- const appendix = nodeModulePackageJSONs.reduce((acc, packageJSON) => {
116
- const { dependencies = {}, name, version: version2 } = resolveJSON(packageJSON);
117
- const dependenciesList = Object.keys(dependencies);
118
- if (!dependenciesList.length)
119
- return acc;
120
- const hasOverriddenDependencies = dependenciesList.some((dependencyItem) => resolutionsList.includes(dependencyItem));
121
- if (!hasOverriddenDependencies)
122
- return acc;
123
- const appendixItem = updateAppendix(__spreadValues({
124
- dependencies,
125
- name,
126
- resolutions,
127
- version: version2
128
- }, options.appendix ? { appendix: options.appendix } : {}));
129
- return __spreadValues(__spreadValues({}, acc), appendixItem);
130
- }, {});
131
- const appendixItems = Object.keys(appendix);
132
- const updatedResolutions = appendixItems.length > 0 && appendixItems.filter((item) => Object.keys(appendix[item]).length > 0);
133
- updatePackageJSON({
134
- appendix,
135
- path,
136
- config,
137
- resolutions: updatedResolutions
138
- });
139
- return appendix;
140
- }
141
-
142
- // src/program.ts
143
- var version = "VERSION";
144
- async function action(options = {}) {
145
- try {
146
- if (options == null ? void 0 : options.isTestingCLI)
147
- console.info({ options });
148
- update(options);
149
- } catch (err) {
150
- console.error(err);
151
- }
152
- }
153
- import_commander.program.version(version).description("Pastoralist, a utility CLI to manage your dependency overrides").option("-p, --path <path>", "the path to the package.json file to manage").option("-d, --depPaths <depPaths>", "a path to dependency package.json files").option("-t, --isTestingCLI", "enables CLI testing, no scripts are run").parse(process.argv).action(action);
154
- var program_default = import_commander.program;
155
- // Annotate the CommonJS export names for ESM import in node:
156
- 0 && (module.exports = {
157
- action
158
- });
package/dist/program.mjs DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- action,
4
- program_default
5
- } from "./chunk-CU6RJLCN.mjs";
6
- import "./chunk-AU3CJ5DF.mjs";
7
- export {
8
- action,
9
- program_default as default
10
- };
package/dist/scripts.cjs DELETED
@@ -1,148 +0,0 @@
1
- #!/usr/bin/env node
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
- var __export = (target, all) => {
24
- for (var name in all)
25
- __defProp(target, name, { get: all[name], enumerable: true });
26
- };
27
- var __copyProps = (to, from, except, desc) => {
28
- if (from && typeof from === "object" || typeof from === "function") {
29
- for (let key of __getOwnPropNames(from))
30
- if (!__hasOwnProp.call(to, key) && key !== except)
31
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
- }
33
- return to;
34
- };
35
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
-
37
- // src/scripts.ts
38
- var scripts_exports = {};
39
- __export(scripts_exports, {
40
- resolveJSON: () => resolveJSON,
41
- resolveResolutions: () => resolveResolutions,
42
- update: () => update,
43
- updateAppendix: () => updateAppendix,
44
- updatePackageJSON: () => updatePackageJSON
45
- });
46
- module.exports = __toCommonJS(scripts_exports);
47
- var import_path = require("path");
48
- var import_fs = require("fs");
49
- var import_fast_glob = require("fast-glob");
50
- var import_compare_versions = require("compare-versions");
51
- function resolveJSON(path) {
52
- const jsonPath = (0, import_path.resolve)(path);
53
- return require(jsonPath);
54
- }
55
- function resolveResolutions({
56
- config: {
57
- overrides: npmOverrides = {},
58
- pnpm: { overrides: pnpmOverrides = {} } = {},
59
- resolutions = {}
60
- } = {},
61
- options: { debug = false } = {}
62
- }) {
63
- const overridesItems = Object.keys(npmOverrides);
64
- const hasOverrides = overridesItems.length > 0;
65
- const hasComplexOverrides = hasOverrides && overridesItems.some((name) => typeof npmOverrides[name] === "object");
66
- if (hasComplexOverrides && debug) {
67
- console.warn("\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist only supports simple overrides! Pastoralist is bypassing the specified complex overrides. \u{1F44C}");
68
- }
69
- const overrides = hasOverrides ? overridesItems.filter((name) => typeof npmOverrides[name] === "string").reduce((acc, name) => __spreadProps(__spreadValues({}, acc), { [name]: npmOverrides[name] }), {}) : {};
70
- return __spreadValues(__spreadValues(__spreadValues({}, overrides), pnpmOverrides), resolutions);
71
- }
72
- function updateAppendix({
73
- dependencies,
74
- resolutions,
75
- name,
76
- version,
77
- appendix = {}
78
- }) {
79
- const dependencyList = Object.keys(dependencies);
80
- const resolutionsList = Object.keys(resolutions);
81
- return resolutionsList.reduce((acc, resolution) => {
82
- if (!dependencyList.includes(resolution)) {
83
- const hasResolutionOverride = (0, import_compare_versions.compare)(resolutions[resolution], dependencies[resolution], ">");
84
- if (hasResolutionOverride) {
85
- return __spreadProps(__spreadValues(__spreadValues({}, appendix), acc), {
86
- [`${resolution}@${resolutions[resolution]}`]: __spreadProps(__spreadValues({}, appendix[resolution]), {
87
- [name]: [version]
88
- })
89
- });
90
- }
91
- }
92
- return acc || {};
93
- }, {});
94
- }
95
- function updatePackageJSON({
96
- appendix,
97
- path,
98
- config,
99
- resolutions
100
- }) {
101
- var _a;
102
- const jsonPath = (0, import_path.resolve)(path);
103
- const pastoralist = (config == null ? void 0 : config.pastoralist) ? __spreadProps(__spreadValues({}, config.pastoralist), { appendix }) : { appendix };
104
- const json = __spreadValues(__spreadProps(__spreadValues({}, config), {
105
- pastoralist
106
- }), (config == null ? void 0 : config.resolutions) ? { resolutions } : (config == null ? void 0 : config.overrides) ? { overrides: resolutions } : ((_a = config == null ? void 0 : config.pnpm) == null ? void 0 : _a.overrides) ? { pnpm: __spreadProps(__spreadValues({}, config.pnpm), { overrides: resolutions }) } : {});
107
- (0, import_fs.writeFile)(jsonPath, JSON.stringify(json, null, 2), (err) => console.log(`\u{1F411} \u{1F469}\u{1F3FD}\u200D\u{1F33E} Pastoralist had an issue updating overrides or resolutions in the package.json!${err ? `, ${err}` : ""}`));
108
- }
109
- function update(options) {
110
- const { depPaths = ["node_modules/**/package.json"], path = "package.json" } = options;
111
- const config = resolveJSON(path);
112
- const resolutions = resolveResolutions({ options, config });
113
- const resolutionsList = Object.keys(resolutions);
114
- const nodeModulePackageJSONs = (0, import_fast_glob.sync)(depPaths);
115
- const appendix = nodeModulePackageJSONs.reduce((acc, packageJSON) => {
116
- const { dependencies = {}, name, version } = resolveJSON(packageJSON);
117
- const dependenciesList = Object.keys(dependencies);
118
- if (!dependenciesList.length)
119
- return acc;
120
- const hasOverriddenDependencies = dependenciesList.some((dependencyItem) => resolutionsList.includes(dependencyItem));
121
- if (!hasOverriddenDependencies)
122
- return acc;
123
- const appendixItem = updateAppendix(__spreadValues({
124
- dependencies,
125
- name,
126
- resolutions,
127
- version
128
- }, options.appendix ? { appendix: options.appendix } : {}));
129
- return __spreadValues(__spreadValues({}, acc), appendixItem);
130
- }, {});
131
- const appendixItems = Object.keys(appendix);
132
- const updatedResolutions = appendixItems.length > 0 && appendixItems.filter((item) => Object.keys(appendix[item]).length > 0);
133
- updatePackageJSON({
134
- appendix,
135
- path,
136
- config,
137
- resolutions: updatedResolutions
138
- });
139
- return appendix;
140
- }
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
143
- resolveJSON,
144
- resolveResolutions,
145
- update,
146
- updateAppendix,
147
- updatePackageJSON
148
- });
package/dist/scripts.mjs DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- resolveJSON,
4
- resolveResolutions,
5
- update,
6
- updateAppendix,
7
- updatePackageJSON
8
- } from "./chunk-AU3CJ5DF.mjs";
9
- export {
10
- resolveJSON,
11
- resolveResolutions,
12
- update,
13
- updateAppendix,
14
- updatePackageJSON
15
- };
package/dist/types.mjs DELETED
File without changes