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