@fynjs/run 1.1.6 → 1.1.7
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 +10 -10
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.7",
|
|
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",
|
|
@@ -88,29 +88,29 @@
|
|
|
88
88
|
"homepage": "https://github.com/jchip/fynjs/tree/main/packages/xarc-run",
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"chalk": "^6.0.0",
|
|
91
|
-
"chalker": "^2.1.
|
|
91
|
+
"chalker": "^2.1.6",
|
|
92
92
|
"insync": "^2.1.1",
|
|
93
93
|
"jaro-winkler": "^0.2.8",
|
|
94
|
-
"@fynjs/cli-args": "^1.1.
|
|
94
|
+
"@fynjs/cli-args": "^1.1.6",
|
|
95
95
|
"optional-require": "^2.1.0",
|
|
96
96
|
"read-package-up": "^12.0.0",
|
|
97
|
-
"string-array": "^2.1.
|
|
98
|
-
"unwrap-npm-cmd": "^2.1.
|
|
99
|
-
"xsh": "^1.1.
|
|
97
|
+
"string-array": "^2.1.6",
|
|
98
|
+
"unwrap-npm-cmd": "^2.1.6",
|
|
99
|
+
"xsh": "^1.1.7"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@fynjs/ts-resolve": "^1.0.3",
|
|
103
103
|
"@types/node": "^26.4.1",
|
|
104
104
|
"@vitest/coverage-v8": "^5.0.0",
|
|
105
|
-
"munchy": "^2.0.
|
|
105
|
+
"munchy": "^2.0.6",
|
|
106
106
|
"prettier": "^3.5.3",
|
|
107
|
-
"publish-util": "^3.1.
|
|
108
|
-
"run-verify": "^2.1.
|
|
107
|
+
"publish-util": "^3.1.6",
|
|
108
|
+
"run-verify": "^2.1.7",
|
|
109
109
|
"strip-ansi": "^7.2.0",
|
|
110
110
|
"typescript": "^7.0.2",
|
|
111
111
|
"vite": "^8.2.2",
|
|
112
112
|
"vitest": "^5.0.0",
|
|
113
|
-
"xaa": "^3.1.
|
|
113
|
+
"xaa": "^3.1.6",
|
|
114
114
|
"xstdout": "^0.1.1"
|
|
115
115
|
},
|
|
116
116
|
"type": "module"
|