ts-swc-transform 2.6.9 → 2.6.11
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/lib/transformFile.js +1 -1
- package/dist/cjs/lib/transformFile.js.map +1 -1
- package/dist/cjs/toPath.js +3 -1
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/esm/lib/transformFile.js +1 -1
- package/dist/esm/lib/transformFile.js.map +1 -1
- package/dist/esm/toPath.js +4 -2
- package/dist/esm/toPath.js.map +1 -1
- package/package.json +1 -1
|
@@ -96,7 +96,7 @@ function transformFile(entry, dest, type, options, callback) {
|
|
|
96
96
|
(0, _mkdirpclassic.default)(_path.default.dirname(outPath), function() {
|
|
97
97
|
var queue = new _queuecb.default();
|
|
98
98
|
queue.defer(_fs.default.writeFile.bind(null, outPath, output.code, 'utf8'));
|
|
99
|
-
|
|
99
|
+
if (output.map && options.sourceMaps) queue.defer(_fs.default.writeFile.bind(null, "".concat(outPath, ".map"), output.map, 'utf8'));
|
|
100
100
|
queue.await(function(err) {
|
|
101
101
|
return err ? callback(err) : callback(null, outPath);
|
|
102
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n if(output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","prepareSWCOptions","swc","ext","path","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","map","sourceMaps","await","err","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAdT;oEAEI;6DACA;2DACF;8DACC;iEACG;iEACA;0EACS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAI3E,SAASF,cAAcK,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW,mBAAKA;QAChBA,SAASC,MAA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GAAG,EAAE;YACvGP,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMtC,SAASsC,OAAOtC,SAAS,MAAMsB;;QAC7D;IACF,GACCiB,KAAK,CAACvC;AACX"}
|
package/dist/cjs/toPath.js
CHANGED
|
@@ -62,6 +62,8 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
62
62
|
}
|
|
63
63
|
return newObj;
|
|
64
64
|
}
|
|
65
|
+
var _resolve_default;
|
|
66
|
+
var resolveSync = ((_resolve_default = _resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : _resolve).sync;
|
|
65
67
|
var useCJS = !_module.default.createRequire;
|
|
66
68
|
var fileURLToPath = _url.default.fileURLToPath || _urlFileUrlts.fileURLToPath;
|
|
67
69
|
var pathToFileURL = _url.default.pathToFileURL || _urlFileUrlts.pathToFileURL;
|
|
@@ -88,7 +90,7 @@ function toPath(specifier, context) {
|
|
|
88
90
|
} catch (_) {
|
|
89
91
|
/* it may fail due to commonjs edge cases */ }
|
|
90
92
|
}
|
|
91
|
-
var entryPath =
|
|
93
|
+
var entryPath = resolveSync(specifier, {
|
|
92
94
|
basedir: parentPath1,
|
|
93
95
|
extensions: [
|
|
94
96
|
'.js',
|
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
|
|
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';\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;\nconst startsWith = (string, check) => string.lastIndexOf(check, 0) === 0;\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 (startsWith(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","startsWith","string","check","lastIndexOf","getParentPath","context","parentPath","path","dirname","parentURL","process","cwd","specifier","isAbsolute","join","moduleRegEx","test","entryURL","importMetaResolve","_","entryPath","basedir","extensions"],"mappings":";;;;+BAsBA;;;eAAwBA;;;iEAtBD;6DACJ;2DACF;+DACQ;0DACT;2BACY;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;AACrE,IAAMC,aAAa,SAACC,QAAQC;WAAUD,OAAOE,WAAW,CAACD,OAAO,OAAO;;AAEvE,SAASE,cAAcC,OAAgB;IACrC,IAAIA,QAAQC,UAAU,EAAE,OAAOC,aAAI,CAACC,OAAO,CAACH,QAAQC,UAAU;IAC9D,OAAOD,QAAQI,SAAS,GAAGF,aAAI,CAACC,OAAO,CAACpB,OAAOiB,QAAQI,SAAS,KAAKC,QAAQC,GAAG;AAClF;AAEe,SAASvB,OAAOwB,SAAiB,EAAEP,OAAiB;IACjE,IAAIL,WAAWY,WAAW,UAAU,OAAOhB,cAAcgB;IACzD,IAAIC,IAAAA,mBAAU,EAACD,YAAY,OAAOA;IAClC,IAAIA,SAAS,CAAC,EAAE,KAAK,KAAK;QACxB,IAAMN,aAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,OAAOJ,aAAI,CAACO,IAAI,CAACR,YAAYM;IAC/B;IACA,IAAIG,wBAAW,CAACC,IAAI,CAACJ,YAAY;QAC/B,IAAMN,cAAaD,UAAUD,cAAcC,WAAWK,QAAQC,GAAG;QACjE,IAAI,CAAClB,QAAQ;YACX,IAAI;gBACF,IAAMwB,WAAWC,IAAAA,4BAAiB,EAACN,WAAWb,cAAcO;gBAC5D,IAAIW,UAAU,OAAOrB,cAAcqB;YACrC,EAAE,OAAOE,GAAG;YACV,0CAA0C,GAC5C;QACF;QACA,IAAMC,YAAY9B,YAAYsB,WAAW;YACvCS,SAASf;YACTgB,YAAY;gBAAC;gBAAO;gBAAS;gBAAS;aAAO;QAC/C;QACA,IAAIF,WAAW,OAAOA;IACxB;IAEA,OAAOR;AACT"}
|
|
@@ -36,7 +36,7 @@ export default function transformFile(entry, dest, type, options, callback) {
|
|
|
36
36
|
mkdirp(path.dirname(outPath), ()=>{
|
|
37
37
|
const queue = new Queue();
|
|
38
38
|
queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
|
|
39
|
-
|
|
39
|
+
if (output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));
|
|
40
40
|
queue.await((err)=>err ? callback(err) : callback(null, outPath));
|
|
41
41
|
});
|
|
42
42
|
}).catch(callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import type { Output } from '@swc/core';\nimport fs from 'fs';\nimport type { Entry } from 'fs-iterator';\nimport mkdirp from 'mkdirp-classic';\nimport Module from 'module';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport patchCJS from '../lib/patchCJS.ts';\nimport patchESM from '../lib/patchESM.ts';\nimport prepareSWCOptions from '../lib/prepareSWCOptions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { ConfigOptions, TargetType, TransformFileCallback } from '../types.ts';\n\nexport default function transformFile(entry: Entry, dest: string, type: TargetType, options: ConfigOptions, callback: TransformFileCallback): undefined {\n let tsconfig = options.tsconfig;\n\n // overrides for cjs\n if (type === 'cjs') {\n tsconfig = { ...tsconfig };\n tsconfig.config = { ...tsconfig.config };\n tsconfig.config.compilerOptions = { ...(tsconfig.config.compilerOptions || {}) };\n tsconfig.config.compilerOptions.module = 'commonjs';\n tsconfig.config.compilerOptions.target = 'es5';\n }\n\n const swcOptions = prepareSWCOptions(tsconfig);\n const swc = _require('@swc/core');\n const ext = path.extname(entry.basename);\n\n swc\n .transformFile(entry.fullPath, {\n ...(ext === '.tsx' || ext === '.jsx' ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((output: Output) => {\n const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);\n const ext = path.extname(entry.path);\n const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);\n\n mkdirp(path.dirname(outPath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));\n if(output.map && options.sourceMaps) queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));\n queue.await((err) => (err ? callback(err) : callback(null, outPath)));\n });\n })\n .catch(callback);\n}\n"],"names":["fs","mkdirp","Module","path","Queue","patchCJS","patchESM","prepareSWCOptions","_require","require","createRequire","url","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","ext","extname","basename","fullPath","tsxOptions","nonTsxOptions","filename","then","output","extTarget","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","map","sourceMaps","await","err","catch"],"mappings":"AACA,OAAOA,QAAQ,KAAK;AAEpB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,cAAc,qBAAqB;AAC1C,OAAOC,uBAAuB,8BAA8B;AAE5D,MAAMC,WAAW,OAAOC,YAAY,cAAcP,OAAOQ,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAI1F,eAAe,SAASG,cAAcC,KAAY,EAAEC,IAAY,EAAEC,IAAgB,EAAEC,OAAsB,EAAEC,QAA+B;IACzI,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW;YAAE,GAAGA,QAAQ;QAAC;QACzBA,SAASC,MAAM,GAAG;YAAE,GAAGD,SAASC,MAAM;QAAC;QACvCD,SAASC,MAAM,CAACC,eAAe,GAAG;YAAE,GAAIF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAC;QAAE;QAC/EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,MAAMC,aAAahB,kBAAkBW;IACrC,MAAMM,MAAMhB,SAAS;IACrB,MAAMiB,MAAMtB,KAAKuB,OAAO,CAACb,MAAMc,QAAQ;IAEvCH,IACGZ,aAAa,CAACC,MAAMe,QAAQ,EAAE;QAC7B,GAAIH,QAAQ,UAAUA,QAAQ,SAASF,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QACvFC,UAAUlB,MAAMc,QAAQ;IAC1B,GACCK,IAAI,CAAC,CAACC;QACL,MAAMC,YAAYnB,SAAS,QAAQT,SAASO,OAAOoB,QAAQjB,WAAWX,SAASQ,OAAOoB,QAAQjB;QAC9F,MAAMS,MAAMtB,KAAKuB,OAAO,CAACb,MAAMV,IAAI;QACnC,MAAMgC,UAAUhC,KAAKiC,IAAI,CAACtB,MAAM,AAACW,CAAAA,MAAMZ,MAAMV,IAAI,CAACkC,KAAK,CAAC,GAAG,CAACZ,IAAIa,MAAM,IAAIzB,MAAMV,IAAI,AAAD,IAAK+B;QAExFjC,OAAOE,KAAKoC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAIpC;YAClBoC,MAAMC,KAAK,CAACzC,GAAG0C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASF,OAAOW,IAAI,EAAE;YAC1D,IAAGX,OAAOY,GAAG,IAAI7B,QAAQ8B,UAAU,EAAEN,MAAMC,KAAK,CAACzC,GAAG0C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEF,OAAOY,GAAG,EAAE;YACvGL,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAM/B,SAAS+B,OAAO/B,SAAS,MAAMkB;QAC7D;IACF,GACCc,KAAK,CAAChC;AACX"}
|
package/dist/esm/toPath.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import isAbsolute from 'is-absolute';
|
|
2
2
|
import module from 'module';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import * as
|
|
4
|
+
import * as resolve from 'resolve';
|
|
5
5
|
import url from 'url';
|
|
6
6
|
import { moduleRegEx } from './constants.js';
|
|
7
7
|
import importMetaResolve from './lib/import-meta-resolve.js';
|
|
8
8
|
import * as urlPolyfills from './lib/urlFileUrl.js';
|
|
9
|
+
var _resolve_default;
|
|
10
|
+
const resolveSync = ((_resolve_default = resolve.default) !== null && _resolve_default !== void 0 ? _resolve_default : resolve).sync;
|
|
9
11
|
const useCJS = !module.createRequire;
|
|
10
12
|
const fileURLToPath = url.fileURLToPath || urlPolyfills.fileURLToPath;
|
|
11
13
|
const pathToFileURL = url.pathToFileURL || urlPolyfills.pathToFileURL;
|
|
@@ -30,7 +32,7 @@ export default function toPath(specifier, context) {
|
|
|
30
32
|
} catch (_) {
|
|
31
33
|
/* it may fail due to commonjs edge cases */ }
|
|
32
34
|
}
|
|
33
|
-
const entryPath =
|
|
35
|
+
const entryPath = resolveSync(specifier, {
|
|
34
36
|
basedir: parentPath,
|
|
35
37
|
extensions: [
|
|
36
38
|
'.js',
|
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
|
|
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';\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;\nconst startsWith = (string, check) => string.lastIndexOf(check, 0) === 0;\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 (startsWith(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","moduleRegEx","importMetaResolve","urlPolyfills","resolveSync","default","sync","useCJS","createRequire","fileURLToPath","pathToFileURL","startsWith","string","check","lastIndexOf","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,OAAO;AACxB,YAAYC,aAAa,UAAU;AACnC,OAAOC,SAAS,MAAM;AACtB,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,uBAAuB,+BAA+B;AAC7D,YAAYC,kBAAkB,sBAAsB;IAG/BJ;AAArB,MAAMK,cAAc,AAACL,CAAAA,CAAAA,mBAAAA,QAAQM,OAAO,cAAfN,8BAAAA,mBAAmBA,OAAM,EAAGO,IAAI;AAErD,MAAMC,SAAS,CAACV,OAAOW,aAAa;AACpC,MAAMC,gBAAgBT,IAAIS,aAAa,IAAIN,aAAaM,aAAa;AACrE,MAAMC,gBAAgBV,IAAIU,aAAa,IAAIP,aAAaO,aAAa;AACrE,MAAMC,aAAa,CAACC,QAAQC,QAAUD,OAAOE,WAAW,CAACD,O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