ts-swc-transform 2.6.25 → 2.7.1
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.d.cts +7 -0
- package/dist/cjs/compat.d.ts +7 -0
- package/dist/cjs/compat.js +64 -0
- package/dist/cjs/compat.js.map +1 -0
- package/dist/cjs/lib/rewriteExtensions.js +2 -7
- package/dist/cjs/lib/rewriteExtensions.js.map +1 -1
- package/dist/cjs/lib/urlFileUrl.d.cts +1 -2
- package/dist/cjs/lib/urlFileUrl.d.ts +1 -2
- package/dist/cjs/lib/urlFileUrl.js +31 -19
- package/dist/cjs/lib/urlFileUrl.js.map +1 -1
- package/dist/cjs/toPath.js +2 -2
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/cjs/transformSync.js +2 -2
- package/dist/cjs/transformSync.js.map +1 -1
- package/dist/cjs/workers/transformTypes.js +2 -1
- package/dist/cjs/workers/transformTypes.js.map +1 -1
- package/dist/esm/compat.d.ts +7 -0
- package/dist/esm/compat.js +42 -0
- package/dist/esm/compat.js.map +1 -0
- package/dist/esm/lib/rewriteExtensions.js +2 -2
- package/dist/esm/lib/rewriteExtensions.js.map +1 -1
- package/dist/esm/lib/urlFileUrl.d.ts +1 -2
- package/dist/esm/lib/urlFileUrl.js +31 -19
- package/dist/esm/lib/urlFileUrl.js.map +1 -1
- package/dist/esm/toPath.js +2 -2
- package/dist/esm/toPath.js.map +1 -1
- package/dist/esm/transformSync.js +2 -2
- package/dist/esm/transformSync.js.map +1 -1
- package/dist/esm/workers/transformTypes.js +2 -1
- package/dist/esm/workers/transformTypes.js.map +1 -1
- package/package.json +1 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility Layer for Node.js 0.8+
|
|
3
|
+
* Local to this package - contains only needed functions.
|
|
4
|
+
*/
|
|
5
|
+
export declare function stringStartsWith(str: string, search: string, position?: number): boolean;
|
|
6
|
+
export declare function stringEndsWith(str: string, search: string, position?: number): boolean;
|
|
7
|
+
export declare function stringReplaceAll(str: string, search: string, replace: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility Layer for Node.js 0.8+
|
|
3
|
+
* Local to this package - contains only needed functions.
|
|
4
|
+
*/
|
|
5
|
+
export declare function stringStartsWith(str: string, search: string, position?: number): boolean;
|
|
6
|
+
export declare function stringEndsWith(str: string, search: string, position?: number): boolean;
|
|
7
|
+
export declare function stringReplaceAll(str: string, search: string, replace: string): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get stringEndsWith () {
|
|
13
|
+
return stringEndsWith;
|
|
14
|
+
},
|
|
15
|
+
get stringReplaceAll () {
|
|
16
|
+
return stringReplaceAll;
|
|
17
|
+
},
|
|
18
|
+
get stringStartsWith () {
|
|
19
|
+
return stringStartsWith;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Compatibility Layer for Node.js 0.8+
|
|
24
|
+
* Local to this package - contains only needed functions.
|
|
25
|
+
*/ /**
|
|
26
|
+
* String.prototype.startsWith wrapper for Node.js 0.8+
|
|
27
|
+
* - Uses native startsWith on Node 4.0+ / ES2015+
|
|
28
|
+
* - Falls back to indexOf on Node 0.8-3.x
|
|
29
|
+
*/ var hasStartsWith = typeof String.prototype.startsWith === 'function';
|
|
30
|
+
function stringStartsWith(str, search, position) {
|
|
31
|
+
if (hasStartsWith) {
|
|
32
|
+
return str.startsWith(search, position);
|
|
33
|
+
}
|
|
34
|
+
position = position || 0;
|
|
35
|
+
return str.indexOf(search, position) === position;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* String.prototype.endsWith wrapper for Node.js 0.8+
|
|
39
|
+
* - Uses native endsWith on Node 4.0+ / ES2015+
|
|
40
|
+
* - Falls back to lastIndexOf on Node 0.8-3.x
|
|
41
|
+
*/ var hasEndsWith = typeof String.prototype.endsWith === 'function';
|
|
42
|
+
function stringEndsWith(str, search, position) {
|
|
43
|
+
if (hasEndsWith) {
|
|
44
|
+
return str.endsWith(search, position);
|
|
45
|
+
}
|
|
46
|
+
var len = position === undefined ? str.length : position;
|
|
47
|
+
return str.lastIndexOf(search) === len - search.length;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* String.prototype.replaceAll wrapper for Node.js 0.8+
|
|
51
|
+
* - Uses native replaceAll on Node 15.0+ / ES2021+
|
|
52
|
+
* - Falls back to regex replace on older versions
|
|
53
|
+
*/ // biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll
|
|
54
|
+
var hasReplaceAll = typeof String.prototype.replaceAll === 'function';
|
|
55
|
+
function stringReplaceAll(str, search, replace) {
|
|
56
|
+
if (hasReplaceAll) {
|
|
57
|
+
// biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available
|
|
58
|
+
return str.replaceAll(search, replace);
|
|
59
|
+
}
|
|
60
|
+
// Escape special regex characters
|
|
61
|
+
var escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
62
|
+
return str.replace(new RegExp(escaped, 'g'), replace);
|
|
63
|
+
}
|
|
64
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +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 */\nvar 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 */\nvar 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 var 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\nvar 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 var 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,IAAIC,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAEpD,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,IAAIE,cAAc,OAAOP,OAAOC,SAAS,CAACO,QAAQ,KAAK;AAEhD,SAASZ,eAAeO,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAII,MAAMJ,aAAaK,YAAYP,IAAIQ,MAAM,GAAGN;IAChD,OAAOF,IAAIS,WAAW,CAACR,YAAYK,MAAML,OAAOO,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAIE,gBAAgB,OAAO,AAACb,OAAOC,SAAS,CAASa,UAAU,KAAK;AAE7D,SAASjB,iBAAiBM,GAAW,EAAEC,MAAc,EAAEW,OAAe;IAC3E,IAAIF,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACV,IAAYW,UAAU,CAACV,QAAQW;IACzC;IACA,kCAAkC;IAClC,IAAIC,UAAUZ,OAAOW,OAAO,CAAC,uBAAuB;IACpD,OAAOZ,IAAIY,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
|
|
@@ -22,12 +22,7 @@ _export(exports, {
|
|
|
22
22
|
return rewriteExtensionsCJS;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
var
|
|
26
|
-
function _interop_require_default(obj) {
|
|
27
|
-
return obj && obj.__esModule ? obj : {
|
|
28
|
-
default: obj
|
|
29
|
-
};
|
|
30
|
-
}
|
|
25
|
+
var _compatts = require("../compat.js");
|
|
31
26
|
var extensions = {
|
|
32
27
|
'.ts': '.js',
|
|
33
28
|
'.tsx': '.js',
|
|
@@ -40,7 +35,7 @@ function replaceExtension(ext) {
|
|
|
40
35
|
}
|
|
41
36
|
// Helper to check if a path is relative (starts with ./ or ../)
|
|
42
37
|
function isRelativePath(path) {
|
|
43
|
-
return (0,
|
|
38
|
+
return (0, _compatts.stringStartsWith)(path, './') || (0, _compatts.stringStartsWith)(path, '../');
|
|
44
39
|
}
|
|
45
40
|
function rewriteExtensions(content) {
|
|
46
41
|
var result = content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import { stringStartsWith } from '../compat.ts';\n\nexport const extensions = {\n '.ts': '.js',\n '.tsx': '.js',\n '.mts': '.mjs',\n '.cts': '.cjs',\n};\n\nexport function replaceExtension(ext: string): string {\n const replace = extensions[ext];\n return replace === undefined ? ext : replace;\n}\n\n// Helper to check if a path is relative (starts with ./ or ../)\nfunction isRelativePath(path: string): boolean {\n return stringStartsWith(path, './') || stringStartsWith(path, '../');\n}\n\n// Multi-pattern transformer for TypeScript extension rewriting\n// See: https://github.com/microsoft/TypeScript/issues/61037\n// TODO: Remove when TypeScript natively supports rewriteRelativeImportExtensions in .d.ts files\n\nexport function rewriteExtensions(content: string): string {\n let result = content;\n\n // Pattern 1: Import/Export statements (with optional 'type' keyword)\n // Matches: import { X } from './path.ts'\n // import type { X } from './path.ts'\n // export * from './path.ts'\n // export type * from './path.ts'\n result = result.replace(/\\b(import|export)(\\s+type)?(?:\\s+[^'\"]*?\\s+from\\s+|\\s+)['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]/g, (match, _keyword, _typeKeyword, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 2: Dynamic import types\n // Matches: typeof import('./path.ts')\n result = result.replace(/\\bimport\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 3: Triple-slash path references\n // Matches: /// <reference path=\"./file.ts\" />\n // /// <reference path=\"./file.d.ts\" />\n result = result.replace(/\\/\\/\\/\\s*<reference\\s+path\\s*=\\s*['\"]([^'\"]+)\\.(d\\.ts|tsx?|mts|cts)['\"]\\s*\\/>/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n // Special case: .d.ts → .d.js\n const newExt = ext === 'd.ts' ? '.d.js' : replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n\n// CJS-specific version that also handles require() statements\nexport function rewriteExtensionsCJS(content: string): string {\n // Start with all ESM patterns\n let result = rewriteExtensions(content);\n\n // Pattern 4: CommonJS require() statements\n // Matches: require('./path.ts')\n result = result.replace(/\\brequire\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n"],"names":["extensions","replaceExtension","rewriteExtensions","rewriteExtensionsCJS","ext","replace","undefined","isRelativePath","path","stringStartsWith","content","result","match","_keyword","_typeKeyword","newExt"],"mappings":";;;;;;;;;;;Q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|
|
22
|
-
var _index = /*#__PURE__*/ _interop_require_default(require("core-js-pure/actual/url/index.js"));
|
|
21
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
23
22
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
23
|
+
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
24
|
+
var _compatts = require("../compat.js");
|
|
24
25
|
function _interop_require_default(obj) {
|
|
25
26
|
return obj && obj.__esModule ? obj : {
|
|
26
27
|
default: obj
|
|
27
28
|
};
|
|
28
29
|
}
|
|
30
|
+
// ESM-compatible require
|
|
31
|
+
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
32
|
+
// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x
|
|
33
|
+
// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class
|
|
34
|
+
var URLClass = _url.default.URL;
|
|
35
|
+
if (!URLClass) {
|
|
36
|
+
URLClass = _require('core-js-pure/actual/url/index.js');
|
|
37
|
+
}
|
|
29
38
|
var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
30
|
-
function fileURLToPath(
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
function fileURLToPath(urlInput) {
|
|
40
|
+
var parsedUrl;
|
|
41
|
+
if (typeof urlInput === 'string') {
|
|
42
|
+
parsedUrl = new URLClass(urlInput);
|
|
43
|
+
} else {
|
|
44
|
+
parsedUrl = urlInput;
|
|
33
45
|
}
|
|
34
|
-
if (
|
|
46
|
+
if (parsedUrl.protocol !== 'file:') {
|
|
35
47
|
throw new Error('The URL must use the file: protocol');
|
|
36
48
|
}
|
|
37
49
|
if (isWindows) {
|
|
38
|
-
if (/%2f|%5c/i.test(
|
|
50
|
+
if (/%2f|%5c/i.test(parsedUrl.pathname)) {
|
|
39
51
|
throw new Error('The file: URL path must not include encoded \\ or / characters');
|
|
40
52
|
}
|
|
41
53
|
} else {
|
|
42
|
-
if (
|
|
54
|
+
if (parsedUrl.hostname) {
|
|
43
55
|
throw new Error("The file: URL host must be 'localhost' or empty");
|
|
44
56
|
}
|
|
45
|
-
if (/%2f/i.test(
|
|
57
|
+
if (/%2f/i.test(parsedUrl.pathname)) {
|
|
46
58
|
throw new Error('The file: URL path must not include encoded / characters');
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
|
-
var pathname = _path.default.normalize(decodeURIComponent(
|
|
61
|
+
var pathname = _path.default.normalize(decodeURIComponent(parsedUrl.pathname));
|
|
50
62
|
if (isWindows) {
|
|
51
|
-
if (
|
|
63
|
+
if (parsedUrl.hostname) return "\\\\".concat(parsedUrl.hostname).concat(pathname);
|
|
52
64
|
var letter = pathname.charCodeAt(1) | 0x20;
|
|
53
65
|
if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */ ) {
|
|
54
66
|
throw new Error('The file: URL path must be absolute');
|
|
@@ -64,15 +76,15 @@ function pathToFileURL(pathname) {
|
|
|
64
76
|
} else if (isWindows && pathname[pathname.length - 1] === '\\') {
|
|
65
77
|
resolved += '\\';
|
|
66
78
|
}
|
|
67
|
-
resolved = (0,
|
|
68
|
-
resolved = (0,
|
|
69
|
-
resolved = (0,
|
|
70
|
-
resolved = (0,
|
|
71
|
-
resolved = (0,
|
|
72
|
-
resolved = (0,
|
|
79
|
+
resolved = (0, _compatts.stringReplaceAll)(resolved, '%', '%25'); // Must be first
|
|
80
|
+
resolved = (0, _compatts.stringReplaceAll)(resolved, '#', '%23');
|
|
81
|
+
resolved = (0, _compatts.stringReplaceAll)(resolved, '?', '%3f');
|
|
82
|
+
resolved = (0, _compatts.stringReplaceAll)(resolved, '\n', '%0a');
|
|
83
|
+
resolved = (0, _compatts.stringReplaceAll)(resolved, '\r', '%0d');
|
|
84
|
+
resolved = (0, _compatts.stringReplaceAll)(resolved, '\t', '%09');
|
|
73
85
|
if (!isWindows) {
|
|
74
|
-
resolved = (0,
|
|
86
|
+
resolved = (0, _compatts.stringReplaceAll)(resolved, '\\', '%5c');
|
|
75
87
|
}
|
|
76
|
-
return new
|
|
88
|
+
return new URLClass("file:".concat(resolved));
|
|
77
89
|
}
|
|
78
90
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -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
|
|
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\nvar _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\nvar 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 var 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,IAA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5B,IAAIA,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,KAAK;QACzCF,YAAY;IACd,OAAO,IAAIlB,aAAaU,QAAQ,CAACA,SAASU,MAAM,GAAG,EAAE,KAAK,MAAM;QAC9DF,YAAY;IACd;IAEAA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK,QAAQ,gBAAgB;IACnEA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK;IAC3CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,KAAK;IAC3CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC5CA,WAAWG,IAAAA,0BAAgB,EAACH,UAAU,MAAM;IAC5CA,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/cjs/toPath.js
CHANGED
|
@@ -12,8 +12,8 @@ var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"))
|
|
|
12
12
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
13
13
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
14
|
var _resolve = /*#__PURE__*/ _interop_require_wildcard(require("resolve"));
|
|
15
|
-
var _startswith = /*#__PURE__*/ _interop_require_default(require("starts-with"));
|
|
16
15
|
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
16
|
+
var _compatts = require("./compat.js");
|
|
17
17
|
var _constantsts = require("./constants.js");
|
|
18
18
|
var _importmetaresolvets = /*#__PURE__*/ _interop_require_default(require("./lib/import-meta-resolve.js"));
|
|
19
19
|
var _urlFileUrlts = /*#__PURE__*/ _interop_require_wildcard(require("./lib/urlFileUrl.js"));
|
|
@@ -73,7 +73,7 @@ function getParentPath(context) {
|
|
|
73
73
|
return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : process.cwd();
|
|
74
74
|
}
|
|
75
75
|
function toPath(specifier, context) {
|
|
76
|
-
if ((0,
|
|
76
|
+
if ((0, _compatts.stringStartsWith)(specifier, 'file:')) return fileURLToPath(specifier);
|
|
77
77
|
if ((0, _isabsolute.default)(specifier)) return specifier;
|
|
78
78
|
if (specifier[0] === '.') {
|
|
79
79
|
var parentPath = context ? getParentPath(context) : process.cwd();
|
package/dist/cjs/toPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport url from 'url';\n\nimport { stringStartsWith } from './compat.ts';\nimport { moduleRegEx } from './constants.ts';\nimport importMetaResolve from './lib/import-meta-resolve.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context): string {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context): string {\n if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = importMetaResolve(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["toPath","resolve","resolveSync","default","sync","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","stringStartsWith","isAbsolute","join","moduleRegEx","test","entryURL","importMetaResolve","_","entryPath","basedir","extensions"],"mappings":";;;;+BAuBA;;;eAAwBA;;;iEAvBD;6DACJ;2DACF;+DACQ;0DACT;wBAEiB;2BACL;0EACE;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAGTC;AAArB,IAAMC,cAAc,AAACD,CAAAA,CAAAA,mBAAAA,SAAQE,OAAO,cAAfF,8BAAAA,mBAAmBA,QAAM,EAAGG,IAAI;AAErD,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,cAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,cAAaC,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAAChB,OAAOa,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASnB,OAAOoB,SAAiB,EAAEP,OAAiB;IACjE,IAAIQ,IAAAA,0BAAgB,EAACD,WAAW,UAAU,OAAOZ,cAAcY;IAC/D,IAAIE,IAAAA,mBAAU,EAACF,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACQ,IAAI,CAACT,YAAYM;IAC/B;IACA,IAAII,wBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACd,QAAQ;YACX,IAAI;gBACF,IAAMqB,WAAWC,IAAAA,4BAAiB,EAACP,WAAWT,cAAcG;gBAC5D,IAAIY,UAAU,OAAOlB,cAAckB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAY3B,YAAYkB,WAAW;YACvCU,SAAShB;YACTiB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
|
|
@@ -27,8 +27,8 @@ function dispatch(version, contents, fileName, tsconfig) {
|
|
|
27
27
|
return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);
|
|
28
28
|
}
|
|
29
29
|
function transformSync(contents, fileName, tsconfig) {
|
|
30
|
-
if (typeof contents !== 'string') throw new Error('
|
|
31
|
-
if (typeof fileName !== 'string') throw new Error('
|
|
30
|
+
if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');
|
|
31
|
+
if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');
|
|
32
32
|
if (!tsconfig) tsconfig = (0, _readtsconfigsync.default)(process.cwd());
|
|
33
33
|
return dispatch(version, contents, fileName, tsconfig);
|
|
34
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["transformSync","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","dispatch","contents","fileName","tsconfig","Error","loadConfigSync","cwd"],"mappings":";;;;+BAqBA;;;eAAwBA;;;2DArBP;uEACU;0DACX;6DASG;;;;;;AALnB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,SAASG,SAASb,OAAO,EAAEc,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAIhB,YAAY,SAAS,OAAOS,SAASF,YAAYO,UAAUC,UAAUC;IACzE,OAAOP,SAAS,qBAAqBT,SAASO,YAAYO,UAAUC,UAAUC;AAChF;AAGe,SAAStB,cAAcoB,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAIE,MAAM;IAClD,IAAI,CAACD,UAAUA,WAAWE,IAAAA,yBAAc,EAACtB,QAAQuB,GAAG;IACpD,OAAON,SAASb,SAASc,UAAUC,UAAUC;AAC/C"}
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
12
|
var _fsiterator = /*#__PURE__*/ _interop_require_default(require("fs-iterator"));
|
|
13
13
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
14
|
+
var _compatts = require("../compat.js");
|
|
14
15
|
var _constantsts = require("../constants.js");
|
|
15
16
|
var _createMatcherts = /*#__PURE__*/ _interop_require_default(require("../createMatcher.js"));
|
|
16
17
|
var _rewriteExtensionsts = require("../lib/rewriteExtensions.js");
|
|
@@ -123,7 +124,7 @@ function transformTypesWorker(src, dest, options, callback) {
|
|
|
123
124
|
// TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037
|
|
124
125
|
if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {
|
|
125
126
|
res.emittedFiles.forEach(function(file) {
|
|
126
|
-
if (
|
|
127
|
+
if ((0, _compatts.stringEndsWith)(file, '.d.ts') || (0, _compatts.stringEndsWith)(file, '.d.cts') || (0, _compatts.stringEndsWith)(file, '.d.mts')) {
|
|
127
128
|
try {
|
|
128
129
|
var content = _fs.default.readFileSync(file, 'utf8');
|
|
129
130
|
var updated = (0, _rewriteExtensionsts.rewriteExtensions)(content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): undefined {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err): undefined => {\n if (err) {\n callback(err);\n return;\n }\n\n const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...compilerOptions.options,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n\n // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {\n res.emittedFiles.forEach((file) => {\n if (file
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): undefined {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err): undefined => {\n if (err) {\n callback(err);\n return;\n }\n\n const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...compilerOptions.options,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n\n // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {\n res.emittedFiles.forEach((file) => {\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n try {\n const content = fs.readFileSync(file, 'utf8');\n const updated = rewriteExtensions(content);\n if (updated !== content) {\n fs.writeFileSync(file, updated, 'utf8');\n }\n } catch (_err) {\n // Ignore errors\n }\n }\n });\n }\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["transformTypesWorker","_require","require","Module","createRequire","src","dest","options","callback","tsconfig","matcher","createMatcher","ts","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","push","concurrency","Infinity","err","compilerOptions","convertCompilerOptionsFromJson","config","fileNames","map","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","emittedFiles","rewriteRelativeImportExtensions","file","stringEndsWith","content","fs","readFileSync","updated","rewriteExtensions","writeFileSync","_err"],"mappings":";;;;+BAaA;;;eAAwBA;;;yDAbT;iEACsB;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B,wBAAwB,CAACnC,WAAS,gBAAgB,GAAGoC,WAAW/B,GAAGgC,GAAG;QACtF,IAAMC,iBAAiB;YACrBC,WAAWf;YACXxB,SAAAA;YACAgC,mBAAAA;YACAE,MAAAA;YACAM,8BAA8BnC,GAAGoC,+BAA+B,CAAC;gBAAEjB,WAAAA;gBAAWxB,SAAAA;YAAQ;QACxF;QACA,IAAM0C,UAAUrC,GAAGsC,aAAa,CAACL;QACjC,IAAMM,MAAMF,QAAQG,IAAI;QAExB,8EAA8E;QAC9E,IAAID,IAAIE,YAAY,IAAIzB,gBAAgBrB,OAAO,CAAC+C,+BAA+B,EAAE;YAC/EH,IAAIE,YAAY,CAACrC,OAAO,CAAC,SAACuC;gBACxB,IAAIC,IAAAA,wBAAc,EAACD,MAAM,YAAYC,IAAAA,wBAAc,EAACD,MAAM,aAAaC,IAAAA,wBAAc,EAACD,MAAM,WAAW;oBACrG,IAAI;wBACF,IAAME,UAAUC,WAAE,CAACC,YAAY,CAACJ,MAAM;wBACtC,IAAMK,UAAUC,IAAAA,sCAAiB,EAACJ;wBAClC,IAAIG,YAAYH,SAAS;4BACvBC,WAAE,CAACI,aAAa,CAACP,MAAMK,SAAS;wBAClC;oBACF,EAAE,OAAOG,MAAM;oBACb,gBAAgB;oBAClB;gBACF;YACF;QACF;QACAvD,SAAS,MAAM2C,IAAIE,YAAY;IACjC;AAEJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility Layer for Node.js 0.8+
|
|
3
|
+
* Local to this package - contains only needed functions.
|
|
4
|
+
*/
|
|
5
|
+
export declare function stringStartsWith(str: string, search: string, position?: number): boolean;
|
|
6
|
+
export declare function stringEndsWith(str: string, search: string, position?: number): boolean;
|
|
7
|
+
export declare function stringReplaceAll(str: string, search: string, replace: string): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility Layer for Node.js 0.8+
|
|
3
|
+
* Local to this package - contains only needed functions.
|
|
4
|
+
*/ /**
|
|
5
|
+
* String.prototype.startsWith wrapper for Node.js 0.8+
|
|
6
|
+
* - Uses native startsWith on Node 4.0+ / ES2015+
|
|
7
|
+
* - Falls back to indexOf on Node 0.8-3.x
|
|
8
|
+
*/ var hasStartsWith = typeof String.prototype.startsWith === 'function';
|
|
9
|
+
export function stringStartsWith(str, search, position) {
|
|
10
|
+
if (hasStartsWith) {
|
|
11
|
+
return str.startsWith(search, position);
|
|
12
|
+
}
|
|
13
|
+
position = position || 0;
|
|
14
|
+
return str.indexOf(search, position) === position;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* String.prototype.endsWith wrapper for Node.js 0.8+
|
|
18
|
+
* - Uses native endsWith on Node 4.0+ / ES2015+
|
|
19
|
+
* - Falls back to lastIndexOf on Node 0.8-3.x
|
|
20
|
+
*/ var hasEndsWith = typeof String.prototype.endsWith === 'function';
|
|
21
|
+
export function stringEndsWith(str, search, position) {
|
|
22
|
+
if (hasEndsWith) {
|
|
23
|
+
return str.endsWith(search, position);
|
|
24
|
+
}
|
|
25
|
+
var len = position === undefined ? str.length : position;
|
|
26
|
+
return str.lastIndexOf(search) === len - search.length;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* String.prototype.replaceAll wrapper for Node.js 0.8+
|
|
30
|
+
* - Uses native replaceAll on Node 15.0+ / ES2021+
|
|
31
|
+
* - Falls back to regex replace on older versions
|
|
32
|
+
*/ // biome-ignore lint/suspicious/noExplicitAny: Feature detection for ES2021 replaceAll
|
|
33
|
+
var hasReplaceAll = typeof String.prototype.replaceAll === 'function';
|
|
34
|
+
export function stringReplaceAll(str, search, replace) {
|
|
35
|
+
if (hasReplaceAll) {
|
|
36
|
+
// biome-ignore lint/suspicious/noExplicitAny: Using native replaceAll when available
|
|
37
|
+
return str.replaceAll(search, replace);
|
|
38
|
+
}
|
|
39
|
+
// Escape special regex characters
|
|
40
|
+
var escaped = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
41
|
+
return str.replace(new RegExp(escaped, 'g'), replace);
|
|
42
|
+
}
|
|
@@ -0,0 +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 */\nvar 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 */\nvar 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 var 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\nvar 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 var 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,IAAIA,gBAAgB,OAAOC,OAAOC,SAAS,CAACC,UAAU,KAAK;AAE3D,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,IAAIE,cAAc,OAAOR,OAAOC,SAAS,CAACQ,QAAQ,KAAK;AAEvD,OAAO,SAASC,eAAeN,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIE,aAAa;QACf,OAAOJ,IAAIK,QAAQ,CAACJ,QAAQC;IAC9B;IACA,IAAIK,MAAML,aAAaM,YAAYR,IAAIS,MAAM,GAAGP;IAChD,OAAOF,IAAIU,WAAW,CAACT,YAAYM,MAAMN,OAAOQ,MAAM;AACxD;AAEA;;;;CAIC,GACD,sFAAsF;AACtF,IAAIE,gBAAgB,OAAO,AAACf,OAAOC,SAAS,CAASe,UAAU,KAAK;AAEpE,OAAO,SAASC,iBAAiBb,GAAW,EAAEC,MAAc,EAAEa,OAAe;IAC3E,IAAIH,eAAe;QACjB,qFAAqF;QACrF,OAAO,AAACX,IAAYY,UAAU,CAACX,QAAQa;IACzC;IACA,kCAAkC;IAClC,IAAIC,UAAUd,OAAOa,OAAO,CAAC,uBAAuB;IACpD,OAAOd,IAAIc,OAAO,CAAC,IAAIE,OAAOD,SAAS,MAAMD;AAC/C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { stringStartsWith } from '../compat.js';
|
|
2
2
|
export const extensions = {
|
|
3
3
|
'.ts': '.js',
|
|
4
4
|
'.tsx': '.js',
|
|
@@ -11,7 +11,7 @@ export function replaceExtension(ext) {
|
|
|
11
11
|
}
|
|
12
12
|
// Helper to check if a path is relative (starts with ./ or ../)
|
|
13
13
|
function isRelativePath(path) {
|
|
14
|
-
return
|
|
14
|
+
return stringStartsWith(path, './') || stringStartsWith(path, '../');
|
|
15
15
|
}
|
|
16
16
|
// Multi-pattern transformer for TypeScript extension rewriting
|
|
17
17
|
// See: https://github.com/microsoft/TypeScript/issues/61037
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/rewriteExtensions.ts"],"sourcesContent":["import { stringStartsWith } from '../compat.ts';\n\nexport const extensions = {\n '.ts': '.js',\n '.tsx': '.js',\n '.mts': '.mjs',\n '.cts': '.cjs',\n};\n\nexport function replaceExtension(ext: string): string {\n const replace = extensions[ext];\n return replace === undefined ? ext : replace;\n}\n\n// Helper to check if a path is relative (starts with ./ or ../)\nfunction isRelativePath(path: string): boolean {\n return stringStartsWith(path, './') || stringStartsWith(path, '../');\n}\n\n// Multi-pattern transformer for TypeScript extension rewriting\n// See: https://github.com/microsoft/TypeScript/issues/61037\n// TODO: Remove when TypeScript natively supports rewriteRelativeImportExtensions in .d.ts files\n\nexport function rewriteExtensions(content: string): string {\n let result = content;\n\n // Pattern 1: Import/Export statements (with optional 'type' keyword)\n // Matches: import { X } from './path.ts'\n // import type { X } from './path.ts'\n // export * from './path.ts'\n // export type * from './path.ts'\n result = result.replace(/\\b(import|export)(\\s+type)?(?:\\s+[^'\"]*?\\s+from\\s+|\\s+)['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]/g, (match, _keyword, _typeKeyword, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 2: Dynamic import types\n // Matches: typeof import('./path.ts')\n result = result.replace(/\\bimport\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n // Pattern 3: Triple-slash path references\n // Matches: /// <reference path=\"./file.ts\" />\n // /// <reference path=\"./file.d.ts\" />\n result = result.replace(/\\/\\/\\/\\s*<reference\\s+path\\s*=\\s*['\"]([^'\"]+)\\.(d\\.ts|tsx?|mts|cts)['\"]\\s*\\/>/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n // Special case: .d.ts → .d.js\n const newExt = ext === 'd.ts' ? '.d.js' : replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n\n// CJS-specific version that also handles require() statements\nexport function rewriteExtensionsCJS(content: string): string {\n // Start with all ESM patterns\n let result = rewriteExtensions(content);\n\n // Pattern 4: CommonJS require() statements\n // Matches: require('./path.ts')\n result = result.replace(/\\brequire\\s*\\(\\s*['\"]([^'\"]+)\\.(tsx?|mts|cts)['\"]\\s*\\)/g, (match, path, ext) => {\n if (!isRelativePath(path)) return match;\n const newExt = replaceExtension(`.${ext}`);\n return match.replace(`.${ext}\"`, `${newExt}\"`).replace(`.${ext}'`, `${newExt}'`).replace(`.${ext}\\``, `${newExt}\\``);\n });\n\n return result;\n}\n"],"names":["stringStartsWith","extensions","replaceExtension","ext","replace","undefined","isRelativePath","path","rewriteExtensions","content","result","match","_keyword","_typeKeyword","newExt","rewriteExtensionsCJS"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,eAAe;AA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AO,EAAE,CAAC;IACrH;IAEA,OAAOJ;AACT"}
|
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js
|
|
2
2
|
// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE
|
|
3
|
-
import
|
|
4
|
-
import URL from 'core-js-pure/actual/url/index.js';
|
|
3
|
+
import Module from 'module';
|
|
5
4
|
import path from 'path';
|
|
5
|
+
import url from 'url';
|
|
6
|
+
import { stringReplaceAll } from '../compat.js';
|
|
7
|
+
// ESM-compatible require
|
|
8
|
+
var _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
9
|
+
// URL class - available natively in Node 7.0+, use core-js-pure for Node 0.8-6.x
|
|
10
|
+
// biome-ignore lint/suspicious/noExplicitAny: Feature detection for URL class
|
|
11
|
+
var URLClass = url.URL;
|
|
12
|
+
if (!URLClass) {
|
|
13
|
+
URLClass = _require('core-js-pure/actual/url/index.js');
|
|
14
|
+
}
|
|
6
15
|
const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
7
|
-
export function fileURLToPath(
|
|
8
|
-
|
|
9
|
-
|
|
16
|
+
export function fileURLToPath(urlInput) {
|
|
17
|
+
var parsedUrl;
|
|
18
|
+
if (typeof urlInput === 'string') {
|
|
19
|
+
parsedUrl = new URLClass(urlInput);
|
|
20
|
+
} else {
|
|
21
|
+
parsedUrl = urlInput;
|
|
10
22
|
}
|
|
11
|
-
if (
|
|
23
|
+
if (parsedUrl.protocol !== 'file:') {
|
|
12
24
|
throw new Error('The URL must use the file: protocol');
|
|
13
25
|
}
|
|
14
26
|
if (isWindows) {
|
|
15
|
-
if (/%2f|%5c/i.test(
|
|
27
|
+
if (/%2f|%5c/i.test(parsedUrl.pathname)) {
|
|
16
28
|
throw new Error('The file: URL path must not include encoded \\ or / characters');
|
|
17
29
|
}
|
|
18
30
|
} else {
|
|
19
|
-
if (
|
|
31
|
+
if (parsedUrl.hostname) {
|
|
20
32
|
throw new Error("The file: URL host must be 'localhost' or empty");
|
|
21
33
|
}
|
|
22
|
-
if (/%2f/i.test(
|
|
34
|
+
if (/%2f/i.test(parsedUrl.pathname)) {
|
|
23
35
|
throw new Error('The file: URL path must not include encoded / characters');
|
|
24
36
|
}
|
|
25
37
|
}
|
|
26
|
-
const pathname = path.normalize(decodeURIComponent(
|
|
38
|
+
const pathname = path.normalize(decodeURIComponent(parsedUrl.pathname));
|
|
27
39
|
if (isWindows) {
|
|
28
|
-
if (
|
|
40
|
+
if (parsedUrl.hostname) return `\\\\${parsedUrl.hostname}${pathname}`;
|
|
29
41
|
const letter = pathname.charCodeAt(1) | 0x20;
|
|
30
42
|
if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */ ) {
|
|
31
43
|
throw new Error('The file: URL path must be absolute');
|
|
@@ -41,14 +53,14 @@ export function pathToFileURL(pathname) {
|
|
|
41
53
|
} else if (isWindows && pathname[pathname.length - 1] === '\\') {
|
|
42
54
|
resolved += '\\';
|
|
43
55
|
}
|
|
44
|
-
resolved =
|
|
45
|
-
resolved =
|
|
46
|
-
resolved =
|
|
47
|
-
resolved =
|
|
48
|
-
resolved =
|
|
49
|
-
resolved =
|
|
56
|
+
resolved = stringReplaceAll(resolved, '%', '%25'); // Must be first
|
|
57
|
+
resolved = stringReplaceAll(resolved, '#', '%23');
|
|
58
|
+
resolved = stringReplaceAll(resolved, '?', '%3f');
|
|
59
|
+
resolved = stringReplaceAll(resolved, '\n', '%0a');
|
|
60
|
+
resolved = stringReplaceAll(resolved, '\r', '%0d');
|
|
61
|
+
resolved = stringReplaceAll(resolved, '\t', '%09');
|
|
50
62
|
if (!isWindows) {
|
|
51
|
-
resolved =
|
|
63
|
+
resolved = stringReplaceAll(resolved, '\\', '%5c');
|
|
52
64
|
}
|
|
53
|
-
return new
|
|
65
|
+
return new URLClass(`file:${resolved}`);
|
|
54
66
|
}
|
|
@@ -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
|
|
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\nvar _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\nvar 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 var 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,IAAIC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYJ,GAAG,IAAIG;AAExF,iFAAiF;AACjF,8EAA8E;AAC9E,IAAIE,WAAuB,AAACL,IAAYM,GAAG;AAC3C,IAAI,CAACD,UAAU;IACbA,WAAWH,SAAS;AACtB;AAEA,MAAMK,YAAYC,QAAQC,QAAQ,KAAK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;IACnEA,WAAWzB,iBAAiByB,UAAU,KAAK;IAC3CA,WAAWzB,iBAAiByB,UAAU,KAAK;IAC3CA,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/dist/esm/toPath.js
CHANGED
|
@@ -2,8 +2,8 @@ import isAbsolute from 'is-absolute';
|
|
|
2
2
|
import module from 'module';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import * as resolve from 'resolve';
|
|
5
|
-
import startsWith from 'starts-with';
|
|
6
5
|
import url from 'url';
|
|
6
|
+
import { stringStartsWith } from './compat.js';
|
|
7
7
|
import { moduleRegEx } from './constants.js';
|
|
8
8
|
import importMetaResolve from './lib/import-meta-resolve.js';
|
|
9
9
|
import * as urlPolyfills from './lib/urlFileUrl.js';
|
|
@@ -17,7 +17,7 @@ function getParentPath(context) {
|
|
|
17
17
|
return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
|
|
18
18
|
}
|
|
19
19
|
export default function toPath(specifier, context) {
|
|
20
|
-
if (
|
|
20
|
+
if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);
|
|
21
21
|
if (isAbsolute(specifier)) return specifier;
|
|
22
22
|
if (specifier[0] === '.') {
|
|
23
23
|
const parentPath = context ? getParentPath(context) : process.cwd();
|
package/dist/esm/toPath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import isAbsolute from 'is-absolute';\nimport module from 'module';\nimport path from 'path';\nimport * as resolve from 'resolve';\nimport url from 'url';\n\nimport { stringStartsWith } from './compat.ts';\nimport { moduleRegEx } from './constants.ts';\nimport importMetaResolve from './lib/import-meta-resolve.ts';\nimport * as urlPolyfills from './lib/urlFileUrl.ts';\nimport type { Context } from './types.ts';\n\nconst resolveSync = (resolve.default ?? resolve).sync;\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context): string {\n if (context.parentPath) return path.dirname(context.parentPath);\n return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();\n}\n\nexport default function toPath(specifier: string, context?: Context): string {\n if (stringStartsWith(specifier, 'file:')) return fileURLToPath(specifier);\n if (isAbsolute(specifier)) return specifier;\n if (specifier[0] === '.') {\n const parentPath = context ? getParentPath(context) : process.cwd();\n return path.join(parentPath, specifier);\n }\n if (moduleRegEx.test(specifier)) {\n const parentPath = context ? getParentPath(context) : process.cwd();\n if (!useCJS) {\n try {\n const entryURL = importMetaResolve(specifier, pathToFileURL(parentPath));\n if (entryURL) return fileURLToPath(entryURL);\n } catch (_) {\n /* it may fail due to commonjs edge cases */\n }\n }\n const entryPath = resolveSync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["isAbsolute","module","path","resolve","url","stringStartsWith","moduleRegEx","importMetaResolve","urlPolyfills","resolveSync","default","sync","useCJS","createRequire","fileURLToPath","pathToFileURL","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","join","test","entryURL","_","entryPath","basedir","extensions"],"mappings":"AAAA,OAAOA,gBAAgB,cAAc;AACrC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,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AAYe,WAAW;YACvCM,SAASZ;YACTa,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOL;AACT"}
|
|
@@ -12,8 +12,8 @@ function dispatch(version, contents, fileName, tsconfig) {
|
|
|
12
12
|
return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);
|
|
13
13
|
}
|
|
14
14
|
export default function transformSync(contents, fileName, tsconfig) {
|
|
15
|
-
if (typeof contents !== 'string') throw new Error('
|
|
16
|
-
if (typeof fileName !== 'string') throw new Error('
|
|
15
|
+
if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');
|
|
16
|
+
if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');
|
|
17
17
|
if (!tsconfig) tsconfig = loadConfigSync(process.cwd());
|
|
18
18
|
return dispatch(version, contents, fileName, tsconfig);
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformSync.ts"],"sourcesContent":["import path from 'path';\nimport loadConfigSync from 'read-tsconfig-sync';\nimport url from 'url';\n\nimport type { TSConfig } from './types.ts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformSync.js');\n\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nfunction dispatch(version, contents, fileName, tsconfig) {\n if (version === 'local') return _require(workerPath)(contents, fileName, tsconfig);\n return _require('node-version-call')(version, workerPath, contents, fileName, tsconfig);\n}\n\nimport type { Output } from '@swc/core';\nexport default function transformSync(contents: string, fileName: string, tsconfig?: TSConfig): Output {\n if (typeof contents !== 'string') throw new Error('transformSync: unexpected contents');\n if (typeof fileName !== 'string') throw new Error('transformSync: unexpected fileName');\n if (!tsconfig) tsconfig = loadConfigSync(process.cwd());\n return dispatch(version, contents, fileName, tsconfig);\n}\n"],"names":["path","loadConfigSync","url","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","_require","require","createRequire","dispatch","contents","fileName","tsconfig","transformSync","Error","cwd"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,oBAAoB,qBAAqB;AAChD,OAAOC,SAAS,MAAM;AAItB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcT,IAAIU,aAAa,CAAC,YAAYV,GAAG,IAAIS;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYhB,GAAG,IAAIe;AAE1F,SAASE,SAASX,OAAO,EAAEY,QAAQ,EAAEC,QAAQ,EAAEC,QAAQ;IACrD,IAAId,YAAY,SAAS,OAAOQ,SAASH,YAAYO,UAAUC,UAAUC;IACzE,OAAON,SAAS,qBAAqBR,SAASK,YAAYO,UAAUC,UAAUC;AAChF;AAGA,eAAe,SAASC,cAAcH,QAAgB,EAAEC,QAAgB,EAAEC,QAAmB;IAC3F,IAAI,OAAOF,aAAa,UAAU,MAAM,IAAII,MAAM;IAClD,IAAI,OAAOH,aAAa,UAAU,MAAM,IAAIG,MAAM;IAClD,IAAI,CAACF,UAAUA,WAAWrB,eAAeG,QAAQqB,GAAG;IACpD,OAAON,SAASX,SAASY,UAAUC,UAAUC;AAC/C"}
|
|
@@ -2,6 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import Iterator from 'fs-iterator';
|
|
3
3
|
import Module from 'module';
|
|
4
4
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
5
|
+
import { stringEndsWith } from '../compat.js';
|
|
5
6
|
import { typeFileRegEx } from '../constants.js';
|
|
6
7
|
import createMatcher from '../createMatcher.js';
|
|
7
8
|
import { rewriteExtensions } from '../lib/rewriteExtensions.js';
|
|
@@ -55,7 +56,7 @@ export default function transformTypesWorker(src, dest, options, callback) {
|
|
|
55
56
|
// TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037
|
|
56
57
|
if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {
|
|
57
58
|
res.emittedFiles.forEach((file)=>{
|
|
58
|
-
if (file
|
|
59
|
+
if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {
|
|
59
60
|
try {
|
|
60
61
|
const content = fs.readFileSync(file, 'utf8');
|
|
61
62
|
const updated = rewriteExtensions(content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): undefined {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err): undefined => {\n if (err) {\n callback(err);\n return;\n }\n\n const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...compilerOptions.options,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n\n // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {\n res.emittedFiles.forEach((file) => {\n if (file
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformTypes.ts"],"sourcesContent":["import fs from 'fs';\nimport Iterator, { type Entry } from 'fs-iterator';\nimport Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport { stringEndsWith } from '../compat.ts';\nimport { typeFileRegEx } from '../constants.ts';\nimport createMatcher from '../createMatcher.ts';\nimport { rewriteExtensions } from '../lib/rewriteExtensions.ts';\n\nimport type { ConfigOptions, TransformTypesCallback } from '../types.ts';\n\nexport default function transformTypesWorker(src: string, dest: string, options: ConfigOptions, callback: TransformTypesCallback): undefined {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n const ts = _require('typescript');\n\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry: Entry): undefined => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n entries.push(entry);\n },\n { concurrency: Infinity },\n (err): undefined => {\n if (err) {\n callback(err);\n return;\n }\n\n const compilerOptions = ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, '');\n const config = {\n fileNames: entries.map((entry) => entry.fullPath),\n options: {\n ...compilerOptions.options,\n outDir: dest,\n noEmit: false,\n allowJs: true,\n declaration: true,\n emitDeclarationOnly: true,\n listEmittedFiles: true,\n },\n projectReferences: tsconfig.config.references,\n };\n const { fileNames, options, projectReferences } = config;\n const host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, ts.sys);\n const programOptions = {\n rootNames: fileNames,\n options,\n projectReferences,\n host,\n configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics({ fileNames, options }),\n };\n const program = ts.createProgram(programOptions);\n const res = program.emit();\n\n // TODO: remove patch for https://github.com/microsoft/TypeScript/issues/61037\n if (res.emittedFiles && compilerOptions.options.rewriteRelativeImportExtensions) {\n res.emittedFiles.forEach((file) => {\n if (stringEndsWith(file, '.d.ts') || stringEndsWith(file, '.d.cts') || stringEndsWith(file, '.d.mts')) {\n try {\n const content = fs.readFileSync(file, 'utf8');\n const updated = rewriteExtensions(content);\n if (updated !== content) {\n fs.writeFileSync(file, updated, 'utf8');\n }\n } catch (_err) {\n // Ignore errors\n }\n }\n });\n }\n callback(null, res.emittedFiles);\n }\n );\n}\n"],"names":["fs","Iterator","Module","_require","require","createRequire","url","stringEndsWith","typeFileRegEx","createMatcher","rewriteExtensions","transformTypesWorker","src","dest","options","callback","tsconfig","matcher","ts","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","push","concurrency","Infinity","err","compilerOptions","convertCompilerOptionsFromJson","config","fileNames","map","outDir","noEmit","allowJs","declaration","emitDeclarationOnly","listEmittedFiles","projectReferences","references","host","createCompilerHostWorker","undefined","sys","programOptions","rootNames","configFileParsingDiagnostics","getConfigFileParsingDiagnostics","program","createProgram","res","emit","emittedFiles","rewriteRelativeImportExtensions","file","content","readFileSync","updated","writeFileSync","_err"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,cAA8B,cAAc;AACnD,OAAOC,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,SAASG,cAAc,QAAQ,eAAe;AAC9C,SAASC,aAAa,QAAQ,kBAAkB;AAChD,OAAOC,mBAAmB,sBAAsB;AAChD,SAASC,iBAAiB,QAAQ,8BAA8B;AAIhE,eAAe,SAASC,qBAAqBC,GAAW,EAAEC,IAAY,EAAEC,OAAsB,EAAEC,QAAgC;IAC9H,MAAMC,WAAWF,QAAQE,QAAQ;IACjC,MAAMC,UAAUR,cAAcO;IAC9B,MAAME,KAAKf,SAAS;IAEpB,MAAMgB,UAAU,EAAE;IAClB,MAAMC,WAAW,IAAInB,SAASW;IAC9BQ,SAASC,OAAO,CACd,CAACC;QACC,IAAI,CAACA,MAAMC,KAAK,CAACC,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AAMC,UAAU5D,GAAG6D,YAAY,CAACF,MAAM;wBACtC,MAAMG,UAAUpD,kBAAkBkD;wBAClC,IAAIE,YAAYF,SAAS;4BACvB5D,GAAG+D,aAAa,CAACJ,MAAMG,SAAS;wBAClC;oBACF,EAAE,OAAOE,MAAM;oBACb,gBAAgB;oBAClB;gBACF;YACF;QACF;QACAjD,SAAS,MAAMwC,IAAIE,YAAY;IACjC;AAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"read-tsconfig-sync": "*",
|
|
58
58
|
"resolve": "*",
|
|
59
59
|
"rimraf2": "*",
|
|
60
|
-
"starts-with": "^1.0.2",
|
|
61
60
|
"test-match": "*",
|
|
62
61
|
"ts-node": "*",
|
|
63
62
|
"typescript": "*"
|