@html-validate/release-scripts 3.4.8 → 3.5.5
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 +34 -9
- package/lib/get-args.js +11 -0
- package/lib/postpack.js +1 -1
- package/lib/prepack.js +21 -15
- package/lib/read-package-json.js +11 -0
- package/lib/strip-fields.js +21 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,24 +9,49 @@ Various scripts used by release toolchain.
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
11
11
|
"scripts": {
|
|
12
|
-
"prepack": "release-prepack
|
|
13
|
-
"postpack": "release-postpack
|
|
14
|
-
"prepublishOnly": "release-prepublish
|
|
15
|
-
"postpublish": "release-postpublish
|
|
12
|
+
"prepack": "release-prepack",
|
|
13
|
+
"postpack": "release-postpack",
|
|
14
|
+
"prepublishOnly": "release-prepublish",
|
|
15
|
+
"postpublish": "release-postpublish"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
If the library or CLI tool bundles all dependencies use `release-prepack
|
|
20
|
+
If the library or CLI tool bundles all dependencies use `release-prepack --bundle`.
|
|
21
21
|
Dependencies can also be filtered by marking dependencies as external: `--bundle --external:foo --external:bar`.
|
|
22
22
|
|
|
23
23
|
```json
|
|
24
24
|
{
|
|
25
25
|
"scripts": {
|
|
26
|
-
"prepack": "release-prepack
|
|
27
|
-
"postpack": "release-postpack
|
|
28
|
-
"prepublishOnly": "release-prepublish
|
|
29
|
-
"postpublish": "release-postpublish
|
|
26
|
+
"prepack": "release-prepack --bundle --external:foo --external:bar",
|
|
27
|
+
"postpack": "release-postpack",
|
|
28
|
+
"prepublishOnly": "release-prepublish --bundle --external:foo --external:bar",
|
|
29
|
+
"postpublish": "release-postpublish"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
|
+
|
|
34
|
+
### Usage
|
|
35
|
+
|
|
36
|
+
release-prepack [FILENAME] [OPTIONS..]
|
|
37
|
+
release-postpack [FILENAME]
|
|
38
|
+
release-prepublish [FILENAME] [OPTIONS..]
|
|
39
|
+
release-postpublish [FILENAME]
|
|
40
|
+
|
|
41
|
+
If `FILENAME` is set it is the filename to use instead of the default `package.json`.
|
|
42
|
+
|
|
43
|
+
### Options
|
|
44
|
+
|
|
45
|
+
#### `--bundle`
|
|
46
|
+
|
|
47
|
+
By default the `dependencies` field in `package.json` is intact but if your package bundles its dependencies the `--bundle` flag can be used to strip out dependencies as well.
|
|
48
|
+
|
|
49
|
+
#### `--external:${NAME}`
|
|
50
|
+
|
|
51
|
+
When using in conjunction with `--bundle` it marks a dependency which should still be intact.
|
|
52
|
+
For instance, using `--external:foobar` all packages in `dependencies` except `foobar` will be stripped.
|
|
53
|
+
This flag can be used multiple times.
|
|
54
|
+
|
|
55
|
+
#### `--retain-scripts`
|
|
56
|
+
|
|
57
|
+
By default the `scripts` field is stripped but with this flag enabled the scripts will be intact.
|
package/lib/get-args.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string[]} argv
|
|
3
|
+
* @returns {[flags: string[], positionals: string[]]}
|
|
4
|
+
*/
|
|
5
|
+
function getArgs(argv) {
|
|
6
|
+
const flags = argv.filter((it) => it.startsWith("--"));
|
|
7
|
+
const positionals = argv.filter((it) => !it.startsWith("--"));
|
|
8
|
+
return [flags, positionals];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = { getArgs };
|
package/lib/postpack.js
CHANGED
package/lib/prepack.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const { filterDependencies } = require("./filter-dependencies");
|
|
6
|
+
const { getArgs } = require("./get-args");
|
|
7
|
+
const { readPackageJson } = require("./read-package-json");
|
|
6
8
|
const { stripFields } = require("./strip-fields");
|
|
7
9
|
|
|
8
10
|
/* ensure this script runs via the correct lifecycle event */
|
|
@@ -11,41 +13,45 @@ if (command === "publish" && event === "prepack") {
|
|
|
11
13
|
process.exit(0);
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const bundle = process.argv.includes("--bundle");
|
|
20
|
-
const externals = process.argv
|
|
16
|
+
const [flags, positionals] = getArgs(process.argv.slice(2));
|
|
17
|
+
const bundle = flags.includes("--bundle");
|
|
18
|
+
const retainScripts = flags.includes("--retain-scripts");
|
|
19
|
+
const externals = flags
|
|
21
20
|
.filter((it) => it.startsWith("--external:"))
|
|
22
21
|
.map((it) => it.slice("--external:".length));
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const filename = positionals[0] || "package.json";
|
|
24
|
+
const filePath = path.resolve(filename);
|
|
25
|
+
const tmpfile = `${filePath}.tmp`;
|
|
26
|
+
const origfile = `${filePath}.orig`;
|
|
27
|
+
|
|
28
|
+
if (!fs.existsSync(filePath)) {
|
|
29
|
+
process.stderr.write(`release-prepack: No such file or directory: "${filePath}"\n`);
|
|
26
30
|
process.exit(1);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
const pkg =
|
|
33
|
+
const pkg = readPackageJson(filePath);
|
|
30
34
|
pkg.dependencies = filterDependencies(pkg.dependencies, bundle, externals);
|
|
31
35
|
|
|
32
|
-
stripFields(pkg
|
|
36
|
+
const stripped = stripFields(pkg, {
|
|
37
|
+
retainScripts,
|
|
38
|
+
});
|
|
33
39
|
|
|
34
|
-
const content = JSON.stringify(
|
|
40
|
+
const content = JSON.stringify(stripped, null, 2);
|
|
35
41
|
console.log(content);
|
|
36
42
|
|
|
37
43
|
/* backup original file in case of error */
|
|
38
|
-
fs.copyFileSync(
|
|
44
|
+
fs.copyFileSync(filePath, origfile);
|
|
39
45
|
|
|
40
46
|
try {
|
|
41
47
|
/* write to a temporary file first */
|
|
42
48
|
fs.writeFileSync(tmpfile, `${content}\n`, "utf-8");
|
|
43
49
|
|
|
44
50
|
/* swap tempfile for original */
|
|
45
|
-
fs.renameSync(tmpfile,
|
|
51
|
+
fs.renameSync(tmpfile, filePath);
|
|
46
52
|
} catch (err) {
|
|
47
53
|
console.error(err);
|
|
48
54
|
process.stderr.write(`\nRestoring "${filename}" after failure\n`);
|
|
49
|
-
fs.copyFileSync(origfile,
|
|
55
|
+
fs.copyFileSync(origfile, filePath);
|
|
50
56
|
process.exit(1);
|
|
51
57
|
}
|
package/lib/strip-fields.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} StripOptions
|
|
3
|
+
* @property {boolean} [retainScripts]
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
const strip = [
|
|
2
7
|
"ava",
|
|
3
8
|
"c8",
|
|
@@ -12,18 +17,31 @@ const strip = [
|
|
|
12
17
|
"prettier",
|
|
13
18
|
"release",
|
|
14
19
|
"renovate",
|
|
15
|
-
"scripts",
|
|
16
20
|
"simple-git-hooks",
|
|
17
21
|
"stylelint",
|
|
18
22
|
"tsd",
|
|
23
|
+
"workspaces",
|
|
19
24
|
"xo",
|
|
20
25
|
];
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @template T
|
|
29
|
+
* @param {T} pkg
|
|
30
|
+
* @param {StripOptions} options
|
|
31
|
+
* @returns {Partial<T>}
|
|
32
|
+
*/
|
|
33
|
+
function stripFields(pkg, options = {}) {
|
|
34
|
+
const result = { ...pkg };
|
|
23
35
|
for (const key of strip) {
|
|
24
36
|
/* eslint-disable-next-line security/detect-object-injection */
|
|
25
|
-
delete
|
|
37
|
+
delete result[key];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!options.retainScripts) {
|
|
41
|
+
delete result.scripts;
|
|
26
42
|
}
|
|
43
|
+
|
|
44
|
+
return result;
|
|
27
45
|
}
|
|
28
46
|
|
|
29
47
|
module.exports = { stripFields };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@html-validate/release-scripts",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.5",
|
|
4
4
|
"description": "Various script used by release toolchain",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"release"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "fbdc33d5e5b2df22bc9a7593e0ba7bc0276f7a26"
|
|
42
42
|
}
|