@rspack/binding 1.4.10 → 1.5.0-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.
Files changed (3) hide show
  1. package/binding.js +358 -193
  2. package/napi-binding.d.ts +261 -5
  3. package/package.json +15 -13
package/binding.js CHANGED
@@ -1,229 +1,394 @@
1
- const { existsSync } = require('fs')
2
- const { join } = require('path')
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
3
5
 
4
- const { platform, arch } = process
6
+ const { createRequire } = require('node:module')
7
+ require = createRequire(__filename)
5
8
 
9
+ const { readFileSync } = require('node:fs')
6
10
  let nativeBinding = null
7
- let localFileExisted = false
8
- let loadError = null
11
+ const loadErrors = []
9
12
 
10
- function isMusl() {
11
- const { glibcVersionRuntime } = process.report.getReport().header
12
- return !glibcVersionRuntime
13
+ const isMusl = () => {
14
+ let musl = false
15
+ if (process.platform === 'linux') {
16
+ musl = isMuslFromFilesystem()
17
+ if (musl === null) {
18
+ musl = isMuslFromReport()
19
+ }
20
+ if (musl === null) {
21
+ musl = isMuslFromChildProcess()
22
+ }
23
+ }
24
+ return musl
25
+ }
26
+
27
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
28
+
29
+ const isMuslFromFilesystem = () => {
30
+ try {
31
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
32
+ } catch {
33
+ return null
34
+ }
13
35
  }
14
36
 
15
- switch (platform) {
16
- case 'android':
17
- switch (arch) {
18
- case 'arm64':
19
- localFileExisted = existsSync(join(__dirname, 'rspack.android-arm64.node'))
20
- try {
21
- if (localFileExisted) {
22
- nativeBinding = require('./rspack.android-arm64.node')
23
- } else {
24
- nativeBinding = require('@rspack/binding-android-arm64')
25
- }
26
- } catch (e) {
27
- loadError = e
28
- }
29
- break
30
- case 'arm':
31
- localFileExisted = existsSync(join(__dirname, 'rspack.android-arm-eabi.node'))
32
- try {
33
- if (localFileExisted) {
34
- nativeBinding = require('./rspack.android-arm-eabi.node')
35
- } else {
36
- nativeBinding = require('@rspack/binding-android-arm-eabi')
37
- }
38
- } catch (e) {
39
- loadError = e
40
- }
41
- break
42
- default:
43
- throw new Error(`Unsupported architecture on Android ${arch}`)
37
+ const isMuslFromReport = () => {
38
+ let report = null
39
+ if (typeof process.report?.getReport === 'function') {
40
+ process.report.excludeNetwork = true
41
+ report = process.report.getReport()
42
+ }
43
+ if (!report) {
44
+ return null
45
+ }
46
+ if (report.header && report.header.glibcVersionRuntime) {
47
+ return false
48
+ }
49
+ if (Array.isArray(report.sharedObjects)) {
50
+ if (report.sharedObjects.some(isFileMusl)) {
51
+ return true
44
52
  }
45
- break
46
- case 'win32':
47
- switch (arch) {
48
- case 'x64':
49
- localFileExisted = existsSync(join(__dirname, 'rspack.win32-x64-msvc.node'))
50
- try {
51
- if (localFileExisted) {
52
- nativeBinding = require('./rspack.win32-x64-msvc.node')
53
- } else {
54
- nativeBinding = require('@rspack/binding-win32-x64-msvc')
55
- }
56
- } catch (e) {
57
- loadError = e
58
- }
59
- break
60
- case 'ia32':
61
- localFileExisted = existsSync(join(__dirname, 'rspack.win32-ia32-msvc.node'))
62
- try {
63
- if (localFileExisted) {
64
- nativeBinding = require('./rspack.win32-ia32-msvc.node')
65
- } else {
66
- nativeBinding = require('@rspack/binding-win32-ia32-msvc')
67
- }
68
- } catch (e) {
69
- loadError = e
70
- }
71
- break
72
- case 'arm64':
73
- localFileExisted = existsSync(join(__dirname, 'rspack.win32-arm64-msvc.node'))
74
- try {
75
- if (localFileExisted) {
76
- nativeBinding = require('./rspack.win32-arm64-msvc.node')
77
- } else {
78
- nativeBinding = require('@rspack/binding-win32-arm64-msvc')
79
- }
80
- } catch (e) {
81
- loadError = e
82
- }
83
- break
84
- default:
85
- throw new Error(`Unsupported architecture on Windows: ${arch}`)
53
+ }
54
+ return false
55
+ }
56
+
57
+ const isMuslFromChildProcess = () => {
58
+ try {
59
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
60
+ } catch (e) {
61
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
62
+ return false
63
+ }
64
+ }
65
+
66
+ function requireNative() {
67
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
68
+ try {
69
+ nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
70
+ } catch (err) {
71
+ loadErrors.push(err)
86
72
  }
87
- break
88
- case 'darwin':
89
- switch (arch) {
90
- case 'x64':
91
- localFileExisted = existsSync(join(__dirname, 'rspack.darwin-x64.node'))
92
- try {
93
- if (localFileExisted) {
94
- nativeBinding = require('./rspack.darwin-x64.node')
95
- } else {
96
- nativeBinding = require('@rspack/binding-darwin-x64')
97
- }
98
- } catch (e) {
99
- loadError = e
100
- }
101
- break
102
- case 'arm64':
103
- localFileExisted = existsSync(join(__dirname, 'rspack.darwin-arm64.node'))
104
- try {
105
- if (localFileExisted) {
106
- nativeBinding = require('./rspack.darwin-arm64.node')
107
- } else {
108
- nativeBinding = require('@rspack/binding-darwin-arm64')
109
- }
110
- } catch (e) {
111
- loadError = e
112
- }
113
- break
114
- default:
115
- throw new Error(`Unsupported architecture on macOS: ${arch}`)
73
+ } else if (process.platform === 'android') {
74
+ if (process.arch === 'arm64') {
75
+ try {
76
+ return require('./rspack.android-arm64.node')
77
+ } catch (e) {
78
+ loadErrors.push(e)
79
+ }
80
+ try {
81
+ return require('@rspack/binding-android-arm64')
82
+ } catch (e) {
83
+ loadErrors.push(e)
84
+ }
85
+ } else if (process.arch === 'arm') {
86
+ try {
87
+ return require('./rspack.android-arm-eabi.node')
88
+ } catch (e) {
89
+ loadErrors.push(e)
90
+ }
91
+ try {
92
+ return require('@rspack/binding-android-arm-eabi')
93
+ } catch (e) {
94
+ loadErrors.push(e)
95
+ }
96
+ } else {
97
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
116
98
  }
117
- break
118
- case 'freebsd':
119
- if (arch !== 'x64') {
120
- throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
99
+ } else if (process.platform === 'win32') {
100
+ if (process.arch === 'x64') {
101
+ try {
102
+ return require('./rspack.win32-x64-msvc.node')
103
+ } catch (e) {
104
+ loadErrors.push(e)
105
+ }
106
+ try {
107
+ return require('@rspack/binding-win32-x64-msvc')
108
+ } catch (e) {
109
+ loadErrors.push(e)
110
+ }
111
+ } else if (process.arch === 'ia32') {
112
+ try {
113
+ return require('./rspack.win32-ia32-msvc.node')
114
+ } catch (e) {
115
+ loadErrors.push(e)
116
+ }
117
+ try {
118
+ return require('@rspack/binding-win32-ia32-msvc')
119
+ } catch (e) {
120
+ loadErrors.push(e)
121
+ }
122
+ } else if (process.arch === 'arm64') {
123
+ try {
124
+ return require('./rspack.win32-arm64-msvc.node')
125
+ } catch (e) {
126
+ loadErrors.push(e)
127
+ }
128
+ try {
129
+ return require('@rspack/binding-win32-arm64-msvc')
130
+ } catch (e) {
131
+ loadErrors.push(e)
132
+ }
133
+ } else {
134
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
135
+ }
136
+ } else if (process.platform === 'darwin') {
137
+ try {
138
+ return require('./rspack.darwin-universal.node')
139
+ } catch (e) {
140
+ loadErrors.push(e)
121
141
  }
122
- localFileExisted = existsSync(join(__dirname, 'rspack.freebsd-x64.node'))
123
142
  try {
124
- if (localFileExisted) {
125
- nativeBinding = require('./rspack.freebsd-x64.node')
143
+ return require('@rspack/binding-darwin-universal')
144
+ } catch (e) {
145
+ loadErrors.push(e)
146
+ }
147
+ if (process.arch === 'x64') {
148
+ try {
149
+ return require('./rspack.darwin-x64.node')
150
+ } catch (e) {
151
+ loadErrors.push(e)
152
+ }
153
+ try {
154
+ return require('@rspack/binding-darwin-x64')
155
+ } catch (e) {
156
+ loadErrors.push(e)
157
+ }
158
+ } else if (process.arch === 'arm64') {
159
+ try {
160
+ return require('./rspack.darwin-arm64.node')
161
+ } catch (e) {
162
+ loadErrors.push(e)
163
+ }
164
+ try {
165
+ return require('@rspack/binding-darwin-arm64')
166
+ } catch (e) {
167
+ loadErrors.push(e)
168
+ }
169
+ } else {
170
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
171
+ }
172
+ } else if (process.platform === 'freebsd') {
173
+ if (process.arch === 'x64') {
174
+ try {
175
+ return require('./rspack.freebsd-x64.node')
176
+ } catch (e) {
177
+ loadErrors.push(e)
178
+ }
179
+ try {
180
+ return require('@rspack/binding-freebsd-x64')
181
+ } catch (e) {
182
+ loadErrors.push(e)
183
+ }
184
+ } else if (process.arch === 'arm64') {
185
+ try {
186
+ return require('./rspack.freebsd-arm64.node')
187
+ } catch (e) {
188
+ loadErrors.push(e)
189
+ }
190
+ try {
191
+ return require('@rspack/binding-freebsd-arm64')
192
+ } catch (e) {
193
+ loadErrors.push(e)
194
+ }
195
+ } else {
196
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
197
+ }
198
+ } else if (process.platform === 'linux') {
199
+ if (process.arch === 'x64') {
200
+ if (isMusl()) {
201
+ try {
202
+ return require('./rspack.linux-x64-musl.node')
203
+ } catch (e) {
204
+ loadErrors.push(e)
205
+ }
206
+ try {
207
+ return require('@rspack/binding-linux-x64-musl')
208
+ } catch (e) {
209
+ loadErrors.push(e)
210
+ }
211
+ } else {
212
+ try {
213
+ return require('./rspack.linux-x64-gnu.node')
214
+ } catch (e) {
215
+ loadErrors.push(e)
216
+ }
217
+ try {
218
+ return require('@rspack/binding-linux-x64-gnu')
219
+ } catch (e) {
220
+ loadErrors.push(e)
221
+ }
222
+ }
223
+ } else if (process.arch === 'arm64') {
224
+ if (isMusl()) {
225
+ try {
226
+ return require('./rspack.linux-arm64-musl.node')
227
+ } catch (e) {
228
+ loadErrors.push(e)
229
+ }
230
+ try {
231
+ return require('@rspack/binding-linux-arm64-musl')
232
+ } catch (e) {
233
+ loadErrors.push(e)
234
+ }
126
235
  } else {
127
- nativeBinding = require('@rspack/binding-freebsd-x64')
236
+ try {
237
+ return require('./rspack.linux-arm64-gnu.node')
238
+ } catch (e) {
239
+ loadErrors.push(e)
240
+ }
241
+ try {
242
+ return require('@rspack/binding-linux-arm64-gnu')
243
+ } catch (e) {
244
+ loadErrors.push(e)
245
+ }
128
246
  }
129
- } catch (e) {
130
- loadError = e
247
+ } else if (process.arch === 'arm') {
248
+ if (isMusl()) {
249
+ try {
250
+ return require('./rspack.linux-arm-musleabihf.node')
251
+ } catch (e) {
252
+ loadErrors.push(e)
253
+ }
254
+ try {
255
+ return require('@rspack/binding-linux-arm-musleabihf')
256
+ } catch (e) {
257
+ loadErrors.push(e)
258
+ }
259
+ } else {
260
+ try {
261
+ return require('./rspack.linux-arm-gnueabihf.node')
262
+ } catch (e) {
263
+ loadErrors.push(e)
264
+ }
265
+ try {
266
+ return require('@rspack/binding-linux-arm-gnueabihf')
267
+ } catch (e) {
268
+ loadErrors.push(e)
269
+ }
270
+ }
271
+ } else if (process.arch === 'riscv64') {
272
+ if (isMusl()) {
273
+ try {
274
+ return require('./rspack.linux-riscv64-musl.node')
275
+ } catch (e) {
276
+ loadErrors.push(e)
277
+ }
278
+ try {
279
+ return require('@rspack/binding-linux-riscv64-musl')
280
+ } catch (e) {
281
+ loadErrors.push(e)
282
+ }
283
+ } else {
284
+ try {
285
+ return require('./rspack.linux-riscv64-gnu.node')
286
+ } catch (e) {
287
+ loadErrors.push(e)
288
+ }
289
+ try {
290
+ return require('@rspack/binding-linux-riscv64-gnu')
291
+ } catch (e) {
292
+ loadErrors.push(e)
293
+ }
294
+ }
295
+ } else if (process.arch === 'ppc64') {
296
+ try {
297
+ return require('./rspack.linux-ppc64-gnu.node')
298
+ } catch (e) {
299
+ loadErrors.push(e)
300
+ }
301
+ try {
302
+ return require('@rspack/binding-linux-ppc64-gnu')
303
+ } catch (e) {
304
+ loadErrors.push(e)
305
+ }
306
+ } else if (process.arch === 's390x') {
307
+ try {
308
+ return require('./rspack.linux-s390x-gnu.node')
309
+ } catch (e) {
310
+ loadErrors.push(e)
311
+ }
312
+ try {
313
+ return require('@rspack/binding-linux-s390x-gnu')
314
+ } catch (e) {
315
+ loadErrors.push(e)
316
+ }
317
+ } else {
318
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
131
319
  }
132
- break
133
- case 'linux':
134
- switch (arch) {
135
- case 'x64':
136
- if (isMusl()) {
137
- localFileExisted = existsSync(join(__dirname, 'rspack.linux-x64-musl.node'))
138
- try {
139
- if (localFileExisted) {
140
- nativeBinding = require('./rspack.linux-x64-musl.node')
141
- } else {
142
- nativeBinding = require('@rspack/binding-linux-x64-musl')
143
- }
144
- } catch (e) {
145
- loadError = e
146
- }
147
- } else {
148
- localFileExisted = existsSync(join(__dirname, 'rspack.linux-x64-gnu.node'))
149
- try {
150
- if (localFileExisted) {
151
- nativeBinding = require('./rspack.linux-x64-gnu.node')
152
- } else {
153
- nativeBinding = require('@rspack/binding-linux-x64-gnu')
154
- }
155
- } catch (e) {
156
- loadError = e
157
- }
158
- }
159
- break
160
- case 'arm64':
161
- if (isMusl()) {
162
- localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm64-musl.node'))
163
- try {
164
- if (localFileExisted) {
165
- nativeBinding = require('./rspack.linux-arm64-musl.node')
166
- } else {
167
- nativeBinding = require('@rspack/binding-linux-arm64-musl')
168
- }
169
- } catch (e) {
170
- loadError = e
171
- }
172
- } else {
173
- localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm64-gnu.node'))
174
- try {
175
- if (localFileExisted) {
176
- nativeBinding = require('./rspack.linux-arm64-gnu.node')
177
- } else {
178
- nativeBinding = require('@rspack/binding-linux-arm64-gnu')
179
- }
180
- } catch (e) {
181
- loadError = e
182
- }
183
- }
184
- break
185
- case 'arm':
186
- localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm-gnueabihf.node'))
187
- try {
188
- if (localFileExisted) {
189
- nativeBinding = require('./rspack.linux-arm-gnueabihf.node')
190
- } else {
191
- nativeBinding = require('@rspack/binding-linux-arm-gnueabihf')
192
- }
193
- } catch (e) {
194
- loadError = e
195
- }
196
- break
197
- default:
198
- throw new Error(`Unsupported architecture on Linux: ${arch}`)
320
+ } else if (process.platform === 'openharmony') {
321
+ if (process.arch === 'arm64') {
322
+ try {
323
+ return require('./rspack.linux-arm64-ohos.node')
324
+ } catch (e) {
325
+ loadErrors.push(e)
326
+ }
327
+ try {
328
+ return require('@rspack/binding-linux-arm64-ohos')
329
+ } catch (e) {
330
+ loadErrors.push(e)
331
+ }
332
+ } else if (process.arch === 'x64') {
333
+ try {
334
+ return require('./rspack.linux-x64-ohos.node')
335
+ } catch (e) {
336
+ loadErrors.push(e)
337
+ }
338
+ try {
339
+ return require('@rspack/binding-linux-x64-ohos')
340
+ } catch (e) {
341
+ loadErrors.push(e)
342
+ }
343
+ } else if (process.arch === 'arm') {
344
+ try {
345
+ return require('./rspack.linux-arm-ohos.node')
346
+ } catch (e) {
347
+ loadErrors.push(e)
348
+ }
349
+ try {
350
+ return require('@rspack/binding-linux-arm-ohos')
351
+ } catch (e) {
352
+ loadErrors.push(e)
353
+ }
354
+ } else {
355
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
199
356
  }
200
- break
201
- default:
202
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
357
+ } else {
358
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
359
+ }
203
360
  }
204
361
 
362
+ nativeBinding = requireNative()
363
+
205
364
  if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
206
365
  try {
207
366
  nativeBinding = require('./rspack.wasi.cjs')
208
- } catch (e) {
367
+ } catch (err) {
209
368
  if (process.env.NAPI_RS_FORCE_WASI) {
210
- loadError = e
369
+ loadErrors.push(err)
211
370
  }
212
371
  }
213
372
  if (!nativeBinding) {
214
373
  try {
215
374
  nativeBinding = require('@rspack/binding-wasm32-wasi')
216
- } catch (e) {
375
+ } catch (err) {
217
376
  if (process.env.NAPI_RS_FORCE_WASI) {
218
- loadError = e
377
+ loadErrors.push(err)
219
378
  }
220
379
  }
221
380
  }
222
381
  }
223
382
 
224
383
  if (!nativeBinding) {
225
- if (loadError) {
226
- throw loadError
384
+ if (loadErrors.length > 0) {
385
+ throw new Error(
386
+ `Cannot find native binding. ` +
387
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
388
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.' +
389
+ `\n\n${loadErrors.map((e) => e.message).join('\n')}`,
390
+ { cause: loadErrors }
391
+ )
227
392
  }
228
393
  throw new Error(`Failed to load native binding`)
229
394
  }
package/napi-binding.d.ts CHANGED
@@ -328,6 +328,7 @@ export declare class JsCompiler {
328
328
  /** Rebuild with the given option passed to the constructor */
329
329
  rebuild(changed_files: string[], removed_files: string[], callback: (err: null | Error) => void): void
330
330
  close(): Promise<void>
331
+ getVirtualFileStore(): VirtualFileStore | null
331
332
  }
332
333
 
333
334
  export declare class JsContextModuleFactoryAfterResolveData {
@@ -406,11 +407,10 @@ export declare class JsModuleGraph {
406
407
  export declare class JsResolver {
407
408
  resolveSync(path: string, request: string): string | undefined
408
409
  resolve(path: string, request: string, callback: (err: null | Error, req?: string) => void): void
409
- withOptions(raw?: RawResolveOptionsWithDependencyType | undefined | null): JsResolver
410
410
  }
411
411
 
412
412
  export declare class JsResolverFactory {
413
- constructor(pnp: boolean)
413
+ constructor(pnp: boolean, jsResolveOptions: RawResolveOptions, jsLoaderResolveOptions: RawResolveOptions)
414
414
  get(type: string, options?: RawResolveOptionsWithDependencyType): JsResolver
415
415
  }
416
416
 
@@ -444,6 +444,7 @@ export declare class ModuleGraphConnection {
444
444
  export declare class NativeWatcher {
445
445
  constructor(options: NativeWatcherOptions)
446
446
  watch(files: [Array<string>, Array<string>], directories: [Array<string>, Array<string>], missing: [Array<string>, Array<string>], callback: (err: Error | null, result: NativeWatchResult) => void, callbackUndelayed: (path: string) => void): void
447
+ triggerEvent(kind: 'change' | 'remove' | 'create', path: string): void
447
448
  /**
448
449
  * # Safety
449
450
  *
@@ -471,10 +472,31 @@ export declare class ReadonlyResourceData {
471
472
  get descriptionFilePath(): string
472
473
  }
473
474
 
475
+ export declare class ResolverFactory {
476
+ constructor(options?: NapiResolveOptions | undefined | null)
477
+ static default(): ResolverFactory
478
+ /** Clone the resolver using the same underlying cache. */
479
+ cloneWithOptions(options: NapiResolveOptions): ResolverFactory
480
+ /** Clear the underlying cache. */
481
+ clearCache(): void
482
+ /** Synchronously resolve `specifier` at an absolute path to a `directory`. */
483
+ sync(directory: string, request: string): ResolveResult
484
+ /** Asynchronously resolve `specifier` at an absolute path to a `directory`. */
485
+ async(directory: string, request: string): Promise<ResolveResult>
486
+ }
487
+
474
488
  export declare class Sources {
475
489
  _get(sourceType: string): JsCompatSourceOwned | null
476
490
  }
477
491
 
492
+ export declare class VirtualFileStore {
493
+ writeVirtualFileSync(path: string, content: string): void
494
+ batchWriteVirtualFilesSync(files: Array<JsVirtualFile>): void
495
+ }
496
+ export type JsVirtualFileStore = VirtualFileStore
497
+
498
+ export declare function async(path: string, request: string): Promise<ResolveResult>
499
+
478
500
  export interface BuiltinPlugin {
479
501
  name: BuiltinPluginName | CustomPluginName
480
502
  options: unknown
@@ -583,6 +605,12 @@ export interface CssChunkingPluginOptions {
583
605
  exclude?: RegExp
584
606
  }
585
607
 
608
+ export declare enum EnforceExtension {
609
+ Auto = 0,
610
+ Enabled = 1,
611
+ Disabled = 2
612
+ }
613
+
586
614
  /**
587
615
  * Expected version of @rspack/core to the current binding version
588
616
  * @internal
@@ -1146,6 +1174,11 @@ export interface JsRsdoctorSideEffect {
1146
1174
  variable?: number
1147
1175
  }
1148
1176
 
1177
+ export interface JsRsdoctorSourceMapFeatures {
1178
+ cheap?: boolean
1179
+ module?: boolean
1180
+ }
1181
+
1149
1182
  export interface JsRsdoctorSourcePosition {
1150
1183
  line?: number
1151
1184
  column?: number
@@ -1454,6 +1487,11 @@ export interface JsTap {
1454
1487
  stage: number
1455
1488
  }
1456
1489
 
1490
+ export interface JsVirtualFile {
1491
+ path: string
1492
+ content: string
1493
+ }
1494
+
1457
1495
  export interface KnownAssetInfo {
1458
1496
  /** if the asset can be long term cached forever (contains a hash) */
1459
1497
  immutable?: boolean
@@ -1495,12 +1533,187 @@ export declare function minify(source: string, options: string): Promise<Transfo
1495
1533
 
1496
1534
  export declare function minifySync(source: string, options: string): TransformOutput
1497
1535
 
1536
+ /**
1537
+ * Module Resolution Options
1538
+ *
1539
+ * Options are directly ported from [enhanced-resolve](https://github.com/webpack/enhanced-resolve#resolver-options).
1540
+ *
1541
+ * See [rspack resolve](https://rspack.rs/config/resolve) for information and examples
1542
+ */
1543
+ export interface NapiResolveOptions {
1544
+ /**
1545
+ * Path to TypeScript configuration file.
1546
+ *
1547
+ * Default `None`
1548
+ */
1549
+ tsconfig?: TsconfigOptions
1550
+ /**
1551
+ * Alias for [ResolveOptions::alias] and [ResolveOptions::fallback].
1552
+ *
1553
+ * For the second value of the tuple, `None -> AliasValue::Ignore`, Some(String) ->
1554
+ * AliasValue::Path(String)`
1555
+ * Create aliases to import or require certain modules more easily.
1556
+ * A trailing $ can also be added to the given object's keys to signify an exact match.
1557
+ */
1558
+ alias?: Record<string, Array<string | undefined | null>>
1559
+ /**
1560
+ * A list of alias fields in description files.
1561
+ * Specify a field, such as `browser`, to be parsed according to [this specification](https://github.com/defunctzombie/package-browser-field-spec).
1562
+ * Can be a path to json object such as `["path", "to", "exports"]`.
1563
+ *
1564
+ * Default `[]`
1565
+ */
1566
+ aliasFields?: (string | string[])[]
1567
+ /**
1568
+ * Condition names for exports field which defines entry points of a package.
1569
+ * The key order in the exports field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.
1570
+ *
1571
+ * Default `[]`
1572
+ */
1573
+ conditionNames?: Array<string>
1574
+ /**
1575
+ * The JSON files to use for descriptions. (There was once a `bower.json`.)
1576
+ *
1577
+ * Default `["package.json"]`
1578
+ */
1579
+ descriptionFiles?: Array<string>
1580
+ /**
1581
+ * If true, it will not allow extension-less files.
1582
+ * So by default `require('./foo')` works if `./foo` has a `.js` extension,
1583
+ * but with this enabled only `require('./foo.js')` will work.
1584
+ *
1585
+ * Default to `true` when [ResolveOptions::extensions] contains an empty string.
1586
+ * Use `Some(false)` to disable the behavior.
1587
+ * See <https://github.com/webpack/enhanced-resolve/pull/285>
1588
+ *
1589
+ * Default None, which is the same as `Some(false)` when the above empty rule is not applied.
1590
+ */
1591
+ enforceExtension?: EnforceExtension
1592
+ /**
1593
+ * A list of exports fields in description files.
1594
+ * Can be a path to json object such as `["path", "to", "exports"]`.
1595
+ *
1596
+ * Default `[["exports"]]`.
1597
+ */
1598
+ exportsFields?: (string | string[])[]
1599
+ /**
1600
+ * Fields from `package.json` which are used to provide the internal requests of a package
1601
+ * (requests starting with # are considered internal).
1602
+ *
1603
+ * Can be a path to a JSON object such as `["path", "to", "imports"]`.
1604
+ *
1605
+ * Default `[["imports"]]`.
1606
+ */
1607
+ importsFields?: (string | string[])[]
1608
+ /**
1609
+ * An object which maps extension to extension aliases.
1610
+ *
1611
+ * Default `{}`
1612
+ */
1613
+ extensionAlias?: Record<string, Array<string>>
1614
+ /**
1615
+ * Attempt to resolve these extensions in order.
1616
+ * If multiple files share the same name but have different extensions,
1617
+ * will resolve the one with the extension listed first in the array and skip the rest.
1618
+ *
1619
+ * Default `[".js", ".json", ".node"]`
1620
+ */
1621
+ extensions?: Array<string>
1622
+ /**
1623
+ * Redirect module requests when normal resolving fails.
1624
+ *
1625
+ * Default `[]`
1626
+ */
1627
+ fallback?: Record<string, Array<string | undefined | null>>
1628
+ /**
1629
+ * Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests).
1630
+ *
1631
+ * See also rspack configuration [resolve.fullySpecified](https://rspack.rs/config/resolve#resolvefullyspecified)
1632
+ *
1633
+ * Default `false`
1634
+ */
1635
+ fullySpecified?: boolean
1636
+ /**
1637
+ * A list of main fields in description files
1638
+ *
1639
+ * Default `["main"]`.
1640
+ */
1641
+ mainFields?: string | string[]
1642
+ /**
1643
+ * The filename to be used while resolving directories.
1644
+ *
1645
+ * Default `["index"]`
1646
+ */
1647
+ mainFiles?: Array<string>
1648
+ /**
1649
+ * A list of directories to resolve modules from, can be absolute path or folder name.
1650
+ *
1651
+ * Default `["node_modules"]`
1652
+ */
1653
+ modules?: string | string[]
1654
+ /**
1655
+ * Resolve to a context instead of a file.
1656
+ *
1657
+ * Default `false`
1658
+ */
1659
+ resolveToContext?: boolean
1660
+ /**
1661
+ * Prefer to resolve module requests as relative requests instead of using modules from node_modules directories.
1662
+ *
1663
+ * Default `false`
1664
+ */
1665
+ preferRelative?: boolean
1666
+ /**
1667
+ * Prefer to resolve server-relative urls as absolute paths before falling back to resolve in ResolveOptions::roots.
1668
+ *
1669
+ * Default `false`
1670
+ */
1671
+ preferAbsolute?: boolean
1672
+ /**
1673
+ * A list of resolve restrictions to restrict the paths that a request can be resolved on.
1674
+ *
1675
+ * Default `[]`
1676
+ */
1677
+ restrictions?: Array<Restriction>
1678
+ /**
1679
+ * A list of directories where requests of server-relative URLs (starting with '/') are resolved.
1680
+ * On non-Windows systems these requests are resolved as an absolute path first.
1681
+ *
1682
+ * Default `[]`
1683
+ */
1684
+ roots?: Array<string>
1685
+ /**
1686
+ * Whether to resolve symlinks to their symlinked location.
1687
+ * When enabled, symlinked resources are resolved to their real path, not their symlinked location.
1688
+ * Note that this may cause module resolution to fail when using tools that symlink packages (like npm link).
1689
+ *
1690
+ * Default `true`
1691
+ */
1692
+ symlinks?: boolean
1693
+ /**
1694
+ * Whether to parse [module.builtinModules](https://nodejs.org/api/module.html#modulebuiltinmodules) or not.
1695
+ * For example, "zlib" will throw [crate::ResolveError::Builtin] when set to true.
1696
+ *
1697
+ * Default `false`
1698
+ */
1699
+ builtinModules?: boolean
1700
+ /**
1701
+ * Whether to enable yarn Plug'n'Play
1702
+ *
1703
+ * Default `false`
1704
+ */
1705
+ enablePnp?: boolean
1706
+ }
1707
+
1498
1708
  export interface NativeWatcherOptions {
1499
1709
  followSymlinks?: boolean
1500
1710
  pollInterval?: number
1501
1711
  aggregateTimeout?: number
1502
- /** A function that will be called with the path of a file or directory that is ignored. */
1503
- ignored?: (path: string) => boolean
1712
+ /**
1713
+ * The ignored paths for the watcher.
1714
+ * It can be a single path, an array of paths, or a regular expression.
1715
+ */
1716
+ ignored?: string | string[] | RegExp
1504
1717
  }
1505
1718
 
1506
1719
  export interface NodeFsStats {
@@ -1911,6 +2124,7 @@ useInputFileSystem?: false | Array<RegExp>
1911
2124
  inlineConst: boolean
1912
2125
  inlineEnum: boolean
1913
2126
  typeReexportsPresence: boolean
2127
+ lazyBarrel: boolean
1914
2128
  }
1915
2129
 
1916
2130
  export interface RawExperimentSnapshotOptions {
@@ -2334,6 +2548,7 @@ export interface RawOptions {
2334
2548
  amd?: string
2335
2549
  bail: boolean
2336
2550
  __references: Record<string, any>
2551
+ __virtual_files?: Array<JsVirtualFile>
2337
2552
  }
2338
2553
 
2339
2554
  export interface RawOutputOptions {
@@ -2475,7 +2690,7 @@ export interface RawResolveOptionsWithDependencyType {
2475
2690
  aliasFields?: Array<string>
2476
2691
  restrictions?: (string | RegExp)[]
2477
2692
  roots?: Array<string>
2478
- dependencyCategory?: string
2693
+ dependencyType?: string
2479
2694
  resolveToContext?: boolean
2480
2695
  pnp?: boolean
2481
2696
  }
@@ -2489,6 +2704,7 @@ export interface RawResolveTsconfigOptions {
2489
2704
  export interface RawRsdoctorPluginOptions {
2490
2705
  moduleGraphFeatures: boolean | Array<'graph' | 'ids' | 'sources'>
2491
2706
  chunkGraphFeatures: boolean | Array<'graph' | 'assets'>
2707
+ sourceMapFeatures?: { module?: boolean; cheap?: boolean } | undefined
2492
2708
  }
2493
2709
 
2494
2710
  export interface RawRslibPluginOptions {
@@ -2744,6 +2960,22 @@ export interface RegisterJsTaps {
2744
2960
  registerRsdoctorPluginAssetsTaps: (stages: Array<number>) => Array<{ function: ((arg: JsRsdoctorAssetPatch) => Promise<boolean | undefined>); stage: number; }>
2745
2961
  }
2746
2962
 
2963
+ export interface ResolveResult {
2964
+ path?: string
2965
+ error?: string
2966
+ /** "type" field in the package.json file */
2967
+ moduleType?: string
2968
+ }
2969
+
2970
+ /**
2971
+ * Alias Value for [ResolveOptions::alias] and [ResolveOptions::fallback].
2972
+ * Use struct because napi don't support structured union now
2973
+ */
2974
+ export interface Restriction {
2975
+ path?: string
2976
+ regex?: string
2977
+ }
2978
+
2747
2979
  export interface SourceMapDevToolPluginOptions {
2748
2980
  append?: (false | null) | string | Function
2749
2981
  columns?: boolean
@@ -2767,6 +2999,8 @@ export interface SourcePosition {
2767
2999
  column?: number
2768
3000
  }
2769
3001
 
3002
+ export declare function sync(path: string, request: string): ResolveResult
3003
+
2770
3004
  export declare function syncTraceEvent(events: Array<RawTraceEvent>): void
2771
3005
 
2772
3006
  export interface SyntheticDependencyLocation {
@@ -2804,3 +3038,25 @@ export interface TransformOutput {
2804
3038
  }
2805
3039
 
2806
3040
  export declare function transformSync(source: string, options: string): TransformOutput
3041
+
3042
+ /**
3043
+ * Tsconfig Options
3044
+ *
3045
+ * Derived from [tsconfig-paths-webpack-plugin](https://github.com/dividab/tsconfig-paths-webpack-plugin#options)
3046
+ */
3047
+ export interface TsconfigOptions {
3048
+ /**
3049
+ * Allows you to specify where to find the TypeScript configuration file.
3050
+ * You may provide
3051
+ * * a relative path to the configuration file. It will be resolved relative to cwd.
3052
+ * * an absolute path to the configuration file.
3053
+ */
3054
+ configFile: string
3055
+ /**
3056
+ * Support for Typescript Project References.
3057
+ *
3058
+ * * `'auto'`: use the `references` field from tsconfig of `config_file`.
3059
+ * * `string[]`: manually provided relative or absolute path.
3060
+ */
3061
+ references?: 'auto' | string[]
3062
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/binding",
3
- "version": "1.4.10",
3
+ "version": "1.5.0-beta.0",
4
4
  "license": "MIT",
5
5
  "description": "Node binding for rspack",
6
6
  "main": "binding.js",
@@ -18,10 +18,10 @@
18
18
  "bugs": "https://github.com/web-infra-dev/rspack/issues",
19
19
  "repository": "web-infra-dev/rspack",
20
20
  "devDependencies": {
21
- "@napi-rs/cli": "3.0.1",
21
+ "@napi-rs/cli": "3.0.4",
22
22
  "@napi-rs/wasm-runtime": "^1.0.1",
23
23
  "emnapi": "^1.4.5",
24
- "typescript": "^5.8.3"
24
+ "typescript": "^5.9.2"
25
25
  },
26
26
  "napi": {
27
27
  "binaryName": "rspack",
@@ -50,16 +50,16 @@
50
50
  }
51
51
  },
52
52
  "optionalDependencies": {
53
- "@rspack/binding-linux-arm64-gnu": "1.4.10",
54
- "@rspack/binding-darwin-arm64": "1.4.10",
55
- "@rspack/binding-win32-arm64-msvc": "1.4.10",
56
- "@rspack/binding-win32-ia32-msvc": "1.4.10",
57
- "@rspack/binding-darwin-x64": "1.4.10",
58
- "@rspack/binding-linux-arm64-musl": "1.4.10",
59
- "@rspack/binding-win32-x64-msvc": "1.4.10",
60
- "@rspack/binding-linux-x64-gnu": "1.4.10",
61
- "@rspack/binding-linux-x64-musl": "1.4.10",
62
- "@rspack/binding-wasm32-wasi": "1.4.10"
53
+ "@rspack/binding-darwin-arm64": "1.5.0-beta.0",
54
+ "@rspack/binding-win32-arm64-msvc": "1.5.0-beta.0",
55
+ "@rspack/binding-linux-arm64-musl": "1.5.0-beta.0",
56
+ "@rspack/binding-linux-arm64-gnu": "1.5.0-beta.0",
57
+ "@rspack/binding-win32-ia32-msvc": "1.5.0-beta.0",
58
+ "@rspack/binding-darwin-x64": "1.5.0-beta.0",
59
+ "@rspack/binding-wasm32-wasi": "1.5.0-beta.0",
60
+ "@rspack/binding-win32-x64-msvc": "1.5.0-beta.0",
61
+ "@rspack/binding-linux-x64-musl": "1.5.0-beta.0",
62
+ "@rspack/binding-linux-x64-gnu": "1.5.0-beta.0"
63
63
  },
64
64
  "scripts": {
65
65
  "build:dev": "node scripts/build.js",
@@ -69,6 +69,8 @@
69
69
  "build:release": "node scripts/build.js --profile release",
70
70
  "build:dev:wasm": "DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads node scripts/build.js",
71
71
  "build:release:wasm": "DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads node scripts/build.js --profile release-wasi",
72
+ "build:dev:browser": "DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads BROWSER=1 node scripts/build.js",
73
+ "build:release:browser": "DISABLE_PLUGIN=1 RUST_TARGET=wasm32-wasip1-threads BROWSER=1 node scripts/build.js --profile release-wasi",
72
74
  "move-binding": "node scripts/move-binding",
73
75
  "test": "tsc -p tsconfig.type-test.json"
74
76
  }