@hirarijs/loader-ts 1.0.17 → 1.0.19
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.cjs +10 -16
- package/dist/index.js +10 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -213430,6 +213430,9 @@ function createTsResolveForConfig(tsconfigPath, debug = false) {
|
|
|
213430
213430
|
const resolver = (specifier, importer) => {
|
|
213431
213431
|
const result = import_typescript.default.resolveModuleName(specifier, importer, options, host);
|
|
213432
213432
|
let resolved = result.resolvedModule?.resolvedFileName;
|
|
213433
|
+
if (result.resolvedModule?.isExternalLibraryImport || !result.resolvedModule) {
|
|
213434
|
+
return null;
|
|
213435
|
+
}
|
|
213433
213436
|
if (resolved && resolved.endsWith(".d.ts")) {
|
|
213434
213437
|
const candidates = [
|
|
213435
213438
|
resolved.replace(/\.d\.ts$/, ".ts"),
|
|
@@ -213481,6 +213484,7 @@ function rewriteImports(code, filename, resolve, debug = false) {
|
|
|
213481
213484
|
}
|
|
213482
213485
|
const resolved = resolve(spec, filename);
|
|
213483
213486
|
if (!resolved) return full;
|
|
213487
|
+
if (resolved.includes("node_modules")) return full;
|
|
213484
213488
|
if (debug) {
|
|
213485
213489
|
console.log(`[loader-ts] rewrite ${spec} -> ${resolved}`);
|
|
213486
213490
|
}
|
|
@@ -213489,9 +213493,7 @@ function rewriteImports(code, filename, resolve, debug = false) {
|
|
|
213489
213493
|
return full.replace(spec, normalized);
|
|
213490
213494
|
});
|
|
213491
213495
|
}
|
|
213492
|
-
var
|
|
213493
|
-
var JS_EXTS = [".js", ".mjs", ".cjs"];
|
|
213494
|
-
var extensions = [...TS_EXTS, ...JS_EXTS];
|
|
213496
|
+
var extensions = [".ts", ".mts", ".cts"];
|
|
213495
213497
|
function runTransform(code, filename, ctx) {
|
|
213496
213498
|
const ext = import_path.default.extname(filename);
|
|
213497
213499
|
if (!extensions.includes(ext)) {
|
|
@@ -213504,27 +213506,20 @@ function runTransform(code, filename, ctx) {
|
|
|
213504
213506
|
}
|
|
213505
213507
|
const pathResolver = createTsResolve(filename, ctx.loaderConfig.debug);
|
|
213506
213508
|
const rewrittenCode = pathResolver && !filename.includes("node_modules") ? rewriteImports(code, filename, pathResolver, ctx.loaderConfig.debug) : code;
|
|
213507
|
-
if (JS_EXTS.includes(ext)) {
|
|
213508
|
-
return {
|
|
213509
|
-
code: rewrittenCode,
|
|
213510
|
-
map: void 0,
|
|
213511
|
-
format: ctx.format,
|
|
213512
|
-
continue: opts.continue === true
|
|
213513
|
-
};
|
|
213514
|
-
}
|
|
213515
213509
|
if (ctx.loaderConfig.debug) {
|
|
213516
213510
|
console.log(`[loader-ts] transforming ${filename}`);
|
|
213517
213511
|
if (!pathResolver) {
|
|
213518
213512
|
console.log("[loader-ts] no tsconfig resolver created for", filename);
|
|
213519
213513
|
}
|
|
213520
213514
|
}
|
|
213521
|
-
const
|
|
213515
|
+
const outFormat = opts.format || "esm";
|
|
213516
|
+
const banner = outFormat === "cjs" ? `const ${import_loader.IMPORT_META_URL_VARIABLE} = require('url').pathToFileURL(__filename).href;` : void 0;
|
|
213522
213517
|
const result = (0, import_esbuild.transformSync)(rewrittenCode, {
|
|
213523
213518
|
loader: "ts",
|
|
213524
|
-
format:
|
|
213519
|
+
format: outFormat,
|
|
213525
213520
|
sourcemap: "both",
|
|
213526
213521
|
sourcefile: filename,
|
|
213527
|
-
define:
|
|
213522
|
+
define: outFormat === "cjs" ? {
|
|
213528
213523
|
"import.meta.url": import_loader.IMPORT_META_URL_VARIABLE
|
|
213529
213524
|
} : void 0,
|
|
213530
213525
|
banner
|
|
@@ -213532,7 +213527,7 @@ function runTransform(code, filename, ctx) {
|
|
|
213532
213527
|
return {
|
|
213533
213528
|
code: result.code,
|
|
213534
213529
|
map: result.map,
|
|
213535
|
-
format:
|
|
213530
|
+
format: outFormat,
|
|
213536
213531
|
continue: opts.continue === true
|
|
213537
213532
|
};
|
|
213538
213533
|
}
|
|
@@ -213541,7 +213536,6 @@ var plugin = {
|
|
|
213541
213536
|
extensions,
|
|
213542
213537
|
match: (filename) => {
|
|
213543
213538
|
const ext = import_path.default.extname(filename);
|
|
213544
|
-
if (!ext) return true;
|
|
213545
213539
|
return extensions.includes(ext);
|
|
213546
213540
|
},
|
|
213547
213541
|
transform: runTransform
|
package/dist/index.js
CHANGED
|
@@ -213427,6 +213427,9 @@ function createTsResolveForConfig(tsconfigPath, debug = false) {
|
|
|
213427
213427
|
const resolver = (specifier, importer) => {
|
|
213428
213428
|
const result = import_typescript.default.resolveModuleName(specifier, importer, options, host);
|
|
213429
213429
|
let resolved = result.resolvedModule?.resolvedFileName;
|
|
213430
|
+
if (result.resolvedModule?.isExternalLibraryImport || !result.resolvedModule) {
|
|
213431
|
+
return null;
|
|
213432
|
+
}
|
|
213430
213433
|
if (resolved && resolved.endsWith(".d.ts")) {
|
|
213431
213434
|
const candidates = [
|
|
213432
213435
|
resolved.replace(/\.d\.ts$/, ".ts"),
|
|
@@ -213478,6 +213481,7 @@ function rewriteImports(code, filename, resolve, debug = false) {
|
|
|
213478
213481
|
}
|
|
213479
213482
|
const resolved = resolve(spec, filename);
|
|
213480
213483
|
if (!resolved) return full;
|
|
213484
|
+
if (resolved.includes("node_modules")) return full;
|
|
213481
213485
|
if (debug) {
|
|
213482
213486
|
console.log(`[loader-ts] rewrite ${spec} -> ${resolved}`);
|
|
213483
213487
|
}
|
|
@@ -213486,9 +213490,7 @@ function rewriteImports(code, filename, resolve, debug = false) {
|
|
|
213486
213490
|
return full.replace(spec, normalized);
|
|
213487
213491
|
});
|
|
213488
213492
|
}
|
|
213489
|
-
var
|
|
213490
|
-
var JS_EXTS = [".js", ".mjs", ".cjs"];
|
|
213491
|
-
var extensions = [...TS_EXTS, ...JS_EXTS];
|
|
213493
|
+
var extensions = [".ts", ".mts", ".cts"];
|
|
213492
213494
|
function runTransform(code, filename, ctx) {
|
|
213493
213495
|
const ext = path.extname(filename);
|
|
213494
213496
|
if (!extensions.includes(ext)) {
|
|
@@ -213501,27 +213503,20 @@ function runTransform(code, filename, ctx) {
|
|
|
213501
213503
|
}
|
|
213502
213504
|
const pathResolver = createTsResolve(filename, ctx.loaderConfig.debug);
|
|
213503
213505
|
const rewrittenCode = pathResolver && !filename.includes("node_modules") ? rewriteImports(code, filename, pathResolver, ctx.loaderConfig.debug) : code;
|
|
213504
|
-
if (JS_EXTS.includes(ext)) {
|
|
213505
|
-
return {
|
|
213506
|
-
code: rewrittenCode,
|
|
213507
|
-
map: void 0,
|
|
213508
|
-
format: ctx.format,
|
|
213509
|
-
continue: opts.continue === true
|
|
213510
|
-
};
|
|
213511
|
-
}
|
|
213512
213506
|
if (ctx.loaderConfig.debug) {
|
|
213513
213507
|
console.log(`[loader-ts] transforming ${filename}`);
|
|
213514
213508
|
if (!pathResolver) {
|
|
213515
213509
|
console.log("[loader-ts] no tsconfig resolver created for", filename);
|
|
213516
213510
|
}
|
|
213517
213511
|
}
|
|
213518
|
-
const
|
|
213512
|
+
const outFormat = opts.format || "esm";
|
|
213513
|
+
const banner = outFormat === "cjs" ? `const ${IMPORT_META_URL_VARIABLE} = require('url').pathToFileURL(__filename).href;` : void 0;
|
|
213519
213514
|
const result = transformSync(rewrittenCode, {
|
|
213520
213515
|
loader: "ts",
|
|
213521
|
-
format:
|
|
213516
|
+
format: outFormat,
|
|
213522
213517
|
sourcemap: "both",
|
|
213523
213518
|
sourcefile: filename,
|
|
213524
|
-
define:
|
|
213519
|
+
define: outFormat === "cjs" ? {
|
|
213525
213520
|
"import.meta.url": IMPORT_META_URL_VARIABLE
|
|
213526
213521
|
} : void 0,
|
|
213527
213522
|
banner
|
|
@@ -213529,7 +213524,7 @@ function runTransform(code, filename, ctx) {
|
|
|
213529
213524
|
return {
|
|
213530
213525
|
code: result.code,
|
|
213531
213526
|
map: result.map,
|
|
213532
|
-
format:
|
|
213527
|
+
format: outFormat,
|
|
213533
213528
|
continue: opts.continue === true
|
|
213534
213529
|
};
|
|
213535
213530
|
}
|
|
@@ -213538,7 +213533,6 @@ var plugin = {
|
|
|
213538
213533
|
extensions,
|
|
213539
213534
|
match: (filename) => {
|
|
213540
213535
|
const ext = path.extname(filename);
|
|
213541
|
-
if (!ext) return true;
|
|
213542
213536
|
return extensions.includes(ext);
|
|
213543
213537
|
},
|
|
213544
213538
|
transform: runTransform
|