@swc/core 1.7.18 → 1.7.19

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/binding.d.ts CHANGED
@@ -2,91 +2,55 @@
2
2
  /* eslint-disable */
3
3
 
4
4
  export class Compiler {
5
- constructor();
5
+ constructor()
6
6
  }
7
- export type JsCompiler = Compiler;
8
-
9
- export function bundle(
10
- confItems: Buffer,
11
- signal?: AbortSignal | undefined | null
12
- ): Promise<{ [index: string]: { code: string; map?: string } }>;
13
-
14
- export function getTargetTriple(): string;
15
-
16
- export function initCustomTraceSubscriber(
17
- traceOutFilePath?: string | undefined | null
18
- ): void;
19
-
20
- export function minify(
21
- code: Buffer,
22
- opts: Buffer,
23
- signal?: AbortSignal | undefined | null
24
- ): Promise<TransformOutput>;
25
-
26
- export function minifySync(code: Buffer, opts: Buffer): TransformOutput;
27
-
28
- export function parse(
29
- src: string,
30
- options: Buffer,
31
- filename?: string | undefined | null,
32
- signal?: AbortSignal | undefined | null
33
- ): Promise<string>;
34
-
35
- export function parseFile(
36
- path: string,
37
- options: Buffer,
38
- signal?: AbortSignal | undefined | null
39
- ): Promise<string>;
40
-
41
- export function parseFileSync(path: string, opts: Buffer): string;
42
-
43
- export function parseSync(
44
- src: string,
45
- opts: Buffer,
46
- filename?: string | undefined | null
47
- ): string;
48
-
49
- export function print(
50
- programJson: string,
51
- options: Buffer,
52
- signal?: AbortSignal | undefined | null
53
- ): Promise<TransformOutput>;
54
-
55
- export function printSync(program: string, options: Buffer): TransformOutput;
56
-
57
- export function transform(
58
- src: string,
59
- isModule: boolean,
60
- options: Buffer,
61
- signal?: AbortSignal | undefined | null
62
- ): Promise<TransformOutput>;
63
-
64
- export function transformFile(
65
- src: string,
66
- isModule: boolean,
67
- options: Buffer,
68
- signal?: AbortSignal | undefined | null
69
- ): Promise<TransformOutput>;
70
-
71
- export function transformFileSync(
72
- s: string,
73
- isModule: boolean,
74
- opts: Buffer
75
- ): TransformOutput;
7
+ export type JsCompiler = Compiler
8
+
9
+ export declare function bundle(confItems: Buffer, signal?: AbortSignal | undefined | null): Promise<{ [index: string]: { code: string, map?: string } }>
10
+
11
+ export declare function getTargetTriple(): string
12
+
13
+ export declare function initCustomTraceSubscriber(traceOutFilePath?: string | undefined | null): void
14
+
15
+ export declare function minify(code: Buffer, opts: Buffer, extras: NapiMinifyExtra, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
16
+
17
+ export declare function minifySync(code: Buffer, opts: Buffer, extras: NapiMinifyExtra): TransformOutput
18
+
19
+ export interface NapiMinifyExtra {
20
+ mangleNameCache?: object
21
+ }
22
+
23
+ export declare function newMangleNameCache(): object
24
+
25
+ export declare function parse(src: string, options: Buffer, filename?: string | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
26
+
27
+ export declare function parseFile(path: string, options: Buffer, signal?: AbortSignal | undefined | null): Promise<string>
28
+
29
+ export declare function parseFileSync(path: string, opts: Buffer): string
30
+
31
+ export declare function parseSync(src: string, opts: Buffer, filename?: string | undefined | null): string
32
+
33
+ export declare function print(programJson: string, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
34
+
35
+ export declare function printSync(program: string, options: Buffer): TransformOutput
36
+
37
+ export declare function transform(src: string, isModule: boolean, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
38
+
39
+ export declare function transformFile(src: string, isModule: boolean, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
40
+
41
+ export declare function transformFileSync(s: string, isModule: boolean, opts: Buffer): TransformOutput
76
42
 
77
43
  export interface TransformOutput {
78
- code: string;
79
- map?: string;
44
+ code: string
45
+ map?: string
46
+ output?: string
80
47
  }
81
48
 
82
49
  /** Hack for `Type Generation` */
83
50
  export interface TransformOutput {
84
- code: string;
85
- map?: string;
51
+ code: string
52
+ map?: string
86
53
  }
87
54
 
88
- export function transformSync(
89
- s: string,
90
- isModule: boolean,
91
- opts: Buffer
92
- ): TransformOutput;
55
+ export declare function transformSync(s: string, isModule: boolean, opts: Buffer): TransformOutput
56
+
package/binding.js CHANGED
@@ -4,358 +4,352 @@
4
4
 
5
5
  const { readFileSync } = require('fs')
6
6
 
7
- let nativeBinding = null;
8
- const loadErrors = [];
7
+ let nativeBinding = null
8
+ const loadErrors = []
9
9
 
10
10
  const isMusl = () => {
11
- let musl = false;
12
- if (process.platform === "linux") {
13
- musl = isMuslFromFilesystem();
14
- if (musl === null) {
15
- musl = isMuslFromReport();
16
- }
17
- if (musl === null) {
18
- musl = isMuslFromChildProcess();
19
- }
11
+ let musl = false
12
+ if (process.platform === 'linux') {
13
+ musl = isMuslFromFilesystem()
14
+ if (musl === null) {
15
+ musl = isMuslFromReport()
20
16
  }
21
- return musl;
22
- };
17
+ if (musl === null) {
18
+ musl = isMuslFromChildProcess()
19
+ }
20
+ }
21
+ return musl
22
+ }
23
23
 
24
- const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
24
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
25
25
 
26
26
  const isMuslFromFilesystem = () => {
27
- try {
28
- return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
29
- } catch {
30
- return null;
31
- }
32
- };
27
+ try {
28
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
29
+ } catch {
30
+ return null
31
+ }
32
+ }
33
33
 
34
34
  const isMuslFromReport = () => {
35
- const report =
36
- typeof process.report.getReport === "function"
37
- ? process.report.getReport()
38
- : null;
39
- if (!report) {
40
- return null;
41
- }
42
- if (report.header && report.header.glibcVersionRuntime) {
43
- return false;
35
+ const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
36
+ if (!report) {
37
+ return null
38
+ }
39
+ if (report.header && report.header.glibcVersionRuntime) {
40
+ return false
41
+ }
42
+ if (Array.isArray(report.sharedObjects)) {
43
+ if (report.sharedObjects.some(isFileMusl)) {
44
+ return true
44
45
  }
45
- if (Array.isArray(report.sharedObjects)) {
46
- if (report.sharedObjects.some(isFileMusl)) {
47
- return true;
48
- }
49
- }
50
- return false;
51
- };
46
+ }
47
+ return false
48
+ }
52
49
 
53
50
  const isMuslFromChildProcess = () => {
51
+ try {
52
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
53
+ } catch (e) {
54
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
55
+ return false
56
+ }
57
+ }
58
+
59
+ function requireNative() {
60
+ if (process.platform === 'android') {
61
+ if (process.arch === 'arm64') {
62
+ try {
63
+ return require('./swc.android-arm64.node')
64
+ } catch (e) {
65
+ loadErrors.push(e)
66
+ }
67
+ try {
68
+ return require('@swc/core-android-arm64')
69
+ } catch (e) {
70
+ loadErrors.push(e)
71
+ }
72
+
73
+ } else if (process.arch === 'arm') {
74
+ try {
75
+ return require('./swc.android-arm-eabi.node')
76
+ } catch (e) {
77
+ loadErrors.push(e)
78
+ }
79
+ try {
80
+ return require('@swc/core-android-arm-eabi')
81
+ } catch (e) {
82
+ loadErrors.push(e)
83
+ }
84
+
85
+ } else {
86
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
87
+ }
88
+ } else if (process.platform === 'win32') {
89
+ if (process.arch === 'x64') {
90
+ try {
91
+ return require('./swc.win32-x64-msvc.node')
92
+ } catch (e) {
93
+ loadErrors.push(e)
94
+ }
95
+ try {
96
+ return require('@swc/core-win32-x64-msvc')
97
+ } catch (e) {
98
+ loadErrors.push(e)
99
+ }
100
+
101
+ } else if (process.arch === 'ia32') {
102
+ try {
103
+ return require('./swc.win32-ia32-msvc.node')
104
+ } catch (e) {
105
+ loadErrors.push(e)
106
+ }
107
+ try {
108
+ return require('@swc/core-win32-ia32-msvc')
109
+ } catch (e) {
110
+ loadErrors.push(e)
111
+ }
112
+
113
+ } else if (process.arch === 'arm64') {
114
+ try {
115
+ return require('./swc.win32-arm64-msvc.node')
116
+ } catch (e) {
117
+ loadErrors.push(e)
118
+ }
119
+ try {
120
+ return require('@swc/core-win32-arm64-msvc')
121
+ } catch (e) {
122
+ loadErrors.push(e)
123
+ }
124
+
125
+ } else {
126
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
127
+ }
128
+ } else if (process.platform === 'darwin') {
54
129
  try {
55
- return require("child_process")
56
- .execSync("ldd --version", { encoding: "utf8" })
57
- .includes("musl");
58
- } catch (e) {
59
- // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
60
- return false;
130
+ return require('./swc.darwin-universal.node')
131
+ } catch (e) {
132
+ loadErrors.push(e)
133
+ }
134
+ try {
135
+ return require('@swc/core-darwin-universal')
136
+ } catch (e) {
137
+ loadErrors.push(e)
138
+ }
139
+
140
+ if (process.arch === 'x64') {
141
+ try {
142
+ return require('./swc.darwin-x64.node')
143
+ } catch (e) {
144
+ loadErrors.push(e)
145
+ }
146
+ try {
147
+ return require('@swc/core-darwin-x64')
148
+ } catch (e) {
149
+ loadErrors.push(e)
150
+ }
151
+
152
+ } else if (process.arch === 'arm64') {
153
+ try {
154
+ return require('./swc.darwin-arm64.node')
155
+ } catch (e) {
156
+ loadErrors.push(e)
157
+ }
158
+ try {
159
+ return require('@swc/core-darwin-arm64')
160
+ } catch (e) {
161
+ loadErrors.push(e)
162
+ }
163
+
164
+ } else {
165
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
61
166
  }
62
- };
167
+ } else if (process.platform === 'freebsd') {
168
+ if (process.arch === 'x64') {
169
+ try {
170
+ return require('./swc.freebsd-x64.node')
171
+ } catch (e) {
172
+ loadErrors.push(e)
173
+ }
174
+ try {
175
+ return require('@swc/core-freebsd-x64')
176
+ } catch (e) {
177
+ loadErrors.push(e)
178
+ }
63
179
 
64
- function requireNative() {
65
- if (process.platform === "android") {
66
- if (process.arch === "arm64") {
67
- try {
68
- return require("./swc.android-arm64.node");
69
- } catch (e) {
70
- loadErrors.push(e);
71
- }
72
- try {
73
- return require("@swc/core-android-arm64");
74
- } catch (e) {
75
- loadErrors.push(e);
76
- }
77
- } else if (process.arch === "arm") {
78
- try {
79
- return require("./swc.android-arm-eabi.node");
80
- } catch (e) {
81
- loadErrors.push(e);
82
- }
83
- try {
84
- return require("@swc/core-android-arm-eabi");
85
- } catch (e) {
86
- loadErrors.push(e);
87
- }
88
- } else {
89
- loadErrors.push(
90
- new Error(`Unsupported architecture on Android ${process.arch}`)
91
- );
92
- }
93
- } else if (process.platform === "win32") {
94
- if (process.arch === "x64") {
95
- try {
96
- return require("./swc.win32-x64-msvc.node");
97
- } catch (e) {
98
- loadErrors.push(e);
99
- }
100
- try {
101
- return require("@swc/core-win32-x64-msvc");
102
- } catch (e) {
103
- loadErrors.push(e);
104
- }
105
- } else if (process.arch === "ia32") {
106
- try {
107
- return require("./swc.win32-ia32-msvc.node");
108
- } catch (e) {
109
- loadErrors.push(e);
110
- }
111
- try {
112
- return require("@swc/core-win32-ia32-msvc");
113
- } catch (e) {
114
- loadErrors.push(e);
115
- }
116
- } else if (process.arch === "arm64") {
117
- try {
118
- return require("./swc.win32-arm64-msvc.node");
119
- } catch (e) {
120
- loadErrors.push(e);
121
- }
122
- try {
123
- return require("@swc/core-win32-arm64-msvc");
124
- } catch (e) {
125
- loadErrors.push(e);
126
- }
127
- } else {
128
- loadErrors.push(
129
- new Error(
130
- `Unsupported architecture on Windows: ${process.arch}`
131
- )
132
- );
133
- }
134
- } else if (process.platform === "darwin") {
180
+ } else if (process.arch === 'arm64') {
181
+ try {
182
+ return require('./swc.freebsd-arm64.node')
183
+ } catch (e) {
184
+ loadErrors.push(e)
185
+ }
186
+ try {
187
+ return require('@swc/core-freebsd-arm64')
188
+ } catch (e) {
189
+ loadErrors.push(e)
190
+ }
191
+
192
+ } else {
193
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
194
+ }
195
+ } else if (process.platform === 'linux') {
196
+ if (process.arch === 'x64') {
197
+ if (isMusl()) {
135
198
  try {
136
- return require("./swc.darwin-universal.node");
137
- } catch (e) {
138
- loadErrors.push(e);
139
- }
199
+ return require('./swc.linux-x64-musl.node')
200
+ } catch (e) {
201
+ loadErrors.push(e)
202
+ }
203
+ try {
204
+ return require('@swc/core-linux-x64-musl')
205
+ } catch (e) {
206
+ loadErrors.push(e)
207
+ }
208
+
209
+ } else {
210
+ try {
211
+ return require('./swc.linux-x64-gnu.node')
212
+ } catch (e) {
213
+ loadErrors.push(e)
214
+ }
215
+ try {
216
+ return require('@swc/core-linux-x64-gnu')
217
+ } catch (e) {
218
+ loadErrors.push(e)
219
+ }
220
+
221
+ }
222
+ } else if (process.arch === 'arm64') {
223
+ if (isMusl()) {
224
+ try {
225
+ return require('./swc.linux-arm64-musl.node')
226
+ } catch (e) {
227
+ loadErrors.push(e)
228
+ }
229
+ try {
230
+ return require('@swc/core-linux-arm64-musl')
231
+ } catch (e) {
232
+ loadErrors.push(e)
233
+ }
234
+
235
+ } else {
140
236
  try {
141
- return require("@swc/core-darwin-universal");
142
- } catch (e) {
143
- loadErrors.push(e);
144
- }
237
+ return require('./swc.linux-arm64-gnu.node')
238
+ } catch (e) {
239
+ loadErrors.push(e)
240
+ }
241
+ try {
242
+ return require('@swc/core-linux-arm64-gnu')
243
+ } catch (e) {
244
+ loadErrors.push(e)
245
+ }
246
+
247
+ }
248
+ } else if (process.arch === 'arm') {
249
+ try {
250
+ return require('./swc.linux-arm-gnueabihf.node')
251
+ } catch (e) {
252
+ loadErrors.push(e)
253
+ }
254
+ try {
255
+ return require('@swc/core-linux-arm-gnueabihf')
256
+ } catch (e) {
257
+ loadErrors.push(e)
258
+ }
259
+
260
+ } else if (process.arch === 'riscv64') {
261
+ if (isMusl()) {
262
+ try {
263
+ return require('./swc.linux-riscv64-musl.node')
264
+ } catch (e) {
265
+ loadErrors.push(e)
266
+ }
267
+ try {
268
+ return require('@swc/core-linux-riscv64-musl')
269
+ } catch (e) {
270
+ loadErrors.push(e)
271
+ }
272
+
273
+ } else {
274
+ try {
275
+ return require('./swc.linux-riscv64-gnu.node')
276
+ } catch (e) {
277
+ loadErrors.push(e)
278
+ }
279
+ try {
280
+ return require('@swc/core-linux-riscv64-gnu')
281
+ } catch (e) {
282
+ loadErrors.push(e)
283
+ }
284
+
285
+ }
286
+ } else if (process.arch === 's390x') {
287
+ try {
288
+ return require('./swc.linux-s390x-gnu.node')
289
+ } catch (e) {
290
+ loadErrors.push(e)
291
+ }
292
+ try {
293
+ return require('@swc/core-linux-s390x-gnu')
294
+ } catch (e) {
295
+ loadErrors.push(e)
296
+ }
145
297
 
146
- if (process.arch === "x64") {
147
- try {
148
- return require("./swc.darwin-x64.node");
149
- } catch (e) {
150
- loadErrors.push(e);
151
- }
152
- try {
153
- return require("@swc/core-darwin-x64");
154
- } catch (e) {
155
- loadErrors.push(e);
156
- }
157
- } else if (process.arch === "arm64") {
158
- try {
159
- return require("./swc.darwin-arm64.node");
160
- } catch (e) {
161
- loadErrors.push(e);
162
- }
163
- try {
164
- return require("@swc/core-darwin-arm64");
165
- } catch (e) {
166
- loadErrors.push(e);
167
- }
168
- } else {
169
- loadErrors.push(
170
- new Error(`Unsupported architecture on macOS: ${process.arch}`)
171
- );
172
- }
173
- } else if (process.platform === "freebsd") {
174
- if (process.arch === "x64") {
175
- try {
176
- return require("./swc.freebsd-x64.node");
177
- } catch (e) {
178
- loadErrors.push(e);
179
- }
180
- try {
181
- return require("@swc/core-freebsd-x64");
182
- } catch (e) {
183
- loadErrors.push(e);
184
- }
185
- } else if (process.arch === "arm64") {
186
- try {
187
- return require("./swc.freebsd-arm64.node");
188
- } catch (e) {
189
- loadErrors.push(e);
190
- }
191
- try {
192
- return require("@swc/core-freebsd-arm64");
193
- } catch (e) {
194
- loadErrors.push(e);
195
- }
196
- } else {
197
- loadErrors.push(
198
- new Error(
199
- `Unsupported architecture on FreeBSD: ${process.arch}`
200
- )
201
- );
202
- }
203
- } else if (process.platform === "linux") {
204
- if (process.arch === "x64") {
205
- if (isMusl()) {
206
- try {
207
- return require("./swc.linux-x64-musl.node");
208
- } catch (e) {
209
- loadErrors.push(e);
210
- }
211
- try {
212
- return require("@swc/core-linux-x64-musl");
213
- } catch (e) {
214
- loadErrors.push(e);
215
- }
216
- } else {
217
- try {
218
- return require("./swc.linux-x64-gnu.node");
219
- } catch (e) {
220
- loadErrors.push(e);
221
- }
222
- try {
223
- return require("@swc/core-linux-x64-gnu");
224
- } catch (e) {
225
- loadErrors.push(e);
226
- }
227
- }
228
- } else if (process.arch === "arm64") {
229
- if (isMusl()) {
230
- try {
231
- return require("./swc.linux-arm64-musl.node");
232
- } catch (e) {
233
- loadErrors.push(e);
234
- }
235
- try {
236
- return require("@swc/core-linux-arm64-musl");
237
- } catch (e) {
238
- loadErrors.push(e);
239
- }
240
- } else {
241
- try {
242
- return require("./swc.linux-arm64-gnu.node");
243
- } catch (e) {
244
- loadErrors.push(e);
245
- }
246
- try {
247
- return require("@swc/core-linux-arm64-gnu");
248
- } catch (e) {
249
- loadErrors.push(e);
250
- }
251
- }
252
- } else if (process.arch === "arm") {
253
- try {
254
- return require("./swc.linux-arm-gnueabihf.node");
255
- } catch (e) {
256
- loadErrors.push(e);
257
- }
258
- try {
259
- return require("@swc/core-linux-arm-gnueabihf");
260
- } catch (e) {
261
- loadErrors.push(e);
262
- }
263
- } else if (process.arch === "riscv64") {
264
- if (isMusl()) {
265
- try {
266
- return require("./swc.linux-riscv64-musl.node");
267
- } catch (e) {
268
- loadErrors.push(e);
269
- }
270
- try {
271
- return require("@swc/core-linux-riscv64-musl");
272
- } catch (e) {
273
- loadErrors.push(e);
274
- }
275
- } else {
276
- try {
277
- return require("./swc.linux-riscv64-gnu.node");
278
- } catch (e) {
279
- loadErrors.push(e);
280
- }
281
- try {
282
- return require("@swc/core-linux-riscv64-gnu");
283
- } catch (e) {
284
- loadErrors.push(e);
285
- }
286
- }
287
- } else if (process.arch === "s390x") {
288
- try {
289
- return require("./swc.linux-s390x-gnu.node");
290
- } catch (e) {
291
- loadErrors.push(e);
292
- }
293
- try {
294
- return require("@swc/core-linux-s390x-gnu");
295
- } catch (e) {
296
- loadErrors.push(e);
297
- }
298
- } else {
299
- loadErrors.push(
300
- new Error(`Unsupported architecture on Linux: ${process.arch}`)
301
- );
302
- }
303
298
  } else {
304
- loadErrors.push(
305
- new Error(
306
- `Unsupported OS: ${process.platform}, architecture: ${process.arch}`
307
- )
308
- );
299
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
309
300
  }
301
+ } else {
302
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
303
+ }
310
304
  }
311
305
 
312
- nativeBinding = requireNative();
306
+ nativeBinding = requireNative()
313
307
 
314
308
  if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
309
+ try {
310
+ nativeBinding = require('./swc.wasi.cjs')
311
+ } catch (err) {
312
+ if (process.env.NAPI_RS_FORCE_WASI) {
313
+ console.error(err)
314
+ }
315
+ }
316
+ if (!nativeBinding) {
315
317
  try {
316
- nativeBinding = require("./swc.wasi.cjs");
318
+ nativeBinding = require('@swc/core-wasm32-wasi')
317
319
  } catch (err) {
318
- if (process.env.NAPI_RS_FORCE_WASI) {
319
- console.error(err);
320
- }
321
- }
322
- if (!nativeBinding) {
323
- try {
324
- nativeBinding = require("@swc/core-wasm32-wasi");
325
- } catch (err) {
326
- if (process.env.NAPI_RS_FORCE_WASI) {
327
- console.error(err);
328
- }
329
- }
320
+ if (process.env.NAPI_RS_FORCE_WASI) {
321
+ console.error(err)
322
+ }
330
323
  }
324
+ }
331
325
  }
332
326
 
333
327
  if (!nativeBinding) {
334
- if (loadErrors.length > 0) {
335
- // TODO Link to documentation with potential fixes
336
- // - The package owner could build/publish bindings for this arch
337
- // - The user may need to bundle the correct files
338
- // - The user may need to re-install node_modules to get new packages
339
- throw new Error("Failed to load native binding", { cause: loadErrors });
340
- }
341
- throw new Error(`Failed to load native binding`);
328
+ if (loadErrors.length > 0) {
329
+ // TODO Link to documentation with potential fixes
330
+ // - The package owner could build/publish bindings for this arch
331
+ // - The user may need to bundle the correct files
332
+ // - The user may need to re-install node_modules to get new packages
333
+ throw new Error('Failed to load native binding', { cause: loadErrors })
334
+ }
335
+ throw new Error(`Failed to load native binding`)
342
336
  }
343
337
 
344
- module.exports.Compiler = nativeBinding.Compiler;
345
- module.exports.JsCompiler = nativeBinding.JsCompiler;
346
- module.exports.bundle = nativeBinding.bundle;
347
- module.exports.getTargetTriple = nativeBinding.getTargetTriple;
348
- module.exports.initCustomTraceSubscriber =
349
- nativeBinding.initCustomTraceSubscriber;
350
- module.exports.minify = nativeBinding.minify;
351
- module.exports.minifySync = nativeBinding.minifySync;
352
- module.exports.parse = nativeBinding.parse;
353
- module.exports.parseFile = nativeBinding.parseFile;
354
- module.exports.parseFileSync = nativeBinding.parseFileSync;
355
- module.exports.parseSync = nativeBinding.parseSync;
356
- module.exports.print = nativeBinding.print;
357
- module.exports.printSync = nativeBinding.printSync;
358
- module.exports.transform = nativeBinding.transform;
359
- module.exports.transformFile = nativeBinding.transformFile;
360
- module.exports.transformFileSync = nativeBinding.transformFileSync;
361
- module.exports.transformSync = nativeBinding.transformSync;
338
+ module.exports.Compiler = nativeBinding.Compiler
339
+ module.exports.JsCompiler = nativeBinding.JsCompiler
340
+ module.exports.bundle = nativeBinding.bundle
341
+ module.exports.getTargetTriple = nativeBinding.getTargetTriple
342
+ module.exports.initCustomTraceSubscriber = nativeBinding.initCustomTraceSubscriber
343
+ module.exports.minify = nativeBinding.minify
344
+ module.exports.minifySync = nativeBinding.minifySync
345
+ module.exports.newMangleNameCache = nativeBinding.newMangleNameCache
346
+ module.exports.parse = nativeBinding.parse
347
+ module.exports.parseFile = nativeBinding.parseFile
348
+ module.exports.parseFileSync = nativeBinding.parseFileSync
349
+ module.exports.parseSync = nativeBinding.parseSync
350
+ module.exports.print = nativeBinding.print
351
+ module.exports.printSync = nativeBinding.printSync
352
+ module.exports.transform = nativeBinding.transform
353
+ module.exports.transformFile = nativeBinding.transformFile
354
+ module.exports.transformFileSync = nativeBinding.transformFileSync
355
+ module.exports.transformSync = nativeBinding.transformSync
package/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Plugin, ParseOptions, Module, Output, Options, Script, Program, JsMinifyOptions } from "@swc/types";
2
2
  export type * from "@swc/types";
3
+ export { newMangleNameCache as experimental_newMangleNameCache } from "./binding";
3
4
  import { BundleInput } from "./spack";
5
+ import type { NapiMinifyExtra } from "../binding";
4
6
  /**
5
7
  * Version of the swc binding.
6
8
  */
@@ -11,8 +13,8 @@ export declare const version: string;
11
13
  export declare function plugins(ps: Plugin[]): Plugin;
12
14
  export declare class Compiler {
13
15
  private fallbackBindingsPluginWarningDisplayed;
14
- minify(src: string, opts?: JsMinifyOptions): Promise<Output>;
15
- minifySync(src: string, opts?: JsMinifyOptions): Output;
16
+ minify(src: string, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Promise<Output>;
17
+ minifySync(src: string, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Output;
16
18
  /**
17
19
  * @deprecated Use Rust instead.
18
20
  */
@@ -78,8 +80,8 @@ export declare function transformFileSync(path: string, options?: Options): Outp
78
80
  export declare function bundle(options?: BundleInput | string): Promise<{
79
81
  [name: string]: Output;
80
82
  }>;
81
- export declare function minify(src: string, opts?: JsMinifyOptions): Promise<Output>;
82
- export declare function minifySync(src: string, opts?: JsMinifyOptions): Output;
83
+ export declare function minify(src: string, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Promise<Output>;
84
+ export declare function minifySync(src: string, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Output;
83
85
  /**
84
86
  * Configure custom trace configuration runs for a process lifecycle.
85
87
  * Currently only chromium's trace event format is supported.
package/index.js CHANGED
@@ -43,8 +43,11 @@ var __rest = (this && this.__rest) || function (s, e) {
43
43
  return t;
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.DEFAULT_EXTENSIONS = exports.getBinaryMetadata = exports.__experimental_registerGlobalTraceConfig = exports.minifySync = exports.minify = exports.bundle = exports.transformFileSync = exports.transformFile = exports.transformSync = exports.transform = exports.printSync = exports.print = exports.parseFileSync = exports.parseFile = exports.parseSync = exports.parse = exports.Compiler = exports.plugins = exports.version = void 0;
46
+ exports.DEFAULT_EXTENSIONS = exports.getBinaryMetadata = exports.__experimental_registerGlobalTraceConfig = exports.minifySync = exports.minify = exports.bundle = exports.transformFileSync = exports.transformFile = exports.transformSync = exports.transform = exports.printSync = exports.print = exports.parseFileSync = exports.parseFile = exports.parseSync = exports.parse = exports.Compiler = exports.plugins = exports.version = exports.experimental_newMangleNameCache = void 0;
47
47
  const path_1 = require("path");
48
+ // @ts-ignore
49
+ var binding_1 = require("./binding");
50
+ Object.defineProperty(exports, "experimental_newMangleNameCache", { enumerable: true, get: function () { return binding_1.newMangleNameCache; } });
48
51
  const spack_1 = require("./spack");
49
52
  const assert = __importStar(require("assert"));
50
53
  // Allow overrides to the location of the .node binding file
@@ -92,10 +95,10 @@ class Compiler {
92
95
  constructor() {
93
96
  this.fallbackBindingsPluginWarningDisplayed = false;
94
97
  }
95
- minify(src, opts) {
98
+ minify(src, opts, extras) {
96
99
  return __awaiter(this, void 0, void 0, function* () {
97
100
  if (bindings) {
98
- return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
101
+ return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}), extras !== null && extras !== void 0 ? extras : {});
99
102
  }
100
103
  else if (fallbackBindings) {
101
104
  return fallbackBindings.minify(src, opts);
@@ -103,9 +106,9 @@ class Compiler {
103
106
  throw new Error("Bindings not found.");
104
107
  });
105
108
  }
106
- minifySync(src, opts) {
109
+ minifySync(src, opts, extras) {
107
110
  if (bindings) {
108
- return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
111
+ return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}), extras !== null && extras !== void 0 ? extras : {});
109
112
  }
110
113
  else if (fallbackBindings) {
111
114
  return fallbackBindings.minifySync(src, opts);
@@ -368,14 +371,14 @@ function bundle(options) {
368
371
  return compiler.bundle(options);
369
372
  }
370
373
  exports.bundle = bundle;
371
- function minify(src, opts) {
374
+ function minify(src, opts, extras) {
372
375
  return __awaiter(this, void 0, void 0, function* () {
373
- return compiler.minify(src, opts);
376
+ return compiler.minify(src, opts, extras);
374
377
  });
375
378
  }
376
379
  exports.minify = minify;
377
- function minifySync(src, opts) {
378
- return compiler.minifySync(src, opts);
380
+ function minifySync(src, opts, extras) {
381
+ return compiler.minifySync(src, opts, extras);
379
382
  }
380
383
  exports.minifySync = minifySync;
381
384
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swc/core",
3
- "version": "1.7.18",
3
+ "version": "1.7.19",
4
4
  "description": "Super-fast alternative for babel",
5
5
  "homepage": "https://swc.rs",
6
6
  "main": "./index.js",
@@ -100,15 +100,15 @@
100
100
  "typescript": "^5.3.3"
101
101
  },
102
102
  "optionalDependencies": {
103
- "@swc/core-darwin-x64": "1.7.18",
104
- "@swc/core-win32-x64-msvc": "1.7.18",
105
- "@swc/core-linux-x64-gnu": "1.7.18",
106
- "@swc/core-linux-x64-musl": "1.7.18",
107
- "@swc/core-win32-ia32-msvc": "1.7.18",
108
- "@swc/core-linux-arm-gnueabihf": "1.7.18",
109
- "@swc/core-linux-arm64-gnu": "1.7.18",
110
- "@swc/core-darwin-arm64": "1.7.18",
111
- "@swc/core-linux-arm64-musl": "1.7.18",
112
- "@swc/core-win32-arm64-msvc": "1.7.18"
103
+ "@swc/core-darwin-x64": "1.7.19",
104
+ "@swc/core-win32-x64-msvc": "1.7.19",
105
+ "@swc/core-linux-x64-gnu": "1.7.19",
106
+ "@swc/core-linux-x64-musl": "1.7.19",
107
+ "@swc/core-win32-ia32-msvc": "1.7.19",
108
+ "@swc/core-linux-arm-gnueabihf": "1.7.19",
109
+ "@swc/core-linux-arm64-gnu": "1.7.19",
110
+ "@swc/core-darwin-arm64": "1.7.19",
111
+ "@swc/core-linux-arm64-musl": "1.7.19",
112
+ "@swc/core-win32-arm64-msvc": "1.7.19"
113
113
  }
114
114
  }