@rspack/binding 0.1.9 → 0.1.10

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 +639 -529
  2. package/package.json +12 -12
package/binding.d.ts CHANGED
@@ -1,148 +1,368 @@
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): Array<JsStatsModule>
39
+ getChunks(chunkModules: boolean, chunksRelations: boolean, reasons: boolean, moduleAssets: 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?: 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>
308
+ }
309
+
310
+ export interface JsStatsModuleIssuer {
311
+ identifier: string
312
+ name: string
313
+ id?: string
314
+ }
315
+
316
+ export interface JsStatsModuleReason {
317
+ moduleIdentifier?: string
318
+ moduleName?: string
319
+ moduleId?: string
320
+ type?: string
321
+ userRequest?: string
105
322
  }
106
- export interface RawPostCssConfig {
107
- pxtorem?: RawPxToRemConfig
323
+
324
+ export interface JsStatsWarning {
325
+ message: string
326
+ formatted: string
108
327
  }
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
328
+
329
+ export interface NodeFS {
330
+ writeFile: (...args: any[]) => any
331
+ mkdir: (...args: any[]) => any
332
+ mkdirp: (...args: any[]) => any
117
333
  }
118
- export interface RawProgressPluginConfig {
119
- prefix?: string
334
+
335
+ export interface RawAssetParserDataUrlOption {
336
+ maxSize?: number
120
337
  }
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
338
+
339
+ export interface RawAssetParserOptions {
340
+ dataUrlCondition?: RawAssetParserDataUrlOption
131
341
  }
132
- export interface RawRelayConfig {
133
- artifactDirectory?: string
134
- language: 'javascript' | 'typescript' | 'flow'
342
+
343
+ export interface RawBannerCondition {
344
+ type: "string" | "regexp"
345
+ stringMatcher?: string
346
+ regexpMatcher?: string
135
347
  }
136
- export interface RawMinification {
137
- passes: number
138
- dropConsole: boolean
139
- pureFuncs: Array<string>
348
+
349
+ export interface RawBannerConditions {
350
+ type: "string" | "regexp" | "array"
351
+ stringMatcher?: string
352
+ regexpMatcher?: string
353
+ arrayMatcher?: Array<RawBannerCondition>
140
354
  }
141
- export interface RawPresetEnv {
142
- targets: Array<string>
143
- mode?: 'usage' | 'entry'
144
- coreJs?: string
355
+
356
+ export interface RawBannerConfig {
357
+ banner: string
358
+ entryOnly?: boolean
359
+ footer?: boolean
360
+ raw?: boolean
361
+ test?: RawBannerConditions
362
+ include?: RawBannerConditions
363
+ exclude?: RawBannerConditions
145
364
  }
365
+
146
366
  export interface RawBuiltins {
147
367
  html?: Array<RawHtmlPluginConfig>
148
368
  css?: RawCssPluginConfig
@@ -162,7 +382,20 @@ export interface RawBuiltins {
162
382
  banner?: Array<RawBannerConfig>
163
383
  pluginImport?: Array<RawPluginImportConfig>
164
384
  relay?: RawRelayConfig
385
+ codeGeneration?: RawCodeGeneration
386
+ }
387
+
388
+ export interface RawCacheGroupOptions {
389
+ priority?: number
390
+ test?: string
391
+ /** What kind of chunks should be selected. */
392
+ chunks?: string
393
+ minChunks?: number
394
+ minSize?: number
395
+ name?: string
396
+ reuseExistingChunk?: boolean
165
397
  }
398
+
166
399
  export interface RawCacheOptions {
167
400
  type: string
168
401
  maxGenerations: number
@@ -174,19 +407,53 @@ export interface RawCacheOptions {
174
407
  name: string
175
408
  version: string
176
409
  }
410
+
411
+ export interface RawCodeGeneration {
412
+ keepComments: boolean
413
+ }
414
+
415
+ export interface RawCopyConfig {
416
+ patterns: Array<RawPattern>
417
+ }
418
+
419
+ export interface RawCrossOriginLoading {
420
+ type: "bool" | "string"
421
+ stringPayload?: string
422
+ boolPayload?: boolean
423
+ }
424
+
425
+ export interface RawCssModulesConfig {
426
+ localsConvention: "asIs" | "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly"
427
+ localIdentName: string
428
+ exportsOnly: boolean
429
+ }
430
+
431
+ export interface RawCssPluginConfig {
432
+ modules: RawCssModulesConfig
433
+ }
434
+
435
+ export interface RawDecoratorOptions {
436
+ legacy: boolean
437
+ emitMetadata: boolean
438
+ }
439
+
177
440
  export interface RawDevServer {
178
441
  hot: boolean
179
442
  }
443
+
180
444
  export interface RawEntryItem {
181
445
  import: Array<string>
182
446
  runtime?: string
183
447
  }
448
+
184
449
  export interface RawExperiments {
185
450
  lazyCompilation: boolean
186
451
  incrementalRebuild: boolean
187
452
  asyncWebAssembly: boolean
188
453
  newSplitChunks: boolean
454
+ css: boolean
189
455
  }
456
+
190
457
  export interface RawExternalItem {
191
458
  type: "string" | "regexp" | "object" | "function"
192
459
  stringPayload?: string
@@ -194,87 +461,91 @@ export interface RawExternalItem {
194
461
  objectPayload?: Record<string, RawExternalItemValue>
195
462
  fnPayload?: (value: any) => any
196
463
  }
197
- export interface RawExternalItemValue {
198
- type: "string" | "bool"
199
- stringPayload?: string
200
- boolPayload?: boolean
464
+
465
+ export interface RawExternalItemFnCtx {
466
+ request: string
467
+ context: string
468
+ dependencyType: string
201
469
  }
470
+
202
471
  export interface RawExternalItemFnResult {
203
472
  externalType?: string
204
473
  result?: RawExternalItemValue
205
474
  }
206
- export interface RawExternalItemFnCtx {
207
- request: string
208
- context: string
209
- dependencyType: string
475
+
476
+ export interface RawExternalItemValue {
477
+ type: "string" | "bool"
478
+ stringPayload?: string
479
+ boolPayload?: boolean
210
480
  }
481
+
211
482
  export interface RawExternalsPresets {
212
483
  node: boolean
484
+ web: boolean
213
485
  }
214
- export interface JsLoader {
215
- /** composed loader name, xx-loader$yy-loader$zz-loader */
216
- identifier: string
486
+
487
+ export interface RawGlobOptions {
488
+ caseSensitiveMatch?: boolean
489
+ dot?: boolean
490
+ ignore?: Array<string>
217
491
  }
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
492
+
493
+ export interface RawHtmlPluginConfig {
494
+ /** emitted file name in output path */
495
+ filename?: string
496
+ /** template html file */
497
+ template?: string
498
+ templateContent?: string
499
+ templateParameters?: Record<string, string>
500
+ /** `head`, `body` or None */
501
+ inject?: "head" | "body"
502
+ /** path or `auto` */
503
+ publicPath?: string
504
+ /** `blocking`, `defer`, or `module` */
505
+ scriptLoading?: "blocking" | "defer" | "module"
506
+ /** entry_chunk_name (only entry chunks are supported) */
507
+ chunks?: Array<string>
508
+ excludedChunks?: Array<string>
509
+ sri?: "sha256" | "sha384" | "sha512"
510
+ minify?: boolean
511
+ title?: string
512
+ favicon?: string
513
+ meta?: Record<string, Record<string, string>>
235
514
  }
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
515
+
516
+ export interface RawLibraryAuxiliaryComment {
517
+ root?: string
518
+ commonjs?: string
519
+ commonjs2?: string
520
+ amd?: string
248
521
  }
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
522
+
523
+ export interface RawLibraryName {
524
+ amd?: string
525
+ commonjs?: string
526
+ root?: Array<string>
264
527
  }
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
528
+
529
+ export interface RawLibraryOptions {
530
+ name?: RawLibraryName
531
+ export?: Array<string>
532
+ libraryType: string
533
+ umdNamedDefine?: boolean
534
+ auxiliaryComment?: RawLibraryAuxiliaryComment
272
535
  }
273
- export interface RawRuleSetLogicalConditions {
274
- and?: Array<RawRuleSetCondition>
275
- or?: Array<RawRuleSetCondition>
276
- not?: RawRuleSetCondition
536
+
537
+ export interface RawMinification {
538
+ passes: number
539
+ dropConsole: boolean
540
+ pureFuncs: Array<string>
541
+ extractComments?: string
542
+ }
543
+
544
+ export interface RawModuleOptions {
545
+ rules: Array<RawModuleRule>
546
+ parser?: RawParserOptions
277
547
  }
548
+
278
549
  export interface RawModuleRule {
279
550
  /** A condition matcher matching an absolute path. */
280
551
  test?: RawRuleSetCondition
@@ -297,134 +568,46 @@ export interface RawModuleRule {
297
568
  /** Specifies the category of the loader. No value means normal loader. */
298
569
  enforce?: 'pre' | 'post'
299
570
  }
571
+
300
572
  export interface RawModuleRuleGenerator {
301
573
  filename?: string
302
574
  }
575
+
303
576
  export interface RawModuleRuleParser {
304
577
  dataUrlCondition?: RawAssetParserDataUrlOption
305
578
  }
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
579
+
580
+ /**
581
+ * `loader` is for js side loader, `builtin_loader` is for rust side loader,
582
+ * which is mapped to real rust side loader by [get_builtin_loader].
583
+ *
584
+ * `options` is
585
+ * - a `None` on rust side and handled by js side `getOptions` when
586
+ * using with `loader`.
587
+ * - a `Some(string)` on rust side, deserialized by `serde_json::from_str`
588
+ * and passed to rust side loader in [get_builtin_loader] when using with
589
+ * `builtin_loader`.
590
+ */
591
+ export interface RawModuleRuleUse {
592
+ jsLoader?: JsLoader
593
+ builtinLoader?: string
594
+ options?: string
318
595
  }
596
+
319
597
  export interface RawNodeOption {
320
598
  dirname: string
321
599
  filename: string
322
600
  global: string
323
601
  }
602
+
324
603
  export interface RawOptimizationOptions {
325
604
  splitChunks?: RawSplitChunksOptions
326
605
  moduleIds: string
327
606
  removeAvailableModules: boolean
328
607
  sideEffects: string
608
+ realContentHash: boolean
329
609
  }
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
- }
610
+
428
611
  export interface RawOptions {
429
612
  entry: Record<string, RawEntryItem>
430
613
  /**
@@ -452,255 +635,182 @@ export interface RawOptions {
452
635
  experiments: RawExperiments
453
636
  node?: RawNodeOption
454
637
  }
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
638
+
639
+ export interface RawOutputOptions {
640
+ path: string
641
+ clean: boolean
642
+ publicPath: string
643
+ assetModuleFilename: string
644
+ wasmLoading: string
645
+ enabledWasmLoadingTypes: Array<string>
646
+ webassemblyModuleFilename: string
492
647
  filename: string
648
+ chunkFilename: string
649
+ crossOriginLoading: RawCrossOriginLoading
650
+ cssFilename: string
651
+ cssChunkFilename: string
652
+ uniqueName: string
653
+ chunkLoadingGlobal: string
654
+ library?: RawLibraryOptions
655
+ strictModuleErrorHandling: boolean
656
+ enabledLibraryTypes?: Array<string>
657
+ globalObject: string
658
+ importFunctionName: string
659
+ iife: boolean
660
+ module: boolean
661
+ chunkFormat?: string
662
+ chunkLoading?: string
663
+ enabledChunkLoadingTypes?: Array<string>
664
+ trustedTypes?: RawTrustedTypes
665
+ sourceMapFilename: string
493
666
  }
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
520
- }
521
- export interface SchemeAndJsResourceData {
522
- resourceData: JsResourceData
523
- scheme: string
667
+
668
+ export interface RawParserOptions {
669
+ asset?: RawAssetParserOptions
524
670
  }
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
671
+
672
+ export interface RawPattern {
673
+ from: string
674
+ to?: string
675
+ context?: string
676
+ toType?: string
677
+ noErrorOnMissing: boolean
678
+ force: boolean
679
+ priority: number
680
+ globOptions: RawGlobOptions
534
681
  }
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
682
+
683
+ export interface RawPluginImportConfig {
684
+ libraryName: string
685
+ libraryDirectory?: string
686
+ customName?: string
687
+ customStyleName?: string
688
+ style?: RawStyleConfig
689
+ camelToDashComponentName?: boolean
690
+ transformToDefaultImport?: boolean
691
+ ignoreEsComponent?: Array<string>
692
+ ignoreStyleComponent?: Array<string>
542
693
  }
543
- export interface JsStatsError {
544
- message: string
545
- formatted: string
694
+
695
+ export interface RawPostCssConfig {
696
+ pxtorem?: RawPxToRemConfig
546
697
  }
547
- export interface JsStatsWarning {
548
- message: string
549
- formatted: string
698
+
699
+ export interface RawPresetEnv {
700
+ targets: Array<string>
701
+ mode?: 'usage' | 'entry'
702
+ coreJs?: string
550
703
  }
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
704
+
705
+ export interface RawProgressPluginConfig {
706
+ prefix?: string
559
707
  }
560
- export interface JsStatsAssetInfo {
561
- development: boolean
562
- hotModuleReplacement: boolean
708
+
709
+ export interface RawPxToRemConfig {
710
+ rootValue?: number
711
+ unitPrecision?: number
712
+ selectorBlackList?: Array<string>
713
+ propList?: Array<string>
714
+ replace?: boolean
715
+ mediaQuery?: boolean
716
+ minPixelValue?: number
563
717
  }
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>
718
+
719
+ export interface RawReactOptions {
720
+ runtime?: "automatic" | "classic"
721
+ importSource?: string
722
+ pragma?: string
723
+ pragmaFrag?: string
724
+ throwIfNamespace?: boolean
725
+ development?: boolean
726
+ useBuiltins?: boolean
727
+ useSpread?: boolean
728
+ refresh?: boolean
578
729
  }
579
- export interface JsStatsModuleIssuer {
580
- identifier: string
581
- name: string
582
- id?: string
730
+
731
+ export interface RawRelayConfig {
732
+ artifactDirectory?: string
733
+ language: 'javascript' | 'typescript' | 'flow'
583
734
  }
584
- export interface JsStatsModuleReason {
585
- moduleIdentifier?: string
586
- moduleName?: string
587
- moduleId?: string
588
- type?: string
589
- userRequest?: string
735
+
736
+ export interface RawResolveOptions {
737
+ preferRelative?: boolean
738
+ extensions?: Array<string>
739
+ mainFiles?: Array<string>
740
+ mainFields?: Array<string>
741
+ browserField?: boolean
742
+ conditionNames?: Array<string>
743
+ alias?: Record<string, Array<string | false>>
744
+ fallback?: Record<string, Array<string | false>>
745
+ symlinks?: boolean
746
+ tsConfigPath?: string
747
+ modules?: Array<string>
748
+ byDependency?: Record<string, RawResolveOptions>
749
+ fullySpecified?: boolean
590
750
  }
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>
751
+
752
+ export interface RawRuleSetCondition {
753
+ type: "string" | "regexp" | "logical" | "array" | "function"
754
+ stringMatcher?: string
755
+ regexpMatcher?: string
756
+ logicalMatcher?: Array<RawRuleSetLogicalConditions>
757
+ arrayMatcher?: Array<RawRuleSetCondition>
758
+ funcMatcher?: (value: string) => boolean
603
759
  }
604
- export interface JsStatsChunkGroupAsset {
605
- name: string
606
- size: number
760
+
761
+ export interface RawRuleSetLogicalConditions {
762
+ and?: Array<RawRuleSetCondition>
763
+ or?: Array<RawRuleSetCondition>
764
+ not?: RawRuleSetCondition
607
765
  }
608
- export interface JsStatsChunkGroup {
609
- name: string
610
- assets: Array<JsStatsChunkGroupAsset>
611
- chunks: Array<string>
612
- assetsSize: number
766
+
767
+ export interface RawSnapshotOptions {
768
+ resolve: RawSnapshotStrategy
769
+ module: RawSnapshotStrategy
613
770
  }
614
- export interface JsStatsAssetsByChunkName {
615
- name: string
616
- files: Array<string>
771
+
772
+ export interface RawSnapshotStrategy {
773
+ hash: boolean
774
+ timestamp: boolean
617
775
  }
618
- export interface JsStatsGetAssets {
619
- assets: Array<JsStatsAsset>
620
- assetsByChunkName: Array<JsStatsAssetsByChunkName>
776
+
777
+ export interface RawSplitChunksOptions {
778
+ name?: string
779
+ cacheGroups?: Record<string, RawCacheGroupOptions>
780
+ /** What kind of chunks should be selected. */
781
+ chunks?: string
782
+ maxAsyncRequests?: number
783
+ maxInitialRequests?: number
784
+ minChunks?: number
785
+ minSize?: number
786
+ enforceSizeThreshold?: number
787
+ minRemainingSize?: number
621
788
  }
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
789
+
790
+ export interface RawStatsOptions {
791
+ colors: boolean
660
792
  }
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
793
+
794
+ export interface RawStyleConfig {
795
+ styleLibraryDirectory?: string
796
+ custom?: string
797
+ css?: string
798
+ bool?: boolean
670
799
  }
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
800
+
801
+ export interface RawTrustedTypes {
802
+ policyName?: string
803
+ }
804
+
805
+ export interface SchemeAndJsResourceData {
806
+ resourceData: JsResourceData
807
+ scheme: string
706
808
  }
809
+
810
+ export interface ThreadsafeNodeFS {
811
+ writeFile: (...args: any[]) => any
812
+ mkdir: (...args: any[]) => any
813
+ mkdirp: (...args: any[]) => any
814
+ removeDirAll: (...args: any[]) => any
815
+ }
816
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/binding",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
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.10",
29
+ "@rspack/binding-win32-arm64-msvc": "0.1.10",
30
+ "@rspack/binding-linux-arm64-gnu": "0.1.10",
31
+ "@rspack/binding-linux-arm64-musl": "0.1.10",
32
+ "@rspack/binding-win32-ia32-msvc": "0.1.10",
33
+ "@rspack/binding-darwin-x64": "0.1.10",
34
+ "@rspack/binding-win32-x64-msvc": "0.1.10",
35
+ "@rspack/binding-linux-x64-gnu": "0.1.10",
36
+ "@rspack/binding-linux-x64-musl": "0.1.10"
37
37
  },
38
38
  "scripts": {
39
39
  "build:debug": "node scripts/build.js",