@swc/html 0.0.5

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.
@@ -0,0 +1,11 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export function minify(
7
+ code: Buffer,
8
+ opts: Buffer,
9
+ signal?: AbortSignal | undefined | null
10
+ ): Promise<string>;
11
+ export function minifySync(code: Buffer, opts: Buffer): string;
package/lib/binding.js ADDED
@@ -0,0 +1,246 @@
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(
29
+ join(__dirname, "html.android-arm64.node")
30
+ );
31
+ try {
32
+ if (localFileExisted) {
33
+ nativeBinding = require("./html.android-arm64.node");
34
+ } else {
35
+ nativeBinding = require("@swc/html-android-arm64");
36
+ }
37
+ } catch (e) {
38
+ loadError = e;
39
+ }
40
+ break;
41
+ case "arm":
42
+ localFileExisted = existsSync(
43
+ join(__dirname, "html.android-arm-eabi.node")
44
+ );
45
+ try {
46
+ if (localFileExisted) {
47
+ nativeBinding = require("./html.android-arm-eabi.node");
48
+ } else {
49
+ nativeBinding = require("@swc/html-android-arm-eabi");
50
+ }
51
+ } catch (e) {
52
+ loadError = e;
53
+ }
54
+ break;
55
+ default:
56
+ throw new Error(`Unsupported architecture on Android ${arch}`);
57
+ }
58
+ break;
59
+ case "win32":
60
+ switch (arch) {
61
+ case "x64":
62
+ localFileExisted = existsSync(
63
+ join(__dirname, "html.win32-x64-msvc.node")
64
+ );
65
+ try {
66
+ if (localFileExisted) {
67
+ nativeBinding = require("./html.win32-x64-msvc.node");
68
+ } else {
69
+ nativeBinding = require("@swc/html-win32-x64-msvc");
70
+ }
71
+ } catch (e) {
72
+ loadError = e;
73
+ }
74
+ break;
75
+ case "ia32":
76
+ localFileExisted = existsSync(
77
+ join(__dirname, "html.win32-ia32-msvc.node")
78
+ );
79
+ try {
80
+ if (localFileExisted) {
81
+ nativeBinding = require("./html.win32-ia32-msvc.node");
82
+ } else {
83
+ nativeBinding = require("@swc/html-win32-ia32-msvc");
84
+ }
85
+ } catch (e) {
86
+ loadError = e;
87
+ }
88
+ break;
89
+ case "arm64":
90
+ localFileExisted = existsSync(
91
+ join(__dirname, "html.win32-arm64-msvc.node")
92
+ );
93
+ try {
94
+ if (localFileExisted) {
95
+ nativeBinding = require("./html.win32-arm64-msvc.node");
96
+ } else {
97
+ nativeBinding = require("@swc/html-win32-arm64-msvc");
98
+ }
99
+ } catch (e) {
100
+ loadError = e;
101
+ }
102
+ break;
103
+ default:
104
+ throw new Error(`Unsupported architecture on Windows: ${arch}`);
105
+ }
106
+ break;
107
+ case "darwin":
108
+ switch (arch) {
109
+ case "x64":
110
+ localFileExisted = existsSync(join(__dirname, "html.darwin-x64.node"));
111
+ try {
112
+ if (localFileExisted) {
113
+ nativeBinding = require("./html.darwin-x64.node");
114
+ } else {
115
+ nativeBinding = require("@swc/html-darwin-x64");
116
+ }
117
+ } catch (e) {
118
+ loadError = e;
119
+ }
120
+ break;
121
+ case "arm64":
122
+ localFileExisted = existsSync(
123
+ join(__dirname, "html.darwin-arm64.node")
124
+ );
125
+ try {
126
+ if (localFileExisted) {
127
+ nativeBinding = require("./html.darwin-arm64.node");
128
+ } else {
129
+ nativeBinding = require("@swc/html-darwin-arm64");
130
+ }
131
+ } catch (e) {
132
+ loadError = e;
133
+ }
134
+ break;
135
+ default:
136
+ throw new Error(`Unsupported architecture on macOS: ${arch}`);
137
+ }
138
+ break;
139
+ case "freebsd":
140
+ if (arch !== "x64") {
141
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
142
+ }
143
+ localFileExisted = existsSync(join(__dirname, "html.freebsd-x64.node"));
144
+ try {
145
+ if (localFileExisted) {
146
+ nativeBinding = require("./html.freebsd-x64.node");
147
+ } else {
148
+ nativeBinding = require("@swc/html-freebsd-x64");
149
+ }
150
+ } catch (e) {
151
+ loadError = e;
152
+ }
153
+ break;
154
+ case "linux":
155
+ switch (arch) {
156
+ case "x64":
157
+ if (isMusl()) {
158
+ localFileExisted = existsSync(
159
+ join(__dirname, "html.linux-x64-musl.node")
160
+ );
161
+ try {
162
+ if (localFileExisted) {
163
+ nativeBinding = require("./html.linux-x64-musl.node");
164
+ } else {
165
+ nativeBinding = require("@swc/html-linux-x64-musl");
166
+ }
167
+ } catch (e) {
168
+ loadError = e;
169
+ }
170
+ } else {
171
+ localFileExisted = existsSync(
172
+ join(__dirname, "html.linux-x64-gnu.node")
173
+ );
174
+ try {
175
+ if (localFileExisted) {
176
+ nativeBinding = require("./html.linux-x64-gnu.node");
177
+ } else {
178
+ nativeBinding = require("@swc/html-linux-x64-gnu");
179
+ }
180
+ } catch (e) {
181
+ loadError = e;
182
+ }
183
+ }
184
+ break;
185
+ case "arm64":
186
+ if (isMusl()) {
187
+ localFileExisted = existsSync(
188
+ join(__dirname, "html.linux-arm64-musl.node")
189
+ );
190
+ try {
191
+ if (localFileExisted) {
192
+ nativeBinding = require("./html.linux-arm64-musl.node");
193
+ } else {
194
+ nativeBinding = require("@swc/html-linux-arm64-musl");
195
+ }
196
+ } catch (e) {
197
+ loadError = e;
198
+ }
199
+ } else {
200
+ localFileExisted = existsSync(
201
+ join(__dirname, "html.linux-arm64-gnu.node")
202
+ );
203
+ try {
204
+ if (localFileExisted) {
205
+ nativeBinding = require("./html.linux-arm64-gnu.node");
206
+ } else {
207
+ nativeBinding = require("@swc/html-linux-arm64-gnu");
208
+ }
209
+ } catch (e) {
210
+ loadError = e;
211
+ }
212
+ }
213
+ break;
214
+ case "arm":
215
+ localFileExisted = existsSync(
216
+ join(__dirname, "html.linux-arm-gnueabihf.node")
217
+ );
218
+ try {
219
+ if (localFileExisted) {
220
+ nativeBinding = require("./html.linux-arm-gnueabihf.node");
221
+ } else {
222
+ nativeBinding = require("@swc/html-linux-arm-gnueabihf");
223
+ }
224
+ } catch (e) {
225
+ loadError = e;
226
+ }
227
+ break;
228
+ default:
229
+ throw new Error(`Unsupported architecture on Linux: ${arch}`);
230
+ }
231
+ break;
232
+ default:
233
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
234
+ }
235
+
236
+ if (!nativeBinding) {
237
+ if (loadError) {
238
+ throw loadError;
239
+ }
240
+ throw new Error(`Failed to load native binding`);
241
+ }
242
+
243
+ const { minify, minifySync } = nativeBinding;
244
+
245
+ module.exports.minify = minify;
246
+ module.exports.minifySync = minifySync;
package/lib/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import binding = require("./binding");
2
+
3
+ export async function minify(content: Buffer, options: any): Promise<string> {
4
+ return binding.minify(content, toBuffer(options));
5
+ }
6
+
7
+ function toBuffer(t: any): Buffer {
8
+ return Buffer.from(JSON.stringify(t));
9
+ }
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@swc/html",
3
+ "version": "0.0.5",
4
+ "description": "Super-fast alternative for posthtml",
5
+ "homepage": "https://swc.rs",
6
+ "main": "./index.js",
7
+ "author": "강동윤 <kdy1997.dev@gmail.com>",
8
+ "license": "Apache-2.0",
9
+ "keywords": [
10
+ "swc",
11
+ "html"
12
+ ],
13
+ "engines": {
14
+ "node": ">=10"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/swc-project/swc.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/swc-project/swc/issues"
22
+ },
23
+ "napi": {
24
+ "name": "html",
25
+ "triples": {
26
+ "defaults": true,
27
+ "additional": [
28
+ "x86_64-unknown-linux-musl",
29
+ "x86_64-unknown-freebsd",
30
+ "i686-pc-windows-msvc",
31
+ "aarch64-unknown-linux-gnu",
32
+ "armv7-unknown-linux-gnueabihf",
33
+ "aarch64-apple-darwin",
34
+ "aarch64-linux-android",
35
+ "aarch64-unknown-linux-musl",
36
+ "aarch64-pc-windows-msvc",
37
+ "armv7-linux-androideabi"
38
+ ]
39
+ }
40
+ },
41
+ "publishConfig": {
42
+ "registry": "https://registry.npmjs.org/",
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "artifacts": "napi artifacts --dist scripts/npm",
47
+ "prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tagstyle npm",
48
+ "pack": "wasm-pack",
49
+ "build:ts": "tsc -d",
50
+ "build:wasm": "npm-run-all \"pack -- build ./crates/wasm --scope swc {1} -t {2} \" --",
51
+ "build": "tsc -d && napi build --platform --cargo-name html_node --js ./lib/binding.js --dts ./lib/binding.d.ts -p html_node --release --cargo-cwd ../..",
52
+ "build:dev": "tsc -d && napi build --platform --cargo-name html_node --js ./lib/binding.js --dts ./lib/binding.d.ts -p html_node --cargo-cwd ../..",
53
+ "test": "echo 'done!'",
54
+ "version": "napi version -p scripts/npm"
55
+ },
56
+ "optionalDependencies": {
57
+ "@swc/html-win32-x64-msvc": "0.0.7",
58
+ "@swc/html-darwin-x64": "0.0.7",
59
+ "@swc/html-linux-x64-gnu": "0.0.7",
60
+ "@swc/html-linux-x64-musl": "0.0.7",
61
+ "@swc/html-freebsd-x64": "0.0.7",
62
+ "@swc/html-win32-ia32-msvc": "0.0.7",
63
+ "@swc/html-linux-arm64-gnu": "0.0.7",
64
+ "@swc/html-linux-arm-gnueabihf": "0.0.7",
65
+ "@swc/html-darwin-arm64": "0.0.7",
66
+ "@swc/html-android-arm64": "0.0.7",
67
+ "@swc/html-linux-arm64-musl": "0.0.7",
68
+ "@swc/html-win32-arm64-msvc": "0.0.7",
69
+ "@swc/html-android-arm-eabi": "0.0.7"
70
+ }
71
+ }