ts-swc-transform 1.0.2 → 1.1.0
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/createMatcher.js +4 -4
- package/dist/cjs/createMatcher.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lazy.js +3 -0
- package/dist/cjs/lazy.js.map +1 -0
- package/dist/cjs/process.js +3 -0
- package/dist/cjs/process.js.map +1 -0
- package/dist/cjs/transformDirectory.js +4 -4
- package/dist/cjs/transformDirectory.js.map +1 -1
- package/dist/cjs/transformFile.js +6 -5
- package/dist/cjs/transformFile.js.map +1 -1
- package/dist/cjs/transformSync.js +27 -10
- package/dist/cjs/transformSync.js.map +1 -1
- package/dist/cjs/workers/transformSync.js.map +1 -1
- package/dist/esm/createMatcher.mjs +4 -4
- package/dist/esm/createMatcher.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lazy.cjs +1 -0
- package/dist/esm/lazy.cjs.map +1 -0
- package/dist/esm/process.cjs +1 -0
- package/dist/esm/process.cjs.map +1 -0
- package/dist/esm/transformDirectory.mjs +2 -0
- package/dist/esm/transformDirectory.mjs.map +1 -1
- package/dist/esm/transformFile.mjs +6 -4
- package/dist/esm/transformFile.mjs.map +1 -1
- package/dist/esm/transformSync.mjs +18 -0
- package/dist/esm/transformSync.mjs.map +1 -0
- package/dist/esm/workers/transformSync.cjs.map +1 -1
- package/dist/types/{createMatcher.d.mts → createMatcher.d.ts} +1 -4
- package/dist/types/index.d.ts +4 -0
- package/dist/types/lazy.d.cts +1 -0
- package/dist/types/process.d.cts +1 -0
- package/dist/types/{transformDirectory.d.mts → transformDirectory.d.ts} +1 -3
- package/dist/types/{transformFile.d.mts → transformFile.d.ts} +1 -3
- package/dist/types/transformSync.d.ts +6 -0
- package/dist/types/workers/transformSync.d.cts +1 -5
- package/package.json +10 -9
- package/dist/cjs/lib/regexDependencies.js +0 -21
- package/dist/cjs/lib/regexDependencies.js.map +0 -1
- package/dist/esm/lib/regexDependencies.mjs +0 -10
- package/dist/esm/lib/regexDependencies.mjs.map +0 -1
- package/dist/esm/transformSync.cjs +0 -13
- package/dist/esm/transformSync.cjs.map +0 -1
- package/dist/types/index.d.mts +0 -4
- package/dist/types/lib/regexDependencies.d.mts +0 -1
- package/dist/types/transformSync.d.cts +0 -5
|
@@ -13,16 +13,16 @@ Object.defineProperty(exports, /**
|
|
|
13
13
|
});
|
|
14
14
|
var _minimatch = /*#__PURE__*/ _interop_require_default(require("minimatch"));
|
|
15
15
|
var _pathposix = /*#__PURE__*/ _interop_require_default(require("path-posix"));
|
|
16
|
-
var
|
|
16
|
+
var _unixify = /*#__PURE__*/ _interop_require_default(require("unixify"));
|
|
17
17
|
function _interop_require_default(obj) {
|
|
18
18
|
return obj && obj.__esModule ? obj : {
|
|
19
19
|
default: obj
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
function createMatcher(config) {
|
|
23
|
-
var configPath = _pathposix.default.dirname((0,
|
|
23
|
+
var configPath = _pathposix.default.dirname((0, _unixify.default)(config.path));
|
|
24
24
|
function matchFn(condition) {
|
|
25
|
-
var pattern = (0,
|
|
25
|
+
var pattern = (0, _unixify.default)(condition);
|
|
26
26
|
if (!_pathposix.default.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = _pathposix.default.join(configPath, pattern);
|
|
27
27
|
return function match(filePath) {
|
|
28
28
|
return filePath.startsWith(pattern) || (0, _minimatch.default)(filePath, pattern);
|
|
@@ -32,7 +32,7 @@ function createMatcher(config) {
|
|
|
32
32
|
var excludes = (config.config.exclude || []).map(matchFn);
|
|
33
33
|
return function matcher(filePath) {
|
|
34
34
|
if (filePath.endsWith('.json')) return false;
|
|
35
|
-
filePath = (0,
|
|
35
|
+
filePath = (0, _unixify.default)(filePath);
|
|
36
36
|
for(var i = 0; i < excludes.length; ++i){
|
|
37
37
|
if (excludes[i](filePath)) return false;
|
|
38
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["createMatcher.
|
|
1
|
+
{"version":3,"sources":["createMatcher.ts"],"sourcesContent":["import minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\n\n/**\n * @param {{path: string, config: Object}} config The path to the loaded TS config and typescript config.\n * @returns {(filePath:string) => boolean} The function to test for typescript files being included or excluded\n */\nexport default function createMatcher(config) {\n const configPath = path.dirname(unixify(config.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(configPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (config.config.include || []).map(matchFn);\n const excludes = (config.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","config","configPath","path","dirname","unixify","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","minimatch","includes","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":";;;;+BAIA;;;CAGC,GACD;;;eAAwBA;;;gEARF;gEACL;8DACG;;;;;;AAML,SAASA,cAAcC,MAAM;IAC1C,IAAMC,aAAaC,kBAAI,CAACC,OAAO,CAACC,IAAAA,gBAAO,EAACJ,OAAOE,IAAI;IAEnD,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,YAAYM;QAE3F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYM,IAAAA,kBAAS,EAACD,UAAUL;QAC7D;IACF;IAEA,IAAMO,WAAW,AAACd,CAAAA,OAAOA,MAAM,CAACe,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACX;IACnD,IAAMY,WAAW,AAACjB,CAAAA,OAAOA,MAAM,CAACkB,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACX;IAEnD,OAAO,SAASc,QAAQP,QAAQ;QAC9B,IAAIA,SAASQ,QAAQ,CAAC,UAAU,OAAO;QAEvCR,WAAWR,IAAAA,gBAAO,EAACQ;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,IAAIT,SAASQ,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIT,QAAQ,CAACS,EAAE,CAACX,WAAW,OAAO;QACpC;QACA,OAAO,CAACE,SAASQ,MAAM;IACzB;AACF"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,13 +19,13 @@ _export(exports, {
|
|
|
19
19
|
return _transformFile.default;
|
|
20
20
|
},
|
|
21
21
|
transformSync: function() {
|
|
22
|
-
return
|
|
22
|
+
return _transformSync.default;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
var _createMatcher = /*#__PURE__*/ _interop_require_default(require("./createMatcher.js"));
|
|
26
26
|
var _transformFile = /*#__PURE__*/ _interop_require_default(require("./transformFile.js"));
|
|
27
27
|
var _transformDirectory = /*#__PURE__*/ _interop_require_default(require("./transformDirectory.js"));
|
|
28
|
-
var
|
|
28
|
+
var _transformSync = /*#__PURE__*/ _interop_require_default(require("./transformSync.js"));
|
|
29
29
|
function _interop_require_default(obj) {
|
|
30
30
|
return obj && obj.__esModule ? obj : {
|
|
31
31
|
default: obj
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export { default as createMatcher } from './createMatcher.js';\nexport { default as transformFile } from './transformFile.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\n"],"names":["createMatcher","transformDirectory","transformFile","transformSync"],"mappings":";;;;;;;;;;;IAAoBA,aAAa;eAAbA,sBAAa;;IAEbC,kBAAkB;eAAlBA,2BAAkB;;IADlBC,aAAa;eAAbA,sBAAa;;IAEbC,aAAa;eAAbA,sBAAa;;;oEAHQ;oEACA;yEACK;oEACL"}
|
package/dist/cjs/lazy.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = require('lazy-cache')(require);
|
|
3
|
+
/* 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":["lazy.cts"],"sourcesContent":["module.exports = require('lazy-cache')(require);\n"],"names":["module","exports","require"],"mappings":";AAAAA,OAAOC,OAAO,GAAGC,QAAQ,cAAcA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = process;
|
|
3
|
+
/* 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":["process.cts"],"sourcesContent":["module.exports = process;\n"],"names":["module","exports","process"],"mappings":";AAAAA,OAAOC,OAAO,GAAGC"}
|
|
@@ -18,8 +18,8 @@ Object.defineProperty(exports, /**
|
|
|
18
18
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
19
19
|
var _fsiterator = /*#__PURE__*/ _interop_require_default(require("fs-iterator"));
|
|
20
20
|
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_default(require("get-tsconfig-compat"));
|
|
21
|
-
var
|
|
22
|
-
var
|
|
21
|
+
var _createMatcherts = /*#__PURE__*/ _interop_require_default(require("./createMatcher.js"));
|
|
22
|
+
var _transformFilets = /*#__PURE__*/ _interop_require_default(require("./transformFile.js"));
|
|
23
23
|
function _define_property(obj, key, value) {
|
|
24
24
|
if (key in obj) {
|
|
25
25
|
Object.defineProperty(obj, key, {
|
|
@@ -87,7 +87,7 @@ function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
|
87
87
|
if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');
|
|
88
88
|
if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');
|
|
89
89
|
var config = options.confg ? options.confg : _gettsconfigcompat.default.getTsconfig(src);
|
|
90
|
-
var matcher = (0,
|
|
90
|
+
var matcher = (0, _createMatcherts.default)(config);
|
|
91
91
|
options = _object_spread_props(_object_spread({}, options), {
|
|
92
92
|
config: config
|
|
93
93
|
});
|
|
@@ -95,7 +95,7 @@ function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
|
95
95
|
iterator.forEach(function(entry, cb) {
|
|
96
96
|
if (!entry.stats.isFile()) return cb();
|
|
97
97
|
if (!matcher(entry.fullPath)) return cb();
|
|
98
|
-
(0,
|
|
98
|
+
(0, _transformFilets.default)(entry.fullPath, _path.default.dirname(_path.default.join(dest, entry.path)), type, options, cb);
|
|
99
99
|
}, {
|
|
100
100
|
callbacks: true,
|
|
101
101
|
concurrency: options.concurrency || 1024
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\n// @ts-ignore\nimport createMatcher from './createMatcher.ts';\n// @ts-ignore\nimport transformFile from './transformFile.ts';\n\nfunction transformDirectoryCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n const config = options.confg ? options.confg : getTS.getTsconfig(src);\n const matcher = createMatcher(config);\n\n options = { ...options, config };\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry, cb) => {\n if (!entry.stats.isFile()) return cb();\n if (!matcher(entry.fullPath)) return cb();\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, cb);\n },\n { callbacks: true, concurrency: options.concurrency || 1024 },\n callback\n );\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformDirectory","transformDirectoryCallback","src","dest","type","options","callback","Error","config","confg","getTS","getTsconfig","matcher","createMatcher","iterator","Iterator","forEach","entry","cb","stats","isFile","fullPath","transformFile","path","dirname","join","callbacks","concurrency","Promise","resolve","reject","compileCallback","err","result"],"mappings":";;;;+BAoCA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DA5CP;iEACI;wEACH;sEAGQ;sEAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAAS0B,gBAAgBC,GAAG,EAAEC,MAAM;YACvFD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF"}
|
|
@@ -21,8 +21,7 @@ var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn")
|
|
|
21
21
|
var _gettsconfigcompat = /*#__PURE__*/ _interop_require_default(require("get-tsconfig-compat"));
|
|
22
22
|
var _mkdirp = /*#__PURE__*/ _interop_require_default(require("mkdirp"));
|
|
23
23
|
var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
|
|
24
|
-
var
|
|
25
|
-
var _transformSynccjs = /*#__PURE__*/ _interop_require_default(require("./transformSync.js"));
|
|
24
|
+
var _transformSyncts = /*#__PURE__*/ _interop_require_default(require("./transformSync.js"));
|
|
26
25
|
function _define_property(obj, key, value) {
|
|
27
26
|
if (key in obj) {
|
|
28
27
|
Object.defineProperty(obj, key, {
|
|
@@ -56,8 +55,10 @@ function _object_spread(target) {
|
|
|
56
55
|
}
|
|
57
56
|
return target;
|
|
58
57
|
}
|
|
59
|
-
var
|
|
60
|
-
var
|
|
58
|
+
var matchingDeps = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
59
|
+
var matchingName = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
60
|
+
var regexCJS = new RegExp("(?:(?:var|const|let)".concat(matchingName, "=\\s*)?require\\(").concat(matchingDeps, "\\);?"), 'g');
|
|
61
|
+
var regexESM = new RegExp("".concat(regexCJS, "|import(?:").concat(matchingName, "from\\s*)?").concat(matchingDeps, ";?|export(?:").concat(matchingName, "from\\s*)?").concat(matchingDeps, ";?"), 'g');
|
|
61
62
|
var importReplaceMJS = [
|
|
62
63
|
'.js',
|
|
63
64
|
'.ts',
|
|
@@ -125,7 +126,7 @@ function transformFileCallback(src, dest, type, options, callback) {
|
|
|
125
126
|
config.config.compilerOptions.target = 'ES5';
|
|
126
127
|
}
|
|
127
128
|
var basename = _path.default.basename(src);
|
|
128
|
-
var output = (0,
|
|
129
|
+
var output = (0, _transformSyncts.default)(contents, basename, config);
|
|
129
130
|
// infer extension and patch .mjs imports
|
|
130
131
|
var ext = _path.default.extname(basename);
|
|
131
132
|
if (type === 'esm') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.
|
|
1
|
+
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp';\nimport Queue from 'queue-cb';\n\n// @ts-ignore\nimport transformSync from './transformSync.ts';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst 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; }\";\n\nfunction transformFileCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let config = options.confg ? options.confg : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n config = { ...config };\n config.config = { ...(config.config || {}) };\n config.config.compilerOptions = { ...(config.config.compilerOptions || {}) };\n config.config.compilerOptions.module = 'CommonJS';\n config.config.compilerOptions.target = 'ES5';\n }\n\n const basename = path.basename(src);\n const output = transformSync(contents, basename, config);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write the file to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err: Error | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.\n * @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.\n */\nexport default function transformFile(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformFileCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["transformFile","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","dependency","match","ext","find","x","slice","length","matches","push","exec","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileCallback","src","dest","type","options","callback","Error","fs","readFile","err","contents","once","config","confg","getTS","getTsconfig","compilerOptions","module","target","basename","path","output","transformSync","extname","destFilePath","join","replace","mkdirp","dirname","queue","Queue","defer","writeFile","bind","sourceMaps","map","await","Promise","resolve","reject","compileCallback","result"],"mappings":";;;;+BAiGA;;;;;;;CAOC,GACD;;;eAAwBA;;;yDAzGT;2DACE;iEACA;wEACC;6DACC;8DACD;sEAGQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,IAAMC,eAAe;AACrB,IAAMC,eAAe;AACrB,IAAMC,WAAW,IAAIC,OAAO,AAAC,uBAAsDH,OAAhCC,cAAa,qBAAgC,OAAbD,cAAa,UAAQ;AACxG,IAAMI,WAAW,IAAID,OAAO,AAAC,GAAuBF,OAArBC,UAAS,cAAqCF,OAAzBC,cAAa,cAAuCA,OAA3BD,cAAa,gB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"}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var call = null; // break dependencies
|
|
7
|
-
/**
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, /**
|
|
8
6
|
* @param {string} contents The file contents.
|
|
9
7
|
* @param {string} fileName The filename.
|
|
10
8
|
* @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
*/ "default", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return transformSync;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
16
|
+
var _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
17
|
+
var _lazycts = /*#__PURE__*/ _interop_require_default(require("./lazy.js"));
|
|
18
|
+
var _processcts = /*#__PURE__*/ _interop_require_default(require("./process.js"));
|
|
19
|
+
function _interop_require_default(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
var major = +_processcts.default.versions.node.split('.')[0];
|
|
25
|
+
var version = major >= 14 ? 'local' : 'lts';
|
|
26
|
+
var filename = typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString());
|
|
27
|
+
var worker = _path.default.resolve(_path.default.dirname(filename), 'workers', "transformSync".concat(_path.default.extname(filename) === '.mjs' ? '.cjs' : '.js'));
|
|
28
|
+
var call = (0, _lazycts.default)('node-version-call');
|
|
29
|
+
function transformSync(contents, fileName, config) {
|
|
30
|
+
return call()(version, worker, contents, fileName, config);
|
|
31
|
+
}
|
|
15
32
|
/* 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":["transformSync.
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// @ts-ignore\nimport lazy from './lazy.cts';\n// @ts-ignore\nimport process from './process.cts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major >= 14 ? 'local' : 'lts';\nconst filename = typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url);\nconst worker = path.resolve(path.dirname(filename), 'workers', `transformSync${path.extname(filename) === '.mjs' ? '.cjs' : '.js'}`);\nconst call = lazy('node-version-call');\n\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\n * @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.\n */\nexport default function transformSync(contents, fileName, config) {\n return call()(version, worker, contents, fileName, config);\n}\n"],"names":["transformSync","major","process","versions","node","split","version","filename","__filename","url","fileURLToPath","worker","path","resolve","dirname","extname","call","lazy","contents","fileName","config"],"mappings":";;;;+BAaA;;;;CAIC,GACD;;;eAAwBA;;;2DAlBP;0DACD;8DAEC;iEAEG;;;;;;AAEpB,IAAMC,QAAQ,CAACC,mBAAO,CAACC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,SAAS,KAAK,UAAU;AACxC,IAAMM,WAAW,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AACpF,IAAMC,SAASC,aAAI,CAACC,OAAO,CAACD,aAAI,CAACE,OAAO,CAACP,WAAW,WAAW,AAAC,gBAAkE,OAAnDK,aAAI,CAACG,OAAO,CAACR,cAAc,SAAS,SAAS;AAC5H,IAAMS,OAAOC,IAAAA,gBAAI,EAAC;AAOH,SAASjB,cAAckB,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAC9D,OAAOJ,OAAOV,SAASK,QAAQO,UAAUC,UAAUC;AACrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.
|
|
1
|
+
{"version":3,"sources":["transformSync.cts"],"sourcesContent":["const path = require('path');\nconst swc = require('@swc/core');\nconst ts = require('typescript');\nconst swcTranspiler = require('ts-node/transpilers/swc');\n\nmodule.exports = function transformSync(contents, fileName, config) {\n const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(config.path));\n const transpile = swcTranspiler.create({ swc: swc, service: { config: { options: parsed.options } } });\n const res = transpile.transpile(contents, { fileName: fileName });\n return { code: res.outputText, map: res.sourceMapText };\n};\n"],"names":["path","require","swc","ts","swcTranspiler","module","exports","transformSync","contents","fileName","config","parsed","parseJsonConfigFileContent","sys","dirname","transpile","create","service","options","res","code","outputText","map","sourceMapText"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,MAAMD,QAAQ;AACpB,IAAME,KAAKF,QAAQ;AACnB,IAAMG,gBAAgBH,QAAQ;AAE9BI,OAAOC,OAAO,GAAG,SAASC,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAChE,IAAMC,SAASR,GAAGS,0BAA0B,CAACF,OAAOA,MAAM,EAAEP,GAAGU,GAAG,EAAEb,KAAKc,OAAO,CAACJ,OAAOV,IAAI;IAC5F,IAAMe,YAAYX,cAAcY,MAAM,CAAC;QAAEd,KAAKA;QAAKe,SAAS;YAAEP,QAAQ;gBAAEQ,SAASP,OAAOO,OAAO;YAAC;QAAE;IAAE;IACpG,IAAMC,MAAMJ,UAAUA,SAAS,CAACP,UAAU;QAAEC,UAAUA;IAAS;IAC/D,OAAO;QAAEW,MAAMD,IAAIE,UAAU;QAAEC,KAAKH,IAAII,aAAa;IAAC;AACxD"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import minimatch from 'minimatch';
|
|
2
2
|
import path from 'path-posix';
|
|
3
|
-
import
|
|
3
|
+
import unixify from 'unixify';
|
|
4
4
|
/**
|
|
5
5
|
* @param {{path: string, config: Object}} config The path to the loaded TS config and typescript config.
|
|
6
6
|
* @returns {(filePath:string) => boolean} The function to test for typescript files being included or excluded
|
|
7
7
|
*/ export default function createMatcher(config) {
|
|
8
|
-
const configPath = path.dirname(
|
|
8
|
+
const configPath = path.dirname(unixify(config.path));
|
|
9
9
|
function matchFn(condition) {
|
|
10
|
-
let pattern =
|
|
10
|
+
let pattern = unixify(condition);
|
|
11
11
|
if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(configPath, pattern);
|
|
12
12
|
return function match(filePath) {
|
|
13
13
|
return filePath.startsWith(pattern) || minimatch(filePath, pattern);
|
|
@@ -17,7 +17,7 @@ import slash from 'slash';
|
|
|
17
17
|
const excludes = (config.config.exclude || []).map(matchFn);
|
|
18
18
|
return function matcher(filePath) {
|
|
19
19
|
if (filePath.endsWith('.json')) return false;
|
|
20
|
-
filePath =
|
|
20
|
+
filePath = unixify(filePath);
|
|
21
21
|
for(let i = 0; i < excludes.length; ++i){
|
|
22
22
|
if (excludes[i](filePath)) return false;
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["createMatcher.
|
|
1
|
+
{"version":3,"sources":["createMatcher.ts"],"sourcesContent":["import minimatch from 'minimatch';\nimport path from 'path-posix';\nimport unixify from 'unixify';\n\n/**\n * @param {{path: string, config: Object}} config The path to the loaded TS config and typescript config.\n * @returns {(filePath:string) => boolean} The function to test for typescript files being included or excluded\n */\nexport default function createMatcher(config) {\n const configPath = path.dirname(unixify(config.path));\n\n function matchFn(condition) {\n let pattern = unixify(condition);\n if (!path.isAbsolute(pattern) && !pattern.startsWith('*')) pattern = path.join(configPath, pattern);\n\n return function match(filePath) {\n return filePath.startsWith(pattern) || minimatch(filePath, pattern);\n };\n }\n\n const includes = (config.config.include || []).map(matchFn);\n const excludes = (config.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","createMatcher","config","configPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","include","map","excludes","exclude","matcher","endsWith","i","length","j"],"mappings":"AAAA,OAAOA,eAAe,YAAY;AAClC,OAAOC,UAAU,aAAa;AAC9B,OAAOC,aAAa,UAAU;AAE9B;;;CAGC,GACD,eAAe,SAASC,cAAcC,MAAM;IAC1C,MAAMC,aAAaJ,KAAKK,OAAO,CAACJ,QAAQE,OAAOH,IAAI;IAEnD,SAASM,QAAQC,SAAS;QACxB,IAAIC,UAAUP,QAAQM;QACtB,IAAI,CAACP,KAAKS,UAAU,CAACD,YAAY,CAACA,QAAQE,UAAU,CAAC,MAAMF,UAAUR,KAAKW,IAAI,CAACP,YAAYI;QAE3F,OAAO,SAASI,MAAMC,QAAQ;YAC5B,OAAOA,SAASH,UAAU,CAACF,YAAYT,UAAUc,UAAUL;QAC7D;IACF;IAEA,MAAMM,WAAW,AAACX,CAAAA,OAAOA,MAAM,CAACY,OAAO,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACV;IACnD,MAAMW,WAAW,AAACd,CAAAA,OAAOA,MAAM,CAACe,OAAO,IAAI,EAAE,AAAD,EAAGF,GAAG,CAACV;IAEnD,OAAO,SAASa,QAAQN,QAAQ;QAC9B,IAAIA,SAASO,QAAQ,CAAC,UAAU,OAAO;QAEvCP,WAAWZ,QAAQY;QACnB,IAAK,IAAIQ,IAAI,GAAGA,IAAIJ,SAASK,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIJ,QAAQ,CAACI,EAAE,CAACR,WAAW,OAAO;QACpC;QACA,IAAK,IAAIU,IAAI,GAAGA,IAAIT,SAASQ,MAAM,EAAE,EAAEC,EAAG;YACxC,IAAIT,QAAQ,CAACS,EAAE,CAACV,WAAW,OAAO;QACpC;QACA,OAAO,CAACC,SAASQ,MAAM;IACzB;AACF"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as createMatcher } from './createMatcher.mjs';
|
|
2
2
|
export { default as transformFile } from './transformFile.mjs';
|
|
3
3
|
export { default as transformDirectory } from './transformDirectory.mjs';
|
|
4
|
-
export { default as transformSync } from './transformSync.
|
|
4
|
+
export { default as transformSync } from './transformSync.mjs';
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export { default as createMatcher } from './createMatcher.js';\nexport { default as transformFile } from './transformFile.js';\nexport { default as transformDirectory } from './transformDirectory.js';\nexport { default as transformSync } from './transformSync.js';\n"],"names":["default","createMatcher","transformFile","transformDirectory","transformSync"],"mappings":"AAAA,SAASA,WAAWC,aAAa,QAAQ,qBAAqB;AAC9D,SAASD,WAAWE,aAAa,QAAQ,qBAAqB;AAC9D,SAASF,WAAWG,kBAAkB,QAAQ,0BAA0B;AACxE,SAASH,WAAWI,aAAa,QAAQ,qBAAqB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('lazy-cache')(require);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["lazy.cts"],"sourcesContent":["module.exports = require('lazy-cache')(require);\n"],"names":["module","exports","require"],"mappings":"AAAAA,OAAOC,OAAO,GAAGC,QAAQ,cAAcA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = process;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["process.cts"],"sourcesContent":["module.exports = process;\n"],"names":["module","exports","process"],"mappings":"AAAAA,OAAOC,OAAO,GAAGC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import Iterator from 'fs-iterator';
|
|
3
3
|
import getTS from 'get-tsconfig-compat';
|
|
4
|
+
// @ts-ignore
|
|
4
5
|
import createMatcher from './createMatcher.mjs';
|
|
6
|
+
// @ts-ignore
|
|
5
7
|
import transformFile from './transformFile.mjs';
|
|
6
8
|
function transformDirectoryCallback(src, dest, type, options, callback) {
|
|
7
9
|
if (typeof options === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformDirectory.
|
|
1
|
+
{"version":3,"sources":["transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport getTS from 'get-tsconfig-compat';\n\n// @ts-ignore\nimport createMatcher from './createMatcher.ts';\n// @ts-ignore\nimport transformFile from './transformFile.ts';\n\nfunction transformDirectoryCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformDirectory: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformDirectory: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformDirectory: unexpected type');\n\n const config = options.confg ? options.confg : getTS.getTsconfig(src);\n const matcher = createMatcher(config);\n\n options = { ...options, config };\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry, cb) => {\n if (!entry.stats.isFile()) return cb();\n if (!matcher(entry.fullPath)) return cb();\n transformFile(entry.fullPath, path.dirname(path.join(dest, entry.path)), type, options, cb);\n },\n { callbacks: true, concurrency: options.concurrency || 1024 },\n callback\n );\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write files to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.\n * @returns {void | Promise<any>} Optional promise if callback not provided.\n */\nexport default function transformDirectory(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformDirectoryCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformDirectoryCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["path","Iterator","getTS","createMatcher","transformFile","transformDirectoryCallback","src","dest","type","options","callback","Error","config","confg","getTsconfig","matcher","iterator","forEach","entry","cb","stats","isFile","fullPath","dirname","join","callbacks","concurrency","transformDirectory","Promise","resolve","reject","compileCallback","err","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,cAAc,cAAc;AACnC,OAAOC,WAAW,sBAAsB;AAExC,aAAa;AACb,OAAOC,mBAAmB,qBAAqB;AAC/C,aAAa;AACb,OAAOC,mBAAmB,qBAAqB;AAE/C,SAASC,2BAA2BC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACpE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOH,QAAQ,UAAU,MAAM,IAAIK,MAAM;IAC7C,IAAI,OAAOJ,SAAS,UAAU,MAAM,IAAII,MAAM;IAC9C,IAAI,OAAOH,SAAS,UAAU,MAAM,IAAIG,MAAM;IAE9C,MAAMC,SAASH,QAAQI,KAAK,GAAGJ,QAAQI,KAAK,GAAGX,MAAMY,WAAW,CAACR;IACjE,MAAMS,UAAUZ,cAAcS;IAE9BH,UAAU;QAAE,GAAGA,OAAO;QAAEG;IAAO;IAC/B,MAAMI,WAAW,IAAIf,SAASK;IAC9BU,SAASC,OAAO,CACd,CAACC,OAAOC;QACN,IAAI,CAACD,MAAME,KAAK,CAACC,MAAM,IAAI,OAAOF;QAClC,IAAI,CAACJ,QAAQG,MAAMI,QAAQ,GAAG,OAAOH;QACrCf,cAAcc,MAAMI,QAAQ,EAAEtB,KAAKuB,OAAO,CAACvB,KAAKwB,IAAI,CAACjB,MAAMW,MAAMlB,IAAI,IAAIQ,MAAMC,SAASU;IAC1F,GACA;QAAEM,WAAW;QAAMC,aAAajB,QAAQiB,WAAW,IAAI;IAAK,GAC5DhB;AAEJ;AAEA;;;;;;;CAOC,GACD,eAAe,SAASiB,mBAAmBrB,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3E,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IACAA,UAAUA,WAAW,CAAC;IAEtB,IAAI,OAAOC,aAAa,YAAY,OAAOL,2BAA2BC,KAAKC,MAAMC,MAAMC,SAASC;IAChG,OAAO,IAAIkB,QAAQ,CAACC,SAASC;QAC3BzB,2BAA2BC,KAAKC,MAAMC,MAAMC,SAAS,SAASsB,gBAAgBC,GAAG,EAAEC,MAAM;YACvFD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF"}
|
|
@@ -4,10 +4,12 @@ import once from 'call-once-fn';
|
|
|
4
4
|
import getTS from 'get-tsconfig-compat';
|
|
5
5
|
import mkdirp from 'mkdirp';
|
|
6
6
|
import Queue from 'queue-cb';
|
|
7
|
-
|
|
8
|
-
import transformSync from './transformSync.
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import transformSync from './transformSync.mjs';
|
|
9
|
+
const matchingDeps = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
10
|
+
const matchingName = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
11
|
+
const regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\s*)?require\\(${matchingDeps}\\);?`, 'g');
|
|
12
|
+
const regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\s*)?${matchingDeps};?|export(?:${matchingName}from\\s*)?${matchingDeps};?`, 'g');
|
|
11
13
|
const importReplaceMJS = [
|
|
12
14
|
'.js',
|
|
13
15
|
'.ts',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformFile.
|
|
1
|
+
{"version":3,"sources":["transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport once from 'call-once-fn';\nimport getTS from 'get-tsconfig-compat';\nimport mkdirp from 'mkdirp';\nimport Queue from 'queue-cb';\n\n// @ts-ignore\nimport transformSync from './transformSync.ts';\n\nconst matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\nconst matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\nconst regexCJS = new RegExp(`(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`, 'g');\nconst regexESM = new RegExp(`${regexCJS}|import(?:${matchingName}from\\\\s*)?${matchingDeps};?|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`, 'g');\n\nconst importReplaceMJS = ['.js', '.ts', '.tsx', '.mts', '.mjs'];\nconst importReplaceCJS = ['.cts'];\nconst requireReplaceJS = ['.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];\n\nfunction makeReplacements(code, regex, extensions, extension) {\n let matches = [];\n let match = regex.exec(code);\n while (match) {\n const dependency = match[1] || match[2] || match[3] || match[4];\n const ext = extensions.find((x) => dependency.slice(-x.length) === x);\n if (ext) matches.push({ ext, match, dependency });\n match = regex.exec(code);\n }\n\n matches = matches.reverse();\n for (const index in matches) {\n const match = matches[index];\n const start = match.match.index + match.match[0].indexOf(match.dependency) + match.dependency.indexOf(match.ext);\n code = code.substring(0, start) + extension + code.substring(start + match.ext.length);\n }\n return code;\n}\n\n// https://github.com/vercel/next.js/blob/20b63e13ab2631d6043277895d373aa31a1b327c/packages/next/taskfile-swc.js#L118-L125\nconst 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; }\";\n\nfunction transformFileCallback(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n options = options || {};\n\n if (typeof src !== 'string') throw new Error('transformFile: unexpected source');\n if (typeof dest !== 'string') throw new Error('transformFile: unexpected destination directory');\n if (typeof type !== 'string') throw new Error('transformFile: unexpected type');\n\n fs.readFile(src, 'utf8', (err, contents) => {\n if (err) return callback(err);\n callback = once(callback);\n\n try {\n let config = options.confg ? options.confg : getTS.getTsconfig(src);\n\n // overrides for cjs\n if (type === 'cjs') {\n config = { ...config };\n config.config = { ...(config.config || {}) };\n config.config.compilerOptions = { ...(config.config.compilerOptions || {}) };\n config.config.compilerOptions.module = 'CommonJS';\n config.config.compilerOptions.target = 'ES5';\n }\n\n const basename = path.basename(src);\n const output = transformSync(contents, basename, config);\n\n // infer extension and patch .mjs imports\n let ext = path.extname(basename);\n if (type === 'esm') {\n ext = importReplaceMJS.indexOf(ext) >= 0 ? '.mjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceMJS, '.mjs');\n ext = importReplaceCJS.indexOf(ext) >= 0 ? '.cjs' : ext;\n output.code = makeReplacements(output.code, regexESM, importReplaceCJS, '.cjs');\n } else {\n ext = requireReplaceJS.indexOf(ext) >= 0 ? '.js' : ext;\n output.code = makeReplacements(output.code, regexCJS, requireReplaceJS, '.js');\n output.code += interopClientDefaultExport;\n }\n const destFilePath = path.join(dest, basename.replace(/\\.[^/.]+$/, '') + ext);\n\n mkdirp(path.dirname(destFilePath), () => {\n const queue = new Queue();\n queue.defer(fs.writeFile.bind(null, destFilePath, output.code, 'utf8'));\n !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${destFilePath}.map`, output.map, 'utf8'));\n queue.await(() => (err ? callback(err) : callback(null, destFilePath)));\n });\n } catch (err) {\n callback(err);\n }\n });\n}\n\n/**\n * @param {string} src The source directory to traverse.\n * @param {string} dest The output directory to write the file to.\n * @param {string} type The type of transform ('esm' or 'cjs').\n * @param {{sourceMaps: boolean}} options Options to pass to swc.\n * @param {(err: Error | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.\n * @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.\n */\nexport default function transformFile(src, dest, type, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n options = options || {};\n\n if (typeof callback === 'function') return transformFileCallback(src, dest, type, options, callback);\n return new Promise((resolve, reject) => {\n transformFileCallback(src, dest, type, options, function compileCallback(err, result) {\n err ? reject(err) : resolve(result);\n });\n });\n}\n"],"names":["fs","path","once","getTS","mkdirp","Queue","transformSync","matchingDeps","matchingName","regexCJS","RegExp","regexESM","importReplaceMJS","importReplaceCJS","requireReplaceJS","makeReplacements","code","regex","extensions","extension","matches","match","exec","dependency","ext","find","x","slice","length","push","reverse","index","start","indexOf","substring","interopClientDefaultExport","transformFileCallback","src","dest","type","options","callback","Error","readFile","err","contents","config","confg","getTsconfig","compilerOptions","module","target","basename","output","extname","destFilePath","join","replace","dirname","queue","defer","writeFile","bind","sourceMaps","map","await","transformFile","Promise","resolve","reject","compileCallback","result"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,UAAU,eAAe;AAChC,OAAOC,WAAW,sBAAsB;AACxC,OAAOC,YAAY,SAAS;AAC5B,OAAOC,WAAW,WAAW;AAE7B,aAAa;AACb,OAAOC,mBAAmB,qBAAqB;AAE/C,MAAMC,eAAe;AACrB,MAAMC,eAAe;AACrB,MAAMC,WAAW,IAAIC,OAAO,CAAC,oBAAoB,EAAEF,aAAa,iBAAiB,EAAED,aAAa,KAAK,CAAC,EAAE;AACxG,MAAMI,WAAW,IAAID,OAAO,GAAGD,SAAS,UAAU,EAAED,aAAa,UAAU,EAAED,aAAa,YAAY,EAAEC,aAAa,UAAU,EAAED,aAAa,EAAE,CAAC,EAAE;AAEnJ,MAAMK,mBAAmB;IAAC;IAAO;IAAO;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from './lazy.cjs';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import process from './process.cjs';
|
|
7
|
+
const major = +process.versions.node.split('.')[0];
|
|
8
|
+
const version = major >= 14 ? 'local' : 'lts';
|
|
9
|
+
const filename = typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url);
|
|
10
|
+
const worker = path.resolve(path.dirname(filename), 'workers', `transformSync${path.extname(filename) === '.mjs' ? '.cjs' : '.js'}`);
|
|
11
|
+
const call = lazy('node-version-call');
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} contents The file contents.
|
|
14
|
+
* @param {string} fileName The filename.
|
|
15
|
+
* @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.
|
|
16
|
+
*/ export default function transformSync(contents, fileName, config) {
|
|
17
|
+
return call()(version, worker, contents, fileName, config);
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["transformSync.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\n// @ts-ignore\nimport lazy from './lazy.cts';\n// @ts-ignore\nimport process from './process.cts';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major >= 14 ? 'local' : 'lts';\nconst filename = typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url);\nconst worker = path.resolve(path.dirname(filename), 'workers', `transformSync${path.extname(filename) === '.mjs' ? '.cjs' : '.js'}`);\nconst call = lazy('node-version-call');\n\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\n * @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.\n */\nexport default function transformSync(contents, fileName, config) {\n return call()(version, worker, contents, fileName, config);\n}\n"],"names":["path","url","lazy","process","major","versions","node","split","version","filename","__filename","fileURLToPath","worker","resolve","dirname","extname","call","transformSync","contents","fileName","config"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,aAAa;AACb,OAAOC,UAAU,aAAa;AAC9B,aAAa;AACb,OAAOC,aAAa,gBAAgB;AAEpC,MAAMC,QAAQ,CAACD,QAAQE,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUJ,SAAS,KAAK,UAAU;AACxC,MAAMK,WAAW,OAAOC,eAAe,cAAcA,aAAaT,IAAIU,aAAa,CAAC,YAAYV,GAAG;AACnG,MAAMW,SAASZ,KAAKa,OAAO,CAACb,KAAKc,OAAO,CAACL,WAAW,WAAW,CAAC,aAAa,EAAET,KAAKe,OAAO,CAACN,cAAc,SAAS,SAAS,OAAO;AACnI,MAAMO,OAAOd,KAAK;AAElB;;;;CAIC,GACD,eAAe,SAASe,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAC9D,OAAOJ,OAAOR,SAASI,QAAQM,UAAUC,UAAUC;AACrD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.
|
|
1
|
+
{"version":3,"sources":["transformSync.cts"],"sourcesContent":["const path = require('path');\nconst swc = require('@swc/core');\nconst ts = require('typescript');\nconst swcTranspiler = require('ts-node/transpilers/swc');\n\nmodule.exports = function transformSync(contents, fileName, config) {\n const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, path.dirname(config.path));\n const transpile = swcTranspiler.create({ swc: swc, service: { config: { options: parsed.options } } });\n const res = transpile.transpile(contents, { fileName: fileName });\n return { code: res.outputText, map: res.sourceMapText };\n};\n"],"names":["path","require","swc","ts","swcTranspiler","module","exports","transformSync","contents","fileName","config","parsed","parseJsonConfigFileContent","sys","dirname","transpile","create","service","options","res","code","outputText","map","sourceMapText"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AACrB,MAAMC,MAAMD,QAAQ;AACpB,MAAME,KAAKF,QAAQ;AACnB,MAAMG,gBAAgBH,QAAQ;AAE9BI,OAAOC,OAAO,GAAG,SAASC,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAChE,MAAMC,SAASR,GAAGS,0BAA0B,CAACF,OAAOA,MAAM,EAAEP,GAAGU,GAAG,EAAEb,KAAKc,OAAO,CAACJ,OAAOV,IAAI;IAC5F,MAAMe,YAAYX,cAAcY,MAAM,CAAC;QAAEd,KAAKA;QAAKe,SAAS;YAAEP,QAAQ;gBAAEQ,SAASP,OAAOO,OAAO;YAAC;QAAE;IAAE;IACpG,MAAMC,MAAMJ,UAAUA,SAAS,CAACP,UAAU;QAAEC,UAAUA;IAAS;IAC/D,OAAO;QAAEW,MAAMD,IAAIE,UAAU;QAAEC,KAAKH,IAAII,aAAa;IAAC;AACxD"}
|
|
@@ -2,7 +2,4 @@
|
|
|
2
2
|
* @param {{path: string, config: Object}} config The path to the loaded TS config and typescript config.
|
|
3
3
|
* @returns {(filePath:string) => boolean} The function to test for typescript files being included or excluded
|
|
4
4
|
*/
|
|
5
|
-
export default function createMatcher(config:
|
|
6
|
-
path: string;
|
|
7
|
-
config: any;
|
|
8
|
-
}): (filePath: string) => boolean;
|
|
5
|
+
export default function createMatcher(config: any): (filePath: any) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,6 +6,4 @@
|
|
|
6
6
|
* @param {(err?: Error) =>} [callback] Optional callback. Uses promise if callback not provided.
|
|
7
7
|
* @returns {void | Promise<any>} Optional promise if callback not provided.
|
|
8
8
|
*/
|
|
9
|
-
export default function transformDirectory(src:
|
|
10
|
-
sourceMaps: boolean;
|
|
11
|
-
}, callback?: (err?: Error) => any): void | Promise<any>;
|
|
9
|
+
export default function transformDirectory(src: any, dest: any, type: any, options: any, callback: any): void | Promise<unknown>;
|
|
@@ -6,6 +6,4 @@
|
|
|
6
6
|
* @param {(err: Error | null, destFilePath: string) =>} [callback] Optional callback returing the path to the transformed file. Uses promise if callback not provided.
|
|
7
7
|
* @returns {void | Promise<string>} Optional promise returing the path to the transformed file if callback not provided.
|
|
8
8
|
*/
|
|
9
|
-
export default function transformFile(src:
|
|
10
|
-
sourceMaps: boolean;
|
|
11
|
-
}, callback?: (err: Error | null, destFilePath: string) => any): void | Promise<string>;
|
|
9
|
+
export default function transformFile(src: any, dest: any, type: any, options: any, callback: any): void | Promise<unknown>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} contents The file contents.
|
|
3
|
+
* @param {string} fileName The filename.
|
|
4
|
+
* @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.
|
|
5
|
+
*/
|
|
6
|
+
export default function transformSync(contents: any, fileName: any, config: any): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -51,14 +51,17 @@
|
|
|
51
51
|
"@swc/core": "*",
|
|
52
52
|
"call-once-fn": "^1.0.1",
|
|
53
53
|
"exit": "^0.1.2",
|
|
54
|
-
"
|
|
54
|
+
"fs-iterator": "^5.1.1",
|
|
55
|
+
"get-tsconfig-compat": "^1.1.0",
|
|
56
|
+
"lazy-cache": "^2.0.2",
|
|
55
57
|
"minimatch": "^3.1.2",
|
|
56
58
|
"mkdirp": "^0.5.6",
|
|
57
59
|
"node-version-call": "^1.1.0",
|
|
58
60
|
"path-posix": "^1.0.0",
|
|
59
|
-
"
|
|
61
|
+
"queue-cb": "^1.2.1",
|
|
60
62
|
"ts-node": "*",
|
|
61
|
-
"typescript": "*"
|
|
63
|
+
"typescript": "*",
|
|
64
|
+
"unixify": "^1.0.0"
|
|
62
65
|
},
|
|
63
66
|
"devDependencies": {
|
|
64
67
|
"@biomejs/biome": "^1.9.4",
|
|
@@ -68,11 +71,9 @@
|
|
|
68
71
|
"core-js": "^3.39.0",
|
|
69
72
|
"cr": "^0.1.0",
|
|
70
73
|
"cross-spawn-cb": "^1.1.2",
|
|
71
|
-
"
|
|
72
|
-
"queue-cb": "^1.2.1",
|
|
73
|
-
"react": "^18.3.1",
|
|
74
|
+
"react": "^19.0.0",
|
|
74
75
|
"rimraf2": "^2.8.2",
|
|
75
|
-
"ts-dev-stack": "^1.
|
|
76
|
+
"ts-dev-stack": "^1.2.1",
|
|
76
77
|
"ts-node": "^10.8.2",
|
|
77
78
|
"typescript": "^5.7.2"
|
|
78
79
|
},
|
|
@@ -80,7 +81,7 @@
|
|
|
80
81
|
"node": ">=0.8"
|
|
81
82
|
},
|
|
82
83
|
"tsds": {
|
|
83
|
-
"source": "src/index.
|
|
84
|
+
"source": "src/index.ts",
|
|
84
85
|
"targets": [
|
|
85
86
|
"cjs",
|
|
86
87
|
"esm"
|
|
@@ -1,21 +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 regexDependencies;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function regexDependencies(esm) {
|
|
12
|
-
var matchingDeps = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
13
|
-
var matchingName = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
14
|
-
var regex = "(?:(?:var|const|let)".concat(matchingName, "=\\s*)?require\\(").concat(matchingDeps, "\\);?");
|
|
15
|
-
if (esm) {
|
|
16
|
-
regex += "|import(?:".concat(matchingName, "from\\s*)?").concat(matchingDeps, ";?");
|
|
17
|
-
regex += "|export(?:".concat(matchingName, "from\\s*)?").concat(matchingDeps, ";?");
|
|
18
|
-
}
|
|
19
|
-
return new RegExp(regex, 'g');
|
|
20
|
-
}
|
|
21
|
-
/* 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":["regexDependencies.mjs"],"sourcesContent":["export default function regexDependencies(esm) {\n const matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\n const matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\n\n let regex = `(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`;\n if (esm) {\n regex += `|import(?:${matchingName}from\\\\s*)?${matchingDeps};?`;\n regex += `|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`;\n }\n return new RegExp(regex, 'g');\n}\n"],"names":["regexDependencies","esm","matchingDeps","matchingName","regex","RegExp"],"mappings":";;;;+BAAA;;;eAAwBA;;;AAAT,SAASA,kBAAkBC,GAAG;IAC3C,IAAMC,eAAe;IACrB,IAAMC,eAAe;IAErB,IAAIC,QAAQ,AAAC,uBAAsDF,OAAhCC,cAAa,qBAAgC,OAAbD,cAAa;IAChF,IAAID,KAAK;QACPG,SAAS,AAAC,aAAqCF,OAAzBC,cAAa,cAAyB,OAAbD,cAAa;QAC5DE,SAAS,AAAC,aAAqCF,OAAzBC,cAAa,cAAyB,OAAbD,cAAa;IAC9D;IACA,OAAO,IAAIG,OAAOD,OAAO;AAC3B"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default function regexDependencies(esm) {
|
|
2
|
-
const matchingDeps = '\\s*[\'"`]([^\'"`]+)[\'"`]\\s*';
|
|
3
|
-
const matchingName = '\\s*(?:[\\w${},\\s*]+)\\s*';
|
|
4
|
-
let regex = `(?:(?:var|const|let)${matchingName}=\\s*)?require\\(${matchingDeps}\\);?`;
|
|
5
|
-
if (esm) {
|
|
6
|
-
regex += `|import(?:${matchingName}from\\s*)?${matchingDeps};?`;
|
|
7
|
-
regex += `|export(?:${matchingName}from\\s*)?${matchingDeps};?`;
|
|
8
|
-
}
|
|
9
|
-
return new RegExp(regex, 'g');
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["regexDependencies.mjs"],"sourcesContent":["export default function regexDependencies(esm) {\n const matchingDeps = '\\\\s*[\\'\"`]([^\\'\"`]+)[\\'\"`]\\\\s*';\n const matchingName = '\\\\s*(?:[\\\\w${},\\\\s*]+)\\\\s*';\n\n let regex = `(?:(?:var|const|let)${matchingName}=\\\\s*)?require\\\\(${matchingDeps}\\\\);?`;\n if (esm) {\n regex += `|import(?:${matchingName}from\\\\s*)?${matchingDeps};?`;\n regex += `|export(?:${matchingName}from\\\\s*)?${matchingDeps};?`;\n }\n return new RegExp(regex, 'g');\n}\n"],"names":["regexDependencies","esm","matchingDeps","matchingName","regex","RegExp"],"mappings":"AAAA,eAAe,SAASA,kBAAkBC,GAAG;IAC3C,MAAMC,eAAe;IACrB,MAAMC,eAAe;IAErB,IAAIC,QAAQ,CAAC,oBAAoB,EAAED,aAAa,iBAAiB,EAAED,aAAa,KAAK,CAAC;IACtF,IAAID,KAAK;QACPG,SAAS,CAAC,UAAU,EAAED,aAAa,UAAU,EAAED,aAAa,EAAE,CAAC;QAC/DE,SAAS,CAAC,UAAU,EAAED,aAAa,UAAU,EAAED,aAAa,EAAE,CAAC;IACjE;IACA,OAAO,IAAIG,OAAOD,OAAO;AAC3B"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const major = +process.versions.node.split('.')[0];
|
|
3
|
-
const version = major >= 14 ? 'local' : 'lts';
|
|
4
|
-
const worker = path.resolve(__dirname, 'workers', `transformSync${path.extname(__filename)}`);
|
|
5
|
-
let call = null; // break dependencies
|
|
6
|
-
/**
|
|
7
|
-
* @param {string} contents The file contents.
|
|
8
|
-
* @param {string} fileName The filename.
|
|
9
|
-
* @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.
|
|
10
|
-
*/ module.exports = function transformSync(contents, fileName, config) {
|
|
11
|
-
if (!call) call = require('node-version-call'); // break dependencies
|
|
12
|
-
return call(version, worker, contents, fileName, config);
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["transformSync.cjs"],"sourcesContent":["const path = require('path');\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major >= 14 ? 'local' : 'lts';\nconst worker = path.resolve(__dirname, 'workers', `transformSync${path.extname(__filename)}`);\n\nlet call = null; // break dependencies\n\n/**\n * @param {string} contents The file contents.\n * @param {string} fileName The filename.\n * @returns {{ code: string, map?: string }} Returns object with the transformed code and source map if option sourceMaps was provided.\n */\nmodule.exports = function transformSync(contents, fileName, config) {\n if (!call) call = require('node-version-call'); // break dependencies\n\n return call(version, worker, contents, fileName, config);\n};\n"],"names":["path","require","major","process","versions","node","split","version","worker","resolve","__dirname","extname","__filename","call","module","exports","transformSync","contents","fileName","config"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AAErB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,SAAS,KAAK,UAAU;AACxC,MAAMM,SAASR,KAAKS,OAAO,CAACC,WAAW,WAAW,CAAC,aAAa,EAAEV,KAAKW,OAAO,CAACC,aAAa;AAE5F,IAAIC,OAAO,MAAM,qBAAqB;AAEtC;;;;CAIC,GACDC,OAAOC,OAAO,GAAG,SAASC,cAAcC,QAAQ,EAAEC,QAAQ,EAAEC,MAAM;IAChE,IAAI,CAACN,MAAMA,OAAOZ,QAAQ,sBAAsB,qBAAqB;IAErE,OAAOY,KAAKN,SAASC,QAAQS,UAAUC,UAAUC;AACnD"}
|
package/dist/types/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function regexDependencies(esm: any): RegExp;
|