@swc/html 0.0.28 → 1.7.15-nightly-20240820.7
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 +39 -23
- package/binding.js +310 -223
- package/index.ts +46 -46
- package/package.json +6 -23
- package/index.js +0 -46
package/binding.d.ts
CHANGED
|
@@ -1,30 +1,46 @@
|
|
|
1
|
-
/*
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export interface Attribute {
|
|
5
|
+
namespace?: string;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
}
|
|
5
10
|
|
|
6
11
|
export interface Diagnostic {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export interface TransformOutput {
|
|
12
|
-
code: string
|
|
13
|
-
errors?: Array<Diagnostic>
|
|
14
|
-
}
|
|
15
|
-
export interface Attribute {
|
|
16
|
-
namespace?: string
|
|
17
|
-
prefix?: string
|
|
18
|
-
name: string
|
|
19
|
-
value?: string
|
|
12
|
+
level: string;
|
|
13
|
+
message: string;
|
|
14
|
+
span: any;
|
|
20
15
|
}
|
|
16
|
+
|
|
21
17
|
export interface Element {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
tagName: string;
|
|
19
|
+
namespace: string;
|
|
20
|
+
attributes: Array<Attribute>;
|
|
21
|
+
isSelfClosing: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare function minify(
|
|
25
|
+
code: Buffer,
|
|
26
|
+
opts: Buffer,
|
|
27
|
+
signal?: AbortSignal | undefined | null
|
|
28
|
+
): Promise<TransformOutput>;
|
|
29
|
+
|
|
30
|
+
export declare function minifyFragment(
|
|
31
|
+
code: Buffer,
|
|
32
|
+
opts: Buffer,
|
|
33
|
+
signal?: AbortSignal | undefined | null
|
|
34
|
+
): Promise<TransformOutput>;
|
|
35
|
+
|
|
36
|
+
export declare function minifyFragmentSync(
|
|
37
|
+
code: Buffer,
|
|
38
|
+
opts: Buffer
|
|
39
|
+
): TransformOutput;
|
|
40
|
+
|
|
41
|
+
export declare function minifySync(code: Buffer, opts: Buffer): TransformOutput;
|
|
42
|
+
|
|
43
|
+
export interface TransformOutput {
|
|
44
|
+
code: string;
|
|
45
|
+
errors?: Array<Diagnostic>;
|
|
26
46
|
}
|
|
27
|
-
export function minify(code: Buffer, opts: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
|
|
28
|
-
export function minifyFragment(code: Buffer, opts: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
|
|
29
|
-
export function minifySync(code: Buffer, opts: Buffer): TransformOutput
|
|
30
|
-
export function minifyFragmentSync(code: Buffer, opts: Buffer): TransformOutput
|
package/binding.js
CHANGED
|
@@ -1,260 +1,347 @@
|
|
|
1
|
-
|
|
1
|
+
// prettier-ignore
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
/* prettier-ignore */
|
|
4
|
-
|
|
5
3
|
/* auto-generated by NAPI-RS */
|
|
6
4
|
|
|
7
|
-
const {
|
|
8
|
-
|
|
5
|
+
const { readFileSync } = require('fs')
|
|
6
|
+
|
|
7
|
+
let nativeBinding = null;
|
|
8
|
+
const loadErrors = [];
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const isMusl = () => {
|
|
11
|
+
let musl = false;
|
|
12
|
+
if (process.platform === "linux") {
|
|
13
|
+
musl = isMuslFromFilesystem();
|
|
14
|
+
if (musl === null) {
|
|
15
|
+
musl = isMuslFromReport();
|
|
16
|
+
}
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromChildProcess();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return musl;
|
|
22
|
+
};
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
let localFileExisted = false
|
|
14
|
-
let loadError = null
|
|
24
|
+
const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
// For Node 10
|
|
18
|
-
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
26
|
+
const isMuslFromFilesystem = () => {
|
|
19
27
|
try {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return true
|
|
28
|
+
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
24
31
|
}
|
|
25
|
-
|
|
26
|
-
const { glibcVersionRuntime } = process.report.getReport().header
|
|
27
|
-
return !glibcVersionRuntime
|
|
28
|
-
}
|
|
29
|
-
}
|
|
32
|
+
};
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
break
|
|
46
|
-
case 'arm':
|
|
47
|
-
localFileExisted = existsSync(join(__dirname, 'html.android-arm-eabi.node'))
|
|
48
|
-
try {
|
|
49
|
-
if (localFileExisted) {
|
|
50
|
-
nativeBinding = require('./html.android-arm-eabi.node')
|
|
51
|
-
} else {
|
|
52
|
-
nativeBinding = require('@swc/html-android-arm-eabi')
|
|
53
|
-
}
|
|
54
|
-
} catch (e) {
|
|
55
|
-
loadError = e
|
|
34
|
+
const isMuslFromReport = () => {
|
|
35
|
+
const report =
|
|
36
|
+
typeof process.report.getReport === "function"
|
|
37
|
+
? process.report.getReport()
|
|
38
|
+
: 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;
|
|
56
48
|
}
|
|
57
|
-
break
|
|
58
|
-
default:
|
|
59
|
-
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const isMuslFromChildProcess = () => {
|
|
54
|
+
try {
|
|
55
|
+
return require("child_process")
|
|
56
|
+
.execSync("ldd --version", { encoding: "utf8" })
|
|
57
|
+
.includes("musl");
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function requireNative() {
|
|
65
|
+
if (process.platform === "android") {
|
|
66
|
+
if (process.arch === "arm64") {
|
|
67
|
+
try {
|
|
68
|
+
return require("./swc-html.android-arm64.node");
|
|
69
|
+
} catch (e) {
|
|
70
|
+
loadErrors.push(e);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return require("@swc/html-android-arm64");
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadErrors.push(e);
|
|
76
|
+
}
|
|
77
|
+
} else if (process.arch === "arm") {
|
|
78
|
+
try {
|
|
79
|
+
return require("./swc-html.android-arm-eabi.node");
|
|
80
|
+
} catch (e) {
|
|
81
|
+
loadErrors.push(e);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return require("@swc/html-android-arm-eabi");
|
|
85
|
+
} catch (e) {
|
|
86
|
+
loadErrors.push(e);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
loadErrors.push(
|
|
90
|
+
new Error(`Unsupported architecture on Android ${process.arch}`)
|
|
91
|
+
);
|
|
76
92
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
} else if (process.platform === "win32") {
|
|
94
|
+
if (process.arch === "x64") {
|
|
95
|
+
try {
|
|
96
|
+
return require("./swc-html.win32-x64-msvc.node");
|
|
97
|
+
} catch (e) {
|
|
98
|
+
loadErrors.push(e);
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
return require("@swc/html-win32-x64-msvc");
|
|
102
|
+
} catch (e) {
|
|
103
|
+
loadErrors.push(e);
|
|
104
|
+
}
|
|
105
|
+
} else if (process.arch === "ia32") {
|
|
106
|
+
try {
|
|
107
|
+
return require("./swc-html.win32-ia32-msvc.node");
|
|
108
|
+
} catch (e) {
|
|
109
|
+
loadErrors.push(e);
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return require("@swc/html-win32-ia32-msvc");
|
|
113
|
+
} catch (e) {
|
|
114
|
+
loadErrors.push(e);
|
|
115
|
+
}
|
|
116
|
+
} else if (process.arch === "arm64") {
|
|
117
|
+
try {
|
|
118
|
+
return require("./swc-html.win32-arm64-msvc.node");
|
|
119
|
+
} catch (e) {
|
|
120
|
+
loadErrors.push(e);
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
return require("@swc/html-win32-arm64-msvc");
|
|
124
|
+
} catch (e) {
|
|
125
|
+
loadErrors.push(e);
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
loadErrors.push(
|
|
129
|
+
new Error(
|
|
130
|
+
`Unsupported architecture on Windows: ${process.arch}`
|
|
131
|
+
)
|
|
132
|
+
);
|
|
90
133
|
}
|
|
91
|
-
|
|
92
|
-
case 'arm64':
|
|
93
|
-
localFileExisted = existsSync(
|
|
94
|
-
join(__dirname, 'html.win32-arm64-msvc.node')
|
|
95
|
-
)
|
|
134
|
+
} else if (process.platform === "darwin") {
|
|
96
135
|
try {
|
|
97
|
-
|
|
98
|
-
nativeBinding = require('./html.win32-arm64-msvc.node')
|
|
99
|
-
} else {
|
|
100
|
-
nativeBinding = require('@swc/html-win32-arm64-msvc')
|
|
101
|
-
}
|
|
136
|
+
return require("./swc-html.darwin-universal.node");
|
|
102
137
|
} catch (e) {
|
|
103
|
-
|
|
138
|
+
loadErrors.push(e);
|
|
104
139
|
}
|
|
105
|
-
break
|
|
106
|
-
default:
|
|
107
|
-
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
108
|
-
}
|
|
109
|
-
break
|
|
110
|
-
case 'darwin':
|
|
111
|
-
localFileExisted = existsSync(join(__dirname, 'html.darwin-universal.node'))
|
|
112
|
-
try {
|
|
113
|
-
if (localFileExisted) {
|
|
114
|
-
nativeBinding = require('./html.darwin-universal.node')
|
|
115
|
-
} else {
|
|
116
|
-
nativeBinding = require('@swc/html-darwin-universal')
|
|
117
|
-
}
|
|
118
|
-
break
|
|
119
|
-
} catch {}
|
|
120
|
-
switch (arch) {
|
|
121
|
-
case 'x64':
|
|
122
|
-
localFileExisted = existsSync(join(__dirname, 'html.darwin-x64.node'))
|
|
123
140
|
try {
|
|
124
|
-
|
|
125
|
-
nativeBinding = require('./html.darwin-x64.node')
|
|
126
|
-
} else {
|
|
127
|
-
nativeBinding = require('@swc/html-darwin-x64')
|
|
128
|
-
}
|
|
141
|
+
return require("@swc/html-darwin-universal");
|
|
129
142
|
} catch (e) {
|
|
130
|
-
|
|
143
|
+
loadErrors.push(e);
|
|
131
144
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
|
|
146
|
+
if (process.arch === "x64") {
|
|
147
|
+
try {
|
|
148
|
+
return require("./swc-html.darwin-x64.node");
|
|
149
|
+
} catch (e) {
|
|
150
|
+
loadErrors.push(e);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
return require("@swc/html-darwin-x64");
|
|
154
|
+
} catch (e) {
|
|
155
|
+
loadErrors.push(e);
|
|
156
|
+
}
|
|
157
|
+
} else if (process.arch === "arm64") {
|
|
158
|
+
try {
|
|
159
|
+
return require("./swc-html.darwin-arm64.node");
|
|
160
|
+
} catch (e) {
|
|
161
|
+
loadErrors.push(e);
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
return require("@swc/html-darwin-arm64");
|
|
165
|
+
} catch (e) {
|
|
166
|
+
loadErrors.push(e);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
loadErrors.push(
|
|
170
|
+
new Error(`Unsupported architecture on macOS: ${process.arch}`)
|
|
171
|
+
);
|
|
145
172
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
case 'x64':
|
|
169
|
-
if (isMusl()) {
|
|
170
|
-
localFileExisted = existsSync(
|
|
171
|
-
join(__dirname, 'html.linux-x64-musl.node')
|
|
172
|
-
)
|
|
173
|
-
try {
|
|
174
|
-
if (localFileExisted) {
|
|
175
|
-
nativeBinding = require('./html.linux-x64-musl.node')
|
|
176
|
-
} else {
|
|
177
|
-
nativeBinding = require('@swc/html-linux-x64-musl')
|
|
173
|
+
} else if (process.platform === "freebsd") {
|
|
174
|
+
if (process.arch === "x64") {
|
|
175
|
+
try {
|
|
176
|
+
return require("./swc-html.freebsd-x64.node");
|
|
177
|
+
} catch (e) {
|
|
178
|
+
loadErrors.push(e);
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
return require("@swc/html-freebsd-x64");
|
|
182
|
+
} catch (e) {
|
|
183
|
+
loadErrors.push(e);
|
|
184
|
+
}
|
|
185
|
+
} else if (process.arch === "arm64") {
|
|
186
|
+
try {
|
|
187
|
+
return require("./swc-html.freebsd-arm64.node");
|
|
188
|
+
} catch (e) {
|
|
189
|
+
loadErrors.push(e);
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
return require("@swc/html-freebsd-arm64");
|
|
193
|
+
} catch (e) {
|
|
194
|
+
loadErrors.push(e);
|
|
178
195
|
}
|
|
179
|
-
} catch (e) {
|
|
180
|
-
loadError = e
|
|
181
|
-
}
|
|
182
196
|
} else {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
197
|
+
loadErrors.push(
|
|
198
|
+
new Error(
|
|
199
|
+
`Unsupported architecture on FreeBSD: ${process.arch}`
|
|
200
|
+
)
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
} else if (process.platform === "linux") {
|
|
204
|
+
if (process.arch === "x64") {
|
|
205
|
+
if (isMusl()) {
|
|
206
|
+
try {
|
|
207
|
+
return require("./swc-html.linux-x64-musl.node");
|
|
208
|
+
} catch (e) {
|
|
209
|
+
loadErrors.push(e);
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
return require("@swc/html-linux-x64-musl");
|
|
213
|
+
} catch (e) {
|
|
214
|
+
loadErrors.push(e);
|
|
215
|
+
}
|
|
189
216
|
} else {
|
|
190
|
-
|
|
217
|
+
try {
|
|
218
|
+
return require("./swc-html.linux-x64-gnu.node");
|
|
219
|
+
} catch (e) {
|
|
220
|
+
loadErrors.push(e);
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
return require("@swc/html-linux-x64-gnu");
|
|
224
|
+
} catch (e) {
|
|
225
|
+
loadErrors.push(e);
|
|
226
|
+
}
|
|
191
227
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
nativeBinding = require('./html.linux-arm64-musl.node')
|
|
228
|
+
} else if (process.arch === "arm64") {
|
|
229
|
+
if (isMusl()) {
|
|
230
|
+
try {
|
|
231
|
+
return require("./swc-html.linux-arm64-musl.node");
|
|
232
|
+
} catch (e) {
|
|
233
|
+
loadErrors.push(e);
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
return require("@swc/html-linux-arm64-musl");
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadErrors.push(e);
|
|
239
|
+
}
|
|
205
240
|
} else {
|
|
206
|
-
|
|
241
|
+
try {
|
|
242
|
+
return require("./swc-html.linux-arm64-gnu.node");
|
|
243
|
+
} catch (e) {
|
|
244
|
+
loadErrors.push(e);
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
return require("@swc/html-linux-arm64-gnu");
|
|
248
|
+
} catch (e) {
|
|
249
|
+
loadErrors.push(e);
|
|
250
|
+
}
|
|
207
251
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
252
|
+
} else if (process.arch === "arm") {
|
|
253
|
+
try {
|
|
254
|
+
return require("./swc-html.linux-arm-gnueabihf.node");
|
|
255
|
+
} catch (e) {
|
|
256
|
+
loadErrors.push(e);
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
return require("@swc/html-linux-arm-gnueabihf");
|
|
260
|
+
} catch (e) {
|
|
261
|
+
loadErrors.push(e);
|
|
262
|
+
}
|
|
263
|
+
} else if (process.arch === "riscv64") {
|
|
264
|
+
if (isMusl()) {
|
|
265
|
+
try {
|
|
266
|
+
return require("./swc-html.linux-riscv64-musl.node");
|
|
267
|
+
} catch (e) {
|
|
268
|
+
loadErrors.push(e);
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
return require("@swc/html-linux-riscv64-musl");
|
|
272
|
+
} catch (e) {
|
|
273
|
+
loadErrors.push(e);
|
|
274
|
+
}
|
|
218
275
|
} else {
|
|
219
|
-
|
|
276
|
+
try {
|
|
277
|
+
return require("./swc-html.linux-riscv64-gnu.node");
|
|
278
|
+
} catch (e) {
|
|
279
|
+
loadErrors.push(e);
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
return require("@swc/html-linux-riscv64-gnu");
|
|
283
|
+
} catch (e) {
|
|
284
|
+
loadErrors.push(e);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
} else if (process.arch === "s390x") {
|
|
288
|
+
try {
|
|
289
|
+
return require("./swc-html.linux-s390x-gnu.node");
|
|
290
|
+
} catch (e) {
|
|
291
|
+
loadErrors.push(e);
|
|
220
292
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
293
|
+
try {
|
|
294
|
+
return require("@swc/html-linux-s390x-gnu");
|
|
295
|
+
} catch (e) {
|
|
296
|
+
loadErrors.push(e);
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
loadErrors.push(
|
|
300
|
+
new Error(`Unsupported architecture on Linux: ${process.arch}`)
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
loadErrors.push(
|
|
305
|
+
new Error(
|
|
306
|
+
`Unsupported OS: ${process.platform}, architecture: ${process.arch}`
|
|
307
|
+
)
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
nativeBinding = requireNative();
|
|
313
|
+
|
|
314
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
315
|
+
try {
|
|
316
|
+
nativeBinding = require("./swc-html.wasi.cjs");
|
|
317
|
+
} catch (err) {
|
|
318
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
319
|
+
console.error(err);
|
|
224
320
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
localFileExisted = existsSync(
|
|
228
|
-
join(__dirname, 'html.linux-arm-gnueabihf.node')
|
|
229
|
-
)
|
|
321
|
+
}
|
|
322
|
+
if (!nativeBinding) {
|
|
230
323
|
try {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
} catch (e) {
|
|
237
|
-
loadError = e
|
|
324
|
+
nativeBinding = require("@swc/html-wasm32-wasi");
|
|
325
|
+
} catch (err) {
|
|
326
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
327
|
+
console.error(err);
|
|
328
|
+
}
|
|
238
329
|
}
|
|
239
|
-
break
|
|
240
|
-
default:
|
|
241
|
-
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
242
330
|
}
|
|
243
|
-
break
|
|
244
|
-
default:
|
|
245
|
-
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
246
331
|
}
|
|
247
332
|
|
|
248
333
|
if (!nativeBinding) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
334
|
+
if (loadErrors.length > 0) {
|
|
335
|
+
// TODO Link to documentation with potential fixes
|
|
336
|
+
// - The package owner could build/publish bindings for this arch
|
|
337
|
+
// - The user may need to bundle the correct files
|
|
338
|
+
// - The user may need to re-install node_modules to get new packages
|
|
339
|
+
throw new Error("Failed to load native binding", { cause: loadErrors });
|
|
340
|
+
}
|
|
341
|
+
throw new Error(`Failed to load native binding`);
|
|
253
342
|
}
|
|
254
343
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
module.exports.
|
|
258
|
-
module.exports.
|
|
259
|
-
module.exports.minifySync = minifySync
|
|
260
|
-
module.exports.minifyFragmentSync = minifyFragmentSync
|
|
344
|
+
module.exports.minify = nativeBinding.minify;
|
|
345
|
+
module.exports.minifyFragment = nativeBinding.minifyFragment;
|
|
346
|
+
module.exports.minifyFragmentSync = nativeBinding.minifyFragmentSync;
|
|
347
|
+
module.exports.minifySync = nativeBinding.minifySync;
|
package/index.ts
CHANGED
|
@@ -3,72 +3,72 @@ import * as binding from "./binding";
|
|
|
3
3
|
export type MinifierType = "js-module" | "js-script" | "json" | "css" | "html";
|
|
4
4
|
|
|
5
5
|
export type Options = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
6
|
+
filename?: string;
|
|
7
|
+
iframeSrcdoc?: boolean;
|
|
8
|
+
scriptingEnabled?: boolean;
|
|
9
|
+
forceSetHtml5Doctype?: boolean;
|
|
10
|
+
collapseWhitespaces?:
|
|
11
|
+
| "none"
|
|
12
|
+
| "all"
|
|
13
|
+
| "smart"
|
|
14
|
+
| "conservative"
|
|
15
|
+
| "advanced-conservative"
|
|
16
|
+
| "only-metadata";
|
|
17
|
+
removeEmptyMetadataElements?: boolean;
|
|
18
|
+
removeComments?: boolean;
|
|
19
|
+
preserveComments: string[];
|
|
20
|
+
minifyConditionalComments?: boolean;
|
|
21
|
+
removeEmptyAttributes?: boolean;
|
|
22
|
+
removeRedundantAttributes?: boolean;
|
|
23
|
+
collapseBooleanAttributes?: boolean;
|
|
24
|
+
normalizeAttributes?: boolean;
|
|
25
|
+
minifyJson?: boolean | { pretty?: boolean };
|
|
26
|
+
// TODO improve me after typing `@swc/css`
|
|
27
|
+
minifyJs?: boolean | { parser?: any; minifier?: any; codegen?: any };
|
|
28
|
+
minifyCss?: boolean | { parser?: any; minifier?: any; codegen?: any };
|
|
29
|
+
minifyAdditionalScriptsContent?: [string, MinifierType][];
|
|
30
|
+
minifyAdditionalAttributes?: [string, MinifierType][];
|
|
31
|
+
sortSpaceSeparatedAttributeValues?: boolean;
|
|
32
|
+
sortAttributes?: boolean;
|
|
33
|
+
tagOmission?: boolean;
|
|
34
|
+
selfClosingVoidElements?: boolean;
|
|
35
|
+
quotes?: boolean;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export type FragmentOptions = Options & {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
mode?: "no-quirks" | "limited-quirks" | "quirks";
|
|
40
|
+
context_element?: binding.Element;
|
|
41
|
+
form_element?: binding.Element;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
export async function minify(
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
content: Buffer,
|
|
46
|
+
options?: Options
|
|
47
47
|
): Promise<binding.TransformOutput> {
|
|
48
|
-
|
|
48
|
+
return binding.minify(content, toBuffer(options ?? {}));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export async function minifyFragment(
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
content: Buffer,
|
|
53
|
+
options?: FragmentOptions
|
|
54
54
|
): Promise<binding.TransformOutput> {
|
|
55
|
-
|
|
55
|
+
return binding.minifyFragment(content, toBuffer(options ?? {}));
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export function minifySync(
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
content: Buffer,
|
|
60
|
+
options?: Options
|
|
61
61
|
): binding.TransformOutput {
|
|
62
|
-
|
|
62
|
+
return binding.minifySync(content, toBuffer(options ?? {}));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export async function minifyFragmentSync(
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
content: Buffer,
|
|
67
|
+
options?: FragmentOptions
|
|
68
68
|
): Promise<binding.TransformOutput> {
|
|
69
|
-
|
|
69
|
+
return binding.minifyFragmentSync(content, toBuffer(options ?? {}));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
function toBuffer(t: any): Buffer {
|
|
73
|
-
|
|
73
|
+
return Buffer.from(JSON.stringify(t));
|
|
74
74
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swc/html",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "Super-fast alternative for posthtml",
|
|
3
|
+
"version": "1.7.15-nightly-20240820.7",
|
|
4
|
+
"description": "Super-fast HTML minifier",
|
|
6
5
|
"homepage": "https://swc.rs",
|
|
7
6
|
"main": "./index.js",
|
|
8
7
|
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
|
@@ -22,7 +21,7 @@
|
|
|
22
21
|
"url": "https://github.com/swc-project/swc/issues"
|
|
23
22
|
},
|
|
24
23
|
"napi": {
|
|
25
|
-
"name": "html",
|
|
24
|
+
"name": "swc-html",
|
|
26
25
|
"triples": {
|
|
27
26
|
"defaults": true,
|
|
28
27
|
"additional": [
|
|
@@ -45,30 +44,14 @@
|
|
|
45
44
|
"scripts": {
|
|
46
45
|
"artifacts": "napi artifacts --dist scripts/npm",
|
|
47
46
|
"prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tagstyle npm",
|
|
48
|
-
"pack": "wasm-pack",
|
|
49
47
|
"build:ts": "tsc -d",
|
|
50
|
-
"build
|
|
51
|
-
"build": "tsc -d && napi build --platform
|
|
52
|
-
"build:dev": "tsc -d && napi build --platform --cargo-name html_node --js ./binding.js --dts binding.d.ts -p html_node --cargo-cwd ../..",
|
|
48
|
+
"build": "tsc -d && napi build --manifest-path ../../bindings/Cargo.toml --platform -p binding_html_node --js ./binding.js --dts ./binding.d.ts --release -o .",
|
|
49
|
+
"build:dev": "tsc -d && napi build --manifest-path ../../bindings/Cargo.toml --platform -p binding_html_node --js ./binding.js --dts ./binding.d.ts -o .",
|
|
53
50
|
"test": "echo 'done!'",
|
|
54
51
|
"version": "napi version -p scripts/npm"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
57
|
-
"@napi-rs/cli": "^
|
|
54
|
+
"@napi-rs/cli": "^3.0.0-alpha.43",
|
|
58
55
|
"typescript": "^5.1.6"
|
|
59
|
-
},
|
|
60
|
-
"optionalDependencies": {
|
|
61
|
-
"@swc/html-win32-x64-msvc": "0.0.28",
|
|
62
|
-
"@swc/html-darwin-x64": "0.0.28",
|
|
63
|
-
"@swc/html-linux-x64-gnu": "0.0.28",
|
|
64
|
-
"@swc/html-linux-x64-musl": "0.0.28",
|
|
65
|
-
"@swc/html-win32-ia32-msvc": "0.0.28",
|
|
66
|
-
"@swc/html-linux-arm64-gnu": "0.0.28",
|
|
67
|
-
"@swc/html-linux-arm-gnueabihf": "0.0.28",
|
|
68
|
-
"@swc/html-darwin-arm64": "0.0.28",
|
|
69
|
-
"@swc/html-android-arm64": "0.0.28",
|
|
70
|
-
"@swc/html-linux-arm64-musl": "0.0.28",
|
|
71
|
-
"@swc/html-win32-arm64-msvc": "0.0.28",
|
|
72
|
-
"@swc/html-android-arm-eabi": "0.0.28"
|
|
73
56
|
}
|
|
74
57
|
}
|
package/index.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.minifyFragmentSync = exports.minifySync = exports.minifyFragment = exports.minify = void 0;
|
|
27
|
-
const binding = __importStar(require("./binding"));
|
|
28
|
-
async function minify(content, options) {
|
|
29
|
-
return binding.minify(content, toBuffer(options !== null && options !== void 0 ? options : {}));
|
|
30
|
-
}
|
|
31
|
-
exports.minify = minify;
|
|
32
|
-
async function minifyFragment(content, options) {
|
|
33
|
-
return binding.minifyFragment(content, toBuffer(options !== null && options !== void 0 ? options : {}));
|
|
34
|
-
}
|
|
35
|
-
exports.minifyFragment = minifyFragment;
|
|
36
|
-
function minifySync(content, options) {
|
|
37
|
-
return binding.minifySync(content, toBuffer(options !== null && options !== void 0 ? options : {}));
|
|
38
|
-
}
|
|
39
|
-
exports.minifySync = minifySync;
|
|
40
|
-
async function minifyFragmentSync(content, options) {
|
|
41
|
-
return binding.minifyFragmentSync(content, toBuffer(options !== null && options !== void 0 ? options : {}));
|
|
42
|
-
}
|
|
43
|
-
exports.minifyFragmentSync = minifyFragmentSync;
|
|
44
|
-
function toBuffer(t) {
|
|
45
|
-
return Buffer.from(JSON.stringify(t));
|
|
46
|
-
}
|