ts-swc-transform 1.13.4 → 1.13.6

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.
Files changed (40) hide show
  1. package/dist/cjs/createMatcher.cjs +1 -2
  2. package/dist/cjs/createMatcher.cjs.map +1 -1
  3. package/dist/cjs/lib/{installBindings.cjs → ensureBindings.cjs} +4 -1
  4. package/dist/cjs/lib/ensureBindings.cjs.map +1 -0
  5. package/dist/cjs/lib/swcPrepareOptions.cjs +2 -0
  6. package/dist/cjs/lib/swcPrepareOptions.cjs.map +1 -1
  7. package/dist/cjs/lib/transformFile.cjs +29 -26
  8. package/dist/cjs/lib/transformFile.cjs.map +1 -1
  9. package/dist/cjs/resolveFileSync.cjs +1 -2
  10. package/dist/cjs/resolveFileSync.cjs.map +1 -1
  11. package/dist/cjs/transformDirectory.cjs.map +1 -1
  12. package/dist/cjs/workers/installBindings.cjs +5 -8
  13. package/dist/cjs/workers/installBindings.cjs.map +1 -1
  14. package/dist/cjs/workers/transformDirectory.cjs +32 -37
  15. package/dist/cjs/workers/transformDirectory.cjs.map +1 -1
  16. package/dist/cjs/workers/transformSync.cjs +1 -5
  17. package/dist/cjs/workers/transformSync.cjs.map +1 -1
  18. package/dist/esm/createMatcher.mjs +1 -2
  19. package/dist/esm/createMatcher.mjs.map +1 -1
  20. package/dist/esm/lib/{installBindings.mjs → ensureBindings.mjs} +4 -1
  21. package/dist/esm/lib/ensureBindings.mjs.map +1 -0
  22. package/dist/esm/lib/swcPrepareOptions.mjs +2 -0
  23. package/dist/esm/lib/swcPrepareOptions.mjs.map +1 -1
  24. package/dist/esm/lib/transformFile.mjs +35 -32
  25. package/dist/esm/lib/transformFile.mjs.map +1 -1
  26. package/dist/esm/resolveFileSync.mjs +1 -2
  27. package/dist/esm/resolveFileSync.mjs.map +1 -1
  28. package/dist/esm/transformDirectory.mjs.map +1 -1
  29. package/dist/esm/workers/installBindings.mjs +4 -7
  30. package/dist/esm/workers/installBindings.mjs.map +1 -1
  31. package/dist/esm/workers/transformDirectory.mjs +31 -36
  32. package/dist/esm/workers/transformDirectory.mjs.map +1 -1
  33. package/dist/esm/workers/transformSync.mjs +1 -5
  34. package/dist/esm/workers/transformSync.mjs.map +1 -1
  35. package/dist/types/lib/ensureBindings.d.ts +3 -0
  36. package/dist/types/workers/installBindings.d.ts +1 -2
  37. package/package.json +3 -4
  38. package/dist/cjs/lib/installBindings.cjs.map +0 -1
  39. package/dist/esm/lib/installBindings.mjs.map +0 -1
  40. package/dist/types/lib/installBindings.d.ts +0 -3
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "default", {
8
8
  return createMatcher;
9
9
  }
10
10
  });
11
- var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
12
11
  var _minimatch = /*#__PURE__*/ _interop_require_default(require("minimatch"));
13
12
  var _pathposix = /*#__PURE__*/ _interop_require_default(require("path-posix"));
14
13
  var _unixify = /*#__PURE__*/ _interop_require_default(require("unixify"));
