@ohos-ports/swc-core 1.15.43-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ export class Compiler {
5
+ constructor()
6
+ }
7
+ export type JsCompiler = Compiler
8
+
9
+ export declare function analyze(src: string, options: Buffer, signal?: AbortSignal | undefined | null): Promise<string>
10
+
11
+ export declare function bundle(confItems: Buffer, signal?: AbortSignal | undefined | null): Promise<{ [index: string]: { code: string, map?: string } }>
12
+
13
+ export declare function getTargetTriple(): string
14
+
15
+ /** @deprecated Trace profiling is disabled. This function is kept as a no-op for compatibility. */
16
+ export declare function initCustomTraceSubscriber(traceOutFilePath?: string | undefined | null): void
17
+
18
+ export declare function minify(code: Buffer, opts: Buffer, isJson: boolean, extras: NapiMinifyExtra, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
19
+
20
+ export declare function minifySync(code: Buffer, opts: Buffer, isJson: boolean, extras: NapiMinifyExtra): TransformOutput
21
+
22
+ export interface NapiMinifyExtra {
23
+ mangleNameCache?: object
24
+ }
25
+
26
+ export declare function newMangleNameCache(): object
27
+
28
+ export declare function parse(src: Buffer | string, options: Buffer, filename?: string | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
29
+
30
+ export declare function parseFile(path: string, options: Buffer, signal?: AbortSignal | undefined | null): Promise<string>
31
+
32
+ export declare function parseFileSync(path: string, opts: Buffer): string
33
+
34
+ export declare function parseSync(src: Buffer | string, opts: Buffer, filename?: string | undefined | null): string
35
+
36
+ export declare function print(programJson: string, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
37
+
38
+ export declare function printSync(program: string, options: Buffer): TransformOutput
39
+
40
+ export declare function transform(src: string, isModule: boolean, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
41
+
42
+ export declare function transformFile(src: string, isModule: boolean, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
43
+
44
+ export declare function transformFileSync(s: string, isModule: boolean, opts: Buffer): TransformOutput
45
+
46
+ export interface TransformOutput {
47
+ code: string
48
+ map?: string
49
+ output?: string
50
+ extractedComments?: Array<string>
51
+ diagnostics: Array<string>
52
+ }
53
+
54
+ /** Hack for `Type Generation` */
55
+ export interface TransformOutput {
56
+ code: string
57
+ map?: string
58
+ }
59
+
60
+ export declare function transformSync(s: string, isModule: boolean, opts: Buffer): TransformOutput
package/binding.js ADDED
@@ -0,0 +1,378 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ /* auto-generated by NAPI-RS */
4
+
5
+ const { readFileSync } = require('fs')
6
+
7
+ let nativeBinding = null
8
+ const loadErrors = []
9
+
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
+ }
20
+ }
21
+ return musl
22
+ }
23
+
24
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
25
+
26
+ const isMuslFromFilesystem = () => {
27
+ try {
28
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
29
+ } catch {
30
+ return null
31
+ }
32
+ }
33
+
34
+ const isMuslFromReport = () => {
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
45
+ }
46
+ }
47
+ return false
48
+ }
49
+
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') {
129
+ try {
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}`))
166
+ }
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
+ }
179
+
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()) {
198
+ try {
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 {
236
+ try {
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 === 'ppc64') {
287
+ try {
288
+ return require('./swc.linux-ppc64-gnu.node')
289
+ } catch (e) {
290
+ loadErrors.push(e)
291
+ }
292
+ try {
293
+ return require('@swc/core-linux-ppc64-gnu')
294
+ } catch (e) {
295
+ loadErrors.push(e)
296
+ }
297
+
298
+ } else if (process.arch === 's390x') {
299
+ try {
300
+ return require('./swc.linux-s390x-gnu.node')
301
+ } catch (e) {
302
+ loadErrors.push(e)
303
+ }
304
+ try {
305
+ return require('@swc/core-linux-s390x-gnu')
306
+ } catch (e) {
307
+ loadErrors.push(e)
308
+ }
309
+
310
+ } else {
311
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
312
+ }
313
+ } else if (process.platform === 'openharmony') {
314
+ if (process.arch === 'arm64') {
315
+ try {
316
+ return require('./swc.node')
317
+ } catch (e) {
318
+ loadErrors.push(e)
319
+ }
320
+ } else {
321
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
322
+ }
323
+ } else {
324
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
325
+ }
326
+ }
327
+
328
+ nativeBinding = requireNative()
329
+
330
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
331
+ try {
332
+ nativeBinding = require('./swc.wasi.cjs')
333
+ } catch (err) {
334
+ if (process.env.NAPI_RS_FORCE_WASI) {
335
+ console.error(err)
336
+ }
337
+ }
338
+ if (!nativeBinding) {
339
+ try {
340
+ nativeBinding = require('@swc/core-wasm32-wasi')
341
+ } catch (err) {
342
+ if (process.env.NAPI_RS_FORCE_WASI) {
343
+ console.error(err)
344
+ }
345
+ }
346
+ }
347
+ }
348
+
349
+ if (!nativeBinding) {
350
+ if (loadErrors.length > 0) {
351
+ // TODO Link to documentation with potential fixes
352
+ // - The package owner could build/publish bindings for this arch
353
+ // - The user may need to bundle the correct files
354
+ // - The user may need to re-install node_modules to get new packages
355
+ throw new Error('Failed to load native binding', { cause: loadErrors })
356
+ }
357
+ throw new Error(`Failed to load native binding`)
358
+ }
359
+
360
+ module.exports.Compiler = nativeBinding.Compiler
361
+ module.exports.JsCompiler = nativeBinding.JsCompiler
362
+ module.exports.analyze = nativeBinding.analyze
363
+ module.exports.bundle = nativeBinding.bundle
364
+ module.exports.getTargetTriple = nativeBinding.getTargetTriple
365
+ module.exports.initCustomTraceSubscriber = nativeBinding.initCustomTraceSubscriber
366
+ module.exports.minify = nativeBinding.minify
367
+ module.exports.minifySync = nativeBinding.minifySync
368
+ module.exports.newMangleNameCache = nativeBinding.newMangleNameCache
369
+ module.exports.parse = nativeBinding.parse
370
+ module.exports.parseFile = nativeBinding.parseFile
371
+ module.exports.parseFileSync = nativeBinding.parseFileSync
372
+ module.exports.parseSync = nativeBinding.parseSync
373
+ module.exports.print = nativeBinding.print
374
+ module.exports.printSync = nativeBinding.printSync
375
+ module.exports.transform = nativeBinding.transform
376
+ module.exports.transformFile = nativeBinding.transformFile
377
+ module.exports.transformFileSync = nativeBinding.transformFileSync
378
+ module.exports.transformSync = nativeBinding.transformSync
package/index.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ import type { Plugin, ParseOptions, Module, Output, Options, Script, Program, JsMinifyOptions, WasmAnalysisOptions } from "@swc/types";
2
+ export type * from "@swc/types";
3
+ export { newMangleNameCache as experimental_newMangleNameCache } from "./binding";
4
+ import { BundleInput } from "./spack";
5
+ import type { NapiMinifyExtra } from "./binding";
6
+ /**
7
+ * Version of the swc binding.
8
+ */
9
+ export declare const version: string;
10
+ /**
11
+ * @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
12
+ */
13
+ export declare function plugins(ps: Plugin[]): Plugin;
14
+ export declare class Compiler {
15
+ private fallbackBindingsPluginWarningDisplayed;
16
+ minify(src: string | Buffer, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Promise<Output>;
17
+ minifySync(src: string | Buffer, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Output;
18
+ /**
19
+ * @deprecated Use Rust instead.
20
+ */
21
+ parse(src: string, options: ParseOptions & {
22
+ isModule: false;
23
+ }): Promise<Script>;
24
+ parse(src: string, options?: ParseOptions, filename?: string): Promise<Module>;
25
+ parseSync(src: string, options: ParseOptions & {
26
+ isModule: false;
27
+ }): Script;
28
+ parseSync(src: string, options?: ParseOptions, filename?: string): Module;
29
+ parseFile(path: string, options: ParseOptions & {
30
+ isModule: false;
31
+ }): Promise<Script>;
32
+ parseFile(path: string, options?: ParseOptions): Promise<Module>;
33
+ parseFileSync(path: string, options: ParseOptions & {
34
+ isModule: false;
35
+ }): Script;
36
+ parseFileSync(path: string, options?: ParseOptions): Module;
37
+ /**
38
+ * Note: this method should be invoked on the compiler instance used
39
+ * for `parse()` / `parseSync()`.
40
+ */
41
+ print(m: Program, options?: Options): Promise<Output>;
42
+ /**
43
+ * Note: this method should be invoked on the compiler instance used
44
+ * for `parse()` / `parseSync()`.
45
+ */
46
+ printSync(m: Program, options?: Options): Output;
47
+ transform(src: string | Program, options?: Options): Promise<Output>;
48
+ transformSync(src: string | Program, options?: Options): Output;
49
+ transformFile(path: string, options?: Options): Promise<Output>;
50
+ transformFileSync(path: string, options?: Options): Output;
51
+ bundle(options?: BundleInput | string): Promise<{
52
+ [name: string]: Output;
53
+ }>;
54
+ }
55
+ export declare function experimental_analyze(src: string, options?: WasmAnalysisOptions): Promise<string>;
56
+ /**
57
+ * @deprecated Use Rust instead.
58
+ */
59
+ export declare function parse(src: string, options: ParseOptions & {
60
+ isModule: false;
61
+ }): Promise<Script>;
62
+ export declare function parse(src: string, options?: ParseOptions): Promise<Module>;
63
+ export declare function parseSync(src: string, options: ParseOptions & {
64
+ isModule: false;
65
+ }): Script;
66
+ export declare function parseSync(src: string, options?: ParseOptions): Module;
67
+ export declare function parseFile(path: string, options: ParseOptions & {
68
+ isModule: false;
69
+ }): Promise<Script>;
70
+ export declare function parseFile(path: string, options?: ParseOptions): Promise<Module>;
71
+ export declare function parseFileSync(path: string, options: ParseOptions & {
72
+ isModule: false;
73
+ }): Script;
74
+ export declare function parseFileSync(path: string, options?: ParseOptions): Module;
75
+ export declare function print(m: Program, options?: Options): Promise<Output>;
76
+ export declare function printSync(m: Program, options?: Options): Output;
77
+ export declare function transform(src: string | Program, options?: Options): Promise<Output>;
78
+ export declare function transformSync(src: string | Program, options?: Options): Output;
79
+ export declare function transformFile(path: string, options?: Options): Promise<Output>;
80
+ export declare function transformFileSync(path: string, options?: Options): Output;
81
+ export declare function bundle(options?: BundleInput | string): Promise<{
82
+ [name: string]: Output;
83
+ }>;
84
+ export declare function minify(src: string | Buffer, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Promise<Output>;
85
+ export declare function minifySync(src: string | Buffer, opts?: JsMinifyOptions, extras?: NapiMinifyExtra): Output;
86
+ /**
87
+ * @deprecated Trace profiling is disabled. This function is kept as a no-op for compatibility.
88
+ */
89
+ export declare function __experimental_registerGlobalTraceConfig(traceConfig: {
90
+ type: "traceEvent";
91
+ fileName?: string;
92
+ }): void;
93
+ /**
94
+ * @ignore
95
+ *
96
+ * Returns current binary's metadata to determine which binary is actually loaded.
97
+ *
98
+ * This is undocumented interface, does not guarantee stability across `@swc/core`'s semver
99
+ * as internal representation may change anytime. Use it with caution.
100
+ */
101
+ export declare function getBinaryMetadata(): {
102
+ target: string | undefined;
103
+ };
104
+ export declare const DEFAULT_EXTENSIONS: readonly string[];