ts-arc 1.2.7 → 1.2.9
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/loader.js +31 -19
- package/package.json +1 -1
package/dist/loader.js
CHANGED
|
@@ -305,18 +305,31 @@ function addMetadataDecorators(code) {
|
|
|
305
305
|
async function resolve2(specifier, context, nextResolve) {
|
|
306
306
|
let parentPath = process.cwd();
|
|
307
307
|
if (context.parentURL) {
|
|
308
|
-
|
|
308
|
+
const parentUrl = new URL(context.parentURL);
|
|
309
|
+
if (parentUrl.protocol === "file:") {
|
|
310
|
+
parentPath = path.dirname(url.fileURLToPath(parentUrl));
|
|
311
|
+
} else if (parentUrl.protocol === "copycat:") {
|
|
312
|
+
const as = parentUrl.searchParams.get("as");
|
|
313
|
+
if (as && typeof as === "string") {
|
|
314
|
+
parentPath = path.dirname(as);
|
|
315
|
+
} else {
|
|
316
|
+
parentPath = process.cwd();
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
parentPath = process.cwd();
|
|
320
|
+
}
|
|
309
321
|
}
|
|
310
322
|
if (specifier.startsWith("copycat://")) {
|
|
311
323
|
const u = new URL(specifier);
|
|
312
|
-
const
|
|
313
|
-
if (!
|
|
314
|
-
throw new Error("Copycat file URI is missing the `
|
|
324
|
+
const real = u.searchParams.get("real");
|
|
325
|
+
if (!real) {
|
|
326
|
+
throw new Error("Copycat file URI is missing the `real` searchparam.");
|
|
315
327
|
}
|
|
316
|
-
const
|
|
328
|
+
const realPath = path.resolve(real);
|
|
317
329
|
const out = new URL(specifier);
|
|
318
|
-
out.pathname =
|
|
319
|
-
out.searchParams.set("
|
|
330
|
+
out.pathname = realPath;
|
|
331
|
+
out.searchParams.set("real", realPath);
|
|
332
|
+
out.searchParams.set("copycat", "true");
|
|
320
333
|
return {
|
|
321
334
|
url: out.href,
|
|
322
335
|
shortCircuit: true
|
|
@@ -381,19 +394,18 @@ async function load(urlStr, context, nextLoad) {
|
|
|
381
394
|
});
|
|
382
395
|
}
|
|
383
396
|
function loadSync(urlStr, context, nextLoadSync) {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
const code = fs.readFileSync(filePath, "utf8");
|
|
390
|
-
if (isCopycat) {
|
|
391
|
-
return {
|
|
392
|
-
format: "module",
|
|
393
|
-
source: code,
|
|
394
|
-
shortCircuit: true
|
|
395
|
-
};
|
|
397
|
+
const u = new URL(urlStr);
|
|
398
|
+
if (u.searchParams.has("copycat")) {
|
|
399
|
+
const real = u.searchParams.get("real");
|
|
400
|
+
if (!real) {
|
|
401
|
+
throw new Error("Copycat file URI is missing the `real` searchparam.");
|
|
396
402
|
}
|
|
403
|
+
const code = fs.readFileSync(decodeURI(real), "utf8");
|
|
404
|
+
return {
|
|
405
|
+
format: "module",
|
|
406
|
+
source: code,
|
|
407
|
+
shortCircuit: true
|
|
408
|
+
};
|
|
397
409
|
}
|
|
398
410
|
if (urlStr.endsWith(".ts") || urlStr.endsWith(".tsx")) {
|
|
399
411
|
const esbuildLoader = urlStr.endsWith(".tsx") ? "tsx" : "ts";
|