@qwik.dev/optimizer 2.1.0-beta.7 → 2.1.0-beta.9

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