@rspack/binding 0.0.0-1bce45e7c0-20221109113710

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,326 @@
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
+ /**
20
+ * It seems napi not support enum well
21
+ */
22
+ export interface RawHtmlPluginConfig {
23
+ /** emitted file name in output path */
24
+ filename?: string | void
25
+ /** template html file */
26
+ template?: string
27
+ templateParameters?: Record<string, string>
28
+ /** `head`, `body` or None */
29
+ inject?: string | void
30
+ /** path or `auto` */
31
+ publicPath?: string
32
+ /** `blocking`, `defer`, or `module` */
33
+ scriptLoading?: string | void
34
+ /** entry_chunk_name (only entry chunks are supported) */
35
+ chunks?: Array<string>
36
+ excludedChunks?: Array<string>
37
+ sri?: string | void
38
+ minify?: boolean
39
+ title?: string
40
+ favicon?: string
41
+ meta?: Record<string, Record<string, string>>
42
+ }
43
+ export interface RawPostCssConfig {
44
+ pxtorem?: RawPxToRemConfig
45
+ }
46
+ export interface RawPxToRemConfig {
47
+ rootValue?: number
48
+ unitPrecision?: number
49
+ selectorBlackList?: Array<string>
50
+ propList?: Array<string>
51
+ replace?: boolean
52
+ mediaQuery?: boolean
53
+ minPixelValue?: number
54
+ }
55
+ export interface RawProgressPluginConfig {
56
+ prefix?: string
57
+ }
58
+ export interface RawReactOptions {
59
+ runtime?: string
60
+ importSource?: string
61
+ pragma?: string
62
+ pragmaFrag?: string
63
+ throwIfNamespace?: boolean
64
+ development?: boolean
65
+ useBuiltins?: boolean
66
+ useSpread?: boolean
67
+ refresh?: boolean
68
+ }
69
+ export interface RawBuiltins {
70
+ html?: Array<RawHtmlPluginConfig>
71
+ css?: RawCssPluginConfig
72
+ postcss?: RawPostCssConfig
73
+ minify?: boolean
74
+ polyfill?: boolean
75
+ browserslist?: Array<string>
76
+ define?: Record<string, string>
77
+ treeShaking?: boolean
78
+ progress?: RawProgressPluginConfig
79
+ react?: RawReactOptions
80
+ }
81
+ /**
82
+ * `loader` is for js side loader, `builtin_loader` is for rust side loader,
83
+ * which is mapped to real rust side loader by [get_builtin_loader].
84
+ *
85
+ * `options` is
86
+ * - a `None` on rust side and handled by js side `getOptions` when
87
+ * using with `loader`.
88
+ * - a `Some(string)` on rust side, deserialized by `serde_json::from_str`
89
+ * and passed to rust side loader in [get_builtin_loader] when using with
90
+ * `builtin_loader`.
91
+ */
92
+ export interface RawModuleRuleUse {
93
+ loader?: (...args: any[]) => any
94
+ builtinLoader?: string
95
+ options?: string
96
+ loaderName?: string
97
+ }
98
+ export interface RawModuleRule {
99
+ test?: string
100
+ resource?: string
101
+ resourceQuery?: string
102
+ func?: (...args: any[]) => any
103
+ uses?: Array<RawModuleRuleUse>
104
+ type?: "js" | "jsx" | "ts" | "tsx" | "css" | "json" | "asset" | "asset/resource" | "asset/source" | "asset/inline"
105
+ }
106
+ export interface RawAssetParserDataUrlOption {
107
+ maxSize?: number
108
+ }
109
+ export interface RawAssetParserOptions {
110
+ dataUrlCondition?: RawAssetParserDataUrlOption
111
+ }
112
+ export interface RawParserOptions {
113
+ asset?: RawAssetParserOptions
114
+ }
115
+ export interface RawModuleOptions {
116
+ rules: Array<RawModuleRule>
117
+ parser?: RawParserOptions
118
+ }
119
+ export interface RawOptimizationOptions {
120
+ splitChunks?: RawSplitChunksOptions
121
+ }
122
+ export interface RawOutputOptions {
123
+ path?: string
124
+ publicPath?: string
125
+ assetModuleFilename?: string
126
+ filename?: string
127
+ chunkFilename?: string
128
+ uniqueName?: string
129
+ }
130
+ export interface RawResolveOptions {
131
+ preferRelative?: boolean
132
+ extensions?: Array<string>
133
+ mainFiles?: Array<string>
134
+ mainFields?: Array<string>
135
+ browserField?: boolean
136
+ conditionNames?: Array<string>
137
+ alias?: Record<string, string | false>
138
+ symlinks?: boolean
139
+ tsconfig?: string
140
+ }
141
+ export interface RawSplitChunksOptions {
142
+ cacheGroups: Record<string, RawCacheGroupOptions>
143
+ /** What kind of chunks should be selected. */
144
+ chunks?: string
145
+ }
146
+ export interface RawCacheGroupOptions {
147
+ test: string
148
+ /** What kind of chunks should be selected. */
149
+ chunks?: string
150
+ name: string
151
+ }
152
+ export interface RawStatsOptions {
153
+ colors: boolean
154
+ }
155
+ export interface RawOptions {
156
+ entry?: Record<string, string>
157
+ mode?: string
158
+ target?: string[]
159
+ context?: string
160
+ output?: RawOutputOptions
161
+ resolve?: RawResolveOptions
162
+ module?: RawModuleOptions
163
+ builtins?: RawBuiltins
164
+ externals?: Record<string, string>
165
+ externalsType?: string
166
+ devtool?: string
167
+ optimization?: RawOptimizationOptions
168
+ stats?: RawStatsOptions
169
+ }
170
+ export interface AssetContent {
171
+ buffer?: Buffer
172
+ source?: string
173
+ }
174
+ export interface UpdateAssetOptions {
175
+ asset: AssetContent
176
+ filename: string
177
+ }
178
+ export interface AssetInfoRelated {
179
+ sourceMap?: string
180
+ }
181
+ export interface AssetInfo {
182
+ /**
183
+ * if the asset can be long term cached forever (contains a hash)
184
+ * whether the asset is minimized
185
+ */
186
+ minimized: boolean
187
+ /**
188
+ * the value(s) of the full hash used for this asset
189
+ * the value(s) of the chunk hash used for this asset
190
+ * the value(s) of the module hash used for this asset
191
+ * the value(s) of the content hash used for this asset
192
+ * when asset was created from a source file (potentially transformed), the original filename relative to compilation context
193
+ * size in bytes, only set after asset has been emitted
194
+ * when asset is only used for development and doesn't count towards user-facing assets
195
+ */
196
+ development: boolean
197
+ /**
198
+ * when asset ships data for updating an existing application (HMR)
199
+ * when asset is javascript and an ESM
200
+ * related object to other assets, keyed by type of relation (only points from parent to child)
201
+ */
202
+ related: AssetInfoRelated
203
+ }
204
+ export interface Asset {
205
+ name: string
206
+ source: JsCompatSource
207
+ info: AssetInfo
208
+ }
209
+ export interface PluginCallbacks {
210
+ doneCallback: (...args: any[]) => any
211
+ processAssetsCallback: (...args: any[]) => any
212
+ compilationCallback: (...args: any[]) => any
213
+ thisCompilationCallback: (...args: any[]) => any
214
+ }
215
+ export interface JsCompatSource {
216
+ /** Whether the underlying data structure is a `RawSource` */
217
+ isRaw: boolean
218
+ /** Whether the underlying value is a buffer or string */
219
+ isBuffer: boolean
220
+ source: Buffer
221
+ map?: Buffer
222
+ }
223
+ export const enum DiffStatKind {
224
+ Changed = 0,
225
+ Deleted = 1,
226
+ Added = 2
227
+ }
228
+ export interface DiffStat {
229
+ content: string
230
+ kind: DiffStatKind
231
+ }
232
+ export interface RebuildResult {
233
+ diff: Record<string, DiffStat>
234
+ stats: StatsCompilation
235
+ }
236
+ export interface StatsError {
237
+ message: string
238
+ formatted: string
239
+ }
240
+ export interface StatsWarning {
241
+ message: string
242
+ formatted: string
243
+ }
244
+ export interface StatsAsset {
245
+ type: string
246
+ name: string
247
+ size: number
248
+ chunks: Array<string>
249
+ chunkNames: Array<string>
250
+ info: StatsAssetInfo
251
+ }
252
+ export interface StatsAssetInfo {
253
+ development: boolean
254
+ }
255
+ export interface StatsModule {
256
+ type: string
257
+ moduleType: string
258
+ identifier: string
259
+ name: string
260
+ id: string
261
+ chunks: Array<string>
262
+ size: number
263
+ }
264
+ export interface StatsChunk {
265
+ type: string
266
+ files: Array<string>
267
+ id: string
268
+ entry: boolean
269
+ initial: boolean
270
+ names: Array<string>
271
+ size: number
272
+ }
273
+ export interface StatsCompilation {
274
+ assets: Array<StatsAsset>
275
+ modules: Array<StatsModule>
276
+ chunks: Array<StatsChunk>
277
+ errors: Array<StatsError>
278
+ errorsCount: number
279
+ warnings: Array<StatsWarning>
280
+ warningsCount: number
281
+ }
282
+ export interface OnLoadContext {
283
+ id: string
284
+ }
285
+ export function initCustomTraceSubscriber(): void
286
+ export class JsCompilation {
287
+ updateAsset(filename: string, newSourceOrFunction: JsCompatSource | ((source: JsCompatSource) => JsCompatSource), assetInfoUpdateOrFunction?: AssetInfo | ((assetInfo: AssetInfo) => AssetInfo)): void
288
+ getAssets(): Readonly<Asset>[]
289
+ emitAsset(filename: string, source: JsCompatSource, assetInfo: AssetInfo): void
290
+ get assets(): Record<string, JsCompatSource>
291
+ }
292
+ export class Rspack {
293
+ constructor(options: RawOptions, pluginCallbacks?: PluginCallbacks | undefined | null)
294
+ /**
295
+ * Build with the given option passed to the constructor
296
+ *
297
+ * Warning:
298
+ * Calling this method recursively might cause a deadlock.
299
+ */
300
+ unsafe_build(callback: (err: null | Error, result: StatsCompilation) => void): void
301
+ /**
302
+ * Rebuild with the given option passed to the constructor
303
+ *
304
+ * Warning:
305
+ * Calling this method recursively will cause a deadlock.
306
+ */
307
+ unsafe_rebuild(callback: (err: null | Error, result: Record<string, {content: string, kind: number}>) => void): void
308
+ /**
309
+ * Get the last compilation
310
+ *
311
+ * Warning:
312
+ *
313
+ * Calling this method under the build or rebuild method might cause a deadlock.
314
+ *
315
+ * **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.
316
+ */
317
+ unsafe_last_compilation(f: (arg0: JsCompilation) => void): void
318
+ /**
319
+ * Destroy the compiler
320
+ *
321
+ * Warning:
322
+ *
323
+ * Anything related to this compiler will be invalidated after this method is called.
324
+ */
325
+ unsafe_drop(): void
326
+ }
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,26 @@
1
+ {
2
+ "name": "@rspack/binding",
3
+ "version": "0.0.0-1bce45e7c0-20221109113710",
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": "napi build --release --platform --js false --dts binding.d.ts --config napirs.rc.json"
25
+ }
26
+ }
Binary file