@fynjs/run 1.1.6 → 1.1.8
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 +5 -0
- package/dist/cli/env.d.ts +1 -0
- package/dist/cli/env.js +1 -0
- package/dist/cli/npm-loader.js +14 -2
- package/dist/cli/parse-cmd-args.js +5 -0
- package/dist/lib/util/npm-script-env.d.ts +12 -0
- package/dist/lib/util/npm-script-env.js +22 -0
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -31,6 +31,11 @@ Alias for the options:
|
|
|
31
31
|
|
|
32
32
|
- `-s`: `--serial`
|
|
33
33
|
|
|
34
|
+
npm scripts run through `xrun` get the same environment variables `npm run` sets, so scripts
|
|
35
|
+
that branch on them work unchanged: `npm_lifecycle_event`, `npm_lifecycle_script`,
|
|
36
|
+
`npm_package_name`, `npm_package_version`, `npm_package_json`, `npm_execpath`,
|
|
37
|
+
`npm_node_execpath`, `INIT_CWD`.
|
|
38
|
+
|
|
34
39
|
## Running JavaScript tasks
|
|
35
40
|
|
|
36
41
|
You can write your tasks in JavaScript and run them with `xrun`.
|
package/dist/cli/env.d.ts
CHANGED
package/dist/cli/env.js
CHANGED
package/dist/cli/npm-loader.js
CHANGED
|
@@ -2,6 +2,7 @@ import logger from "../lib/logger.js";
|
|
|
2
2
|
import chalk from "../lib/chalk.js";
|
|
3
3
|
import { readPackageUpSync } from "read-package-up";
|
|
4
4
|
import myPkg from "../lib/my-pkg.js";
|
|
5
|
+
import makeNpmScriptEnv from "../lib/util/npm-script-env.js";
|
|
5
6
|
import config from "./config.js";
|
|
6
7
|
import env from "./env.js";
|
|
7
8
|
export default (xrun, options) => {
|
|
@@ -13,14 +14,25 @@ export default (xrun, options) => {
|
|
|
13
14
|
const pkgName = chalk.magenta(readPkg.path.replace(process.cwd(), "."));
|
|
14
15
|
if (Pkg.scripts && options.npm !== false) {
|
|
15
16
|
const scripts = {};
|
|
17
|
+
const initCwd = env.get(env.xrunInitCwd) || process.cwd();
|
|
18
|
+
const npmExec = key => xrun.exec(Pkg.scripts[key], {
|
|
19
|
+
flags: "npm",
|
|
20
|
+
env: makeNpmScriptEnv({
|
|
21
|
+
pkgPath: readPkg.path,
|
|
22
|
+
pkgJson: Pkg,
|
|
23
|
+
scriptName: key,
|
|
24
|
+
scriptCmd: Pkg.scripts[key],
|
|
25
|
+
initCwd
|
|
26
|
+
})
|
|
27
|
+
});
|
|
16
28
|
for (const k in Pkg.scripts) {
|
|
17
29
|
if (!k.startsWith("pre") && !k.startsWith("post")) {
|
|
18
30
|
const pre = `pre${k}`;
|
|
19
31
|
const post = `post${k}`;
|
|
20
|
-
scripts[k] = xrun.serial(Pkg.scripts.hasOwnProperty(pre) && pre,
|
|
32
|
+
scripts[k] = xrun.serial(Pkg.scripts.hasOwnProperty(pre) && pre, npmExec(k), Pkg.scripts.hasOwnProperty(post) && post);
|
|
21
33
|
}
|
|
22
34
|
else {
|
|
23
|
-
scripts[k] =
|
|
35
|
+
scripts[k] = npmExec(k);
|
|
24
36
|
}
|
|
25
37
|
}
|
|
26
38
|
xrun.load("npm", scripts);
|
|
@@ -91,6 +91,11 @@ async function parseArgs(argv, start) {
|
|
|
91
91
|
env.set(env.xrunNodeBin, process.execPath);
|
|
92
92
|
// don't search if user has explicitly set CWD
|
|
93
93
|
const search = !opts.cwd;
|
|
94
|
+
// capture the true invocation directory once, before any chdir below, so npm scripts get an
|
|
95
|
+
// INIT_CWD that matches npm's semantics even across nested xrun calls in the same process
|
|
96
|
+
if (!env.has(env.xrunInitCwd)) {
|
|
97
|
+
env.set(env.xrunInitCwd, WrapProcess.cwd());
|
|
98
|
+
}
|
|
94
99
|
const saveCwd = env.get(env.xrunCwd);
|
|
95
100
|
opts.cwd = updateCwd(opts.cwd);
|
|
96
101
|
let searchResult = {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface MakeNpmScriptEnvOptions {
|
|
2
|
+
pkgPath: string;
|
|
3
|
+
pkgJson: {
|
|
4
|
+
name?: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
};
|
|
7
|
+
scriptName: string;
|
|
8
|
+
scriptCmd: string;
|
|
9
|
+
initCwd: string;
|
|
10
|
+
}
|
|
11
|
+
export default function makeNpmScriptEnv({ pkgPath, pkgJson, scriptName, scriptCmd, initCwd }: MakeNpmScriptEnvOptions): Record<string, string>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Path from "path";
|
|
2
|
+
import { myPkgDir } from "../my-pkg.js";
|
|
3
|
+
export default function makeNpmScriptEnv({ pkgPath, pkgJson, scriptName, scriptCmd, initCwd }) {
|
|
4
|
+
const node = process.env.NODE || process.execPath;
|
|
5
|
+
const env = {
|
|
6
|
+
npm_lifecycle_event: scriptName,
|
|
7
|
+
npm_lifecycle_script: scriptCmd,
|
|
8
|
+
npm_execpath: Path.join(myPkgDir, "bin", "xrun.js"),
|
|
9
|
+
npm_node_execpath: node,
|
|
10
|
+
NODE: node,
|
|
11
|
+
npm_package_json: pkgPath,
|
|
12
|
+
INIT_CWD: initCwd,
|
|
13
|
+
PWD: Path.dirname(pkgPath)
|
|
14
|
+
};
|
|
15
|
+
if (pkgJson.name) {
|
|
16
|
+
env.npm_package_name = pkgJson.name;
|
|
17
|
+
}
|
|
18
|
+
if (pkgJson.version) {
|
|
19
|
+
env.npm_package_version = pkgJson.version;
|
|
20
|
+
}
|
|
21
|
+
return env;
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fynjs/run",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "concurrent or serial run npm scripts, javascript tasks, and more",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"types": "./dist/lib/index.d.ts",
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
"directory": "packages/xarc-run"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
|
-
"access": "public"
|
|
46
|
-
"registry": "https://registry.npmjs.com/"
|
|
45
|
+
"access": "public"
|
|
47
46
|
},
|
|
48
47
|
"files": [
|
|
49
48
|
"dist",
|
|
@@ -88,29 +87,29 @@
|
|
|
88
87
|
"homepage": "https://github.com/jchip/fynjs/tree/main/packages/xarc-run",
|
|
89
88
|
"dependencies": {
|
|
90
89
|
"chalk": "^6.0.0",
|
|
91
|
-
"chalker": "^2.
|
|
90
|
+
"chalker": "^2.2.0",
|
|
92
91
|
"insync": "^2.1.1",
|
|
93
92
|
"jaro-winkler": "^0.2.8",
|
|
94
|
-
"@fynjs/cli-args": "^1.1.
|
|
93
|
+
"@fynjs/cli-args": "^1.1.7",
|
|
95
94
|
"optional-require": "^2.1.0",
|
|
96
95
|
"read-package-up": "^12.0.0",
|
|
97
|
-
"string-array": "^2.1.
|
|
98
|
-
"unwrap-npm-cmd": "^2.1.
|
|
99
|
-
"xsh": "^1.1.
|
|
96
|
+
"string-array": "^2.1.7",
|
|
97
|
+
"unwrap-npm-cmd": "^2.1.7",
|
|
98
|
+
"xsh": "^1.1.8"
|
|
100
99
|
},
|
|
101
100
|
"devDependencies": {
|
|
102
101
|
"@fynjs/ts-resolve": "^1.0.3",
|
|
103
102
|
"@types/node": "^26.4.1",
|
|
104
103
|
"@vitest/coverage-v8": "^5.0.0",
|
|
105
|
-
"munchy": "^2.0.
|
|
104
|
+
"munchy": "^2.0.7",
|
|
106
105
|
"prettier": "^3.5.3",
|
|
107
|
-
"publish-util": "^3.1.
|
|
108
|
-
"run-verify": "^2.1.
|
|
106
|
+
"publish-util": "^3.1.7",
|
|
107
|
+
"run-verify": "^2.1.8",
|
|
109
108
|
"strip-ansi": "^7.2.0",
|
|
110
109
|
"typescript": "^7.0.2",
|
|
111
110
|
"vite": "^8.2.2",
|
|
112
111
|
"vitest": "^5.0.0",
|
|
113
|
-
"xaa": "^3.1.
|
|
112
|
+
"xaa": "^3.1.7",
|
|
114
113
|
"xstdout": "^0.1.1"
|
|
115
114
|
},
|
|
116
115
|
"type": "module"
|