oxc-transform-relay 0.0.1 → 0.147.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present VoidZero Inc. & Contributors
4
+ Copyright (c) 2023 Boshen
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,48 @@
1
- # oxc-transform-relay
1
+ # Oxc Relay Transform
2
2
 
3
- Placeholder package used to reserve the npm name for Oxc's Relay transform bindings.
3
+ Native Node.js bindings for Oxc's Rust port of the Relay transform
4
+ ([babel-plugin-relay](https://github.com/facebook/relay/tree/main/packages/babel-plugin-relay) /
5
+ [@swc/plugin-relay](https://github.com/swc-project/plugins/tree/main/packages/relay)).
4
6
 
5
- The functional package is published by the Oxc release workflow.
7
+ The API follows `oxc-transform`: pass a filename, source text, and optional
8
+ options to either `transformSync` or `transform`. `graphql` tagged template
9
+ expressions are replaced with references to the artifact files generated by
10
+ `relay-compiler`; everything else — including TypeScript and JSX syntax — is
11
+ preserved untouched, so the output composes with any downstream toolchain.
12
+
13
+ ```javascript
14
+ import { transformSync } from "oxc-transform-relay";
15
+
16
+ const result = transformSync("src/Component.tsx", "const data = graphql`query FooQuery { id }`;");
17
+
18
+ console.log(result.code);
19
+ // import _FooQuery from "./__generated__/FooQuery.graphql.js";
20
+ // const data = _FooQuery;
21
+ ```
22
+
23
+ `errors` contains every diagnostic reported by parsing and the transform; when
24
+ it is non-empty, `code` is empty.
25
+
26
+ ## Options
27
+
28
+ - `artifactDirectory` — directory `relay-compiler` emits all artifacts to (its
29
+ `artifactDirectory` setting). When set, artifacts are imported via a relative
30
+ path computed lexically from the file being transformed, so pass the filename
31
+ and directory either both absolute or both relative to the same base
32
+ directory. When unset, artifacts are imported from the `__generated__`
33
+ directory next to the file being transformed.
34
+ - `language` — `"typescript"`, `"javascript"` (default), or `"flow"`. Artifacts
35
+ are imported as `Name.graphql.ts` for `"typescript"` and `Name.graphql.js`
36
+ otherwise.
37
+ - `eagerEsModules` — emit a hoisted default import per `graphql` tag (default,
38
+ matching `babel-plugin-relay` since Relay v17) instead of an inline
39
+ `require()` call (`@swc/plugin-relay` and Next.js behavior).
40
+ - `lang`, `sourceType`, `sourcemap` — configure the surrounding Oxc
41
+ parse/codegen pipeline, as in `oxc-transform`.
42
+
43
+ ## Limitations
44
+
45
+ Compared to `babel-plugin-relay`: no development-mode artifact hash validation,
46
+ no `jsModuleFormat: "haste"`, no `isDevVariableName`, and the GraphQL definition
47
+ name is extracted textually (like `@swc/plugin-relay`) rather than by parsing
48
+ the document, so documents are not validated.
package/browser.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@oxc-transform-relay/binding-wasm32-wasi'
package/index.d.ts ADDED
@@ -0,0 +1,114 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export interface Comment {
4
+ type: 'Line' | 'Block'
5
+ value: string
6
+ start: number
7
+ end: number
8
+ }
9
+
10
+ export interface ErrorLabel {
11
+ message: string | null
12
+ start: number
13
+ end: number
14
+ }
15
+
16
+ export interface OxcError {
17
+ severity: Severity
18
+ message: string
19
+ labels: Array<ErrorLabel>
20
+ helpMessage: string | null
21
+ codeframe: string | null
22
+ }
23
+
24
+ export declare const enum Severity {
25
+ Error = 'Error',
26
+ Warning = 'Warning',
27
+ Advice = 'Advice'
28
+ }
29
+ export interface SourceMap {
30
+ file?: string
31
+ mappings: string
32
+ names: Array<string>
33
+ sourceRoot?: string
34
+ sources: Array<string>
35
+ sourcesContent?: Array<string>
36
+ version: number
37
+ x_google_ignoreList?: Array<number>
38
+ }
39
+ /**
40
+ * Apply the Relay `graphql` tagged template transform asynchronously.
41
+ *
42
+ * This uses a worker-pool thread and can be slower than `transformSync` for a
43
+ * single small module.
44
+ */
45
+ export declare function transform(filename: string, sourceText: string, options?: TransformOptions | undefined | null): Promise<TransformResult>
46
+
47
+ /**
48
+ * Options for the Relay transform.
49
+ *
50
+ * `lang`, `sourceType`, and `sourcemap` configure the surrounding Oxc
51
+ * parse/codegen pipeline; the remaining fields mirror the options of
52
+ * `babel-plugin-relay` / `@swc/plugin-relay`.
53
+ */
54
+ export interface TransformOptions {
55
+ /** Treat the source as `js`, `jsx`, `ts`, `tsx`, or `dts`. */
56
+ lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'
57
+ /** Treat the source as script, module, CommonJS, or infer it from syntax. */
58
+ sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous'
59
+ /**
60
+ * Generate a source map.
61
+ *
62
+ * @default false
63
+ */
64
+ sourcemap?: boolean
65
+ /**
66
+ * Directory `relay-compiler` emits all artifacts to (its
67
+ * `artifactDirectory` setting). When set, artifacts are imported via a
68
+ * relative path from the file being transformed to this directory; the
69
+ * path is computed lexically, so both must either be absolute or relative
70
+ * to the same base directory. When unset, artifacts are imported from the
71
+ * `__generated__` directory next to the file being transformed.
72
+ */
73
+ artifactDirectory?: string
74
+ /**
75
+ * Artifact language, determining the imported file extension:
76
+ * `Name.graphql.ts` for `typescript`, `Name.graphql.js` otherwise.
77
+ *
78
+ * @default 'javascript'
79
+ */
80
+ language?: 'typescript' | 'javascript' | 'flow'
81
+ /**
82
+ * Emit a hoisted default import per `graphql` tag instead of an inline
83
+ * `require()` call.
84
+ *
85
+ * Defaults to `true`, matching `babel-plugin-relay` since Relay v17.
86
+ * `@swc/plugin-relay` and Next.js default to `false`.
87
+ *
88
+ * @default true
89
+ */
90
+ eagerEsModules?: boolean
91
+ }
92
+
93
+ /** Result returned by the Relay transform. */
94
+ export interface TransformResult {
95
+ /**
96
+ * Transformed code.
97
+ *
98
+ * This is empty when parsing, semantic analysis, option validation, or
99
+ * the Relay transform reports an error.
100
+ */
101
+ code: string
102
+ /** Source map, populated when `sourcemap` is `true`. */
103
+ map?: SourceMap
104
+ /** Parse, semantic, option validation, and Relay transform diagnostics. */
105
+ errors: Array<OxcError>
106
+ }
107
+
108
+ /**
109
+ * Apply the Relay `graphql` tagged template transform synchronously.
110
+ *
111
+ * Only `graphql` tags are rewritten; TypeScript and JSX syntax are preserved
112
+ * untouched, so the output composes with any downstream toolchain.
113
+ */
114
+ export declare function transformSync(filename: string, sourceText: string, options?: TransformOptions | undefined | null): TransformResult
package/index.js ADDED
@@ -0,0 +1,717 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ import { createRequire } from 'module'
7
+ const require = createRequire(import.meta.url)
8
+ const __dirname = new URL('.', import.meta.url).pathname
9
+
10
+ const { readFileSync } = require('fs')
11
+ let nativeBinding = null
12
+ const loadErrors = []
13
+
14
+ const isMusl = () => {
15
+ let musl = false
16
+ if (process.platform === 'linux') {
17
+ musl = isMuslFromFilesystem()
18
+ if (musl === null) {
19
+ musl = isMuslFromReport()
20
+ }
21
+ if (musl === null) {
22
+ musl = isMuslFromChildProcess()
23
+ }
24
+ }
25
+ return musl
26
+ }
27
+
28
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
29
+
30
+ const isMuslFromFilesystem = () => {
31
+ try {
32
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
33
+ } catch {
34
+ return null
35
+ }
36
+ }
37
+
38
+ const isMuslFromReport = () => {
39
+ let report = null
40
+ if (process.report && typeof process.report.getReport === 'function') {
41
+ process.report.excludeNetwork = true
42
+ report = process.report.getReport()
43
+ }
44
+ if (!report) {
45
+ return null
46
+ }
47
+ if (report.header && report.header.glibcVersionRuntime) {
48
+ return false
49
+ }
50
+ if (Array.isArray(report.sharedObjects)) {
51
+ if (report.sharedObjects.some(isFileMusl)) {
52
+ return true
53
+ }
54
+ }
55
+ return false
56
+ }
57
+
58
+ const isMuslFromChildProcess = () => {
59
+ try {
60
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
61
+ } catch (e) {
62
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
63
+ return false
64
+ }
65
+ }
66
+
67
+ function requireNative() {
68
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
69
+ try {
70
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
71
+ } catch (err) {
72
+ loadErrors.push(err)
73
+ }
74
+ } else if (process.platform === 'android') {
75
+ if (process.arch === 'arm64') {
76
+ try {
77
+ return require('./transform-relay.android-arm64.node')
78
+ } catch (e) {
79
+ loadErrors.push(e)
80
+ }
81
+ try {
82
+ const binding = require('@oxc-transform-relay/binding-android-arm64')
83
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-android-arm64/package.json').version
84
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
86
+ }
87
+ return binding
88
+ } catch (e) {
89
+ loadErrors.push(e)
90
+ }
91
+ } else if (process.arch === 'arm') {
92
+ try {
93
+ return require('./transform-relay.android-arm-eabi.node')
94
+ } catch (e) {
95
+ loadErrors.push(e)
96
+ }
97
+ try {
98
+ const binding = require('@oxc-transform-relay/binding-android-arm-eabi')
99
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-android-arm-eabi/package.json').version
100
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
+ }
103
+ return binding
104
+ } catch (e) {
105
+ loadErrors.push(e)
106
+ }
107
+ } else {
108
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
109
+ }
110
+ } else if (process.platform === 'win32') {
111
+ if (process.arch === 'x64') {
112
+ if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
113
+ try {
114
+ return require('./transform-relay.win32-x64-gnu.node')
115
+ } catch (e) {
116
+ loadErrors.push(e)
117
+ }
118
+ try {
119
+ const binding = require('@oxc-transform-relay/binding-win32-x64-gnu')
120
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-x64-gnu/package.json').version
121
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
123
+ }
124
+ return binding
125
+ } catch (e) {
126
+ loadErrors.push(e)
127
+ }
128
+ } else {
129
+ try {
130
+ return require('./transform-relay.win32-x64-msvc.node')
131
+ } catch (e) {
132
+ loadErrors.push(e)
133
+ }
134
+ try {
135
+ const binding = require('@oxc-transform-relay/binding-win32-x64-msvc')
136
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-x64-msvc/package.json').version
137
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
139
+ }
140
+ return binding
141
+ } catch (e) {
142
+ loadErrors.push(e)
143
+ }
144
+ }
145
+ } else if (process.arch === 'ia32') {
146
+ try {
147
+ return require('./transform-relay.win32-ia32-msvc.node')
148
+ } catch (e) {
149
+ loadErrors.push(e)
150
+ }
151
+ try {
152
+ const binding = require('@oxc-transform-relay/binding-win32-ia32-msvc')
153
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-ia32-msvc/package.json').version
154
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
156
+ }
157
+ return binding
158
+ } catch (e) {
159
+ loadErrors.push(e)
160
+ }
161
+ } else if (process.arch === 'arm64') {
162
+ try {
163
+ return require('./transform-relay.win32-arm64-msvc.node')
164
+ } catch (e) {
165
+ loadErrors.push(e)
166
+ }
167
+ try {
168
+ const binding = require('@oxc-transform-relay/binding-win32-arm64-msvc')
169
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-win32-arm64-msvc/package.json').version
170
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
+ }
173
+ return binding
174
+ } catch (e) {
175
+ loadErrors.push(e)
176
+ }
177
+ } else {
178
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
179
+ }
180
+ } else if (process.platform === 'darwin') {
181
+ try {
182
+ return require('./transform-relay.darwin-universal.node')
183
+ } catch (e) {
184
+ loadErrors.push(e)
185
+ }
186
+ try {
187
+ const binding = require('@oxc-transform-relay/binding-darwin-universal')
188
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-darwin-universal/package.json').version
189
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
191
+ }
192
+ return binding
193
+ } catch (e) {
194
+ loadErrors.push(e)
195
+ }
196
+ if (process.arch === 'x64') {
197
+ try {
198
+ return require('./transform-relay.darwin-x64.node')
199
+ } catch (e) {
200
+ loadErrors.push(e)
201
+ }
202
+ try {
203
+ const binding = require('@oxc-transform-relay/binding-darwin-x64')
204
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-darwin-x64/package.json').version
205
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
207
+ }
208
+ return binding
209
+ } catch (e) {
210
+ loadErrors.push(e)
211
+ }
212
+ } else if (process.arch === 'arm64') {
213
+ try {
214
+ return require('./transform-relay.darwin-arm64.node')
215
+ } catch (e) {
216
+ loadErrors.push(e)
217
+ }
218
+ try {
219
+ const binding = require('@oxc-transform-relay/binding-darwin-arm64')
220
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-darwin-arm64/package.json').version
221
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
+ }
224
+ return binding
225
+ } catch (e) {
226
+ loadErrors.push(e)
227
+ }
228
+ } else {
229
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
230
+ }
231
+ } else if (process.platform === 'freebsd') {
232
+ if (process.arch === 'x64') {
233
+ try {
234
+ return require('./transform-relay.freebsd-x64.node')
235
+ } catch (e) {
236
+ loadErrors.push(e)
237
+ }
238
+ try {
239
+ const binding = require('@oxc-transform-relay/binding-freebsd-x64')
240
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-freebsd-x64/package.json').version
241
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
243
+ }
244
+ return binding
245
+ } catch (e) {
246
+ loadErrors.push(e)
247
+ }
248
+ } else if (process.arch === 'arm64') {
249
+ try {
250
+ return require('./transform-relay.freebsd-arm64.node')
251
+ } catch (e) {
252
+ loadErrors.push(e)
253
+ }
254
+ try {
255
+ const binding = require('@oxc-transform-relay/binding-freebsd-arm64')
256
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-freebsd-arm64/package.json').version
257
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
259
+ }
260
+ return binding
261
+ } catch (e) {
262
+ loadErrors.push(e)
263
+ }
264
+ } else {
265
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
266
+ }
267
+ } else if (process.platform === 'linux') {
268
+ if (process.arch === 'x64') {
269
+ if (isMusl()) {
270
+ try {
271
+ return require('./transform-relay.linux-x64-musl.node')
272
+ } catch (e) {
273
+ loadErrors.push(e)
274
+ }
275
+ try {
276
+ const binding = require('@oxc-transform-relay/binding-linux-x64-musl')
277
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-x64-musl/package.json').version
278
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
280
+ }
281
+ return binding
282
+ } catch (e) {
283
+ loadErrors.push(e)
284
+ }
285
+ } else {
286
+ try {
287
+ return require('./transform-relay.linux-x64-gnu.node')
288
+ } catch (e) {
289
+ loadErrors.push(e)
290
+ }
291
+ try {
292
+ const binding = require('@oxc-transform-relay/binding-linux-x64-gnu')
293
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-x64-gnu/package.json').version
294
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
+ }
297
+ return binding
298
+ } catch (e) {
299
+ loadErrors.push(e)
300
+ }
301
+ }
302
+ } else if (process.arch === 'arm64') {
303
+ if (isMusl()) {
304
+ try {
305
+ return require('./transform-relay.linux-arm64-musl.node')
306
+ } catch (e) {
307
+ loadErrors.push(e)
308
+ }
309
+ try {
310
+ const binding = require('@oxc-transform-relay/binding-linux-arm64-musl')
311
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm64-musl/package.json').version
312
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
313
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
314
+ }
315
+ return binding
316
+ } catch (e) {
317
+ loadErrors.push(e)
318
+ }
319
+ } else {
320
+ try {
321
+ return require('./transform-relay.linux-arm64-gnu.node')
322
+ } catch (e) {
323
+ loadErrors.push(e)
324
+ }
325
+ try {
326
+ const binding = require('@oxc-transform-relay/binding-linux-arm64-gnu')
327
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm64-gnu/package.json').version
328
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
329
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
330
+ }
331
+ return binding
332
+ } catch (e) {
333
+ loadErrors.push(e)
334
+ }
335
+ }
336
+ } else if (process.arch === 'arm') {
337
+ if (isMusl()) {
338
+ try {
339
+ return require('./transform-relay.linux-arm-musleabihf.node')
340
+ } catch (e) {
341
+ loadErrors.push(e)
342
+ }
343
+ try {
344
+ const binding = require('@oxc-transform-relay/binding-linux-arm-musleabihf')
345
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm-musleabihf/package.json').version
346
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
347
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
348
+ }
349
+ return binding
350
+ } catch (e) {
351
+ loadErrors.push(e)
352
+ }
353
+ } else {
354
+ try {
355
+ return require('./transform-relay.linux-arm-gnueabihf.node')
356
+ } catch (e) {
357
+ loadErrors.push(e)
358
+ }
359
+ try {
360
+ const binding = require('@oxc-transform-relay/binding-linux-arm-gnueabihf')
361
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-arm-gnueabihf/package.json').version
362
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
363
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
364
+ }
365
+ return binding
366
+ } catch (e) {
367
+ loadErrors.push(e)
368
+ }
369
+ }
370
+ } else if (process.arch === 'loong64') {
371
+ if (isMusl()) {
372
+ try {
373
+ return require('./transform-relay.linux-loong64-musl.node')
374
+ } catch (e) {
375
+ loadErrors.push(e)
376
+ }
377
+ try {
378
+ const binding = require('@oxc-transform-relay/binding-linux-loong64-musl')
379
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-loong64-musl/package.json').version
380
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
382
+ }
383
+ return binding
384
+ } catch (e) {
385
+ loadErrors.push(e)
386
+ }
387
+ } else {
388
+ try {
389
+ return require('./transform-relay.linux-loong64-gnu.node')
390
+ } catch (e) {
391
+ loadErrors.push(e)
392
+ }
393
+ try {
394
+ const binding = require('@oxc-transform-relay/binding-linux-loong64-gnu')
395
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-loong64-gnu/package.json').version
396
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
398
+ }
399
+ return binding
400
+ } catch (e) {
401
+ loadErrors.push(e)
402
+ }
403
+ }
404
+ } else if (process.arch === 'riscv64') {
405
+ if (isMusl()) {
406
+ try {
407
+ return require('./transform-relay.linux-riscv64-musl.node')
408
+ } catch (e) {
409
+ loadErrors.push(e)
410
+ }
411
+ try {
412
+ const binding = require('@oxc-transform-relay/binding-linux-riscv64-musl')
413
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-riscv64-musl/package.json').version
414
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
415
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
416
+ }
417
+ return binding
418
+ } catch (e) {
419
+ loadErrors.push(e)
420
+ }
421
+ } else {
422
+ try {
423
+ return require('./transform-relay.linux-riscv64-gnu.node')
424
+ } catch (e) {
425
+ loadErrors.push(e)
426
+ }
427
+ try {
428
+ const binding = require('@oxc-transform-relay/binding-linux-riscv64-gnu')
429
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-riscv64-gnu/package.json').version
430
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
432
+ }
433
+ return binding
434
+ } catch (e) {
435
+ loadErrors.push(e)
436
+ }
437
+ }
438
+ } else if (process.arch === 'ppc64') {
439
+ try {
440
+ return require('./transform-relay.linux-ppc64-gnu.node')
441
+ } catch (e) {
442
+ loadErrors.push(e)
443
+ }
444
+ try {
445
+ const binding = require('@oxc-transform-relay/binding-linux-ppc64-gnu')
446
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-ppc64-gnu/package.json').version
447
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
449
+ }
450
+ return binding
451
+ } catch (e) {
452
+ loadErrors.push(e)
453
+ }
454
+ } else if (process.arch === 's390x') {
455
+ try {
456
+ return require('./transform-relay.linux-s390x-gnu.node')
457
+ } catch (e) {
458
+ loadErrors.push(e)
459
+ }
460
+ try {
461
+ const binding = require('@oxc-transform-relay/binding-linux-s390x-gnu')
462
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-linux-s390x-gnu/package.json').version
463
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
465
+ }
466
+ return binding
467
+ } catch (e) {
468
+ loadErrors.push(e)
469
+ }
470
+ } else {
471
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
472
+ }
473
+ } else if (process.platform === 'openharmony') {
474
+ if (process.arch === 'arm64') {
475
+ try {
476
+ return require('./transform-relay.openharmony-arm64.node')
477
+ } catch (e) {
478
+ loadErrors.push(e)
479
+ }
480
+ try {
481
+ const binding = require('@oxc-transform-relay/binding-openharmony-arm64')
482
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-openharmony-arm64/package.json').version
483
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
484
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
485
+ }
486
+ return binding
487
+ } catch (e) {
488
+ loadErrors.push(e)
489
+ }
490
+ } else if (process.arch === 'x64') {
491
+ try {
492
+ return require('./transform-relay.openharmony-x64.node')
493
+ } catch (e) {
494
+ loadErrors.push(e)
495
+ }
496
+ try {
497
+ const binding = require('@oxc-transform-relay/binding-openharmony-x64')
498
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-openharmony-x64/package.json').version
499
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
500
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
501
+ }
502
+ return binding
503
+ } catch (e) {
504
+ loadErrors.push(e)
505
+ }
506
+ } else if (process.arch === 'arm') {
507
+ try {
508
+ return require('./transform-relay.openharmony-arm.node')
509
+ } catch (e) {
510
+ loadErrors.push(e)
511
+ }
512
+ try {
513
+ const binding = require('@oxc-transform-relay/binding-openharmony-arm')
514
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-openharmony-arm/package.json').version
515
+ if (bindingPackageVersion !== '0.147.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
+ throw new Error(`Native binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
517
+ }
518
+ return binding
519
+ } catch (e) {
520
+ loadErrors.push(e)
521
+ }
522
+ } else {
523
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
524
+ }
525
+ } else {
526
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
527
+ }
528
+ }
529
+
530
+ function createLoadErrorChain(errors) {
531
+ return errors.reduce((previous, current) => {
532
+ let message
533
+ try {
534
+ message =
535
+ current && typeof current.message === 'string'
536
+ ? current.message
537
+ : String(current)
538
+ } catch {
539
+ message = 'Unknown error'
540
+ }
541
+ const error = new Error(message)
542
+ error.cause = previous
543
+ return error
544
+ }, null)
545
+ }
546
+
547
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
548
+ // unset / any other value → native binding preferred, WASI is only a fallback
549
+ // 'true' → prefer WASI, but retain native as a lazy fallback
550
+ // 'error' → require WASI without initializing a native fallback
551
+ // Treating any non-empty string as truthy (the historical behavior) meant
552
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
553
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
554
+ //
555
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
556
+ // WASI loading. It never crosses into another flavor or falls back to native.
557
+ const __napiWasiFlavors = ["wasm32-wasi"]
558
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
559
+ const __napiWasiFlavorRequested =
560
+ typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
561
+ if (
562
+ __napiWasiFlavorRequested &&
563
+ __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
564
+ ) {
565
+ throw new Error(
566
+ 'Unsupported WASI flavor "' +
567
+ __napiWasiFlavor +
568
+ '". Available flavors: ' +
569
+ __napiWasiFlavors.join(', '),
570
+ )
571
+ }
572
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
573
+ const forceWasi =
574
+ process.env.NAPI_RS_FORCE_WASI === 'true' ||
575
+ forceWasiError ||
576
+ __napiWasiFlavorRequested
577
+
578
+ if (!forceWasi) {
579
+ nativeBinding = requireNative()
580
+ }
581
+
582
+ if (!nativeBinding || forceWasi) {
583
+ let wasiBinding = null
584
+ let wasiBindingLoaded = false
585
+ const wasiBindingErrors = []
586
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
587
+ try {
588
+ require.resolve(specifier)
589
+ } catch (resolveError) {
590
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
591
+ throw resolveError
592
+ }
593
+ if (isPackage) {
594
+ try {
595
+ require.resolve(specifier + '/package.json')
596
+ } catch (packageError) {
597
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
598
+ return resolveError
599
+ }
600
+ // An exports restriction proves the package exists even when its
601
+ // package.json is not public. Preserve the root resolution failure.
602
+ throw resolveError
603
+ }
604
+ // The package exists but its main/export target is broken.
605
+ throw resolveError
606
+ }
607
+ return resolveError
608
+ }
609
+ if (localArtifacts) {
610
+ let artifactError = null
611
+ for (let i = 0; i < localArtifacts.length; i++) {
612
+ try {
613
+ require.resolve(localArtifacts[i])
614
+ return null
615
+ } catch (resolveError) {
616
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
617
+ throw resolveError
618
+ }
619
+ artifactError = resolveError
620
+ }
621
+ }
622
+ return artifactError
623
+ }
624
+ return null
625
+ }
626
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
627
+ let candidateError = null
628
+ let candidateFailed = false
629
+ try {
630
+ candidateError = __napiWasiResolveCandidate('./transform-relay.wasi.cjs', false, ["./transform-relay.wasm32-wasi.debug.wasm","./transform-relay.wasm32-wasi.wasm"])
631
+ candidateFailed = candidateError !== null
632
+ if (!candidateFailed) {
633
+ wasiBinding = require('./transform-relay.wasi.cjs')
634
+ nativeBinding = wasiBinding
635
+ wasiBindingLoaded = true
636
+ }
637
+ } catch (err) {
638
+ candidateError = err
639
+ candidateFailed = true
640
+ }
641
+ if (candidateFailed) {
642
+ wasiBindingErrors.push(candidateError)
643
+ loadErrors.push(candidateError)
644
+ }
645
+ }
646
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
647
+ let candidateError = null
648
+ let candidateFailed = false
649
+ try {
650
+ candidateError = __napiWasiResolveCandidate('@oxc-transform-relay/binding-wasm32-wasi', true, undefined)
651
+ candidateFailed = candidateError !== null
652
+ if (!candidateFailed) {
653
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
654
+ const bindingPackageVersion = require('@oxc-transform-relay/binding-wasm32-wasi/package.json').version
655
+ if (bindingPackageVersion !== '0.147.0') {
656
+ throw new Error(`WASI binding package version mismatch, expected 0.147.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
657
+ }
658
+ }
659
+ wasiBinding = require('@oxc-transform-relay/binding-wasm32-wasi')
660
+ nativeBinding = wasiBinding
661
+ wasiBindingLoaded = true
662
+ }
663
+ } catch (err) {
664
+ candidateError = err
665
+ candidateFailed = true
666
+ }
667
+ if (candidateFailed) {
668
+ wasiBindingErrors.push(candidateError)
669
+ loadErrors.push(candidateError)
670
+ }
671
+ }
672
+ if (
673
+ !wasiBindingLoaded &&
674
+ forceWasi &&
675
+ !forceWasiError &&
676
+ !__napiWasiFlavorRequested
677
+ ) {
678
+ nativeBinding = requireNative()
679
+ }
680
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
681
+ const error = new Error(
682
+ __napiWasiFlavorRequested
683
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
684
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
685
+ )
686
+ error.cause = createLoadErrorChain(wasiBindingErrors)
687
+ throw error
688
+ }
689
+ }
690
+
691
+ if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
692
+ try {
693
+ nativeBinding = require('./webcontainer-fallback.cjs');
694
+ } catch (err) {
695
+ loadErrors.push(err)
696
+ }
697
+ }
698
+
699
+ if (!nativeBinding) {
700
+ if (loadErrors.length > 0) {
701
+ const error = new Error(
702
+ `Cannot find native binding. ` +
703
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
704
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
705
+ )
706
+ // assign instead of the `new Error(message, { cause })` options form,
707
+ // which Node < 16.9 silently ignores
708
+ error.cause = createLoadErrorChain(loadErrors)
709
+ throw error
710
+ }
711
+ throw new Error(`Failed to load native binding`)
712
+ }
713
+
714
+ const { Severity, transform, transformSync } = nativeBinding
715
+ export { Severity }
716
+ export { transform }
717
+ export { transformSync }
package/package.json CHANGED
@@ -1,15 +1,112 @@
1
1
  {
2
2
  "name": "oxc-transform-relay",
3
- "version": "0.0.1",
4
- "description": "Placeholder package for the Oxc Relay Transform Node API",
3
+ "version": "0.147.0",
4
+ "description": "Oxc Relay Transform Node API",
5
+ "keywords": [
6
+ "graphql",
7
+ "javascript",
8
+ "oxc",
9
+ "relay",
10
+ "transform",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://oxc.rs",
14
+ "bugs": "https://github.com/oxc-project/oxc/issues",
5
15
  "license": "MIT",
16
+ "author": "Boshen and oxc contributors",
6
17
  "repository": {
7
18
  "type": "git",
8
19
  "url": "git+https://github.com/oxc-project/oxc.git",
9
20
  "directory": "napi/transform-relay"
10
21
  },
22
+ "funding": {
23
+ "url": "https://github.com/sponsors/Boshen"
24
+ },
25
+ "files": [
26
+ "browser.js",
27
+ "index.d.ts",
28
+ "index.js",
29
+ "webcontainer-fallback.cjs"
30
+ ],
31
+ "type": "module",
32
+ "sideEffects": false,
33
+ "main": "index.js",
34
+ "browser": "browser.js",
11
35
  "publishConfig": {
12
36
  "access": "public",
13
37
  "registry": "https://registry.npmjs.org/"
38
+ },
39
+ "devDependencies": {
40
+ "@emnapi/core": "2.0.0-alpha.3",
41
+ "@emnapi/runtime": "2.0.0-alpha.3",
42
+ "@napi-rs/cli": "3.8.6",
43
+ "@types/node": "24.1.0",
44
+ "publint": "0.3.24",
45
+ "vitest": "4.1.11"
46
+ },
47
+ "napi": {
48
+ "binaryName": "transform-relay",
49
+ "packageName": "@oxc-transform-relay/binding",
50
+ "targets": [
51
+ "aarch64-apple-darwin",
52
+ "aarch64-linux-android",
53
+ "aarch64-pc-windows-msvc",
54
+ "aarch64-unknown-linux-gnu",
55
+ "aarch64-unknown-linux-musl",
56
+ "aarch64-unknown-linux-ohos",
57
+ "armv7-linux-androideabi",
58
+ "armv7-unknown-linux-gnueabihf",
59
+ "armv7-unknown-linux-musleabihf",
60
+ "i686-pc-windows-msvc",
61
+ "powerpc64le-unknown-linux-gnu",
62
+ "riscv64gc-unknown-linux-gnu",
63
+ "riscv64gc-unknown-linux-musl",
64
+ "s390x-unknown-linux-gnu",
65
+ "wasm32-wasip1-threads",
66
+ "x86_64-apple-darwin",
67
+ "x86_64-pc-windows-msvc",
68
+ "x86_64-unknown-freebsd",
69
+ "x86_64-unknown-linux-gnu",
70
+ "x86_64-unknown-linux-musl"
71
+ ],
72
+ "wasm": {
73
+ "browser": {
74
+ "fs": false
75
+ }
76
+ }
77
+ },
78
+ "engines": {
79
+ "node": "^20.19.0 || >=22.12.0"
80
+ },
81
+ "optionalDependencies": {
82
+ "@oxc-transform-relay/binding-darwin-arm64": "0.147.0",
83
+ "@oxc-transform-relay/binding-android-arm64": "0.147.0",
84
+ "@oxc-transform-relay/binding-win32-arm64-msvc": "0.147.0",
85
+ "@oxc-transform-relay/binding-linux-arm64-gnu": "0.147.0",
86
+ "@oxc-transform-relay/binding-linux-arm64-musl": "0.147.0",
87
+ "@oxc-transform-relay/binding-openharmony-arm64": "0.147.0",
88
+ "@oxc-transform-relay/binding-android-arm-eabi": "0.147.0",
89
+ "@oxc-transform-relay/binding-linux-arm-gnueabihf": "0.147.0",
90
+ "@oxc-transform-relay/binding-linux-arm-musleabihf": "0.147.0",
91
+ "@oxc-transform-relay/binding-win32-ia32-msvc": "0.147.0",
92
+ "@oxc-transform-relay/binding-linux-ppc64-gnu": "0.147.0",
93
+ "@oxc-transform-relay/binding-linux-riscv64-gnu": "0.147.0",
94
+ "@oxc-transform-relay/binding-linux-riscv64-musl": "0.147.0",
95
+ "@oxc-transform-relay/binding-linux-s390x-gnu": "0.147.0",
96
+ "@oxc-transform-relay/binding-darwin-x64": "0.147.0",
97
+ "@oxc-transform-relay/binding-win32-x64-msvc": "0.147.0",
98
+ "@oxc-transform-relay/binding-freebsd-x64": "0.147.0",
99
+ "@oxc-transform-relay/binding-linux-x64-gnu": "0.147.0",
100
+ "@oxc-transform-relay/binding-linux-x64-musl": "0.147.0"
101
+ },
102
+ "scripts": {
103
+ "build-dev": "napi build --esm --platform",
104
+ "build-test": "pnpm run build-dev --profile coverage",
105
+ "build": "pnpm run build-dev --features allocator --release",
106
+ "postbuild": "publint",
107
+ "postbuild-dev": "node scripts/patch.js",
108
+ "build-wasm": "pnpm run build-wasm-dev --release",
109
+ "build-wasm-dev": "pnpm run build-dev --target wasm32-wasip1-threads --dts transform-relay.wasi.d.cts",
110
+ "test": "vitest run --dir ./test"
14
111
  }
15
- }
112
+ }
@@ -0,0 +1,23 @@
1
+ const fs = require("node:fs");
2
+ const childProcess = require("node:child_process");
3
+
4
+ const pkg = JSON.parse(
5
+ fs.readFileSync(require.resolve("oxc-transform-relay/package.json"), "utf-8"),
6
+ );
7
+ const { version } = pkg;
8
+ const baseDir = `/tmp/oxc-transform-relay-${version}`;
9
+ const bindingEntry = `${baseDir}/node_modules/@oxc-transform-relay/binding-wasm32-wasi/transform-relay.wasi.cjs`;
10
+
11
+ if (!fs.existsSync(bindingEntry)) {
12
+ fs.rmSync(baseDir, { recursive: true, force: true });
13
+ fs.mkdirSync(baseDir, { recursive: true });
14
+ const bindingPkg = `@oxc-transform-relay/binding-wasm32-wasi@${version}`;
15
+ // oxlint-disable-next-line no-console
16
+ console.log(`[oxc-transform-relay] Downloading ${bindingPkg} on WebContainer...`);
17
+ childProcess.execFileSync("pnpm", ["i", bindingPkg], {
18
+ cwd: baseDir,
19
+ stdio: "inherit",
20
+ });
21
+ }
22
+
23
+ module.exports = require(bindingEntry);