pastoralist 0.1.4 โ 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -20
- package/dist/scripts.d.ts +1 -1
- package/dist/scripts.js +39 -7
- package/dist/types.d.ts +3 -1
- package/package.json +30 -1
package/README.md
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|

|
|
4
4
|

|
|
5
5
|
|
|
6
|
-
A tool to watch over node module
|
|
6
|
+
A tool to watch over node module **`*overrides and resolutions`** ๐ ๐ฉ๐ฝโ๐พ
|
|
7
7
|
|
|
8
|
-
> \***overrides and resolutions**
|
|
8
|
+
> \***overrides and resolutions**
|
|
9
|
+
>
|
|
10
|
+
> Overrides and resolutions solve the same problem-they give developers a way to specify the dependency versions downloaded to repository's `node_modules`. This is very convenient for setting dependency dependencies to specific versions to fix security issues. However, it is easy to lose track of why an override or resolution is specified. This is an inconvenient problem when trying to maintain useable dependencies over timeโuntil now.
|
|
9
11
|
|
|
10
12
|
---
|
|
11
13
|
## Synopsis
|
|
12
14
|
|
|
13
|
-
By
|
|
15
|
+
By running **Pastoralist** in a `pre-commit` hook (or other command) an override/resolution which looks like this:
|
|
14
16
|
|
|
15
17
|
```js
|
|
16
18
|
// package.json
|
|
@@ -35,13 +37,17 @@ Will look like this:
|
|
|
35
37
|
}
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
By
|
|
40
|
+
By running this!
|
|
39
41
|
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
+
```sh
|
|
43
|
+
pastoralist
|
|
44
|
+
# oh hech yeah!
|
|
42
45
|
```
|
|
43
46
|
|
|
44
|
-
But there's more!
|
|
47
|
+
But there's more!
|
|
48
|
+
|
|
49
|
+
If **Pastoralist** is run and a `resolution` or `override` is no longer required
|
|
50
|
+
it will clean up itself and resolutions!
|
|
45
51
|
|
|
46
52
|
```js
|
|
47
53
|
// pastoralist finds and removes `trim` when/if it's no longer needed!
|
|
@@ -49,7 +55,6 @@ But there's more! If `pastoralist` is run and a `resolution` or `override` is no
|
|
|
49
55
|
"pastoralist": {
|
|
50
56
|
"appendix": {}
|
|
51
57
|
}
|
|
52
|
-
|
|
53
58
|
```
|
|
54
59
|
|
|
55
60
|
---
|
|
@@ -58,17 +63,19 @@ But there's more! If `pastoralist` is run and a `resolution` or `override` is no
|
|
|
58
63
|
|
|
59
64
|
**Pastoralist** manages `overrides` and `resolutions` so you don't have to!
|
|
60
65
|
|
|
61
|
-
Pastoralist is comprised of a few functions which read
|
|
66
|
+
**Pastoralist** is comprised of a few functions which read **node_modules** `package.json` files and reduce overrides or resolutions within the root `package.json` into a single `pastoralist.appendix` object.
|
|
62
67
|
|
|
63
|
-
- Pastoralist adds an `appendix` with a list of "resolved" dependencies
|
|
68
|
+
- **Pastoralist** adds an `pastoralist.appendix` with a list of "resolved" dependencies.
|
|
64
69
|
- Better yet, if Pastoralist observes an `override` or `resolution` is no longer needed, it removes it from `resolutions`, `overrides`, and the pastoralist `appendix` object.
|
|
65
|
-
- This means with Pastoralist
|
|
70
|
+
- This means with **Pastoralist**, your **only** concern is adding dependencies to the `overrides` and `resolutions` objects.
|
|
66
71
|
|
|
67
72
|
### Key notes
|
|
68
73
|
|
|
69
|
-
- Pastoralist does **not** manage what is added to overrides and resolutions objects.
|
|
70
|
-
- Pastoralist
|
|
71
|
-
- Pastoralist will remove overrides and resolutions if they become unneeded according to child `package.json`'s spec!
|
|
74
|
+
- **Pastoralist** does **not** manage what is added to overrides and resolutions objects.
|
|
75
|
+
- **Pastoralist does** manage dependenceis that exists in a `package.json`'s overrides or resolutions objects.
|
|
76
|
+
- **Pastoralist** will remove overrides and resolutions if they become unneeded according to child `package.json`'s spec!
|
|
77
|
+
|
|
78
|
+
View the **[Pasture lifecycle doc](./docs/pasture-lifecycle.md)** to get some visuals into what Pastoralist has got going on!
|
|
72
79
|
|
|
73
80
|
---
|
|
74
81
|
## Install
|
|
@@ -82,19 +89,21 @@ npm install pastoralist --save-dev
|
|
|
82
89
|
|
|
83
90
|
## Usage
|
|
84
91
|
|
|
85
|
-
Pastoralist is built to be used as a CLI program and runs with a single word "pastoralist".`
|
|
92
|
+
**Pastoralist** is built to be used as a CLI program and runs with a single word "pastoralist".`
|
|
86
93
|
|
|
87
94
|
```sh
|
|
88
95
|
pastoralist
|
|
89
96
|
# => That's it! Chack out your package json
|
|
90
97
|
```
|
|
91
98
|
|
|
92
|
-
Pastoralist can _and should be incorporated_ into your workflowโwhich ever way is best for you and your team's developer experience! ๐
|
|
99
|
+
**Pastoralist** can _and should be incorporated_ into your workflowโwhich ever way is best for you and your team's developer experience! ๐
|
|
93
100
|
|
|
94
101
|
---
|
|
95
102
|
## Roadmap
|
|
96
103
|
|
|
97
|
-
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
104
|
+
**Updated `2022-05-20`**
|
|
105
|
+
|
|
106
|
+
- More tests (in progress)
|
|
107
|
+
- Local development setup (next few days)
|
|
108
|
+
- Provide more configuration options using a tool like [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) (within the next weeks)
|
|
109
|
+
- Provide caveats, code examples, and more documentation (next few days)
|
package/dist/scripts.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { Appendix, Options, OverridesType, PastoralistJSON, ResolveResolutionOpt
|
|
|
2
2
|
export declare function resolveJSON(path: string, debug?: boolean): PastoralistJSON | void;
|
|
3
3
|
export declare function resolveResolutions({ config: { overrides: npmOverrides, pnpm: { overrides: pnpmOverrides }, resolutions, }, options: { debug }, }: ResolveResolutionOptions): OverridesType;
|
|
4
4
|
export declare function updateAppendix({ dependencies, resolutions, name, version, appendix, }: UpdateAppendixOptions): Appendix;
|
|
5
|
-
export declare function updatePackageJSON({ appendix, path, config, resolutions, }: UpdatePackageJSONOptions): void;
|
|
5
|
+
export declare function updatePackageJSON({ appendix, path, config, resolutions, isTesting, debug, }: UpdatePackageJSONOptions): PastoralistJSON | void;
|
|
6
6
|
export declare function update(options: Options): Appendix | void;
|
package/dist/scripts.js
CHANGED
|
@@ -57,19 +57,31 @@ function updateAppendix(_a) {
|
|
|
57
57
|
exports.updateAppendix = updateAppendix;
|
|
58
58
|
function updatePackageJSON(_a) {
|
|
59
59
|
var _b;
|
|
60
|
-
var appendix = _a.appendix, path = _a.path, config = _a.config, resolutions = _a.resolutions;
|
|
60
|
+
var appendix = _a.appendix, path = _a.path, config = _a.config, resolutions = _a.resolutions, _c = _a.isTesting, isTesting = _c === void 0 ? false : _c, _d = _a.debug, debug = _d === void 0 ? false : _d;
|
|
61
61
|
var jsonPath = (0, path_1.resolve)(path);
|
|
62
62
|
var pastoralist = (config === null || config === void 0 ? void 0 : config.pastoralist)
|
|
63
63
|
? tslib_1.__assign(tslib_1.__assign({}, config.pastoralist), { appendix: appendix }) : { appendix: appendix };
|
|
64
|
-
var
|
|
64
|
+
var hasResolutions = resolutions && Object.keys(resolutions).length > 0;
|
|
65
|
+
var json = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, config), { pastoralist: pastoralist }), ((config === null || config === void 0 ? void 0 : config.resolutions) && hasResolutions
|
|
65
66
|
? { resolutions: resolutions }
|
|
66
|
-
: (config === null || config === void 0 ? void 0 : config.overrides)
|
|
67
|
+
: (config === null || config === void 0 ? void 0 : config.overrides) && hasResolutions
|
|
67
68
|
? { overrides: resolutions }
|
|
68
|
-
: ((_b = config === null || config === void 0 ? void 0 : config.pnpm) === null || _b === void 0 ? void 0 : _b.overrides)
|
|
69
|
+
: ((_b = config === null || config === void 0 ? void 0 : config.pnpm) === null || _b === void 0 ? void 0 : _b.overrides) && hasResolutions
|
|
69
70
|
? { pnpm: tslib_1.__assign(tslib_1.__assign({}, config.pnpm), { overrides: resolutions }) }
|
|
70
71
|
: {}));
|
|
72
|
+
if (debug)
|
|
73
|
+
console.log({
|
|
74
|
+
log: "๐ ๐ฉ๐ฝโ๐พ Pastoralist:updatePackageJSON:fn:",
|
|
75
|
+
json: json,
|
|
76
|
+
config: config,
|
|
77
|
+
pastoralist: pastoralist,
|
|
78
|
+
resolutions: resolutions,
|
|
79
|
+
});
|
|
80
|
+
if (isTesting)
|
|
81
|
+
return json;
|
|
71
82
|
(0, fs_1.writeFile)(jsonPath, JSON.stringify(json, null, 2), function (err) {
|
|
72
|
-
return
|
|
83
|
+
return debug &&
|
|
84
|
+
console.log("\uD83D\uDC11 \uD83D\uDC69\uD83C\uDFFD\u200D\uD83C\uDF3E Pastoralist had an issue updating overrides or resolutions in the package.json!\n".concat(err));
|
|
73
85
|
});
|
|
74
86
|
}
|
|
75
87
|
exports.updatePackageJSON = updatePackageJSON;
|
|
@@ -96,8 +108,28 @@ function update(options) {
|
|
|
96
108
|
return tslib_1.__assign(tslib_1.__assign({}, acc), appendixItem);
|
|
97
109
|
}, {});
|
|
98
110
|
var appendixItems = Object.keys(appendix);
|
|
99
|
-
var
|
|
100
|
-
appendixItems
|
|
111
|
+
var appendixItemsToBeRemoved = appendixItems.length > 0
|
|
112
|
+
? appendixItems
|
|
113
|
+
.filter(function (item) { return Object.keys(appendix[item]).length > 0; })
|
|
114
|
+
.map(function (item) { return item.split("@")[0]; })
|
|
115
|
+
: [];
|
|
116
|
+
var updatedResolutions = appendixItemsToBeRemoved.length > 0
|
|
117
|
+
? Object.keys(resolutions).reduce(function (acc, item) {
|
|
118
|
+
var _a;
|
|
119
|
+
var isItemToBeRemoved = appendixItemsToBeRemoved.includes(item);
|
|
120
|
+
if (isItemToBeRemoved)
|
|
121
|
+
return acc;
|
|
122
|
+
return tslib_1.__assign(tslib_1.__assign({}, acc), (_a = {}, _a[item] = resolutions[item], _a));
|
|
123
|
+
}, {})
|
|
124
|
+
: resolutions;
|
|
125
|
+
if (debug)
|
|
126
|
+
console.log({
|
|
127
|
+
log: "๐ ๐ฉ๐ฝโ๐พ Pastoralist:update:fn:",
|
|
128
|
+
appendix: appendix,
|
|
129
|
+
config: config,
|
|
130
|
+
path: path,
|
|
131
|
+
updatedResolutions: updatedResolutions,
|
|
132
|
+
});
|
|
101
133
|
if (!isTesting) {
|
|
102
134
|
updatePackageJSON({
|
|
103
135
|
appendix: appendix,
|
package/dist/types.d.ts
CHANGED
|
@@ -40,7 +40,9 @@ export declare type Options = {
|
|
|
40
40
|
export declare type OverridesType = Record<string, string>;
|
|
41
41
|
export declare type UpdatePackageJSONOptions = {
|
|
42
42
|
appendix?: Appendix;
|
|
43
|
+
debug?: boolean;
|
|
43
44
|
path: string;
|
|
44
45
|
config: PastoralistJSON;
|
|
45
|
-
resolutions?:
|
|
46
|
+
resolutions?: OverridesType;
|
|
47
|
+
isTesting?: boolean;
|
|
46
48
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pastoralist",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "A tool to watch over node module resolutions and overrides ๐ ๐ฉ๐ฝโ๐พ",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,15 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "npm run clean && npm run dist",
|
|
15
15
|
"clean": "rm -rf dist",
|
|
16
|
+
"commit": "git-cz",
|
|
17
|
+
"commit-msg": "commitlint --edit $1",
|
|
16
18
|
"dist": "tsc",
|
|
19
|
+
"husky-setup:commit-msg": "(path-exists .husky/commit-msg) || (npx husky add .husky/commit-msg 'npm run commit-msg')",
|
|
20
|
+
"husky-setup:post-merge": "(path-exists .husky/post-merge) || (npx husky add .husky/post-merge 'npm install && npm run build')",
|
|
21
|
+
"husky-setup:pre-commit": "(path-exists .husky/pre-commit) || (npx husky add .husky/pre-commit 'npm run pre-commit')",
|
|
22
|
+
"pre-commit": "lint-staged --quiet && npm run test",
|
|
23
|
+
"prepare": "is-ci || (husky install && npm run husky-setup:commit-msg --silent; npm run husky-setup:post-merge --silent; npm run husky-setup:pre-commit --silent)",
|
|
24
|
+
"prepublishOnly": "npm run test && npm run build",
|
|
17
25
|
"test": "vitest run"
|
|
18
26
|
},
|
|
19
27
|
"repository": {
|
|
@@ -42,15 +50,36 @@
|
|
|
42
50
|
"tslib": "^2.3.1"
|
|
43
51
|
},
|
|
44
52
|
"devDependencies": {
|
|
53
|
+
"@commitlint/cli": "^17.0.0",
|
|
54
|
+
"@commitlint/config-conventional": "^17.0.0",
|
|
45
55
|
"@types/node": "^17.0.31",
|
|
46
56
|
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
47
57
|
"@typescript-eslint/parser": "^5.21.0",
|
|
48
58
|
"eslint": "^8.10.0",
|
|
49
59
|
"eslint-config-prettier": "^8.5.0",
|
|
60
|
+
"husky": "^8.0.1",
|
|
61
|
+
"is-ci": "^3.0.1",
|
|
62
|
+
"lint-staged": "^12.4.1",
|
|
63
|
+
"path-exists-cli": "^2.0.0",
|
|
50
64
|
"release-it": "^15.0.0",
|
|
51
65
|
"stdouttojson": "^0.3.1",
|
|
52
66
|
"ts-node": "^10.7.0",
|
|
53
67
|
"typescript": "^4.6.4",
|
|
54
68
|
"vitest": "^0.12.1"
|
|
69
|
+
},
|
|
70
|
+
"commitlint": {
|
|
71
|
+
"extends": [
|
|
72
|
+
"@commitlint/config-conventional"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"lint-staged": {
|
|
76
|
+
"src/**/*.ts": [
|
|
77
|
+
"eslint --fix"
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
"release-it": {
|
|
81
|
+
"git": {
|
|
82
|
+
"commitMessage": "chore: release v%s"
|
|
83
|
+
}
|
|
55
84
|
}
|
|
56
85
|
}
|