@umijs/plugin-run 4.2.6-alpha.6 → 4.2.6
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/dist/index.d.ts +5 -0
- package/dist/index.js +108 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default,
|
|
33
|
+
getBinPath: () => getBinPath,
|
|
34
|
+
getFileNameByPath: () => getFileNameByPath
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var import_assert = __toESM(require("assert"));
|
|
38
|
+
var import_child_process = require("child_process");
|
|
39
|
+
var import_fs = require("fs");
|
|
40
|
+
var import_path = require("path");
|
|
41
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
42
|
+
var src_default = (api) => {
|
|
43
|
+
api.describe({
|
|
44
|
+
key: "run",
|
|
45
|
+
config: {
|
|
46
|
+
schema({ zod }) {
|
|
47
|
+
return zod.object({
|
|
48
|
+
globals: zod.array(zod.string()).optional()
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
api.registerCommand({
|
|
54
|
+
name: "run",
|
|
55
|
+
description: "run the script commands, support for ts and zx",
|
|
56
|
+
configResolveMode: "loose",
|
|
57
|
+
fn: ({ args }) => {
|
|
58
|
+
var _a;
|
|
59
|
+
const globals = ((_a = api.config.run) == null ? void 0 : _a.globals) || [];
|
|
60
|
+
const [scriptFilePath, ...restArgs] = args._;
|
|
61
|
+
const absScriptFilePath = (0, import_path.join)(api.cwd, scriptFilePath);
|
|
62
|
+
const fileName = getFileNameByPath(absScriptFilePath);
|
|
63
|
+
(0, import_assert.default)(fileName, `${absScriptFilePath} is not a valid file`);
|
|
64
|
+
(0, import_assert.default)(
|
|
65
|
+
/\.([jt])s$/.test(fileName),
|
|
66
|
+
`${fileName} is not a valid js or ts file`
|
|
67
|
+
);
|
|
68
|
+
const absTmpFilePath = (0, import_path.join)(
|
|
69
|
+
api.paths.absNodeModulesPath,
|
|
70
|
+
".cache",
|
|
71
|
+
"umi-plugin-run",
|
|
72
|
+
fileName
|
|
73
|
+
);
|
|
74
|
+
import_plugin_utils.fsExtra.mkdirpSync((0, import_path.dirname)(absTmpFilePath));
|
|
75
|
+
(0, import_fs.writeFileSync)(
|
|
76
|
+
absTmpFilePath,
|
|
77
|
+
`${globals.map(
|
|
78
|
+
(item) => `import '${item}'
|
|
79
|
+
`
|
|
80
|
+
)}import '${absScriptFilePath}';`,
|
|
81
|
+
"utf-8"
|
|
82
|
+
);
|
|
83
|
+
const tsxPath = getBinPath();
|
|
84
|
+
(0, import_child_process.fork)(tsxPath, [absTmpFilePath, ...restArgs], {
|
|
85
|
+
stdio: "inherit",
|
|
86
|
+
env: {
|
|
87
|
+
...process.env,
|
|
88
|
+
// disable `(node:92349) ExperimentalWarning: `--experimental-loader` may be removed in the future;` warning
|
|
89
|
+
// more context: https://github.com/umijs/umi/pull/11981
|
|
90
|
+
NODE_NO_WARNINGS: "1"
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
function getBinPath() {
|
|
97
|
+
const pkgPath = import_plugin_utils.resolve.sync("tsx/package.json", { basedir: __dirname });
|
|
98
|
+
const pkgContent = require(pkgPath);
|
|
99
|
+
return (0, import_path.join)((0, import_path.dirname)(pkgPath), pkgContent.bin);
|
|
100
|
+
}
|
|
101
|
+
function getFileNameByPath(params) {
|
|
102
|
+
return params.split("/").at(-1);
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
getBinPath,
|
|
107
|
+
getFileNameByPath
|
|
108
|
+
});
|
package/package.json
CHANGED