ts-swc-transform 2.7.7 → 2.7.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/dist/cjs/compat.js.map +1 -1
- package/dist/cjs/lib/patchCJS.d.cts +1 -1
- package/dist/cjs/lib/patchCJS.d.ts +1 -1
- package/dist/cjs/lib/patchCJS.js +1 -1
- package/dist/cjs/lib/patchCJS.js.map +1 -1
- package/dist/cjs/lib/urlFileUrl.js.map +1 -1
- package/dist/esm/compat.js +5 -5
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/lib/patchCJS.d.ts +1 -1
- package/dist/esm/lib/patchCJS.js +1 -1
- package/dist/esm/lib/patchCJS.js.map +1 -1
- package/dist/esm/lib/urlFileUrl.js +3 -3
- package/dist/esm/lib/urlFileUrl.js.map +1 -1
- package/package.json +10 -10
package/dist/cjs/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["stringEndsWith","stringReplaceAll","stringStartsWith","hasStartsWith","String","prototype","startsWith","str","search","position","indexOf","hasEndsWith","endsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","replace","escaped","RegExp"],"mappings":";;;;;;;;;;;QA2BgBA;eAAAA;;QAgBAC;eAAAA;;QA/BAC;eAAAA;;;AAZhB;;;CAGC,GAED;;;;CAIC,GACD,IAAMC,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAEtD,SAASJ,iBAAiBK,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIN,eAAe;QACjB,OAAOI,IAAID,UAAU,CAACE,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,IAAME,cAAc,OAAOP,OAAOC,SAAS,CAACO,QAAQ,KAAK;AAElD,SAASZ,eAAeO,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAMI,MAAMJ,aAAaK,YAAYP,IAAIQ,MAAM,GAAGN;IAClD,OAAOF,IAAIS,WAAW,CAACR,YAAYK,MAAML,OAAOO,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAME,gBAAgB,OAAO,AAACb,OAAOC,SAAS,CAASa,UAAU,KAAK;AAE/D,SAASjB,iBAAiBM,GAAW,EAAEC,MAAc,EAAEW,OAAe;IAC3E,IAAIF,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACV,IAAYW,UAAU,CAACV,QAAQW;IACzC;IACA,kCAAkC;IAClC,IAAMC,UAAUZ,OAAOW,OAAO,CAAC,uBAAuB;IACtD,OAAOZ,IAAIY,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (
|
|
1
|
+
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
2
2
|
import type { Output } from '@swc/core';
|
|
3
3
|
import type { Entry } from 'fs-iterator';
|
|
4
4
|
import type { ConfigOptions } from '../types.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (
|
|
1
|
+
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
2
2
|
import type { Output } from '@swc/core';
|
|
3
3
|
import type { Entry } from 'fs-iterator';
|
|
4
4
|
import type { ConfigOptions } from '../types.js';
|
package/dist/cjs/lib/patchCJS.js
CHANGED
|
@@ -23,7 +23,7 @@ function _interop_require_default(obj) {
|
|
|
23
23
|
default: obj
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
var interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (
|
|
26
|
+
var interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
27
27
|
function patchCJS(entry, output, options) {
|
|
28
28
|
var rewrite = (options.tsconfig.config.compilerOptions || {}).rewriteRelativeImportExtensions;
|
|
29
29
|
if (rewrite) output.code = (0, _rewriteExtensionsts.rewriteExtensionsCJS)(output.code);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["patchCJS","interop","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","rewriteExtensionsCJS","replaceExtension","path","extname","basename"],"mappings":";;;;;;;;;;;QAeA;eAAwBA;;QAXXC;eAAAA;;;2DAJI;mCACsC;;;;;;AAGhD,IAAMA,UAAU;AAWR,SAASD,SAASE,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,IAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGC,IAAAA,yCAAoB,EAACR,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIT;IAEf,OAAOW,IAAAA,qCAAgB,EAACC,aAAI,CAACC,OAAO,CAACZ,MAAMa,QAAQ;AACrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nlet URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(urlInput: string | URL): string {\n let parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["fileURLToPath","pathToFileURL","_require","require","Module","createRequire","URLClass","url","URL","isWindows","process","platform","test","env","OSTYPE","urlInput","parsedUrl","protocol","Error","pathname","hostname","path","normalize","decodeURIComponent","letter","charCodeAt","slice","resolved","resolve","length","stringReplaceAll"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;;;;;;;;;;;;QAoBjEA;eAAAA;;QA2CAC;eAAAA;;;6DA7DG;2DACF;0DACD;wBAEiB;;;;;;AAEjC,yBAAyB;AACzB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIG,WAAuB,AAACC,YAAG,CAASC,GAAG;AAC3C,IAAI,CAACF,UAAU;IACbA,WAAWJ,SAAS;AACtB;AAEA,IAAMO,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAEpF,SAASd,cAAce,QAAsB;IAClD,IAAIC;IACJ,IAAI,OAAOD,aAAa,UAAU;QAChCC,YAAY,IAAIV,SAASS;IAC3B,OAAO;QACLC,YAAYD;IACd;IAEA,IAAIC,UAA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AC5CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAE5C,IAAI,CAAClB,WAAW;QACdkB,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIrB,SAAS,AAAC,QAAgB,OAATqB;AAC9B"}
|
package/dist/esm/compat.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* String.prototype.startsWith wrapper for Node.js 0.8+
|
|
6
6
|
* - Uses native startsWith on Node 4.0+ / ES2015+
|
|
7
7
|
* - Falls back to indexOf on Node 0.8-3.x
|
|
8
|
-
*/
|
|
8
|
+
*/ const hasStartsWith = typeof String.prototype.startsWith === 'function';
|
|
9
9
|
export function stringStartsWith(str, search, position) {
|
|
10
10
|
if (hasStartsWith) {
|
|
11
11
|
return str.startsWith(search, position);
|
|
@@ -17,12 +17,12 @@ export function stringStartsWith(str, search, position) {
|
|
|
17
17
|
* String.prototype.endsWith wrapper for Node.js 0.8+
|
|
18
18
|
* - Uses native endsWith on Node 4.0+ / ES2015+
|
|
19
19
|
* - Falls back to lastIndexOf on Node 0.8-3.x
|
|
20
|
-
*/
|
|
20
|
+
*/ const hasEndsWith = typeof String.prototype.endsWith === 'function';
|
|
21
21
|
export function stringEndsWith(str, search, position) {
|
|
22
22
|
if (hasEndsWith) {
|
|
23
23
|
return str.endsWith(search, position);
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
const len = position === undefined ? str.length : position;
|
|
26
26
|
return str.lastIndexOf(search) === len - search.length;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -30,13 +30,13 @@ export function stringEndsWith(str, search, position) {
|
|
|
30
30
|
* - Uses native replaceAll on Node 15.0+ / ES2021+
|
|
31
31
|
* - Falls back to regex replace on older versions
|
|
32
32
|
*/ // biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll
|
|
33
|
-
|
|
33
|
+
const hasReplaceAll = typeof String.prototype.replaceAll === 'function';
|
|
34
34
|
export function stringReplaceAll(str, search, replace) {
|
|
35
35
|
if (hasReplaceAll) {
|
|
36
36
|
// biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available
|
|
37
37
|
return str.replaceAll(search, replace);
|
|
38
38
|
}
|
|
39
39
|
// Escape special regex characters
|
|
40
|
-
|
|
40
|
+
const escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
41
41
|
return str.replace(new RegExp(escaped, 'g'), replace);
|
|
42
42
|
}
|
package/dist/esm/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\n\n/**\n * String.prototype.startsWith wrapper for Node.js 0.8+\n * - Uses native startsWith on Node 4.0+ / ES2015+\n * - Falls back to indexOf on Node 0.8-3.x\n */\nconst hasStartsWith = typeof String.prototype.startsWith === 'function';\n\nexport function stringStartsWith(str: string, search: string, position?: number): boolean {\n if (hasStartsWith) {\n return str.startsWith(search, position);\n }\n position = position || 0;\n return str.indexOf(search, position) === position;\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * String.prototype.replaceAll wrapper for Node.js 0.8+\n * - Uses native replaceAll on Node 15.0+ / ES2021+\n * - Falls back to regex replace on older versions\n */\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll\nconst hasReplaceAll = typeof (String.prototype as any).replaceAll === 'function';\n\nexport function stringReplaceAll(str: string, search: string, replace: string): string {\n if (hasReplaceAll) {\n // biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available\n return (str as any).replaceAll(search, replace);\n }\n // Escape special regex characters\n const escaped = search.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n return str.replace(new RegExp(escaped, 'g'), replace);\n}\n"],"names":["hasStartsWith","String","prototype","startsWith","stringStartsWith","str","search","position","indexOf","hasEndsWith","endsWith","stringEndsWith","len","undefined","length","lastIndexOf","hasReplaceAll","replaceAll","stringReplaceAll","replace","escaped","RegExp"],"mappings":"AAAA;;;CAGC,GAED;;;;CAIC,GACD,MAAMA,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAE7D,OAAO,SAASC,iBAAiBC,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC7E,IAAIP,eAAe;QACjB,OAAOK,IAAIF,UAAU,CAACG,QAAQC;IAChC;IACAA,WAAWA,YAAY;IACvB,OAAOF,IAAIG,OAAO,CAACF,QAAQC,cAAcA;AAC3C;AAEA;;;;CAIC,GACD,MAAME,cAAc,OAAOR,OAAOC,SAAS,CAACQ,QAAQ,KAAK;AAEzD,OAAO,SAASC,eAAeN,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,MAAMK,MAAML,aAAaM,YAAYR,IAAIS,MAAM,GAAGP;IAClD,OAAOF,IAAIU,WAAW,CAACT,YAAYM,MAAMN,OAAOQ,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,MAAME,gBAAgB,OAAO,AAACf,OAAOC,SAAS,CAASe,UAAU,KAAK;AAEtE,OAAO,SAASC,iBAAiBb,GAAW,EAAEC,MAAc,EAAEa,OAAe;IAC3E,IAAIH,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACX,IAAYY,UAAU,CAACX,QAAQa;IACzC;IACA,kCAAkC;IAClC,MAAMC,UAAUd,OAAOa,OAAO,CAAC,uBAAuB;IACtD,OAAOd,IAAIc,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (
|
|
1
|
+
export declare const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
2
2
|
import type { Output } from '@swc/core';
|
|
3
3
|
import type { Entry } from 'fs-iterator';
|
|
4
4
|
import type { ConfigOptions } from '../types.js';
|
package/dist/esm/lib/patchCJS.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.js';
|
|
3
3
|
// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
|
|
4
|
-
export const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (
|
|
4
|
+
export const interop = "/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }";
|
|
5
5
|
export default function patchCJS(entry, output, options) {
|
|
6
6
|
const rewrite = (options.tsconfig.config.compilerOptions || {}).rewriteRelativeImportExtensions;
|
|
7
7
|
if (rewrite) output.code = rewriteExtensionsCJS(output.code);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import path from 'path';\nimport { replaceExtension, rewriteExtensionsCJS } from './rewriteExtensions.ts';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nexport const interop = \"/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (let key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nimport type { Output } from '@swc/core';\nimport type { Entry } from 'fs-iterator';\nimport type { CompilerOptions } from 'typescript';\nimport type { ConfigOptions } from '../types.ts';\n\ninterface InternalCompilerOptions extends CompilerOptions {\n rewriteRelativeImportExtensions?: boolean;\n}\n\nexport default function patchCJS(entry: Entry, output: Output, options: ConfigOptions): string {\n const rewrite = ((options.tsconfig.config.compilerOptions || {}) as unknown as InternalCompilerOptions).rewriteRelativeImportExtensions;\n if (rewrite) output.code = rewriteExtensionsCJS(output.code);\n output.code += interop;\n\n return replaceExtension(path.extname(entry.basename));\n}\n"],"names":["path","replaceExtension","rewriteExtensionsCJS","interop","patchCJS","entry","output","options","rewrite","tsconfig","config","compilerOptions","rewriteRelativeImportExtensions","code","extname","basename"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,gBAAgB,EAAEC,oBAAoB,QAAQ,yBAAyB;AAEhF,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAW3R,eAAe,SAASC,SAASC,KAAY,EAAEC,MAAc,EAAEC,OAAsB;IACnF,MAAMC,UAAU,AAAED,CAAAA,QAAQE,QAAQ,CAACC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAA,EAA0CC,+BAA+B;IACvI,IAAIJ,SAASF,OAAOO,IAAI,GAAGX,qBAAqBI,OAAOO,IAAI;IAC3DP,OAAOO,IAAI,IAAIV;IAEf,OAAOF,iBAAiBD,KAAKc,OAAO,CAACT,MAAMU,QAAQ;AACrD"}
|
|
@@ -5,16 +5,16 @@ import path from 'path';
|
|
|
5
5
|
import url from 'url';
|
|
6
6
|
import { stringReplaceAll } from '../compat.js';
|
|
7
7
|
// ESM-compatible require
|
|
8
|
-
|
|
8
|
+
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
9
9
|
// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x
|
|
10
10
|
// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class
|
|
11
|
-
|
|
11
|
+
let URLClass = url.URL;
|
|
12
12
|
if (!URLClass) {
|
|
13
13
|
URLClass = _require('core-js-pure/actual/url/index.js');
|
|
14
14
|
}
|
|
15
15
|
const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
16
16
|
export function fileURLToPath(urlInput) {
|
|
17
|
-
|
|
17
|
+
let parsedUrl;
|
|
18
18
|
if (typeof urlInput === 'string') {
|
|
19
19
|
parsedUrl = new URLClass(urlInput);
|
|
20
20
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/urlFileUrl.ts"],"sourcesContent":["// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js\n// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\nimport { stringReplaceAll } from '../compat.ts';\n\n// ESM-compatible require\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x\n// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class\nlet URLClass: typeof URL = (url as any).URL;\nif (!URLClass) {\n URLClass = _require('core-js-pure/actual/url/index.js');\n}\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(urlInput: string | URL): string {\n let parsedUrl: URL;\n if (typeof urlInput === 'string') {\n parsedUrl = new URLClass(urlInput);\n } else {\n parsedUrl = urlInput;\n }\n\n if (parsedUrl.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (parsedUrl.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(parsedUrl.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));\n\n if (isWindows) {\n if (parsedUrl.hostname) return `\\\\\\\\${parsedUrl.hostname}${pathname}`;\n\n const letter = pathname.charCodeAt(1) | 0x20;\n\n if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */) {\n throw new Error('The file: URL path must be absolute');\n }\n\n return pathname.slice(1);\n }\n\n return pathname;\n}\n\nexport function pathToFileURL(pathname: string): URL {\n let resolved = path.resolve(pathname);\n\n if (pathname[pathname.length - 1] === '/') {\n resolved += '/';\n } else if (isWindows && pathname[pathname.length - 1] === '\\\\') {\n resolved += '\\\\';\n }\n\n resolved = stringReplaceAll(resolved, '%', '%25'); // Must be first\n resolved = stringReplaceAll(resolved, '#', '%23');\n resolved = stringReplaceAll(resolved, '?', '%3f');\n resolved = stringReplaceAll(resolved, '\\n', '%0a');\n resolved = stringReplaceAll(resolved, '\\r', '%0d');\n resolved = stringReplaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = stringReplaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URLClass(`file:${resolved}`);\n}\n"],"names":["Module","path","url","stringReplaceAll","_require","require","createRequire","URLClass","URL","isWindows","process","platform","test","env","OSTYPE","fileURLToPath","urlInput","parsedUrl","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,SAASC,gBAAgB,QAAQ,eAAe;AAEhD,yBAAyB;AACzB,MAAMC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYJ,GAAG,IAAIG;AAE1F,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIE,WAAuB,AAACL,IAAYM,GAAG;AAC3C,IAAI,CAACD,UAAU;IACbA,WAAWH,SAAS;AACtB;AAEA,MAAMK,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,OAAO,SAASC,cAAcC,QA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A,WAAWzB,iBAAiByB,UAAU,MAAM;IAC5CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAC5CA,WAAWzB,iBAAiByB,UAAU,MAAM;IAE5C,IAAI,CAACnB,WAAW;QACdmB,WAAWzB,iBAAiByB,UAAU,MAAM;IAC9C;IAEA,OAAO,IAAIrB,SAAS,CAAC,KAAK,EAAEqB,UAAU;AACxC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.8",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -46,33 +46,33 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@swc/core": "^1.15.3",
|
|
48
48
|
"core-js-pure": "^3.47.0",
|
|
49
|
-
"exit-compat": "^1.0.
|
|
49
|
+
"exit-compat": "^1.0.1",
|
|
50
50
|
"fs-iterator": "^6.1.10",
|
|
51
|
-
"install-optional": "^1.0.
|
|
51
|
+
"install-optional": "^1.0.18",
|
|
52
52
|
"is-absolute": "^1.0.0",
|
|
53
53
|
"lodash.debounce": "^4.0.8",
|
|
54
54
|
"lodash.find": "^4.6.0",
|
|
55
55
|
"mkdirp-classic": "^0.5.3",
|
|
56
56
|
"node-version-call": "^1.9.19",
|
|
57
57
|
"queue-cb": "^1.6.1",
|
|
58
|
-
"read-tsconfig-sync": "^1.1.
|
|
58
|
+
"read-tsconfig-sync": "^1.1.7",
|
|
59
59
|
"resolve": "^1.22.11",
|
|
60
|
-
"test-match": "^1.1.
|
|
60
|
+
"test-match": "^1.1.2",
|
|
61
61
|
"ts-node": "^10.9.2",
|
|
62
62
|
"typescript": "^5.9.3"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/mocha": "^10.0.10",
|
|
66
|
-
"@types/node": "^25.0.
|
|
66
|
+
"@types/node": "^25.0.1",
|
|
67
67
|
"core-js": "^3.47.0",
|
|
68
68
|
"cr": "^0.1.0",
|
|
69
|
-
"cross-spawn-cb": "^2.4.
|
|
69
|
+
"cross-spawn-cb": "^2.4.12",
|
|
70
70
|
"fs-remove-compat": "^0.2.1",
|
|
71
|
-
"node-version-use": "^2.1.
|
|
71
|
+
"node-version-use": "^2.1.5",
|
|
72
72
|
"pinkie-promise": "^2.0.1",
|
|
73
|
-
"react": "^19.2.
|
|
73
|
+
"react": "^19.2.3",
|
|
74
74
|
"ts-dev-stack": "^1.21.3",
|
|
75
|
-
"tsds-config": "^0.2.
|
|
75
|
+
"tsds-config": "^0.2.1"
|
|
76
76
|
},
|
|
77
77
|
"engines": {
|
|
78
78
|
"node": ">=0.8"
|