@rspack/binding 0.0.0-02df4322c5-20221125030212

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/binding.d.ts ADDED
@@ -0,0 +1,360 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ 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
+ }
19
+ export interface RawDecoratorOptions {
20
+ legacy: boolean
21
+ emitMetadata: boolean
22
+ useDefineForClassFields: boolean
23
+ }
24
+ /**
25
+ * It seems napi not support enum well
26
+ */
27
+ export interface RawHtmlPluginConfig {
28
+ /** emitted file name in output path */
29
+ filename?: string | void
30
+ /** template html file */
31
+ template?: string
32
+ templateParameters?: Record<string, string>
33
+ /** `head`, `body` or None */
34
+ inject?: string | void
35
+ /** path or `auto` */
36
+ publicPath?: string
37
+ /** `blocking`, `defer`, or `module` */
38
+ scriptLoading?: string | void
39
+ /** entry_chunk_name (only entry chunks are supported) */
40
+ chunks?: Array<string>
41
+ excludedChunks?: Array<string>
42
+ sri?: string | void
43
+ minify?: boolean
44
+ title?: string
45
+ favicon?: string
46
+ meta?: Record<string, Record<string, string>>
47
+ }
48
+ export interface RawPostCssConfig {
49
+ pxtorem?: RawPxToRemConfig
50
+ }
51
+ export interface RawPxToRemConfig {
52
+ rootValue?: number
53
+ unitPrecision?: number
54
+ selectorBlackList?: Array<string>
55
+ propList?: Array<string>
56
+ replace?: boolean
57
+ mediaQuery?: boolean
58
+ minPixelValue?: number
59
+ }
60
+ export interface RawProgressPluginConfig {
61
+ prefix?: string
62
+ }
63
+ export interface RawReactOptions {
64
+ runtime?: string
65
+ importSource?: string
66
+ pragma?: string
67
+ pragmaFrag?: string
68
+ throwIfNamespace?: boolean
69
+ development?: boolean
70
+ useBuiltins?: boolean
71
+ useSpread?: boolean
72
+ refresh?: boolean
73
+ }
74
+ export interface RawBuiltins {
75
+ html?: Array<RawHtmlPluginConfig>
76
+ css?: RawCssPluginConfig
77
+ postcss?: RawPostCssConfig
78
+ minify?: boolean
79
+ polyfill?: boolean
80
+ browserslist?: Array<string>
81
+ define?: Record<string, string>
82
+ treeShaking?: boolean
83
+ progress?: RawProgressPluginConfig
84
+ react?: RawReactOptions
85
+ decorator?: RawDecoratorOptions
86
+ }
87
+ export interface RawDevServer {
88
+ hot?: boolean
89
+ }
90
+ /**
91
+ * `loader` is for js side loader, `builtin_loader` is for rust side loader,
92
+ * which is mapped to real rust side loader by [get_builtin_loader].
93
+ *
94
+ * `options` is
95
+ * - a `None` on rust side and handled by js side `getOptions` when
96
+ * using with `loader`.
97
+ * - a `Some(string)` on rust side, deserialized by `serde_json::from_str`
98
+ * and passed to rust side loader in [get_builtin_loader] when using with
99
+ * `builtin_loader`.
100
+ */
101
+ export interface RawModuleRuleUse {
102
+ loader?: (...args: any[]) => any
103
+ builtinLoader?: string
104
+ options?: string
105
+ loaderName?: string
106
+ }
107
+ export interface RawModuleRuleCondition {
108
+ /** Condition can be either a `string` or `Regexp`. */
109
+ type: "string" | "regexp"
110
+ /**
111
+ * Based on the condition type, the value can be either a `string` or `Regexp`.
112
+ * - "string": The value will be matched against the string.
113
+ * - "regexp": The value will be matched against the raw regexp source from JS side.
114
+ */
115
+ matcher?: string
116
+ }
117
+ export interface RawModuleRule {
118
+ /**
119
+ * A condition matcher matching an absolute path.
120
+ * - String: To match the input must start with the provided string. I. e. an absolute directory path, or absolute path to the file.
121
+ * - Regexp: It's tested with the input.
122
+ */
123
+ test?: RawModuleRuleCondition
124
+ /**
125
+ * A condition matcher matching an absolute path.
126
+ * See `test` above
127
+ */
128
+ resource?: RawModuleRuleCondition
129
+ /**
130
+ * A condition matcher against the resource query.
131
+ * TODO: align with webpack's `?` prefixed `resourceQuery`
132
+ */
133
+ resourceQuery?: RawModuleRuleCondition
134
+ func?: (...args: any[]) => any
135
+ use?: Array<RawModuleRuleUse>
136
+ type?: "js" | "jsx" | "ts" | "tsx" | "css" | "json" | "asset" | "asset/resource" | "asset/source" | "asset/inline"
137
+ }
138
+ export interface RawAssetParserDataUrlOption {
139
+ maxSize?: number
140
+ }
141
+ export interface RawAssetParserOptions {
142
+ dataUrlCondition?: RawAssetParserDataUrlOption
143
+ }
144
+ export interface RawParserOptions {
145
+ asset?: RawAssetParserOptions
146
+ }
147
+ export interface RawModuleOptions {
148
+ rules: Array<RawModuleRule>
149
+ parser?: RawParserOptions
150
+ }
151
+ export interface RawOptimizationOptions {
152
+ splitChunks?: RawSplitChunksOptions
153
+ }
154
+ export interface RawOutputOptions {
155
+ path?: string
156
+ publicPath?: string
157
+ assetModuleFilename?: string
158
+ filename?: string
159
+ chunkFilename?: string
160
+ cssFilename?: string
161
+ cssChunkFilename?: string
162
+ uniqueName?: string
163
+ }
164
+ export interface RawResolveOptions {
165
+ preferRelative?: boolean
166
+ extensions?: Array<string>
167
+ mainFiles?: Array<string>
168
+ mainFields?: Array<string>
169
+ browserField?: boolean
170
+ conditionNames?: Array<string>
171
+ alias?: Record<string, string | false>
172
+ symlinks?: boolean
173
+ tsconfig?: string
174
+ }
175
+ export interface RawSplitChunksOptions {
176
+ cacheGroups?: Record<string, RawCacheGroupOptions>
177
+ /** What kind of chunks should be selected. */
178
+ chunks?: string
179
+ }
180
+ export interface RawCacheGroupOptions {
181
+ test: string
182
+ /** What kind of chunks should be selected. */
183
+ chunks?: string
184
+ name: string
185
+ }
186
+ export interface RawStatsOptions {
187
+ colors: boolean
188
+ }
189
+ export interface RawOptions {
190
+ entry?: Record<string, string>
191
+ mode?: string
192
+ target?: string[]
193
+ context?: string
194
+ output?: RawOutputOptions
195
+ resolve?: RawResolveOptions
196
+ module?: RawModuleOptions
197
+ builtins?: RawBuiltins
198
+ externals?: Record<string, string>
199
+ externalsType?: string
200
+ devtool?: string
201
+ optimization?: RawOptimizationOptions
202
+ stats?: RawStatsOptions
203
+ devServer?: RawDevServer
204
+ }
205
+ export interface JsAssetInfoRelated {
206
+ sourceMap?: string
207
+ }
208
+ export interface JsAssetInfo {
209
+ /**
210
+ * if the asset can be long term cached forever (contains a hash)
211
+ * whether the asset is minimized
212
+ */
213
+ minimized: boolean
214
+ /**
215
+ * the value(s) of the full hash used for this asset
216
+ * the value(s) of the chunk hash used for this asset
217
+ * the value(s) of the module hash used for this asset
218
+ * the value(s) of the content hash used for this asset
219
+ * when asset was created from a source file (potentially transformed), the original filename relative to compilation context
220
+ * size in bytes, only set after asset has been emitted
221
+ * when asset is only used for development and doesn't count towards user-facing assets
222
+ */
223
+ development: boolean
224
+ /** when asset ships data for updating an existing application (HMR) */
225
+ hotModuleReplacement: boolean
226
+ /**
227
+ * when asset is javascript and an ESM
228
+ * related object to other assets, keyed by type of relation (only points from parent to child)
229
+ */
230
+ related: JsAssetInfoRelated
231
+ }
232
+ export interface JsAsset {
233
+ name: string
234
+ source: JsCompatSource
235
+ info: JsAssetInfo
236
+ }
237
+ export interface JsChunk {
238
+ files: Array<string>
239
+ }
240
+ export interface JsChunkGroup {
241
+ chunks: Array<JsChunk>
242
+ }
243
+ export interface JsHooks {
244
+ done: (...args: any[]) => any
245
+ processAssets: (...args: any[]) => any
246
+ compilation: (...args: any[]) => any
247
+ thisCompilation: (...args: any[]) => any
248
+ }
249
+ export interface JsCompatSource {
250
+ /** Whether the underlying data structure is a `RawSource` */
251
+ isRaw: boolean
252
+ /** Whether the underlying value is a buffer or string */
253
+ isBuffer: boolean
254
+ source: Buffer
255
+ map?: Buffer
256
+ }
257
+ export interface JsStatsError {
258
+ message: string
259
+ formatted: string
260
+ }
261
+ export interface JsStatsWarning {
262
+ message: string
263
+ formatted: string
264
+ }
265
+ export interface JsStatsAsset {
266
+ type: string
267
+ name: string
268
+ size: number
269
+ chunks: Array<string>
270
+ chunkNames: Array<string>
271
+ info: JsStatsAssetInfo
272
+ emitted: boolean
273
+ }
274
+ export interface JsStatsAssetInfo {
275
+ development: boolean
276
+ hotModuleReplacement: boolean
277
+ }
278
+ export interface JsStatsModule {
279
+ type: string
280
+ moduleType: string
281
+ identifier: string
282
+ name: string
283
+ id: string
284
+ chunks: Array<string>
285
+ size: number
286
+ }
287
+ export interface JsStatsChunk {
288
+ type: string
289
+ files: Array<string>
290
+ id: string
291
+ entry: boolean
292
+ initial: boolean
293
+ names: Array<string>
294
+ size: number
295
+ }
296
+ export interface JsStatsEntrypointAsset {
297
+ name: string
298
+ size: number
299
+ }
300
+ export interface JsStatsEntrypoint {
301
+ name: string
302
+ assets: Array<JsStatsEntrypointAsset>
303
+ chunks: Array<string>
304
+ assetsSize: number
305
+ }
306
+ export interface JsStatsCompilation {
307
+ assets: Array<JsStatsAsset>
308
+ modules: Array<JsStatsModule>
309
+ chunks: Array<JsStatsChunk>
310
+ entrypoints: Array<JsStatsEntrypoint>
311
+ errors: Array<JsStatsError>
312
+ errorsCount: number
313
+ warnings: Array<JsStatsWarning>
314
+ warningsCount: number
315
+ }
316
+ export function initCustomTraceSubscriber(): void
317
+ export class JsCompilation {
318
+ updateAsset(filename: string, newSourceOrFunction: JsCompatSource | ((source: JsCompatSource) => JsCompatSource), assetInfoUpdateOrFunction?: JsAssetInfo | ((assetInfo: JsAssetInfo) => JsAssetInfo)): void
319
+ getAssets(): Readonly<JsAsset>[]
320
+ getAsset(name: string): JsAsset | null
321
+ emitAsset(filename: string, source: JsCompatSource, assetInfo: JsAssetInfo): void
322
+ deleteAsset(filename: string): void
323
+ get assets(): Record<string, JsCompatSource>
324
+ get entrypoints(): Record<string, JsChunkGroup>
325
+ }
326
+ export class Rspack {
327
+ constructor(options: RawOptions, jsHooks?: JsHooks | undefined | null)
328
+ /**
329
+ * Build with the given option passed to the constructor
330
+ *
331
+ * Warning:
332
+ * Calling this method recursively might cause a deadlock.
333
+ */
334
+ unsafe_build(callback: (err: null | Error, result: JsStatsCompilation) => void): void
335
+ /**
336
+ * Rebuild with the given option passed to the constructor
337
+ *
338
+ * Warning:
339
+ * Calling this method recursively will cause a deadlock.
340
+ */
341
+ unsafe_rebuild(callback: (err: null | Error, result: Record<string, {content: string, kind: number}>) => void): void
342
+ /**
343
+ * Get the last compilation
344
+ *
345
+ * Warning:
346
+ *
347
+ * Calling this method under the build or rebuild method might cause a deadlock.
348
+ *
349
+ * **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.
350
+ */
351
+ unsafe_last_compilation(f: (arg0: JsCompilation) => void): void
352
+ /**
353
+ * Destroy the compiler
354
+ *
355
+ * Warning:
356
+ *
357
+ * Anything related to this compiler will be invalidated after this method is called.
358
+ */
359
+ unsafe_drop(): void
360
+ }
package/binding.js ADDED
@@ -0,0 +1,221 @@
1
+ const { existsSync, readFileSync } = require('fs')
2
+ const { join } = require('path')
3
+
4
+ const { platform, arch } = process
5
+
6
+ let nativeBinding = null
7
+ let localFileExisted = false
8
+ let loadError = null
9
+
10
+ function isMusl() {
11
+ // For Node 10
12
+ if (!process.report || typeof process.report.getReport !== 'function') {
13
+ try {
14
+ return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
15
+ } catch (e) {
16
+ return true
17
+ }
18
+ } else {
19
+ const { glibcVersionRuntime } = process.report.getReport().header
20
+ return !glibcVersionRuntime
21
+ }
22
+ }
23
+
24
+ switch (platform) {
25
+ case 'android':
26
+ switch (arch) {
27
+ case 'arm64':
28
+ localFileExisted = existsSync(join(__dirname, 'rspack.android-arm64.node'))
29
+ try {
30
+ if (localFileExisted) {
31
+ nativeBinding = require('./rspack.android-arm64.node')
32
+ } else {
33
+ nativeBinding = require('@rspack/binding-android-arm64')
34
+ }
35
+ } catch (e) {
36
+ loadError = e
37
+ }
38
+ break
39
+ case 'arm':
40
+ localFileExisted = existsSync(join(__dirname, 'rspack.android-arm-eabi.node'))
41
+ try {
42
+ if (localFileExisted) {
43
+ nativeBinding = require('./rspack.android-arm-eabi.node')
44
+ } else {
45
+ nativeBinding = require('@rspack/binding-android-arm-eabi')
46
+ }
47
+ } catch (e) {
48
+ loadError = e
49
+ }
50
+ break
51
+ default:
52
+ throw new Error(`Unsupported architecture on Android ${arch}`)
53
+ }
54
+ break
55
+ case 'win32':
56
+ switch (arch) {
57
+ case 'x64':
58
+ localFileExisted = existsSync(join(__dirname, 'rspack.win32-x64-msvc.node'))
59
+ try {
60
+ if (localFileExisted) {
61
+ nativeBinding = require('./rspack.win32-x64-msvc.node')
62
+ } else {
63
+ nativeBinding = require('@rspack/binding-win32-x64-msvc')
64
+ }
65
+ } catch (e) {
66
+ loadError = e
67
+ }
68
+ break
69
+ case 'ia32':
70
+ localFileExisted = existsSync(join(__dirname, 'rspack.win32-ia32-msvc.node'))
71
+ try {
72
+ if (localFileExisted) {
73
+ nativeBinding = require('./rspack.win32-ia32-msvc.node')
74
+ } else {
75
+ nativeBinding = require('@rspack/binding-win32-ia32-msvc')
76
+ }
77
+ } catch (e) {
78
+ loadError = e
79
+ }
80
+ break
81
+ case 'arm64':
82
+ localFileExisted = existsSync(join(__dirname, 'rspack.win32-arm64-msvc.node'))
83
+ try {
84
+ if (localFileExisted) {
85
+ nativeBinding = require('./rspack.win32-arm64-msvc.node')
86
+ } else {
87
+ nativeBinding = require('@rspack/binding-win32-arm64-msvc')
88
+ }
89
+ } catch (e) {
90
+ loadError = e
91
+ }
92
+ break
93
+ default:
94
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
95
+ }
96
+ break
97
+ case 'darwin':
98
+ switch (arch) {
99
+ case 'x64':
100
+ localFileExisted = existsSync(join(__dirname, 'rspack.darwin-x64.node'))
101
+ try {
102
+ if (localFileExisted) {
103
+ nativeBinding = require('./rspack.darwin-x64.node')
104
+ } else {
105
+ nativeBinding = require('@rspack/binding-darwin-x64')
106
+ }
107
+ } catch (e) {
108
+ loadError = e
109
+ }
110
+ break
111
+ case 'arm64':
112
+ localFileExisted = existsSync(join(__dirname, 'rspack.darwin-arm64.node'))
113
+ try {
114
+ if (localFileExisted) {
115
+ nativeBinding = require('./rspack.darwin-arm64.node')
116
+ } else {
117
+ nativeBinding = require('@rspack/binding-darwin-arm64')
118
+ }
119
+ } catch (e) {
120
+ loadError = e
121
+ }
122
+ break
123
+ default:
124
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
125
+ }
126
+ break
127
+ case 'freebsd':
128
+ if (arch !== 'x64') {
129
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
130
+ }
131
+ localFileExisted = existsSync(join(__dirname, 'rspack.freebsd-x64.node'))
132
+ try {
133
+ if (localFileExisted) {
134
+ nativeBinding = require('./rspack.freebsd-x64.node')
135
+ } else {
136
+ nativeBinding = require('@rspack/binding-freebsd-x64')
137
+ }
138
+ } catch (e) {
139
+ loadError = e
140
+ }
141
+ break
142
+ case 'linux':
143
+ switch (arch) {
144
+ case 'x64':
145
+ if (isMusl()) {
146
+ localFileExisted = existsSync(join(__dirname, 'rspack.linux-x64-musl.node'))
147
+ try {
148
+ if (localFileExisted) {
149
+ nativeBinding = require('./rspack.linux-x64-musl.node')
150
+ } else {
151
+ nativeBinding = require('@rspack/binding-linux-x64-musl')
152
+ }
153
+ } catch (e) {
154
+ loadError = e
155
+ }
156
+ } else {
157
+ localFileExisted = existsSync(join(__dirname, 'rspack.linux-x64-gnu.node'))
158
+ try {
159
+ if (localFileExisted) {
160
+ nativeBinding = require('./rspack.linux-x64-gnu.node')
161
+ } else {
162
+ nativeBinding = require('@rspack/binding-linux-x64-gnu')
163
+ }
164
+ } catch (e) {
165
+ loadError = e
166
+ }
167
+ }
168
+ break
169
+ case 'arm64':
170
+ if (isMusl()) {
171
+ localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm64-musl.node'))
172
+ try {
173
+ if (localFileExisted) {
174
+ nativeBinding = require('./rspack.linux-arm64-musl.node')
175
+ } else {
176
+ nativeBinding = require('@rspack/binding-linux-arm64-musl')
177
+ }
178
+ } catch (e) {
179
+ loadError = e
180
+ }
181
+ } else {
182
+ localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm64-gnu.node'))
183
+ try {
184
+ if (localFileExisted) {
185
+ nativeBinding = require('./rspack.linux-arm64-gnu.node')
186
+ } else {
187
+ nativeBinding = require('@rspack/binding-linux-arm64-gnu')
188
+ }
189
+ } catch (e) {
190
+ loadError = e
191
+ }
192
+ }
193
+ break
194
+ case 'arm':
195
+ localFileExisted = existsSync(join(__dirname, 'rspack.linux-arm-gnueabihf.node'))
196
+ try {
197
+ if (localFileExisted) {
198
+ nativeBinding = require('./rspack.linux-arm-gnueabihf.node')
199
+ } else {
200
+ nativeBinding = require('@rspack/binding-linux-arm-gnueabihf')
201
+ }
202
+ } catch (e) {
203
+ loadError = e
204
+ }
205
+ break
206
+ default:
207
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
208
+ }
209
+ break
210
+ default:
211
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
212
+ }
213
+
214
+ if (!nativeBinding) {
215
+ if (loadError) {
216
+ throw loadError
217
+ }
218
+ throw new Error(`Failed to load native binding`)
219
+ }
220
+
221
+ module.exports.default = module.exports = nativeBinding
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@rspack/binding",
3
+ "version": "0.0.0-02df4322c5-20221125030212",
4
+ "description": "Node binding for rspack",
5
+ "main": "binding.js",
6
+ "types": "binding.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "files": [
11
+ "binding.js",
12
+ "binding.d.ts",
13
+ "*.node"
14
+ ],
15
+ "keywords": [],
16
+ "author": "",
17
+ "license": "ISC",
18
+ "devDependencies": {
19
+ "@napi-rs/cli": "^2.6.2",
20
+ "why-is-node-running": "2.2.1"
21
+ },
22
+ "scripts": {
23
+ "build": "napi build --platform --js false --dts binding.d.ts --config napirs.rc.json",
24
+ "build:release:all": "pnpm build:release && pnpm build:release:x64 && pnpm build:release:linux",
25
+ "build:release": "napi build --release --platform --js false --dts binding.d.ts --config napirs.rc.json",
26
+ "build:release:x64": "napi build --release --platform --js false --dts binding.d.ts --config napirs.rc.json --target x86_64-apple-darwin",
27
+ "build:release:linux": "napi build --release --platform --js false --dts binding.d.ts --config napirs.rc.json --zig --target x86_64-unknown-linux-gnu --zig-abi-suffix=2.17"
28
+ }
29
+ }
Binary file