arcadible 1.0.11 → 1.0.12

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/package.json CHANGED
@@ -65,5 +65,5 @@
65
65
  "scripts": {
66
66
  "test": "node --test \"test/**/*.test.js\""
67
67
  },
68
- "version": "1.0.11"
68
+ "version": "1.0.12"
69
69
  }
@@ -9,33 +9,22 @@ const path = require("node:path");
9
9
 
10
10
  const cfgcode = require("../../config/code");
11
11
  const error = require("../../util/error");
12
+ const lockfile = require("../../util/lockfile");
12
13
  const phrase = require("../../phrase");
13
14
 
14
15
  // [use]
15
16
 
16
17
  const ArcError = error.ArcError;
18
+ const detect = lockfile.detect;
17
19
  const existsSync = fs.existsSync; // eslint-disable-line no-sync
18
20
  const join = path.join;
19
21
 
20
- // [declare]
21
-
22
- const LOCK_FILES = [
23
- // npm
24
- "package-lock.json",
25
- "npm-shrinkwrap.json",
26
- // pnpm
27
- "pnpm-lock.yaml",
28
- // yarn
29
- "yarn.lock",
30
- ];
31
-
32
22
  // [function]
33
23
 
34
24
  // fails when there's a package.json without a lockfile: the release workflow
35
25
  // installs exactly what the lockfile pins.
36
26
  const ensureLockFile = function (root) {
37
- const has = (file) => existsSync(join(root, file));
38
- if (has("package.json") && !LOCK_FILES.some(has)) {
27
+ if (existsSync(join(root, "package.json")) && !detect(root)) {
39
28
  return Promise.reject(
40
29
  new ArcError(cfgcode.LOCKFILE_MISSING, phrase.lockfileMissing()),
41
30
  );
package/src/parser/env.js CHANGED
@@ -12,6 +12,7 @@ const fs = require("fs-extra");
12
12
 
13
13
  const cfgcode = require("../config/code");
14
14
  const error = require("../util/error");
15
+ const lockfile = require("../util/lockfile");
15
16
  const objs = require("../util/objs");
16
17
  const phrase = require("../phrase");
17
18
 
@@ -19,14 +20,13 @@ const phrase = require("../phrase");
19
20
 
20
21
  const ArcError = error.ArcError;
21
22
  const deepCompact = objs.deepCompact;
23
+ const detect = lockfile.detect;
22
24
  const join = path.join;
23
25
  const pathExists = fs.pathExists;
24
26
  const readFile = fs.readFile;
25
27
 
26
28
  // [declare]
27
29
 
28
- // the build a package.json build script stands for.
29
- const NPM_RUN_BUILD = "npm run build";
30
30
  const PACKAGE = "package.json";
31
31
 
32
32
  // [function]
@@ -53,13 +53,19 @@ const parseJson = function (buf) {
53
53
 
54
54
  // [function]
55
55
 
56
- // package.json's version, and its build script as `npm run build`: run
57
- // through npm, the script finds the project's own tools on the PATH
58
- // (node_modules/.bin), and its prebuild and postbuild run, as they do
59
- // locally. npm runs the scripts of a pnpm or Yarn project too.
60
- const extract = function (conf) {
56
+ // package.json's version, and its build script as `<manager> run build`, run
57
+ // with the package manager its lockfile names (npm without one): the script
58
+ // finds the project's own tools, and its prebuild and postbuild run, as they do
59
+ // locally. A Yarn project on Plug'n'Play has no node_modules, so only Yarn
60
+ // finds its tools.
61
+ const extract = function (conf, manager) {
62
+ if (!Object.keys(conf).length) {
63
+ return {};
64
+ }
61
65
  const game = { version: conf.version };
62
- const workflow = conf.scripts?.build ? { build: NPM_RUN_BUILD } : {};
66
+ const workflow = conf.scripts?.build
67
+ ? { build: `${manager || "npm"} run build` }
68
+ : {};
63
69
  return deepCompact({ game, workflow }) ?? {};
64
70
  };
65
71
 
@@ -70,7 +76,7 @@ const main = function (root) {
70
76
  return pathExists(file)
71
77
  .then((exists) => (exists ? readFile(file, "utf8") : null))
72
78
  .then((buf) => (buf === null ? {} : parseJson(buf)))
73
- .then((conf) => (Object.keys(conf).length ? extract(conf) : {}));
79
+ .then((conf) => extract(conf, detect(root)));
74
80
  };
75
81
 
76
82
  // [export]
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const fs = require("node:fs");
6
+ const path = require("node:path");
7
+
8
+ // [use]
9
+
10
+ const existsSync = fs.existsSync; // eslint-disable-line no-sync
11
+ const join = path.join;
12
+
13
+ // [declare]
14
+
15
+ // each package manager, and the lockfiles that mean a project uses it, in the
16
+ // order they're checked, as the release tools' install checks them.
17
+ const LOCKFILES = [
18
+ ["npm", ["package-lock.json", "npm-shrinkwrap.json"]],
19
+ ["pnpm", ["pnpm-lock.yaml"]],
20
+ ["yarn", ["yarn.lock"]],
21
+ ];
22
+
23
+ // [function]
24
+
25
+ // the package manager a project's lockfile names, or "" when it has none.
26
+ const detect = function (root) {
27
+ const found = LOCKFILES.find(([, names]) =>
28
+ names.some((name) => existsSync(join(root, name))),
29
+ );
30
+ return found ? found[0] : "";
31
+ };
32
+
33
+ // [export]
34
+
35
+ module.exports = { detect };