@@ -33,7 +32,7 @@ function createMatcher(tsConfig) {
33
32
  var includes = (tsconfig.config.include || []).map(matchFn);
34
33
  var excludes = (tsconfig.config.exclude || []).map(matchFn);
35
34
  return function matcher(filePath) {
36
- if ((0, _lodashendswith.default)(filePath, '.json')) return false;
35
+ if (filePath.endsWith('.json')) return false;
37
36
  filePath = (0, _unixify.default)(filePath);
38
37
  for(var i = 0; i < excludes.length; ++i){
39
38
  if (excludes[i](filePath)) return false;
@@ -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 endsWith from 'lodash.endswith';\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 (endsWith(filePath, '.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":";;;;+BAQA;;;eAAwBA;;;qEAPH;gEACC;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,IAAIS,IAAAA,uBAAQ,EAACT,UAAU,UAAU,OAAO;QAExCA,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 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"}
@@ -16,6 +16,7 @@ _export(exports, {
16
16
  return sync;
17
17
  }
18
18
  });
19
+ var _resolveoncemapcb = /*#__PURE__*/ _interop_require_default(require("resolve-once-map-cb"));
19
20
  var _installBindings = /*#__PURE__*/ _interop_require_wildcard(require("../workers/installBindings.cjs"));
20
21
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
21
22
  var _url = /*#__PURE__*/ _interop_require_default(require("url"));
@@ -67,7 +68,6 @@ function _interop_require_wildcard(obj, nodeInterop) {
67
68
  }
68
69
  return newObj;
69
70
  }
70
- var _default = _installBindings.default;
71
71
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
72
72
  var __dirname = _path.default.dirname(typeof __filename === 'undefined' ? _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()) : __filename);
73
73
  var workerPath = _path.default.join(__dirname, '..', '..', 'cjs', 'workers', 'installBindings.cjs');
@@ -83,4 +83,7 @@ var install = (0, _lazycache.default)(function(target) {
83
83
  var sync = function(target) {
84
84
  return install(target)();
85
85
  };
86
+ var _default = (0, _resolveoncemapcb.default)(function(target, callback) {
87
+ return (0, _installBindings.isInstalled)(target) ? callback() : (0, _installBindings.default)(target, callback);
88
+ });
86
89
  /* 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/ensureBindings.ts"],"sourcesContent":["import resolveOnceMap from 'resolve-once-map-cb';\nimport installBindings, { isInstalled } from '../workers/installBindings';\n\nimport path from 'path';\nimport url from 'url';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', '..', 'cjs', 'workers', 'installBindings.cjs');\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\n\nconst callLazy = lazy(_require)('node-version-call');\nconst install = lazy((target) => {\n return isInstalled(target) ? target : callLazy()({ version, callbacks: true }, workerPath, target);\n});\n\nexport const sync = (target) => install(target)();\nexport default resolveOnceMap((target, callback) => {\n return isInstalled(target) ? callback() : installBindings(target, callback);\n});\n"],"names":["sync","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","major","process","versions","node","split","version","callLazy","lazy","install","target","isInstalled","callbacks","resolveOnceMap","callback","installBindings"],"mappings":";;;;;;;;;;;IAoBA,OAEG;eAFH;;IADaA,IAAI;eAAJA;;;uEAnBc;uEACkB;2DAE5B;0DACD;6DAEG;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,MAAM,OAAO,WAAW;AACtE,IAAMQ,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AAExC,IAAMM,WAAWC,IAAAA,kBAAI,EAACnB,UAAU;AAChC,IAAMoB,UAAUD,IAAAA,kBAAI,EAAC,SAACE;IACpB,OAAOC,IAAAA,4BAAW,EAACD,UAAUA,SAASH,WAAW;QAAED,SAAAA;QAASM,WAAW;IAAK,GAAGb,YAAYW;AAC7F;AAEO,IAAMtB,OAAO,SAACsB;WAAWD,QAAQC;;IACxC,WAAeG,IAAAA,yBAAc,EAAC,SAACH,QAAQI;IACrC,OAAOH,IAAAA,4BAAW,EAACD,UAAUI,aAAaC,IAAAA,wBAAe,EAACL,QAAQI;AACpE"}
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
12
+ var _ensureBindings = require("./ensureBindings.cjs");
12
13
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
13
14
  var _lazycache = /*#__PURE__*/ _interop_require_default(require("lazy-cache"));
14
15
  function _interop_require_default(obj) {
@@ -21,6 +22,7 @@ var tsLazy = (0, _lazycache.default)(_require)('typescript');
21
22
  var swcLazy = (0, _lazycache.default)(_require)('@swc/core');
22
23
  var transpilerLazy = (0, _lazycache.default)(_require)('ts-node/transpilers/swc');
23
24
  function swcPrepareOptions(tsconfig) {
25
+ (0, _ensureBindings.sync)("".concat(process.platform, "-").concat(process.arch));
24
26
  try {
25
27
  var ts = tsLazy();
26
28
  var swc = swcLazy();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","tsLazy","lazy","swcLazy","transpilerLazy","tsconfig","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAWA;;;eAAwBA;;;2DAXP;6DAEE;gEACF;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,SAASC,IAAAA,kBAAI,EAACL,UAAU;AAC9B,IAAMM,UAAUD,IAAAA,kBAAI,EAACL,UAAU;AAC/B,IAAMO,iBAAiBF,IAAAA,kBAAI,EAACL,UAAU;AAIvB,SAASD,kBAAkBS,QAAwB;IAChE,IAAI;QACF,IAAMC,KAAKL;QACX,IAAMM,MAAMJ;QACZ,IAAMK,aAAaJ;QACnB,IAAMK,SAASH,GAAGI,0BAA0B,CAACL,SAASM,MAAM,EAAEL,GAAGM,GAAG,EAAEC,aAAI,CAACC,OAAO,CAACT,SAASQ,IAAI;QAChG,OAAOL,WAAWO,gBAAgB,CAACN,OAAOO,OAAO,EAAEC,WAAWV,KAAK;IACrE,EAAE,OAAOW,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport { sync as ensureBindings } from './ensureBindings';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n ensureBindings(`${process.platform}-${process.arch}`);\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["swcPrepareOptions","_require","require","Module","createRequire","tsLazy","lazy","swcLazy","transpilerLazy","tsconfig","ensureBindings","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAYA;;;eAAwBA;;;2DAZP;8BACsB;6DAEpB;gEACF;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,SAASC,IAAAA,kBAAI,EAACL,UAAU;AAC9B,IAAMM,UAAUD,IAAAA,kBAAI,EAACL,UAAU;AAC/B,IAAMO,iBAAiBF,IAAAA,kBAAI,EAACL,UAAU;AAIvB,SAASD,kBAAkBS,QAAwB;IAChEC,IAAAA,oBAAc,EAAC,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI;IAClD,IAAI;QACF,IAAMC,KAAKT;QACX,IAAMU,MAAMR;QACZ,IAAMS,aAAaR;QACnB,IAAMS,SAASH,GAAGI,0BAA0B,CAACT,SAASU,MAAM,EAAEL,GAAGM,GAAG,EAAEC,aAAI,CAACC,OAAO,CAACb,SAASY,IAAI;QAChG,OAAOL,WAAWO,gBAAgB,CAACN,OAAOO,OAAO,EAAEC,WAAWV,KAAK;IACrE,EAAE,OAAOW,KAAK;QACZC,QAAQC,GAAG,CAAC,AAAC,6BAAwC,OAAZF,IAAIG,OAAO;QACpD,OAAO,CAAC;IACV;AACF"}
@@ -10,9 +10,9 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
12
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
- var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
14
13
  var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
15
14
  var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
15
+ var _ensureBindings = /*#__PURE__*/ _interop_require_default(require("./ensureBindings.cjs"));
16
16
  var _patchCJS = /*#__PURE__*/ _interop_require_default(require("../lib/patchCJS.cjs"));
17
17
  var _patchESM = /*#__PURE__*/ _interop_require_default(require("../lib/patchESM.cjs"));
18
18
  var _swcPrepareOptions = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.cjs"));
@@ -78,31 +78,34 @@ function _object_spread_props(target, source) {
78
78
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
79
79
  var swcLazy = (0, _lazycache.default)(_require)('@swc/core');
80
80
  function transformFile(entry, dest, type, options, callback) {
81
- var tsconfig = options.tsconfig;
82
- // overrides for cjs
83
- if (type === 'cjs') {
84
- tsconfig = _object_spread({}, tsconfig);
85
- tsconfig.config = _object_spread({}, tsconfig.config);
86
- tsconfig.config.compilerOptions = _object_spread({}, tsconfig.config.compilerOptions || {});
87
- tsconfig.config.compilerOptions.module = 'CommonJS';
88
- tsconfig.config.compilerOptions.target = 'ES5';
89
- }
90
- var swcOptions = (0, _swcPrepareOptions.default)(tsconfig);
91
- var swc = swcLazy();
92
- swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, (0, _lodashendswith.default)(entry.basename, '.tsx') || (0, _lodashendswith.default)(entry.basename, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
93
- filename: entry.basename
94
- })).then(function(output) {
95
- var extTarget = type === 'esm' ? (0, _patchESM.default)(entry, output, options) : (0, _patchCJS.default)(entry, output, options);
96
- var ext = _path.default.extname(entry.path);
97
- var outPath = _path.default.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
98
- (0, _mkdirpclassic.default)(_path.default.dirname(outPath), function() {
99
- var queue = new _queuecb.default();
100
- queue.defer(_fs.default.writeFile.bind(null, outPath, output.code, 'utf8'));
101
- !options.sourceMaps || queue.defer(_fs.default.writeFile.bind(null, "".concat(outPath, ".map"), output.map, 'utf8'));
102
- queue.await(function(err) {
103
- return err ? callback(err) : callback(null, outPath);
81
+ (0, _ensureBindings.default)("".concat(process.platform, "-").concat(process.arch), function(err) {
82
+ if (err) return callback(err);
83
+ var tsconfig = options.tsconfig;
84
+ // overrides for cjs
85
+ if (type === 'cjs') {
86
+ tsconfig = _object_spread({}, tsconfig);
87
+ tsconfig.config = _object_spread({}, tsconfig.config);
88
+ tsconfig.config.compilerOptions = _object_spread({}, tsconfig.config.compilerOptions || {});
89
+ tsconfig.config.compilerOptions.module = 'CommonJS';
90
+ tsconfig.config.compilerOptions.target = 'ES5';
91
+ }
92
+ var swcOptions = (0, _swcPrepareOptions.default)(tsconfig);
93
+ var swc = swcLazy();
94
+ swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
95
+ filename: entry.basename
96
+ })).then(function(output) {
97
+ var extTarget = type === 'esm' ? (0, _patchESM.default)(entry, output, options) : (0, _patchCJS.default)(entry, output, options);
98
+ var ext = _path.default.extname(entry.path);
99
+ var outPath = _path.default.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
100
+ (0, _mkdirpclassic.default)(_path.default.dirname(outPath), function() {
101
+ var queue = new _queuecb.default();
102
+ queue.defer(_fs.default.writeFile.bind(null, outPath, output.code, 'utf8'));
103
+ !options.sourceMaps || queue.defer(_fs.default.writeFile.bind(null, "".concat(outPath, ".map"), output.map, 'utf8'));
104
+ queue.await(function(err) {
105
+ return err ? callback(err) : callback(null, outPath);
106
+ });
104
107
  });
105
- });
106
- }).catch(callback);
108
+ }).catch(callback);
109
+ });
107
110
  }
108
111
  /* 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/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport endsWith from 'lodash.endswith';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nexport default function transformFile(entry, dest, type, options, callback) {\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 = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n\n swc\n .transformFile(entry.fullPath, {\n ...(endsWith(entry.basename, '.tsx') || endsWith(entry.basename, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((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 !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","swcLazy","lazy","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","endsWith","basename","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAfT;2DACE;qEACI;oEACF;8DACD;+DAEG;+DACA;wEACS;6DAEX;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,UAAUC,IAAAA,kBAAI,EAACL,UAAU;AAEhB,SAASD,cAAcO,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACxE,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW,mBAAKA;QAChBA,SAASC,MAAM,GAAG,mBAAKD,SAASC,MAAM;QACtCD,SAASC,MAAM,CAACC,eAAe,GAAG,mBAAMF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC;QAC5EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,IAAMC,aAAaC,IAAAA,0BAAiB,EAACN;IACrC,IAAMO,MAAMd;IAEZc,IACGnB,aAAa,CAACO,MAAMa,QAAQ,EAAE,wCACzBC,IAAAA,uBAAQ,EAACd,MAAMe,QAAQ,EAAE,WAAWD,IAAAA,uBAAQ,EAACd,MAAMe,QAAQ,EAAE,UAAUL,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QAC3HC,UAAUlB,MAAMe,QAAQ;QAEzBI,IAAI,CAAC,SAACC;QACL,IAAMC,YAAYnB,SAAS,QAAQoB,IAAAA,iBAAQ,EAACtB,OAAOoB,QAAQjB,WAAWoB,IAAAA,iBAAQ,EAACvB,OAAOoB,QAAQjB;QAC9F,IAAMqB,MAAMC,aAAI,CAACC,OAAO,CAAC1B,MAAMyB,IAAI;QACnC,IAAME,UAAUF,aAAI,CAACG,IAAI,CAAC3B,MAAM,AAACuB,CAAAA,MAAMxB,MAAMyB,IAAI,CAACI,KAAK,CAAC,GAAG,CAACL,IAAIM,MAAM,IAAI9B,MAAMyB,IAAI,AAAD,IAAKJ;QAExFU,IAAAA,sBAAM,EAACN,aAAI,CAACO,OAAO,CAACL,UAAU;YAC5B,IAAMM,QAAQ,IAAIC,gBAAK;YACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMX,SAASP,OAAOmB,IAAI,EAAE;YAC1D,CAACpC,QAAQqC,UAAU,IAAIP,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARX,SAAQ,SAAOP,OAAOqB,GAAG,EAAE;YACzFR,MAAMS,KAAK,CAAC,SAACC;uBAASA,MAAMvC,SAASuC,OAAOvC,SAAS,MAAMuB;;QAC7D;IACF,GACCiB,KAAK,CAACxC;AACX"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\nimport ensureBindings from './ensureBindings';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nexport default function transformFile(entry, dest, type, options, callback) {\n ensureBindings(`${process.platform}-${process.arch}`, (err) => {\n if (err) return callback(err);\n\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 = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((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 !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}\n"],"names":["transformFile","_require","require","Module","createRequire","swcLazy","lazy","entry","dest","type","options","callback","ensureBindings","process","platform","arch","err","tsconfig","config","compilerOptions","module","target","swcOptions","swcPrepareOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","patchESM","patchCJS","ext","path","extname","outPath","join","slice","length","mkdirp","dirname","queue","Queue","defer","fs","writeFile","bind","code","sourceMaps","map","await","catch"],"mappings":";;;;+BAeA;;;eAAw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,QAAQtB;YAC9F,IAAM0B,MAAMC,aAAI,CAACC,OAAO,CAAC/B,MAAM8B,IAAI;YACnC,IAAME,UAAUF,aAAI,CAACG,IAAI,CAAChC,MAAM,AAAC4B,CAAAA,MAAM7B,MAAM8B,IAAI,CAACI,KAAK,CAAC,GAAG,CAACL,IAAIM,MAAM,IAAInC,MAAM8B,IAAI,AAAD,IAAKJ;YAExFU,IAAAA,sBAAM,EAACN,aAAI,CAACO,OAAO,CAACL,UAAU;gBAC5B,IAAMM,QAAQ,IAAIC,gBAAK;gBACvBD,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAMX,SAASP,OAAOmB,IAAI,EAAE;gBAC1D,CAACzC,QAAQ0C,UAAU,IAAIP,MAAME,KAAK,CAACC,WAAE,CAACC,SAAS,CAACC,IAAI,CAAC,MAAM,AAAC,GAAU,OAARX,SAAQ,SAAOP,OAAOqB,GAAG,EAAE;gBACzFR,MAAMS,KAAK,CAAC,SAACtC;2BAASA,MAAML,SAASK,OAAOL,SAAS,MAAM4B;;YAC7D;QACF,GACCgB,KAAK,CAAC5C;IACX;AACF"}
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
12
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
- var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
14
13
  var _constants = require("./constants.cjs");
15
14
  var _toPath = /*#__PURE__*/ _interop_require_default(require("./toPath.cjs"));
16
15
  function _interop_require_default(obj) {
@@ -28,7 +27,7 @@ function resolveFileSync(specifier, context) {
28
27
  stat = _fs.default.statSync(filePath);
29
28
  } catch (_err) {}
30
29
  try {
31
- if (stat && stat.isDirectory() || (0, _lodashendswith.default)(specifier, '/')) {
30
+ if (stat && stat.isDirectory() || specifier.endsWith('/')) {
32
31
  var items = _fs.default.readdirSync(filePath);
33
32
  var item = items.find(function(x) {
34
33
  return indexExtensions.indexOf(x) >= 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport endsWith from 'lodash.endswith';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || endsWith(specifier, '/')) {\n const items = fs.readdirSync(filePath);\n const item = items.find((x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = items.find((x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","length","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BASA;;;eAAwBA;;;yDATT;2DACE;qEACI;yBACkC;6DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,qBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,eA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/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = items.find((x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = items.find((x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["resolveFileSync","indexExtensions","extensions","map","x","specifier","context","filePath","toPath","stat","fs","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","path","join","moduleRegEx","test","ext","extname","basename","slice","length","dirname","typeFileRegEx","extTest","basenameTest"],"mappings":";;;;+BAQA;;;eAAwBA;;;yDART;2DACE;yBACsC;6DACpC;;;;;;AAGnB,IAAMC,kBAAkBC,qBAAU,CAACC,GAAG,CAAC,SAACC;WAAM,AAAC,QAAS,OAAFA;;AAEvC,SAASJ,gBAAgBK,SAAiB,EAAEC,OAAiB;IAC1E,IAAMC,WAAWC,IAAAA,eAAM,EAACH,WAAWC;IACnC,IAAIG;IACJ,IAAI;QACFA,OAAOC,WAAE,CAACC,QAAQ,CAACJ;IACrB,EAAE,OAAOK,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACH,QAAQA,KAAKI,WAAW,MAAOR,UAAUS,QAAQ,CAAC,MAAM;YAC3D,IAAMC,QAAQL,WAAE,CAACM,WAAW,CAACT;YAC7B,IAAMU,OAAOF,MAAMG,IAAI,CAAC,SAACd;uBAAMH,gBAAgBkB,OAAO,CAACf,MAAM;;YAC7D,IAAIa,MAAM,OAAOG,aAAI,CAACC,IAAI,CAACd,UAAUU;QACvC,OAAO,IAAI,CAACR,QAAQ,CAACa,sBAAW,CAACC,IAAI,CAAClB,YAAY;YAChD,IAAMmB,MAAMJ,aAAI,CAACK,OAAO,CAAClB;YACzB,IAAMmB,WAAWF,MAAMJ,aAAI,CAACM,QAAQ,CAACnB,UAAUoB,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACnB;YACrF,IAAMQ,SAAQL,WAAE,CAACM,WAAW,CAACI,aAAI,CAACS,OAAO,CAACtB;YAC1C,IAAMU,QAAOF,OAAMG,IAAI,CAAC,SAACd;gBACvB,IAAI0B,wBAAa,CAACP,IAAI,CAACnB,IAAI,OAAO;gBAClC,IAAM2B,UAAUX,aAAI,CAACK,OAAO,CAACrB;gBAC7B,IAAM4B,eAAeD,UAAUX,aAAI,CAACM,QAAQ,CAACtB,GAAGuB,KAAK,CAAC,GAAG,CAACI,QAAQH,MAAM,IAAIR,aAAI,CAACM,QAAQ,CAACtB;gBAC1F,OAAOsB,aAAaM;YACtB;YACA,IAAIf,OAAM,OAAOG,aAAI,CAACC,IAAI,CAACD,aAAI,CAACS,OAAO,CAACtB,WAAWU;QACrD;QACA,wBAAwB;QACxB,OAAOR,OAAOF,WAAW;IAC3B,EAAE,OAAOK,MAAM;QACb,OAAO;IACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return workerLazy()(src, dest, type, options, callback);\n try {\n callback(null, callLazy()({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types';\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: string, dest: string, type: string, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, type, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformDirectory","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","callLazy","lazy","workerLazy","dispatch","src","dest","type","options","callback","callbacks","err","Error","tsconfig","loadTsConfig","cwd","Promise","resolve","reject","result"],"mappings":";;;;+BAyBA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DAjCP;0DACD;mEACS;6DAON;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANjB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,OAAO,WAAW;AAIhE,IAAMQ,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,WAAWC,IAAAA,kBAAI,EAACL,UAAU;AAChC,IAAMM,aAAaD,IAAAA,kBAAI,EAACL,UAAUF;AAElC,SAASS,SAAShB,OAAO,EAAEiB,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3D,IAAIrB,YAAY,SAAS,OAAOe,aAAaE,KAAKC,MAAMC,MAAMC,SAASC;IACvE,IAAI;QACFA,SAAS,MAAMR,WAAW;YAAEb,SAAAA;YAASsB,WAAW;QAAK,GAAGf,YAAYU,KAAKC,MAAMC,MAAMC;IACvF,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAWe,SAAS7B,mBAAmBuB,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAAoD,EAAEC,QAAqC;IAC7K,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIO,MAAM;QAC7C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAC9C,IAAI,OAAOL,SAAS,UAAU,MAAM,IAAIK,MAAM;QAE9C,IAAI,OAAOJ,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,IAAMK,WAAWC,IAAAA,qBAAY,EAAC;YAAEC,KAAKV;WAAQG,UAAW;QACxDA,UAAU;YAAEK,UAAAA;WAAaL;QAEzB,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAAShB,SAASiB,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIO,QAAQ,SAACC,SAASC;mBAAWd,SAAShB,SAASiB,KAAKC,MAAMC,MAAMC,SAAS,SAACG,KAAKQ;uBAAYR,MAAMO,OAAOP,OAAOM,QAAQE;;;IACpI,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport ensureBindings from './lib/ensureBindings';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return workerLazy()(src, dest, type, options, callback);\n try {\n callback(null, callLazy()({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types';\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: string, dest: string, type: string, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) => dispatch(version, src, dest, type, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["transformDirectory","major","process","versions","node","split","version","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","_require","require","Module","createRequire","callLazy","lazy","workerLazy","dispatch","src","dest","type","options","callback","callbacks","err","Error","tsconfig","loadTsConfig","cwd","Promise","resolve","reject","result"],"mappings":";;;;+BA0BA;;;;;;;CAOC,GACD;;;eAAwBA;;;2DAlCP;0DACD;mEAES;6DAON;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANjB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,IAAMM,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,Y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,MAAMO,OAAOP,OAAOM,QAAQE;;;IACpI,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
@@ -10,7 +10,7 @@ function _export(target, all) {
10
10
  }
11
11
  _export(exports, {
12
12
  default: function() {
13
- return _default;
13
+ return installBindings;
14
14
  },
15
15
  getDependencyInfo: function() {
16
16
  return getDependencyInfo;
@@ -23,7 +23,6 @@ var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
23
23
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
24
24
  var _installmodulelinked = /*#__PURE__*/ _interop_require_default(require("install-module-linked"));
25
25
  var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
26
- var _resolveoncemapcb = /*#__PURE__*/ _interop_require_default(require("resolve-once-map-cb"));
27
26
  function _interop_require_default(obj) {
28
27
  return obj && obj.__esModule ? obj : {
29
28
  default: obj
@@ -51,14 +50,12 @@ function isInstalled(target) {
51
50
  return false;
52
51
  }
53
52
  }
54
- var _default = (0, _resolveoncemapcb.default)(function installBindings(target, callback) {
55
- if (isInstalled(target)) return callback();
53
+ function installBindings(target, callback) {
56
54
  var _getDependencyInfo = getDependencyInfo(target), name = _getDependencyInfo.name, version = _getDependencyInfo.version, nodeModules = _getDependencyInfo.nodeModules;
57
55
  var installString = version ? "".concat(name, "@").concat(version) : name;
58
56
  (0, _installmodulelinked.default)(installString, nodeModules, function(err) {
59
- if (err) return callback(err);
60
- console.log("installed ".concat(_path.default.join(nodeModules, name)));
61
- callback();
57
+ console.log("installed ".concat(_path.default.join(nodeModules, name), " ").concat(!err ? 'successfully' : 'with errors: ${err.message}'));
58
+ callback(err);
62
59
  });
63
- });
60
+ }
64
61
  /* 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/workers/installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport installModule from 'install-module-linked';\nimport resolve from 'resolve';\nimport resolveOnceMap from 'resolve-once-map-cb';\n\nexport function getDependencyInfo(target) {\n const packagePath = resolve.sync('@swc/core/package.json');\n const nodeModules = path.dirname(path.dirname(path.dirname(packagePath)));\n const optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;\n const name = Object.keys(optionalDependencies).find((name) => name.indexOf(target) >= 0);\n return { name, version: optionalDependencies[name], nodeModules };\n}\n\nexport function isInstalled(target) {\n const { name, nodeModules } = getDependencyInfo(target);\n try {\n fs.statSync(path.join(nodeModules, name));\n return true;\n } catch (_err) {\n return false;\n }\n}\n\nexport default resolveOnceMap(function installBindings(target, callback) {\n if (isInstalled(target)) return callback();\n\n const { name, version, nodeModules } = getDependencyInfo(target);\n const installString = version ? `${name}@${version}` : name;\n\n installModule(installString, nodeModules, (err) => {\n if (err) return callback(err);\n console.log(`installed ${path.join(nodeModules, name)}`);\n callback();\n });\n});\n"],"names":["getDependencyInfo","isInstalled","target","packagePath","resolve","sync","nodeModules","path","dirname","optionalDependencies","JSON","parse","fs","readFileSync","name","Object","keys","find","indexOf","version","statSync","join","_err","resolveOnceMap","installBindings","callback","installString","installModule","err","console","log"],"mappings":";;;;;;;;;;;IAwBA,OAWG;eAXH;;IAlBgBA,iBAAiB;eAAjBA;;IAQAC,WAAW;eAAXA;;;yDAdD;2DACE;0EACS;8DACN;uEACO;;;;;;AAEpB,SAASD,kBAAkBE,MAAM;IACtC,IAAMC,cAAcC,gBAAO,CAACC,IAAI,CAAC;IACjC,IAAMC,cAAcC,aAAI,CAACC,OAAO,CAACD,aAAI,CAACC,OAAO,CAACD,aAAI,CAACC,OAAO,CAACL;IAC3D,IAAMM,uBAAuBC,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACV,aAAa,SAASM,oBAAoB;IAClG,IAAMK,OAAOC,OAAOC,IAAI,CAACP,sBAAsBQ,IAAI,CAAC,SAACH;eAASA,KAAKI,OAAO,CAAChB,WAAW;;IACtF,OAAO;QAAEY,MAAAA;QAAMK,SAASV,oBAAoB,CAACK,KAAK;QAAER,aAAAA;IAAY;AAClE;AAEO,SAASL,YAAYC,MAAM;IAChC,IAA8BF,qBAAAA,kBAAkBE,SAAxCY,OAAsBd,mBAAtBc,MAAMR,cAAgBN,mBAAhBM;IACd,IAAI;QACFM,WAAE,CAACQ,QAAQ,CAACb,aAAI,CAACc,IAAI,CAACf,aAAaQ;QACnC,OAAO;IACT,EAAE,OAAOQ,MAAM;QACb,OAAO;IACT;AACF;IAEA,WAAeC,IAAAA,yBAAc,EAAC,SAASC,gBAAgBtB,MAAM,EAAEuB,QAAQ;IACrE,IAAIxB,YAAYC,SAAS,OAAOuB;IAEhC,IAAuCzB,qBAAAA,kBAAkBE,SAAjDY,OAA+Bd,mBAA/Bc,MAAMK,UAAyBnB,mBAAzBmB,SAASb,cAAgBN,mBAAhBM;IACvB,IAAMoB,gBAAgBP,UAAU,AAAC,GAAUA,OAARL,MAAK,KAAW,OAARK,WAAYL;IAEvDa,IAAAA,4BAAa,EAACD,eAAepB,aAAa,SAACsB;QACzC,IAAIA,KAAK,OAAOH,SAASG;QACzBC,QAAQC,GAAG,CAAC,AAAC,aAAyC,OAA7BvB,aAAI,CAACc,IAAI,CAACf,aAAaQ;QAChDW;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport installModule from 'install-module-linked';\nimport resolve from 'resolve';\n\nexport function getDependencyInfo(target) {\n const packagePath = resolve.sync('@swc/core/package.json');\n const nodeModules = path.dirname(path.dirname(path.dirname(packagePath)));\n const optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;\n const name = Object.keys(optionalDependencies).find((name) => name.indexOf(target) >= 0);\n return { name, version: optionalDependencies[name], nodeModules };\n}\n\nexport function isInstalled(target) {\n const { name, nodeModules } = getDependencyInfo(target);\n try {\n fs.statSync(path.join(nodeModules, name));\n return true;\n } catch (_err) {\n return false;\n }\n}\n\nexport default function installBindings(target, callback) {\n const { name, version, nodeModules } = getDependencyInfo(target);\n const installString = version ? `${name}@${version}` : name;\n\n installModule(installString, nodeModules, (err) => {\n console.log(`installed ${path.join(nodeModules, name)} ${!err ? 'successfully' : 'with errors: ${err.message}'}`);\n callback(err);\n });\n}\n"],"names":["installBindings","getDependencyInfo","isInstalled","target","packagePath","resolve","sync","nodeModules","path","dirname","optionalDependencies","JSON","parse","fs","readFileSync","name","Object","keys","find","indexOf","version","statSync","join","_err","callback","installString","installModule","err","console","log"],"mappings":";;;;;;;;;;;IAuBA,OAQC;eARuBA;;IAlBRC,iBAAiB;eAAjBA;;IAQAC,WAAW;eAAXA;;;yDAbD;2DACE;0EACS;8DACN;;;;;;AAEb,SAASD,kBAAkBE,MAAM;IACtC,IAAMC,cAAcC,gBAAO,CAACC,IAAI,CAAC;IACjC,IAAMC,cAAcC,aAAI,CAACC,OAAO,CAACD,aAAI,CAACC,OAAO,CAACD,aAAI,CAACC,OAAO,CAACL;IAC3D,IAAMM,uBAAuBC,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACV,aAAa,SAASM,oBAAoB;IAClG,IAAMK,OAAOC,OAAOC,IAAI,CAACP,sBAAsBQ,IAAI,CAAC,SAACH;eAASA,KAAKI,OAAO,CAAChB,WAAW;;IACtF,OAAO;QAAEY,MAAAA;QAAMK,SAASV,oBAAoB,CAACK,KAAK;QAAER,aAAAA;IAAY;AAClE;AAEO,SAASL,YAAYC,MAAM;IAChC,IAA8BF,qBAAAA,kBAAkBE,SAAxCY,OAAsBd,mBAAtBc,MAAMR,cAAgBN,mBAAhBM;IACd,IAAI;QACFM,WAAE,CAACQ,QAAQ,CAACb,aAAI,CAACc,IAAI,CAACf,aAAaQ;QACnC,OAAO;IACT,EAAE,OAAOQ,MAAM;QACb,OAAO;IACT;AACF;AAEe,SAASvB,gBAAgBG,MAAM,EAAEqB,QAAQ;IACtD,IAAuCvB,qBAAAA,kBAAkBE,SAAjDY,OAA+Bd,mBAA/Bc,MAAMK,UAAyBnB,mBAAzBmB,SAASb,cAAgBN,mBAAhBM;IACvB,IAAMkB,gBAAgBL,UAAU,AAAC,GAAUA,OAARL,MAAK,KAAW,OAARK,WAAYL;IAEvDW,IAAAA,4BAAa,EAACD,eAAelB,aAAa,SAACoB;QACzCC,QAAQC,GAAG,CAAC,AAAC,aAA4C,OAAhCrB,aAAI,CAACc,IAAI,CAACf,aAAaQ,OAAM,KAAyD,OAAtD,CAACY,MAAM,iBAAiB;QACjFH,SAASG;IACX;AACF"}
@@ -14,7 +14,6 @@ var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
14
14
  var _rimraf2 = /*#__PURE__*/ _interop_require_default(require("rimraf2"));
15
15
  var _constants = require("../constants.cjs");
16
16
  var _createMatcher = /*#__PURE__*/ _interop_require_default(require("../createMatcher.cjs"));
17
- var _installBindings = /*#__PURE__*/ _interop_require_default(require("../lib/installBindings.cjs"));
18
17
  var _transformFile = /*#__PURE__*/ _interop_require_default(require("../lib/transformFile.cjs"));
19
18
  function _define_property(obj, key, value) {
20
19
  if (key in obj) {
@@ -73,47 +72,43 @@ function _object_spread_props(target, source) {
73
72
  }
74
73
  return target;
75
74
  }
76
- var target = "".concat(process.platform, "-").concat(process.arch);
77
75
  function transformDirectoryWorker(src, dest, type, options, callback) {
78
76
  var tsconfig = options.tsconfig;
79
77
  var matcher = (0, _createMatcher.default)(tsconfig);
80
- (0, _installBindings.default)(target, function(err) {
81
- if (err) return callback(err);
82
- (0, _rimraf2.default)(dest, {
83
- disableGlob: true
84
- }, function() {
85
- var entries = [];
86
- var iterator = new _fsiterator.default(src);
87
- iterator.forEach(function(entry) {
88
- if (!entry.stats.isFile()) return;
89
- if (entry.basename[0] === '.') return;
90
- if (_constants.typeFileRegEx.test(entry.basename)) return;
91
- if (!matcher(entry.fullPath)) return;
92
- var ext = _path.default.extname(entry.basename);
93
- if (ext && _constants.extensions.indexOf(ext) < 0) return;
94
- entries.push(entry);
95
- }, function(err) {
96
- if (err) return callback(err);
97
- var results = [];
98
- options = _object_spread_props(_object_spread({}, options), {
99
- tsconfig: tsconfig,
100
- src: src,
101
- dest: dest
102
- });
103
- var queue = new _queuecb.default();
104
- entries.forEach(function(entry) {
105
- queue.defer(function(cb) {
106
- return (0, _transformFile.default)(entry, dest, type, options, function(err, outPath) {
107
- if (err) return cb(err);
108
- results.push(_path.default.normalize(outPath));
109
- if (options.sourceMaps) results.push("".concat(_path.default.normalize(outPath), ".map"));
110
- cb();
111
- });
78
+ (0, _rimraf2.default)(dest, {
79
+ disableGlob: true
80
+ }, function() {
81
+ var entries = [];
82
+ var iterator = new _fsiterator.default(src);
83
+ iterator.forEach(function(entry) {
84
+ if (!entry.stats.isFile()) return;
85
+ if (entry.basename[0] === '.') return;
86
+ if (_constants.typeFileRegEx.test(entry.basename)) return;
87
+ if (!matcher(entry.fullPath)) return;
88
+ var ext = _path.default.extname(entry.basename);
89
+ if (ext && _constants.extensions.indexOf(ext) < 0) return;
90
+ entries.push(entry);
91
+ }, function(err) {
92
+ if (err) return callback(err);
93
+ var results = [];
94
+ options = _object_spread_props(_object_spread({}, options), {
95
+ tsconfig: tsconfig,
96
+ src: src,
97
+ dest: dest
98
+ });
99
+ var queue = new _queuecb.default();
100
+ entries.forEach(function(entry) {
101
+ queue.defer(function(cb) {
102
+ return (0, _transformFile.default)(entry, dest, type, options, function(err, outPath) {
103
+ if (err) return cb(err);
104
+ results.push(_path.default.normalize(outPath));
105
+ if (options.sourceMaps) results.push("".concat(_path.default.normalize(outPath), ".map"));
106
+ cb();
112
107
  });
113
108
  });
114
- queue.await(function(err) {
115
- return err ? callback(err) : callback(null, results);
116
- });
109
+ });
110
+ queue.await(function(err) {
111
+ return err ? callback(err) : callback(null, results);
117
112
  });
118
113
  });
119
114
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { extensions, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport installBindings from '../lib/installBindings';\nimport transformFile from '../lib/transformFile';\n\nconst target = `${process.platform}-${process.arch}`;\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n installBindings(target, (err) => {\n if (err) return callback(err);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n });\n}\n"],"names":["transformDirectoryWorker","target","process","platform","arch","src","dest","type","options","callback","tsconfig","matcher","createMatcher","installBindings","err","rimraf2","disableGlob","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","results","queue","Queue","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BAYA;;;eAAwBA;;;2D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sBAAa,EAAClB,OAAOf,MAAMC,MAAMC,SAAS,SAACM,KAAK0B;4BAC9C,IAAI1B,KAAK,OAAOwB,GAAGxB;4BACnBoB,QAAQD,IAAI,CAACJ,aAAI,CAACY,SAAS,CAACD;4BAC5B,IAAIhC,QAAQkC,UAAU,EAAER,QAAQD,IAAI,CAAC,AAAC,GAA0B,OAAxBJ,aAAI,CAACY,SAAS,CAACD,UAAS;4BAChEF;wBACF;;gBAEJ;gBACAH,MAAMQ,KAAK,CAAC,SAAC7B;2BAASA,MAAML,SAASK,OAAOL,SAAS,MAAMyB;;YAC7D;QAEJ;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { extensions, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport transformFile from '../lib/transformFile';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n}\n"],"names":["transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","createMatcher","rimraf2","disableGlob","entries","iterator","Iterator","forEach","entry","stats","isFile","basename","typeFileRegEx","test","fullPath","ext","path","extname","extensions","indexOf","push","err","results","queue","Queue","defer","cb","transformFile","outPath","normalize","sourceMaps","await"],"mappings":";;;;+BASA;;;eAAwBA;;;2DATP;iEACI;8DACH;8DACE;yBAEsB;oEAChB;oEACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEX,SAASA,yBAAyBC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACjF,IAAMC,WAAWF,QAAQE,QAAQ;IACjC,IAAMC,UAAUC,IAAAA,sBAAa,EAACF;IAE9BG,IAAAA,gBAAO,EAACP,MAAM;QAAEQ,aAAa;IAAK,GAAG;QACnC,IAAMC,UAAU,EAAE;QAClB,IAAMC,WAAW,IAAIC,mBAAQ,CAACZ;QAC9BW,SAASE,OAAO,CACd,SAACC;YACC,IAAI,CAACA,MAAMC,KAAK,CAACC,MAAM,IAAI;YAC3B,IAAIF,MAAMG,QAAQ,CAAC,EAAE,KAAK,KAAK;YAC/B,IAAIC,wBAAa,CAACC,IAAI,CAACL,MAAMG,QAAQ,GAAG;YACxC,IAAI,CAACX,QAAQQ,MAAMM,QAAQ,GAAG;YAC9B,IAAMC,MAAMC,aAAI,CAACC,OAAO,CAACT,MAAMG,QAAQ;YACvC,IAAII,OAAOG,qBAAU,CAACC,OAAO,CAACJ,OAAO,GAAG;YACxCX,QAAQgB,IAAI,CAACZ;QACf,GACA,SAACa;YACC,IAAIA,KAAK,OAAOvB,SAASuB;YACzB,IAAMC,UAAU,EAAE;YAClBzB,UAAU,wCAAKA;gBAASE,UAAAA;gBAAUL,KAAAA;gBAAKC,MAAAA;;YAEvC,IAAM4B,QAAQ,IAAIC,gBAAK;YACvBpB,QAAQG,OAAO,CAAC,SAACC;gBACfe,MAAME,KAAK,CAAC,SAACC;2BACXC,IAAAA,sBAAa,EAACnB,OAAOb,MAAMC,MAAMC,SAAS,SAACwB,KAAKO;wBAC9C,IAAIP,KAAK,OAAOK,GAAGL;wBACnBC,QAAQF,IAAI,CAACJ,aAAI,CAACa,SAAS,CAACD;wBAC5B,IAAI/B,QAAQiC,UAAU,EAAER,QAAQF,IAAI,CAAC,AAAC,GAA0B,OAAxBJ,aAAI,CAACa,SAAS,CAACD,UAAS;wBAChEF;oBACF;;YAEJ;YACAH,MAAMQ,KAAK,CAAC,SAACV;uBAASA,MAAMvB,SAASuB,OAAOvB,SAAS,MAAMwB;;QAC7D;IAEJ;AACF"}
@@ -8,8 +8,6 @@ Object.defineProperty(exports, "default", {
8
8
  return transformSyncWorker;
9
9
  }
10
10
  });
11
- var _lodashendswith = /*#__PURE__*/ _interop_require_default(require("lodash.endswith"));
12
- var _installBindings = require("../lib/installBindings.cjs");
13
11
  var _swcPrepareOptions = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.cjs"));
14
12
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
15
13
  var _lazycache = /*#__PURE__*/ _interop_require_default(require("lazy-cache"));
@@ -72,12 +70,10 @@ function _object_spread_props(target, source) {
72
70
  }
73
71
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
74
72
  var swcLazy = (0, _lazycache.default)(_require)('@swc/core');
75
- var target = "".concat(process.platform, "-").concat(process.arch);
76
73
  function transformSyncWorker(contents, fileName, tsconfig) {
77
- (0, _installBindings.sync)(target);
78
74
  var swcOptions = (0, _swcPrepareOptions.default)(tsconfig);
79
75
  var swc = swcLazy();
80
- return swc.transformSync(contents, _object_spread_props(_object_spread({}, (0, _lodashendswith.default)(fileName, '.tsx') || (0, _lodashendswith.default)(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
76
+ return swc.transformSync(contents, _object_spread_props(_object_spread({}, fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
81
77
  filename: fileName
82
78
  }));
83
79
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import endsWith from 'lodash.endswith';\nimport { sync as installBindingsSync } from '../lib/installBindings';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\nconst target = `${process.platform}-${process.arch}`;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n installBindingsSync(target);\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(endsWith(fileName, '.tsx') || endsWith(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","swcLazy","lazy","target","process","platform","arch","contents","fileName","tsconfig","installBindingsSync","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAWA;;;eAAwBA;;;qEAXH;+BACuB;wEACd;6DAEX;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,UAAUC,IAAAA,kBAAI,EAACL,UAAU;AAC/B,IAAMM,SAAS,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI;AAGnC,SAASV,oBAAoBW,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtGC,IAAAA,qBAAmB,EAACP;IAEpB,IAAMQ,aAAaC,IAAAA,0BAAiB,EAACH;IACrC,IAAMI,MAAMZ;IACZ,OAAOY,IAAIC,aAAa,CAACP,UAAU,wCAC7BQ,IAAAA,uBAAQ,EAACP,UAAU,WAAWO,IAAAA,uBAAQ,EAACP,UAAU,UAAUG,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC/GC,UAAUV;;AAEd"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["transformSyncWorker","_require","require","Module","createRequire","swcLazy","lazy","contents","fileName","tsconfig","swcOptions","swcPrepareOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":";;;;+BAQA;;;eAAwBA;;;wEARM;6DAEX;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACjB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,UAAUC,IAAAA,kBAAI,EAACL,UAAU;AAGhB,SAASD,oBAAoBO,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,IAAMC,aAAaC,IAAAA,0BAAiB,EAACF;IACrC,IAAMG,MAAMP;IACZ,OAAOO,IAAIC,aAAa,CAACN,UAAU,wCAC7BC,SAASM,QAAQ,CAAC,WAAWN,SAASM,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QAC7GC,UAAUT;;AAEd"}
@@ -1,4 +1,3 @@
1
- import endsWith from 'lodash.endswith';
2
1
  import minimatch from 'minimatch';
3
2
  import path from 'path-posix';
4
3
  import unixify from 'unixify';
@@ -18,7 +17,7 @@ export default function createMatcher(tsConfig) {
18
17
  const includes = (tsconfig.config.include || []).map(matchFn);
19
18
  const excludes = (tsconfig.config.exclude || []).map(matchFn);
20
19
  return function matcher(filePath) {
21
- if (endsWith(filePath, '.json')) return false;
20
+ if (filePath.endsWith('.json')) return false;
22
21
  filePath = unixify(filePath);
23
22
  for(let i = 0; i < excludes.length; ++i){
24
23
  if (excludes[i](filePath)) return false;
@@ -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 endsWith from 'lodash.endswith';\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 (endsWith(filePath, '.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":["endsWith","minimatch","path","unixify","loadTsConfig","createMatcher","tsConfig","tsconfig","tsconfigPath","dirname","matchFn","condition","pattern","isAbsolute","startsWith","join","match","filePath","includes","config","include","map","excludes","exclude","matcher","i","length","j"],"mappings":"AACA,OAAOA,cAAc,kBAAkB;AACvC,OAAOC,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,IAAIjB,SAASiB,UAAU,UAAU,OAAO;QAExCA,WAAWd,QAAQc;QACnB,IAAK,IAAIQ,IAAI,GAAGA,IAAIH,SAASI,MAAM,EAAE,EAAED,EAAG;YACxC,IAAIH,QAAQ,CAACG,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"}
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,5 +1,5 @@
1
+ import resolveOnceMap from 'resolve-once-map-cb';
1
2
  import installBindings, { isInstalled } from '../workers/installBindings.mjs';
2
- export default installBindings;
3
3
  import path from 'path';
4
4
  import url from 'url';
5
5
  import Module from 'module';
@@ -17,3 +17,6 @@ const install = lazy((target)=>{
17
17
  }, workerPath, target);
18
18
  });
19
19
  export const sync = (target)=>install(target)();
20
+ export default resolveOnceMap((target, callback)=>{
21
+ return isInstalled(target) ? callback() : installBindings(target, callback);
22
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/ensureBindings.ts"],"sourcesContent":["import resolveOnceMap from 'resolve-once-map-cb';\nimport installBindings, { isInstalled } from '../workers/installBindings';\n\nimport path from 'path';\nimport url from 'url';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', '..', 'cjs', 'workers', 'installBindings.cjs');\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\n\nconst callLazy = lazy(_require)('node-version-call');\nconst install = lazy((target) => {\n return isInstalled(target) ? target : callLazy()({ version, callbacks: true }, workerPath, target);\n});\n\nexport const sync = (target) => install(target)();\nexport default resolveOnceMap((target, callback) => {\n return isInstalled(target) ? callback() : installBindings(target, callback);\n});\n"],"names":["resolveOnceMap","installBindings","isInstalled","path","url","Module","lazy","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","major","process","versions","node","split","version","callLazy","install","target","callbacks","sync","callback"],"mappings":"AAAA,OAAOA,oBAAoB,sBAAsB;AACjD,OAAOC,mBAAmBC,WAAW,QAAQ,6BAA6B;AAE1E,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYL,GAAG,IAAII;AAC1F,MAAME,YAAYP,KAAKQ,OAAO,CAAC,OAAOC,eAAe,cAAcR,IAAIS,aAAa,CAAC,YAAYT,GAAG,IAAIQ;AACxG,MAAME,aAAaX,KAAKY,IAAI,CAACL,WAAW,MAAM,MAAM,OAAO,WAAW;AACtE,MAAMM,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AAExC,MAAMM,WAAWhB,KAAKC,UAAU;AAChC,MAAMgB,UAAUjB,KAAK,CAACkB;IACpB,OAAOtB,YAAYsB,UAAUA,SAASF,WAAW;QAAED;QAASI,WAAW;IAAK,GAAGX,YAAYU;AAC7F;AAEA,OAAO,MAAME,OAAO,CAACF,SAAWD,QAAQC,UAAU;AAClD,eAAexB,eAAe,CAACwB,QAAQG;IACrC,OAAOzB,YAAYsB,UAAUG,aAAa1B,gBAAgBuB,QAAQG;AACpE,GAAG"}
@@ -1,4 +1,5 @@
1
1
  import path from 'path';
2
+ import { sync as ensureBindings } from './ensureBindings.mjs';
2
3
  import Module from 'module';
3
4
  import lazy from 'lazy-cache';
4
5
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
@@ -6,6 +7,7 @@ const tsLazy = lazy(_require)('typescript');
6
7
  const swcLazy = lazy(_require)('@swc/core');
7
8
  const transpilerLazy = lazy(_require)('ts-node/transpilers/swc');
8
9
  export default function swcPrepareOptions(tsconfig) {
10
+ ensureBindings(`${process.platform}-${process.arch}`);
9
11
  try {
10
12
  const ts = tsLazy();
11
13
  const swc = swcLazy();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["path","Module","lazy","_require","require","createRequire","url","tsLazy","swcLazy","transpilerLazy","swcPrepareOptions","tsconfig","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AAExB,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,SAASL,KAAKC,UAAU;AAC9B,MAAMK,UAAUN,KAAKC,UAAU;AAC/B,MAAMM,iBAAiBP,KAAKC,UAAU;AAItC,eAAe,SAASO,kBAAkBC,QAAwB;IAChE,IAAI;QACF,MAAMC,KAAKL;QACX,MAAMM,MAAML;QACZ,MAAMM,aAAaL;QACnB,MAAMM,SAASH,GAAGI,0BAA0B,CAACL,SAASM,MAAM,EAAEL,GAAGM,GAAG,EAAElB,KAAKmB,OAAO,CAACR,SAASX,IAAI;QAChG,OAAOc,WAAWM,gBAAgB,CAACL,OAAOM,OAAO,EAAEC,WAAWT,KAAK;IACrE,EAAE,OAAOU,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport { sync as ensureBindings } from './ensureBindings';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst tsLazy = lazy(_require)('typescript');\nconst swcLazy = lazy(_require)('@swc/core');\nconst transpilerLazy = lazy(_require)('ts-node/transpilers/swc');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\n\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n ensureBindings(`${process.platform}-${process.arch}`);\n try {\n const ts = tsLazy();\n const swc = swcLazy();\n const transpiler = transpilerLazy();\n const parsed = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, path.dirname(tsconfig.path));\n return transpiler.createSwcOptions(parsed.options, undefined, swc, 'swc');\n } catch (err) {\n console.log(`swcPrepareOptions failed: ${err.message}`);\n return {};\n }\n}\n"],"names":["path","sync","ensureBindings","Module","lazy","_require","require","createRequire","url","tsLazy","swcLazy","transpilerLazy","swcPrepareOptions","tsconfig","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,SAASC,QAAQC,cAAc,QAAQ,mBAAmB;AAE1D,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,SAASL,KAAKC,UAAU;AAC9B,MAAMK,UAAUN,KAAKC,UAAU;AAC/B,MAAMM,iBAAiBP,KAAKC,UAAU;AAItC,eAAe,SAASO,kBAAkBC,QAAwB;IAChEX,eAAe,GAAGY,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE;IACpD,IAAI;QACF,MAAMC,KAAKR;QACX,MAAMS,MAAMR;QACZ,MAAMS,aAAaR;QACnB,MAAMS,SAASH,GAAGI,0BAA0B,CAACR,SAASS,MAAM,EAAEL,GAAGM,GAAG,EAAEvB,KAAKwB,OAAO,CAACX,SAASb,IAAI;QAChG,OAAOmB,WAAWM,gBAAgB,CAACL,OAAOM,OAAO,EAAEC,WAAWT,KAAK;IACrE,EAAE,OAAOU,KAAK;QACZC,QAAQC,GAAG,CAAC,CAAC,0BAA0B,EAAEF,IAAIG,OAAO,EAAE;QACtD,OAAO,CAAC;IACV;AACF"}
@@ -1,8 +1,8 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import endsWith from 'lodash.endswith';
4
3
  import mkdirp from 'mkdirp-classic';
5
4
  import Queue from 'queue-cb';
5
+ import ensureBindings from './ensureBindings.mjs';
6
6
  import patchCJS from '../lib/patchCJS.mjs';
7
7
  import patchESM from '../lib/patchESM.mjs';
8
8
  import swcPrepareOptions from '../lib/swcPrepareOptions.mjs';
@@ -11,35 +11,38 @@ import lazy from 'lazy-cache';
11
11
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
12
12
  const swcLazy = lazy(_require)('@swc/core');
13
13
  export default function transformFile(entry, dest, type, options, callback) {
14
- let tsconfig = options.tsconfig;
15
- // overrides for cjs
16
- if (type === 'cjs') {
17
- tsconfig = {
18
- ...tsconfig
19
- };
20
- tsconfig.config = {
21
- ...tsconfig.config
22
- };
23
- tsconfig.config.compilerOptions = {
24
- ...tsconfig.config.compilerOptions || {}
25
- };
26
- tsconfig.config.compilerOptions.module = 'CommonJS';
27
- tsconfig.config.compilerOptions.target = 'ES5';
28
- }
29
- const swcOptions = swcPrepareOptions(tsconfig);
30
- const swc = swcLazy();
31
- swc.transformFile(entry.fullPath, {
32
- ...endsWith(entry.basename, '.tsx') || endsWith(entry.basename, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
33
- filename: entry.basename
34
- }).then((output)=>{
35
- const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);
36
- const ext = path.extname(entry.path);
37
- const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
38
- mkdirp(path.dirname(outPath), ()=>{
39
- const queue = new Queue();
40
- queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
41
- !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));
42
- queue.await((err)=>err ? callback(err) : callback(null, outPath));
43
- });
44
- }).catch(callback);
14
+ ensureBindings(`${process.platform}-${process.arch}`, (err)=>{
15
+ if (err) return callback(err);
16
+ let tsconfig = options.tsconfig;
17
+ // overrides for cjs
18
+ if (type === 'cjs') {
19
+ tsconfig = {
20
+ ...tsconfig
21
+ };
22
+ tsconfig.config = {
23
+ ...tsconfig.config
24
+ };
25
+ tsconfig.config.compilerOptions = {
26
+ ...tsconfig.config.compilerOptions || {}
27
+ };
28
+ tsconfig.config.compilerOptions.module = 'CommonJS';
29
+ tsconfig.config.compilerOptions.target = 'ES5';
30
+ }
31
+ const swcOptions = swcPrepareOptions(tsconfig);
32
+ const swc = swcLazy();
33
+ swc.transformFile(entry.fullPath, {
34
+ ...entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
35
+ filename: entry.basename
36
+ }).then((output)=>{
37
+ const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);
38
+ const ext = path.extname(entry.path);
39
+ const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
40
+ mkdirp(path.dirname(outPath), ()=>{
41
+ const queue = new Queue();
42
+ queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
43
+ !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));
44
+ queue.await((err)=>err ? callback(err) : callback(null, outPath));
45
+ });
46
+ }).catch(callback);
47
+ });
45
48
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport endsWith from 'lodash.endswith';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nexport default function transformFile(entry, dest, type, options, callback) {\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 = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n\n swc\n .transformFile(entry.fullPath, {\n ...(endsWith(entry.basename, '.tsx') || endsWith(entry.basename, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((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 !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","path","endsWith","mkdirp","Queue","patchCJS","patchESM","swcPrepareOptions","Module","lazy","_require","require","createRequire","url","swcLazy","transformFile","entry","dest","type","options","callback","tsconfig","config","compilerOptions","module","target","swcOptions","swc","fullPath","basename","tsxOptions","nonTsxOptions","filename","then","output","extTarget","ext","extname","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","sourceMaps","map","await","err","catch"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAA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IAAI,CAACuC,KAAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAIzB,MAAMf,IAAI,AAAD,IAAKkC;QAExFhC,OAAOF,KAAKyC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAIvC;YAClBuC,MAAMC,KAAK,CAAC5C,GAAG6C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;YAC1D,CAAC5B,QAAQ6B,UAAU,IAAIL,MAAMC,KAAK,CAAC5C,GAAG6C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEJ,OAAOe,GAAG,EAAE;YACzFN,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAM/B,SAAS+B,OAAO/B,SAAS,MAAMkB;QAC7D;IACF,GACCc,KAAK,CAAChC;AACX"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/transformFile.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport mkdirp from 'mkdirp-classic';\nimport Queue from 'queue-cb';\nimport ensureBindings from './ensureBindings';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nexport default function transformFile(entry, dest, type, options, callback) {\n ensureBindings(`${process.platform}-${process.arch}`, (err) => {\n if (err) return callback(err);\n\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 = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n\n swc\n .transformFile(entry.fullPath, {\n ...(entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: entry.basename,\n })\n .then((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 !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}\n"],"names":["fs","path","mkdirp","Queue","ensureBindings","patchCJS","patchESM","swcPrepareOptions","Module","lazy","_require","require","createRequire","url","swcLazy","transformFile","entry","dest","type","options","callback","process","platform","arch","err","tsconfig","config","compilerOptions","module","target","swcOptions","swc","fullPath","basename","endsWith","tsxOptions","nonTsxOptions","filename","then","output","extTarget","ext","extname","outPath","join","slice","length","dirname","queue","defer","writeFile","bind","code","sourceMaps","map","await","catch"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,YAAY,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAC7B,OAAOC,oBAAoB,mBAAmB;AAE9C,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,cAAc,kBAAkB;AACvC,OAAOC,uBAAuB,2BAA2B;AAEzD,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,UAAUL,KAAKC,UAAU;AAE/B,eAAe,SAASK,cAAcC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAA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AAGkD,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;gBAC1D,CAACjC,QAAQkC,UAAU,IAAIL,MAAMC,KAAK,CAACjD,GAAGkD,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEJ,OAAOe,GAAG,EAAE;gBACzFN,MAAMO,KAAK,CAAC,CAAC/B,MAASA,MAAMJ,SAASI,OAAOJ,SAAS,MAAMuB;YAC7D;QACF,GACCa,KAAK,CAACpC;IACX;AACF"}
@@ -1,6 +1,5 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import endsWith from 'lodash.endswith';
4
3
  import { extensions, moduleRegEx, typeFileRegEx } from './constants.mjs';
5
4
  import toPath from './toPath.mjs';
6
5
  const indexExtensions = extensions.map((x)=>`index${x}`);
@@ -11,7 +10,7 @@ export default function resolveFileSync(specifier, context) {
11
10
  stat = fs.statSync(filePath);
12
11
  } catch (_err) {}
13
12
  try {
14
- if (stat && stat.isDirectory() || endsWith(specifier, '/')) {
13
+ if (stat && stat.isDirectory() || specifier.endsWith('/')) {
15
14
  const items = fs.readdirSync(filePath);
16
15
  const item = items.find((x)=>indexExtensions.indexOf(x) >= 0);
17
16
  if (item) return path.join(filePath, item);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport endsWith from 'lodash.endswith';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || endsWith(specifier, '/')) {\n const items = fs.readdirSync(filePath);\n const item = items.find((x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = items.find((x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","path","endsWith","extensions","moduleRegEx","typeFileRegEx","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","items","readdirSync","item","find","indexOf","join","test","ext","extname","basename","slice","length","dirname","extTest","basenameTest"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,cAAc,kBAAkB;AACvC,SAASC,UAAU,EAAEC,WAAW,EAAEC,aAAa,QAAQ,cAAc;AACrE,OAAOC,YAAY,WAAW;AAG9B,MAAMC,kBAAkBJ,WAAWK,GAAG,CAAC,CAACC,IAAM,CAAC,KAAK,EAAEA,GAAG;AAEzD,eAAe,SAASC,gBAAgBC,SAAiB,EAAEC,OAAiB;IAC1E,MAAMC,WAAWP,OAAOK,WAAWC;IACnC,IAAIE;IACJ,IAAI;QACFA,OAAOd,GAAGe,QAAQ,CAACF;IACrB,EAAE,OAAOG,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACF,QAAQA,KAAKG,WAAW,MAAOf,SAASS,WAAW,MAAM;YAC5D,MAAMO,QAAQlB,GAAGmB,WAAW,CAACN;YAC7B,MAAMO,OAAOF,MAAMG,IAAI,CAAC,CAACZ,IAAMF,gBAAgBe,OAAO,CAACb,MAAM;YAC7D,IAAIW,MAAM,OAAOnB,KAAKsB,IAAI,CAACV,UAAUO;QACvC,OAAO,IAAI,CAACN,QAAQ,CAACV,YAAYoB,IAAI,CAACb,YAAY;YAChD,MAAMc,MAAMxB,KAAKyB,OAAO,CAACb;YACzB,MAAMc,WAAWF,MAAMxB,KAAK0B,QAAQ,CAACd,UAAUe,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAI5B,KAAK0B,QAAQ,CAACd;YACrF,MAAMK,QAAQlB,GAAGmB,WAAW,CAAClB,KAAK6B,OAAO,CAACjB;YAC1C,MAAMO,OAAOF,MAAMG,IAAI,CAAC,CAACZ;gBACvB,IAAIJ,cAAcmB,IAAI,CAACf,IAAI,OAAO;gBAClC,MAAMsB,UAAU9B,KAAKyB,OAAO,CAACjB;gBAC7B,MAAMuB,eAAeD,UAAU9B,KAAK0B,QAAQ,CAAClB,GAAGmB,KAAK,CAAC,GAAG,CAACG,QAAQF,MAAM,IAAI5B,KAAK0B,QAAQ,CAAClB;gBAC1F,OAAOkB,aAAaK;YACtB;YACA,IAAIZ,MAAM,OAAOnB,KAAKsB,IAAI,CAACtB,KAAK6B,OAAO,CAACjB,WAAWO;QACrD;QACA,wBAAwB;QACxB,OAAON,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/resolveFileSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { extensions, moduleRegEx, typeFileRegEx } from './constants';\nimport toPath from './toPath';\nimport type { Context } from './types';\n\nconst indexExtensions = extensions.map((x) => `index${x}`);\n\nexport default function resolveFileSync(specifier: string, context?: Context) {\n const filePath = toPath(specifier, context);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(filePath);\n } catch (_err) {}\n try {\n if ((stat && stat.isDirectory()) || specifier.endsWith('/')) {\n const items = fs.readdirSync(filePath);\n const item = items.find((x) => indexExtensions.indexOf(x) >= 0);\n if (item) return path.join(filePath, item);\n } else if (!stat && !moduleRegEx.test(specifier)) {\n const ext = path.extname(filePath);\n const basename = ext ? path.basename(filePath).slice(0, -ext.length) : path.basename(filePath);\n const items = fs.readdirSync(path.dirname(filePath));\n const item = items.find((x) => {\n if (typeFileRegEx.test(x)) return false;\n const extTest = path.extname(x);\n const basenameTest = extTest ? path.basename(x).slice(0, -extTest.length) : path.basename(x);\n return basename === basenameTest;\n });\n if (item) return path.join(path.dirname(filePath), item);\n }\n // return what was found\n return stat ? filePath : null;\n } catch (_err) {\n return null;\n }\n}\n"],"names":["fs","path","extensions","moduleRegEx","typeFileRegEx","toPath","indexExtensions","map","x","resolveFileSync","specifier","context","filePath","stat","statSync","_err","isDirectory","endsWith","items","readdirSync","item","find","indexOf","join","test","ext","extname","basename","slice","length","dirname","extTest","basenameTest"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,UAAU,EAAEC,WAAW,EAAEC,aAAa,QAAQ,cAAc;AACrE,OAAOC,YAAY,WAAW;AAG9B,MAAMC,kBAAkBJ,WAAWK,GAAG,CAAC,CAACC,IAAM,CAAC,KAAK,EAAEA,GAAG;AAEzD,eAAe,SAASC,gBAAgBC,SAAiB,EAAEC,OAAiB;IAC1E,MAAMC,WAAWP,OAAOK,WAAWC;IACnC,IAAIE;IACJ,IAAI;QACFA,OAAOb,GAAGc,QAAQ,CAACF;IACrB,EAAE,OAAOG,MAAM,CAAC;IAChB,IAAI;QACF,IAAI,AAACF,QAAQA,KAAKG,WAAW,MAAON,UAAUO,QAAQ,CAAC,MAAM;YAC3D,MAAMC,QAAQlB,GAAGmB,WAAW,CAACP;YAC7B,MAAMQ,OAAOF,MAAMG,IAAI,CAAC,CAACb,IAAMF,gBAAgBgB,OAAO,CAACd,MAAM;YAC7D,IAAIY,MAAM,OAAOnB,KAAKsB,IAAI,CAACX,UAAUQ;QACvC,OAAO,IAAI,CAACP,QAAQ,CAACV,YAAYqB,IAAI,CAACd,YAAY;YAChD,MAAMe,MAAMxB,KAAKyB,OAAO,CAACd;YACzB,MAAMe,WAAWF,MAAMxB,KAAK0B,QAAQ,CAACf,UAAUgB,KAAK,CAAC,GAAG,CAACH,IAAII,MAAM,IAAI5B,KAAK0B,QAAQ,CAACf;YACrF,MAAMM,QAAQlB,GAAGmB,WAAW,CAAClB,KAAK6B,OAAO,CAAClB;YAC1C,MAAMQ,OAAOF,MAAMG,IAAI,CAAC,CAACb;gBACvB,IAAIJ,cAAcoB,IAAI,CAAChB,IAAI,OAAO;gBAClC,MAAMuB,UAAU9B,KAAKyB,OAAO,CAAClB;gBAC7B,MAAMwB,eAAeD,UAAU9B,KAAK0B,QAAQ,CAACnB,GAAGoB,KAAK,CAAC,GAAG,CAACG,QAAQF,MAAM,IAAI5B,KAAK0B,QAAQ,CAACnB;gBAC1F,OAAOmB,aAAaK;YACtB;YACA,IAAIZ,MAAM,OAAOnB,KAAKsB,IAAI,CAACtB,KAAK6B,OAAO,CAAClB,WAAWQ;QACrD;QACA,wBAAwB;QACxB,OAAOP,OAAOD,WAAW;IAC3B,EAAE,OAAOG,MAAM;QACb,OAAO;IACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return workerLazy()(src, dest, type, options, callback);\n try {\n callback(null, callLazy()({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types';\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: string, dest: string, type: string, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback);\n return new Promise((resolve, reject) => dispatch(version, src, dest, type, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","lazy","_require","require","createRequire","callLazy","workerLazy","dispatch","src","dest","type","options","callback","callbacks","err","transformDirectory","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AACtB,OAAOC,kBAAkB,iBAAiB;AAE1C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAA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AWd,SAASd,SAASe,KAAKC,MAAMC,MAAMC,SAAS,CAACG,KAAKQ,SAAYR,MAAMO,OAAOP,OAAOM,QAAQE;IACpI,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport url from 'url';\nimport ensureBindings from './lib/ensureBindings';\nimport loadTsConfig from './loadTsConfig';\n\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', 'cjs', 'workers', 'transformDirectory.cjs');\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst callLazy = lazy(_require)('node-version-call');\nconst workerLazy = lazy(_require)(workerPath);\n\nfunction dispatch(version, src, dest, type, options, callback) {\n if (version === 'local') return workerLazy()(src, dest, type, options, callback);\n try {\n callback(null, callLazy()({ version, callbacks: true }, workerPath, src, dest, type, options));\n } catch (err) {\n callback(err);\n }\n}\n\nimport type { ConfigOptions, TransformDirectoryCallback } from './types';\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: string, dest: string, type: string, options?: ConfigOptions | TransformDirectoryCallback, callback?: TransformDirectoryCallback): undefined | Promise<string[]> {\n try {\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 if (typeof options === 'function') {\n callback = options as TransformDirectoryCallback;\n options = null;\n }\n options = options || {};\n const tsconfig = loadTsConfig({ cwd: src, ...options }, 'transformDirectory');\n options = { tsconfig, ...options };\n\n if (typeof callback === 'function') return dispatch(version, src, dest, type, options, callback) as undefined;\n return new Promise((resolve, reject) => dispatch(version, src, dest, type, options, (err, result) => (err ? reject(err) : resolve(result))));\n } catch (err) {\n if (callback) callback(err);\n else return Promise.reject(err);\n }\n}\n"],"names":["path","url","loadTsConfig","major","process","versions","node","split","version","__dirname","dirname","__filename","fileURLToPath","workerPath","join","Module","lazy","_require","require","createRequire","callLazy","workerLazy","dispatch","src","dest","type","options","callback","callbacks","err","transformDirectory","Error","tsconfig","cwd","Promise","resolve","reject","result"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,OAAOC,kBAAkB,iBAAiB;AAE1C,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AACxC,MAAMM,YAAYT,KAAKU,OAAO,CAAC,OAAOC,eAAe,cAAcV,IAAIW,aAAa,CAAC,YAAYX,GAAG,IAAIU;AACxG,MAAME,aAAab,KAAKc,IAAI,CAACL,WAAW,MAAM,OAAO,WAAW;AAEhE,OAAOM,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYlB,GAAG,IAAIiB;AAC1F,MAAME,WAAWJ,KAAKC,UAAU;AAChC,MAAMI,aAAaL,KAAKC,UAAUJ;AAElC,SAASS,SAASd,OAAO,EAAEe,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC3D,IAAInB,YAAY,SAAS,OAAOa,aAAaE,KAAKC,MAAMC,MAAMC,SAASC;IACvE,IAAI;QACFA,SAAS,MAAMP,WAAW;YAAEZ;YAASoB,WAAW;QAAK,GAAGf,YAAYU,KAAKC,MAAMC,MAAMC;IACvF,EAAE,OAAOG,KAAK;QACZF,SAASE;IACX;AACF;AAGA;;;;;;;CAOC,GACD,eAAe,SAASC,mBAAmBP,GAAW,EAAEC,IAAY,EAAEC,IAAY,EAAEC,OAAoD,EAAEC,QAAqC;IAC7K,IAAI;QACF,IAAI,OAAOJ,QAAQ,UAAU,MAAM,IAAIQ,MAAM;QAC7C,IAAI,OAAOP,SAAS,UAAU,MAAM,IAAIO,MAAM;QAC9C,IAAI,OAAON,SAAS,UAAU,MAAM,IAAIM,MAAM;QAE9C,IAAI,OAAOL,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACAA,UAAUA,WAAW,CAAC;QACtB,MAAMM,WAAW9B,aAAa;YAAE+B,KAAKV;YAAK,GAAGG,OAAO;QAAC,GAAG;QACxDA,UAAU;YAAEM;YAAU,GAAGN,OAAO;QAAC;QAEjC,IAAI,OAAOC,aAAa,YAAY,OAAOL,SAASd,SAASe,KAAKC,MAAMC,MAAMC,SAASC;QACvF,OAAO,IAAIO,QAAQ,CAACC,SAASC,SAAWd,SAASd,SAASe,KAAKC,MAAMC,MAAMC,SAAS,CAACG,KAAKQ,SAAYR,MAAMO,OAAOP,OAAOM,QAAQE;IACpI,EAAE,OAAOR,KAAK;QACZ,IAAIF,UAAUA,SAASE;aAClB,OAAOK,QAAQE,MAAM,CAACP;IAC7B;AACF"}
@@ -2,7 +2,6 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import installModule from 'install-module-linked';
4
4
  import resolve from 'resolve';
5
- import resolveOnceMap from 'resolve-once-map-cb';
6
5
  export function getDependencyInfo(target) {
7
6
  const packagePath = resolve.sync('@swc/core/package.json');
8
7
  const nodeModules = path.dirname(path.dirname(path.dirname(packagePath)));
@@ -23,13 +22,11 @@ export function isInstalled(target) {
23
22
  return false;
24
23
  }
25
24
  }
26
- export default resolveOnceMap(function installBindings(target, callback) {
27
- if (isInstalled(target)) return callback();
25
+ export default function installBindings(target, callback) {
28
26
  const { name, version, nodeModules } = getDependencyInfo(target);
29
27
  const installString = version ? `${name}@${version}` : name;
30
28
  installModule(installString, nodeModules, (err)=>{
31
- if (err) return callback(err);
32
- console.log(`installed ${path.join(nodeModules, name)}`);
33
- callback();
29
+ console.log(`installed ${path.join(nodeModules, name)} ${!err ? 'successfully' : 'with errors: ${err.message}'}`);
30
+ callback(err);
34
31
  });
35
- });
32
+ }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport installModule from 'install-module-linked';\nimport resolve from 'resolve';\nimport resolveOnceMap from 'resolve-once-map-cb';\n\nexport function getDependencyInfo(target) {\n const packagePath = resolve.sync('@swc/core/package.json');\n const nodeModules = path.dirname(path.dirname(path.dirname(packagePath)));\n const optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;\n const name = Object.keys(optionalDependencies).find((name) => name.indexOf(target) >= 0);\n return { name, version: optionalDependencies[name], nodeModules };\n}\n\nexport function isInstalled(target) {\n const { name, nodeModules } = getDependencyInfo(target);\n try {\n fs.statSync(path.join(nodeModules, name));\n return true;\n } catch (_err) {\n return false;\n }\n}\n\nexport default resolveOnceMap(function installBindings(target, callback) {\n if (isInstalled(target)) return callback();\n\n const { name, version, nodeModules } = getDependencyInfo(target);\n const installString = version ? `${name}@${version}` : name;\n\n installModule(installString, nodeModules, (err) => {\n if (err) return callback(err);\n console.log(`installed ${path.join(nodeModules, name)}`);\n callback();\n });\n});\n"],"names":["fs","path","installModule","resolve","resolveOnceMap","getDependencyInfo","target","packagePath","sync","nodeModules","dirname","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf","version","isInstalled","statSync","join","_err","installBindings","callback","installString","err","console","log"],"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-swc-transform/src/workers/installBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport installModule from 'install-module-linked';\nimport resolve from 'resolve';\n\nexport function getDependencyInfo(target) {\n const packagePath = resolve.sync('@swc/core/package.json');\n const nodeModules = path.dirname(path.dirname(path.dirname(packagePath)));\n const optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;\n const name = Object.keys(optionalDependencies).find((name) => name.indexOf(target) >= 0);\n return { name, version: optionalDependencies[name], nodeModules };\n}\n\nexport function isInstalled(target) {\n const { name, nodeModules } = getDependencyInfo(target);\n try {\n fs.statSync(path.join(nodeModules, name));\n return true;\n } catch (_err) {\n return false;\n }\n}\n\nexport default function installBindings(target, callback) {\n const { name, version, nodeModules } = getDependencyInfo(target);\n const installString = version ? `${name}@${version}` : name;\n\n installModule(installString, nodeModules, (err) => {\n console.log(`installed ${path.join(nodeModules, name)} ${!err ? 'successfully' : 'with errors: ${err.message}'}`);\n callback(err);\n });\n}\n"],"names":["fs","path","installModule","resolve","getDependencyInfo","target","packagePath","sync","nodeModules","dirname","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf","version","isInstalled","statSync","join","_err","installBindings","callback","installString","err","console","log"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,mBAAmB,wBAAwB;AAClD,OAAOC,aAAa,UAAU;AAE9B,OAAO,SAASC,kBAAkBC,MAAM;IACtC,MAAMC,cAAcH,QAAQI,IAAI,CAAC;IACjC,MAAMC,cAAcP,KAAKQ,OAAO,CAACR,KAAKQ,OAAO,CAACR,KAAKQ,OAAO,CAACH;IAC3D,MAAMI,uBAAuBC,KAAKC,KAAK,CAACZ,GAAGa,YAAY,CAACP,aAAa,SAASI,oBAAoB;IAClG,MAAMI,OAAOC,OAAOC,IAAI,CAACN,sBAAsBO,IAAI,CAAC,CAACH,OAASA,KAAKI,OAAO,CAACb,WAAW;IACtF,OAAO;QAAES;QAAMK,SAAST,oBAAoB,CAACI,KAAK;QAAEN;IAAY;AAClE;AAEA,OAAO,SAASY,YAAYf,MAAM;IAChC,MAAM,EAAES,IAAI,EAAEN,WAAW,EAAE,GAAGJ,kBAAkBC;IAChD,IAAI;QACFL,GAAGqB,QAAQ,CAACpB,KAAKqB,IAAI,CAACd,aAAaM;QACnC,OAAO;IACT,EAAE,OAAOS,MAAM;QACb,OAAO;IACT;AACF;AAEA,eAAe,SAASC,gBAAgBnB,MAAM,EAAEoB,QAAQ;IACtD,MAAM,EAAEX,IAAI,EAAEK,OAAO,EAAEX,WAAW,EAAE,GAAGJ,kBAAkBC;IACzD,MAAMqB,gBAAgBP,UAAU,GAAGL,KAAK,CAAC,EAAEK,SAAS,GAAGL;IAEvDZ,cAAcwB,eAAelB,aAAa,CAACmB;QACzCC,QAAQC,GAAG,CAAC,CAAC,UAAU,EAAE5B,KAAKqB,IAAI,CAACd,aAAaM,MAAM,CAAC,EAAE,CAACa,MAAM,iBAAiB,+BAA+B;QAChHF,SAASE;IACX;AACF"}
@@ -4,47 +4,42 @@ import Queue from 'queue-cb';
4
4
  import rimraf2 from 'rimraf2';
5
5
  import { extensions, typeFileRegEx } from '../constants.mjs';
6
6
  import createMatcher from '../createMatcher.mjs';
7
- import installBindings from '../lib/installBindings.mjs';
8
7
  import transformFile from '../lib/transformFile.mjs';
9
- const target = `${process.platform}-${process.arch}`;
10
8
  export default function transformDirectoryWorker(src, dest, type, options, callback) {
11
9
  const tsconfig = options.tsconfig;
12
10
  const matcher = createMatcher(tsconfig);
13
- installBindings(target, (err)=>{
14
- if (err) return callback(err);
15
- rimraf2(dest, {
16
- disableGlob: true
17
- }, ()=>{
18
- const entries = [];
19
- const iterator = new Iterator(src);
20
- iterator.forEach((entry)=>{
21
- if (!entry.stats.isFile()) return;
22
- if (entry.basename[0] === '.') return;
23
- if (typeFileRegEx.test(entry.basename)) return;
24
- if (!matcher(entry.fullPath)) return;
25
- const ext = path.extname(entry.basename);
26
- if (ext && extensions.indexOf(ext) < 0) return;
27
- entries.push(entry);
28
- }, (err)=>{
29
- if (err) return callback(err);
30
- const results = [];
31
- options = {
32
- ...options,
33
- tsconfig,
34
- src,
35
- dest
36
- };
37
- const queue = new Queue();
38
- entries.forEach((entry)=>{
39
- queue.defer((cb)=>transformFile(entry, dest, type, options, (err, outPath)=>{
40
- if (err) return cb(err);
41
- results.push(path.normalize(outPath));
42
- if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);
43
- cb();
44
- }));
45
- });
46
- queue.await((err)=>err ? callback(err) : callback(null, results));
11
+ rimraf2(dest, {
12
+ disableGlob: true
13
+ }, ()=>{
14
+ const entries = [];
15
+ const iterator = new Iterator(src);
16
+ iterator.forEach((entry)=>{
17
+ if (!entry.stats.isFile()) return;
18
+ if (entry.basename[0] === '.') return;
19
+ if (typeFileRegEx.test(entry.basename)) return;
20
+ if (!matcher(entry.fullPath)) return;
21
+ const ext = path.extname(entry.basename);
22
+ if (ext && extensions.indexOf(ext) < 0) return;
23
+ entries.push(entry);
24
+ }, (err)=>{
25
+ if (err) return callback(err);
26
+ const results = [];
27
+ options = {
28
+ ...options,
29
+ tsconfig,
30
+ src,
31
+ dest
32
+ };
33
+ const queue = new Queue();
34
+ entries.forEach((entry)=>{
35
+ queue.defer((cb)=>transformFile(entry, dest, type, options, (err, outPath)=>{
36
+ if (err) return cb(err);
37
+ results.push(path.normalize(outPath));
38
+ if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);
39
+ cb();
40
+ }));
47
41
  });
42
+ queue.await((err)=>err ? callback(err) : callback(null, results));
48
43
  });
49
44
  });
50
45
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { extensions, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport installBindings from '../lib/installBindings';\nimport transformFile from '../lib/transformFile';\n\nconst target = `${process.platform}-${process.arch}`;\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n installBindings(target, (err) => {\n if (err) return callback(err);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n });\n}\n"],"names":["path","Iterator","Queue","rimraf2","extensions","typeFileRegEx","createMatcher","installBindings","transformFile","target","process","platform","arch","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","err","disableGlob","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","ext","extname","indexOf","push","results","queue","defer","cb","outPath","normalize","sourceMaps","await"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,cAAc,cAAc;AACnC,OAAOC,WAAW,WAAW;AAC7B,OAAOC,aAAa,UAAU;AAE9B,SAASC,UAAU,EAAEC,aAAa,QAAQ,eAAe;AACzD,OAAOC,mBAAmB,mBAAmB;AAC7C,OAAOC,qBAAqB,yBAAyB;AACrD,OAAOC,mBAAmB,uBAAuB;AAEjD,MAAMC,SAAS,GAAGC,QAAQC,QAAQ,CAAC,CAAC,E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;gBAEJ;gBACAF,MAAMM,KAAK,CAAC,CAACtB,MAASA,MAAMH,SAASG,OAAOH,SAAS,MAAMkB;YAC7D;QAEJ;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformDirectory.ts"],"sourcesContent":["import path from 'path';\nimport Iterator from 'fs-iterator';\nimport Queue from 'queue-cb';\nimport rimraf2 from 'rimraf2';\n\nimport { extensions, typeFileRegEx } from '../constants';\nimport createMatcher from '../createMatcher';\nimport transformFile from '../lib/transformFile';\n\nexport default function transformDirectoryWorker(src, dest, type, options, callback) {\n const tsconfig = options.tsconfig;\n const matcher = createMatcher(tsconfig);\n\n rimraf2(dest, { disableGlob: true }, () => {\n const entries = [];\n const iterator = new Iterator(src);\n iterator.forEach(\n (entry) => {\n if (!entry.stats.isFile()) return;\n if (entry.basename[0] === '.') return;\n if (typeFileRegEx.test(entry.basename)) return;\n if (!matcher(entry.fullPath)) return;\n const ext = path.extname(entry.basename);\n if (ext && extensions.indexOf(ext) < 0) return;\n entries.push(entry);\n },\n (err) => {\n if (err) return callback(err);\n const results = [];\n options = { ...options, tsconfig, src, dest };\n\n const queue = new Queue();\n entries.forEach((entry) => {\n queue.defer((cb) =>\n transformFile(entry, dest, type, options, (err, outPath) => {\n if (err) return cb(err);\n results.push(path.normalize(outPath));\n if (options.sourceMaps) results.push(`${path.normalize(outPath)}.map`);\n cb();\n })\n );\n });\n queue.await((err) => (err ? callback(err) : callback(null, results)));\n }\n );\n });\n}\n"],"names":["path","Iterator","Queue","rimraf2","extensions","typeFileRegEx","createMatcher","transformFile","transformDirectoryWorker","src","dest","type","options","callback","tsconfig","matcher","disableGlob","entries","iterator","forEach","entry","stats","isFile","basename","test","fullPath","ext","extname","indexOf","push","err","results","queue","defer","cb","outPath","normalize","sourceMaps","await"],"mappings":"AAAA,OAAOA,UAAU,OAAO;AACxB,OAAOC,cAAc,cAAc;AACnC,OAAOC,WAAW,WAAW;AAC7B,OA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AAI,CAAC;wBACrED;oBACF;YAEJ;YACAF,MAAMM,KAAK,CAAC,CAACR,MAASA,MAAMjB,SAASiB,OAAOjB,SAAS,MAAMkB;QAC7D;IAEJ;AACF"}
@@ -1,17 +1,13 @@
1
- import endsWith from 'lodash.endswith';
2
- import { sync as installBindingsSync } from '../lib/installBindings.mjs';
3
1
  import swcPrepareOptions from '../lib/swcPrepareOptions.mjs';
4
2
  import Module from 'module';
5
3
  import lazy from 'lazy-cache';
6
4
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
7
5
  const swcLazy = lazy(_require)('@swc/core');
8
- const target = `${process.platform}-${process.arch}`;
9
6
  export default function transformSyncWorker(contents, fileName, tsconfig) {
10
- installBindingsSync(target);
11
7
  const swcOptions = swcPrepareOptions(tsconfig);
12
8
  const swc = swcLazy();
13
9
  return swc.transformSync(contents, {
14
- ...endsWith(fileName, '.tsx') || endsWith(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
10
+ ...fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
15
11
  filename: fileName
16
12
  });
17
13
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import endsWith from 'lodash.endswith';\nimport { sync as installBindingsSync } from '../lib/installBindings';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\nconst target = `${process.platform}-${process.arch}`;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n installBindingsSync(target);\n\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(endsWith(fileName, '.tsx') || endsWith(fileName, '.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["endsWith","sync","installBindingsSync","swcPrepareOptions","Module","lazy","_require","require","createRequire","url","swcLazy","target","process","platform","arch","transformSyncWorker","contents","fileName","tsconfig","swcOptions","swc","transformSync","tsxOptions","nonTsxOptions","filename"],"mappings":"AAAA,OAAOA,cAAc,kBAAkB;AACvC,SAASC,QAAQC,mBAAmB,QAAQ,yBAAyB;AACrE,OAAOC,uBAAuB,2BAA2B;AAEzD,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,UAAUL,KAAKC,UAAU;AAC/B,MAAMK,SAAS,GAAGC,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE;AAGpD,eAAe,SAASC,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtGhB,oBAAoBS;IAEpB,MAAMQ,aAAahB,kBAAkBe;IACrC,MAAME,MAAMV;IACZ,OAAOU,IAAIC,aAAa,CAACL,UAAU;QACjC,GAAIhB,SAASiB,UAAU,WAAWjB,SAASiB,UAAU,UAAUE,WAAWG,UAAU,GAAGH,WAAWI,aAAa;QAC/GC,UAAUP;IACZ;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/workers/transformSync.ts"],"sourcesContent":["import swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst swcLazy = lazy(_require)('@swc/core');\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function transformSyncWorker(contents: string, fileName: string, tsconfig: TsConfigResult) {\n const swcOptions = swcPrepareOptions(tsconfig);\n const swc = swcLazy();\n return swc.transformSync(contents, {\n ...(fileName.endsWith('.tsx') || fileName.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions),\n filename: fileName,\n });\n}\n"],"names":["swcPrepareOptions","Module","lazy","_require","require","createRequire","url","swcLazy","transformSyncWorker","contents","fileName","tsconfig","swcOptions","swc","transformSync","endsWith","tsxOptions","nonTsxOptions","filename"],"mappings":"AAAA,OAAOA,uBAAuB,2BAA2B;AAEzD,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,UAAUL,KAAKC,UAAU;AAG/B,eAAe,SAASK,oBAAoBC,QAAgB,EAAEC,QAAgB,EAAEC,QAAwB;IACtG,MAAMC,aAAaZ,kBAAkBW;IACrC,MAAME,MAAMN;IACZ,OAAOM,IAAIC,aAAa,CAACL,UAAU;QACjC,GAAIC,SAASK,QAAQ,CAAC,WAAWL,SAASK,QAAQ,CAAC,UAAUH,WAAWI,UAAU,GAAGJ,WAAWK,aAAa;QAC7GC,UAAUR;IACZ;AACF"}
@@ -0,0 +1,3 @@
1
+ export declare const sync: (target: any) => any;
2
+ declare const _default: any;
3
+ export default _default;
@@ -4,5 +4,4 @@ export declare function getDependencyInfo(target: any): {
4
4
  nodeModules: any;
5
5
  };
6
6
  export declare function isInstalled(target: any): boolean;
7
- declare const _default: any;
8
- export default _default;
7
+ export default function installBindings(target: any, callback: any): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-swc-transform",
3
- "version": "1.13.4",
3
+ "version": "1.13.6",
4
4
  "description": "Typescript transformers for swc. Supports Node >= 0.8",
5
5
  "keywords": [
6
6
  "matcher",
@@ -51,10 +51,9 @@
51
51
  "install-module-linked": "^1.1.6",
52
52
  "is-absolute": "^1.0.0",
53
53
  "lazy-cache": "^2.0.2",
54
- "lodash.endswith": "^4.2.1",
55
54
  "minimatch": "^3.1.2",
56
55
  "mkdirp-classic": "^0.5.3",
57
- "node-version-call": "^1.6.0",
56
+ "node-version-call": "^1.6.5",
58
57
  "path-posix": "^1.0.0",
59
58
  "queue-cb": "^1.4.10",
60
59
  "resolve": "^1.22.10",
@@ -70,7 +69,7 @@
70
69
  "@types/mocha": "^10.0.10",
71
70
  "@types/node": "^22.10.5",
72
71
  "cr": "^0.1.0",
73
- "cross-spawn-cb": "^2.1.0",
72
+ "cross-spawn-cb": "^2.1.2",
74
73
  "es6-map": "^0.1.5",
75
74
  "es6-symbol": "^3.1.4",
76
75
  "lodash.difference": "^4.5.0",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/installBindings.ts"],"sourcesContent":["import installBindings, { isInstalled } from '../workers/installBindings';\nexport default installBindings;\n\nimport path from 'path';\nimport url from 'url';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', '..', 'cjs', 'workers', 'installBindings.cjs');\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\n\nconst callLazy = lazy(_require)('node-version-call');\nconst install = lazy((target) => {\n return isInstalled(target) ? target : callLazy()({ version, callbacks: true }, workerPath, target);\n});\n\nexport const sync = (target) => install(target)();\n"],"names":["sync","installBindings","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","workerPath","join","major","process","versions","node","split","version","callLazy","lazy","install","target","isInstalled","callbacks"],"mappings":";;;;;;;;;;;IACA,OAA+B;eAA/B;;IAkBaA,IAAI;eAAJA;;;uEAnBgC;2DAG5B;0DACD;6DAEG;gEACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IANjB,WAAeC,wBAAe;AAO9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcC,YAAG,CAACC,aAAa,CAAC,uDAAmBF;AACxG,IAAMG,aAAaL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,MAAM,OAAO,WAAW;AACtE,IAAMQ,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAMC,UAAUL,QAAQ,KAAK,WAAW;AAExC,IAAMM,WAAWC,IAAAA,kBAAI,EAACnB,UAAU;AAChC,IAAMoB,UAAUD,IAAAA,kBAAI,EAAC,SAACE;IACpB,OAAOC,IAAAA,4BAAW,EAACD,UAAUA,SAASH,WAAW;QAAED,SAAAA;QAASM,WAAW;IAAK,GAAGb,YAAYW;AAC7F;AAEO,IAAMvB,OAAO,SAACuB;WAAWD,QAAQC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/installBindings.ts"],"sourcesContent":["import installBindings, { isInstalled } from '../workers/installBindings';\nexport default installBindings;\n\nimport path from 'path';\nimport url from 'url';\n\nimport Module from 'module';\nimport lazy from 'lazy-cache';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename === 'undefined' ? url.fileURLToPath(import.meta.url) : __filename);\nconst workerPath = path.join(__dirname, '..', '..', 'cjs', 'workers', 'installBindings.cjs');\nconst major = +process.versions.node.split('.')[0];\nconst version = major < 14 ? 'stable' : 'local';\n\nconst callLazy = lazy(_require)('node-version-call');\nconst install = lazy((target) => {\n return isInstalled(target) ? target : callLazy()({ version, callbacks: true }, workerPath, target);\n});\n\nexport const sync = (target) => install(target)();\n"],"names":["installBindings","isInstalled","path","url","Module","lazy","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","workerPath","join","major","process","versions","node","split","version","callLazy","install","target","callbacks","sync"],"mappings":"AAAA,OAAOA,mBAAmBC,WAAW,QAAQ,6BAA6B;AAC1E,eAAeD,gBAAgB;AAE/B,OAAOE,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,OAAOC,YAAY,SAAS;AAC5B,OAAOC,UAAU,aAAa;AAC9B,MAAMC,WAAW,OAAOC,YAAY,cAAcH,OAAOI,aAAa,CAAC,YAAYL,GAAG,IAAII;AAC1F,MAAME,YAAYP,KAAKQ,OAAO,CAAC,OAAOC,eAAe,cAAcR,IAAIS,aAAa,CAAC,YAAYT,GAAG,IAAIQ;AACxG,MAAME,aAAaX,KAAKY,IAAI,CAACL,WAAW,MAAM,MAAM,OAAO,WAAW;AACtE,MAAMM,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,MAAMC,UAAUL,QAAQ,KAAK,WAAW;AAExC,MAAMM,WAAWhB,KAAKC,UAAU;AAChC,MAAMgB,UAAUjB,KAAK,CAACkB;IACpB,OAAOtB,YAAYsB,UAAUA,SAASF,WAAW;QAAED;QAASI,WAAW;IAAK,GAAGX,YAAYU;AAC7F;AAEA,OAAO,MAAME,OAAO,CAACF,SAAWD,QAAQC,UAAU"}
@@ -1,3 +0,0 @@
1
- import installBindings from '../workers/installBindings';
2
- export default installBindings;
3
- export declare const sync: (target: any) => any;