@html-validate/release-scripts 3.2.1 → 3.3.0

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,11 @@
1
+ /* eslint-disable no-console, no-process-exit */
2
+
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+
6
+ const filename = process.argv[2];
7
+ const filepath = path.resolve(filename);
8
+ const origfile = `${filepath}.orig`;
9
+
10
+ console.log(`Restoring "${filepath}"`);
11
+ fs.renameSync(origfile, filepath);
package/lib/prepack.js CHANGED
@@ -1,25 +1,45 @@
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");
4
7
 
5
8
  const filename = process.argv[2];
6
9
  const filepath = path.resolve(filename);
7
- const pkg = JSON.parse(fs.readFileSync(filepath, "utf-8"));
10
+ const tmpfile = `${filepath}.tmp`;
11
+ const origfile = `${filepath}.orig`;
8
12
 
9
13
  const bundle = process.argv.includes("--bundle");
10
14
  const externals = process.argv
11
15
  .filter((it) => it.startsWith("--external:"))
12
16
  .map((it) => it.slice("--external:".length));
13
17
 
18
+ if (!fs.existsSync(filepath)) {
19
+ process.stderr.write(`release-prepack: No such file or directory: "${filepath}"\n`);
20
+ process.exit(1);
21
+ }
22
+
23
+ const pkg = JSON.parse(fs.readFileSync(filepath, "utf-8"));
14
24
  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));
25
+
26
+ stripFields(pkg);
27
+
28
+ const content = JSON.stringify(pkg, null, 2);
29
+ console.log(content);
30
+
31
+ /* backup original file in case of error */
32
+ fs.copyFileSync(filepath, origfile);
33
+
34
+ try {
35
+ /* write to a temporary file first */
36
+ fs.writeFileSync(tmpfile, `${content}\n`, "utf-8");
37
+
38
+ /* swap tempfile for original */
39
+ fs.renameSync(tmpfile, filepath);
40
+ } catch (err) {
41
+ console.error(err);
42
+ process.stderr.write(`\nRestoring "${filename}" after failure\n`);
43
+ fs.copyFileSync(origfile, filepath);
44
+ process.exit(1);
45
+ }
@@ -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.3.0",
4
4
  "description": "Various script used by release toolchain",
5
5
  "keywords": [
6
6
  "release"
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "12f3a6a1b803337fc138e80d1180e98dd53c4dfb"
39
+ "gitHead": "e0f7962305559737b4ceab5e95e65b6642dbbcb0"
40
40
  }
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");
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");