ts-swc-transform 1.13.12 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +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
+ var _installoptional = require("install-optional");
13
13
  var _module = /*#__PURE__*/ _interop_require_default(require("module"));
14
14
  function _interop_require_default(obj) {
15
15
  return obj && obj.__esModule ? obj : {
@@ -18,7 +18,7 @@ function _interop_require_default(obj) {
18
18
  }
19
19
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
20
20
  function swcPrepareOptions(tsconfig) {
21
- (0, _ensureBindings.sync)('@swc/core', "".concat(process.platform, "-").concat(process.arch));
21
+ (0, _installoptional.installSync)('@swc/core', "".concat(process.platform, "-").concat(process.arch));
22
22
  try {
23
23
  var ts = _require('typescript');
24
24
  var swc = _require('@swc/core');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport { sync as ensureBindingsSync } from './ensureBindings';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n ensureBindingsSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\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","tsconfig","ensureBindingsSync","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAOA;;;eAAwBA;;;2DAPP;8BAC0B;6DAExB;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,kBAAkBK,QAAwB;IAChEC,IAAAA,oBAAkB,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI;IACnE,IAAI;QACF,IAAMC,KAAKT,SAAS;QACpB,IAAMU,MAAMV,SAAS;QACrB,IAAMW,aAAaX,SAAS;QAC5B,IAAMY,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"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport { installSync } from 'install-optional';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n installSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\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","tsconfig","installSync","process","platform","arch","ts","swc","transpiler","parsed","parseJsonConfigFileContent","config","sys","path","dirname","createSwcOptions","options","undefined","err","console","log","message"],"mappings":";;;;+BAOA;;;eAAwBA;;;2DAPP;+BACW;6DAET;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,kBAAkBK,QAAwB;IAChEC,IAAAA,4BAAW,EAAC,aAAa,AAAC,GAAsBC,OAApBA,QAAQC,QAAQ,EAAC,KAAgB,OAAbD,QAAQE,IAAI;IAC5D,IAAI;QACF,IAAMC,KAAKT,SAAS;QACpB,IAAMU,MAAMV,SAAS;QACrB,IAAMW,aAAaX,SAAS;QAC5B,IAAMY,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"}
@@ -12,7 +12,6 @@ var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
12
  var _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
13
  var _mkdirpclassic = /*#__PURE__*/ _interop_require_default(require("mkdirp-classic"));
14
14
  var _queuecb = /*#__PURE__*/ _interop_require_default(require("queue-cb"));
15
- var _ensureBindings = /*#__PURE__*/ _interop_require_default(require("./ensureBindings.cjs"));
16
15
  var _patchCJS = /*#__PURE__*/ _interop_require_default(require("../lib/patchCJS.cjs"));
17
16
  var _patchESM = /*#__PURE__*/ _interop_require_default(require("../lib/patchESM.cjs"));
18
17
  var _swcPrepareOptions = /*#__PURE__*/ _interop_require_default(require("../lib/swcPrepareOptions.cjs"));
@@ -76,34 +75,31 @@ function _object_spread_props(target, source) {
76
75
  }
77
76
  var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
78
77
  function transformFile(entry, dest, type, options, callback) {
79
- (0, _ensureBindings.default)('@swc/core', "".concat(process.platform, "-").concat(process.arch), function(err) {
80
- if (err) return callback(err);
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 = _require('@swc/core');
92
- swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, entry.basename.endsWith('.tsx') || entry.basename.endsWith('.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);
104
- });
78
+ var tsconfig = options.tsconfig;
79
+ // overrides for cjs
80
+ if (type === 'cjs') {
81
+ tsconfig = _object_spread({}, tsconfig);
82
+ tsconfig.config = _object_spread({}, tsconfig.config);
83
+ tsconfig.config.compilerOptions = _object_spread({}, tsconfig.config.compilerOptions || {});
84
+ tsconfig.config.compilerOptions.module = 'CommonJS';
85
+ tsconfig.config.compilerOptions.target = 'ES5';
86
+ }
87
+ var swcOptions = (0, _swcPrepareOptions.default)(tsconfig);
88
+ var swc = _require('@swc/core');
89
+ swc.transformFile(entry.fullPath, _object_spread_props(_object_spread({}, entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions), {
90
+ filename: entry.basename
91
+ })).then(function(output) {
92
+ var extTarget = type === 'esm' ? (0, _patchESM.default)(entry, output, options) : (0, _patchCJS.default)(entry, output, options);
93
+ var ext = _path.default.extname(entry.path);
94
+ var outPath = _path.default.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
95
+ (0, _mkdirpclassic.default)(_path.default.dirname(outPath), function() {
96
+ var queue = new _queuecb.default();
97
+ queue.defer(_fs.default.writeFile.bind(null, outPath, output.code, 'utf8'));
98
+ !options.sourceMaps || queue.defer(_fs.default.writeFile.bind(null, "".concat(outPath, ".map"), output.map, 'utf8'));
99
+ queue.await(function(err) {
100
+ return err ? callback(err) : callback(null, outPath);
105
101
  });
106
- }).catch(callback);
107
- });
102
+ });
103
+ }).catch(callback);
108
104
  }
