@rspack/binding 1.4.10 → 1.4.11

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 +357 -193
  2. package/napi-binding.d.ts +11 -2
  3. package/package.json +12 -12
package/binding.js CHANGED
@@ -1,229 +1,393 @@
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
+ { cause: loadErrors }
390
+ )
227
391
  }
228
392
  throw new Error(`Failed to load native binding`)
229
393
  }
package/napi-binding.d.ts CHANGED
@@ -1146,6 +1146,11 @@ export interface JsRsdoctorSideEffect {
1146
1146
  variable?: number
1147
1147
  }
1148
1148
 
1149
+ export interface JsRsdoctorSourceMapFeatures {
1150
+ cheap?: boolean
1151
+ module?: boolean
1152
+ }
1153
+
1149
1154
  export interface JsRsdoctorSourcePosition {
1150
1155
  line?: number
1151
1156
  column?: number
@@ -1499,8 +1504,11 @@ export interface NativeWatcherOptions {
1499
1504
  followSymlinks?: boolean
1500
1505
  pollInterval?: number
1501
1506
  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
1507
+ /**
1508
+ * The ignored paths for the watcher.
1509
+ * It can be a single path, an array of paths, or a regular expression.
1510
+ */
1511
+ ignored?: string | string[] | RegExp
1504
1512
  }
1505
1513
 
1506
1514
  export interface NodeFsStats {
@@ -2489,6 +2497,7 @@ export interface RawResolveTsconfigOptions {
2489
2497
  export interface RawRsdoctorPluginOptions {
2490
2498
  moduleGraphFeatures: boolean | Array<'graph' | 'ids' | 'sources'>
2491
2499
  chunkGraphFeatures: boolean | Array<'graph' | 'assets'>
2500
+ sourceMapFeatures?: { module?: boolean; cheap?: boolean } | undefined
2492
2501
  }
2493
2502
 
2494
2503
  export interface RawRslibPluginOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/binding",
3
- "version": "1.4.10",
3
+ "version": "1.4.11",
4
4
  "license": "MIT",
5
5
  "description": "Node binding for rspack",
6
6
  "main": "binding.js",
@@ -18,7 +18,7 @@
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
24
  "typescript": "^5.8.3"
@@ -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.4.11",
54
+ "@rspack/binding-win32-arm64-msvc": "1.4.11",
55
+ "@rspack/binding-linux-arm64-musl": "1.4.11",
56
+ "@rspack/binding-linux-arm64-gnu": "1.4.11",
57
+ "@rspack/binding-win32-ia32-msvc": "1.4.11",
58
+ "@rspack/binding-darwin-x64": "1.4.11",
59
+ "@rspack/binding-wasm32-wasi": "1.4.11",
60
+ "@rspack/binding-linux-x64-musl": "1.4.11",
61
+ "@rspack/binding-linux-x64-gnu": "1.4.11",
62
+ "@rspack/binding-win32-x64-msvc": "1.4.11"
63
63
  },
64
64
  "scripts": {
65
65
  "build:dev": "node scripts/build.js",