@swc/core 1.2.215 → 1.2.218

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/CHANGELOG.md CHANGED
@@ -5,9 +5,86 @@
5
5
 
6
6
 
7
7
 
8
- - **(es/codegen)** Mark bigint as an item starting with number (#5207) ([387d5e4](https://github.com/swc-project/swc/commit/387d5e41db260893297b65d0fd9084f60c71443a))
8
+ - **(cli)** Emit sourcemap with file inputs (#5213) ([3e3be80](https://github.com/swc-project/swc/commit/3e3be80efda09ae494f8962947562b4411874061))
9
+
10
+
11
+ - **(es)** Fix resolving of symlinks (#5222) ([27cc45d](https://github.com/swc-project/swc/commit/27cc45d50fa035fbb7bbab307752ec55c8d5ed0c))
12
+
13
+
14
+ - **(es/lints)** Disallow duplicate export functions (#5234) ([c68d484](https://github.com/swc-project/swc/commit/c68d484305d3dfac3e14e45682c9d5ec10b49a45))
15
+
16
+
17
+ - **(es/minifier)** Fix size calculation of numbers (#5232) ([2e9c9be](https://github.com/swc-project/swc/commit/2e9c9bea1ad5c95a1e4867eba2f9bbe53c466fc7))
18
+
19
+
20
+ - **(es/modules)** Preserve order for ts import equals (#5215) ([6b1ce09](https://github.com/swc-project/swc/commit/6b1ce09b6f59e53a750a71e447a148aedcef8468))
21
+
22
+
23
+ - **(html/parser)** Fix span (#5209) ([b4daa30](https://github.com/swc-project/swc/commit/b4daa3005803be23676bec666bb8f8791f2472b3))
24
+
25
+
26
+ - **(html/parser)** Improve span (#5230) ([0f7646c](https://github.com/swc-project/swc/commit/0f7646cc4763f2d79d0b3cb4529a0c7ec7df94e8))
27
+
28
+
29
+ - **(testing)** Allow space in file names (#5237) ([de76868](https://github.com/swc-project/swc/commit/de76868cad88b9afe103a60331c1456a3f02e37e))- **general**: Fix(es/lints: Handle ts export import equals (#5225)
30
+
31
+ ([04de455](https://github.com/swc-project/swc/commit/04de455a9a34dbcbb193bffc9ab504c0e30e8706))
32
+
33
+ ### Features
34
+
35
+
36
+
37
+ - **(css/ast)** Make `raw` optional (#5211) ([b65a16c](https://github.com/swc-project/swc/commit/b65a16c7aa58bca57ad861ca015867f89fb80a79))
38
+
39
+
40
+ - **(es/lints)** Support `ignoreReadBeforeAssign` for `prefer-const` (#4933) ([d035648](https://github.com/swc-project/swc/commit/d0356489cb1dfae8e6ced8dd239643bf6f5b029d))
41
+
42
+
43
+ - **(html/ast)** Add `raw` to attributes (#5208) ([64237fa](https://github.com/swc-project/swc/commit/64237fa7fb9c95030f92892143f476c2573bed75))
44
+
45
+
46
+ - **(html/ast)** Add `raw` to doctype (#5198) ([945510a](https://github.com/swc-project/swc/commit/945510a6954db87f78dcffa888f49b630f4eb74d))
47
+
48
+
49
+ - **(html/minifier)** Compress more default attributes (#5182) ([625fc18](https://github.com/swc-project/swc/commit/625fc18da01643d81af535eefd4c636e5a632af0))
50
+
51
+
52
+ - **(html/minifier)** Improve minifier (#5227) ([1da6016](https://github.com/swc-project/swc/commit/1da6016da7db783a4207cfff480b057ea911006c))
9
53
 
10
- ## [1.2.215] - 2022-07-14
54
+
55
+ - **(node)** Use wasm as a fallback (#5233) ([1cebf62](https://github.com/swc-project/swc/commit/1cebf626e66b52f0fe325f679443d8243ab9eba3))
56
+
57
+
58
+ - **(plugin)** Pass `unresolved_mark` to plugins (#5212) ([92c0153](https://github.com/swc-project/swc/commit/92c0153cb56a6b3b7d6503216a14d5ed78df71dc))
59
+
60
+ ### Miscellaneous Tasks
61
+
62
+
63
+
64
+ - **(ci)** Fix publish script (#5241) ([66550d6](https://github.com/swc-project/swc/commit/66550d6e87582bb3cb34d18c0dffd8f33814d81d))
65
+
66
+
67
+ - **(visit)** Specify version of `swc_macros_common` (#5231) ([1aa0223](https://github.com/swc-project/swc/commit/1aa022361e7918f4077eacae6e51899eac007be5))- **general**: Typo (#5239) ([17f1cee](https://github.com/swc-project/swc/commit/17f1cee0a8132c79712c742f645e098df9309999))- **general**: Typo (#5238) ([df426d7](https://github.com/swc-project/swc/commit/df426d7b1d2ca74505051bfe78aa78a2a315e0ab))
68
+
69
+ ### Testing
70
+
71
+
72
+
73
+ - **(css/parser)** Add a test (#5228) ([8e5efb6](https://github.com/swc-project/swc/commit/8e5efb65d55706883663a25a0e281a4ef013001b))
74
+
75
+
76
+ - **(es/plugin)** Build plugins for e2e testing (#5210) ([cd94f0a](https://github.com/swc-project/swc/commit/cd94f0a2e9a7331073d20638031ae86d3308760e))
77
+
78
+
79
+ - **(plugin)** Fix e2e tests on windows (#5216) ([f1ba332](https://github.com/swc-project/swc/commit/f1ba3327cfcc37534484362293cfac19587110da))
80
+
81
+ ### Build
82
+
83
+
84
+
85
+ - **(node)** Use explicit list for package files (#5229) ([b01b6cf](https://github.com/swc-project/swc/commit/b01b6cf57ee2dcd33886ba9196f364bcb9273afe))
86
+
87
+ ## [1.2.216] - 2022-07-14
11
88
 
12
89
  ### Bug Fixes
13
90
 
@@ -16,6 +93,9 @@
16
93
  - **(es)** Check the syntax context of `arguments` (#5174) ([375774d](https://github.com/swc-project/swc/commit/375774d31e690142faeb8422fed4cc996bf1de16))
17
94
 
18
95
 
96
+ - **(es/codegen)** Mark bigint as an item starting with number (#5207) ([387d5e4](https://github.com/swc-project/swc/commit/387d5e41db260893297b65d0fd9084f60c71443a))
97
+
98
+
19
99
  - **(es/fixer)** Handle invalid numeric literals (#5201) ([436f620](https://github.com/swc-project/swc/commit/436f6200bc05d1d88c9b3fb991f793ed308f607b))
20
100
 
21
101
 
@@ -45,6 +125,9 @@
45
125
 
46
126
  - **(ci)** Disable plugin tests while publishing ([31bbf2d](https://github.com/swc-project/swc/commit/31bbf2ddbbd2babd5f2431ed39a6bcb464dbb7c4))
47
127
 
128
+
129
+ - **(ci)** Disable some tests ([ff949b0](https://github.com/swc-project/swc/commit/ff949b0bc7df790a6d1df11f2129d589b0dd46b8))
130
+
48
131
  ### Testing
49
132
 
50
133
 
package/index.js CHANGED
@@ -6,9 +6,21 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
6
6
  if (k2 === undefined) k2 = k;
7
7
  o[k2] = m[k];
8
8
  }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
9
14
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
16
  };
17
+ var __importStar = (this && this.__importStar) || function (mod) {
18
+ if (mod && mod.__esModule) return mod;
19
+ var result = {};
20
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ __setModuleDefault(result, mod);
22
+ return result;
23
+ };
12
24
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
25
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
26
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,9 +46,27 @@ exports.DEFAULT_EXTENSIONS = exports.getBinaryMetadata = exports.__experimental_
34
46
  const path_1 = require("path");
35
47
  __exportStar(require("./types"), exports);
36
48
  const spack_1 = require("./spack");
49
+ const assert = __importStar(require("assert"));
37
50
  // Allow overrides to the location of the .node binding file
38
51
  const bindingsOverride = process.env["SWC_BINARY_PATH"];
39
- const bindings = !!bindingsOverride ? require((0, path_1.resolve)(bindingsOverride)) : require('./binding');
52
+ let fallbackBindings;
53
+ const bindings = (() => {
54
+ let binding;
55
+ try {
56
+ binding = !!bindingsOverride ? require((0, path_1.resolve)(bindingsOverride)) : require('./binding');
57
+ // If native binding loaded successfully, it should return proper target triple constant.
58
+ const triple = binding.getTargetTriple();
59
+ assert.ok(triple, 'Failed to read target triple from native binary.');
60
+ return binding;
61
+ }
62
+ catch (_) {
63
+ // postinstall supposed to install `@swc/wasm` already
64
+ fallbackBindings = require('@swc/wasm');
65
+ }
66
+ finally {
67
+ return binding;
68
+ }
69
+ })();
40
70
  /**
41
71
  * Version of the swc binding.
42
72
  */
@@ -54,16 +84,34 @@ exports.plugins = plugins;
54
84
  class Compiler {
55
85
  minify(src, opts) {
56
86
  return __awaiter(this, void 0, void 0, function* () {
87
+ if (!bindings && !!fallbackBindings) {
88
+ throw new Error('Fallback bindings does not support this interface yet.');
89
+ }
90
+ else if (!bindings) {
91
+ throw new Error('Bindings not found.');
92
+ }
57
93
  return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
58
94
  });
59
95
  }
60
96
  minifySync(src, opts) {
61
- return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
97
+ if (bindings) {
98
+ return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
99
+ }
100
+ else if (fallbackBindings) {
101
+ return fallbackBindings.minifySync(src, opts);
102
+ }
103
+ throw new Error('Bindings not found.');
62
104
  }
63
105
  parse(src, options, filename) {
64
106
  return __awaiter(this, void 0, void 0, function* () {
65
107
  options = options || { syntax: "ecmascript" };
66
108
  options.syntax = options.syntax || "ecmascript";
109
+ if (!bindings && !!fallbackBindings) {
110
+ throw new Error('Fallback bindings does not support this interface yet.');
111
+ }
112
+ else if (!bindings) {
113
+ throw new Error('Bindings not found.');
114
+ }
67
115
  const res = yield bindings.parse(src, toBuffer(options), filename);
68
116
  return JSON.parse(res);
69
117
  });
@@ -71,12 +119,24 @@ class Compiler {
71
119
  parseSync(src, options, filename) {
72
120
  options = options || { syntax: "ecmascript" };
73
121
  options.syntax = options.syntax || "ecmascript";
74
- return JSON.parse(bindings.parseSync(src, toBuffer(options), filename));
122
+ if (bindings) {
123
+ return JSON.parse(bindings.parseSync(src, toBuffer(options), filename));
124
+ }
125
+ else if (fallbackBindings) {
126
+ return JSON.parse(fallbackBindings.parseSync(src, options));
127
+ }
128
+ throw new Error('Bindings not found.');
75
129
  }
76
130
  parseFile(path, options) {
77
131
  return __awaiter(this, void 0, void 0, function* () {
78
132
  options = options || { syntax: "ecmascript" };
79
133
  options.syntax = options.syntax || "ecmascript";
134
+ if (!bindings && !!fallbackBindings) {
135
+ throw new Error('Fallback bindings does not support filesystem access.');
136
+ }
137
+ else if (!bindings) {
138
+ throw new Error('Bindings not found.');
139
+ }
80
140
  const res = yield bindings.parseFile(path, toBuffer(options));
81
141
  return JSON.parse(res);
82
142
  });
@@ -84,6 +144,12 @@ class Compiler {
84
144
  parseFileSync(path, options) {
85
145
  options = options || { syntax: "ecmascript" };
86
146
  options.syntax = options.syntax || "ecmascript";
147
+ if (!bindings && !!fallbackBindings) {
148
+ throw new Error('Fallback bindings does not support filesystem access');
149
+ }
150
+ else if (!bindings) {
151
+ throw new Error('Bindings not found.');
152
+ }
87
153
  return JSON.parse(bindings.parseFileSync(path, toBuffer(options)));
88
154
  }
89
155
  /**
@@ -93,6 +159,12 @@ class Compiler {
93
159
  print(m, options) {
94
160
  return __awaiter(this, void 0, void 0, function* () {
95
161
  options = options || {};
162
+ if (!bindings && !!fallbackBindings) {
163
+ throw new Error('Fallback bindings does not support this interface yet.');
164
+ }
165
+ else if (!bindings) {
166
+ throw new Error('Bindings not found.');
167
+ }
96
168
  return bindings.print(JSON.stringify(m), toBuffer(options));
97
169
  });
98
170
  }
@@ -102,11 +174,23 @@ class Compiler {
102
174
  */
103
175
  printSync(m, options) {
104
176
  options = options || {};
105
- return bindings.printSync(JSON.stringify(m), toBuffer(options));
177
+ if (bindings) {
178
+ return bindings.printSync(JSON.stringify(m), toBuffer(options));
179
+ }
180
+ else if (fallbackBindings) {
181
+ return fallbackBindings.printSync(JSON.stringify(m), options);
182
+ }
183
+ throw new Error('Bindings not found.');
106
184
  }
107
185
  transform(src, options) {
108
186
  var _a, _b, _c;
109
187
  return __awaiter(this, void 0, void 0, function* () {
188
+ if (!bindings && !!fallbackBindings) {
189
+ throw new Error('Fallback bindings does not support this interface yet.');
190
+ }
191
+ else if (!bindings) {
192
+ throw new Error('Bindings not found.');
193
+ }
110
194
  const isModule = typeof src !== "string";
111
195
  options = options || {};
112
196
  if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
@@ -129,16 +213,28 @@ class Compiler {
129
213
  if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
130
214
  options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
131
215
  }
132
- const { plugin } = options, newOptions = __rest(options, ["plugin"]);
133
- if (plugin) {
134
- const m = typeof src === "string" ? this.parseSync(src, (_c = options === null || options === void 0 ? void 0 : options.jsc) === null || _c === void 0 ? void 0 : _c.parser, options.filename) : src;
135
- return this.transformSync(plugin(m), newOptions);
216
+ if (bindings) {
217
+ const { plugin } = options, newOptions = __rest(options, ["plugin"]);
218
+ if (plugin) {
219
+ const m = typeof src === "string" ? this.parseSync(src, (_c = options === null || options === void 0 ? void 0 : options.jsc) === null || _c === void 0 ? void 0 : _c.parser, options.filename) : src;
220
+ return this.transformSync(plugin(m), newOptions);
221
+ }
222
+ return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
223
+ }
224
+ else if (fallbackBindings) {
225
+ return fallbackBindings.transformSync(src, options);
136
226
  }
137
- return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
227
+ throw new Error("Bindings not found");
138
228
  }
139
229
  transformFile(path, options) {
140
230
  var _a, _b, _c;
141
231
  return __awaiter(this, void 0, void 0, function* () {
232
+ if (!bindings && !!fallbackBindings) {
233
+ throw new Error('Fallback bindings does not support filesystem access.');
234
+ }
235
+ else if (!bindings) {
236
+ throw new Error('Bindings not found.');
237
+ }
142
238
  options = options || {};
143
239
  if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
144
240
  options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
@@ -154,6 +250,12 @@ class Compiler {
154
250
  }
155
251
  transformFileSync(path, options) {
156
252
  var _a, _b, _c;
253
+ if (!bindings && !!fallbackBindings) {
254
+ throw new Error('Fallback bindings does not support filesystem access.');
255
+ }
256
+ else if (!bindings) {
257
+ throw new Error('Bindings not found.');
258
+ }
157
259
  options = options || {};
158
260
  if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
159
261
  options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
@@ -168,6 +270,12 @@ class Compiler {
168
270
  }
169
271
  bundle(options) {
170
272
  return __awaiter(this, void 0, void 0, function* () {
273
+ if (!bindings && !!fallbackBindings) {
274
+ throw new Error('Fallback bindings does not support this interface yet.');
275
+ }
276
+ else if (!bindings) {
277
+ throw new Error('Bindings not found.');
278
+ }
171
279
  const opts = yield (0, spack_1.compileBundleOptions)(options);
172
280
  if (Array.isArray(opts)) {
173
281
  const all = yield Promise.all(opts.map((opt) => __awaiter(this, void 0, void 0, function* () {
@@ -258,8 +366,12 @@ exports.minifySync = minifySync;
258
366
  * or bug report at https://github.com/swc-project/swc/discussions.
259
367
  */
260
368
  function __experimental_registerGlobalTraceConfig(traceConfig) {
261
- if (traceConfig.type === 'traceEvent') {
262
- bindings.initCustomTraceSubscriber(traceConfig.fileName);
369
+ // Do not raise error if binding doesn't exists - fallback binding will not support
370
+ // this ever.
371
+ if (bindings) {
372
+ if (traceConfig.type === 'traceEvent') {
373
+ bindings.initCustomTraceSubscriber(traceConfig.fileName);
374
+ }
263
375
  }
264
376
  }
265
377
  exports.__experimental_registerGlobalTraceConfig = __experimental_registerGlobalTraceConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swc/core",
3
- "version": "1.2.215",
3
+ "version": "1.2.218",
4
4
  "description": "Super-fast alternative for babel",
5
5
  "homepage": "https://swc.rs",
6
6
  "main": "./index.js",
@@ -54,6 +54,7 @@
54
54
  "scripts": {
55
55
  "changelog": "git cliff --output CHANGELOG.md",
56
56
  "prepare": "husky install && git config feature.manyFiles true && node ./crates/swc_ecma_preset_env/scripts/copy-data.js",
57
+ "postinstall": "node postinstall.js",
57
58
  "artifacts": "napi artifacts --dist scripts/npm",
58
59
  "prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tagstyle npm",
59
60
  "pack": "wasm-pack",
@@ -136,18 +137,38 @@
136
137
  "url": "https://opencollective.com/swc"
137
138
  },
138
139
  "optionalDependencies": {
139
- "@swc/core-win32-x64-msvc": "1.2.216",
140
- "@swc/core-darwin-x64": "1.2.216",
141
- "@swc/core-linux-x64-gnu": "1.2.216",
142
- "@swc/core-linux-x64-musl": "1.2.216",
143
- "@swc/core-freebsd-x64": "1.2.216",
144
- "@swc/core-win32-ia32-msvc": "1.2.216",
145
- "@swc/core-linux-arm64-gnu": "1.2.216",
146
- "@swc/core-linux-arm-gnueabihf": "1.2.216",
147
- "@swc/core-darwin-arm64": "1.2.216",
148
- "@swc/core-android-arm64": "1.2.216",
149
- "@swc/core-linux-arm64-musl": "1.2.216",
150
- "@swc/core-win32-arm64-msvc": "1.2.216",
151
- "@swc/core-android-arm-eabi": "1.2.216"
152
- }
140
+ "@swc/core-win32-x64-msvc": "1.2.218",
141
+ "@swc/core-darwin-x64": "1.2.218",
142
+ "@swc/core-linux-x64-gnu": "1.2.218",
143
+ "@swc/core-linux-x64-musl": "1.2.218",
144
+ "@swc/core-freebsd-x64": "1.2.218",
145
+ "@swc/core-win32-ia32-msvc": "1.2.218",
146
+ "@swc/core-linux-arm64-gnu": "1.2.218",
147
+ "@swc/core-linux-arm-gnueabihf": "1.2.218",
148
+ "@swc/core-darwin-arm64": "1.2.218",
149
+ "@swc/core-android-arm64": "1.2.218",
150
+ "@swc/core-linux-arm64-musl": "1.2.218",
151
+ "@swc/core-win32-arm64-msvc": "1.2.218",
152
+ "@swc/core-android-arm-eabi": "1.2.218"
153
+ },
154
+ "files": [
155
+ "CHANGELOG.md",
156
+ "Visitor.d.ts",
157
+ "index.d.ts",
158
+ "spack.js",
159
+ "util.d.ts",
160
+ "LICENSE",
161
+ "Visitor.js",
162
+ "binding.d.ts",
163
+ "index.js",
164
+ "run_swcx.js",
165
+ "types.d.ts",
166
+ "util.js",
167
+ "README.md",
168
+ "binding.js",
169
+ "package.json",
170
+ "spack.d.ts",
171
+ "types.js",
172
+ "postinstall.js"
173
+ ]
153
174
  }
package/postinstall.js ADDED
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ /**
32
+ * A postinstall script runs after `@swc/core` is installed.
33
+ *
34
+ * It checks if corresponding optional dependencies for native binary is installed and can be loaded properly.
35
+ * If it fails, it'll internally try to install `@swc/wasm` as fallback.
36
+ */
37
+ const fs_1 = require("fs");
38
+ const assert = __importStar(require("assert"));
39
+ const path = __importStar(require("path"));
40
+ const child_process = __importStar(require("child_process"));
41
+ const fs = __importStar(require("fs"));
42
+ function removeRecursive(dir) {
43
+ for (const entry of fs.readdirSync(dir)) {
44
+ const entryPath = path.join(dir, entry);
45
+ let stats;
46
+ try {
47
+ stats = fs.lstatSync(entryPath);
48
+ }
49
+ catch (_a) {
50
+ continue; // Guard against https://github.com/nodejs/node/issues/4760
51
+ }
52
+ if (stats.isDirectory())
53
+ removeRecursive(entryPath);
54
+ else
55
+ fs.unlinkSync(entryPath);
56
+ }
57
+ fs.rmdirSync(dir);
58
+ }
59
+ /**
60
+ * Trying to validate @swc/core's native binary installation, then installs if it is not supported.
61
+ */
62
+ const validateBinary = () => __awaiter(void 0, void 0, void 0, function* () {
63
+ var _a;
64
+ try {
65
+ const { name } = require(path.resolve(process.env.INIT_CWD, 'package.json'));
66
+ if (name === '@swc/core') {
67
+ return;
68
+ }
69
+ }
70
+ catch (_) {
71
+ return;
72
+ }
73
+ // TODO: We do not take care of the case if user try to install with `--no-optional`.
74
+ // For now, it is considered as deliberate decision.
75
+ let binding;
76
+ try {
77
+ binding = require('./binding');
78
+ // Check if binding binary actually works.
79
+ // For the latest version, checks target triple. If it's old version doesn't have target triple, use parseSync instead.
80
+ const triple = binding.getTargetTriple ? binding.getTargetTriple() : binding.parseSync('console.log()', Buffer.from(JSON.stringify({ syntax: "ecmascript" })));
81
+ assert.ok(triple, 'Failed to read target triple from native binary.');
82
+ }
83
+ catch (error) {
84
+ // if error is unsupported architecture, ignore to display.
85
+ if (!((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Unsupported architecture'))) {
86
+ console.warn(error);
87
+ }
88
+ console.warn(`@swc/core was not able to resolve native bindings installation. It'll try to use @swc/wasm as fallback instead.`);
89
+ }
90
+ if (!!binding) {
91
+ return;
92
+ }
93
+ // User choose to override the binary installation. Skip remanining validation.
94
+ if (!!process.env["SWC_BINARY_PATH"]) {
95
+ console.warn(`@swc/core could not resolve native bindings installation, but found manual override config SWC_BINARY_PATH specified. Skipping remaning validation.`);
96
+ return;
97
+ }
98
+ // Check if top-level package.json installs @swc/wasm separately already
99
+ let wasmBinding;
100
+ try {
101
+ wasmBinding = require.resolve(`@swc/wasm`);
102
+ }
103
+ catch (_) {
104
+ }
105
+ if (!!wasmBinding && (0, fs_1.existsSync)(wasmBinding)) {
106
+ return;
107
+ }
108
+ const env = Object.assign(Object.assign({}, process.env), { npm_config_global: undefined });
109
+ const { version } = require(path.join(path.dirname(require.resolve('@swc/core')), 'package.json'));
110
+ // We want to place @swc/wasm next to the @swc/core as if normal installation was done,
111
+ // but can't directly set cwd to INIT_CWD as npm seems to acquire lock to the working dir.
112
+ // Instead, create a temporary inner and move it out.
113
+ const coreDir = path.dirname(require.resolve('@swc/core'));
114
+ const installDir = path.join(coreDir, 'npm-install');
115
+ try {
116
+ fs.mkdirSync(installDir);
117
+ fs.writeFileSync(path.join(installDir, 'package.json'), '{}');
118
+ // Instead of carrying over own dependencies to download & resolve package which increases installation sizes of `@swc/core`,
119
+ // assume & relies on system's npm installation.
120
+ child_process.execSync(`npm install --no-save --loglevel=error --prefer-offline --no-audit --progress=false @swc/wasm@${version}`, { cwd: installDir, stdio: 'pipe', env });
121
+ const installedBinPath = path.join(installDir, 'node_modules', `@swc/wasm`);
122
+ // INIT_CWD is injected via npm. If it doesn't exists, can't proceed.
123
+ fs.renameSync(installedBinPath, path.resolve(process.env.INIT_CWD, 'node_modules', `@swc/wasm`));
124
+ }
125
+ catch (error) {
126
+ console.error(error);
127
+ console.error(`Failed to install fallback @swc/wasm@${version}. @swc/core will not properly.
128
+ Please install @swc/wasm manually, or retry whole installation.
129
+ If there are unexpected errors, please report at https://github.com/swc-project/swc/issues`);
130
+ }
131
+ finally {
132
+ try {
133
+ removeRecursive(installDir);
134
+ }
135
+ catch (_) {
136
+ // Gracefully ignore any failures. This'll make few leftover files but it shouldn't block installation.
137
+ }
138
+ }
139
+ });
140
+ validateBinary().catch((error) => {
141
+ // for now just throw the error as-is.
142
+ throw error;
143
+ });
package/.prettierignore DELETED
@@ -1,63 +0,0 @@
1
- # Bundler cache files
2
- .cache/
3
-
4
- # Generated
5
- CHANGELOG.md
6
- target/
7
- node_modules/
8
-
9
- # Space sensitive
10
- crates/jsdoc/tests/
11
- crates/swc/tests/errors/
12
- crates/swc/tests/projects/
13
- crates/swc/tests/serde/
14
- crates/swc_css_codegen/tests/
15
- crates/swc_css_lints/tests/
16
- crates/swc_css_minifier/tests/
17
- crates/swc_css_parser/tests/
18
- crates/swc_css_prefixer/tests/
19
- crates/swc_ecma_codegen/tests/
20
- crates/swc_ecma_lints/tests/
21
- crates/swc_ecma_parser/tests/
22
- crates/swc_estree_compat/tests/
23
- crates/swc_html_codegen/tests/
24
- crates/swc_html_minifier/tests/
25
- crates/swc_html_parser/tests/
26
- crates/swc_webpack_ast/tests/
27
-
28
- # Generated by testing system
29
- output/
30
- output.js
31
- output.*.js
32
- output.full.js
33
- output.mjs
34
- index.g.js
35
- output.json
36
- output.ts
37
- output.css
38
- output.min.css
39
- output.html
40
- output.min.html
41
-
42
- # Generated
43
- crates/swc_ecma_preset_env/data
44
- crates/swc_ecma_preset_env/**/*.json
45
- crates/swc/tests/tsc-references
46
- scripts/npm
47
-
48
- # Downloaded
49
- benches/
50
-
51
- # TODO: Enable formatting
52
- helpers/
53
- packages/swc-helpers
54
- node-swc/__tests__
55
- node-swc/src
56
- node-swc/tests
57
- crates/swc/tests/srcmap/
58
- crates/swc/tests/stacktrace/
59
-
60
-
61
- # git submodules
62
- crates/swc_ecma_parser/tests/test262-parser
63
- crates/swc_html_parser/tests/html5lib-tests
package/.prettierrc.json DELETED
@@ -1 +0,0 @@
1
- {}
package/babel.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Options, ParseOptions } from './types';
2
- export declare type BabelifyOptions = {
3
- /**
4
- * If it's not specified, transforms will not be applied.
5
- *
6
- * The parser config should be provided via this property when transformations are enabled.
7
- */
8
- transforms: Options;
9
- } | {
10
- /**
11
- * Option for the parser.
12
- */
13
- parser: ParseOptions;
14
- };
package/babel.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/run_swcx.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};