@rspack/binding 0.1.9 → 0.1.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 (2) hide show
  1. package/binding.d.ts +629 -529
  2. package/package.json +12 -12
package/binding.d.ts CHANGED
@@ -1,148 +1,362 @@
1
- /* tslint:disable */
1
+ /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
3
 
4
- /* auto-generated by NAPI-RS */
4
+ export class JsCompilation {
5
+ updateAsset(filename: string, newSourceOrFunction: JsCompatSource | ((source: JsCompatSource) => JsCompatSource), assetInfoUpdateOrFunction?: JsAssetInfo | ((assetInfo: JsAssetInfo) => JsAssetInfo)): void
6
+ getAssets(): Readonly<JsAsset>[]
7
+ getAsset(name: string): JsAsset | null
8
+ getAssetSource(name: string): JsCompatSource | null
9
+ getModules(): Array<JsModule>
10
+ getChunks(): Array<JsChunk>
11
+ /**
12
+ * Only available for those none Js and Css source,
13
+ * return true if set module source successfully, false if failed.
14
+ */
15
+ setNoneAstModuleSource(moduleIdentifier: string, source: JsCompatSource): boolean
16
+ setAssetSource(name: string, source: JsCompatSource): void
17
+ deleteAssetSource(name: string): void
18
+ getAssetFilenames(): Array<string>
19
+ hasAsset(name: string): boolean
20
+ emitAsset(filename: string, source: JsCompatSource, assetInfo: JsAssetInfo): void
21
+ deleteAsset(filename: string): void
22
+ get entrypoints(): Record<string, JsChunkGroup>
23
+ get hash(): string
24
+ getFileDependencies(): Array<string>
25
+ getContextDependencies(): Array<string>
26
+ getMissingDependencies(): Array<string>
27
+ getBuildDependencies(): Array<string>
28
+ pushDiagnostic(severity: "error" | "warning", title: string, message: string): void
29
+ getStats(): JsStats
30
+ addFileDependencies(deps: Array<string>): void
31
+ addContextDependencies(deps: Array<string>): void
32
+ addMissingDependencies(deps: Array<string>): void
33
+ addBuildDependencies(deps: Array<string>): void
34
+ }
5
35
 
