pastoralist 0.0.2 → 0.0.4

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,130 @@
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
+ };
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,130 @@
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 ADDED
@@ -0,0 +1,132 @@
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.js CHANGED
@@ -1,132 +1,3 @@
1
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}@${resolutions[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);
2
+ import "./chunk-K3VYYVO7.js";
3
+ import "./chunk-YUCCQ46M.js";
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import "./chunk-T637KLSH.mjs";
3
- import "./chunk-WXUCJGGF.mjs";
2
+ import "./chunk-CU6RJLCN.mjs";
3
+ import "./chunk-AU3CJ5DF.mjs";
@@ -0,0 +1,158 @@
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.js CHANGED
@@ -1,158 +1,10 @@
1
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;
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
21
10
  };
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}@${resolutions[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 CHANGED
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  action,
4
4
  program_default
5
- } from "./chunk-T637KLSH.mjs";
6
- import "./chunk-WXUCJGGF.mjs";
5
+ } from "./chunk-CU6RJLCN.mjs";
6
+ import "./chunk-AU3CJ5DF.mjs";
7
7
  export {
8
8
  action,
9
9
  program_default as default
@@ -0,0 +1,148 @@
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.js CHANGED
@@ -1,148 +1,15 @@
1
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}@${resolutions[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 = {
2
+ import {
143
3
  resolveJSON,
144
4
  resolveResolutions,
145
5
  update,
146
6
  updateAppendix,
147
7
  updatePackageJSON
148
- });
8
+ } from "./chunk-YUCCQ46M.js";
9
+ export {
10
+ resolveJSON,
11
+ resolveResolutions,
12
+ update,
13
+ updateAppendix,
14
+ updatePackageJSON
15
+ };
package/dist/scripts.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  update,
6
6
  updateAppendix,
7
7
  updatePackageJSON
8
- } from "./chunk-WXUCJGGF.mjs";
8
+ } from "./chunk-AU3CJ5DF.mjs";
9
9
  export {
10
10
  resolveJSON,
11
11
  resolveResolutions,
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "pastoralist",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "(WIP) a tool to watch over node module resolutions and overrides 🐑 👩🏽‍🌾",
5
+ "type": "module",
5
6
  "main": "dist/index.js",
7
+ "module": "dist/index.mjs",
6
8
  "types": "dist/types.d.ts",
7
9
  "exports": {
8
10
  ".": {
9
- "require": "./dist/index.cjs",
11
+ "require": "./dist/index.js",
10
12
  "import": "./dist/index.mjs"
11
13
  }
12
14
  },
@@ -17,7 +19,7 @@
17
19
  "pastoralist": "./dist/index.js"
18
20
  },
19
21
  "scripts": {
20
- "build": "tsup src/index.ts src/program.ts src/scripts.ts --format cjs,esm && tsup src/types.ts --dts-only",
22
+ "build": "tsup src/index.ts src/program.ts src/scripts.ts --format cjs,esm",
21
23
  "test": "vitest run"
22
24
  },
23
25
  "repository": {
@@ -56,6 +58,6 @@
56
58
  "tslib": "^2.3.1",
57
59
  "tsup": "^5.12.6",
58
60
  "typescript": "^4.6.4",
59
- "vitest": "^0.10.0"
61
+ "vitest": "^0.12.1"
60
62
  }
61
63
  }