@swc/react-compiler 1.11.26-nightly-20250512.1

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/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@swc/react-compiler",
3
+ "version": "1.11.26-nightly-20250512.1",
4
+ "description": "SWC support for React Compiler",
5
+ "homepage": "https://swc.rs",
6
+ "main": "./index.js",
7
+ "author": "강동윤 <kdy1997.dev@gmail.com>",
8
+ "license": "Apache-2.0",
9
+ "keywords": [
10
+ "swc",
11
+ "react",
12
+ "react-compiler"
13
+ ],
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/swc-project/swc.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/swc-project/swc/issues"
23
+ },
24
+ "napi": {
25
+ "binaryName": "react-compiler",
26
+ "targets": [
27
+ "x86_64-apple-darwin",
28
+ "x86_64-pc-windows-msvc",
29
+ "x86_64-unknown-linux-gnu",
30
+ "x86_64-unknown-linux-musl",
31
+ "i686-pc-windows-msvc",
32
+ "armv7-unknown-linux-gnueabihf",
33
+ "aarch64-unknown-linux-gnu",
34
+ "aarch64-apple-darwin",
35
+ "aarch64-unknown-linux-musl",
36
+ "aarch64-pc-windows-msvc"
37
+ ]
38
+ },
39
+ "publishConfig": {
40
+ "registry": "https://registry.npmjs.org/",
41
+ "access": "public"
42
+ },
43
+ "types": "./index.d.ts",
44
+ "scripts": {
45
+ "artifacts": "napi artifacts --npm-dir scripts/npm",
46
+ "prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tagstyle npm",
47
+ "pack": "wasm-pack",
48
+ "build:ts": "tsc -d",
49
+ "build": "tsc -d && napi build --platform --js ./src/binding.js --dts ./src/binding.d.ts --manifest-path ../../bindings/Cargo.toml -p binding_react_compiler_node --output-dir . --release",
50
+ "build:dev": "tsc -d && napi build --platform --js ./src/binding.js --dts ./src/binding.d.ts --manifest-path ../../bindings/Cargo.toml -p binding_react_compiler_node --output-dir .",
51
+ "test": "cross-env NODE_OPTIONS='--experimental-vm-modules' echo 'no test'",
52
+ "version": "napi version --npm-dir scripts/npm"
53
+ },
54
+ "funding": {
55
+ "type": "opencollective",
56
+ "url": "https://opencollective.com/swc"
57
+ },
58
+ "dependencies": {
59
+ "@swc/counter": "^0.1.3",
60
+ "@swc/types": "^0.1.21"
61
+ },
62
+ "devDependencies": {
63
+ "@napi-rs/cli": "^3.0.0-alpha.22",
64
+ "@types/node": "^20.7.1",
65
+ "cross-env": "^7.0.3",
66
+ "typescript": "^5.2.2"
67
+ }
68
+ }
@@ -0,0 +1,22 @@
1
+ #!/bin/sh
2
+
3
+ mkdir -p ./artifacts_cli
4
+ # Naive substitution to napi artifacts for the cli binary.
5
+ for filename in artifacts/*/*.node
6
+ do
7
+ BINDING_NAME=${filename#*.}
8
+ BINDING_ABI=${BINDING_NAME%%.*}
9
+ CLI_BINARY_PATH=${filename%%.*}
10
+
11
+ echo "Preparing build artifacts:"
12
+ echo "Binding name $BINDING_NAME"
13
+ echo "Filename $filename"
14
+ echo "Cli binary path $CLI_BINARY_PATH"
15
+
16
+ if [ -f "$CLI_BINARY_PATH" ]; then
17
+ chmod +x $CLI_BINARY_PATH
18
+ mv -v $CLI_BINARY_PATH ./artifacts_cli/swc-$BINDING_ABI
19
+ elif [ -f "$CLI_BINARY_PATH.exe" ]; then
20
+ mv -v $CLI_BINARY_PATH.exe ./artifacts_cli/swc-$BINDING_ABI.exe
21
+ fi
22
+ done
@@ -0,0 +1,13 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export declare function isReactCompilerRequired(code: Buffer, signal?: AbortSignal | undefined | null): Promise<boolean>
4
+
5
+ export declare function isReactCompilerRequiredSync(code: Buffer): boolean
6
+
7
+ export interface TransformOutput {
8
+ code: string
9
+ map?: string
10
+ output?: string
11
+ diagnostics: Array<string>
12
+ }
13
+
package/src/binding.js ADDED
@@ -0,0 +1,365 @@
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('./react-compiler.android-arm64.node')
64
+ } catch (e) {
65
+ loadErrors.push(e)
66
+ }
67
+ try {
68
+ return require('@swc/react-compiler-android-arm64')
69
+ } catch (e) {
70
+ loadErrors.push(e)
71
+ }
72
+
73
+ } else if (process.arch === 'arm') {
74
+ try {
75
+ return require('./react-compiler.android-arm-eabi.node')
76
+ } catch (e) {
77
+ loadErrors.push(e)
78
+ }
79
+ try {
80
+ return require('@swc/react-compiler-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('./react-compiler.win32-x64-msvc.node')
92
+ } catch (e) {
93
+ loadErrors.push(e)
94
+ }
95
+ try {
96
+ return require('@swc/react-compiler-win32-x64-msvc')
97
+ } catch (e) {
98
+ loadErrors.push(e)
99
+ }
100
+
101
+ } else if (process.arch === 'ia32') {
102
+ try {
103
+ return require('./react-compiler.win32-ia32-msvc.node')
104
+ } catch (e) {
105
+ loadErrors.push(e)
106
+ }
107
+ try {
108
+ return require('@swc/react-compiler-win32-ia32-msvc')
109
+ } catch (e) {
110
+ loadErrors.push(e)
111
+ }
112
+
113
+ } else if (process.arch === 'arm64') {
114
+ try {
115
+ return require('./react-compiler.win32-arm64-msvc.node')
116
+ } catch (e) {
117
+ loadErrors.push(e)
118
+ }
119
+ try {
120
+ return require('@swc/react-compiler-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('./react-compiler.darwin-universal.node')
131
+ } catch (e) {
132
+ loadErrors.push(e)
133
+ }
134
+ try {
135
+ return require('@swc/react-compiler-darwin-universal')
136
+ } catch (e) {
137
+ loadErrors.push(e)
138
+ }
139
+
140
+ if (process.arch === 'x64') {
141
+ try {
142
+ return require('./react-compiler.darwin-x64.node')
143
+ } catch (e) {
144
+ loadErrors.push(e)
145
+ }
146
+ try {
147
+ return require('@swc/react-compiler-darwin-x64')
148
+ } catch (e) {
149
+ loadErrors.push(e)
150
+ }
151
+
152
+ } else if (process.arch === 'arm64') {
153
+ try {
154
+ return require('./react-compiler.darwin-arm64.node')
155
+ } catch (e) {
156
+ loadErrors.push(e)
157
+ }
158
+ try {
159
+ return require('@swc/react-compiler-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('./react-compiler.freebsd-x64.node')
171
+ } catch (e) {
172
+ loadErrors.push(e)
173
+ }
174
+ try {
175
+ return require('@swc/react-compiler-freebsd-x64')
176
+ } catch (e) {
177
+ loadErrors.push(e)
178
+ }
179
+
180
+ } else if (process.arch === 'arm64') {
181
+ try {
182
+ return require('./react-compiler.freebsd-arm64.node')
183
+ } catch (e) {
184
+ loadErrors.push(e)
185
+ }
186
+ try {
187
+ return require('@swc/react-compiler-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('./react-compiler.linux-x64-musl.node')
200
+ } catch (e) {
201
+ loadErrors.push(e)
202
+ }
203
+ try {
204
+ return require('@swc/react-compiler-linux-x64-musl')
205
+ } catch (e) {
206
+ loadErrors.push(e)
207
+ }
208
+
209
+ } else {
210
+ try {
211
+ return require('./react-compiler.linux-x64-gnu.node')
212
+ } catch (e) {
213
+ loadErrors.push(e)
214
+ }
215
+ try {
216
+ return require('@swc/react-compiler-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('./react-compiler.linux-arm64-musl.node')
226
+ } catch (e) {
227
+ loadErrors.push(e)
228
+ }
229
+ try {
230
+ return require('@swc/react-compiler-linux-arm64-musl')
231
+ } catch (e) {
232
+ loadErrors.push(e)
233
+ }
234
+
235
+ } else {
236
+ try {
237
+ return require('./react-compiler.linux-arm64-gnu.node')
238
+ } catch (e) {
239
+ loadErrors.push(e)
240
+ }
241
+ try {
242
+ return require('@swc/react-compiler-linux-arm64-gnu')
243
+ } catch (e) {
244
+ loadErrors.push(e)
245
+ }
246
+
247
+ }
248
+ } else if (process.arch === 'arm') {
249
+ if (isMusl()) {
250
+ try {
251
+ return require('./react-compiler.linux-arm-musleabihf.node')
252
+ } catch (e) {
253
+ loadErrors.push(e)
254
+ }
255
+ try {
256
+ return require('@swc/react-compiler-linux-arm-musleabihf')
257
+ } catch (e) {
258
+ loadErrors.push(e)
259
+ }
260
+
261
+ } else {
262
+ try {
263
+ return require('./react-compiler.linux-arm-gnueabihf.node')
264
+ } catch (e) {
265
+ loadErrors.push(e)
266
+ }
267
+ try {
268
+ return require('@swc/react-compiler-linux-arm-gnueabihf')
269
+ } catch (e) {
270
+ loadErrors.push(e)
271
+ }
272
+
273
+ }
274
+ } else if (process.arch === 'riscv64') {
275
+ if (isMusl()) {
276
+ try {
277
+ return require('./react-compiler.linux-riscv64-musl.node')
278
+ } catch (e) {
279
+ loadErrors.push(e)
280
+ }
281
+ try {
282
+ return require('@swc/react-compiler-linux-riscv64-musl')
283
+ } catch (e) {
284
+ loadErrors.push(e)
285
+ }
286
+
287
+ } else {
288
+ try {
289
+ return require('./react-compiler.linux-riscv64-gnu.node')
290
+ } catch (e) {
291
+ loadErrors.push(e)
292
+ }
293
+ try {
294
+ return require('@swc/react-compiler-linux-riscv64-gnu')
295
+ } catch (e) {
296
+ loadErrors.push(e)
297
+ }
298
+
299
+ }
300
+ } else if (process.arch === 'ppc64') {
301
+ try {
302
+ return require('./react-compiler.linux-ppc64-gnu.node')
303
+ } catch (e) {
304
+ loadErrors.push(e)
305
+ }
306
+ try {
307
+ return require('@swc/react-compiler-linux-ppc64-gnu')
308
+ } catch (e) {
309
+ loadErrors.push(e)
310
+ }
311
+
312
+ } else if (process.arch === 's390x') {
313
+ try {
314
+ return require('./react-compiler.linux-s390x-gnu.node')
315
+ } catch (e) {
316
+ loadErrors.push(e)
317
+ }
318
+ try {
319
+ return require('@swc/react-compiler-linux-s390x-gnu')
320
+ } catch (e) {
321
+ loadErrors.push(e)
322
+ }
323
+
324
+ } else {
325
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
326
+ }
327
+ } else {
328
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
329
+ }
330
+ }
331
+
332
+ nativeBinding = requireNative()
333
+
334
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
335
+ try {
336
+ nativeBinding = require('./react-compiler.wasi.cjs')
337
+ } catch (err) {
338
+ if (process.env.NAPI_RS_FORCE_WASI) {
339
+ console.error(err)
340
+ }
341
+ }
342
+ if (!nativeBinding) {
343
+ try {
344
+ nativeBinding = require('@swc/react-compiler-wasm32-wasi')
345
+ } catch (err) {
346
+ if (process.env.NAPI_RS_FORCE_WASI) {
347
+ console.error(err)
348
+ }
349
+ }
350
+ }
351
+ }
352
+
353
+ if (!nativeBinding) {
354
+ if (loadErrors.length > 0) {
355
+ // TODO Link to documentation with potential fixes
356
+ // - The package owner could build/publish bindings for this arch
357
+ // - The user may need to bundle the correct files
358
+ // - The user may need to re-install node_modules to get new packages
359
+ throw new Error('Failed to load native binding', { cause: loadErrors })
360
+ }
361
+ throw new Error(`Failed to load native binding`)
362
+ }
363
+
364
+ module.exports.isReactCompilerRequired = nativeBinding.isReactCompilerRequired
365
+ module.exports.isReactCompilerRequiredSync = nativeBinding.isReactCompilerRequiredSync
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+
2
+ import * as binding from './binding'
3
+
4
+ /**
5
+ * TODO
6
+ */
7
+ export async function isReactCompilerRequired(code: Buffer) {
8
+ return await binding.isReactCompilerRequired(code)
9
+ }
10
+
11
+
12
+ /**
13
+ * TODO
14
+ */
15
+ export function isReactCompilerRequiredSync(code: Buffer): boolean {
16
+ return binding.isReactCompilerRequiredSync(code)
17
+ }
18
+
package/tsconfig.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Basic Options */
4
+ "target": "es2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
5
+ "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
6
+ // "lib": [], /* Specify library files to be included in the compilation. */
7
+ "allowJs": true /* Allow javascript files to be compiled. */,
8
+ // "checkJs": true, /* Report errors in .js files. */
9
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10
+ "declaration": true /* Generates corresponding '.d.ts' file. */,
11
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12
+ "sourceMap": false /* Generates corresponding '.map' file. */,
13
+ // "outFile": "./", /* Concatenate and emit output to single file. */
14
+ "outDir": "./" /* Redirect output structure to the directory. */,
15
+ "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
16
+ // "composite": true, /* Enable project compilation */
17
+ "removeComments": false /* Do not emit comments to output. */,
18
+ // "noEmit": true, /* Do not emit outputs. */
19
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
20
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
21
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
22
+ /* Strict Type-Checking Options */
23
+ "strict": true /* Enable all strict type-checking options. */,
24
+ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
25
+ // "strictNullChecks": true, /* Enable strict null checks. */
26
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
27
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
28
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
29
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
30
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
31
+ /* Additional Checks */
32
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
33
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
34
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
35
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
36
+ /* Module Resolution Options */
37
+ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
38
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
39
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
40
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
41
+ // "typeRoots": [], /* List of folders to include type definitions from. */
42
+ // "types": [], /* Type declaration files to be included in compilation. */
43
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
44
+ "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
45
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
46
+ /* Source Map Options */
47
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
48
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
49
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
50
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
51
+ /* Experimental Options */
52
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
53
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
54
+ "incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */,
55
+ "tsBuildInfoFile": ".tsbuildinfo"
56
+ },
57
+ "include": [
58
+ "src/"
59
+ ],
60
+ "exclude": [
61
+ "*.js"
62
+ ]
63
+ }