6
- export interface NodeFS {
7
- writeFile: (...args: any[]) => any
8
- mkdir: (...args: any[]) => any
9
- mkdirp: (...args: any[]) => any
36
+ export class JsStats {
37
+ getAssets(): JsStatsGetAssets
38
+ getModules(reasons: boolean, moduleAssets: boolean, nestedModules: boolean): Array<JsStatsModule>
39
+ getChunks(chunkModules: boolean, chunksRelations: boolean, reasons: boolean, moduleAssets: boolean, nestedModules: boolean): Array<JsStatsChunk>
40
+ getEntrypoints(): Array<JsStatsChunkGroup>
41
+ getNamedChunkGroups(): Array<JsStatsChunkGroup>
42
+ getErrors(): Array<JsStatsError>
43
+ getWarnings(): Array<JsStatsWarning>
44
+ getHash(): string
10
45
  }
11
- export interface ThreadsafeNodeFS {
12
- writeFile: (...args: any[]) => any
13
- mkdir: (...args: any[]) => any
14
- mkdirp: (...args: any[]) => any
15
- removeDirAll: (...args: any[]) => any
46
+
47
+ export class Rspack {
48
+ constructor(options: RawOptions, jsHooks: JsHooks | undefined | null, outputFilesystem: ThreadsafeNodeFS, jsLoaderRunner: (...args: any[]) => any)
49
+ unsafe_set_disabled_hooks(hooks: Array<string>): void
50
+ /**
51
+ * Build with the given option passed to the constructor
52
+ *
53
+ * Warning:
54
+ * Calling this method recursively might cause a deadlock.
55
+ */
56
+ unsafe_build(callback: (err: null | Error) => void): void
57
+ /**
58
+ * Rebuild with the given option passed to the constructor
59
+ *
60
+ * Warning:
61
+ * Calling this method recursively will cause a deadlock.
62
+ */
63
+ unsafe_rebuild(changed_files: string[], removed_files: string[], callback: (err: null | Error) => void): void
64
+ /**
65
+ * Get the last compilation
66
+ *
67
+ * Warning:
68
+ *
69
+ * Calling this method under the build or rebuild method might cause a deadlock.
70
+ *
71
+ * **Note** that this method is not safe if you cache the _JsCompilation_ on the Node side, as it will be invalidated by the next build and accessing a dangling ptr is a UB.
72
+ */
73
+ unsafe_last_compilation(f: (arg0: JsCompilation) => void): void
74
+ /**
75
+ * Destroy the compiler
76
+ *
77
+ * Warning:
78
+ *
79
+ * Anything related to this compiler will be invalidated after this method is called.
80
+ */
81
+ unsafe_drop(): void
16
82
  }
17
- export interface RawBannerCondition {
18
- type: "string" | "regexp"
19
- stringMatcher?: string
20
- regexpMatcher?: string
83
+
84
+ export interface BeforeResolveData {
85
+ request: string
86
+ context?: string
21
87
  }
22
- export interface RawBannerConditions {
23
- type: "string" | "regexp" | "array"
24
- stringMatcher?: string
25
- regexpMatcher?: string
26
- arrayMatcher?: Array<RawBannerCondition>
88
+
89
+ /**
90
+ * Some code is modified based on
91
+ * https://github.com/swc-project/swc/blob/d1d0607158ab40463d1b123fed52cc526eba8385/bindings/binding_core_node/src/util.rs#L29-L58
92
+ * Apache-2.0 licensed
93
+ * Author Donny/강동윤
94
+ * Copyright (c)
95
+ */
96
+ export function initCustomTraceSubscriber(): void
97
+
98
+ export interface JsAsset {
99
+ name: string
100
+ source?: JsCompatSource
101
+ info: JsAssetInfo
27
102
  }
28
- export interface RawBannerConfig {
29
- banner: string
30
- entryOnly?: boolean
31
- footer?: boolean
32
- raw?: boolean
33
- test?: RawBannerConditions
34
- include?: RawBannerConditions
35
- exclude?: RawBannerConditions
103
+
104
+ export interface JsAssetInfo {
105
+ /**
106
+ * if the asset can be long term cached forever (contains a hash)
107
+ * whether the asset is minimized
108
+ */
109
+ minimized: boolean
110
+ /**
111
+ * the value(s) of the full hash used for this asset
112
+ * the value(s) of the chunk hash used for this asset
113
+ * the value(s) of the module hash used for this asset
114
+ * the value(s) of the content hash used for this asset
115
+ */
116
+ contentHash: Array<string>
117
+ /**
118
+ * when asset was created from a source file (potentially transformed), the original filename relative to compilation context
119
+ * size in bytes, only set after asset has been emitted
120
+ * when asset is only used for development and doesn't count towards user-facing assets
121
+ */
122
+ development: boolean
123
+ /** when asset ships data for updating an existing application (HMR) */
124
+ hotModuleReplacement: boolean
125
+ /**
126
+ * when asset is javascript and an ESM
127
+ * related object to other assets, keyed by type of relation (only points from parent to child)
128
+ */
129
+ related: JsAssetInfoRelated
36
130
  }
37
- export interface RawPattern {
38
- from: string
39
- to?: string
40
- context?: string
41
- toType?: string
42
- noErrorOnMissing: boolean
43
- force: boolean
44
- priority: number
45
- globOptions: RawGlobOptions
131
+
132
+ export interface JsAssetInfoRelated {
133
+ sourceMap?: string
46
134
  }
47
- export interface RawGlobOptions {
48
- caseSensitiveMatch?: boolean
49
- dot?: boolean
50
- ignore?: Array<string>
135
+
136
+ export interface JsChunk {
137
+ files: Array<string>
51
138
  }
52
- export interface RawCopyConfig {
53
- patterns: Array<RawPattern>
139
+
140
+ export interface JsChunkAssetArgs {
141
+ chunk: JsChunk
142
+ filename: string
54
143
  }
55
- export interface RawCssPluginConfig {
56
- modules: RawCssModulesConfig
144
+
145
+ export interface JsChunkGroup {
146
+ chunks: Array<JsChunk>
57
147
  }
58
- export interface RawCssModulesConfig {
59
- localsConvention: "asIs" | "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly"
60
- localIdentName: string
61
- exportsOnly: boolean
148
+
149
+ export interface JsCompatSource {
150
+ /** Whether the underlying data structure is a `RawSource` */
151
+ isRaw: boolean
152
+ /** Whether the underlying value is a buffer or string */
153
+ isBuffer: boolean
154
+ source: Buffer
155
+ map?: Buffer
62
156
  }
63
- export interface RawDecoratorOptions {
64
- legacy: boolean
65
- emitMetadata: boolean
157
+
158
+ export interface JsHooks {
159
+ processAssetsStageAdditional: (...args: any[]) => any
160
+ processAssetsStagePreProcess: (...args: any[]) => any
161
+ processAssetsStageAdditions: (...args: any[]) => any
162
+ processAssetsStageNone: (...args: any[]) => any
163
+ processAssetsStageOptimizeInline: (...args: any[]) => any
164
+ processAssetsStageSummarize: (...args: any[]) => any
165
+ processAssetsStageOptimizeHash: (...args: any[]) => any
166
+ processAssetsStageReport: (...args: any[]) => any
167
+ compilation: (...args: any[]) => any
168
+ thisCompilation: (...args: any[]) => any
169
+ emit: (...args: any[]) => any
170
+ afterEmit: (...args: any[]) => any
171
+ make: (...args: any[]) => any
172
+ optimizeModules: (...args: any[]) => any
173
+ optimizeChunkModule: (...args: any[]) => any
174
+ beforeCompile: (...args: any[]) => any
175
+ finishModules: (...args: any[]) => any
176
+ beforeResolve: (...args: any[]) => any
177
+ contextModuleBeforeResolve: (...args: any[]) => any
178
+ normalModuleFactoryResolveForScheme: (...args: any[]) => any
179
+ chunkAsset: (...args: any[]) => any
66
180
  }
67
- export interface RawHtmlPluginConfig {
68
- /** emitted file name in output path */
69
- filename?: string
70
- /** template html file */
71
- template?: string
72
- templateContent?: string
73
- templateParameters?: Record<string, string>
74
- /** `head`, `body` or None */
75
- inject?: "head" | "body"
76
- /** path or `auto` */
77
- publicPath?: string
78
- /** `blocking`, `defer`, or `module` */
79
- scriptLoading?: "blocking" | "defer" | "module"
80
- /** entry_chunk_name (only entry chunks are supported) */
81
- chunks?: Array<string>
82
- excludedChunks?: Array<string>
83
- sri?: "sha256" | "sha384" | "sha512"
84
- minify?: boolean
85
- title?: string
86
- favicon?: string
87
- meta?: Record<string, Record<string, string>>
181
+
182
+ export interface JsLoader {
183
+ /** composed loader name, xx-loader$yy-loader$zz-loader */
184
+ identifier: string
88
185
  }
89
- export interface RawStyleConfig {
90
- styleLibraryDirectory?: string
91
- custom?: string
92
- css?: string
93
- bool?: boolean
186
+
187
+ export interface JsLoaderContext {
188
+ /** Content maybe empty in pitching stage */
189
+ content?: Buffer
190
+ additionalData?: Buffer
191
+ sourceMap?: Buffer
192
+ resource: string
193
+ resourcePath: string
194
+ resourceQuery?: string
195
+ resourceFragment?: string
196
+ cacheable: boolean
197
+ fileDependencies: Array<string>
198
+ contextDependencies: Array<string>
199
+ missingDependencies: Array<string>
200
+ buildDependencies: Array<string>
201
+ assetFilenames: Array<string>
202
+ currentLoader: string
203
+ isPitching: boolean
94
204
  }
95
- export interface RawPluginImportConfig {
96
- libraryName: string
97
- libraryDirectory?: string
98
- customName?: string
99
- customStyleName?: string
100
- style?: RawStyleConfig
101
- camelToDashComponentName?: boolean
102
- transformToDefaultImport?: boolean
103
- ignoreEsComponent?: Array<string>
104
- ignoreStyleComponent?: Array<string>
205
+
206
+ export interface JsLoaderResult {
207
+ /** Content in pitching stage can be empty */
208
+ content?: Buffer
209
+ fileDependencies: Array<string>
210
+ contextDependencies: Array<string>
211
+ missingDependencies: Array<string>
212
+ buildDependencies: Array<string>
213
+ sourceMap?: Buffer
214
+ additionalData?: Buffer
215
+ cacheable: boolean
216
+ /** Used to instruct how rust loaders should execute */
217
+ isPitching: boolean
218
+ }
219
+
220
+ export interface JsModule {
221
+ originalSource?: JsCompatSource
222
+ resource: string
223
+ moduleIdentifier: string
224
+ }
225
+
226
+ export interface JsResourceData {
227
+ /** Resource with absolute path, query and fragment */
228
+ resource: string
229
+ /** Absolute resource path only */
230
+ path: string
231
+ /** Resource query with `?` prefix */
232
+ query?: string
233
+ /** Resource fragment with `#` prefix */
234
+ fragment?: string
235
+ }
236
+
237
+ export interface JsStatsAsset {
238
+ type: string
239
+ name: string
240
+ size: number
241
+ chunks: Array<string>
242
+ chunkNames: Array<string>
243
+ info: JsStatsAssetInfo
244
+ emitted: boolean
245
+ }
246
+
247
+ export interface JsStatsAssetInfo {
248
+ development: boolean
249
+ hotModuleReplacement: boolean
250
+ }
251
+
252
+ export interface JsStatsAssetsByChunkName {
253
+ name: string
254
+ files: Array<string>
255
+ }
256
+
257
+ export interface JsStatsChunk {
258
+ type: string
259
+ files: Array<string>
260
+ id: string
261
+ entry: boolean
262
+ initial: boolean
263
+ names: Array<string>
264
+ size: number
265
+ modules?: Array<JsStatsModule>
266
+ parents?: Array<string>
267
+ children?: Array<string>
268
+ siblings?: Array<string>
269
+ }
270
+
271
+ export interface JsStatsChunkGroup {
272
+ name: string
273
+ assets: Array<JsStatsChunkGroupAsset>
274
+ chunks: Array<string>
275
+ assetsSize: number
276
+ }
277
+
278
+ export interface JsStatsChunkGroupAsset {
279
+ name: string
280
+ size: number
281
+ }
282
+
283
+ export interface JsStatsError {
284
+ message: string
285
+ formatted: string
286
+ title: string
287
+ }
288
+
289
+ export interface JsStatsGetAssets {
290
+ assets: Array<JsStatsAsset>
291
+ assetsByChunkName: Array<JsStatsAssetsByChunkName>
292
+ }
293
+
294
+ export interface JsStatsModule {
295
+ type: string
296
+ moduleType: string
297
+ identifier: string
298
+ name: string
299
+ id?: string
300
+ chunks: Array<string>
301
+ size: number
302
+ issuer?: string
303
+ issuerName?: string
304
+ issuerId?: string
305
+ issuerPath: Array<JsStatsModuleIssuer>
306
+ reasons?: Array<JsStatsModuleReason>
307
+ assets?: Array<string>
105
308
  }
106
- export interface RawPostCssConfig {
107
- pxtorem?: RawPxToRemConfig
309
+
310
+ export interface JsStatsModuleIssuer {
311
+ identifier: string
312
+ name: string
313
+ id?: string
108
314
  }
109
- export interface RawPxToRemConfig {
110
- rootValue?: number
111
- unitPrecision?: number
112
- selectorBlackList?: Array<string>
113
- propList?: Array<string>
114
- replace?: boolean
115
- mediaQuery?: boolean
116
- minPixelValue?: number
315
+
316
+ export interface JsStatsModuleReason {
317
+ moduleIdentifier?: string
318
+ moduleName?: string
319
+ moduleId?: string
320
+ type?: string
321
+ userRequest?: string
117
322
  }
118
- export interface RawProgressPluginConfig {
119
- prefix?: string
323
+
324
+ export interface JsStatsWarning {
325
+ message: string
326
+ formatted: string
120
327
  }
121
- export interface RawReactOptions {
122
- runtime?: "automatic" | "classic"
123
- importSource?: string
124
- pragma?: string
125
- pragmaFrag?: string
126
- throwIfNamespace?: boolean
127
- development?: boolean
128
- useBuiltins?: boolean
129
- useSpread?: boolean
130
- refresh?: boolean
328
+
329
+ export interface RawAssetParserDataUrlOption {
330
+ maxSize?: number
131
331
  }
132
- export interface RawRelayConfig {
133
- artifactDirectory?: string
134
- language: 'javascript' | 'typescript' | 'flow'
332
+
333
+ export interface RawAssetParserOptions {
334
+ dataUrlCondition?: RawAssetParserDataUrlOption
135
335
  }
136
- export interface RawMinification {
137
- passes: number
138
- dropConsole: boolean
139
- pureFuncs: Array<string>
336
+
337
+ export interface RawBannerCondition {
338
+ type: "string" | "regexp"
339
+ stringMatcher?: string
340
+ regexpMatcher?: string
140
341
  }
141
- export interface RawPresetEnv {
142
- targets: Array<string>
143
- mode?: 'usage' | 'entry'
144
- coreJs?: string
342
+
343
+ export interface RawBannerConditions {
344
+ type: "string" | "regexp" | "array"
345
+ stringMatcher?: string
346
+ regexpMatcher?: string
347
+ arrayMatcher?: Array<RawBannerCondition>
348
+ }
349
+
350
+ export interface RawBannerConfig {
351
+ banner: string
352
+ entryOnly?: boolean
353
+ footer?: boolean
354
+ raw?: boolean
355
+ test?: RawBannerConditions
356
+ include?: RawBannerConditions
357
+ exclude?: RawBannerConditions
145
358
  }
359
+
146
360
  export interface RawBuiltins {
147
361
  html?: Array<RawHtmlPluginConfig>
148
362
  css?: RawCssPluginConfig
@@ -151,7 +365,7 @@ export interface RawBuiltins {
151
365
  presetEnv?: RawPresetEnv
152
366
  define: Record<string, string>
153
367
  provide: Record<string, string[]>
154
- treeShaking: boolean
368
+ treeShaking: string
155
369
  progress?: RawProgressPluginConfig
156
370
  react: RawReactOptions
157
371
  decorator?: RawDecoratorOptions
@@ -162,7 +376,21 @@ export interface RawBuiltins {
162
376
  banner?: Array<RawBannerConfig>
163
377
  pluginImport?: Array<RawPluginImportConfig>
164
378
  relay?: RawRelayConfig
379
+ codeGeneration?: RawCodeGeneration
380
+ }
381
+
382
+ export interface RawCacheGroupOptions {
383
+ priority?: number
384
+ test?: string
385
+ /** What kind of chunks should be selected. */
386
+ chunks?: string
387
+ minChunks?: number
388
+ minSize?: number
389
+ name?: string
390
+ reuseExistingChunk?: boolean
391
+ enforce?: boolean
165
392
  }
393
+
166
394
  export interface RawCacheOptions {
167
395
  type: string
168
396
  maxGenerations: number
@@ -174,19 +402,53 @@ export interface RawCacheOptions {
174
402
  name: string
175
403
  version: string
176
404
  }
405
+
406
+ export interface RawCodeGeneration {
407
+ keepComments: boolean
408
+ }
409
+
410
+ export interface RawCopyConfig {
411
+ patterns: Array<RawPattern>
412
+ }
413
+
414
+ export interface RawCrossOriginLoading {
415
+ type: "bool" | "string"
416
+ stringPayload?: string
417
+ boolPayload?: boolean
418
+ }
419
+
420
+ export interface RawCssModulesConfig {
421
+ localsConvention: "asIs" | "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly"
422
+ localIdentName: string
423
+ exportsOnly: boolean
424
+ }
425
+
426
+ export interface RawCssPluginConfig {
427
+ modules: RawCssModulesConfig
428
+ }
429
+
430
+ export interface RawDecoratorOptions {
431
+ legacy: boolean
432
+ emitMetadata: boolean
433
+ }
434
+
177
435
  export interface RawDevServer {
178
436
  hot: boolean
179
437
  }
438
+
180
439
  export interface RawEntryItem {
181
440
  import: Array<string>
182
441
  runtime?: string
183
442
  }
443
+
184
444
  export interface RawExperiments {
185
445
  lazyCompilation: boolean
186
446
  incrementalRebuild: boolean
187
447
  asyncWebAssembly: boolean
188
448
  newSplitChunks: boolean
449
+ css: boolean
189
450
  }
451
+
190
452
  export interface RawExternalItem {
191
453
  type: "string" | "regexp" | "object" | "function"
192
454
  stringPayload?: string
@@ -194,87 +456,92 @@ export interface RawExternalItem {
194
456
  objectPayload?: Record<string, RawExternalItemValue>
195
457
  fnPayload?: (value: any) => any
196
458
  }
197
- export interface RawExternalItemValue {
198
- type: "string" | "bool"
199
- stringPayload?: string
200
- boolPayload?: boolean
459
+
460
+ export interface RawExternalItemFnCtx {
461
+ request: string
462
+ context: string
463
+ dependencyType: string
201
464
  }
465
+
202
466
  export interface RawExternalItemFnResult {
203
467
  externalType?: string
204
468
  result?: RawExternalItemValue
205
469
  }
206
- export interface RawExternalItemFnCtx {
207
- request: string
208
- context: string
209
- dependencyType: string
470
+
471
+ export interface RawExternalItemValue {
472
+ type: "string" | "bool" | "array"
473
+ stringPayload?: string
474
+ boolPayload?: boolean
475
+ arrayPayload?: Array<string>
210
476
  }
477
+
211
478
  export interface RawExternalsPresets {
212
479
  node: boolean
480
+ web: boolean
213
481
  }
214
- export interface JsLoader {
215
- /** composed loader name, xx-loader$yy-loader$zz-loader */
216
- identifier: string
482
+
483
+ export interface RawGlobOptions {
484
+ caseSensitiveMatch?: boolean
485
+ dot?: boolean
486
+ ignore?: Array<string>
217
487
  }
218
- export interface JsLoaderContext {
219
- /** Content maybe empty in pitching stage */
220
- content?: Buffer
221
- additionalData?: Buffer
222
- sourceMap?: Buffer
223
- resource: string
224
- resourcePath: string
225
- resourceQuery?: string
226
- resourceFragment?: string
227
- cacheable: boolean
228
- fileDependencies: Array<string>
229
- contextDependencies: Array<string>
230
- missingDependencies: Array<string>
231
- buildDependencies: Array<string>
232
- assetFilenames: Array<string>
233
- currentLoader: string
234
- isPitching: boolean
488
+
489
+ export interface RawHtmlPluginConfig {
490
+ /** emitted file name in output path */
491
+ filename?: string
492
+ /** template html file */
493
+ template?: string
494
+ templateContent?: string
495
+ templateParameters?: Record<string, string>
496
+ /** `head`, `body` or None */
497
+ inject?: "head" | "body"
498
+ /** path or `auto` */
499
+ publicPath?: string
500
+ /** `blocking`, `defer`, or `module` */
501
+ scriptLoading?: "blocking" | "defer" | "module"
502
+ /** entry_chunk_name (only entry chunks are supported) */
503
+ chunks?: Array<string>
504
+ excludedChunks?: Array<string>
505
+ sri?: "sha256" | "sha384" | "sha512"
506
+ minify?: boolean
507
+ title?: string
508
+ favicon?: string
509
+ meta?: Record<string, Record<string, string>>
235
510
  }
236
- export interface JsLoaderResult {
237
- /** Content in pitching stage can be empty */
238
- content?: Buffer
239
- fileDependencies: Array<string>
240
- contextDependencies: Array<string>
241
- missingDependencies: Array<string>
242
- buildDependencies: Array<string>
243
- sourceMap?: Buffer
244
- additionalData?: Buffer
245
- cacheable: boolean
246
- /** Used to instruct how rust loaders should execute */
247
- isPitching: boolean
511
+
512
+ export interface RawLibraryAuxiliaryComment {
513
+ root?: string
514
+ commonjs?: string
515
+ commonjs2?: string
516
+ amd?: string
248
517
  }
249
- /**
250
- * `loader` is for js side loader, `builtin_loader` is for rust side loader,
251
- * which is mapped to real rust side loader by [get_builtin_loader].
252
- *
253
- * `options` is
254
- * - a `None` on rust side and handled by js side `getOptions` when
255
- * using with `loader`.
256
- * - a `Some(string)` on rust side, deserialized by `serde_json::from_str`
257
- * and passed to rust side loader in [get_builtin_loader] when using with
258
- * `builtin_loader`.
259
- */
260
- export interface RawModuleRuleUse {
261
- jsLoader?: JsLoader
262
- builtinLoader?: string
263
- options?: string
518
+
519
+ export interface RawLibraryName {
520
+ amd?: string
521
+ commonjs?: string
522
+ root?: Array<string>
264
523
  }
265
- export interface RawRuleSetCondition {
266
- type: "string" | "regexp" | "logical" | "array" | "function"
267
- stringMatcher?: string
268
- regexpMatcher?: string
269
- logicalMatcher?: Array<RawRuleSetLogicalConditions>
270
- arrayMatcher?: Array<RawRuleSetCondition>
271
- funcMatcher?: (value: string) => boolean
524
+
525
+ export interface RawLibraryOptions {
526
+ name?: RawLibraryName
527
+ export?: Array<string>
528
+ libraryType: string
529
+ umdNamedDefine?: boolean
530
+ auxiliaryComment?: RawLibraryAuxiliaryComment
272
531
  }
273
- export interface RawRuleSetLogicalConditions {
274
- and?: Array<RawRuleSetCondition>
275
- or?: Array<RawRuleSetCondition>
276
- not?: RawRuleSetCondition
532
+
533
+ export interface RawMinification {
534
+ passes: number
535
+ dropConsole: boolean
536
+ pureFuncs: Array<string>
537
+ extractComments?: string
538
+ }
539
+
540
+ export interface RawModuleOptions {
541
+ rules: Array<RawModuleRule>
542
+ parser?: RawParserOptions
277
543
  }
544
+
278
545
  export interface RawModuleRule {
279
546
  /** A condition matcher matching an absolute path. */
280
547
  test?: RawRuleSetCondition
@@ -297,134 +564,47 @@ export interface RawModuleRule {
297
564
  /** Specifies the category of the loader. No value means normal loader. */
298
565
  enforce?: 'pre' | 'post'
299
566
  }
567
+
300
568
  export interface RawModuleRuleGenerator {
301
569
  filename?: string
302
570
  }
571
+
303
572
  export interface RawModuleRuleParser {
304
573
  dataUrlCondition?: RawAssetParserDataUrlOption
305
574
  }
306
- export interface RawAssetParserDataUrlOption {
307
- maxSize?: number
308
- }
309
- export interface RawAssetParserOptions {
310
- dataUrlCondition?: RawAssetParserDataUrlOption
311
- }
312
- export interface RawParserOptions {
313
- asset?: RawAssetParserOptions
314
- }
315
- export interface RawModuleOptions {
316
- rules: Array<RawModuleRule>
317
- parser?: RawParserOptions
575
+
576
+ /**
577
+ * `loader` is for js side loader, `builtin_loader` is for rust side loader,
578
+ * which is mapped to real rust side loader by [get_builtin_loader].
579
+ *
580
+ * `options` is
581
+ * - a `None` on rust side and handled by js side `getOptions` when
582
+ * using with `loader`.
583
+ * - a `Some(string)` on rust side, deserialized by `serde_json::from_str`
584
+ * and passed to rust side loader in [get_builtin_loader] when using with
585
+ * `builtin_loader`.
586
+ */
587
+ export interface RawModuleRuleUse {
588
+ jsLoader?: JsLoader
589
+ builtinLoader?: string
590
+ options?: string
318
591
  }
592
+
319
593
  export interface RawNodeOption {
320
594
  dirname: string
321
595
  filename: string
322
596
  global: string
323
597
  }
598
+
324
599
  export interface RawOptimizationOptions {
325
600
  splitChunks?: RawSplitChunksOptions
326
601
  moduleIds: string
327
602
  removeAvailableModules: boolean
603
+ removeEmptyChunks: boolean
328
604
  sideEffects: string
605
+ realContentHash: boolean
329
606
  }
330
- export interface RawTrustedTypes {
331
- policyName?: string
332
- }
333
- export interface RawLibraryName {
334
- amd?: string
335
- commonjs?: string
336
- root?: Array<string>
337
- }
338
- export interface RawLibraryAuxiliaryComment {
339
- root?: string
340
- commonjs?: string
341
- commonjs2?: string
342
- amd?: string
343
- }
344
- export interface RawLibraryOptions {
345
- name?: RawLibraryName
346
- export?: Array<string>
347
- libraryType: string
348
- umdNamedDefine?: boolean
349
- auxiliaryComment?: RawLibraryAuxiliaryComment
350
- }
351
- export interface RawCrossOriginLoading {
352
- type: "bool" | "string"
353
- stringPayload?: string
354
- boolPayload?: boolean
355
- }
356
- export interface RawOutputOptions {
357
- path: string
358
- clean: boolean
359
- publicPath: string
360
- assetModuleFilename: string
361
- wasmLoading: string
362
- enabledWasmLoadingTypes: Array<string>
363
- webassemblyModuleFilename: string
364
- filename: string
365
- chunkFilename: string
366
- crossOriginLoading: RawCrossOriginLoading
367
- cssFilename: string
368
- cssChunkFilename: string
369
- uniqueName: string
370
- chunkLoadingGlobal: string
371
- library?: RawLibraryOptions
372
- strictModuleErrorHandling: boolean
373
- enabledLibraryTypes?: Array<string>
374
- globalObject: string
375
- importFunctionName: string
376
- iife: boolean
377
- module: boolean
378
- chunkFormat?: string
379
- chunkLoading?: string
380
- enabledChunkLoadingTypes?: Array<string>
381
- trustedTypes?: RawTrustedTypes
382
- }
383
- export interface RawResolveOptions {
384
- preferRelative?: boolean
385
- extensions?: Array<string>
386
- mainFiles?: Array<string>
387
- mainFields?: Array<string>
388
- browserField?: boolean
389
- conditionNames?: Array<string>
390
- alias?: Record<string, Array<string | false>>
391
- fallback?: Record<string, Array<string | false>>
392
- symlinks?: boolean
393
- tsConfigPath?: string
394
- modules?: Array<string>
395
- byDependency?: Record<string, RawResolveOptions>
396
- fullySpecified?: boolean
397
- }
398
- export interface RawSnapshotStrategy {
399
- hash: boolean
400
- timestamp: boolean
401
- }
402
- export interface RawSnapshotOptions {
403
- resolve: RawSnapshotStrategy
404
- module: RawSnapshotStrategy
405
- }
406
- export interface RawSplitChunksOptions {
407
- cacheGroups?: Record<string, RawCacheGroupOptions>
408
- /** What kind of chunks should be selected. */
409
- chunks?: string
410
- maxAsyncRequests?: number
411
- maxInitialRequests?: number
412
- minChunks?: number
413
- minSize?: number
414
- enforceSizeThreshold?: number
415
- minRemainingSize?: number
416
- }
417
- export interface RawCacheGroupOptions {
418
- priority?: number
419
- test?: string
420
- /** What kind of chunks should be selected. */
421
- chunks?: string
422
- minChunks?: number
423
- name?: string
424
- }
425
- export interface RawStatsOptions {
426
- colors: boolean
427
- }
607
+
428
608
  export interface RawOptions {
429
609
  entry: Record<string, RawEntryItem>
430
610
  /**
@@ -452,255 +632,175 @@ export interface RawOptions {
452
632
  experiments: RawExperiments
453
633
  node?: RawNodeOption
454
634
  }
455
- export interface JsAssetInfoRelated {
456
- sourceMap?: string
457
- }
458
- export interface JsAssetInfo {
459
- /**
460
- * if the asset can be long term cached forever (contains a hash)
461
- * whether the asset is minimized
462
- */
463
- minimized: boolean
464
- /**
465
- * the value(s) of the full hash used for this asset
466
- * the value(s) of the chunk hash used for this asset
467
- * the value(s) of the module hash used for this asset
468
- * the value(s) of the content hash used for this asset
469
- * when asset was created from a source file (potentially transformed), the original filename relative to compilation context
470
- * size in bytes, only set after asset has been emitted
471
- * when asset is only used for development and doesn't count towards user-facing assets
472
- */
473
- development: boolean
474
- /** when asset ships data for updating an existing application (HMR) */
475
- hotModuleReplacement: boolean
476
- /**
477
- * when asset is javascript and an ESM
478
- * related object to other assets, keyed by type of relation (only points from parent to child)
479
- */
480
- related: JsAssetInfoRelated
481
- }
482
- export interface JsAsset {
483
- name: string
484
- source?: JsCompatSource
485
- info: JsAssetInfo
486
- }
487
- export interface JsChunk {
488
- files: Array<string>
489
- }
490
- export interface JsChunkAssetArgs {
491
- chunk: JsChunk
635
+
636
+ export interface RawOutputOptions {
637
+ path: string
638
+ clean: boolean
639
+ publicPath: string
640
+ assetModuleFilename: string
641
+ wasmLoading: string
642
+ enabledWasmLoadingTypes: Array<string>
643
+ webassemblyModuleFilename: string
492
644
  filename: string
645
+ chunkFilename: string
646
+ crossOriginLoading: RawCrossOriginLoading
647
+ cssFilename: string
648
+ cssChunkFilename: string
649
+ uniqueName: string
650
+ chunkLoadingGlobal: string
651
+ library?: RawLibraryOptions
652
+ strictModuleErrorHandling: boolean
653
+ enabledLibraryTypes?: Array<string>
654
+ globalObject: string
655
+ importFunctionName: string
656
+ iife: boolean
657
+ module: boolean
658
+ chunkFormat?: string
659
+ chunkLoading?: string
660
+ enabledChunkLoadingTypes?: Array<string>
661
+ trustedTypes?: RawTrustedTypes
662
+ sourceMapFilename: string
493
663
  }
494
- export interface JsChunkGroup {
495
- chunks: Array<JsChunk>
496
- }
497
- export interface JsHooks {
498
- processAssetsStageAdditional: (...args: any[]) => any
499
- processAssetsStagePreProcess: (...args: any[]) => any
500
- processAssetsStageAdditions: (...args: any[]) => any
501
- processAssetsStageNone: (...args: any[]) => any
502
- processAssetsStageOptimizeInline: (...args: any[]) => any
503
- processAssetsStageSummarize: (...args: any[]) => any
504
- processAssetsStageReport: (...args: any[]) => any
505
- compilation: (...args: any[]) => any
506
- thisCompilation: (...args: any[]) => any
507
- emit: (...args: any[]) => any
508
- afterEmit: (...args: any[]) => any
509
- make: (...args: any[]) => any
510
- optimizeModules: (...args: any[]) => any
511
- optimizeChunkModule: (...args: any[]) => any
512
- finishModules: (...args: any[]) => any
513
- normalModuleFactoryResolveForScheme: (...args: any[]) => any
514
- chunkAsset: (...args: any[]) => any
515
- }
516
- export interface JsModule {
517
- originalSource?: JsCompatSource
518
- resource: string
519
- moduleIdentifier: string
664
+
665
+ export interface RawParserOptions {
666
+ asset?: RawAssetParserOptions
520
667
  }
521
- export interface SchemeAndJsResourceData {
522
- resourceData: JsResourceData
523
- scheme: string
668
+
669
+ export interface RawPattern {
670
+ from: string
671
+ to?: string
672
+ context?: string
673
+ toType?: string
674
+ noErrorOnMissing: boolean
675
+ force: boolean
676
+ priority: number
677
+ globOptions: RawGlobOptions
524
678
  }
525
- export interface JsResourceData {
526
- /** Resource with absolute path, query and fragment */
527
- resource: string
528
- /** Absolute resource path only */
529
- path: string
530
- /** Resource query with `?` prefix */
531
- query?: string
532
- /** Resource fragment with `#` prefix */
533
- fragment?: string
679
+
680
+ export interface RawPluginImportConfig {
681
+ libraryName: string
682
+ libraryDirectory?: string
683
+ customName?: string
684
+ customStyleName?: string
685
+ style?: RawStyleConfig
686
+ camelToDashComponentName?: boolean
687
+ transformToDefaultImport?: boolean
688
+ ignoreEsComponent?: Array<string>
689
+ ignoreStyleComponent?: Array<string>
534
690
  }
535
- export interface JsCompatSource {
536
- /** Whether the underlying data structure is a `RawSource` */
537
- isRaw: boolean
538
- /** Whether the underlying value is a buffer or string */
539
- isBuffer: boolean
540
- source: Buffer
541
- map?: Buffer
691
+
692
+ export interface RawPostCssConfig {
693
+ pxtorem?: RawPxToRemConfig
542
694
  }
543
- export interface JsStatsError {
544
- message: string
545
- formatted: string
695
+
696
+ export interface RawPresetEnv {
697
+ targets: Array<string>
698
+ mode?: 'usage' | 'entry'
699
+ coreJs?: string
546
700
  }
547
- export interface JsStatsWarning {
548
- message: string
549
- formatted: string
701
+
702
+ export interface RawProgressPluginConfig {
703
+ prefix?: string
550
704
  }
551
- export interface JsStatsAsset {
552
- type: string
553
- name: string
554
- size: number
555
- chunks: Array<string>
556
- chunkNames: Array<string>
557
- info: JsStatsAssetInfo
558
- emitted: boolean
705
+
706
+ export interface RawPxToRemConfig {
707
+ rootValue?: number
708
+ unitPrecision?: number
709
+ selectorBlackList?: Array<string>
710
+ propList?: Array<string>
711
+ replace?: boolean
712
+ mediaQuery?: boolean
713
+ minPixelValue?: number
559
714
  }
560
- export interface JsStatsAssetInfo {
561
- development: boolean
562
- hotModuleReplacement: boolean
715
+
716
+ export interface RawReactOptions {
717
+ runtime?: "automatic" | "classic"
718
+ importSource?: string
719
+ pragma?: string
720
+ pragmaFrag?: string
721
+ throwIfNamespace?: boolean
722
+ development?: boolean
723
+ useBuiltins?: boolean
724
+ useSpread?: boolean
725
+ refresh?: boolean
563
726
  }
564
- export interface JsStatsModule {
565
- type: string
566
- moduleType: string
567
- identifier: string
568
- name: string
569
- id?: string
570
- chunks: Array<string>
571
- size: number
572
- issuer?: string
573
- issuerName?: string
574
- issuerId?: string
575
- issuerPath: Array<JsStatsModuleIssuer>
576
- reasons?: Array<JsStatsModuleReason>
577
- assets?: Array<string>
727
+
728
+ export interface RawRelayConfig {
729
+ artifactDirectory?: string
730
+ language: 'javascript' | 'typescript' | 'flow'
578
731
  }
579
- export interface JsStatsModuleIssuer {
580
- identifier: string
581
- name: string
582
- id?: string
732
+
733
+ export interface RawResolveOptions {
734
+ preferRelative?: boolean
735
+ extensions?: Array<string>
736
+ mainFiles?: Array<string>
737
+ mainFields?: Array<string>
738
+ browserField?: boolean
739
+ conditionNames?: Array<string>
740
+ alias?: Record<string, Array<string | false>>
741
+ fallback?: Record<string, Array<string | false>>
742
+ symlinks?: boolean
743
+ tsConfigPath?: string
744
+ modules?: Array<string>
745
+ byDependency?: Record<string, RawResolveOptions>
746
+ fullySpecified?: boolean
583
747
  }
584
- export interface JsStatsModuleReason {
585
- moduleIdentifier?: string
586
- moduleName?: string
587
- moduleId?: string
588
- type?: string
589
- userRequest?: string
748
+
749
+ export interface RawRuleSetCondition {
750
+ type: "string" | "regexp" | "logical" | "array" | "function"
751
+ stringMatcher?: string
752
+ regexpMatcher?: string
753
+ logicalMatcher?: Array<RawRuleSetLogicalConditions>
754
+ arrayMatcher?: Array<RawRuleSetCondition>
755
+ funcMatcher?: (value: string) => boolean
590
756
  }
591
- export interface JsStatsChunk {
592
- type: string
593
- files: Array<string>
594
- id: string
595
- entry: boolean
596
- initial: boolean
597
- names: Array<string>
598
- size: number
599
- modules?: Array<JsStatsModule>
600
- parents?: Array<string>
601
- children?: Array<string>
602
- siblings?: Array<string>
757
+
758
+ export interface RawRuleSetLogicalConditions {
759
+ and?: Array<RawRuleSetCondition>
760
+ or?: Array<RawRuleSetCondition>
761
+ not?: RawRuleSetCondition
603
762
  }
604
- export interface JsStatsChunkGroupAsset {
605
- name: string
606
- size: number
763
+
764
+ export interface RawSnapshotOptions {
765
+ resolve: RawSnapshotStrategy
766
+ module: RawSnapshotStrategy
607
767
  }
608
- export interface JsStatsChunkGroup {
609
- name: string
610
- assets: Array<JsStatsChunkGroupAsset>
611
- chunks: Array<string>
612
- assetsSize: number
768
+
769
+ export interface RawSnapshotStrategy {
770
+ hash: boolean
771
+ timestamp: boolean
613
772
  }
614
- export interface JsStatsAssetsByChunkName {
615
- name: string
616
- files: Array<string>
773
+
774
+ export interface RawSplitChunksOptions {
775
+ name?: string
776
+ cacheGroups?: Record<string, RawCacheGroupOptions>
777
+ /** What kind of chunks should be selected. */
778
+ chunks?: string
779
+ maxAsyncRequests?: number
780
+ maxInitialRequests?: number
781
+ minChunks?: number
782
+ minSize?: number
783
+ enforceSizeThreshold?: number
784
+ minRemainingSize?: number
617
785
  }
618
- export interface JsStatsGetAssets {
619
- assets: Array<JsStatsAsset>
620
- assetsByChunkName: Array<JsStatsAssetsByChunkName>
786
+
787
+ export interface RawStatsOptions {
788
+ colors: boolean
621
789
  }
622
- /**
623
- * Some code is modified based on
624
- * https://github.com/swc-project/swc/blob/d1d0607158ab40463d1b123fed52cc526eba8385/bindings/binding_core_node/src/util.rs#L29-L58
625
- * Apache-2.0 licensed
626
- * Author Donny/강동윤
627
- * Copyright (c)
628
- */
629
- export function initCustomTraceSubscriber(): void
630
- export class JsCompilation {
631
- updateAsset(filename: string, newSourceOrFunction: JsCompatSource | ((source: JsCompatSource) => JsCompatSource), assetInfoUpdateOrFunction?: JsAssetInfo | ((assetInfo: JsAssetInfo) => JsAssetInfo)): void
632
- getAssets(): Readonly<JsAsset>[]
633
- getAsset(name: string): JsAsset | null
634
- getAssetSource(name: string): JsCompatSource | null
635
- getModules(): Array<JsModule>
636
- getChunks(): Array<JsChunk>
637
- /**
638
- * Only available for those none Js and Css source,
639
- * return true if set module source successfully, false if failed.
640
- */
641
- setNoneAstModuleSource(moduleIdentifier: string, source: JsCompatSource): boolean
642
- setAssetSource(name: string, source: JsCompatSource): void
643
- deleteAssetSource(name: string): void
644
- getAssetFilenames(): Array<string>
645
- hasAsset(name: string): boolean
646
- emitAsset(filename: string, source: JsCompatSource, assetInfo: JsAssetInfo): void
647
- deleteAsset(filename: string): void
648
- get entrypoints(): Record<string, JsChunkGroup>
649
- get hash(): string
650
- getFileDependencies(): Array<string>
651
- getContextDependencies(): Array<string>
652
- getMissingDependencies(): Array<string>
653
- getBuildDependencies(): Array<string>
654
- pushDiagnostic(severity: "error" | "warning", title: string, message: string): void
655
- getStats(): JsStats
656
- addFileDependencies(deps: Array<string>): void
657
- addContextDependencies(deps: Array<string>): void
658
- addMissingDependencies(deps: Array<string>): void
659
- addBuildDependencies(deps: Array<string>): void
790
+
791
+ export interface RawStyleConfig {
792
+ styleLibraryDirectory?: string
793
+ custom?: string
794
+ css?: string
795
+ bool?: boolean
660
796
  }
661
- export class JsStats {
662
- getAssets(): JsStatsGetAssets
663
- getModules(reasons: boolean, moduleAssets: boolean): Array<JsStatsModule>
664
- getChunks(chunkModules: boolean, chunksRelations: boolean, reasons: boolean, moduleAssets: boolean): Array<JsStatsChunk>
665
- getEntrypoints(): Array<JsStatsChunkGroup>
666
- getNamedChunkGroups(): Array<JsStatsChunkGroup>
667
- getErrors(): Array<JsStatsError>
668
- getWarnings(): Array<JsStatsWarning>
669
- getHash(): string
797
+
798
+ export interface RawTrustedTypes {
799
+ policyName?: string
670
800
  }
671
- export class Rspack {
672
- constructor(options: RawOptions, jsHooks: JsHooks | undefined | null, outputFilesystem: ThreadsafeNodeFS, jsLoaderRunner: (...args: any[]) => any)
673
- unsafe_set_disabled_hooks(hooks: Array<string>): void
674
- /**
675
- * Build with the given option passed to the constructor
676
- *
677
- * Warning:
678
- * Calling this method recursively might cause a deadlock.
679
- */
680
- unsafe_build(callback: (err: null | Error) => void): void
681
- /**
682
- * Rebuild with the given option passed to the constructor
683
- *
684
- * Warning:
685
- * Calling this method recursively will cause a deadlock.
686
- */
687
- unsafe_rebuild(changed_files: string[], removed_files: string[], callback: (err: null | Error) => void): void
688
- /**
689
- * Get the last compilation
690
- *
691
- * Warning:
692
- *
693
- * Calling this method under the build or rebuild method might cause a deadlock.
694
- *
695
- * **Note** that this method is not safe if you cache the _JsCompilation_ on the Node side, as it will be invalidated by the next build and accessing a dangling ptr is a UB.
696
- */
697
- unsafe_last_compilation(f: (arg0: JsCompilation) => void): void
698
- /**
699
- * Destroy the compiler
700
- *
701
- * Warning:
702
- *
703
- * Anything related to this compiler will be invalidated after this method is called.
704
- */
705
- unsafe_drop(): void
801
+
802
+ export interface SchemeAndJsResourceData {
803
+ resourceData: JsResourceData
804
+ scheme: string
706
805
  }
806
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/binding",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "license": "MIT",
5
5
  "description": "Node binding for rspack",
6
6
  "main": "binding.js",
@@ -16,24 +16,24 @@
16
16
  "bugs": "https://github.com/web-infra-dev/rspack/issues",
17
17
  "repository": "web-infra-dev/rspack",
18
18
  "devDependencies": {
19
- "@napi-rs/cli": "2.15.2",
19
+ "@napi-rs/cli": "3.0.0-alpha.3",
20
20
  "cross-env": "^7.0.3",
21
21
  "npm-run-all": "4.1.5",
22
22
  "why-is-node-running": "2.2.1"
23
23
  },
24
24
  "napi": {
25
- "name": "rspack"
25
+ "binaryName": "rspack"
26
26
  },
27
27
  "optionalDependencies": {
28
- "@rspack/binding-darwin-arm64": "0.1.9",
29
- "@rspack/binding-win32-arm64-msvc": "0.1.9",
30
- "@rspack/binding-linux-arm64-gnu": "0.1.9",
31
- "@rspack/binding-linux-arm64-musl": "0.1.9",
32
- "@rspack/binding-win32-ia32-msvc": "0.1.9",
33
- "@rspack/binding-darwin-x64": "0.1.9",
34
- "@rspack/binding-win32-x64-msvc": "0.1.9",
35
- "@rspack/binding-linux-x64-gnu": "0.1.9",
36
- "@rspack/binding-linux-x64-musl": "0.1.9"
28
+ "@rspack/binding-darwin-arm64": "0.1.11",
29
+ "@rspack/binding-win32-arm64-msvc": "0.1.11",
30
+ "@rspack/binding-linux-arm64-gnu": "0.1.11",
31
+ "@rspack/binding-linux-arm64-musl": "0.1.11",
32
+ "@rspack/binding-win32-ia32-msvc": "0.1.11",
33
+ "@rspack/binding-darwin-x64": "0.1.11",
34
+ "@rspack/binding-win32-x64-msvc": "0.1.11",
35
+ "@rspack/binding-linux-x64-gnu": "0.1.11",
36
+ "@rspack/binding-linux-x64-musl": "0.1.11"
37
37
  },
38
38
  "scripts": {
39
39
  "build:debug": "node scripts/build.js",