jsshaker 0.0.0
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/browser.js +1 -0
- package/cli.js +51 -0
- package/index.d.ts +22 -0
- package/index.js +512 -0
- package/package.json +54 -0
package/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@jsshaker/binding-wasm32-wasi'
|
package/cli.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { parseArgs } = require("node:util");
|
|
4
|
+
const { shakeSingleModule } = require("./index.js");
|
|
5
|
+
const { writeFile, mkdir } = require("node:fs/promises");
|
|
6
|
+
const { join, dirname } = require("node:path");
|
|
7
|
+
|
|
8
|
+
const { values, positionals } = parseArgs({
|
|
9
|
+
options: {
|
|
10
|
+
preset: {
|
|
11
|
+
type: "string",
|
|
12
|
+
short: "p",
|
|
13
|
+
},
|
|
14
|
+
minify: {
|
|
15
|
+
type: "boolean",
|
|
16
|
+
short: "m",
|
|
17
|
+
},
|
|
18
|
+
outdir: {
|
|
19
|
+
type: "string",
|
|
20
|
+
short: "o",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
allowPositionals: true,
|
|
24
|
+
strict: false,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (positionals.length !== 1) {
|
|
28
|
+
throw new Error("Must provide exactly one entry js file path.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const result = shakeSingleModule(
|
|
32
|
+
positionals[0],
|
|
33
|
+
{
|
|
34
|
+
preset: values.preset,
|
|
35
|
+
minify: values.minify,
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
for (const message of result.diagnostics) {
|
|
40
|
+
console.warn(message);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (let [path, content] of Object.entries(result.output)) {
|
|
44
|
+
if (values.outdir) {
|
|
45
|
+
path = join(values.outdir, path);
|
|
46
|
+
}
|
|
47
|
+
const dir = dirname(path);
|
|
48
|
+
mkdir(dir, { recursive: true });
|
|
49
|
+
console.log(path);
|
|
50
|
+
writeFile(path, content);
|
|
51
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export interface MultiModuleResult {
|
|
4
|
+
output: Record<string, string>
|
|
5
|
+
diagnostics: Array<string>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface Options {
|
|
9
|
+
preset?: 'safest' | 'recommended' | 'smallest' | 'disabled'
|
|
10
|
+
minify?: boolean
|
|
11
|
+
alwaysInlineLiteral?: boolean
|
|
12
|
+
jsx?: 'react'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export declare function shakeMultiModule(entryPath: string, options: Options): MultiModuleResult
|
|
16
|
+
|
|
17
|
+
export declare function shakeSingleModule(sourceText: string, options: Options): SingleModuleResult
|
|
18
|
+
|
|
19
|
+
export interface SingleModuleResult {
|
|
20
|
+
output: string
|
|
21
|
+
diagnostics: Array<string>
|
|
22
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
require = createRequire(__filename)
|
|
8
|
+
|
|
9
|
+
const { readFileSync } = require('node:fs')
|
|
10
|
+
let nativeBinding = null
|
|
11
|
+
const loadErrors = []
|
|
12
|
+
|
|
13
|
+
const isMusl = () => {
|
|
14
|
+
let musl = false
|
|
15
|
+
if (process.platform === 'linux') {
|
|
16
|
+
musl = isMuslFromFilesystem()
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromReport()
|
|
19
|
+
}
|
|
20
|
+
if (musl === null) {
|
|
21
|
+
musl = isMuslFromChildProcess()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return musl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
28
|
+
|
|
29
|
+
const isMuslFromFilesystem = () => {
|
|
30
|
+
try {
|
|
31
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isMuslFromReport = () => {
|
|
38
|
+
let report = null
|
|
39
|
+
if (typeof process.report?.getReport === 'function') {
|
|
40
|
+
process.report.excludeNetwork = true
|
|
41
|
+
report = process.report.getReport()
|
|
42
|
+
}
|
|
43
|
+
if (!report) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
50
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isMuslFromChildProcess = () => {
|
|
58
|
+
try {
|
|
59
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requireNative() {
|
|
67
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
+
try {
|
|
69
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
loadErrors.push(err)
|
|
72
|
+
}
|
|
73
|
+
} else if (process.platform === 'android') {
|
|
74
|
+
if (process.arch === 'arm64') {
|
|
75
|
+
try {
|
|
76
|
+
return require('./jsshaker.android-arm64.node')
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadErrors.push(e)
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const binding = require('@jsshaker/binding-android-arm64')
|
|
82
|
+
const bindingPackageVersion = require('@jsshaker/binding-android-arm64/package.json').version
|
|
83
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
84
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
85
|
+
}
|
|
86
|
+
return binding
|
|
87
|
+
} catch (e) {
|
|
88
|
+
loadErrors.push(e)
|
|
89
|
+
}
|
|
90
|
+
} else if (process.arch === 'arm') {
|
|
91
|
+
try {
|
|
92
|
+
return require('./jsshaker.android-arm-eabi.node')
|
|
93
|
+
} catch (e) {
|
|
94
|
+
loadErrors.push(e)
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const binding = require('@jsshaker/binding-android-arm-eabi')
|
|
98
|
+
const bindingPackageVersion = require('@jsshaker/binding-android-arm-eabi/package.json').version
|
|
99
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
100
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
101
|
+
}
|
|
102
|
+
return binding
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadErrors.push(e)
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
108
|
+
}
|
|
109
|
+
} else if (process.platform === 'win32') {
|
|
110
|
+
if (process.arch === 'x64') {
|
|
111
|
+
try {
|
|
112
|
+
return require('./jsshaker.win32-x64-msvc.node')
|
|
113
|
+
} catch (e) {
|
|
114
|
+
loadErrors.push(e)
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const binding = require('@jsshaker/binding-win32-x64-msvc')
|
|
118
|
+
const bindingPackageVersion = require('@jsshaker/binding-win32-x64-msvc/package.json').version
|
|
119
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
120
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
121
|
+
}
|
|
122
|
+
return binding
|
|
123
|
+
} catch (e) {
|
|
124
|
+
loadErrors.push(e)
|
|
125
|
+
}
|
|
126
|
+
} else if (process.arch === 'ia32') {
|
|
127
|
+
try {
|
|
128
|
+
return require('./jsshaker.win32-ia32-msvc.node')
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadErrors.push(e)
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const binding = require('@jsshaker/binding-win32-ia32-msvc')
|
|
134
|
+
const bindingPackageVersion = require('@jsshaker/binding-win32-ia32-msvc/package.json').version
|
|
135
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
136
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
137
|
+
}
|
|
138
|
+
return binding
|
|
139
|
+
} catch (e) {
|
|
140
|
+
loadErrors.push(e)
|
|
141
|
+
}
|
|
142
|
+
} else if (process.arch === 'arm64') {
|
|
143
|
+
try {
|
|
144
|
+
return require('./jsshaker.win32-arm64-msvc.node')
|
|
145
|
+
} catch (e) {
|
|
146
|
+
loadErrors.push(e)
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const binding = require('@jsshaker/binding-win32-arm64-msvc')
|
|
150
|
+
const bindingPackageVersion = require('@jsshaker/binding-win32-arm64-msvc/package.json').version
|
|
151
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
152
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
153
|
+
}
|
|
154
|
+
return binding
|
|
155
|
+
} catch (e) {
|
|
156
|
+
loadErrors.push(e)
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
160
|
+
}
|
|
161
|
+
} else if (process.platform === 'darwin') {
|
|
162
|
+
try {
|
|
163
|
+
return require('./jsshaker.darwin-universal.node')
|
|
164
|
+
} catch (e) {
|
|
165
|
+
loadErrors.push(e)
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const binding = require('@jsshaker/binding-darwin-universal')
|
|
169
|
+
const bindingPackageVersion = require('@jsshaker/binding-darwin-universal/package.json').version
|
|
170
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
171
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
|
+
}
|
|
173
|
+
return binding
|
|
174
|
+
} catch (e) {
|
|
175
|
+
loadErrors.push(e)
|
|
176
|
+
}
|
|
177
|
+
if (process.arch === 'x64') {
|
|
178
|
+
try {
|
|
179
|
+
return require('./jsshaker.darwin-x64.node')
|
|
180
|
+
} catch (e) {
|
|
181
|
+
loadErrors.push(e)
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const binding = require('@jsshaker/binding-darwin-x64')
|
|
185
|
+
const bindingPackageVersion = require('@jsshaker/binding-darwin-x64/package.json').version
|
|
186
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
187
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
188
|
+
}
|
|
189
|
+
return binding
|
|
190
|
+
} catch (e) {
|
|
191
|
+
loadErrors.push(e)
|
|
192
|
+
}
|
|
193
|
+
} else if (process.arch === 'arm64') {
|
|
194
|
+
try {
|
|
195
|
+
return require('./jsshaker.darwin-arm64.node')
|
|
196
|
+
} catch (e) {
|
|
197
|
+
loadErrors.push(e)
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const binding = require('@jsshaker/binding-darwin-arm64')
|
|
201
|
+
const bindingPackageVersion = require('@jsshaker/binding-darwin-arm64/package.json').version
|
|
202
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
203
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
204
|
+
}
|
|
205
|
+
return binding
|
|
206
|
+
} catch (e) {
|
|
207
|
+
loadErrors.push(e)
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
211
|
+
}
|
|
212
|
+
} else if (process.platform === 'freebsd') {
|
|
213
|
+
if (process.arch === 'x64') {
|
|
214
|
+
try {
|
|
215
|
+
return require('./jsshaker.freebsd-x64.node')
|
|
216
|
+
} catch (e) {
|
|
217
|
+
loadErrors.push(e)
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const binding = require('@jsshaker/binding-freebsd-x64')
|
|
221
|
+
const bindingPackageVersion = require('@jsshaker/binding-freebsd-x64/package.json').version
|
|
222
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
223
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
224
|
+
}
|
|
225
|
+
return binding
|
|
226
|
+
} catch (e) {
|
|
227
|
+
loadErrors.push(e)
|
|
228
|
+
}
|
|
229
|
+
} else if (process.arch === 'arm64') {
|
|
230
|
+
try {
|
|
231
|
+
return require('./jsshaker.freebsd-arm64.node')
|
|
232
|
+
} catch (e) {
|
|
233
|
+
loadErrors.push(e)
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
const binding = require('@jsshaker/binding-freebsd-arm64')
|
|
237
|
+
const bindingPackageVersion = require('@jsshaker/binding-freebsd-arm64/package.json').version
|
|
238
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
239
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
240
|
+
}
|
|
241
|
+
return binding
|
|
242
|
+
} catch (e) {
|
|
243
|
+
loadErrors.push(e)
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
247
|
+
}
|
|
248
|
+
} else if (process.platform === 'linux') {
|
|
249
|
+
if (process.arch === 'x64') {
|
|
250
|
+
if (isMusl()) {
|
|
251
|
+
try {
|
|
252
|
+
return require('./jsshaker.linux-x64-musl.node')
|
|
253
|
+
} catch (e) {
|
|
254
|
+
loadErrors.push(e)
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
const binding = require('@jsshaker/binding-linux-x64-musl')
|
|
258
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-x64-musl/package.json').version
|
|
259
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
260
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
261
|
+
}
|
|
262
|
+
return binding
|
|
263
|
+
} catch (e) {
|
|
264
|
+
loadErrors.push(e)
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
try {
|
|
268
|
+
return require('./jsshaker.linux-x64-gnu.node')
|
|
269
|
+
} catch (e) {
|
|
270
|
+
loadErrors.push(e)
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const binding = require('@jsshaker/binding-linux-x64-gnu')
|
|
274
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-x64-gnu/package.json').version
|
|
275
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
276
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
277
|
+
}
|
|
278
|
+
return binding
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadErrors.push(e)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} else if (process.arch === 'arm64') {
|
|
284
|
+
if (isMusl()) {
|
|
285
|
+
try {
|
|
286
|
+
return require('./jsshaker.linux-arm64-musl.node')
|
|
287
|
+
} catch (e) {
|
|
288
|
+
loadErrors.push(e)
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const binding = require('@jsshaker/binding-linux-arm64-musl')
|
|
292
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-arm64-musl/package.json').version
|
|
293
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
294
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
295
|
+
}
|
|
296
|
+
return binding
|
|
297
|
+
} catch (e) {
|
|
298
|
+
loadErrors.push(e)
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
try {
|
|
302
|
+
return require('./jsshaker.linux-arm64-gnu.node')
|
|
303
|
+
} catch (e) {
|
|
304
|
+
loadErrors.push(e)
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
const binding = require('@jsshaker/binding-linux-arm64-gnu')
|
|
308
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-arm64-gnu/package.json').version
|
|
309
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
310
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
311
|
+
}
|
|
312
|
+
return binding
|
|
313
|
+
} catch (e) {
|
|
314
|
+
loadErrors.push(e)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} else if (process.arch === 'arm') {
|
|
318
|
+
if (isMusl()) {
|
|
319
|
+
try {
|
|
320
|
+
return require('./jsshaker.linux-arm-musleabihf.node')
|
|
321
|
+
} catch (e) {
|
|
322
|
+
loadErrors.push(e)
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const binding = require('@jsshaker/binding-linux-arm-musleabihf')
|
|
326
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-arm-musleabihf/package.json').version
|
|
327
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
328
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
329
|
+
}
|
|
330
|
+
return binding
|
|
331
|
+
} catch (e) {
|
|
332
|
+
loadErrors.push(e)
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
try {
|
|
336
|
+
return require('./jsshaker.linux-arm-gnueabihf.node')
|
|
337
|
+
} catch (e) {
|
|
338
|
+
loadErrors.push(e)
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
const binding = require('@jsshaker/binding-linux-arm-gnueabihf')
|
|
342
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-arm-gnueabihf/package.json').version
|
|
343
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
344
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
345
|
+
}
|
|
346
|
+
return binding
|
|
347
|
+
} catch (e) {
|
|
348
|
+
loadErrors.push(e)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} else if (process.arch === 'riscv64') {
|
|
352
|
+
if (isMusl()) {
|
|
353
|
+
try {
|
|
354
|
+
return require('./jsshaker.linux-riscv64-musl.node')
|
|
355
|
+
} catch (e) {
|
|
356
|
+
loadErrors.push(e)
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
const binding = require('@jsshaker/binding-linux-riscv64-musl')
|
|
360
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-riscv64-musl/package.json').version
|
|
361
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
362
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
363
|
+
}
|
|
364
|
+
return binding
|
|
365
|
+
} catch (e) {
|
|
366
|
+
loadErrors.push(e)
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
try {
|
|
370
|
+
return require('./jsshaker.linux-riscv64-gnu.node')
|
|
371
|
+
} catch (e) {
|
|
372
|
+
loadErrors.push(e)
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
const binding = require('@jsshaker/binding-linux-riscv64-gnu')
|
|
376
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-riscv64-gnu/package.json').version
|
|
377
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
378
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
379
|
+
}
|
|
380
|
+
return binding
|
|
381
|
+
} catch (e) {
|
|
382
|
+
loadErrors.push(e)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else if (process.arch === 'ppc64') {
|
|
386
|
+
try {
|
|
387
|
+
return require('./jsshaker.linux-ppc64-gnu.node')
|
|
388
|
+
} catch (e) {
|
|
389
|
+
loadErrors.push(e)
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
const binding = require('@jsshaker/binding-linux-ppc64-gnu')
|
|
393
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-ppc64-gnu/package.json').version
|
|
394
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
395
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
396
|
+
}
|
|
397
|
+
return binding
|
|
398
|
+
} catch (e) {
|
|
399
|
+
loadErrors.push(e)
|
|
400
|
+
}
|
|
401
|
+
} else if (process.arch === 's390x') {
|
|
402
|
+
try {
|
|
403
|
+
return require('./jsshaker.linux-s390x-gnu.node')
|
|
404
|
+
} catch (e) {
|
|
405
|
+
loadErrors.push(e)
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
const binding = require('@jsshaker/binding-linux-s390x-gnu')
|
|
409
|
+
const bindingPackageVersion = require('@jsshaker/binding-linux-s390x-gnu/package.json').version
|
|
410
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
|
+
}
|
|
413
|
+
return binding
|
|
414
|
+
} catch (e) {
|
|
415
|
+
loadErrors.push(e)
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
419
|
+
}
|
|
420
|
+
} else if (process.platform === 'openharmony') {
|
|
421
|
+
if (process.arch === 'arm64') {
|
|
422
|
+
try {
|
|
423
|
+
return require('./jsshaker.openharmony-arm64.node')
|
|
424
|
+
} catch (e) {
|
|
425
|
+
loadErrors.push(e)
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
const binding = require('@jsshaker/binding-openharmony-arm64')
|
|
429
|
+
const bindingPackageVersion = require('@jsshaker/binding-openharmony-arm64/package.json').version
|
|
430
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
431
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
432
|
+
}
|
|
433
|
+
return binding
|
|
434
|
+
} catch (e) {
|
|
435
|
+
loadErrors.push(e)
|
|
436
|
+
}
|
|
437
|
+
} else if (process.arch === 'x64') {
|
|
438
|
+
try {
|
|
439
|
+
return require('./jsshaker.openharmony-x64.node')
|
|
440
|
+
} catch (e) {
|
|
441
|
+
loadErrors.push(e)
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
const binding = require('@jsshaker/binding-openharmony-x64')
|
|
445
|
+
const bindingPackageVersion = require('@jsshaker/binding-openharmony-x64/package.json').version
|
|
446
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
447
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
448
|
+
}
|
|
449
|
+
return binding
|
|
450
|
+
} catch (e) {
|
|
451
|
+
loadErrors.push(e)
|
|
452
|
+
}
|
|
453
|
+
} else if (process.arch === 'arm') {
|
|
454
|
+
try {
|
|
455
|
+
return require('./jsshaker.openharmony-arm.node')
|
|
456
|
+
} catch (e) {
|
|
457
|
+
loadErrors.push(e)
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
const binding = require('@jsshaker/binding-openharmony-arm')
|
|
461
|
+
const bindingPackageVersion = require('@jsshaker/binding-openharmony-arm/package.json').version
|
|
462
|
+
if (bindingPackageVersion !== '0.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
463
|
+
throw new Error(`Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
464
|
+
}
|
|
465
|
+
return binding
|
|
466
|
+
} catch (e) {
|
|
467
|
+
loadErrors.push(e)
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
471
|
+
}
|
|
472
|
+
} else {
|
|
473
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
nativeBinding = requireNative()
|
|
478
|
+
|
|
479
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
480
|
+
try {
|
|
481
|
+
nativeBinding = require('./jsshaker.wasi.cjs')
|
|
482
|
+
} catch (err) {
|
|
483
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
484
|
+
loadErrors.push(err)
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (!nativeBinding) {
|
|
488
|
+
try {
|
|
489
|
+
nativeBinding = require('@jsshaker/binding-wasm32-wasi')
|
|
490
|
+
} catch (err) {
|
|
491
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
492
|
+
loadErrors.push(err)
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (!nativeBinding) {
|
|
499
|
+
if (loadErrors.length > 0) {
|
|
500
|
+
throw new Error(
|
|
501
|
+
`Cannot find native binding. ` +
|
|
502
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
503
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
504
|
+
{ cause: loadErrors }
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
throw new Error(`Failed to load native binding`)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
module.exports = nativeBinding
|
|
511
|
+
module.exports.shakeMultiModule = nativeBinding.shakeMultiModule
|
|
512
|
+
module.exports.shakeSingleModule = nativeBinding.shakeSingleModule
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jsshaker",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"browser": "browser.js",
|
|
7
|
+
"napi": {
|
|
8
|
+
"binaryName": "jsshaker",
|
|
9
|
+
"packageName": "@jsshaker/binding",
|
|
10
|
+
"targets": [
|
|
11
|
+
"x86_64-unknown-linux-gnu",
|
|
12
|
+
"x86_64-pc-windows-msvc",
|
|
13
|
+
"x86_64-apple-darwin",
|
|
14
|
+
"aarch64-apple-darwin",
|
|
15
|
+
"wasm32-wasip1-threads"
|
|
16
|
+
],
|
|
17
|
+
"wasm": {
|
|
18
|
+
"browser": {
|
|
19
|
+
"fs": false,
|
|
20
|
+
"asyncInit": true
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"jsshaker": "./cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.d.ts",
|
|
29
|
+
"index.js",
|
|
30
|
+
"cli.js"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@napi-rs/cli": "^3.1.5",
|
|
35
|
+
"@napi-rs/wasm-runtime": "^1.0.3",
|
|
36
|
+
"emnapi": "^1.5.0",
|
|
37
|
+
"ohash": "^2.0.11"
|
|
38
|
+
},
|
|
39
|
+
"optionalDependencies": {
|
|
40
|
+
"@jsshaker/binding-linux-x64-gnu": "0.0.0",
|
|
41
|
+
"@jsshaker/binding-win32-x64-msvc": "0.0.0",
|
|
42
|
+
"@jsshaker/binding-darwin-x64": "0.0.0",
|
|
43
|
+
"@jsshaker/binding-darwin-arm64": "0.0.0",
|
|
44
|
+
"@jsshaker/binding-wasm32-wasi": "0.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"artifacts": "napi artifacts",
|
|
48
|
+
"build": "napi build --platform --release",
|
|
49
|
+
"build:debug": "napi build --platform",
|
|
50
|
+
"build:wasi": "pnpm build:debug --target wasm32-wasip1-threads",
|
|
51
|
+
"universal": "napi universal",
|
|
52
|
+
"version": "napi version"
|
|
53
|
+
}
|
|
54
|
+
}
|