unrun 0.2.6 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Gugustinette
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as unrunCli, r as unrunSync, t as unrun } from "./src-BW3bFBxp.mjs";
1
+ import { n as unrunCli, r as unrunSync, t as unrun } from "./src-BoMbIRQr.mjs";
2
2
 
3
3
  export { unrun, unrunCli, unrunSync };
@@ -1,4 +1,4 @@
1
- import { createRequire } from "node:module";
1
+ import { builtinModules, createRequire } from "node:module";
2
2
  import process from "node:process";
3
3
  import path from "node:path";
4
4
  import fs, { existsSync } from "node:fs";
@@ -74,6 +74,56 @@ function resolveOptions(options = {}) {
74
74
  return resolvedOptions;
75
75
  }
76
76
 
77
+ //#endregion
78
+ //#region src/utils/module-resolution.ts
79
+ /**
80
+ * Precomputed set of Node.js builtin module specifiers, including both plain and `node:` prefixed forms.
81
+ */
82
+ const BUILTIN_MODULE_SPECIFIERS = new Set([...builtinModules, ...builtinModules.map((name) => `node:${name}`)]);
83
+ /**
84
+ * Returns true when `id` refers to a Node.js builtin module, accepting both plain and `node:` specifiers.
85
+ */
86
+ function isBuiltinModuleSpecifier(id) {
87
+ if (!id) return false;
88
+ return BUILTIN_MODULE_SPECIFIERS.has(id) || id.startsWith("node:");
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
+
106
+ //#endregion
107
+ //#region src/features/external.ts
108
+ /**
109
+ * Builds the rolldown external resolver used to decide which imports remain external.
110
+ * Treat bare imports from the primary node_modules as external, but inline
111
+ * nested node_modules so they keep working once executed from .unrun.
112
+ */
113
+ function createExternalResolver(options) {
114
+ const projectNodeModules = path.resolve(process.cwd(), "node_modules");
115
+ return function external(id, importer) {
116
+ if (!id || id.startsWith("\0")) return false;
117
+ if (id.startsWith(".") || id.startsWith("#") || path.isAbsolute(id)) return false;
118
+ if (isBuiltinModuleSpecifier(id)) return true;
119
+ const importerPath = normalizeImporterPath(importer, options.path);
120
+ try {
121
+ if (!isPathWithinDirectory(projectNodeModules, createRequire(importerPath).resolve(id))) return false;
122
+ } catch {}
123
+ return true;
124
+ };
125
+ }
126
+
77
127
  //#endregion
78
128
  //#region src/plugins/console-output-customizer.ts
79
129
  /**
@@ -372,7 +422,7 @@ async function bundle(options) {
372
422
  const inputOptions = {
373
423
  input: options.path,
374
424
  platform: "node",
375
- external: (id) => !id.startsWith(".") && !path.isAbsolute(id) && !id.startsWith("#"),
425
+ external: createExternalResolver(options),
376
426
  plugins: [
377
427
  createMakeCjsWrapperAsyncFriendlyPlugin(),
378
428
  createRequireResolveFix(options),
@@ -1,4 +1,4 @@
1
- import { t as unrun } from "../src-BW3bFBxp.mjs";
1
+ import { t as unrun } from "../src-BoMbIRQr.mjs";
2
2
  import { runAsWorker } from "synckit";
3
3
 
4
4
  //#region src/sync/worker.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unrun",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "A tool to load and execute any JavaScript or TypeScript code at runtime.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@oxc-project/runtime": "^0.96.0",
43
- "rolldown": "1.0.0-beta.47"
43
+ "rolldown": "1.0.0-beta.49"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@sxzz/eslint-config": "^7.2.8",