unrun 0.2.16 → 0.2.18
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 +14 -10
- package/dist/cli.mjs +1 -0
- package/dist/index.mjs +1 -1
- package/dist/{src-Cy584dFT.mjs → src-OFTjuv5c.mjs} +39 -34
- package/dist/sync/worker.mjs +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -4,13 +4,9 @@
|
|
|
4
4
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
5
|
[![Unit Test][unit-test-src]][unit-test-href]
|
|
6
6
|
|
|
7
|
-
unrun is a tool that enables running any module at runtime (TypeScript, ESM, CJS, JSX, etc.) by bundling it with [Rolldown](https://rolldown.rs/).
|
|
7
|
+
unrun is a tool that enables running and loading any module at runtime (TypeScript, ESM, CJS, JSX, etc.) by bundling it with [Rolldown](https://rolldown.rs/).
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- [jiti](https://github.com/unjs/jiti)
|
|
12
|
-
- [bundle-require](https://github.com/egoist/bundle-require)
|
|
13
|
-
- [tsx](https://tsx.is/)
|
|
9
|
+
Check the [documentation](https://gugustinette.github.io/unrun/) for more details.
|
|
14
10
|
|
|
15
11
|
## Install
|
|
16
12
|
|
|
@@ -20,6 +16,12 @@ npm i unrun
|
|
|
20
16
|
|
|
21
17
|
## Usage
|
|
22
18
|
|
|
19
|
+
### CLI
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx unrun ./path/to/file.ts
|
|
23
|
+
```
|
|
24
|
+
|
|
23
25
|
### Programmatic API
|
|
24
26
|
|
|
25
27
|
- Async
|
|
@@ -42,11 +44,13 @@ const { module } = unrunSync({
|
|
|
42
44
|
})
|
|
43
45
|
```
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
## Credits
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
`unrun` is highly inspired by tools like :
|
|
50
|
+
|
|
51
|
+
- [jiti](https://github.com/unjs/jiti)
|
|
52
|
+
- [bundle-require](https://github.com/egoist/bundle-require)
|
|
53
|
+
- [tsx](https://tsx.is/)
|
|
50
54
|
|
|
51
55
|
<!-- Badges -->
|
|
52
56
|
|
package/dist/cli.mjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -87,21 +87,6 @@ function isBuiltinModuleSpecifier(id) {
|
|
|
87
87
|
if (!id) return false;
|
|
88
88
|
return BUILTIN_MODULE_SPECIFIERS.has(id) || id.startsWith("node:");
|
|
89
89
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Removes Rollup-style query/hash suffixes from importer paths, falling back when importer is virtual or missing.
|
|
92
|
-
*/
|
|
93
|
-
function normalizeImporterPath(importer, fallback) {
|
|
94
|
-
if (!importer || importer.startsWith("\0")) return fallback;
|
|
95
|
-
const [withoutQuery] = importer.split("?");
|
|
96
|
-
return withoutQuery || fallback;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Checks if `child` is inside `parent` directory.
|
|
100
|
-
*/
|
|
101
|
-
function isPathWithinDirectory(parent, child) {
|
|
102
|
-
const relative = path.relative(parent, child);
|
|
103
|
-
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
104
|
-
}
|
|
105
90
|
|
|
106
91
|
//#endregion
|
|
107
92
|
//#region src/features/external.ts
|
|
@@ -124,19 +109,10 @@ function createExternalResolver(options) {
|
|
|
124
109
|
}
|
|
125
110
|
return false;
|
|
126
111
|
};
|
|
127
|
-
return function external(id
|
|
112
|
+
return function external(id) {
|
|
128
113
|
if (!id || id.startsWith("\0")) return false;
|
|
129
114
|
if (id.startsWith(".") || id.startsWith("#") || path.isAbsolute(id)) return false;
|
|
130
115
|
if (isBuiltinModuleSpecifier(id)) return true;
|
|
131
|
-
const importerPath = normalizeImporterPath(importer, options.path);
|
|
132
|
-
try {
|
|
133
|
-
const containingNodeModules = findContainingNodeModules(createRequire(importerPath).resolve(id));
|
|
134
|
-
if (!containingNodeModules) return false;
|
|
135
|
-
const ownerDir = path.dirname(containingNodeModules);
|
|
136
|
-
const ownerInsideEntry = isPathWithinDirectory(entryDir, ownerDir);
|
|
137
|
-
const entryInsideOwner = isPathWithinDirectory(ownerDir, entryDir);
|
|
138
|
-
if (ownerInsideEntry && !entryInsideOwner) return false;
|
|
139
|
-
} catch {}
|
|
140
116
|
if (!canResolveFromEntry(id)) return false;
|
|
141
117
|
return true;
|
|
142
118
|
};
|
|
@@ -151,15 +127,6 @@ function getPackageName(specifier) {
|
|
|
151
127
|
const [name] = specifier.split("/");
|
|
152
128
|
return name || void 0;
|
|
153
129
|
}
|
|
154
|
-
function findContainingNodeModules(filePath) {
|
|
155
|
-
let current = path.dirname(filePath);
|
|
156
|
-
const { root } = path.parse(current);
|
|
157
|
-
while (true) {
|
|
158
|
-
if (path.basename(current) === "node_modules") return current;
|
|
159
|
-
if (current === root) break;
|
|
160
|
-
current = path.dirname(current);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
130
|
|
|
164
131
|
//#endregion
|
|
165
132
|
//#region src/plugins/console-output-customizer.ts
|
|
@@ -614,10 +581,48 @@ function execModule(moduleUrl, args = []) {
|
|
|
614
581
|
"inherit",
|
|
615
582
|
"inherit"
|
|
616
583
|
] });
|
|
584
|
+
const lifecycleSignals = [
|
|
585
|
+
"SIGINT",
|
|
586
|
+
"SIGTERM",
|
|
587
|
+
"SIGQUIT"
|
|
588
|
+
];
|
|
589
|
+
const signalListeners = /* @__PURE__ */ new Map();
|
|
590
|
+
let exitListener;
|
|
591
|
+
const cleanupChildProcess = (signal) => {
|
|
592
|
+
if (childProcess.killed || childProcess.exitCode !== null) return;
|
|
593
|
+
try {
|
|
594
|
+
childProcess.kill(signal);
|
|
595
|
+
} catch {}
|
|
596
|
+
};
|
|
597
|
+
const removeLifecycleListeners = () => {
|
|
598
|
+
if (exitListener) {
|
|
599
|
+
process.removeListener("exit", exitListener);
|
|
600
|
+
exitListener = void 0;
|
|
601
|
+
}
|
|
602
|
+
for (const [signal, listener] of signalListeners) process.removeListener(signal, listener);
|
|
603
|
+
signalListeners.clear();
|
|
604
|
+
};
|
|
605
|
+
exitListener = () => {
|
|
606
|
+
cleanupChildProcess();
|
|
607
|
+
};
|
|
608
|
+
process.on("exit", exitListener);
|
|
609
|
+
for (const signal of lifecycleSignals) {
|
|
610
|
+
const listener = () => {
|
|
611
|
+
cleanupChildProcess(signal);
|
|
612
|
+
removeLifecycleListeners();
|
|
613
|
+
process.nextTick(() => {
|
|
614
|
+
process.kill(process.pid, signal);
|
|
615
|
+
});
|
|
616
|
+
};
|
|
617
|
+
signalListeners.set(signal, listener);
|
|
618
|
+
process.on(signal, listener);
|
|
619
|
+
}
|
|
617
620
|
childProcess.on("close", (exitCode) => {
|
|
621
|
+
removeLifecycleListeners();
|
|
618
622
|
resolve({ exitCode: exitCode ?? 0 });
|
|
619
623
|
});
|
|
620
624
|
childProcess.on("error", (error) => {
|
|
625
|
+
removeLifecycleListeners();
|
|
621
626
|
reject(/* @__PURE__ */ new Error(`[unrun]: Failed to start child process: ${error.message}`));
|
|
622
627
|
});
|
|
623
628
|
});
|
package/dist/sync/worker.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unrun",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.18",
|
|
5
5
|
"description": "A tool to load and execute any JavaScript or TypeScript code at runtime.",
|
|
6
6
|
"author": "Augustin Mercier <gugustinette@proton.me>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"consola": "^3.4.2",
|
|
61
61
|
"defu": "^6.1.4",
|
|
62
62
|
"destr": "^2.0.5",
|
|
63
|
-
"esbuild": "^0.27.
|
|
63
|
+
"esbuild": "^0.27.1",
|
|
64
64
|
"eslint": "^9.39.1",
|
|
65
65
|
"estree-walker": "^3.0.3",
|
|
66
66
|
"etag": "^1.8.1",
|
|
@@ -75,26 +75,26 @@
|
|
|
75
75
|
"preact": "^10.28.0",
|
|
76
76
|
"preact-render-to-string": "^6.6.3",
|
|
77
77
|
"prettier": "^3.7.4",
|
|
78
|
-
"react": "^19.2.
|
|
79
|
-
"react-dom": "^19.2.
|
|
78
|
+
"react": "^19.2.1",
|
|
79
|
+
"react-dom": "^19.2.1",
|
|
80
80
|
"reflect-metadata": "^0.2.2",
|
|
81
81
|
"synckit": "^0.11.11",
|
|
82
82
|
"test-ecosystem-ci": "^0.0.2",
|
|
83
83
|
"tinyexec": "^1.0.2",
|
|
84
|
-
"tsdown": "^0.17.
|
|
84
|
+
"tsdown": "^0.17.1",
|
|
85
85
|
"tsx": "^4.21.0",
|
|
86
86
|
"typedoc": "^0.28.15",
|
|
87
87
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
88
88
|
"typedoc-vitepress-theme": "^1.1.2",
|
|
89
89
|
"typescript": "^5.9.3",
|
|
90
|
-
"unconfig": "^7.4.
|
|
91
|
-
"unplugin-vue": "^7.0
|
|
92
|
-
"vite": "^7.2.
|
|
90
|
+
"unconfig": "^7.4.2",
|
|
91
|
+
"unplugin-vue": "^7.1.0",
|
|
92
|
+
"vite": "^7.2.7",
|
|
93
93
|
"vitepress": "2.0.0-alpha.12",
|
|
94
94
|
"vitepress-plugin-group-icons": "^1.6.5",
|
|
95
95
|
"vitest": "4.0.15",
|
|
96
96
|
"vue": "^3.5.25",
|
|
97
|
-
"vue-tsc": "^3.1.
|
|
97
|
+
"vue-tsc": "^3.1.7",
|
|
98
98
|
"zod": "^4.1.13"
|
|
99
99
|
},
|
|
100
100
|
"prettier": "@sxzz/prettier-config",
|