@sushichan044/eslint-config-array-resolver 0.2.1 → 0.2.2

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.
@@ -0,0 +1,32 @@
1
+ Name: unrun
2
+ Version: 0.2.26
3
+ License: MIT
4
+ Private: false
5
+ Description: A tool to load and execute any JavaScript or TypeScript code at runtime.
6
+ Repository: git+https://github.com/Gugustinette/unrun.git
7
+ Homepage: https://gugustinette.github.io/unrun/
8
+ Author: Augustin Mercier <gugustinette@proton.me>
9
+ License Copyright:
10
+ ===
11
+
12
+ MIT License
13
+
14
+ Copyright (c) 2025 Gugustinette
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all
24
+ copies or substantial portions of the Software.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ SOFTWARE.
package/dist/index.mjs CHANGED
@@ -1,7 +1,666 @@
1
+ import { builtinModules, createRequire } from "node:module";
1
2
  import { any } from "empathic/find";
2
3
  import { resolve } from "mlly";
3
4
  import { dirname, normalize } from "pathe";
4
- import { unrun } from "unrun";
5
+ import path from "node:path";
6
+ import fs, { existsSync } from "node:fs";
7
+ import process$1 from "node:process";
8
+ import { fileURLToPath, pathToFileURL } from "node:url";
9
+ import { rolldown } from "rolldown";
10
+ import { Buffer } from "node:buffer";
11
+ import crypto from "node:crypto";
12
+ import { tmpdir } from "node:os";
13
+ import.meta.url;
14
+ function preset(options, module) {
15
+ if (options.preset === "bundle-require") return module;
16
+ if (options.preset === "jiti") {
17
+ const ext = path.extname(options.path);
18
+ if (module && typeof module === "object" && module[Symbol.toStringTag] === "Module" && Object.keys(module).length === 0) return ext === ".mjs" ? module : {};
19
+ }
20
+ if (module && typeof module === "object" && "default" in module) return module.default;
21
+ return module;
22
+ }
23
+ function normalizePath(pathLike) {
24
+ if (!pathLike) return "index.ts";
25
+ if (pathLike instanceof URL) {
26
+ if (pathLike.protocol === "file:") return fileURLToPath(pathLike);
27
+ return pathLike.href;
28
+ }
29
+ if (typeof pathLike === "string") {
30
+ if (!pathLike.startsWith("file:")) return pathLike;
31
+ try {
32
+ return fileURLToPath(pathLike);
33
+ } catch {
34
+ try {
35
+ return fileURLToPath(new URL(pathLike));
36
+ } catch {
37
+ return pathLike;
38
+ }
39
+ }
40
+ }
41
+ return String(pathLike);
42
+ }
43
+ function resolveOptions(options = {}) {
44
+ const resolvedOptions = {
45
+ path: path.resolve(process$1.cwd(), normalizePath(options.path)),
46
+ debug: options.debug || false,
47
+ preset: options.preset || "none",
48
+ inputOptions: options.inputOptions,
49
+ outputOptions: options.outputOptions
50
+ };
51
+ if (!fs.existsSync(resolvedOptions.path)) throw new Error(`[unrun] File not found: ${resolvedOptions.path}`);
52
+ if (!new Set([
53
+ "none",
54
+ "jiti",
55
+ "bundle-require"
56
+ ]).has(resolvedOptions.preset)) throw new Error(`[unrun] Invalid preset "${resolvedOptions.preset}" (expected: none | jiti | bundle-require)`);
57
+ return resolvedOptions;
58
+ }
59
+ const BUILTIN_MODULE_SPECIFIERS = new Set([...builtinModules, ...builtinModules.map((name) => `node:${name}`)]);
60
+ function isBuiltinModuleSpecifier(id) {
61
+ if (!id) return false;
62
+ return BUILTIN_MODULE_SPECIFIERS.has(id) || id.startsWith("node:");
63
+ }
64
+ function createExternalResolver(options) {
65
+ const entryDir = path.dirname(options.path);
66
+ const canResolveFromEntry = (specifier) => {
67
+ const packageName = getPackageName(specifier);
68
+ if (!packageName) return false;
69
+ let currentDir = entryDir;
70
+ while (true) {
71
+ if (existsSync(path.join(currentDir, "node_modules", packageName))) return true;
72
+ const parentDir = path.dirname(currentDir);
73
+ if (parentDir === currentDir) break;
74
+ currentDir = parentDir;
75
+ }
76
+ return false;
77
+ };
78
+ return function external(id) {
79
+ if (!id || id.startsWith("\0")) return false;
80
+ if (id.startsWith(".") || id.startsWith("#") || path.isAbsolute(id)) return false;
81
+ if (isBuiltinModuleSpecifier(id)) return true;
82
+ if (!canResolveFromEntry(id)) return false;
83
+ return true;
84
+ };
85
+ }
86
+ function getPackageName(specifier) {
87
+ if (!specifier) return void 0;
88
+ if (specifier.startsWith("@")) {
89
+ const segments = specifier.split("/");
90
+ if (segments.length >= 2) return `${segments[0]}/${segments[1]}`;
91
+ return;
92
+ }
93
+ const [name] = specifier.split("/");
94
+ return name || void 0;
95
+ }
96
+ const INSPECT_HELPER_SNIPPET = `(function(){
97
+ function __unrun__fmt(names, getter, np){
98
+ var onlyDefault = names.length === 1 && names[0] === "default";
99
+ var o = np ? Object.create(null) : {};
100
+ for (var i = 0; i < names.length; i++) {
101
+ var n = names[i];
102
+ try { o[n] = getter(n) } catch {}
103
+ }
104
+ if (onlyDefault) {
105
+ try {
106
+ var s = JSON.stringify(o.default);
107
+ if (s !== undefined) {
108
+ s = s.replace(/"([^"]+)":/g, "$1: ").replace(/,/g, ", ").replace(/{/g, "{ ").replace(/}/g, " }");
109
+ return "[Module: null prototype] { default: " + s + " }";
110
+ }
111
+ } catch {}
112
+ return "[Module: null prototype] { default: " + String(o.default) + " }";
113
+ }
114
+ return o;
115
+ }
116
+ function __unrun__setInspect(obj, names, getter, np){
117
+ try {
118
+ var __insp = Symbol.for('nodejs.util.inspect.custom');
119
+ Object.defineProperty(obj, __insp, {
120
+ value: function(){ return __unrun__fmt(names, getter, np) },
121
+ enumerable: false, configurable: true
122
+ });
123
+ } catch {}
124
+ return obj;
125
+ }
126
+ try {
127
+ Object.defineProperty(globalThis, "__unrun__setInspect", {
128
+ value: __unrun__setInspect,
129
+ enumerable: false,
130
+ });
131
+ } catch {}
132
+ })();`;
133
+ const WRAPPER_SNIPPET = `(function __unrun__wrapRolldownHelpers(){
134
+ if (typeof __unrun__setInspect !== "function") return;
135
+ if (typeof __export === "function" && !__export.__unrunPatched) {
136
+ var __unrun__origExport = __export;
137
+ var __unrun__patchedExport = (...__unrun__args) => {
138
+ var __unrun__target = __unrun__origExport(...__unrun__args);
139
+ if (__unrun__target && typeof __unrun__target === "object") {
140
+ try {
141
+ var __unrun__map = (__unrun__args[0] && typeof __unrun__args[0] === "object") ? __unrun__args[0] : {};
142
+ var __unrun__names = Object.keys(__unrun__map).filter(function(n){ return n !== "__esModule" });
143
+ __unrun__setInspect(
144
+ __unrun__target,
145
+ __unrun__names,
146
+ function(n){
147
+ var getter = __unrun__map[n];
148
+ return typeof getter === "function" ? getter() : getter;
149
+ },
150
+ false,
151
+ );
152
+ } catch {}
153
+ }
154
+ return __unrun__target;
155
+ };
156
+ __unrun__patchedExport.__unrunPatched = true;
157
+ __export = __unrun__patchedExport;
158
+ }
159
+ if (typeof __exportAll === "function" && !__exportAll.__unrunPatched) {
160
+ var __unrun__origExportAll = __exportAll;
161
+ var __unrun__patchedExportAll = (...__unrun__args) => {
162
+ var __unrun__target = __unrun__origExportAll(...__unrun__args);
163
+ if (__unrun__target && typeof __unrun__target === "object") {
164
+ try {
165
+ var __unrun__map = (__unrun__args[0] && typeof __unrun__args[0] === "object") ? __unrun__args[0] : {};
166
+ var __unrun__names = Object.keys(__unrun__map).filter(function(n){ return n !== "__esModule" });
167
+ __unrun__setInspect(
168
+ __unrun__target,
169
+ __unrun__names,
170
+ function(n){
171
+ var getter = __unrun__map[n];
172
+ return typeof getter === "function" ? getter() : getter;
173
+ },
174
+ false,
175
+ );
176
+ } catch {}
177
+ }
178
+ return __unrun__target;
179
+ };
180
+ __unrun__patchedExportAll.__unrunPatched = true;
181
+ __exportAll = __unrun__patchedExportAll;
182
+ }
183
+ if (typeof __copyProps === "function" && !__copyProps.__unrunPatched) {
184
+ var __unrun__origCopyProps = __copyProps;
185
+ var __unrun__patchedCopyProps = (...__unrun__args) => {
186
+ var __unrun__result = __unrun__origCopyProps(...__unrun__args);
187
+ if (__unrun__result && typeof __unrun__result === "object") {
188
+ try {
189
+ var __unrun__names = Object.keys(__unrun__result).filter(function(n){ return n !== "__esModule" });
190
+ __unrun__setInspect(__unrun__result, __unrun__names, function(n){ return __unrun__result[n] }, true);
191
+ } catch {}
192
+ }
193
+ return __unrun__result;
194
+ };
195
+ __unrun__patchedCopyProps.__unrunPatched = true;
196
+ __copyProps = __unrun__patchedCopyProps;
197
+ }
198
+ })();`;
199
+ const HELPER_DECLARATION_PATTERN = /__unrun__setInspect\b/;
200
+ const WRAPPER_MARKER = "__unrun__wrapRolldownHelpers";
201
+ function createConsoleOutputCustomizer() {
202
+ return {
203
+ name: "unrun-console-output-customizer",
204
+ generateBundle: { handler(_, bundle$1) {
205
+ for (const chunk of Object.values(bundle$1)) {
206
+ if (chunk.type !== "chunk") continue;
207
+ injectInspectHelper(chunk);
208
+ injectHelperWrappers(chunk);
209
+ }
210
+ } }
211
+ };
212
+ }
213
+ function injectInspectHelper(chunk) {
214
+ if (HELPER_DECLARATION_PATTERN.test(chunk.code)) return;
215
+ chunk.code = chunk.code.startsWith("#!") ? insertAfterShebang(chunk.code, `${INSPECT_HELPER_SNIPPET}\n`) : `${INSPECT_HELPER_SNIPPET}\n${chunk.code}`;
216
+ }
217
+ function injectHelperWrappers(chunk) {
218
+ if (chunk.code.includes(WRAPPER_MARKER)) return;
219
+ const insertIndex = findRuntimeBoundary(chunk.code);
220
+ const snippet = `${WRAPPER_SNIPPET}\n`;
221
+ if (insertIndex === -1) {
222
+ chunk.code = `${chunk.code}\n${snippet}`;
223
+ return;
224
+ }
225
+ chunk.code = `${chunk.code.slice(0, insertIndex)}${snippet}${chunk.code.slice(insertIndex)}`;
226
+ }
227
+ function findRuntimeBoundary(code) {
228
+ const markerIndex = code.indexOf("//#endregion");
229
+ if (markerIndex === -1) return -1;
230
+ const newlineIndex = code.indexOf("\n", markerIndex);
231
+ return newlineIndex === -1 ? code.length : newlineIndex + 1;
232
+ }
233
+ function insertAfterShebang(code, insertion) {
234
+ const nl = code.indexOf("\n");
235
+ if (nl === -1) return `${code}\n${insertion}`;
236
+ return `${code.slice(0, nl + 1)}${insertion}${code.slice(nl + 1)}`;
237
+ }
238
+ function createJsonLoader() {
239
+ return {
240
+ name: "unrun-json-loader",
241
+ resolveId: { handler(source, importer) {
242
+ if (!source.endsWith(".json")) return null;
243
+ const basedir = importer ? path.dirname(importer) : process$1.cwd();
244
+ const resolved = path.resolve(basedir, source);
245
+ let isRequire = false;
246
+ try {
247
+ if (importer) {
248
+ const src = fs.readFileSync(importer, "utf8");
249
+ const escaped = source.replaceAll(/[.*+?^${}()|[\]\\]/g, (m) => `\\${m}`);
250
+ const pattern = String.raw`\brequire\s*\(\s*['"]${escaped}['"]\s*\)`;
251
+ isRequire = new RegExp(pattern).test(src);
252
+ }
253
+ } catch {}
254
+ return { id: `${resolved}?unrun-json.${isRequire ? "cjs" : "mjs"}` };
255
+ } },
256
+ load: {
257
+ filter: { id: /\?unrun-json\.(?:mjs|cjs)$/ },
258
+ handler(id) {
259
+ try {
260
+ const realId = id.replace(/\?unrun-json\.(?:mjs|cjs)$/, "");
261
+ const src = fs.readFileSync(realId, "utf8");
262
+ const data = JSON.parse(src);
263
+ const jsonLiteral = JSON.stringify(data);
264
+ if (id.endsWith("?unrun-json.cjs")) return { code: `const __data = ${jsonLiteral}\ntry { Object.defineProperty(__data, 'default', { value: __data, enumerable: false, configurable: true }) } catch {}\nmodule.exports = __data\n` };
265
+ const named = Object.keys(data).filter((k) => /^[$A-Z_]\w*$/i.test(k)).map((k) => `export const ${k} = __data[${JSON.stringify(k)}]`).join("\n");
266
+ return { code: [
267
+ `const __data = ${jsonLiteral}`,
268
+ `try { Object.defineProperty(__data, 'default', { value: __data, enumerable: false, configurable: true }) } catch {}`,
269
+ named,
270
+ `export default __data`
271
+ ].filter(Boolean).join("\n") };
272
+ } catch {
273
+ return null;
274
+ }
275
+ }
276
+ }
277
+ };
278
+ }
279
+ function createMakeCjsWrapperAsyncFriendlyPlugin() {
280
+ return {
281
+ name: "unrun-make-cjs-wrapper-async-friendly",
282
+ generateBundle: { handler(_outputOptions, bundle$1) {
283
+ for (const chunk of Object.values(bundle$1)) {
284
+ if (chunk.type !== "chunk") continue;
285
+ let code = chunk.code;
286
+ const wrapperMarkers = ["__commonJS({", "__commonJSMin("];
287
+ if (!wrapperMarkers.some((marker) => code.includes(marker))) continue;
288
+ const arrowToken = "(() => {";
289
+ const asyncArrowToken = "(async () => {";
290
+ const patchMarker = (marker) => {
291
+ let pos = 0;
292
+ while (true) {
293
+ const markerIdx = code.indexOf(marker, pos);
294
+ if (markerIdx === -1) break;
295
+ const fnStart = code.indexOf(arrowToken, markerIdx);
296
+ if (fnStart === -1) {
297
+ pos = markerIdx + marker.length;
298
+ continue;
299
+ }
300
+ const bodyStart = fnStart + 8;
301
+ let i = bodyStart;
302
+ let depth = 1;
303
+ while (i < code.length && depth > 0) {
304
+ const ch = code[i++];
305
+ if (ch === "{") depth++;
306
+ else if (ch === "}") depth--;
307
+ }
308
+ if (depth !== 0) break;
309
+ const bodyEnd = i - 1;
310
+ const body = code.slice(bodyStart, bodyEnd);
311
+ if (/\bawait\b/.test(body) && code.slice(fnStart, fnStart + 14) !== asyncArrowToken) {
312
+ code = `${code.slice(0, fnStart + 1)}async ${code.slice(fnStart + 1)}`;
313
+ pos = fnStart + 1 + 6;
314
+ continue;
315
+ }
316
+ pos = bodyEnd;
317
+ }
318
+ };
319
+ for (const marker of wrapperMarkers) patchMarker(marker);
320
+ if (code !== chunk.code) chunk.code = code;
321
+ }
322
+ } }
323
+ };
324
+ }
325
+ function createRequireResolveFix(options) {
326
+ return {
327
+ name: "unrun-require-resolve-fix",
328
+ generateBundle: { handler(_, bundle$1) {
329
+ for (const chunk of Object.values(bundle$1)) if (chunk.type === "chunk") chunk.code = chunk.code.replaceAll(/__require\.resolve\(["']([^"']+)["']\)/g, (match, id) => {
330
+ if (id.startsWith("./") || id.startsWith("../")) try {
331
+ const baseDir = path.dirname(options.path);
332
+ for (const ext of [
333
+ "",
334
+ ".ts",
335
+ ".js",
336
+ ".mts",
337
+ ".mjs",
338
+ ".cts",
339
+ ".cjs"
340
+ ]) {
341
+ const testPath = path.resolve(baseDir, id + ext);
342
+ if (fs.existsSync(testPath)) return JSON.stringify(testPath);
343
+ }
344
+ const resolvedPath = path.resolve(baseDir, id);
345
+ return JSON.stringify(resolvedPath);
346
+ } catch {
347
+ return match;
348
+ }
349
+ return match;
350
+ });
351
+ } }
352
+ };
353
+ }
354
+ function createRequireTypeofFix() {
355
+ return {
356
+ name: "unrun-require-typeof-fix",
357
+ generateBundle: { handler(_, bundle$1) {
358
+ for (const chunk of Object.values(bundle$1)) if (chunk.type === "chunk") chunk.code = chunk.code.replaceAll(/\btypeof\s+__require\b/g, "typeof require");
359
+ } }
360
+ };
361
+ }
362
+ function createSourceContextShimsPlugin() {
363
+ return {
364
+ name: "unrun-source-context-shims",
365
+ load: {
366
+ filter: { id: /\.(?:m?[jt]s|c?tsx?)(?:$|\?)/ },
367
+ handler(id) {
368
+ const physicalId = id.split("?")[0].split("#")[0];
369
+ const normalizedPhysicalId = path.normalize(physicalId);
370
+ let code;
371
+ try {
372
+ code = fs.readFileSync(normalizedPhysicalId, "utf8");
373
+ } catch {
374
+ return null;
375
+ }
376
+ if (normalizedPhysicalId.replaceAll("\\", "/").includes("/node_modules/")) return null;
377
+ const file = normalizedPhysicalId;
378
+ const dir = path.dirname(normalizedPhysicalId);
379
+ const url = pathToFileURL(normalizedPhysicalId).href;
380
+ const hasImportMeta = code.includes("import.meta");
381
+ const usesFilename = /\b__filename\b/.test(code);
382
+ const declaresFilename = /\b(?:const|let|var)\s+__filename\b/.test(code);
383
+ const usesDirname = /\b__dirname\b/.test(code);
384
+ const declaresDirname = /\b(?:const|let|var)\s+__dirname\b/.test(code);
385
+ const needsFilenameShim = usesFilename && !declaresFilename;
386
+ const needsDirnameShim = usesDirname && !declaresDirname;
387
+ if (needsFilenameShim || needsDirnameShim || hasImportMeta) {
388
+ const prologueLines = [];
389
+ if (needsFilenameShim) prologueLines.push(`const __filename = ${JSON.stringify(file)}`);
390
+ if (needsDirnameShim) prologueLines.push(`const __dirname = ${JSON.stringify(dir)}`);
391
+ let transformedCode = code;
392
+ let replacedImportMeta = false;
393
+ if (hasImportMeta) {
394
+ const resolveRe = /import\s*\.\s*meta\s*\.\s*resolve!?\s*\(\s*(["'])([^"']+)\1\s*\)/y;
395
+ const urlRe = /import\s*\.\s*meta\s*\.\s*url\b/y;
396
+ const dirnameRe = /import\s*\.\s*meta\s*\.\s*dirname\b/y;
397
+ const filenameRe = /import\s*\.\s*meta\s*\.\s*filename\b/y;
398
+ let out = "";
399
+ let mode = "normal";
400
+ const modeStack = [];
401
+ let templateExprBraceDepth = 0;
402
+ const popMode = () => {
403
+ mode = modeStack.pop() ?? "normal";
404
+ };
405
+ for (let i = 0; i < transformedCode.length;) {
406
+ const ch = transformedCode[i];
407
+ const next = transformedCode[i + 1];
408
+ if (mode === "lineComment") {
409
+ out += ch;
410
+ i += 1;
411
+ if (ch === "\n") popMode();
412
+ continue;
413
+ }
414
+ if (mode === "blockComment") {
415
+ out += ch;
416
+ i += 1;
417
+ if (ch === "*" && next === "/") {
418
+ out += "/";
419
+ i += 1;
420
+ popMode();
421
+ }
422
+ continue;
423
+ }
424
+ if (mode === "single") {
425
+ out += ch;
426
+ i += 1;
427
+ if (ch === "\\") {
428
+ out += transformedCode[i] ?? "";
429
+ i += 1;
430
+ continue;
431
+ }
432
+ if (ch === "'") popMode();
433
+ continue;
434
+ }
435
+ if (mode === "double") {
436
+ out += ch;
437
+ i += 1;
438
+ if (ch === "\\") {
439
+ out += transformedCode[i] ?? "";
440
+ i += 1;
441
+ continue;
442
+ }
443
+ if (ch === "\"") popMode();
444
+ continue;
445
+ }
446
+ if (mode === "template") {
447
+ out += ch;
448
+ i += 1;
449
+ if (ch === "\\") {
450
+ out += transformedCode[i] ?? "";
451
+ i += 1;
452
+ continue;
453
+ }
454
+ if (ch === "`") {
455
+ popMode();
456
+ continue;
457
+ }
458
+ if (ch === "$" && next === "{") {
459
+ out += "{";
460
+ i += 1;
461
+ modeStack.push(mode);
462
+ mode = "templateExpr";
463
+ templateExprBraceDepth = 1;
464
+ }
465
+ continue;
466
+ }
467
+ if (mode === "templateExpr") {
468
+ if (ch === "{") templateExprBraceDepth += 1;
469
+ else if (ch === "}") {
470
+ templateExprBraceDepth -= 1;
471
+ if (templateExprBraceDepth === 0) {
472
+ out += ch;
473
+ i += 1;
474
+ popMode();
475
+ continue;
476
+ }
477
+ }
478
+ }
479
+ if (ch === "/" && next === "/") {
480
+ out += "//";
481
+ i += 2;
482
+ modeStack.push(mode);
483
+ mode = "lineComment";
484
+ continue;
485
+ }
486
+ if (ch === "/" && next === "*") {
487
+ out += "/*";
488
+ i += 2;
489
+ modeStack.push(mode);
490
+ mode = "blockComment";
491
+ continue;
492
+ }
493
+ if (ch === "'") {
494
+ out += ch;
495
+ i += 1;
496
+ modeStack.push(mode);
497
+ mode = "single";
498
+ continue;
499
+ }
500
+ if (ch === "\"") {
501
+ out += ch;
502
+ i += 1;
503
+ modeStack.push(mode);
504
+ mode = "double";
505
+ continue;
506
+ }
507
+ if (ch === "`") {
508
+ out += ch;
509
+ i += 1;
510
+ modeStack.push(mode);
511
+ mode = "template";
512
+ continue;
513
+ }
514
+ resolveRe.lastIndex = i;
515
+ const resolveMatch = resolveRe.exec(transformedCode);
516
+ if (resolveMatch) {
517
+ const spec = resolveMatch[2];
518
+ const resolvedUrl = pathToFileURL(path.resolve(path.dirname(normalizedPhysicalId), spec)).href;
519
+ out += JSON.stringify(resolvedUrl);
520
+ i = resolveRe.lastIndex;
521
+ replacedImportMeta = true;
522
+ continue;
523
+ }
524
+ urlRe.lastIndex = i;
525
+ if (urlRe.test(transformedCode)) {
526
+ out += JSON.stringify(url);
527
+ i = urlRe.lastIndex;
528
+ replacedImportMeta = true;
529
+ continue;
530
+ }
531
+ dirnameRe.lastIndex = i;
532
+ if (dirnameRe.test(transformedCode)) {
533
+ out += JSON.stringify(dir);
534
+ i = dirnameRe.lastIndex;
535
+ replacedImportMeta = true;
536
+ continue;
537
+ }
538
+ filenameRe.lastIndex = i;
539
+ if (filenameRe.test(transformedCode)) {
540
+ out += JSON.stringify(file);
541
+ i = filenameRe.lastIndex;
542
+ replacedImportMeta = true;
543
+ continue;
544
+ }
545
+ out += ch;
546
+ i += 1;
547
+ }
548
+ if (replacedImportMeta) transformedCode = out;
549
+ }
550
+ if (prologueLines.length > 0) transformedCode = `${prologueLines.join("\n")}\n${transformedCode}`;
551
+ if (transformedCode !== code) return { code: transformedCode };
552
+ }
553
+ return null;
554
+ }
555
+ }
556
+ };
557
+ }
558
+ async function bundle(options) {
559
+ const resolvedTsconfigPath = path.resolve(process$1.cwd(), "tsconfig.json");
560
+ const tsconfig = existsSync(resolvedTsconfigPath) ? resolvedTsconfigPath : void 0;
561
+ const inputOptions = {
562
+ input: options.path,
563
+ platform: "node",
564
+ external: createExternalResolver(options),
565
+ plugins: [
566
+ createMakeCjsWrapperAsyncFriendlyPlugin(),
567
+ createRequireResolveFix(options),
568
+ createSourceContextShimsPlugin(),
569
+ ...options.preset === "jiti" ? [
570
+ createConsoleOutputCustomizer(),
571
+ createJsonLoader(),
572
+ createRequireTypeofFix()
573
+ ] : []
574
+ ],
575
+ transform: { define: {
576
+ __dirname: JSON.stringify(path.dirname(options.path)),
577
+ __filename: JSON.stringify(options.path),
578
+ "import.meta.url": JSON.stringify(pathToFileURL(options.path).href),
579
+ "import.meta.filename": JSON.stringify(options.path),
580
+ "import.meta.dirname": JSON.stringify(path.dirname(options.path)),
581
+ "import.meta.env": "process.env"
582
+ } },
583
+ logLevel: "silent",
584
+ ...options.inputOptions
585
+ };
586
+ if (tsconfig) inputOptions.tsconfig = tsconfig;
587
+ const bundle = await rolldown(inputOptions);
588
+ const outputOptions = {
589
+ format: "esm",
590
+ codeSplitting: false,
591
+ keepNames: true,
592
+ ...options.outputOptions
593
+ };
594
+ const rolldownOutput = await bundle.generate(outputOptions);
595
+ if (!rolldownOutput.output[0]) throw new Error("[unrun] No output chunk found");
596
+ const files = await bundle.watchFiles;
597
+ return {
598
+ chunk: rolldownOutput.output[0],
599
+ dependencies: files
600
+ };
601
+ }
602
+ function cleanModule(moduleUrl, options) {
603
+ if (options.debug) return;
604
+ try {
605
+ if (moduleUrl.startsWith("file://")) {
606
+ const filePath = new URL(moduleUrl);
607
+ fs.unlinkSync(filePath);
608
+ }
609
+ } catch (error) {
610
+ if (error.code !== "ENOENT") throw error;
611
+ }
612
+ }
613
+ function sanitize(name) {
614
+ return name.replaceAll(/[^\w.-]/g, "_");
615
+ }
616
+ function writeModule(code, options) {
617
+ const filenameHint = path.basename(options.path);
618
+ let moduleUrl = "";
619
+ try {
620
+ const randomKey = crypto.randomBytes(16).toString("hex");
621
+ const fname = `${filenameHint ? `${sanitize(filenameHint)}.` : ""}${randomKey}.mjs`;
622
+ const outDir = process$1.cwd();
623
+ const outFile = path.join(outDir, fname);
624
+ if (!fs.existsSync(outFile)) try {
625
+ fs.mkdirSync(outDir, { recursive: true });
626
+ fs.writeFileSync(outFile, code, "utf8");
627
+ } catch {
628
+ const fallbackDir = path.join(tmpdir(), "unrun-cache");
629
+ const fallbackFile = path.join(fallbackDir, fname);
630
+ fs.mkdirSync(fallbackDir, { recursive: true });
631
+ fs.writeFileSync(fallbackFile, code, "utf8");
632
+ moduleUrl = pathToFileURL(fallbackFile).href;
633
+ }
634
+ moduleUrl = moduleUrl || pathToFileURL(outFile).href;
635
+ } catch {
636
+ moduleUrl = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
637
+ }
638
+ return moduleUrl;
639
+ }
640
+ async function loadModule(code, options) {
641
+ const moduleUrl = writeModule(code, options);
642
+ let _module;
643
+ try {
644
+ _module = await import(moduleUrl);
645
+ } finally {
646
+ cleanModule(moduleUrl, options);
647
+ }
648
+ return _module;
649
+ }
650
+ async function unrun(options) {
651
+ const resolvedOptions = resolveOptions(options);
652
+ const output = await bundle(resolvedOptions);
653
+ let module;
654
+ try {
655
+ module = await loadModule(output.chunk.code, resolvedOptions);
656
+ } catch (error) {
657
+ throw new Error(`[unrun] Import failed (code length: ${output.chunk.code.length}): ${error.message}`);
658
+ }
659
+ return {
660
+ module: preset(resolvedOptions, module),
661
+ dependencies: output.dependencies
662
+ };
663
+ }
5
664
  const runInDirectory = async (directory, function_) => {
6
665
  const cwd = process.cwd();
7
666
  process.chdir(directory);
@@ -66,8 +725,8 @@ const resolveFlatConfig = async (root, options = {}) => {
66
725
  const startImportConfig = async () => runInDirectory(basePath, async () => unrun({
67
726
  debug,
68
727
  inputOptions: {
69
- platform: "node",
70
- transform: { define: { "process.env.NODE_ENV": "'production'" } }
728
+ external: [/node_modules/],
729
+ platform: "node"
71
730
  },
72
731
  path: fullPath
73
732
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sushichan044/eslint-config-array-resolver",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Resolves flat config module. For internal use only.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -13,7 +13,8 @@
13
13
  "directory": "packages/eslint-config-array-resolver"
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "LICENSE"
17
18
  ],
18
19
  "type": "module",
19
20
  "exports": {
@@ -32,6 +33,7 @@
32
33
  "empathic": "^2.0.0",
33
34
  "mlly": "^1.8.0",
34
35
  "pathe": "^2.0.3",
36
+ "rolldown": "1.0.0-rc.2",
35
37
  "unrun": "^0.2.26"
36
38
  },
37
39
  "devDependencies": {
@@ -43,6 +45,7 @@
43
45
  "fs-fixture": "^2.11.0",
44
46
  "oxfmt": "^0.28.0",
45
47
  "publint": "^0.3.17",
48
+ "rollup-plugin-license": "3.6.0",
46
49
  "tsdown": "^0.20.1",
47
50
  "typescript": "^5.9.3",
48
51
  "typescript-eslint": "^8.54.0",