109
105
  /* 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 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';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nexport default function transformFile(entry, dest, type, options, callback) {\n ensureBindings('@swc/core', `${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 = _require('@swc/core');\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","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":";;;;+BAaA;;;eAAwBA;;;yDAbT;2DACE;oEACE;8DACD;qEACS;+DAEN;+DACA;wEACS;6D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ACG,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"}
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';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\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 = _require('@swc/core');\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"],"names":["transformFile","_require","require","Module","createRequire","entry","dest","type","options","callback","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","err","catch"],"mappings":";;;;+BAYA;;;eAAwBA;;;yDAZT;2DACE;oEACE;8DACD;+DAEG;+DACA;wEACS;6DAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE3E,SAASF,cAAcK,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,eA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ync as ensureBindingsSync } from './ensureBindings.mjs';
2
+ import { installSync } from 'install-optional';
3
3
  import Module from 'module';
4
4
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
5
5
  export default function swcPrepareOptions(tsconfig) {
6
- ensureBindingsSync('@swc/core', `${process.platform}-${process.arch}`);
6
+ installSync('@swc/core', `${process.platform}-${process.arch}`);
7
7
  try {
8
8
  const ts = _require('typescript');
9
9
  const swc = _require('@swc/core');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport { sync as ensureBindingsSync } from './ensureBindings';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n ensureBindingsSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\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","ensureBindingsSync","Module","_require","require","createRequire","url","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,kBAAkB,QAAQ,mBAAmB;AAE9D,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAG1F,eAAe,SAASG,kBAAkBC,QAAwB;IAChEP,mBAAmB,aAAa,GAAGQ,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE;IACrE,IAAI;QACF,MAAMC,KAAKT,SAAS;QACpB,MAAMU,MAAMV,SAAS;QACrB,MAAMW,aAAaX,SAAS;QAC5B,MAAMY,SAASH,GAAGI,0BAA0B,CAACR,SAASS,MAAM,EAAEL,GAAGM,GAAG,EAAEnB,KAAKoB,OAAO,CAACX,SAAST,IAAI;QAChG,OAAOe,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 { installSync } from 'install-optional';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nimport type { TsConfigResult } from 'get-tsconfig-compat';\nexport default function swcPrepareOptions(tsconfig: TsConfigResult) {\n installSync('@swc/core', `${process.platform}-${process.arch}`);\n try {\n const ts = _require('typescript');\n const swc = _require('@swc/core');\n const transpiler = _require('ts-node/transpilers/swc');\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","installSync","Module","_require","require","createRequire","url","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,WAAW,QAAQ,mBAAmB;AAE/C,OAAOC,YAAY,SAAS;AAC5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAG1F,eAAe,SAASG,kBAAkBC,QAAwB;IAChEP,YAAY,aAAa,GAAGQ,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE;IAC9D,IAAI;QACF,MAAMC,KAAKT,SAAS;QACpB,MAAMU,MAAMV,SAAS;QACrB,MAAMW,aAAaX,SAAS;QAC5B,MAAMY,SAASH,GAAGI,0BAA0B,CAACR,SAASS,MAAM,EAAEL,GAAGM,GAAG,EAAElB,KAAKmB,OAAO,CAACX,SAASR,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"}
@@ -2,45 +2,41 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import mkdirp from 'mkdirp-classic';
4
4
  import Queue from 'queue-cb';
5
- import ensureBindings from './ensureBindings.mjs';
6
5
  import patchCJS from '../lib/patchCJS.mjs';
7
6
  import patchESM from '../lib/patchESM.mjs';
8
7
  import swcPrepareOptions from '../lib/swcPrepareOptions.mjs';
9
8
  import Module from 'module';
10
9
  const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
11
10
  export default function transformFile(entry, dest, type, options, callback) {
12
- ensureBindings('@swc/core', `${process.platform}-${process.arch}`, (err)=>{
13
- if (err) return callback(err);
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 = _require('@swc/core');
31
- swc.transformFile(entry.fullPath, {
32
- ...entry.basename.endsWith('.tsx') || entry.basename.endsWith('.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);
45
- });
11
+ let tsconfig = options.tsconfig;
12
+ // overrides for cjs
13
+ if (type === 'cjs') {
14
+ tsconfig = {
15
+ ...tsconfig
16
+ };
17
+ tsconfig.config = {
18
+ ...tsconfig.config
19
+ };
20
+ tsconfig.config.compilerOptions = {
21
+ ...tsconfig.config.compilerOptions || {}
22
+ };
23
+ tsconfig.config.compilerOptions.module = 'CommonJS';
24
+ tsconfig.config.compilerOptions.target = 'ES5';
25
+ }
26
+ const swcOptions = swcPrepareOptions(tsconfig);
27
+ const swc = _require('@swc/core');
28
+ swc.transformFile(entry.fullPath, {
29
+ ...entry.basename.endsWith('.tsx') || entry.basename.endsWith('.jsx') ? swcOptions.tsxOptions : swcOptions.nonTsxOptions,
30
+ filename: entry.basename
31
+ }).then((output)=>{
32
+ const extTarget = type === 'esm' ? patchESM(entry, output, options) : patchCJS(entry, output, options);
33
+ const ext = path.extname(entry.path);
34
+ const outPath = path.join(dest, (ext ? entry.path.slice(0, -ext.length) : entry.path) + extTarget);
35
+ mkdirp(path.dirname(outPath), ()=>{
36
+ const queue = new Queue();
37
+ queue.defer(fs.writeFile.bind(null, outPath, output.code, 'utf8'));
38
+ !options.sourceMaps || queue.defer(fs.writeFile.bind(null, `${outPath}.map`, output.map, 'utf8'));
39
+ queue.await((err)=>err ? callback(err) : callback(null, outPath));
40
+ });
41
+ }).catch(callback);
46
42
  }
@@ -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 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';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\nexport default function transformFile(entry, dest, type, options, callback) {\n ensureBindings('@swc/core', `${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 = _require('@swc/core');\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","_require","require","createRequire","url","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,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,eAAe,SAASG,cAAcC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACxEd,eAAe,aAAa,GAAGe,QAAQC,QAAQ,CAAC,CAAC,EAAED,QAAQE,IAAI,EAAE,EAAE,CAACC;QAClE,IAAIA,KAAK,OAAOJ,SAASI;QAEzB,IAAIC,WAAWN,QAAQM,QAAQ;QAE/B,oBAAoB;QACpB,IAAIP,SAAS,OAAO;YAClBO,WAAW;gBAAE,GAAGA,QAAQ;YAAC;YACzBA,SAASC,MAAM,GAAG;gBAAE,GAAGD,SAASC,MAAM;YAAC;YACvCD,SAASC,MAAM,CAACC,eAAe,GAAG;gBAAE,GAAIF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAC;YAAE;YAC/EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;YACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;QAC3C;QAEA,MAAMC,aAAarB,kBAAkBgB;QACrC,MAAMM,MAAMpB,SAAS;QAErBoB,IACGhB,aAAa,CAACC,MAAMgB,QAAQ,EAAE;YAC7B,GAAIhB,MAAMiB,QAAQ,CAACC,QAAQ,CAAC,WAAWlB,MAAMiB,QAAQ,CAACC,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;YACzHC,UAAUrB,MAAMiB,QAAQ;QAC1B,GACCK,IAAI,CAAC,CAACC;YACL,MAAMC,YAAYtB,SAAS,QAAQV,SAASQ,OAAOuB,QAAQpB,WAAWZ,SAASS,OAAOuB,QAAQpB;YAC9F,MAAMsB,MAAMtC,KAAKuC,OAAO,CAAC1B,MAAMb,IAAI;YACnC,MAAMwC,UAAUxC,KAAKyC,IAAI,CAAC3B,MAAM,AAACwB,CAAAA,MAAMzB,MAAMb,IAAI,CAAC0C,KAAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAI9B,MAAMb,IAAI,AAAD,IAAKqC;YAExFpC,OAAOD,KAAK4C,OAAO,CAACJ,UAAU;gBAC5B,MAAMK,QAAQ,IAAI3C;gBAClB2C,MAAMC,KAAK,CAAC/C,GAAGgD,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;gBAC1D,CAACjC,QAAQkC,UAAU,IAAIL,MAAMC,KAAK,CAAC/C,GAAGgD,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
+ {"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';\n\nimport patchCJS from '../lib/patchCJS';\nimport patchESM from '../lib/patchESM';\nimport swcPrepareOptions from '../lib/swcPrepareOptions';\n\nimport Module from 'module';\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\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 = _require('@swc/core');\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"],"names":["fs","path","mkdirp","Queue","patchCJS","patchESM","swcPrepareOptions","Module","_require","require","createRequire","url","transformFile","entry","dest","type","options","callback","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","err","catch"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,YAAY,iBAA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AAK,CAAC,GAAG,CAACJ,IAAIK,MAAM,IAAI1B,MAAMZ,IAAI,AAAD,IAAKgC;QAExF/B,OAAOD,KAAKuC,OAAO,CAACJ,UAAU;YAC5B,MAAMK,QAAQ,IAAItC;YAClBsC,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAMR,SAASJ,OAAOa,IAAI,EAAE;YAC1D,CAAC7B,QAAQ8B,UAAU,IAAIL,MAAMC,KAAK,CAAC1C,GAAG2C,SAAS,CAACC,IAAI,CAAC,MAAM,GAAGR,QAAQ,IAAI,CAAC,EAAEJ,OAAOe,GAAG,EAAE;YACzFN,MAAMO,KAAK,CAAC,CAACC,MAASA,MAAMhC,SAASgC,OAAOhC,SAAS,MAAMmB;QAC7D;IACF,GACCc,KAAK,CAACjC;AACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-swc-transform",
3
- "version": "1.13.12",
3
+ "version": "1.14.0",
4
4
  "description": "Typescript transformers for swc. Supports Node >= 0.8",
5
5
  "keywords": [
6
6
  "matcher",
@@ -48,14 +48,13 @@
48
48
  "exit": "^0.1.2",
49
49
  "fs-iterator": "^5.2.10",
50
50
  "get-tsconfig-compat": "^2.0.3",
51
- "install-module-linked": "^1.1.10",
51
+ "install-optional": "^0.1.0",
52
52
  "is-absolute": "^1.0.0",
53
53
  "minimatch": "^3.1.2",
54
54
  "mkdirp-classic": "^0.5.3",
55
55
  "path-posix": "^1.0.0",
56
56
  "queue-cb": "^1.4.10",
57
57
  "resolve": "^1.22.10",
58
- "resolve-once-cb": "^0.1.7",
59
58
  "rimraf2": "^2.8.2",
60
59
  "ts-node": "*",
61
60
  "typescript": "*",
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- default: function() {
13
- return ensureBindings;
14
- },
15
- sync: function() {
16
- return sync;
17
- }
18
- });
19
- var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
20
- var _path = /*#__PURE__*/ _interop_require_default(require("path"));
21
- var _installmodulelinked = /*#__PURE__*/ _interop_require_wildcard(require("install-module-linked"));
22
- var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
23
- var _resolveoncecb = /*#__PURE__*/ _interop_require_default(require("resolve-once-cb"));
24
- function _interop_require_default(obj) {
25
- return obj && obj.__esModule ? obj : {
26
- default: obj
27
- };
28
- }
29
- function _getRequireWildcardCache(nodeInterop) {
30
- if (typeof WeakMap !== "function") return null;
31
- var cacheBabelInterop = new WeakMap();
32
- var cacheNodeInterop = new WeakMap();
33
- return (_getRequireWildcardCache = function(nodeInterop) {
34
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
35
- })(nodeInterop);
36
- }
37
- function _interop_require_wildcard(obj, nodeInterop) {
38
- if (!nodeInterop && obj && obj.__esModule) {
39
- return obj;
40
- }
41
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
42
- return {
43
- default: obj
44
- };
45
- }
46
- var cache = _getRequireWildcardCache(nodeInterop);
47
- if (cache && cache.has(obj)) {
48
- return cache.get(obj);
49
- }
50
- var newObj = {
51
- __proto__: null
52
- };
53
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
54
- for(var key in obj){
55
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
56
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
57
- if (desc && (desc.get || desc.set)) {
58
- Object.defineProperty(newObj, key, desc);
59
- } else {
60
- newObj[key] = obj[key];
61
- }
62
- }
63
- }
64
- newObj.default = obj;
65
- if (cache) {
66
- cache.set(obj, newObj);
67
- }
68
- return newObj;
69
- }
70
- var existsSync = function(test) {
71
- try {
72
- (_fs.default.accessSync || _fs.default.statSync)(test);
73
- return true;
74
- } catch (_) {
75
- return false;
76
- }
77
- };
78
- function findDependency(identifier, target) {
79
- var packagePath = _resolve.default.sync("".concat(identifier, "/package.json"));
80
- var nodeModules = identifier[0] === '@' ? _path.default.join(packagePath, '..', '..', '..') : _path.default.join(packagePath, '..', '..');
81
- var optionalDependencies = JSON.parse(_fs.default.readFileSync(packagePath, 'utf8')).optionalDependencies;
82
- var name = Object.keys(optionalDependencies).find(function(name) {
83
- return name.indexOf(target) >= 0;
84
- });
85
- return name ? {
86
- name: name,
87
- version: optionalDependencies[name],
88
- nodeModules: nodeModules
89
- } : null;
90
- }
91
- var bindings = {};
92
- function ensureBindings(identifier, target, callback) {
93
- if (bindings[identifier] === undefined) bindings[identifier] = {};
94
- if (bindings[identifier][target] === undefined) {
95
- bindings[identifier][target] = (0, _resolveoncecb.default)(function(cb) {
96
- var _findDependency = findDependency(identifier, target), name = _findDependency.name, version = _findDependency.version, nodeModules = _findDependency.nodeModules;
97
- var installString = version ? "".concat(name, "@").concat(version) : name;
98
- return existsSync(_path.default.join(nodeModules, name)) ? cb() : (0, _installmodulelinked.default)(installString, nodeModules, cb);
99
- });
100
- }
101
- bindings[identifier][target](callback);
102
- }
103
- var bindingsSync = {};
104
- function sync(identifier, target) {
105
- if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};
106
- if (bindingsSync[identifier][target] === undefined) {
107
- bindingsSync[identifier][target] = function() {
108
- var _findDependency = findDependency(identifier, target), name = _findDependency.name, version = _findDependency.version, nodeModules = _findDependency.nodeModules;
109
- var installString = version ? "".concat(name, "@").concat(version) : name;
110
- return existsSync(_path.default.join(nodeModules, name)) ? target : (0, _installmodulelinked.sync)(installString, nodeModules);
111
- }();
112
- }
113
- }
114
- /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/ensureBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport installModule, { sync as installModuleSync } from 'install-module-linked';\nimport resolve from 'resolve';\nimport resolveOnce from 'resolve-once-cb';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nfunction findDependency(identifier, target) {\n const packagePath = resolve.sync(`${identifier}/package.json`);\n const nodeModules = identifier[0] === '@' ? path.join(packagePath, '..', '..', '..') : path.join(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 ? { name, version: optionalDependencies[name], nodeModules } : null;\n}\n\nconst bindings = {};\nexport default function ensureBindings(identifier, target, callback) {\n if (bindings[identifier] === undefined) bindings[identifier] = {};\n if (bindings[identifier][target] === undefined) {\n bindings[identifier][target] = resolveOnce((cb) => {\n const { name, version, nodeModules } = findDependency(identifier, target);\n const installString = version ? `${name}@${version}` : name;\n return existsSync(path.join(nodeModules, name)) ? cb() : installModule(installString, nodeModules, cb);\n });\n }\n bindings[identifier][target](callback);\n}\n\nconst bindingsSync = {};\nexport function sync(identifier, target) {\n if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};\n if (bindingsSync[identifier][target] === undefined) {\n bindingsSync[identifier][target] = (() => {\n const { name, version, nodeModules } = findDependency(identifier, target);\n const installString = version ? `${name}@${version}` : name;\n return existsSync(path.join(nodeModules, name)) ? target : installModuleSync(installString, nodeModules);\n })();\n }\n}\n"],"names":["ensureBindings","sync","existsSync","test","fs","accessSync","statSync","_","findDependency","identifier","target","packagePath","resolve","nodeModules","path","join","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf","version","bindings","callback","undefined","resolveOnce","cb","installString","installModule","bindingsSync","installModuleSync"],"mappings":";;;;;;;;;;;IAwBA,OAUC;eAVuBA;;IAaRC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vB,IAAMkB,gBAAgBN,UAAU,AAAC,GAAUA,OAARL,MAAK,KAAW,OAARK,WAAYL;YACvD,OAAOlB,WAAWY,aAAI,CAACC,IAAI,CAACF,aAAaO,SAASU,OAAOE,IAAAA,4BAAa,EAACD,eAAelB,aAAaiB;QACrG;IACF;IACAJ,QAAQ,CAACjB,WAAW,CAACC,OAAO,CAACiB;AAC/B;AAEA,IAAMM,eAAe,CAAC;AACf,SAAShC,KAAKQ,UAAU,EAAEC,MAAM;IACrC,IAAIuB,YAAY,CAACxB,WAAW,KAAKmB,WAAWK,YAAY,CAACxB,WAAW,GAAG,CAAC;IACxE,IAAIwB,YAAY,CAACxB,WAAW,CAACC,OAAO,KAAKkB,WAAW;QAClDK,YAAY,CAACxB,WAAW,CAACC,OAAO,GAAG,AAAC;YAClC,IAAuCF,kBAAAA,eAAeC,YAAYC,SAA1DU,OAA+BZ,gBAA/BY,MAAMK,UAAyBjB,gBAAzBiB,SAASZ,cAAgBL,gBAAhBK;YACvB,IAAMkB,gBAAgBN,UAAU,AAAC,GAAUA,OAARL,MAAK,KAAW,OAARK,WAAYL;YACvD,OAAOlB,WAAWY,aAAI,CAACC,IAAI,CAACF,aAAaO,SAASV,SAASwB,IAAAA,yBAAiB,EAACH,eAAelB;QAC9F;IACF;AACF"}
@@ -1,47 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import installModule, { sync as installModuleSync } from 'install-module-linked';
4
- import resolve from 'resolve';
5
- import resolveOnce from 'resolve-once-cb';
6
- const existsSync = (test)=>{
7
- try {
8
- (fs.accessSync || fs.statSync)(test);
9
- return true;
10
- } catch (_) {
11
- return false;
12
- }
13
- };
14
- function findDependency(identifier, target) {
15
- const packagePath = resolve.sync(`${identifier}/package.json`);
16
- const nodeModules = identifier[0] === '@' ? path.join(packagePath, '..', '..', '..') : path.join(packagePath, '..', '..');
17
- const optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;
18
- const name = Object.keys(optionalDependencies).find((name)=>name.indexOf(target) >= 0);
19
- return name ? {
20
- name,
21
- version: optionalDependencies[name],
22
- nodeModules
23
- } : null;
24
- }
25
- const bindings = {};
26
- export default function ensureBindings(identifier, target, callback) {
27
- if (bindings[identifier] === undefined) bindings[identifier] = {};
28
- if (bindings[identifier][target] === undefined) {
29
- bindings[identifier][target] = resolveOnce((cb)=>{
30
- const { name, version, nodeModules } = findDependency(identifier, target);
31
- const installString = version ? `${name}@${version}` : name;
32
- return existsSync(path.join(nodeModules, name)) ? cb() : installModule(installString, nodeModules, cb);
33
- });
34
- }
35
- bindings[identifier][target](callback);
36
- }
37
- const bindingsSync = {};
38
- export function sync(identifier, target) {
39
- if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};
40
- if (bindingsSync[identifier][target] === undefined) {
41
- bindingsSync[identifier][target] = (()=>{
42
- const { name, version, nodeModules } = findDependency(identifier, target);
43
- const installString = version ? `${name}@${version}` : name;
44
- return existsSync(path.join(nodeModules, name)) ? target : installModuleSync(installString, nodeModules);
45
- })();
46
- }
47
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/ensureBindings.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport installModule, { sync as installModuleSync } from 'install-module-linked';\nimport resolve from 'resolve';\nimport resolveOnce from 'resolve-once-cb';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nfunction findDependency(identifier, target) {\n const packagePath = resolve.sync(`${identifier}/package.json`);\n const nodeModules = identifier[0] === '@' ? path.join(packagePath, '..', '..', '..') : path.join(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 ? { name, version: optionalDependencies[name], nodeModules } : null;\n}\n\nconst bindings = {};\nexport default function ensureBindings(identifier, target, callback) {\n if (bindings[identifier] === undefined) bindings[identifier] = {};\n if (bindings[identifier][target] === undefined) {\n bindings[identifier][target] = resolveOnce((cb) => {\n const { name, version, nodeModules } = findDependency(identifier, target);\n const installString = version ? `${name}@${version}` : name;\n return existsSync(path.join(nodeModules, name)) ? cb() : installModule(installString, nodeModules, cb);\n });\n }\n bindings[identifier][target](callback);\n}\n\nconst bindingsSync = {};\nexport function sync(identifier, target) {\n if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};\n if (bindingsSync[identifier][target] === undefined) {\n bindingsSync[identifier][target] = (() => {\n const { name, version, nodeModules } = findDependency(identifier, target);\n const installString = version ? `${name}@${version}` : name;\n return existsSync(path.join(nodeModules, name)) ? target : installModuleSync(installString, nodeModules);\n })();\n }\n}\n"],"names":["fs","path","installModule","sync","installModuleSync","resolve","resolveOnce","existsSync","test","accessSync","statSync","_","findDependency","identifier","target","packagePath","nodeModules","join","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf","version","bindings","ensureBindings","callback","undefined","cb","installString","bindingsSync"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,iBAAiBC,QAAQC,iBAAiB,QAAQ,wBAAwB;AACjF,OAAOC,aAAa,UAAU;AAC9B,OAAOC,iBAAiB,kBAAkB;AAE1C,MAAMC,aAAa,CAACC;IAClB,IAAI;QACDR,CAAAA,GAAGS,UAAU,IAAIT,GAAGU,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AAEA,SAASC,eAAeC,UAAU,EAAEC,MAAM;IACxC,MAAMC,cAAcV,QAAQF,IAAI,CAAC,GAAGU,WAAW,aAAa,CAAC;IAC7D,MAAMG,cAAcH,UAAU,CAAC,EAAE,KAAK,MAAMZ,KAAKgB,IAAI,CAACF,aAAa,MAAM,MAAM,QAAQd,KAAKgB,IAAI,CAACF,aAAa,MAAM;IACpH,M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GAAGL,KAAK,CAAC,EAAEK,SAAS,GAAGL;YACvD,OAAOf,WAAWN,KAAKgB,IAAI,CAACD,aAAaM,SAASR,SAASV,kBAAkB6B,eAAejB;QAC9F,CAAA;IACF;AACF"}
@@ -1,2 +0,0 @@
1
- export default function ensureBindings(identifier: any, target: any, callback: any): void;
2
- export declare function sync(identifier: any, target: any): void;