ts-swc-transform 1.13.11 → 1.13.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/ensureBindingsSync.cjs +43 -0
- package/dist/cjs/lib/ensureBindingsSync.cjs.map +1 -0
- package/dist/cjs/lib/swcPrepareOptions.cjs +2 -2
- package/dist/cjs/lib/swcPrepareOptions.cjs.map +1 -1
- package/dist/cjs/lib/transformFile.cjs +25 -29
- package/dist/cjs/lib/transformFile.cjs.map +1 -1
- package/dist/esm/lib/ensureBindingsSync.mjs +25 -0
- package/dist/esm/lib/ensureBindingsSync.mjs.map +1 -0
- package/dist/esm/lib/swcPrepareOptions.mjs +2 -2
- package/dist/esm/lib/swcPrepareOptions.mjs.map +1 -1
- package/dist/esm/lib/transformFile.mjs +31 -35
- package/dist/esm/lib/transformFile.mjs.map +1 -1
- package/dist/types/lib/ensureBindingsSync.d.ts +1 -0
- package/package.json +2 -4
- package/dist/cjs/bindings/ensure.cjs +0 -38
- package/dist/cjs/bindings/ensure.cjs.map +0 -1
- package/dist/cjs/bindings/findDependency.cjs +0 -18
- package/dist/cjs/bindings/findDependency.cjs.map +0 -1
- package/dist/cjs/bindings/install.cjs +0 -13
- package/dist/cjs/bindings/install.cjs.map +0 -1
- package/dist/esm/bindings/ensure.cjs +0 -36
- package/dist/esm/bindings/ensure.cjs.map +0 -1
- package/dist/esm/bindings/findDependency.cjs +0 -14
- package/dist/esm/bindings/findDependency.cjs.map +0 -1
- package/dist/esm/bindings/install.cjs +0 -11
- package/dist/esm/bindings/install.cjs.map +0 -1
- package/dist/types/bindings/ensure.d.cts +0 -5
- package/dist/types/bindings/findDependency.d.cts +0 -6
- package/dist/types/bindings/install.d.cts +0 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ensureBindingsSync;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
var _installmodulelinked = require("install-module-linked");
|
|
14
|
+
var _resolve = /*#__PURE__*/ _interop_require_default(require("resolve"));
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
var existsSync = function(test) {
|
|
21
|
+
try {
|
|
22
|
+
(_fs.default.accessSync || _fs.default.statSync)(test);
|
|
23
|
+
return true;
|
|
24
|
+
} catch (_) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var bindingsSync = {};
|
|
29
|
+
function ensureBindingsSync(identifier, target) {
|
|
30
|
+
if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};
|
|
31
|
+
if (bindingsSync[identifier][target] === undefined) {
|
|
32
|
+
bindingsSync[identifier][target] = function() {
|
|
33
|
+
var packagePath = _resolve.default.sync("".concat(identifier, "/package.json"));
|
|
34
|
+
var nodeModules = identifier[0] === '@' ? _path.default.join(packagePath, '..', '..', '..') : _path.default.join(packagePath, '..', '..');
|
|
35
|
+
var optionalDependencies = JSON.parse(_fs.default.readFileSync(packagePath, 'utf8')).optionalDependencies;
|
|
36
|
+
var name = Object.keys(optionalDependencies).find(function(name) {
|
|
37
|
+
return name.indexOf(target) >= 0;
|
|
38
|
+
});
|
|
39
|
+
if (!existsSync(_path.default.join(nodeModules, name))) (0, _installmodulelinked.sync)("".concat(name, "@").concat(optionalDependencies[name]), nodeModules);
|
|
40
|
+
}();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/* 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/ensureBindingsSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { sync as installModuleSync } from 'install-module-linked';\nimport resolve from 'resolve';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nconst bindingsSync = {};\nexport default function ensureBindingsSync(identifier, target) {\n if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};\n if (bindingsSync[identifier][target] === undefined) {\n bindingsSync[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 if (!existsSync(path.join(nodeModules, name))) installModuleSync(`${name}@${optionalDependencies[name]}`, nodeModules);\n })();\n }\n}\n"],"names":["ensureBindingsSync","existsSync","test","fs","accessSync","statSync","_","bindingsSync","identifier","target","undefined","packagePath","resolve","sync","nodeModules","path","join","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf","installModuleSync"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAfT;2DACE;mCACyB;8DACtB;;;;;;AAEpB,IAAMC,aAAa,SAACC;IAClB,IAAI;QACDC,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGH;QAC/B,OAAO;IACT,EAAE,OAAOI,GAAG;QACV,OAAO;IACT;AACF;AAEA,IAAMC,eAAe,CAAC;AACP,SAASP,mBAAmBQ,UAAU,EAAEC,MAAM;IAC3D,IAAIF,YAAY,CAACC,WAAW,KAAKE,WAAWH,YAAY,CAACC,WAAW,GAAG,CAAC;IACxE,IAAID,YAAY,CAACC,WAAW,CAACC,OAAO,KAAKC,WAAW;QAClDH,YAAY,CAACC,WAAW,CAACC,OAAO,GAAG,AAAC;YAClC,IAAME,cAAcC,gBAAO,CAACC,IAAI,CAAC,AAAC,GAAa,OAAXL,YAAW;YAC/C,IAAMM,cAAcN,UAAU,CAAC,EAAE,KAAK,MAAMO,aAAI,CAACC,IAAI,CAACL,aAAa,MAAM,MAAM,QAAQI,aAAI,CAACC,IAAI,CAACL,aAAa,MAAM;YACpH,IAAMM,uBAAuBC,KAAKC,KAAK,CAAChB,WAAE,CAACiB,YAAY,CAACT,aAAa,SAASM,oBAAoB;YAClG,IAAMI,OAAOC,OAAOC,IAAI,CAACN,sBAAsBO,IAAI,CAAC,SAACH;uBAASA,KAAKI,OAAO,CAAChB,WAAW;;YACtF,IAAI,CAACR,WAAWc,aAAI,CAACC,IAAI,CAACF,aAAaO,QAAQK,IAAAA,yBAAiB,EAAC,AAAC,GAAUT,OAARI,MAAK,KAA8B,OAA3BJ,oBAAoB,CAACI,KAAK,GAAIP;QAC5G;IACF;AACF"}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
|
-
var
|
|
12
|
+
var _ensureBindingsSync = /*#__PURE__*/ _interop_require_default(require("./ensureBindingsSync.cjs"));
|
|
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,
|
|
21
|
+
(0, _ensureBindingsSync.default)('@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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport ensureBindingsSync from './ensureBindingsSync';\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;yEACc;6DAEZ;;;;;;AACnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAG3E,SAASF,kBAAkBK,QAAwB;IAChEC,IAAAA,2BAAkB,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"}
|
|
@@ -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 _ensurecjs = /*#__PURE__*/ _interop_require_default(require("../bindings/ensure.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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
})
|
|
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';\
|
|
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,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,IAAMC,aAAaC,IAAAA,0BAAiB,EAACN;IACrC,IAAMO,MAAMhB,SAAS;IAErBgB,IACGjB,aAAa,CAACK,MAAMa,QAAQ,EAAE,wCACzBb,MAAMc,QAAQ,CAACC,QAAQ,CAAC,WAAWf,MAAMc,QAAQ,CAACC,QAAQ,CAAC,UAAUL,WAAWM,UAAU,GAAGN,WAAWO,aAAa;QACzHC,UAAUlB,MAAMc,QAAQ;QAEzBK,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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { sync as installModuleSync } from 'install-module-linked';
|
|
4
|
+
import resolve from 'resolve';
|
|
5
|
+
const existsSync = (test)=>{
|
|
6
|
+
try {
|
|
7
|
+
(fs.accessSync || fs.statSync)(test);
|
|
8
|
+
return true;
|
|
9
|
+
} catch (_) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const bindingsSync = {};
|
|
14
|
+
export default function ensureBindingsSync(identifier, target) {
|
|
15
|
+
if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};
|
|
16
|
+
if (bindingsSync[identifier][target] === undefined) {
|
|
17
|
+
bindingsSync[identifier][target] = (()=>{
|
|
18
|
+
const packagePath = resolve.sync(`${identifier}/package.json`);
|
|
19
|
+
const nodeModules = identifier[0] === '@' ? path.join(packagePath, '..', '..', '..') : path.join(packagePath, '..', '..');
|
|
20
|
+
const optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;
|
|
21
|
+
const name = Object.keys(optionalDependencies).find((name)=>name.indexOf(target) >= 0);
|
|
22
|
+
if (!existsSync(path.join(nodeModules, name))) installModuleSync(`${name}@${optionalDependencies[name]}`, nodeModules);
|
|
23
|
+
})();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/ensureBindingsSync.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { sync as installModuleSync } from 'install-module-linked';\nimport resolve from 'resolve';\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nconst bindingsSync = {};\nexport default function ensureBindingsSync(identifier, target) {\n if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};\n if (bindingsSync[identifier][target] === undefined) {\n bindingsSync[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 if (!existsSync(path.join(nodeModules, name))) installModuleSync(`${name}@${optionalDependencies[name]}`, nodeModules);\n })();\n }\n}\n"],"names":["fs","path","sync","installModuleSync","resolve","existsSync","test","accessSync","statSync","_","bindingsSync","ensureBindingsSync","identifier","target","undefined","packagePath","nodeModules","join","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,QAAQC,iBAAiB,QAAQ,wBAAwB;AAClE,OAAOC,aAAa,UAAU;AAE9B,MAAMC,aAAa,CAACC;IAClB,IAAI;QACDN,CAAAA,GAAGO,UAAU,IAAIP,GAAGQ,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AAEA,MAAMC,eAAe,CAAC;AACtB,eAAe,SAASC,mBAAmBC,UAAU,EAAEC,MAAM;IAC3D,IAAIH,YAAY,CAACE,WAAW,KAAKE,WAAWJ,YAAY,CAACE,WAAW,GAAG,CAAC;IACxE,IAAIF,YAAY,CAACE,WAAW,CAACC,OAAO,KAAKC,WAAW;QAClDJ,YAAY,CAACE,WAAW,CAACC,OAAO,GAAG,AAAC,CAAA;YAClC,MAAME,cAAcX,QAAQF,IAAI,CAAC,GAAGU,WAAW,aAAa,CAAC;YAC7D,MAAMI,cAAcJ,UAAU,CAAC,EAAE,KAAK,MAAMX,KAAKgB,IAAI,CAACF,aAAa,MAAM,MAAM,QAAQd,KAAKgB,IAAI,CAACF,aAAa,MAAM;YACpH,MAAMG,uBAAuBC,KAAKC,KAAK,CAACpB,GAAGqB,YAAY,CAACN,aAAa,SAASG,oBAAoB;YAClG,MAAMI,OAAOC,OAAOC,IAAI,CAACN,sBAAsBO,IAAI,CAAC,CAACH,OAASA,KAAKI,OAAO,CAACb,WAAW;YACtF,IAAI,CAACR,WAAWJ,KAAKgB,IAAI,CAACD,aAAaM,QAAQnB,kBAAkB,GAAGmB,KAAK,CAAC,EAAEJ,oBAAoB,CAACI,KAAK,EAAE,EAAEN;QAC5G,CAAA;IACF;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import
|
|
2
|
+
import ensureBindingsSync from './ensureBindingsSync.mjs';
|
|
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
|
-
|
|
6
|
+
ensureBindingsSync('@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
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/lib/swcPrepareOptions.ts"],"sourcesContent":["import path from 'path';\nimport ensureBindingsSync from './ensureBindingsSync';\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","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,OAAOC,wBAAwB,uBAAuB;AAEtD,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,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 '../bindings/ensure.cjs';
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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';\
|
|
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,iBAAiB;AACpC,OAAOC,WAAW,WAAW;AAE7B,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;IACxE,IAAIC,WAAWF,QAAQE,QAAQ;IAE/B,oBAAoB;IACpB,IAAIH,SAAS,OAAO;QAClBG,WAAW;YAAE,GAAGA,QAAQ;QAAC;QACzBA,SAASC,MAAM,GAAG;YAAE,GAAGD,SAASC,MAAM;QAAC;QACvCD,SAASC,MAAM,CAACC,eAAe,GAAG;YAAE,GAAIF,SAASC,MAAM,CAACC,eAAe,IAAI,CAAC,CAAC;QAAE;QAC/EF,SAASC,MAAM,CAACC,eAAe,CAACC,MAAM,GAAG;QACzCH,SAASC,MAAM,CAACC,eAAe,CAACE,MAAM,GAAG;IAC3C;IAEA,MAAMC,aAAajB,kBAAkBY;IACrC,MAAMM,MAAMhB,SAAS;IAErBgB,IACGZ,aAAa,CAACC,MAAMY,QAAQ,EAAE;QAC7B,GAAIZ,MAAMa,QAAQ,CAACC,QAAQ,CAAC,WAAWd,MAAMa,QAAQ,CAACC,QAAQ,CAAC,UAAUJ,WAAWK,UAAU,GAAGL,WAAWM,aAAa;QACzHC,UAAUjB,MAAMa,QAAQ;IAC1B,GACCK,IAAI,CAAC,CAACC;QACL,MAAMC,YAAYlB,SAAS,QAAQV,SAASQ,OAAOmB,QAAQhB,WAAWZ,SAASS,OAAOmB,QAAQhB;QAC9F,MAAMkB,MAAMjC,KAAKkC,OAAO,CAACtB,MAAMZ,IAAI;QACnC,MAAMmC,UAAUnC,KAAKoC,IAAI,CAACvB,MAAM,AAACoB,CAAAA,MAAMrB,MAAMZ,IAAI,CAACqC,KAAK,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ensureBindingsSync(identifier: any, target: any): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-swc-transform",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.13",
|
|
4
4
|
"description": "Typescript transformers for swc. Supports Node >= 0.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"matcher",
|
|
@@ -47,16 +47,14 @@
|
|
|
47
47
|
"@swc/core": "*",
|
|
48
48
|
"exit": "^0.1.2",
|
|
49
49
|
"fs-iterator": "^5.2.10",
|
|
50
|
-
"function-exec-sync": "^1.2.5",
|
|
51
50
|
"get-tsconfig-compat": "^2.0.3",
|
|
52
|
-
"install-module-linked": "^1.1.
|
|
51
|
+
"install-module-linked": "^1.1.10",
|
|
53
52
|
"is-absolute": "^1.0.0",
|
|
54
53
|
"minimatch": "^3.1.2",
|
|
55
54
|
"mkdirp-classic": "^0.5.3",
|
|
56
55
|
"path-posix": "^1.0.0",
|
|
57
56
|
"queue-cb": "^1.4.10",
|
|
58
57
|
"resolve": "^1.22.10",
|
|
59
|
-
"resolve-once-cb": "^0.1.7",
|
|
60
58
|
"rimraf2": "^2.8.2",
|
|
61
59
|
"ts-node": "*",
|
|
62
60
|
"typescript": "*",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var path = require('path');
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var resolveOnce = require('resolve-once-cb');
|
|
5
|
-
var findDependency = require('./findDependency.cjs');
|
|
6
|
-
var workerPath = path.join(__dirname, 'install.cjs');
|
|
7
|
-
var existsSync = function(test) {
|
|
8
|
-
try {
|
|
9
|
-
(fs.accessSync || fs.statSync)(test);
|
|
10
|
-
return true;
|
|
11
|
-
} catch (_) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var bindings = {};
|
|
16
|
-
module.exports = function ensureBindings(identifier, target, callback) {
|
|
17
|
-
if (bindings[identifier] === undefined) bindings[identifier] = {};
|
|
18
|
-
if (bindings[identifier][target] === undefined) {
|
|
19
|
-
bindings[identifier][target] = resolveOnce(function(cb) {
|
|
20
|
-
var _findDependency = findDependency(identifier, target), name = _findDependency.name, nodeModules = _findDependency.nodeModules;
|
|
21
|
-
return existsSync(path.join(nodeModules, name)) ? cb() : require(workerPath)(identifier, target, cb);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
bindings[identifier][target](callback);
|
|
25
|
-
};
|
|
26
|
-
var bindingsSync = {};
|
|
27
|
-
module.exports.sync = function(identifier, target) {
|
|
28
|
-
if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};
|
|
29
|
-
if (bindingsSync[identifier][target] === undefined) {
|
|
30
|
-
bindingsSync[identifier][target] = function() {
|
|
31
|
-
var _findDependency = findDependency(identifier, target), name = _findDependency.name, nodeModules = _findDependency.nodeModules;
|
|
32
|
-
return existsSync(path.join(nodeModules, name)) ? target : require('function-exec-sync')({
|
|
33
|
-
callbacks: true
|
|
34
|
-
}, workerPath, identifier, target);
|
|
35
|
-
}();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
/* 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/bindings/ensure.cjs"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst resolveOnce = require('resolve-once-cb');\nconst findDependency = require('./findDependency.cjs');\n\nconst workerPath = path.join(__dirname, 'install.cjs');\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nconst bindings = {};\nmodule.exports = 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, nodeModules } = findDependency(identifier, target);\n return existsSync(path.join(nodeModules, name)) ? cb() : require(workerPath)(identifier, target, cb);\n });\n }\n bindings[identifier][target](callback);\n};\n\nconst bindingsSync = {};\nmodule.exports.sync = (identifier, target) => {\n if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};\n if (bindingsSync[identifier][target] === undefined) {\n bindingsSync[identifier][target] = (() => {\n const { name, nodeModules } = findDependency(identifier, target);\n return existsSync(path.join(nodeModules, name)) ? target : require('function-exec-sync')({ callbacks: true }, workerPath, identifier, target);\n })();\n }\n};\n"],"names":["path","require","fs","resolveOnce","findDependency","workerPath","join","__dirname","existsSync","test","accessSync","statSync","_","bindings","module","exports","ensureBindings","identifier","target","callback","undefined","cb","name","nodeModules","bindingsSync","sync","callbacks"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,KAAKD,QAAQ;AACnB,IAAME,cAAcF,QAAQ;AAC5B,IAAMG,iBAAiBH,QAAQ;AAE/B,IAAMI,aAAaL,KAAKM,IAAI,CAACC,WAAW;AAExC,IAAMC,aAAa,SAACC;IAClB,IAAI;QACDP,CAAAA,GAAGQ,UAAU,IAAIR,GAAGS,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AAEA,IAAMC,WAAW,CAAC;AAClBC,OAAOC,OAAO,GAAG,SAASC,eAAeC,UAAU,EAAEC,MAAM,EAAEC,QAAQ;IACnE,IAAIN,QAAQ,CAACI,WAAW,KAAKG,WAAWP,QAAQ,CAACI,WAAW,GAAG,CAAC;IAChE,IAAIJ,QAAQ,CAACI,WAAW,CAACC,OAAO,KAAKE,WAAW;QAC9CP,QAAQ,CAACI,WAAW,CAACC,OAAO,GAAGf,YAAY,SAACkB;YAC1C,IAA8BjB,kBAAAA,eAAea,YAAYC,SAAjDI,OAAsBlB,gBAAtBkB,MAAMC,cAAgBnB,gBAAhBmB;YACd,OAAOf,WAAWR,KAAKM,IAAI,CAACiB,aAAaD,SAASD,OAAOpB,QAAQI,YAAYY,YAAYC,QAAQG;QACnG;IACF;IACAR,QAAQ,CAACI,WAAW,CAACC,OAAO,CAACC;AAC/B;AAEA,IAAMK,eAAe,CAAC;AACtBV,OAAOC,OAAO,CAACU,IAAI,GAAG,SAACR,YAAYC;IACjC,IAAIM,YAAY,CAACP,WAAW,KAAKG,WAAWI,YAAY,CAACP,WAAW,GAAG,CAAC;IACxE,IAAIO,YAAY,CAACP,WAAW,CAACC,OAAO,KAAKE,WAAW;QAClDI,YAAY,CAACP,WAAW,CAACC,OAAO,GAAG,AAAC;YAClC,IAA8Bd,kBAAAA,eAAea,YAAYC,SAAjDI,OAAsBlB,gBAAtBkB,MAAMC,cAAgBnB,gBAAhBmB;YACd,OAAOf,WAAWR,KAAKM,IAAI,CAACiB,aAAaD,SAASJ,SAASjB,QAAQ,sBAAsB;gBAAEyB,WAAW;YAAK,GAAGrB,YAAYY,YAAYC;QACxI;IACF;AACF"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var path = require('path');
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var resolve = require('resolve');
|
|
5
|
-
module.exports = function findDependency(identifier, target) {
|
|
6
|
-
var packagePath = resolve.sync("".concat(identifier, "/package.json"));
|
|
7
|
-
var nodeModules = identifier[0] === '@' ? path.join(packagePath, '..', '..', '..') : path.join(packagePath, '..', '..');
|
|
8
|
-
var optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;
|
|
9
|
-
var name = Object.keys(optionalDependencies).find(function(name) {
|
|
10
|
-
return name.indexOf(target) >= 0;
|
|
11
|
-
});
|
|
12
|
-
return name ? {
|
|
13
|
-
name: name,
|
|
14
|
-
version: optionalDependencies[name],
|
|
15
|
-
nodeModules: nodeModules
|
|
16
|
-
} : null;
|
|
17
|
-
};
|
|
18
|
-
/* 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/bindings/findDependency.cjs"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst resolve = require('resolve');\n\nmodule.exports = function 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"],"names":["path","require","fs","resolve","module","exports","findDependency","identifier","target","packagePath","sync","nodeModules","join","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf","version"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,KAAKD,QAAQ;AACnB,IAAME,UAAUF,QAAQ;AAExBG,OAAOC,OAAO,GAAG,SAASC,eAAeC,UAAU,EAAEC,MAAM;IACzD,IAAMC,cAAcN,QAAQO,IAAI,CAAC,AAAC,GAAa,OAAXH,YAAW;IAC/C,IAAMI,cAAcJ,UAAU,CAAC,EAAE,KAAK,MAAMP,KAAKY,IAAI,CAACH,aAAa,MAAM,MAAM,QAAQT,KAAKY,IAAI,CAACH,aAAa,MAAM;IACpH,IAAMI,uBAAuBC,KAAKC,KAAK,CAACb,GAAGc,YAAY,CAACP,aAAa,SAASI,oBAAoB;IAClG,IAAMI,OAAOC,OAAOC,IAAI,CAACN,sBAAsBO,IAAI,CAAC,SAACH;eAASA,KAAKI,OAAO,CAACb,WAAW;;IACtF,OAAOS,OAAO;QAAEA,MAAAA;QAAMK,SAAST,oBAAoB,CAACI,KAAK;QAAEN,aAAAA;IAAY,IAAI;AAC7E"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var path = require('path');
|
|
3
|
-
var installModule = require('install-module-linked');
|
|
4
|
-
var findDependency = require('./findDependency.cjs');
|
|
5
|
-
module.exports = function installBindings(identifier, target, callback) {
|
|
6
|
-
var _findDependency = findDependency(identifier, target), name = _findDependency.name, version = _findDependency.version, nodeModules = _findDependency.nodeModules;
|
|
7
|
-
var installString = version ? "".concat(name, "@").concat(version) : name;
|
|
8
|
-
installModule(installString, nodeModules, function(err) {
|
|
9
|
-
console.log("installed ".concat(path.join(nodeModules, name)).concat(!err ? '' : ' with errors: ${err.message}'));
|
|
10
|
-
callback(err);
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
/* 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/bindings/install.cjs"],"sourcesContent":["const path = require('path');\nconst installModule = require('install-module-linked');\nconst findDependency = require('./findDependency.cjs');\n\nmodule.exports = function installBindings(identifier, target, callback) {\n const { name, version, nodeModules } = findDependency(identifier, target);\n const installString = version ? `${name}@${version}` : name;\n\n installModule(installString, nodeModules, (err) => {\n console.log(`installed ${path.join(nodeModules, name)}${!err ? '' : ' with errors: ${err.message}'}`);\n callback(err);\n });\n};\n"],"names":["path","require","installModule","findDependency","module","exports","installBindings","identifier","target","callback","name","version","nodeModules","installString","err","console","log","join"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,gBAAgBD,QAAQ;AAC9B,IAAME,iBAAiBF,QAAQ;AAE/BG,OAAOC,OAAO,GAAG,SAASC,gBAAgBC,UAAU,EAAEC,MAAM,EAAEC,QAAQ;IACpE,IAAuCN,kBAAAA,eAAeI,YAAYC,SAA1DE,OAA+BP,gBAA/BO,MAAMC,UAAyBR,gBAAzBQ,SAASC,cAAgBT,gBAAhBS;IACvB,IAAMC,gBAAgBF,UAAU,AAAC,GAAUA,OAARD,MAAK,KAAW,OAARC,WAAYD;IAEvDR,cAAcW,eAAeD,aAAa,SAACE;QACzCC,QAAQC,GAAG,CAAC,AAAC,aAA2C,OAA/BhB,KAAKiB,IAAI,CAACL,aAAaF,OAAmD,OAA3C,CAACI,MAAM,KAAK;QACpEL,SAASK;IACX;AACF"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const resolveOnce = require('resolve-once-cb');
|
|
4
|
-
const findDependency = require('./findDependency.cjs');
|
|
5
|
-
const workerPath = path.join(__dirname, 'install.cjs');
|
|
6
|
-
const existsSync = (test)=>{
|
|
7
|
-
try {
|
|
8
|
-
(fs.accessSync || fs.statSync)(test);
|
|
9
|
-
return true;
|
|
10
|
-
} catch (_) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const bindings = {};
|
|
15
|
-
module.exports = function ensureBindings(identifier, target, callback) {
|
|
16
|
-
if (bindings[identifier] === undefined) bindings[identifier] = {};
|
|
17
|
-
if (bindings[identifier][target] === undefined) {
|
|
18
|
-
bindings[identifier][target] = resolveOnce((cb)=>{
|
|
19
|
-
const { name, nodeModules } = findDependency(identifier, target);
|
|
20
|
-
return existsSync(path.join(nodeModules, name)) ? cb() : require(workerPath)(identifier, target, cb);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
bindings[identifier][target](callback);
|
|
24
|
-
};
|
|
25
|
-
const bindingsSync = {};
|
|
26
|
-
module.exports.sync = (identifier, target)=>{
|
|
27
|
-
if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};
|
|
28
|
-
if (bindingsSync[identifier][target] === undefined) {
|
|
29
|
-
bindingsSync[identifier][target] = (()=>{
|
|
30
|
-
const { name, nodeModules } = findDependency(identifier, target);
|
|
31
|
-
return existsSync(path.join(nodeModules, name)) ? target : require('function-exec-sync')({
|
|
32
|
-
callbacks: true
|
|
33
|
-
}, workerPath, identifier, target);
|
|
34
|
-
})();
|
|
35
|
-
}
|
|
36
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/bindings/ensure.cjs"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst resolveOnce = require('resolve-once-cb');\nconst findDependency = require('./findDependency.cjs');\n\nconst workerPath = path.join(__dirname, 'install.cjs');\n\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nconst bindings = {};\nmodule.exports = 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, nodeModules } = findDependency(identifier, target);\n return existsSync(path.join(nodeModules, name)) ? cb() : require(workerPath)(identifier, target, cb);\n });\n }\n bindings[identifier][target](callback);\n};\n\nconst bindingsSync = {};\nmodule.exports.sync = (identifier, target) => {\n if (bindingsSync[identifier] === undefined) bindingsSync[identifier] = {};\n if (bindingsSync[identifier][target] === undefined) {\n bindingsSync[identifier][target] = (() => {\n const { name, nodeModules } = findDependency(identifier, target);\n return existsSync(path.join(nodeModules, name)) ? target : require('function-exec-sync')({ callbacks: true }, workerPath, identifier, target);\n })();\n }\n};\n"],"names":["path","require","fs","resolveOnce","findDependency","workerPath","join","__dirname","existsSync","test","accessSync","statSync","_","bindings","module","exports","ensureBindings","identifier","target","callback","undefined","cb","name","nodeModules","bindingsSync","sync","callbacks"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AACrB,MAAMC,KAAKD,QAAQ;AACnB,MAAME,cAAcF,QAAQ;AAC5B,MAAMG,iBAAiBH,QAAQ;AAE/B,MAAMI,aAAaL,KAAKM,IAAI,CAACC,WAAW;AAExC,MAAMC,aAAa,CAACC;IAClB,IAAI;QACDP,CAAAA,GAAGQ,UAAU,IAAIR,GAAGS,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AAEA,MAAMC,WAAW,CAAC;AAClBC,OAAOC,OAAO,GAAG,SAASC,eAAeC,UAAU,EAAEC,MAAM,EAAEC,QAAQ;IACnE,IAAIN,QAAQ,CAACI,WAAW,KAAKG,WAAWP,QAAQ,CAACI,WAAW,GAAG,CAAC;IAChE,IAAIJ,QAAQ,CAACI,WAAW,CAACC,OAAO,KAAKE,WAAW;QAC9CP,QAAQ,CAACI,WAAW,CAACC,OAAO,GAAGf,YAAY,CAACkB;YAC1C,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGnB,eAAea,YAAYC;YACzD,OAAOV,WAAWR,KAAKM,IAAI,CAACiB,aAAaD,SAASD,OAAOpB,QAAQI,YAAYY,YAAYC,QAAQG;QACnG;IACF;IACAR,QAAQ,CAACI,WAAW,CAACC,OAAO,CAACC;AAC/B;AAEA,MAAMK,eAAe,CAAC;AACtBV,OAAOC,OAAO,CAACU,IAAI,GAAG,CAACR,YAAYC;IACjC,IAAIM,YAAY,CAACP,WAAW,KAAKG,WAAWI,YAAY,CAACP,WAAW,GAAG,CAAC;IACxE,IAAIO,YAAY,CAACP,WAAW,CAACC,OAAO,KAAKE,WAAW;QAClDI,YAAY,CAACP,WAAW,CAACC,OAAO,GAAG,AAAC,CAAA;YAClC,MAAM,EAAEI,IAAI,EAAEC,WAAW,EAAE,GAAGnB,eAAea,YAAYC;YACzD,OAAOV,WAAWR,KAAKM,IAAI,CAACiB,aAAaD,SAASJ,SAASjB,QAAQ,sBAAsB;gBAAEyB,WAAW;YAAK,GAAGrB,YAAYY,YAAYC;QACxI,CAAA;IACF;AACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const resolve = require('resolve');
|
|
4
|
-
module.exports = function findDependency(identifier, target) {
|
|
5
|
-
const packagePath = resolve.sync(`${identifier}/package.json`);
|
|
6
|
-
const nodeModules = identifier[0] === '@' ? path.join(packagePath, '..', '..', '..') : path.join(packagePath, '..', '..');
|
|
7
|
-
const optionalDependencies = JSON.parse(fs.readFileSync(packagePath, 'utf8')).optionalDependencies;
|
|
8
|
-
const name = Object.keys(optionalDependencies).find((name)=>name.indexOf(target) >= 0);
|
|
9
|
-
return name ? {
|
|
10
|
-
name,
|
|
11
|
-
version: optionalDependencies[name],
|
|
12
|
-
nodeModules
|
|
13
|
-
} : null;
|
|
14
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/bindings/findDependency.cjs"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst resolve = require('resolve');\n\nmodule.exports = function 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"],"names":["path","require","fs","resolve","module","exports","findDependency","identifier","target","packagePath","sync","nodeModules","join","optionalDependencies","JSON","parse","readFileSync","name","Object","keys","find","indexOf","version"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AACrB,MAAMC,KAAKD,QAAQ;AACnB,MAAME,UAAUF,QAAQ;AAExBG,OAAOC,OAAO,GAAG,SAASC,eAAeC,UAAU,EAAEC,MAAM;IACzD,MAAMC,cAAcN,QAAQO,IAAI,CAAC,GAAGH,WAAW,aAAa,CAAC;IAC7D,MAAMI,cAAcJ,UAAU,CAAC,EAAE,KAAK,MAAMP,KAAKY,IAAI,CAACH,aAAa,MAAM,MAAM,QAAQT,KAAKY,IAAI,CAACH,aAAa,MAAM;IACpH,MAAMI,uBAAuBC,KAAKC,KAAK,CAACb,GAAGc,YAAY,CAACP,aAAa,SAASI,oBAAoB;IAClG,MAAMI,OAAOC,OAAOC,IAAI,CAACN,sBAAsBO,IAAI,CAAC,CAACH,OAASA,KAAKI,OAAO,CAACb,WAAW;IACtF,OAAOS,OAAO;QAAEA;QAAMK,SAAST,oBAAoB,CAACI,KAAK;QAAEN;IAAY,IAAI;AAC7E"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const installModule = require('install-module-linked');
|
|
3
|
-
const findDependency = require('./findDependency.cjs');
|
|
4
|
-
module.exports = function installBindings(identifier, target, callback) {
|
|
5
|
-
const { name, version, nodeModules } = findDependency(identifier, target);
|
|
6
|
-
const installString = version ? `${name}@${version}` : name;
|
|
7
|
-
installModule(installString, nodeModules, (err)=>{
|
|
8
|
-
console.log(`installed ${path.join(nodeModules, name)}${!err ? '' : ' with errors: ${err.message}'}`);
|
|
9
|
-
callback(err);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/typescript/ts-swc-transform/src/bindings/install.cjs"],"sourcesContent":["const path = require('path');\nconst installModule = require('install-module-linked');\nconst findDependency = require('./findDependency.cjs');\n\nmodule.exports = function installBindings(identifier, target, callback) {\n const { name, version, nodeModules } = findDependency(identifier, target);\n const installString = version ? `${name}@${version}` : name;\n\n installModule(installString, nodeModules, (err) => {\n console.log(`installed ${path.join(nodeModules, name)}${!err ? '' : ' with errors: ${err.message}'}`);\n callback(err);\n });\n};\n"],"names":["path","require","installModule","findDependency","module","exports","installBindings","identifier","target","callback","name","version","nodeModules","installString","err","console","log","join"],"mappings":"AAAA,MAAMA,OAAOC,QAAQ;AACrB,MAAMC,gBAAgBD,QAAQ;AAC9B,MAAME,iBAAiBF,QAAQ;AAE/BG,OAAOC,OAAO,GAAG,SAASC,gBAAgBC,UAAU,EAAEC,MAAM,EAAEC,QAAQ;IACpE,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,WAAW,EAAE,GAAGT,eAAeI,YAAYC;IAClE,MAAMK,gBAAgBF,UAAU,GAAGD,KAAK,CAAC,EAAEC,SAAS,GAAGD;IAEvDR,cAAcW,eAAeD,aAAa,CAACE;QACzCC,QAAQC,GAAG,CAAC,CAAC,UAAU,EAAEhB,KAAKiB,IAAI,CAACL,aAAaF,QAAQ,CAACI,MAAM,KAAK,gCAAgC;QACpGL,SAASK;IACX;AACF"}
|