@rspack/binding 0.0.22 → 0.0.24

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.
package/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022-present Rspack Authors
3
+ Copyright (c) 2022-present Bytedance, Inc. and its affiliates.
4
+
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://lf3-static.bytednsdoc.com/obj/eden-cn/rjhwzy/ljhwZthlaukjlkulzlp/rspack-banner-1610-dark.png">
3
+ <img alt="Rspack Banner" src="https://lf3-static.bytednsdoc.com/obj/eden-cn/rjhwzy/ljhwZthlaukjlkulzlp/rspack-banner-1610.png">
4
+ </picture>
5
+
6
+ # @rspack/binding
7
+
8
+ Node binding for rspack.
9
+
10
+ ## Documentation
11
+
12
+ See [https://rspack.org](https://rspack.org) for details.
13
+
14
+ ## License
15
+
16
+ Rspack is [MIT licensed](https://github.com/modern-js-dev/rspack/blob/main/LICENSE).
package/binding.d.ts CHANGED
@@ -3,53 +3,73 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
+ export interface RawPattern {
7
+ from: string
8
+ to?: string
9
+ context?: string
10
+ toType?: string
11
+ noErrorOnMissing: boolean
12
+ force: boolean
13
+ priority: number
14
+ globOptions: RawGlobOptions
15
+ }
16
+ export interface RawGlobOptions {
17
+ caseSensitiveMatch?: boolean
18
+ dot?: boolean
19
+ }
20
+ export interface RawCopyConfig {
21
+ patterns: Array<RawPattern>
22
+ }
6
23
  export interface RawCssPluginConfig {
7
- /**
8
- * ## Example
9
- * ```rust,ignore
10
- * RawCssOptions {
11
- * preset_env: vec!["Firefox > 10".into(), "chrome >=20".into()],
12
- * }
13
- * ```
14
- * The preset_env will finally pass into [`browserslist::resolve`](https://docs.rs/browserslist-rs/latest/browserslist/fn.resolve.html).
15
- * For detailed configuration, see https://docs.rs/browserslist-rs/latest/browserslist/
16
- */
17
- presetEnv?: Array<string>
18
- modules?: RawCssModulesConfig
24
+ modules: RawCssModulesConfig
19
25
  }
20
26
  export interface RawCssModulesConfig {
21
- localsConvention?: string
22
- localIdentName?: string
23
- exportsOnly?: boolean
27
+ localsConvention: "asIs" | "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly"
28
+ localIdentName: string
29
+ exportsOnly: boolean
24
30
  }
25
31
  export interface RawDecoratorOptions {
26
32
  legacy: boolean
27
33
  emitMetadata: boolean
28
34
  }
29
- /**
30
- * It seems napi not support enum well
31
- */
32
35
  export interface RawHtmlPluginConfig {
33
36
  /** emitted file name in output path */
34
- filename?: string | void
37
+ filename?: string
35
38
  /** template html file */
36
39
  template?: string
37
40
  templateParameters?: Record<string, string>
38
41
  /** `head`, `body` or None */
39
- inject?: string | void
42
+ inject?: "head" | "body"
40
43
  /** path or `auto` */
41
44
  publicPath?: string
42
45
  /** `blocking`, `defer`, or `module` */
43
- scriptLoading?: string | void
46
+ scriptLoading?: "blocking" | "defer" | "module"
44
47
  /** entry_chunk_name (only entry chunks are supported) */
45
48
  chunks?: Array<string>
46
49
  excludedChunks?: Array<string>
47
- sri?: string | void
50
+ sri?: "sha256" | "sha384" | "sha512"
48
51
  minify?: boolean
49
52
  title?: string
50
53
  favicon?: string
51
54
  meta?: Record<string, Record<string, string>>
52
55
  }
56
+ export interface RawStyleConfig {
57
+ styleLibraryDirectory?: string
58
+ custom?: string
59
+ css?: string
60
+ bool?: boolean
61
+ }
62
+ export interface RawPluginImportConfig {
63
+ libraryName: string
64
+ libraryDirectory?: string
65
+ customName?: string
66
+ customStyleName?: string
67
+ style?: RawStyleConfig
68
+ camelToDashComponentName?: boolean
69
+ transformToDefaultImport?: boolean
70
+ ignoreEsComponent?: Array<string>
71
+ ignoreStyleComponent?: Array<string>
72
+ }
53
73
  export interface RawPostCssConfig {
54
74
  pxtorem?: RawPxToRemConfig
55
75
  }
@@ -66,7 +86,7 @@ export interface RawProgressPluginConfig {
66
86
  prefix?: string
67
87
  }
68
88
  export interface RawReactOptions {
69
- runtime?: string
89
+ runtime?: "automatic" | "classic"
70
90
  importSource?: string
71
91
  pragma?: string
72
92
  pragmaFrag?: string
@@ -76,27 +96,37 @@ export interface RawReactOptions {
76
96
  useSpread?: boolean
77
97
  refresh?: boolean
78
98
  }
79
- export interface Minification {
80
- passes?: number
81
- enable?: boolean
82
- dropConsole?: boolean
83
- pureFuncs?: Array<string>
99
+ export interface RawRelayConfig {
100
+ artifactDirectory?: string
101
+ language: 'javascript' | 'typescript' | 'flow'
102
+ }
103
+ export interface RawMinification {
104
+ passes: number
105
+ dropConsole: boolean
106
+ pureFuncs: Array<string>
107
+ }
108
+ export interface RawPresetEnv {
109
+ targets: Array<string>
110
+ mode?: 'usage' | 'entry'
111
+ coreJs?: string
84
112
  }
85
113
  export interface RawBuiltins {
86
114
  html?: Array<RawHtmlPluginConfig>
87
115
  css?: RawCssPluginConfig
88
116
  postcss?: RawPostCssConfig
89
- minify?: Minification
90
- polyfill?: boolean
91
- browserslist?: Array<string>
92
- define?: Record<string, string>
93
- treeShaking?: boolean
94
- sideEffects?: boolean
117
+ minifyOptions?: RawMinification
118
+ presetEnv?: RawPresetEnv
119
+ define: Record<string, string>
120
+ treeShaking: boolean
95
121
  progress?: RawProgressPluginConfig
96
- react?: RawReactOptions
122
+ react: RawReactOptions
97
123
  decorator?: RawDecoratorOptions
98
- noEmitAssets?: boolean
124
+ noEmitAssets: boolean
99
125
  emotion?: string
126
+ devFriendlySplitChunks: boolean
127
+ copy?: RawCopyConfig
128
+ pluginImport?: Array<RawPluginImportConfig>
129
+ relay?: RawRelayConfig
100
130
  }
101
131
  export interface RawCacheOptions {
102
132
  type: string
@@ -110,7 +140,7 @@ export interface RawCacheOptions {
110
140
  version: string
111
141
  }
112
142
  export interface RawDevServer {
113
- hot?: boolean
143
+ hot: boolean
114
144
  }
115
145
  export interface RawEntryItem {
116
146
  import: Array<string>
@@ -118,7 +148,7 @@ export interface RawEntryItem {
118
148
  }
119
149
  export interface RawExperiments {
120
150
  lazyCompilation: boolean
121
- changedHmr: boolean
151
+ incrementalRebuild: boolean
122
152
  }
123
153
  /**
124
154
  * `loader` is for js side loader, `builtin_loader` is for rust side loader,
@@ -132,51 +162,44 @@ export interface RawExperiments {
132
162
  * `builtin_loader`.
133
163
  */
134
164
  export interface RawModuleRuleUse {
135
- loader?: (...args: any[]) => any
165
+ jsLoader?: JsLoader
136
166
  builtinLoader?: string
137
167
  options?: string
138
- loaderName?: string
139
168
  }
140
- export interface RawModuleRuleCondition {
141
- /** Condition can be either a `string` or `Regexp`. */
142
- type: "string" | "regexp"
143
- /**
144
- * Based on the condition type, the value can be either a `string` or `Regexp`.
145
- * - "string": The value will be matched against the string.
146
- * - "regexp": The value will be matched against the raw regexp source from JS side.
147
- */
148
- matcher?: string
169
+ export interface JsLoader {
170
+ /** composed loader name, xx-loader!yy-loader!zz-loader */
171
+ name: string
172
+ func: (...args: any[]) => any
149
173
  }
150
- export interface RawIssuerOptions {
151
- not?: Array<RawModuleRuleCondition>
174
+ export interface RawRuleSetCondition {
175
+ type: "string" | "regexp" | "logical" | "array"
176
+ stringMatcher?: string
177
+ regexpMatcher?: string
178
+ logicalMatcher?: Array<RawRuleSetLogicalConditions>
179
+ arrayMatcher?: Array<RawRuleSetCondition>
180
+ }
181
+ export interface RawRuleSetLogicalConditions {
182
+ and?: Array<RawRuleSetCondition>
183
+ or?: Array<RawRuleSetCondition>
184
+ not?: RawRuleSetCondition
152
185
  }
153
186
  export interface RawModuleRule {
154
- /**
155
- * A condition matcher matching an absolute path.
156
- * - String: To match the input must start with the provided string. I. e. an absolute directory path, or absolute path to the file.
157
- * - Regexp: It's tested with the input.
158
- */
159
- test?: RawModuleRuleCondition
160
- include?: Array<RawModuleRuleCondition>
161
- exclude?: Array<RawModuleRuleCondition>
162
- /**
163
- * A condition matcher matching an absolute path.
164
- * See `test` above
165
- */
166
- resource?: RawModuleRuleCondition
167
- /**
168
- * A condition matcher against the resource query.
169
- * TODO: align with webpack's `?` prefixed `resourceQuery`
170
- */
171
- resourceQuery?: RawModuleRuleCondition
187
+ /** A condition matcher matching an absolute path. */
188
+ test?: RawRuleSetCondition
189
+ include?: RawRuleSetCondition
190
+ exclude?: RawRuleSetCondition
191
+ /** A condition matcher matching an absolute path. */
192
+ resource?: RawRuleSetCondition
193
+ /** A condition matcher against the resource query. */
194
+ resourceQuery?: RawRuleSetCondition
172
195
  sideEffects?: boolean
173
196
  use?: Array<RawModuleRuleUse>
174
- type?: "js" | "jsx" | "ts" | "tsx" | "css" | "json" | "asset" | "asset/resource" | "asset/source" | "asset/inline"
197
+ type?: string
175
198
  parser?: RawModuleRuleParser
176
199
  generator?: RawModuleRuleGenerator
177
200
  resolve?: RawResolveOptions
178
- issuer?: RawIssuerOptions
179
- func?: (...args: any[]) => any
201
+ issuer?: RawRuleSetCondition
202
+ oneOf?: Array<RawModuleRule>
180
203
  }
181
204
  export interface RawModuleRuleGenerator {
182
205
  filename?: string
@@ -222,24 +245,38 @@ export interface JsLoaderResult {
222
245
  cacheable: boolean
223
246
  }
224
247
  export interface RawNodeOption {
225
- dirname?: string
248
+ dirname: string
249
+ global: string
226
250
  }
227
251
  export interface RawOptimizationOptions {
228
252
  splitChunks?: RawSplitChunksOptions
229
- moduleIds?: string
230
- removeAvailableModules?: boolean
253
+ moduleIds: string
254
+ removeAvailableModules: boolean
255
+ sideEffects: string
256
+ }
257
+ export interface RawLibraryName {
258
+ amd?: string
259
+ commonjs?: string
260
+ root?: Array<string>
261
+ }
262
+ export interface RawLibraryOptions {
263
+ name?: RawLibraryName
264
+ export?: Array<string>
265
+ libraryType: string
266
+ umdNamedDefine?: boolean
231
267
  }
232
268
  export interface RawOutputOptions {
233
- path?: string
234
- publicPath?: string
235
- assetModuleFilename?: string
236
- filename?: string
237
- chunkFilename?: string
238
- cssFilename?: string
239
- cssChunkFilename?: string
240
- uniqueName?: string
241
- library?: string
242
- strictModuleErrorHandling?: boolean
269
+ path: string
270
+ publicPath: string
271
+ assetModuleFilename: string
272
+ filename: string
273
+ chunkFilename: string
274
+ cssFilename: string
275
+ cssChunkFilename: string
276
+ uniqueName: string
277
+ library?: RawLibraryOptions
278
+ strictModuleErrorHandling: boolean
279
+ enabledLibraryTypes?: Array<string>
243
280
  }
244
281
  export interface RawResolveOptions {
245
282
  preferRelative?: boolean
@@ -259,8 +296,6 @@ export interface RawSnapshotStrategy {
259
296
  timestamp: boolean
260
297
  }
261
298
  export interface RawSnapshotOptions {
262
- resolveBuildDependencies: RawSnapshotStrategy
263
- buildDependencies: RawSnapshotStrategy
264
299
  resolve: RawSnapshotStrategy
265
300
  module: RawSnapshotStrategy
266
301
  }
@@ -288,24 +323,34 @@ export interface RawStatsOptions {
288
323
  colors: boolean
289
324
  }
290
325
  export interface RawOptions {
291
- entry?: Record<string, RawEntryItem>
292
- mode?: string
293
- target?: string[]
294
- context?: string
295
- output?: RawOutputOptions
296
- resolve?: RawResolveOptions
297
- module?: RawModuleOptions
298
- builtins?: RawBuiltins
299
- externals?: Record<string, string>
300
- externalsType?: string
301
- devtool?: string
302
- optimization?: RawOptimizationOptions
303
- stats?: RawStatsOptions
304
- devServer?: RawDevServer
305
- snapshot?: RawSnapshotOptions
306
- cache?: RawCacheOptions
307
- experiments?: RawExperiments
308
- node?: RawNodeOption
326
+ entry: Record<string, RawEntryItem>
327
+ mode?: undefined | 'production' | 'development' | 'none'
328
+ target: Array<string>
329
+ context: string
330
+ output: RawOutputOptions
331
+ resolve: RawResolveOptions
332
+ module: RawModuleOptions
333
+ builtins: RawBuiltins
334
+ externals: Record<string, string>
335
+ externalsType: '' | 'node-commonjs' | 'window'
336
+ devtool: string
337
+ optimization: RawOptimizationOptions
338
+ stats: RawStatsOptions
339
+ devServer: RawDevServer
340
+ snapshot: RawSnapshotOptions
341
+ cache: RawCacheOptions
342
+ experiments: RawExperiments
343
+ node: RawNodeOption
344
+ }
345
+ export interface ThreadsafeNodeFs {
346
+ writeFile: (...args: any[]) => any
347
+ mkdir: (...args: any[]) => any
348
+ mkdirp: (...args: any[]) => any
349
+ }
350
+ export interface NodeFs {
351
+ writeFile: (...args: any[]) => any
352
+ mkdir: (...args: any[]) => any
353
+ mkdirp: (...args: any[]) => any
309
354
  }
310
355
  export interface JsAssetInfoRelated {
311
356
  sourceMap?: string
@@ -357,6 +402,12 @@ export interface JsHooks {
357
402
  emit: (...args: any[]) => any
358
403
  afterEmit: (...args: any[]) => any
359
404
  make: (...args: any[]) => any
405
+ optimizeChunkModule: (...args: any[]) => any
406
+ }
407
+ export interface JsModule {
408
+ originalSource?: JsCompatSource
409
+ resource: string
410
+ moduleIdentifier: string
360
411
  }
361
412
  export interface JsCompatSource {
362
413
  /** Whether the underlying data structure is a `RawSource` */
@@ -420,26 +471,23 @@ export interface JsStatsChunk {
420
471
  names: Array<string>
421
472
  size: number
422
473
  }
423
- export interface JsStatsEntrypointAsset {
474
+ export interface JsStatsChunkGroupAsset {
424
475
  name: string
425
476
  size: number
426
477
  }
427
- export interface JsStatsEntrypoint {
478
+ export interface JsStatsChunkGroup {
428
479
  name: string
429
- assets: Array<JsStatsEntrypointAsset>
480
+ assets: Array<JsStatsChunkGroupAsset>
430
481
  chunks: Array<string>
431
482
  assetsSize: number
432
483
  }
433
- export interface JsStatsCompilation {
484
+ export interface JsStatsAssetsByChunkName {
485
+ name: string
486
+ files: Array<string>
487
+ }
488
+ export interface JsStatsGetAssets {
434
489
  assets: Array<JsStatsAsset>
435
- modules: Array<JsStatsModule>
436
- chunks: Array<JsStatsChunk>
437
- entrypoints: Array<JsStatsEntrypoint>
438
- errors: Array<JsStatsError>
439
- errorsCount: number
440
- warnings: Array<JsStatsWarning>
441
- warningsCount: number
442
- hash: string
490
+ assetsByChunkName: Array<JsStatsAssetsByChunkName>
443
491
  }
444
492
  export function initCustomTraceSubscriber(): void
445
493
  export class JsCompilation {
@@ -447,6 +495,12 @@ export class JsCompilation {
447
495
  getAssets(): Readonly<JsAsset>[]
448
496
  getAsset(name: string): JsAsset | null
449
497
  getAssetSource(name: string): JsCompatSource | null
498
+ getModules(): Array<JsModule>
499
+ /**
500
+ * Only available for those none Js and Css source,
501
+ * return true if set module source successfully, false if failed.
502
+ */
503
+ setNoneAstModuleSource(moduleIdentifier: string, source: JsCompatSource): boolean
450
504
  setAssetSource(name: string, source: JsCompatSource): void
451
505
  deleteAssetSource(name: string): void
452
506
  getAssetFilenames(): Array<string>
@@ -467,16 +521,18 @@ export class JsCompilation {
467
521
  addBuildDependencies(deps: Array<string>): void
468
522
  }
469
523
  export class JsStats {
470
- getAssets(): Array<JsStatsAsset>
524
+ getAssets(): JsStatsGetAssets
471
525
  getModules(showReasons: boolean): Array<JsStatsModule>
472
526
  getChunks(): Array<JsStatsChunk>
473
- getEntrypoints(): Array<JsStatsEntrypoint>
527
+ getEntrypoints(): Array<JsStatsChunkGroup>
528
+ getNamedChunkGroups(): Array<JsStatsChunkGroup>
474
529
  getErrors(): Array<JsStatsError>
475
530
  getWarnings(): Array<JsStatsWarning>
476
531
  getHash(): string
477
532
  }
478
533
  export class Rspack {
479
- constructor(options: RawOptions, jsHooks?: JsHooks | undefined | null)
534
+ constructor(options: RawOptions, jsHooks: JsHooks | undefined | null, outputFilesystem: ThreadsafeNodeFS)
535
+ unsafe_set_disabled_hooks(hooks: Array<string>): void
480
536
  /**
481
537
  * Build with the given option passed to the constructor
482
538
  *
package/binding.js CHANGED
@@ -11,7 +11,8 @@ function isMusl() {
11
11
  // For Node 10
12
12
  if (!process.report || typeof process.report.getReport !== 'function') {
13
13
  try {
14
- return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
14
+ const lddPath = require('child_process').execSync('which ldd').toString().trim();
15
+ return readFileSync(lddPath, 'utf8').includes('musl')
15
16
  } catch (e) {
16
17
  return true
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@rspack/binding",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
+ "license": "MIT",
4
5
  "description": "Node binding for rspack",
5
6
  "main": "binding.js",
6
7
  "types": "binding.d.ts",
@@ -11,19 +12,19 @@
11
12
  "binding.js",
12
13
  "binding.d.ts"
13
14
  ],
14
- "keywords": [],
15
- "author": "",
16
- "license": "MIT",
15
+ "homepage": "https://rspack.org",
16
+ "bugs": "https://github.com/modern-js-dev/rspack/issues",
17
+ "repository": "modern-js-dev/rspack",
17
18
  "devDependencies": {
18
19
  "@napi-rs/cli": "2.14.2",
19
20
  "why-is-node-running": "2.2.1",
20
21
  "npm-run-all": "4.1.5"
21
22
  },
22
23
  "optionalDependencies": {
23
- "@rspack/binding-darwin-x64": "0.0.22",
24
- "@rspack/binding-darwin-arm64": "0.0.22",
25
- "@rspack/binding-win32-x64-msvc": "0.0.22",
26
- "@rspack/binding-linux-x64-gnu": "0.0.22"
24
+ "@rspack/binding-darwin-arm64": "0.0.24",
25
+ "@rspack/binding-darwin-x64": "0.0.24",
26
+ "@rspack/binding-win32-x64-msvc": "0.0.24",
27
+ "@rspack/binding-linux-x64-gnu": "0.0.24"
27
28
  },
28
29
  "scripts": {
29
30
  "build:debug": "napi build --platform --js false --dts binding.d.ts --config napirs.rc.json",