@html-validate/release-scripts 3.2.1 → 3.4.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Various scripts used by release toolchain.
4
4
 
5
- ## `release-prepack` and `release-postpack`
5
+ ## `release-pre{pack,publish}` and `release-post{pack,publish}`
6
6
 
7
7
  `package.json`:
8
8
 
@@ -11,6 +11,8 @@ Various scripts used by release toolchain.
11
11
  "scripts": {
12
12
  "prepack": "release-prepack package.json",
13
13
  "postpack": "release-postpack package.json"
14
+ "prepublishOnly": "release-prepublish package.json",
15
+ "postpublish": "release-postpublish package.json"
14
16
  }
15
17
  }
16
18
  ```
@@ -0,0 +1,17 @@
1
+ /* eslint-disable no-console, no-process-exit */
2
+
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+
6
+ /* ensure this script runs via the correct lifecycle event */
7
+ const { npm_command: command, npm_lifecycle_event: event } = process.env; // eslint-disable-line camelcase
8
+ if (command === "publish" && event === "postpack") {
9
+ process.exit(0);
10
+ }
11
+
12
+ const filename = process.argv[2];
13
+ const filepath = path.resolve(filename);
14
+ const origfile = `${filepath}.orig`;
15
+
16
+ console.log(`Restoring "${filepath}"`);
17
+ fs.renameSync(origfile, filepath);
package/lib/prepack.js CHANGED
@@ -1,25 +1,51 @@
1
+ /* eslint-disable no-console, no-process-exit */
2
+
1
3
  const path = require("path");
2
4
  const fs = require("fs");
3
5
  const { filterDependencies } = require("./filter-dependencies");
6
+ const { stripFields } = require("./strip-fields");
7
+
8
+ /* ensure this script runs via the correct lifecycle event */
9
+ const { npm_command: command, npm_lifecycle_event: event } = process.env; // eslint-disable-line camelcase
10
+ if (command === "publish" && event === "prepack") {
11
+ process.exit(0);
12
+ }
4
13
 
5
14
  const filename = process.argv[2];
6
15
  const filepath = path.resolve(filename);
7
- const pkg = JSON.parse(fs.readFileSync(filepath, "utf-8"));
16
+ const tmpfile = `${filepath}.tmp`;
17
+ const origfile = `${filepath}.orig`;
8
18
 
9
19
  const bundle = process.argv.includes("--bundle");
10
20
  const externals = process.argv
11
21
  .filter((it) => it.startsWith("--external:"))
12
22
  .map((it) => it.slice("--external:".length));
13
23
 
24
+ if (!fs.existsSync(filepath)) {
25
+ process.stderr.write(`release-prepack: No such file or directory: "${filepath}"\n`);
26
+ process.exit(1);
27
+ }
28
+
29
+ const pkg = JSON.parse(fs.readFileSync(filepath, "utf-8"));
14
30
  pkg.dependencies = filterDependencies(pkg.dependencies, bundle, externals);
15
- delete pkg.devDependencies;
16
- delete pkg.scripts;
17
- delete pkg.commitlint;
18
- delete pkg["lint-staged"];
19
- delete pkg.prettier;
20
- delete pkg.jest;
21
- delete pkg.release;
22
- delete pkg.renovate;
23
-
24
- /* eslint-disable-next-line no-console */
25
- console.log(JSON.stringify(pkg, null, 2));
31
+
32
+ stripFields(pkg);
33
+
34
+ const content = JSON.stringify(pkg, null, 2);
35
+ console.log(content);
36
+
37
+ /* backup original file in case of error */
38
+ fs.copyFileSync(filepath, origfile);
39
+
40
+ try {
41
+ /* write to a temporary file first */
42
+ fs.writeFileSync(tmpfile, `${content}\n`, "utf-8");
43
+
44
+ /* swap tempfile for original */
45
+ fs.renameSync(tmpfile, filepath);
46
+ } catch (err) {
47
+ console.error(err);
48
+ process.stderr.write(`\nRestoring "${filename}" after failure\n`);
49
+ fs.copyFileSync(origfile, filepath);
50
+ process.exit(1);
51
+ }
@@ -0,0 +1,29 @@
1
+ const strip = [
2
+ "ava",
3
+ "c8",
4
+ "commitlint",
5
+ "devDependencies",
6
+ "greenkeeper",
7
+ "husky",
8
+ "jest",
9
+ "lint-staged",
10
+ "nyc",
11
+ "pre-commit",
12
+ "prettier",
13
+ "release",
14
+ "renovate",
15
+ "scripts",
16
+ "simple-git-hooks",
17
+ "stylelint",
18
+ "tsd",
19
+ "xo",
20
+ ];
21
+
22
+ function stripFields(pkg) {
23
+ for (const key of strip) {
24
+ /* eslint-disable-next-line security/detect-object-injection */
25
+ delete pkg[key];
26
+ }
27
+ }
28
+
29
+ module.exports = { stripFields };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@html-validate/release-scripts",
3
- "version": "3.2.1",
3
+ "version": "3.4.1",
4
4
  "description": "Various script used by release toolchain",
5
5
  "keywords": [
6
6
  "release"
@@ -17,8 +17,10 @@
17
17
  "license": "MIT",
18
18
  "author": "David Sveningsson <ext@sidvind.com>",
19
19
  "bin": {
20
+ "release-prepublish": "scripts/prepack",
21
+ "release-prepack": "scripts/prepack",
20
22
  "release-postpack": "scripts/postpack",
21
- "release-prepack": "scripts/prepack"
23
+ "release-postpublish": "scripts/postpack"
22
24
  },
23
25
  "files": [
24
26
  "lib",
@@ -36,5 +38,5 @@
36
38
  "publishConfig": {
37
39
  "access": "public"
38
40
  },
39
- "gitHead": "12f3a6a1b803337fc138e80d1180e98dd53c4dfb"
41
+ "gitHead": "47aa6af977c3e3f32334ffcc12d3bbd2c68aeee7"
40
42
  }
package/scripts/postpack CHANGED
@@ -1,9 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env node
2
+ "use strict";
2
3
 
3
- set -e
4
-
5
- FILENAME="$1"
6
- ORIGINAL="${FILENAME}.orig"
7
-
8
- echo "Restoring ${FILENAME}"
9
- mv "${ORIGINAL}" "${FILENAME}"
4
+ require("../lib/postpack");
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ require("../lib/postpack");
package/scripts/prepack CHANGED
@@ -1,22 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env node
2
+ "use strict";
2
3
 
3
- FILENAME="$1"
4
- ORIGINAL="${FILENAME}.orig"
5
- TMPFILE="${FILENAME}.tmp"
6
- PREPACK="$(node -p "require.resolve('@html-validate/release-scripts/lib/prepack')")"
7
- shift 1
8
-
9
- restore() {
10
- echo "Restoring ${FILENAME} after failure" > /dev/stderr
11
- if [[ -e "${ORIGINAL}" ]]; then
12
- mv "${ORIGINAL}" "${FILENAME}"
13
- fi
14
- }
15
-
16
- set -e
17
- set -o pipefail
18
- trap restore ERR
19
-
20
- cp "${FILENAME}" "${ORIGINAL}"
21
- node "${PREPACK}" "${FILENAME}" "$@" | tee "${TMPFILE}"
22
- mv "${TMPFILE}" "${FILENAME}"
4
+ require("../lib/prepack");
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ require("../lib/prepack");