ts-swc-transform 1.14.0 → 1.15.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/assets/import-meta-resolve.cjs +1481 -0
- package/dist/cjs/createMatcher.cjs +1 -0
- package/dist/cjs/createMatcher.cjs.map +1 -1
- package/dist/cjs/lib/patchCJS.cjs +13 -6
- package/dist/cjs/lib/patchCJS.cjs.map +1 -1
- package/dist/cjs/lib/url-file-url.cjs +78 -0
- package/dist/cjs/lib/url-file-url.cjs.map +1 -0
- package/dist/cjs/toPath.cjs +58 -27
- package/dist/cjs/toPath.cjs.map +1 -1
- package/dist/esm/createMatcher.mjs +1 -0
- package/dist/esm/createMatcher.mjs.map +1 -1
- package/dist/esm/lib/patchCJS.mjs +2 -2
- package/dist/esm/lib/patchCJS.mjs.map +1 -1
- package/dist/esm/lib/url-file-url.mjs +54 -0
- package/dist/esm/lib/url-file-url.mjs.map +1 -0
- package/dist/esm/toPath.mjs +19 -28
- package/dist/esm/toPath.mjs.map +1 -1
- package/dist/types/lib/patchCJS.d.ts +1 -0
- package/dist/types/lib/url-file-url.d.ts +3 -0
- package/package.json +7 -8
- package/dist/cjs/lib/fileURLToPath.cjs +0 -23
- package/dist/cjs/lib/fileURLToPath.cjs.map +0 -1
- package/dist/esm/lib/fileURLToPath.mjs +0 -7
- package/dist/esm/lib/fileURLToPath.mjs.map +0 -1
- package/dist/types/lib/fileURLToPath.d.ts +0 -2
|
@@ -26,6 +26,7 @@ function createMatcher(tsConfig) {
|
|
|
26
26
|
var pattern = (0, _unixify.default)(condition);
|
|
27
27
|
if (!_pathposix.default.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = _pathposix.default.join(tsconfigPath, pattern);
|
|
28
28
|
return function match(filePath) {
|
|
29
|
+
// @ts-ignore
|
|
29
30
|
return filePath.startsWith(pattern) || (0, _minimatch.default)(filePath, pattern);
|
|
30
31
|
};
|
|
31
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["createMatcher","tsConfig","tsconfig","loadTsConfig","tsconfigPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAOA;;;eAAwBA;;;gEANF;gEACL;8DACG;mEACK;;;;;;AAGV,SAASA,cAAcC,QAAwB;IAC5D,IAAMC,WAAWC,IAAAA,qBAAY,EAAC;QAAED,UAAUD;IAAS,GAAG;IACtD,IAAMG,eAAeC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACL,SAASG,IAAI;IAEvD,SAASG,QAAQC,SAAS;QACxB,IAAIC,UAAUH,IAAAA,gBAAO,EAACE;QACtB,IAAI,CAACJ,kBAAI,CAACM,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUL,kBAAI,CAACQ,IAAI,CAACT,cAAcM;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAACf,CAAAA,SAASgB,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACZ;IACrD,IAAMa,WAAW,AAACnB,CAAAA,SAASgB,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACZ;IAErD,OAAO,SAASe,QAAQR,QAAQ;QAC9B,IAAIA,SAASS,QAAQ,CAAC,UAAU,OAAO;QAEvCT,WAAWR,IAAAA,gBAAO,EAACQ;QACnB,IAAK,IAAIU,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,IAAK,IAAIY,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACZ,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASS,MAAM;IACzB;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n // @ts-ignore\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["createMatcher","tsConfig","tsconfig","loadTsConfig","tsconfigPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAOA;;;eAAwBA;;;gEANF;gEACL;8DACG;mEACK;;;;;;AAGV,SAASA,cAAcC,QAAwB;IAC5D,IAAMC,WAAWC,IAAAA,qBAAY,EAAC;QAAED,UAAUD;IAAS,GAAG;IACtD,IAAMG,eAAeC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACL,SAASG,IAAI;IAEvD,SAASG,QAAQC,SAAS;QACxB,IAAIC,UAAUH,IAAAA,gBAAO,EAACE;QACtB,IAAI,CAACJ,kBAAI,CAACM,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUL,kBAAI,CAACQ,IAAI,CAACT,cAAcM;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,aAAa;YACb,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAACf,CAAAA,SAASgB,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACZ;IACrD,IAAMa,WAAW,AAACnB,CAAAA,SAASgB,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACZ;IAErD,OAAO,SAASe,QAAQR,QAAQ;QAC9B,IAAIA,SAASS,QAAQ,CAAC,UAAU,OAAO;QAEvCT,WAAWR,IAAAA,gBAAO,EAACQ;QACnB,IAAK,IAAIU,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,IAAK,IAAIY,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACZ,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASS,MAAM;IACzB;AACF"}
|
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
default: function() {
|
|
8
13
|
return patchCJS;
|
|
14
|
+
},
|
|
15
|
+
interop: function() {
|
|
16
|
+
return interop;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
11
19
|
var _constants = require("../constants.cjs");
|
|
@@ -15,13 +23,12 @@ function _interop_require_default(obj) {
|
|
|
15
23
|
default: obj
|
|
16
24
|
};
|
|
17
25
|
}
|
|
18
|
-
|
|
19
|
-
var interopClientDefaultExport = "/* 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; }";
|
|
26
|
+
var interop = "/* 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; }";
|
|
20
27
|
var DEFAULT_EXTENSION = '.cjs';
|
|
21
28
|
function patchCJS(entry, output, options) {
|
|
22
29
|
var cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;
|
|
23
30
|
output.code = (0, _makeReplacements.default)(entry, output.code, _constants.requireRegEx, _constants.extensions, cjsExtension, options);
|
|
24
|
-
output.code +=
|
|
31
|
+
output.code += interop;
|
|
25
32
|
return cjsExtension;
|
|
26
33
|
}
|
|
27
34
|
/* 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/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\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 (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interop;\n\n return cjsExtension;\n}\n"],"names":["patchCJS","interop","DEFAULT_EXTENSION","entry","output","options","cjsExtension","extensions","cjs","code","makeReplacements","requireRegEx"],"mappings":";;;;;;;;;;;IAQA,OAOC;eAPuBA;;IAJXC,OAAO;eAAPA;;;yBAJ4B;uEACZ;;;;;;AAGtB,IAAMA,UAAU;AAEvB,IAAMC,oBAAoB;AAEX,SAASF,SAASG,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,IAAMC,eAAe,AAACD,CAAAA,QAAQE,UAAU,GAAGF,QAAQE,UAAU,CAACC,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FE,OAAOK,IAAI,GAAGC,IAAAA,yBAAgB,EAACP,OAAOC,OAAOK,IAAI,EAAEE,uBAAY,EAAEJ,qBAAU,EAAED,cAAcD;IAC3FD,OAAOK,IAAI,IAAIR;IAEf,OAAOK;AACT"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js
|
|
2
|
+
// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE
|
|
3
|
+
"use strict";
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
function _export(target, all) {
|
|
8
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: all[name]
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
_export(exports, {
|
|
14
|
+
fileURLToPath: function() {
|
|
15
|
+
return fileURLToPath;
|
|
16
|
+
},
|
|
17
|
+
pathToFileURL: function() {
|
|
18
|
+
return pathToFileURL;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
22
|
+
var _replaceall = /*#__PURE__*/ _interop_require_default(require("core-js-pure/actual/string/replace-all.js"));
|
|
23
|
+
var _index = /*#__PURE__*/ _interop_require_default(require("core-js-pure/actual/url/index.js"));
|
|
24
|
+
function _interop_require_default(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
30
|
+
function fileURLToPath(url) {
|
|
31
|
+
if (typeof url === 'string') {
|
|
32
|
+
url = new _index.default(url);
|
|
33
|
+
}
|
|
34
|
+
if (url.protocol !== 'file:') {
|
|
35
|
+
throw new Error('The URL must use the file: protocol');
|
|
36
|
+
}
|
|
37
|
+
if (isWindows) {
|
|
38
|
+
if (/%2f|%5c/i.test(url.pathname)) {
|
|
39
|
+
throw new Error('The file: URL path must not include encoded \\ or / characters');
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
if (url.hostname) {
|
|
43
|
+
throw new Error("The file: URL host must be 'localhost' or empty");
|
|
44
|
+
}
|
|
45
|
+
if (/%2f/i.test(url.pathname)) {
|
|
46
|
+
throw new Error('The file: URL path must not include encoded / characters');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var pathname = _path.default.normalize(decodeURIComponent(url.pathname));
|
|
50
|
+
if (isWindows) {
|
|
51
|
+
if (url.hostname) return "\\\\".concat(url.hostname).concat(pathname);
|
|
52
|
+
var letter = pathname.charCodeAt(1) | 0x20;
|
|
53
|
+
if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */ ) {
|
|
54
|
+
throw new Error('The file: URL path must be absolute');
|
|
55
|
+
}
|
|
56
|
+
return pathname.slice(1);
|
|
57
|
+
}
|
|
58
|
+
return pathname;
|
|
59
|
+
}
|
|
60
|
+
function pathToFileURL(pathname) {
|
|
61
|
+
var resolved = _path.default.resolve(pathname);
|
|
62
|
+
if (pathname[pathname.length - 1] === '/') {
|
|
63
|
+
resolved += '/';
|
|
64
|
+
} else if (isWindows && pathname[pathname.length - 1] === '\\') {
|
|
65
|
+
resolved += '\\';
|
|
66
|
+
}
|
|
67
|
+
resolved = (0, _replaceall.default)(resolved, '%', '%25'); // Must be first
|
|
68
|
+
resolved = (0, _replaceall.default)(resolved, '#', '%23');
|
|
69
|
+
resolved = (0, _replaceall.default)(resolved, '?', '%3f');
|
|
70
|
+
resolved = (0, _replaceall.default)(resolved, '\n', '%0a');
|
|
71
|
+
resolved = (0, _replaceall.default)(resolved, '\r', '%0d');
|
|
72
|
+
resolved = (0, _replaceall.default)(resolved, '\t', '%09');
|
|
73
|
+
if (!isWindows) {
|
|
74
|
+
resolved = (0, _replaceall.default)(resolved, '\\', '%5c');
|
|
75
|
+
}
|
|
76
|
+
return new _index.default("file:".concat(resolved));
|
|
77
|
+
}
|
|
78
|
+
/* 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/lib/url-file-url.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 path from 'path';\nimport replaceAll from 'core-js-pure/actual/string/replace-all.js';\nimport URL from 'core-js-pure/actual/url/index.js';\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(url: string | URL): string {\n if (typeof url === 'string') {\n url = new URL(url);\n }\n\n if (url.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (url.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(url.pathname));\n\n if (isWindows) {\n if (url.hostname) return `\\\\\\\\${url.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 = replaceAll(resolved, '%', '%25'); // Must be first\n resolved = replaceAll(resolved, '#', '%23');\n resolved = replaceAll(resolved, '?', '%3f');\n resolved = replaceAll(resolved, '\\n', '%0a');\n resolved = replaceAll(resolved, '\\r', '%0d');\n resolved = replaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = replaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URL(`file:${resolved}`);\n}\n"],"names":["fileURLToPath","pathToFileURL","isWindows","process","platform","test","env","OSTYPE","url","URL","protocol","Error","pathname","hostname","path","normalize","decodeURIComponent","letter","charCodeAt","slice","resolved","resolve","length","replaceAll"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;;;;;;;;;;;;IAOjEA,aAAa;eAAbA;;IAwCAC,aAAa;eAAbA;;;2DA7CC;iEACM;4DACP;;;;;;AAChB,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAEpF,SAASP,cAAcQ,GAAiB;IAC7C,IAAI,OAAOA,QAAQ,UAAU;QAC3BA,MAAM,IAAIC,cAAG,CAACD;IAChB;IAEA,IAAIA,IAAIE,QAAQ,KAAK,SAAS;QAC5B,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,WAAW;QACb,IAAI,WAAWG,IAAI,CAACG,IAAII,QAAQ,GAAG;YACjC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIH,IAAIK,QAAQ,EAAE;YAChB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAON,IAAI,CAACG,IAAII,QAAQ,GAAG;YAC7B,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,IAAMC,WAAWE,aAAI,CAACC,SAAS,CAACC,mBAAmBR,IAAII,QAAQ;IAE/D,IAAIV,WAAW;QACb,IAAIM,IAAIK,QAAQ,EAAE,OAAO,AAAC,OAAqBD,OAAfJ,IAAIK,QAAQ,EAAY,OAATD;QAE/C,IAAMK,SAASL,SAASM,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAML,SAASM,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIP,MAAM;QAClB;QAEA,OAAOC,SAASO,KAAK,CAAC;IACxB;IAEA,OAAOP;AACT;AAEO,SAASX,cAAcW,QAAgB;IAC5C,IAAIQ,WAAWN,aAAI,CAACO,OAAO,CAACT;IAE5B,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,mBAAU,EAACH,UAAU,KAAK,QAAQ,gBAAgB;IAC7DA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,KAAK;IACrCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,KAAK;IACrCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACtCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACtCA,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IAEtC,IAAI,CAAClB,WAAW;QACdkB,WAAWG,IAAAA,mBAAU,EAACH,UAAU,MAAM;IACxC;IAEA,OAAO,IAAIX,cAAG,CAAC,AAAC,QAAgB,OAATW;AACzB"}
|
package/dist/cjs/toPath.cjs
CHANGED
|
@@ -8,31 +8,69 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return toPath;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var
|
|
11
|
+
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
12
12
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
13
14
|
var _isabsolute = /*#__PURE__*/ _interop_require_default(require("is-absolute"));
|
|
14
15
|
var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
|
|
16
|
+
var _importmetaresolvecjs = require("../../assets/import-meta-resolve.cjs");
|
|
15
17
|
var _constants = require("./constants.cjs");
|
|
16
|
-
var
|
|
18
|
+
var _urlfileurl = /*#__PURE__*/ _interop_require_wildcard(require("./lib/url-file-url.cjs"));
|
|
17
19
|
function _interop_require_default(obj) {
|
|
18
20
|
return obj && obj.__esModule ? obj : {
|
|
19
21
|
default: obj
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
24
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
25
|
+
if (typeof WeakMap !== "function") return null;
|
|
26
|
+
var cacheBabelInterop = new WeakMap();
|
|
27
|
+
var cacheNodeInterop = new WeakMap();
|
|
28
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
29
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
30
|
+
})(nodeInterop);
|
|
31
|
+
}
|
|
32
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
33
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
37
|
+
return {
|
|
38
|
+
default: obj
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
42
|
+
if (cache && cache.has(obj)) {
|
|
43
|
+
return cache.get(obj);
|
|
28
44
|
}
|
|
29
|
-
|
|
45
|
+
var newObj = {
|
|
46
|
+
__proto__: null
|
|
47
|
+
};
|
|
48
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
49
|
+
for(var key in obj){
|
|
50
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
51
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
52
|
+
if (desc && (desc.get || desc.set)) {
|
|
53
|
+
Object.defineProperty(newObj, key, desc);
|
|
54
|
+
} else {
|
|
55
|
+
newObj[key] = obj[key];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
newObj.default = obj;
|
|
60
|
+
if (cache) {
|
|
61
|
+
cache.set(obj, newObj);
|
|
62
|
+
}
|
|
63
|
+
return newObj;
|
|
64
|
+
}
|
|
65
|
+
var useCJS = !_module.default.createRequire;
|
|
66
|
+
var fileURLToPath = _url.default.fileURLToPath || _urlfileurl.fileURLToPath;
|
|
67
|
+
var pathToFileURL = _url.default.pathToFileURL || _urlfileurl.pathToFileURL;
|
|
30
68
|
function getParentPath(context) {
|
|
31
69
|
if (context.parentPath) return _path.default.dirname(context.parentPath);
|
|
32
70
|
return context.parentURL ? _path.default.dirname(toPath(context.parentURL)) : process.cwd();
|
|
33
71
|
}
|
|
34
72
|
function toPath(specifier, context) {
|
|
35
|
-
if (specifier.startsWith('file:')) return (
|
|
73
|
+
if (specifier.startsWith('file:')) return fileURLToPath(specifier);
|
|
36
74
|
if ((0, _isabsolute.default)(specifier)) return specifier;
|
|
37
75
|
if (specifier[0] === '.') {
|
|
38
76
|
var parentPath = context ? getParentPath(context) : process.cwd();
|
|
@@ -40,30 +78,23 @@ function toPath(specifier, context) {
|
|
|
40
78
|
}
|
|
41
79
|
if (_constants.moduleRegEx.test(specifier)) {
|
|
42
80
|
var parentPath1 = context ? getParentPath(context) : process.cwd();
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
if (!useCJS) {
|
|
82
|
+
try {
|
|
83
|
+
var entryURL = (0, _importmetaresolvecjs.resolve)(specifier, pathToFileURL(parentPath1));
|
|
84
|
+
if (entryURL) return fileURLToPath(entryURL);
|
|
85
|
+
} catch (_) {
|
|
86
|
+
/* it may fail due to commonjs edge cases */ }
|
|
87
|
+
}
|
|
88
|
+
var entryPath = _resolve.default.sync(specifier, {
|
|
45
89
|
basedir: parentPath1,
|
|
46
90
|
extensions: [
|
|
47
91
|
'.js',
|
|
48
92
|
'.json',
|
|
49
93
|
'.node',
|
|
50
94
|
'.mjs'
|
|
51
|
-
]
|
|
52
|
-
packageFilter: function packageFilter(json, dir) {
|
|
53
|
-
pkg = {
|
|
54
|
-
json: json,
|
|
55
|
-
dir: dir
|
|
56
|
-
};
|
|
57
|
-
return json;
|
|
58
|
-
}
|
|
95
|
+
]
|
|
59
96
|
});
|
|
60
|
-
if (
|
|
61
|
-
if (pkg.json.name === specifier) return _path.default.join(pkg.dir, pkg.json.module); // the module
|
|
62
|
-
// a relative path. Only accept if it doesn't break the relative naming and it exists
|
|
63
|
-
var modulePath = _path.default.join(pkg.dir, pkg.json.module);
|
|
64
|
-
var mainPath = _path.default.join(pkg.dir, pkg.json.main);
|
|
65
|
-
var moduleResolved = _path.default.join(modulePath, _path.default.relative(mainPath, main));
|
|
66
|
-
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;
|
|
97
|
+
if (entryPath) return entryPath;
|
|
67
98
|
}
|
|
68
99
|
return specifier;
|
|
69
100
|
}
|
package/dist/cjs/toPath.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import module from 'module';\nimport path from 'path';\nimport url from 'url';\nimport isAbsolute from 'is-absolute';\nimport resolveCJS from 'resolve';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants';\nimport * as urlPolyfills from './lib/url-file-url';\nimport type { Context } from './types';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\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) {\n if (specifier.startsWith('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 = resolveESM(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 = resolveCJS.sync(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","useCJS","module","createRequire","fileURLToPath","url","urlPolyfills","pathToFileURL","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","startsWith","isAbsolute","join","moduleRegEx","test","entryURL","resolveESM","_","entryPath","resolveCJS","sync","basedir","extensions"],"mappings":";;;;+BAoBA;;;eAAwBA;;;6DApBL;2DACF;0DACD;iEACO;8DACA;oCAEe;yBACV;kEACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAG9B,IAAMC,SAAS,CAACC,eAAM,CAACC,aAAa;AACpC,IAAMC,gBAAgBC,YAAG,CAACD,aAAa,IAAIE,YAAaF,aAAa;AACrE,IAAMG,gBAAgBF,YAAG,CAACE,aAAa,IAAID,YAAaC,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,CAACZ,OAAOS,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASf,OAAOgB,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOb,cAAcY;IACxD,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,sBAAW,CAACC,IAAI,CAACL,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACd,QAAQ;YACX,IAAI;gBACF,IAAMqB,WAAWC,IAAAA,6BAAU,EAACP,WAAWT,cAAcG;gBACrD,IAAIY,UAAU,OAAOlB,cAAckB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAYC,gBAAU,CAACC,IAAI,CAACX,WAAW;YAC3CY,SAASlB;YACTmB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIJ,WAAW,OAAOA;IACxB;IAEA,OAAOT;AACT"}
|
|
@@ -11,6 +11,7 @@ export default function createMatcher(tsConfig) {
|
|
|
11
11
|
let pattern = unixify(condition);
|
|
12
12
|
if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);
|
|
13
13
|
return function match(filePath) {
|
|
14
|
+
// @ts-ignore
|
|
14
15
|
return filePath.startsWith(pattern) || minimatch(filePath, pattern);
|
|
15
16
|
};
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AACA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,kBAAkB,iBAAiB;AAG1C,eAAe,SAASC,cAAcC,QAAwB;IAC5D,MAAMC,WAAWH,aAAa;QAAEG,UAAUD;IAAS,GAAG;IACtD,MAAME,eAAeN,KAAKO,OAAO,CAACN,QAAQI,SAASL,IAAI;IAEvD,SAASQ,QAAQC,SAAS;QACxB,IAAIC,UAAUT,QAAQQ;QACtB,IAAI,CAACT,KAAKW,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUV,KAAKa,IAAI,CAACP,cAAcI;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYX,UAAUgB,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAACX,CAAAA,SAASY,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACX;IACrD,MAAMY,WAAW,AAACf,CAAAA,SAASY,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACX;IAErD,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWd,QAAQc;QACnB,IAAK,IAAIS,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACT,WAAW,OAAO;QACpC;QACA,IAAK,IAAIW,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASS,MAAM;IACzB;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/createMatcher.ts"],"sourcesContent":["import type { TsConfigResult } from 'get-tsconfig-compat';\nimport minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\nimport loadTsConfig from './loadTsConfig';\nimport type { Matcher } from './types';\n\nexport default function createMatcher(tsConfig: TsConfigResult): Matcher {\n const tsconfig = loadTsConfig({ tsconfig: tsConfig }, 'transformTypes');\n const tsconfigPath = path.dirname(unixify(tsconfig.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(tsconfigPath, pattern);\n\n return function match(filePath) {\n // @ts-ignore\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (tsconfig.config.include || []).map(matchFn);\n const excludes = (tsconfig.config.exclude || []).map(matchFn);\n\n return function matcher(filePath) {\n if (filePath.endsWith('.json')) return false;\n\n filePath = unixify(filePath);\n for (let i = 0; i < excludes.length; ++i) {\n if (excludes[i](filePath)) return false;\n }\n for (let j = 0; j < includes.length; ++j) {\n if (includes[j](filePath)) return true;\n }\n return !includes.length;\n };\n}\n"],"names":["minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AACA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,kBAAkB,iBAAiB;AAG1C,eAAe,SAASC,cAAcC,QAAwB;IAC5D,MAAMC,WAAWH,aAAa;QAAEG,UAAUD;IAAS,GAAG;IACtD,MAAME,eAAeN,KAAKO,OAAO,CAACN,QAAQI,SAASL,IAAI;IAEvD,SAASQ,QAAQC,SAAS;QACxB,IAAIC,UAAUT,QAAQQ;QACtB,IAAI,CAACT,KAAKW,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUV,KAAKa,IAAI,CAACP,cAAcI;QAE7F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,aAAa;YACb,OAAOA,SAASH,UAAU,CAACF,YAAYX,UAAUgB,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAACX,CAAAA,SAASY,MAAM,CAACC,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACX;IACrD,MAAMY,WAAW,AAACf,CAAAA,SAASY,MAAM,CAACI,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACX;IAErD,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWd,QAAQc;QACnB,IAAK,IAAIS,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACT,WAAW,OAAO;QACpC;QACA,IAAK,IAAIW,IAAI,GAAGA,IAAIV,SAASS,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIV,QAAQ,CAACU,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASS,MAAM;IACzB;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { extensions, requireRegEx } from '../constants.mjs';
|
|
2
2
|
import makeReplacements from './makeReplacements.mjs';
|
|
3
3
|
// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125
|
|
4
|
-
const
|
|
4
|
+
export const interop = "/* 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; }";
|
|
5
5
|
const DEFAULT_EXTENSION = '.cjs';
|
|
6
6
|
export default function patchCJS(entry, output, options) {
|
|
7
7
|
const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;
|
|
8
8
|
output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);
|
|
9
|
-
output.code +=
|
|
9
|
+
output.code += interop;
|
|
10
10
|
return cjsExtension;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/patchCJS.ts"],"sourcesContent":["import { extensions, requireRegEx } from '../constants';\nimport makeReplacements from './makeReplacements';\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 (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }\";\n\nconst DEFAULT_EXTENSION = '.cjs';\n\nexport default function patchCJS(entry, output, options) {\n const cjsExtension = (options.extensions ? options.extensions.cjs : DEFAULT_EXTENSION) || DEFAULT_EXTENSION;\n\n output.code = makeReplacements(entry, output.code, requireRegEx, extensions, cjsExtension, options);\n output.code += interop;\n\n return cjsExtension;\n}\n"],"names":["extensions","requireRegEx","makeReplacements","interop","DEFAULT_EXTENSION","patchCJS","entry","output","options","cjsExtension","cjs","code"],"mappings":"AAAA,SAASA,UAAU,EAAEC,YAAY,QAAQ,eAAe;AACxD,OAAOC,sBAAsB,qBAAqB;AAElD,0HAA0H;AAC1H,OAAO,MAAMC,UAAU,oQAAoQ;AAE3R,MAAMC,oBAAoB;AAE1B,eAAe,SAASC,SAASC,KAAK,EAAEC,MAAM,EAAEC,OAAO;IACrD,MAAMC,eAAe,AAACD,CAAAA,QAAQR,UAAU,GAAGQ,QAAQR,UAAU,CAACU,GAAG,GAAGN,iBAAgB,KAAMA;IAE1FG,OAAOI,IAAI,GAAGT,iBAAiBI,OAAOC,OAAOI,IAAI,EAAEV,cAAcD,YAAYS,cAAcD;IAC3FD,OAAOI,IAAI,IAAIR;IAEf,OAAOM;AACT"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Extracted from https://raw.githubusercontent.com/holepunchto/url-file-url/refs/heads/main/index.js
|
|
2
|
+
// Apache 2 License https://github.com/holepunchto/url-file-url/blob/main/LICENSE
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import replaceAll from 'core-js-pure/actual/string/replace-all.js';
|
|
5
|
+
import URL from 'core-js-pure/actual/url/index.js';
|
|
6
|
+
const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
7
|
+
export function fileURLToPath(url) {
|
|
8
|
+
if (typeof url === 'string') {
|
|
9
|
+
url = new URL(url);
|
|
10
|
+
}
|
|
11
|
+
if (url.protocol !== 'file:') {
|
|
12
|
+
throw new Error('The URL must use the file: protocol');
|
|
13
|
+
}
|
|
14
|
+
if (isWindows) {
|
|
15
|
+
if (/%2f|%5c/i.test(url.pathname)) {
|
|
16
|
+
throw new Error('The file: URL path must not include encoded \\ or / characters');
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
if (url.hostname) {
|
|
20
|
+
throw new Error("The file: URL host must be 'localhost' or empty");
|
|
21
|
+
}
|
|
22
|
+
if (/%2f/i.test(url.pathname)) {
|
|
23
|
+
throw new Error('The file: URL path must not include encoded / characters');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const pathname = path.normalize(decodeURIComponent(url.pathname));
|
|
27
|
+
if (isWindows) {
|
|
28
|
+
if (url.hostname) return `\\\\${url.hostname}${pathname}`;
|
|
29
|
+
const letter = pathname.charCodeAt(1) | 0x20;
|
|
30
|
+
if (letter < 0x61 /* a */ || letter > 0x7a /* z */ || pathname.charCodeAt(2) !== 0x3a /* : */ ) {
|
|
31
|
+
throw new Error('The file: URL path must be absolute');
|
|
32
|
+
}
|
|
33
|
+
return pathname.slice(1);
|
|
34
|
+
}
|
|
35
|
+
return pathname;
|
|
36
|
+
}
|
|
37
|
+
export function pathToFileURL(pathname) {
|
|
38
|
+
let resolved = path.resolve(pathname);
|
|
39
|
+
if (pathname[pathname.length - 1] === '/') {
|
|
40
|
+
resolved += '/';
|
|
41
|
+
} else if (isWindows && pathname[pathname.length - 1] === '\\') {
|
|
42
|
+
resolved += '\\';
|
|
43
|
+
}
|
|
44
|
+
resolved = replaceAll(resolved, '%', '%25'); // Must be first
|
|
45
|
+
resolved = replaceAll(resolved, '#', '%23');
|
|
46
|
+
resolved = replaceAll(resolved, '?', '%3f');
|
|
47
|
+
resolved = replaceAll(resolved, '\n', '%0a');
|
|
48
|
+
resolved = replaceAll(resolved, '\r', '%0d');
|
|
49
|
+
resolved = replaceAll(resolved, '\t', '%09');
|
|
50
|
+
if (!isWindows) {
|
|
51
|
+
resolved = replaceAll(resolved, '\\', '%5c');
|
|
52
|
+
}
|
|
53
|
+
return new URL(`file:${resolved}`);
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/url-file-url.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 path from 'path';\nimport replaceAll from 'core-js-pure/actual/string/replace-all.js';\nimport URL from 'core-js-pure/actual/url/index.js';\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nexport function fileURLToPath(url: string | URL): string {\n if (typeof url === 'string') {\n url = new URL(url);\n }\n\n if (url.protocol !== 'file:') {\n throw new Error('The URL must use the file: protocol');\n }\n\n if (isWindows) {\n if (/%2f|%5c/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded \\\\ or / characters');\n }\n } else {\n if (url.hostname) {\n throw new Error(\"The file: URL host must be 'localhost' or empty\");\n }\n\n if (/%2f/i.test(url.pathname)) {\n throw new Error('The file: URL path must not include encoded / characters');\n }\n }\n\n const pathname = path.normalize(decodeURIComponent(url.pathname));\n\n if (isWindows) {\n if (url.hostname) return `\\\\\\\\${url.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 = replaceAll(resolved, '%', '%25'); // Must be first\n resolved = replaceAll(resolved, '#', '%23');\n resolved = replaceAll(resolved, '?', '%3f');\n resolved = replaceAll(resolved, '\\n', '%0a');\n resolved = replaceAll(resolved, '\\r', '%0d');\n resolved = replaceAll(resolved, '\\t', '%09');\n\n if (!isWindows) {\n resolved = replaceAll(resolved, '\\\\', '%5c');\n }\n\n return new URL(`file:${resolved}`);\n}\n"],"names":["path","replaceAll","URL","isWindows","process","platform","test","env","OSTYPE","fileURLToPath","url","protocol","Error","pathname","hostname","normalize","decodeURIComponent","letter","charCodeAt","slice","pathToFileURL","resolved","resolve","length"],"mappings":"AAAA,qGAAqG;AACrG,iFAAiF;AAEjF,OAAOA,UAAU,OAAO;AACxB,OAAOC,gBAAgB,4CAA4C;AACnE,OAAOC,SAAS,mCAAmC;AACnD,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,OAAO,SAASC,cAAcC,GAAiB;IAC7C,IAAI,OAAOA,QAAQ,UAAU;QAC3BA,MAAM,IAAIR,IAAIQ;IAChB;IAEA,IAAIA,IAAIC,QAAQ,KAAK,SAAS;QAC5B,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,WAAW;QACb,IAAI,WAAWG,IAAI,CAACI,IAAIG,QAAQ,GAAG;YACjC,MAAM,IAAID,MAAM;QAClB;IACF,OAAO;QACL,IAAIF,IAAII,QAAQ,EAAE;YAChB,MAAM,IAAIF,MAAM;QAClB;QAEA,IAAI,OAAON,IAAI,CAACI,IAAIG,QAAQ,GAAG;YAC7B,MAAM,IAAID,MAAM;QAClB;IACF;IAEA,MAAMC,WAAWb,KAAKe,SAAS,CAACC,mBAAmBN,IAAIG,QAAQ;IAE/D,IAAIV,WAAW;QACb,IAAIO,IAAII,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAEJ,IAAII,QAAQ,GAAGD,UAAU;QAEzD,MAAMI,SAASJ,SAASK,UAAU,CAAC,KAAK;QAExC,IAAID,SAAS,KAAK,KAAK,OAAMA,SAAS,KAAK,KAAK,OAAMJ,SAASK,UAAU,CAAC,OAAO,KAAK,KAAK,KAAI;YAC7F,MAAM,IAAIN,MAAM;QAClB;QAEA,OAAOC,SAASM,KAAK,CAAC;IACxB;IAEA,OAAON;AACT;AAEA,OAAO,SAASO,cAAcP,QAAgB;IAC5C,IAAIQ,WAAWrB,KAAKsB,OAAO,CAACT;IAE5B,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,WAAWpB,WAAWoB,UAAU,KAAK,QAAQ,gBAAgB;IAC7DA,WAAWpB,WAAWoB,UAAU,KAAK;IACrCA,WAAWpB,WAAWoB,UAAU,KAAK;IACrCA,WAAWpB,WAAWoB,UAAU,MAAM;IACtCA,WAAWpB,WAAWoB,UAAU,MAAM;IACtCA,WAAWpB,WAAWoB,UAAU,MAAM;IAEtC,IAAI,CAAClB,WAAW;QACdkB,WAAWpB,WAAWoB,UAAU,MAAM;IACxC;IAEA,OAAO,IAAInB,IAAI,CAAC,KAAK,EAAEmB,UAAU;AACnC"}
|
package/dist/esm/toPath.mjs
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import module from 'module';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import url from 'url';
|
|
3
4
|
import isAbsolute from 'is-absolute';
|
|
4
|
-
import
|
|
5
|
+
import resolveCJS from 'resolve';
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';
|
|
5
8
|
import { moduleRegEx } from './constants.mjs';
|
|
6
|
-
import
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return true;
|
|
11
|
-
} catch (_) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
9
|
+
import * as urlPolyfills from './lib/url-file-url.mjs';
|
|
10
|
+
const useCJS = !module.createRequire;
|
|
11
|
+
const fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;
|
|
12
|
+
const pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;
|
|
15
13
|
function getParentPath(context) {
|
|
16
14
|
if (context.parentPath) return path.dirname(context.parentPath);
|
|
17
15
|
return context.parentURL ? path.dirname(toPath(context.parentURL)) : process.cwd();
|
|
@@ -25,30 +23,23 @@ export default function toPath(specifier, context) {
|
|
|
25
23
|
}
|
|
26
24
|
if (moduleRegEx.test(specifier)) {
|
|
27
25
|
const parentPath = context ? getParentPath(context) : process.cwd();
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (!useCJS) {
|
|
27
|
+
try {
|
|
28
|
+
const entryURL = resolveESM(specifier, pathToFileURL(parentPath));
|
|
29
|
+
if (entryURL) return fileURLToPath(entryURL);
|
|
30
|
+
} catch (_) {
|
|
31
|
+
/* it may fail due to commonjs edge cases */ }
|
|
32
|
+
}
|
|
33
|
+
const entryPath = resolveCJS.sync(specifier, {
|
|
30
34
|
basedir: parentPath,
|
|
31
35
|
extensions: [
|
|
32
36
|
'.js',
|
|
33
37
|
'.json',
|
|
34
38
|
'.node',
|
|
35
39
|
'.mjs'
|
|
36
|
-
]
|
|
37
|
-
packageFilter (json, dir) {
|
|
38
|
-
pkg = {
|
|
39
|
-
json,
|
|
40
|
-
dir
|
|
41
|
-
};
|
|
42
|
-
return json;
|
|
43
|
-
}
|
|
40
|
+
]
|
|
44
41
|
});
|
|
45
|
-
if (
|
|
46
|
-
if (pkg.json.name === specifier) return path.join(pkg.dir, pkg.json.module); // the module
|
|
47
|
-
// a relative path. Only accept if it doesn't break the relative naming and it exists
|
|
48
|
-
const modulePath = path.join(pkg.dir, pkg.json.module);
|
|
49
|
-
const mainPath = path.join(pkg.dir, pkg.json.main);
|
|
50
|
-
const moduleResolved = path.join(modulePath, path.relative(mainPath, main));
|
|
51
|
-
return moduleResolved.indexOf(specifier.replace(pkg.json.name, '')) < 0 || !existsSync(moduleResolved) ? main : moduleResolved;
|
|
42
|
+
if (entryPath) return entryPath;
|
|
52
43
|
}
|
|
53
44
|
return specifier;
|
|
54
45
|
}
|
package/dist/esm/toPath.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/toPath.ts"],"sourcesContent":["import module from 'module';\nimport path from 'path';\nimport url from 'url';\nimport isAbsolute from 'is-absolute';\nimport resolveCJS from 'resolve';\n// @ts-ignore\nimport { resolve as resolveESM } from '../../assets/import-meta-resolve.cjs';\nimport { moduleRegEx } from './constants';\nimport * as urlPolyfills from './lib/url-file-url';\nimport type { Context } from './types';\n\nconst useCJS = !module.createRequire;\nconst fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;\nconst pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;\n\nfunction getParentPath(context: Context) {\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) {\n if (specifier.startsWith('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 = resolveESM(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 = resolveCJS.sync(specifier, {\n basedir: parentPath,\n extensions: ['.js', '.json', '.node', '.mjs'],\n });\n if (entryPath) return entryPath;\n }\n\n return specifier;\n}\n"],"names":["module","path","url","isAbsolute","resolveCJS","resolve","resolveESM","moduleRegEx","urlPolyfills","useCJS","createRequire","fileURLToPath","pathToFileURL","getParentPath","context","parentPath","dirname","parentURL","toPath","process","cwd","specifier","startsWith","join","test","entryURL","_","entryPath","sync","basedir","extensions"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,gBAAgB,cAAc;AACrC,OAAOC,gBAAgB,UAAU;AACjC,aAAa;AACb,SAASC,WAAWC,UAAU,QAAQ,uCAAuC;AAC7E,SAASC,WAAW,QAAQ,cAAc;AAC1C,YAAYC,kBAAkB,qBAAqB;AAGnD,MAAMC,SAAS,CAACT,OAAOU,aAAa;AACpC,MAAMC,gBAAgBT,IAAIS,aAAa,IAAIH,aAAaG,aAAa;AACrE,MAAMC,gBAAgBV,IAAIU,aAAa,IAAIJ,aAAaI,aAAa;AAErE,SAASC,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOd,KAAKe,OAAO,CAACF,QAAQC,UAAU;IAC9D,OAAOD,QAAQG,SAAS,GAAGhB,KAAKe,OAAO,CAACE,OAAOJ,QAAQG,SAAS,KAAKE,QAAQC,GAAG;AAClF;AAEA,eAAe,SAASF,OAAOG,SAAiB,EAAEP,OAAiB;IACjE,IAAIO,UAAUC,UAAU,CAAC,UAAU,OAAOX,cAAcU;IACxD,IAAIlB,WAAWkB,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOnB,KAAKsB,IAAI,CAACR,YAAYM;IAC/B;IACA,IAAId,YAAYiB,IAAI,CAACH,YAAY;QAC/B,MAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAACX,QAAQ;YACX,IAAI;gBACF,MAAMgB,WAAWnB,WAAWe,WAAWT,cAAcG;gBACrD,IAAIU,UAAU,OAAOd,cAAcc;YACrC,EAAE,OAAOC,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,MAAMC,YAAYvB,WAAWwB,IAAI,CAACP,WAAW;YAC3CQ,SAASd;YACTe,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIH,WAAW,OAAOA;IACxB;IAEA,OAAON;AACT"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
+
export declare const interop = "/* 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
2
|
export default function patchCJS(entry: any, output: any, options: any): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.1",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -22,19 +22,17 @@
|
|
|
22
22
|
"author": "Kevin Malakoff <kmalakoff@gmail.com> (https://github.com/kmalakoff)",
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"types": "./dist/types/index.d.ts"
|
|
29
|
-
},
|
|
30
|
-
"./*": "./*"
|
|
25
|
+
"import": "./dist/esm/index.mjs",
|
|
26
|
+
"require": "./dist/cjs/index.cjs",
|
|
27
|
+
"types": "./dist/types/index.d.ts"
|
|
31
28
|
},
|
|
32
29
|
"main": "dist/cjs/index.cjs",
|
|
33
30
|
"module": "dist/dist/esm/index.mjs",
|
|
34
31
|
"types": "dist/types/index.d.ts",
|
|
35
32
|
"files": [
|
|
36
33
|
"dist",
|
|
37
|
-
"scripts"
|
|
34
|
+
"scripts",
|
|
35
|
+
"assets"
|
|
38
36
|
],
|
|
39
37
|
"scripts": {
|
|
40
38
|
"build": "tsds build",
|
|
@@ -45,6 +43,7 @@
|
|
|
45
43
|
},
|
|
46
44
|
"dependencies": {
|
|
47
45
|
"@swc/core": "*",
|
|
46
|
+
"core-js-pure": "^3.40.0",
|
|
48
47
|
"exit": "^0.1.2",
|
|
49
48
|
"fs-iterator": "^5.2.10",
|
|
50
49
|
"get-tsconfig-compat": "^2.0.3",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return _default;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
12
|
-
function _interop_require_default(obj) {
|
|
13
|
-
return obj && obj.__esModule ? obj : {
|
|
14
|
-
default: obj
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function fileURLToPathPolyfill(fileURL) {
|
|
18
|
-
var path = typeof fileURL === 'string' ? fileURL : fileURL.pathname;
|
|
19
|
-
if (!path.startsWith('file:')) throw new Error('The URL must use the file: protocol');
|
|
20
|
-
return decodeURIComponent(path.substring(7));
|
|
21
|
-
}
|
|
22
|
-
var _default = _url.default.fileURLToPath || fileURLToPathPolyfill;
|
|
23
|
-
/* 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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/fileURLToPath.ts"],"sourcesContent":["import url from 'url';\n\nfunction fileURLToPathPolyfill(fileURL) {\n const path = typeof fileURL === 'string' ? fileURL : fileURL.pathname;\n if (!path.startsWith('file:')) throw new Error('The URL must use the file: protocol');\n return decodeURIComponent(path.substring(7));\n}\n\nexport default url.fileURLToPath || fileURLToPathPolyfill;\n"],"names":["fileURLToPathPolyfill","fileURL","path","pathname","startsWith","Error","decodeURIComponent","substring","url","fileURLToPath"],"mappings":";;;;+BAQA;;;eAAA;;;0DARgB;;;;;;AAEhB,SAASA,sBAAsBC,OAAO;IACpC,IAAMC,OAAO,OAAOD,YAAY,WAAWA,UAAUA,QAAQE,QAAQ;IACrE,IAAI,CAACD,KAAKE,UAAU,CAAC,UAAU,MAAM,IAAIC,MAAM;IAC/C,OAAOC,mBAAmBJ,KAAKK,SAAS,CAAC;AAC3C;IAEA,WAAeC,YAAG,CAACC,aAAa,IAAIT"}
|