oxc-minify 0.46.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present VoidZero Inc. & Contributors
4
+ Copyright (c) 2023 Boshen
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Oxc Minify
2
+
3
+ This is alpha software and may yield incorrect results, feel free to [submit a bug report](https://github.com/oxc-project/oxc/issues/new?assignees=&labels=C-bug&projects=&template=bug_report.md).
package/index.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export interface CodegenOptions {
4
+ /**
5
+ * Remove whitespace.
6
+ *
7
+ * @default true
8
+ */
9
+ whitespace?: boolean
10
+ }
11
+
12
+ export interface CompressOptions {
13
+ /**
14
+ * Enables optional catch or nullish-coalescing operator if targeted higher.
15
+ *
16
+ * @default 'es2015'
17
+ */
18
+ target?: string
19
+ /**
20
+ * Pass true to discard calls to `console.*`.
21
+ *
22
+ * @default false
23
+ */
24
+ dropConsole?: boolean
25
+ /**
26
+ * Remove `debugger;` statements.
27
+ *
28
+ * @default true
29
+ */
30
+ dropDebugger?: boolean
31
+ }
32
+
33
+ export interface MangleOptions {
34
+ /** Pass true to mangle names declared in the top level scope. */
35
+ toplevel?: boolean
36
+ /** Debug mangled names. */
37
+ debug?: boolean
38
+ }
39
+
40
+ /**
41
+ * Minify synchronously.
42
+ *
43
+ * # Errors
44
+ *
45
+ * * Fails to parse the options.
46
+ */
47
+ export declare function minify(filename: string, sourceText: string, options?: MinifyOptions | undefined | null): MinifyResult
48
+
49
+ export interface MinifyOptions {
50
+ compress?: boolean | CompressOptions
51
+ mangle?: boolean | MangleOptions
52
+ codegen?: boolean | CodegenOptions
53
+ sourcemap?: boolean
54
+ }
55
+
56
+ export interface MinifyResult {
57
+ code: string
58
+ map?: SourceMap
59
+ }
60
+
61
+ export interface SourceMap {
62
+ file?: string
63
+ mappings: string
64
+ names: Array<string>
65
+ sourceRoot?: string
66
+ sources: Array<string>
67
+ sourcesContent?: Array<string>
68
+ version: number
69
+ x_google_ignoreList?: Array<number>
70
+ }
package/index.js ADDED
@@ -0,0 +1,367 @@
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
+ const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
39
+ if (!report) {
40
+ return null
41
+ }
42
+ if (report.header && report.header.glibcVersionRuntime) {
43
+ return false
44
+ }
45
+ if (Array.isArray(report.sharedObjects)) {
46
+ if (report.sharedObjects.some(isFileMusl)) {
47
+ return true
48
+ }
49
+ }
50
+ return false
51
+ }
52
+
53
+ const isMuslFromChildProcess = () => {
54
+ try {
55
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
56
+ } catch (e) {
57
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
58
+ return false
59
+ }
60
+ }
61
+
62
+ function requireNative() {
63
+ if (process.platform === 'android') {
64
+ if (process.arch === 'arm64') {
65
+ try {
66
+ return require('./minify.android-arm64.node')
67
+ } catch (e) {
68
+ loadErrors.push(e)
69
+ }
70
+ try {
71
+ return require('@oxc-minify/binding-android-arm64')
72
+ } catch (e) {
73
+ loadErrors.push(e)
74
+ }
75
+
76
+ } else if (process.arch === 'arm') {
77
+ try {
78
+ return require('./minify.android-arm-eabi.node')
79
+ } catch (e) {
80
+ loadErrors.push(e)
81
+ }
82
+ try {
83
+ return require('@oxc-minify/binding-android-arm-eabi')
84
+ } catch (e) {
85
+ loadErrors.push(e)
86
+ }
87
+
88
+ } else {
89
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
90
+ }
91
+ } else if (process.platform === 'win32') {
92
+ if (process.arch === 'x64') {
93
+ try {
94
+ return require('./minify.win32-x64-msvc.node')
95
+ } catch (e) {
96
+ loadErrors.push(e)
97
+ }
98
+ try {
99
+ return require('@oxc-minify/binding-win32-x64-msvc')
100
+ } catch (e) {
101
+ loadErrors.push(e)
102
+ }
103
+
104
+ } else if (process.arch === 'ia32') {
105
+ try {
106
+ return require('./minify.win32-ia32-msvc.node')
107
+ } catch (e) {
108
+ loadErrors.push(e)
109
+ }
110
+ try {
111
+ return require('@oxc-minify/binding-win32-ia32-msvc')
112
+ } catch (e) {
113
+ loadErrors.push(e)
114
+ }
115
+
116
+ } else if (process.arch === 'arm64') {
117
+ try {
118
+ return require('./minify.win32-arm64-msvc.node')
119
+ } catch (e) {
120
+ loadErrors.push(e)
121
+ }
122
+ try {
123
+ return require('@oxc-minify/binding-win32-arm64-msvc')
124
+ } catch (e) {
125
+ loadErrors.push(e)
126
+ }
127
+
128
+ } else {
129
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
130
+ }
131
+ } else if (process.platform === 'darwin') {
132
+ try {
133
+ return require('./minify.darwin-universal.node')
134
+ } catch (e) {
135
+ loadErrors.push(e)
136
+ }
137
+ try {
138
+ return require('@oxc-minify/binding-darwin-universal')
139
+ } catch (e) {
140
+ loadErrors.push(e)
141
+ }
142
+
143
+ if (process.arch === 'x64') {
144
+ try {
145
+ return require('./minify.darwin-x64.node')
146
+ } catch (e) {
147
+ loadErrors.push(e)
148
+ }
149
+ try {
150
+ return require('@oxc-minify/binding-darwin-x64')
151
+ } catch (e) {
152
+ loadErrors.push(e)
153
+ }
154
+
155
+ } else if (process.arch === 'arm64') {
156
+ try {
157
+ return require('./minify.darwin-arm64.node')
158
+ } catch (e) {
159
+ loadErrors.push(e)
160
+ }
161
+ try {
162
+ return require('@oxc-minify/binding-darwin-arm64')
163
+ } catch (e) {
164
+ loadErrors.push(e)
165
+ }
166
+
167
+ } else {
168
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
169
+ }
170
+ } else if (process.platform === 'freebsd') {
171
+ if (process.arch === 'x64') {
172
+ try {
173
+ return require('./minify.freebsd-x64.node')
174
+ } catch (e) {
175
+ loadErrors.push(e)
176
+ }
177
+ try {
178
+ return require('@oxc-minify/binding-freebsd-x64')
179
+ } catch (e) {
180
+ loadErrors.push(e)
181
+ }
182
+
183
+ } else if (process.arch === 'arm64') {
184
+ try {
185
+ return require('./minify.freebsd-arm64.node')
186
+ } catch (e) {
187
+ loadErrors.push(e)
188
+ }
189
+ try {
190
+ return require('@oxc-minify/binding-freebsd-arm64')
191
+ } catch (e) {
192
+ loadErrors.push(e)
193
+ }
194
+
195
+ } else {
196
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
197
+ }
198
+ } else if (process.platform === 'linux') {
199
+ if (process.arch === 'x64') {
200
+ if (isMusl()) {
201
+ try {
202
+ return require('./minify.linux-x64-musl.node')
203
+ } catch (e) {
204
+ loadErrors.push(e)
205
+ }
206
+ try {
207
+ return require('@oxc-minify/binding-linux-x64-musl')
208
+ } catch (e) {
209
+ loadErrors.push(e)
210
+ }
211
+
212
+ } else {
213
+ try {
214
+ return require('./minify.linux-x64-gnu.node')
215
+ } catch (e) {
216
+ loadErrors.push(e)
217
+ }
218
+ try {
219
+ return require('@oxc-minify/binding-linux-x64-gnu')
220
+ } catch (e) {
221
+ loadErrors.push(e)
222
+ }
223
+
224
+ }
225
+ } else if (process.arch === 'arm64') {
226
+ if (isMusl()) {
227
+ try {
228
+ return require('./minify.linux-arm64-musl.node')
229
+ } catch (e) {
230
+ loadErrors.push(e)
231
+ }
232
+ try {
233
+ return require('@oxc-minify/binding-linux-arm64-musl')
234
+ } catch (e) {
235
+ loadErrors.push(e)
236
+ }
237
+
238
+ } else {
239
+ try {
240
+ return require('./minify.linux-arm64-gnu.node')
241
+ } catch (e) {
242
+ loadErrors.push(e)
243
+ }
244
+ try {
245
+ return require('@oxc-minify/binding-linux-arm64-gnu')
246
+ } catch (e) {
247
+ loadErrors.push(e)
248
+ }
249
+
250
+ }
251
+ } else if (process.arch === 'arm') {
252
+ if (isMusl()) {
253
+ try {
254
+ return require('./minify.linux-arm-musleabihf.node')
255
+ } catch (e) {
256
+ loadErrors.push(e)
257
+ }
258
+ try {
259
+ return require('@oxc-minify/binding-linux-arm-musleabihf')
260
+ } catch (e) {
261
+ loadErrors.push(e)
262
+ }
263
+
264
+ } else {
265
+ try {
266
+ return require('./minify.linux-arm-gnueabihf.node')
267
+ } catch (e) {
268
+ loadErrors.push(e)
269
+ }
270
+ try {
271
+ return require('@oxc-minify/binding-linux-arm-gnueabihf')
272
+ } catch (e) {
273
+ loadErrors.push(e)
274
+ }
275
+
276
+ }
277
+ } else if (process.arch === 'riscv64') {
278
+ if (isMusl()) {
279
+ try {
280
+ return require('./minify.linux-riscv64-musl.node')
281
+ } catch (e) {
282
+ loadErrors.push(e)
283
+ }
284
+ try {
285
+ return require('@oxc-minify/binding-linux-riscv64-musl')
286
+ } catch (e) {
287
+ loadErrors.push(e)
288
+ }
289
+
290
+ } else {
291
+ try {
292
+ return require('./minify.linux-riscv64-gnu.node')
293
+ } catch (e) {
294
+ loadErrors.push(e)
295
+ }
296
+ try {
297
+ return require('@oxc-minify/binding-linux-riscv64-gnu')
298
+ } catch (e) {
299
+ loadErrors.push(e)
300
+ }
301
+
302
+ }
303
+ } else if (process.arch === 'ppc64') {
304
+ try {
305
+ return require('./minify.linux-ppc64-gnu.node')
306
+ } catch (e) {
307
+ loadErrors.push(e)
308
+ }
309
+ try {
310
+ return require('@oxc-minify/binding-linux-ppc64-gnu')
311
+ } catch (e) {
312
+ loadErrors.push(e)
313
+ }
314
+
315
+ } else if (process.arch === 's390x') {
316
+ try {
317
+ return require('./minify.linux-s390x-gnu.node')
318
+ } catch (e) {
319
+ loadErrors.push(e)
320
+ }
321
+ try {
322
+ return require('@oxc-minify/binding-linux-s390x-gnu')
323
+ } catch (e) {
324
+ loadErrors.push(e)
325
+ }
326
+
327
+ } else {
328
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
329
+ }
330
+ } else {
331
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
332
+ }
333
+ }
334
+
335
+ nativeBinding = requireNative()
336
+
337
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
338
+ try {
339
+ nativeBinding = require('./minify.wasi.cjs')
340
+ } catch (err) {
341
+ if (process.env.NAPI_RS_FORCE_WASI) {
342
+ loadErrors.push(err)
343
+ }
344
+ }
345
+ if (!nativeBinding) {
346
+ try {
347
+ nativeBinding = require('@oxc-minify/binding-wasm32-wasi')
348
+ } catch (err) {
349
+ if (process.env.NAPI_RS_FORCE_WASI) {
350
+ loadErrors.push(err)
351
+ }
352
+ }
353
+ }
354
+ }
355
+
356
+ if (!nativeBinding) {
357
+ if (loadErrors.length > 0) {
358
+ // TODO Link to documentation with potential fixes
359
+ // - The package owner could build/publish bindings for this arch
360
+ // - The user may need to bundle the correct files
361
+ // - The user may need to re-install node_modules to get new packages
362
+ throw new Error('Failed to load native binding', { cause: loadErrors })
363
+ }
364
+ throw new Error(`Failed to load native binding`)
365
+ }
366
+
367
+ module.exports.minify = nativeBinding.minify
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "oxc-minify",
3
+ "version": "0.46.0",
4
+ "description": "Oxc minify Node API",
5
+ "keywords": [
6
+ "minify"
7
+ ],
8
+ "author": "Boshen and oxc contributors",
9
+ "license": "MIT",
10
+ "homepage": "https://oxc.rs",
11
+ "bugs": "https://github.com/oxc-project/oxc/issues",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/oxc-project/oxc.git",
15
+ "directory": "npm/oxc-minify"
16
+ },
17
+ "funding": {
18
+ "url": "https://github.com/sponsors/Boshen"
19
+ },
20
+ "main": "index.js",
21
+ "files": [
22
+ "index.d.ts",
23
+ "index.js"
24
+ ],
25
+ "optionalDependencies": {
26
+ "@oxc-minify/binding-win32-x64-msvc": "0.46.0",
27
+ "@oxc-minify/binding-win32-arm64-msvc": "0.46.0",
28
+ "@oxc-minify/binding-linux-x64-gnu": "0.46.0",
29
+ "@oxc-minify/binding-linux-arm64-gnu": "0.46.0",
30
+ "@oxc-minify/binding-linux-x64-musl": "0.46.0",
31
+ "@oxc-minify/binding-linux-arm64-musl": "0.46.0",
32
+ "@oxc-minify/binding-darwin-x64": "0.46.0",
33
+ "@oxc-minify/binding-darwin-arm64": "0.46.0"
34
+ }
35
+ }