@qwik.dev/optimizer 2.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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @qwik.dev/optimizer
2
+
3
+ Runtime optimizer APIs and platform bindings for Qwik.
Binary file
@@ -0,0 +1,210 @@
1
+ /** @public */
2
+ export declare interface ComponentEntryStrategy {
3
+ type: 'component';
4
+ manual?: Record<string, string>;
5
+ }
6
+
7
+ /** @public */
8
+ export declare const createOptimizer: (optimizerOptions?: OptimizerOptions) => Promise<Optimizer>;
9
+
10
+ /** @public */
11
+ export declare interface Diagnostic {
12
+ scope: string;
13
+ category: DiagnosticCategory;
14
+ code: string | null;
15
+ file: string;
16
+ message: string;
17
+ highlights: SourceLocation[] | null;
18
+ suggestions: string[] | null;
19
+ }
20
+
21
+ /** @public */
22
+ export declare type DiagnosticCategory = 'error' | 'warning' | 'sourceError';
23
+
24
+ /** @public */
25
+ export declare type EmitMode = 'dev' | 'prod' | 'lib' | 'hmr';
26
+
27
+ /** @public */
28
+ export declare type EntryStrategy = InlineEntryStrategy | HoistEntryStrategy | SingleEntryStrategy | HookEntryStrategy | SegmentEntryStrategy | ComponentEntryStrategy | SmartEntryStrategy;
29
+
30
+ /** @public */
31
+ export declare interface HoistEntryStrategy {
32
+ type: 'hoist';
33
+ }
34
+
35
+ /** @public @deprecated Use SegmentStrategy instead */
36
+ export declare interface HookEntryStrategy {
37
+ type: 'hook';
38
+ manual?: Record<string, string>;
39
+ }
40
+
41
+ /** @public */
42
+ export declare interface InlineEntryStrategy {
43
+ type: 'inline';
44
+ }
45
+
46
+ /** @public */
47
+ export declare type MinifyMode = 'simplify' | 'none';
48
+
49
+ /** @public */
50
+ export declare interface Optimizer {
51
+ /** Transforms the input code string, does not access the file system. */
52
+ transformModules(opts: TransformModulesOptions): Promise<TransformOutput>;
53
+ /** Optimizer system use. This can be updated with a custom file system. */
54
+ sys: OptimizerSystem;
55
+ }
56
+
57
+ /** @public */
58
+ export declare interface OptimizerOptions {
59
+ sys?: OptimizerSystem;
60
+ binding?: any;
61
+ /** Inline the global styles if they're smaller than this */
62
+ inlineStylesUpToBytes?: number;
63
+ /** Enable sourcemaps */
64
+ sourcemap?: boolean;
65
+ _optimizer?: unknown;
66
+ }
67
+
68
+ /** @public */
69
+ export declare interface OptimizerSystem {
70
+ cwd: () => string;
71
+ env: SystemEnvironment;
72
+ os: string;
73
+ dynamicImport: (path: string) => Promise<any>;
74
+ strictDynamicImport: (path: string) => Promise<any>;
75
+ getInputFiles?: (rootDir: string) => Promise<TransformModuleInput[]>;
76
+ path: Path;
77
+ }
78
+
79
+ /** @public */
80
+ export declare interface Path {
81
+ resolve(...paths: string[]): string;
82
+ normalize(path: string): string;
83
+ isAbsolute(path: string): boolean;
84
+ join(...paths: string[]): string;
85
+ relative(from: string, to: string): string;
86
+ dirname(path: string): string;
87
+ basename(path: string, ext?: string): string;
88
+ extname(path: string): string;
89
+ format(pathObject: {
90
+ root: string;
91
+ dir: string;
92
+ base: string;
93
+ ext: string;
94
+ name: string;
95
+ }): string;
96
+ parse(path: string): {
97
+ root: string;
98
+ dir: string;
99
+ base: string;
100
+ ext: string;
101
+ name: string;
102
+ };
103
+ readonly sep: string;
104
+ readonly delimiter: string;
105
+ readonly win32: null;
106
+ readonly posix: Path;
107
+ }
108
+
109
+ /** @public */
110
+ export declare interface SegmentAnalysis {
111
+ origin: string;
112
+ name: string;
113
+ entry: string | null;
114
+ displayName: string;
115
+ hash: string;
116
+ canonicalFilename: string;
117
+ extension: string;
118
+ parent: string | null;
119
+ ctxKind: 'eventHandler' | 'function';
120
+ ctxName: string;
121
+ captures: boolean;
122
+ loc: [number, number];
123
+ /** The parameter names if it's a function with parameters */
124
+ paramNames?: string[];
125
+ /** The transformed names of scoped variables, if any */
126
+ captureNames?: string[];
127
+ }
128
+
129
+ /** @public */
130
+ export declare interface SegmentEntryStrategy {
131
+ type: 'segment';
132
+ manual?: Record<string, string>;
133
+ }
134
+
135
+ /** @public */
136
+ export declare interface SingleEntryStrategy {
137
+ type: 'single';
138
+ manual?: Record<string, string>;
139
+ }
140
+
141
+ /** @public */
142
+ export declare interface SmartEntryStrategy {
143
+ type: 'smart';
144
+ manual?: Record<string, string>;
145
+ }
146
+
147
+ /** @public */
148
+ export declare interface SourceLocation {
149
+ hi: number;
150
+ lo: number;
151
+ startLine: number;
152
+ startCol: number;
153
+ endLine: number;
154
+ endCol: number;
155
+ }
156
+
157
+ /** @public */
158
+ export declare type SystemEnvironment = 'node' | 'deno' | 'bun' | 'webworker' | 'browsermain' | 'unknown';
159
+
160
+ /** @public */
161
+ export declare interface TransformModule {
162
+ path: string;
163
+ isEntry: boolean;
164
+ code: string;
165
+ map: string | null;
166
+ segment: SegmentAnalysis | null;
167
+ origPath: string | null;
168
+ }
169
+
170
+ /** @public */
171
+ export declare interface TransformModuleInput {
172
+ path: string;
173
+ devPath?: string;
174
+ code: string;
175
+ }
176
+
177
+ /** @public */
178
+ export declare interface TransformModulesOptions extends TransformOptions {
179
+ input: TransformModuleInput[];
180
+ }
181
+
182
+ /** @public */
183
+ export declare interface TransformOptions {
184
+ srcDir: string;
185
+ rootDir?: string;
186
+ entryStrategy?: EntryStrategy;
187
+ minify?: MinifyMode;
188
+ sourceMaps?: boolean;
189
+ transpileTs?: boolean;
190
+ transpileJsx?: boolean;
191
+ preserveFilenames?: boolean;
192
+ explicitExtensions?: boolean;
193
+ mode?: EmitMode;
194
+ scope?: string;
195
+ stripExports?: string[];
196
+ regCtxName?: string[];
197
+ stripCtxName?: string[];
198
+ stripEventHandlers?: boolean;
199
+ isServer?: boolean;
200
+ }
201
+
202
+ /** @public */
203
+ export declare interface TransformOutput {
204
+ modules: TransformModule[];
205
+ diagnostics: Diagnostic[];
206
+ isTypeScript: boolean;
207
+ isJsx: boolean;
208
+ }
209
+
210
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +1,341 @@
1
+ function q(c = {}) {
2
+ function o(u) {
3
+ if (typeof u != "string")
4
+ throw new TypeError("Path must be a string. Received " + JSON.stringify(u));
5
+ }
6
+ function d(u, n) {
7
+ let e = "", r = 0, i = -1, l = 0, t;
8
+ for (let s = 0; s <= u.length; ++s) {
9
+ if (s < u.length)
10
+ t = u.charCodeAt(s);
11
+ else {
12
+ if (t === 47)
13
+ break;
14
+ t = 47;
15
+ }
16
+ if (t === 47) {
17
+ if (!(i === s - 1 || l === 1)) if (i !== s - 1 && l === 2) {
18
+ if (e.length < 2 || r !== 2 || e.charCodeAt(e.length - 1) !== 46 || e.charCodeAt(e.length - 2) !== 46) {
19
+ if (e.length > 2) {
20
+ const f = e.lastIndexOf("/");
21
+ if (f !== e.length - 1) {
22
+ f === -1 ? (e = "", r = 0) : (e = e.slice(0, f), r = e.length - 1 - e.lastIndexOf("/")), i = s, l = 0;
23
+ continue;
24
+ }
25
+ } else if (e.length === 2 || e.length === 1) {
26
+ e = "", r = 0, i = s, l = 0;
27
+ continue;
28
+ }
29
+ }
30
+ n && (e.length > 0 ? e += "/.." : e = "..", r = 2);
31
+ } else
32
+ e.length > 0 ? e += "/" + u.slice(i + 1, s) : e = u.slice(i + 1, s), r = s - i - 1;
33
+ i = s, l = 0;
34
+ } else t === 46 && l !== -1 ? ++l : l = -1;
35
+ }
36
+ return e;
37
+ }
38
+ function w(u, n) {
39
+ const e = n.dir || n.root, r = n.base || (n.name || "") + (n.ext || "");
40
+ return e ? e === n.root ? e + r : e + u + r : r;
41
+ }
42
+ const g = function(...n) {
43
+ let e = "", r = !1, i;
44
+ for (let l = n.length - 1; l >= -1 && !r; l--) {
45
+ let t;
46
+ l >= 0 ? t = n[l] : (i === void 0 && (c && typeof c.cwd == "function" ? i = c.cwd() : typeof process < "u" && typeof process.cwd == "function" ? i = process.cwd() : i = "/"), t = i), o(t), t.length !== 0 && (e = t + "/" + e, r = t.charCodeAt(0) === 47);
47
+ }
48
+ return e = d(e, !r), r ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
49
+ }, h = function(n) {
50
+ if (o(n), n.length === 0)
51
+ return ".";
52
+ const e = n.charCodeAt(0) === 47, r = n.charCodeAt(n.length - 1) === 47;
53
+ return n = d(n, !e), n.length === 0 && !e && (n = "."), n.length > 0 && r && (n += "/"), e ? "/" + n : n;
54
+ }, p = function(n) {
55
+ return o(n), n.length > 0 && n.charCodeAt(0) === 47;
56
+ }, A = function(...n) {
57
+ if (n.length === 0)
58
+ return ".";
59
+ let e;
60
+ for (let r = 0; r < n.length; ++r) {
61
+ const i = n[r];
62
+ o(i), i.length > 0 && (e === void 0 ? e = i : e += "/" + i);
63
+ }
64
+ return e === void 0 ? "." : h(e);
65
+ }, v = function(n, e) {
66
+ if (o(n), o(e), n === e || (n = g(n), e = g(e), n === e))
67
+ return "";
68
+ let r = 1;
69
+ for (; r < n.length && n.charCodeAt(r) === 47; ++r)
70
+ ;
71
+ const i = n.length, l = i - r;
72
+ let t = 1;
73
+ for (; t < e.length && e.charCodeAt(t) === 47; ++t)
74
+ ;
75
+ const f = e.length - t, y = l < f ? l : f;
76
+ let m = -1, a = 0;
77
+ for (; a <= y; ++a) {
78
+ if (a === y) {
79
+ if (f > y) {
80
+ if (e.charCodeAt(t + a) === 47)
81
+ return e.slice(t + a + 1);
82
+ if (a === 0)
83
+ return e.slice(t + a);
84
+ } else l > y && (n.charCodeAt(r + a) === 47 ? m = a : a === 0 && (m = 0));
85
+ break;
86
+ }
87
+ const D = n.charCodeAt(r + a), _ = e.charCodeAt(t + a);
88
+ if (D !== _)
89
+ break;
90
+ D === 47 && (m = a);
91
+ }
92
+ let b = "";
93
+ for (a = r + m + 1; a <= i; ++a)
94
+ (a === i || n.charCodeAt(a) === 47) && (b.length === 0 ? b += ".." : b += "/..");
95
+ return b.length > 0 ? b + e.slice(t + m) : (t += m, e.charCodeAt(t) === 47 && ++t, e.slice(t));
96
+ }, C = function(n) {
97
+ if (o(n), n.length === 0)
98
+ return ".";
99
+ let e = n.charCodeAt(0);
100
+ const r = e === 47;
101
+ let i = -1, l = !0;
102
+ for (let t = n.length - 1; t >= 1; --t)
103
+ if (e = n.charCodeAt(t), e === 47) {
104
+ if (!l) {
105
+ i = t;
106
+ break;
107
+ }
108
+ } else
109
+ l = !1;
110
+ return i === -1 ? r ? "/" : "." : r && i === 1 ? "//" : n.slice(0, i);
111
+ }, k = function(n, e) {
112
+ if (e !== void 0 && typeof e != "string")
113
+ throw new TypeError('"ext" argument must be a string');
114
+ o(n);
115
+ let r = 0, i = -1, l = !0, t;
116
+ if (e !== void 0 && e.length > 0 && e.length <= n.length) {
117
+ if (e.length === n.length && e === n)
118
+ return "";
119
+ let s = e.length - 1, f = -1;
120
+ for (t = n.length - 1; t >= 0; --t) {
121
+ const y = n.charCodeAt(t);
122
+ if (y === 47) {
123
+ if (!l) {
124
+ r = t + 1;
125
+ break;
126
+ }
127
+ } else
128
+ f === -1 && (l = !1, f = t + 1), s >= 0 && (y === e.charCodeAt(s) ? --s === -1 && (i = t) : (s = -1, i = f));
129
+ }
130
+ return r === i ? i = f : i === -1 && (i = n.length), n.slice(r, i);
131
+ } else {
132
+ for (t = n.length - 1; t >= 0; --t)
133
+ if (n.charCodeAt(t) === 47) {
134
+ if (!l) {
135
+ r = t + 1;
136
+ break;
137
+ }
138
+ } else i === -1 && (l = !1, i = t + 1);
139
+ return i === -1 ? "" : n.slice(r, i);
140
+ }
141
+ }, I = function(n) {
142
+ o(n);
143
+ let e = -1, r = 0, i = -1, l = !0, t = 0;
144
+ for (let s = n.length - 1; s >= 0; --s) {
145
+ const f = n.charCodeAt(s);
146
+ if (f === 47) {
147
+ if (!l) {
148
+ r = s + 1;
149
+ break;
150
+ }
151
+ continue;
152
+ }
153
+ i === -1 && (l = !1, i = s + 1), f === 46 ? e === -1 ? e = s : t !== 1 && (t = 1) : e !== -1 && (t = -1);
154
+ }
155
+ return e === -1 || i === -1 || // We saw a non-dot character immediately before the dot
156
+ t === 0 || // The (right-most) trimmed path component is exactly '..'
157
+ t === 1 && e === i - 1 && e === r + 1 ? "" : n.slice(e, i);
158
+ }, S = function(n) {
159
+ if (n === null || typeof n != "object")
160
+ throw new TypeError(
161
+ 'The "pathObject" argument must be of type Object. Received type ' + typeof n
162
+ );
163
+ return w("/", n);
164
+ }, x = function(n) {
165
+ o(n);
166
+ const e = {
167
+ root: "",
168
+ dir: "",
169
+ base: "",
170
+ ext: "",
171
+ name: ""
172
+ };
173
+ if (n.length === 0)
174
+ return e;
175
+ let r = n.charCodeAt(0), i;
176
+ const l = r === 47;
177
+ l ? (e.root = "/", i = 1) : i = 0;
178
+ let t = -1, s = 0, f = -1, y = !0, m = n.length - 1, a = 0;
179
+ for (; m >= i; --m) {
180
+ if (r = n.charCodeAt(m), r === 47) {
181
+ if (!y) {
182
+ s = m + 1;
183
+ break;
184
+ }
185
+ continue;
186
+ }
187
+ f === -1 && (y = !1, f = m + 1), r === 46 ? t === -1 ? t = m : a !== 1 && (a = 1) : t !== -1 && (a = -1);
188
+ }
189
+ return t === -1 || f === -1 || // We saw a non-dot character immediately before the dot
190
+ a === 0 || // The (right-most) trimmed path component is exactly '..'
191
+ a === 1 && t === f - 1 && t === s + 1 ? f !== -1 && (s === 0 && l ? e.base = e.name = n.slice(1, f) : e.base = e.name = n.slice(s, f)) : (s === 0 && l ? (e.name = n.slice(1, t), e.base = n.slice(1, f)) : (e.name = n.slice(s, t), e.base = n.slice(s, f)), e.ext = n.slice(t, f)), s > 0 ? e.dir = n.slice(0, s - 1) : l && (e.dir = "/"), e;
192
+ }, E = "/", P = ":";
193
+ return {
194
+ relative: v,
195
+ resolve: g,
196
+ parse: x,
197
+ format: S,
198
+ join: A,
199
+ isAbsolute: p,
200
+ basename: k,
201
+ normalize: h,
202
+ dirname: C,
203
+ extname: I,
204
+ delimiter: P,
205
+ sep: E,
206
+ win32: null,
207
+ posix: {
208
+ relative: v,
209
+ resolve: g,
210
+ parse: x,
211
+ format: S,
212
+ join: A,
213
+ isAbsolute: p,
214
+ basename: k,
215
+ normalize: h,
216
+ dirname: C,
217
+ extname: I,
218
+ delimiter: P,
219
+ sep: E,
220
+ win32: null,
221
+ posix: null
222
+ }
223
+ };
224
+ }
225
+ const z = {
226
+ darwin: {
227
+ arm64: [
228
+ {
229
+ platform: "darwin",
230
+ arch: "arm64",
231
+ abi: null,
232
+ platformArchABI: "qwik.darwin-arm64.node"
233
+ }
234
+ ]
235
+ },
236
+ win32: {
237
+ x64: [
238
+ {
239
+ platform: "win32",
240
+ arch: "x64",
241
+ abi: "msvc",
242
+ platformArchABI: "qwik.win32-x64-msvc.node"
243
+ }
244
+ ]
245
+ },
246
+ linux: {
247
+ x64: [
248
+ {
249
+ platform: "linux",
250
+ arch: "x64",
251
+ abi: "gnu",
252
+ platformArchABI: "qwik.linux-x64-gnu.node"
253
+ }
254
+ ]
255
+ }
256
+ };
257
+ async function N() {
258
+ const c = B(), o = {
259
+ dynamicImport: (d) => {
260
+ throw new Error(
261
+ `Qwik Optimizer sys.dynamicImport() not implemented, trying to import: "${d}"`
262
+ );
263
+ },
264
+ strictDynamicImport: (d) => {
265
+ throw new Error(
266
+ `Qwik Optimizer sys.strictDynamicImport() not implemented, trying to import: "${d}"`
267
+ );
268
+ },
269
+ path: null,
270
+ cwd: () => "/",
271
+ os: "unknown",
272
+ env: c
273
+ };
274
+ if (o.path = q(o), o.strictDynamicImport = o.dynamicImport = (d) => import(d), c !== "webworker" && c !== "browsermain")
275
+ try {
276
+ o.path = await o.dynamicImport("node:path"), o.cwd = () => process.cwd(), o.os = process.platform;
277
+ } catch {
278
+ }
279
+ return o;
280
+ }
281
+ async function T(c) {
282
+ const o = B();
283
+ if (o === "node" || o === "bun") {
284
+ const d = z[process.platform];
285
+ if (d) {
286
+ const w = d[process.arch];
287
+ if (w)
288
+ for (const g of w)
289
+ try {
290
+ return (await c.dynamicImport("node:module")).default.createRequire(import.meta.url)(
291
+ `../bindings/${g.platformArchABI}`
292
+ );
293
+ } catch (h) {
294
+ console.warn(
295
+ `Unable to load native binding ${g.platformArchABI}. Falling back to wasm build.`,
296
+ h?.message
297
+ );
298
+ }
299
+ }
300
+ }
301
+ if (o === "node" || o === "bun") {
302
+ const d = await c.dynamicImport("node:url"), w = c.path.dirname(d.fileURLToPath(import.meta.url)), g = c.path.join(w, "..", "bindings", "qwik_wasm_bg.wasm"), h = await c.dynamicImport("../bindings/qwik.wasm.mjs"), A = await (await c.dynamicImport("node:fs")).promises.readFile(g), v = await WebAssembly.compile(A);
303
+ return await h.default(v), h;
304
+ } else {
305
+ const d = await c.dynamicImport("../bindings/qwik.wasm.mjs");
306
+ return await d.default(), d;
307
+ }
308
+ }
309
+ const B = () => typeof Deno < "u" ? "deno" : typeof Bun < "u" ? "bun" : typeof process < "u" && typeof global < "u" && process.versions && process.versions.node ? "node" : typeof self < "u" && typeof location < "u" && typeof navigator < "u" && typeof fetch == "function" && typeof WorkerGlobalScope == "function" && typeof self.importScripts == "function" ? "webworker" : typeof window < "u" && typeof document < "u" && typeof location < "u" && typeof navigator < "u" && typeof Window == "function" && typeof fetch == "function" ? "browsermain" : "unknown", M = async (c = {}) => {
310
+ const o = c?.sys || await N(), d = c?.binding || await T(o);
311
+ return {
312
+ async transformModules(g) {
313
+ return R(d, g);
314
+ },
315
+ sys: o
316
+ };
317
+ }, R = (c, o) => c.transform_modules(L(o)), L = (c) => {
318
+ const o = {
319
+ minify: "simplify",
320
+ sourceMaps: !1,
321
+ transpileTs: !1,
322
+ transpileJsx: !1,
323
+ preserveFilenames: !1,
324
+ explicitExtensions: !1,
325
+ mode: "lib",
326
+ manualChunks: void 0,
327
+ scope: void 0,
328
+ regCtxName: void 0,
329
+ stripEventHandlers: !1,
330
+ rootDir: void 0,
331
+ stripExports: void 0,
332
+ stripCtxName: void 0,
333
+ isServer: void 0
334
+ };
335
+ return Object.entries(c).forEach(([d, w]) => {
336
+ w != null && (o[d] = w);
337
+ }), o.entryStrategy = c.entryStrategy?.type ?? "smart", o.manualChunks = c.entryStrategy?.manual ?? void 0, o;
338
+ };
339
+ export {
340
+ M as createOptimizer
341
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@qwik.dev/optimizer",
3
+ "description": "Qwik optimizer runtime and native bindings.",
4
+ "version": "2.0.0",
5
+ "bugs": "https://github.com/QwikDev/qwik/issues",
6
+ "engines": {
7
+ "node": "^20.3.0 || >=21.0.0"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "README.md",
18
+ "LICENSE",
19
+ "bindings",
20
+ "dist"
21
+ ],
22
+ "homepage": "https://qwik.dev/",
23
+ "license": "MIT",
24
+ "main": "./dist/index.mjs",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/QwikDev/qwik.git",
31
+ "directory": "packages/optimizer"
32
+ },
33
+ "sideEffects": false,
34
+ "type": "module",
35
+ "types": "./dist/index.d.ts"
36
+ }