@utoo/pack 1.1.14 → 1.1.16-alpha.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.
@@ -26,10 +26,60 @@ const find_root_1 = require("../utils/find-root");
26
26
  const mkcert_1 = require("../utils/mkcert");
27
27
  const print_server_info_1 = require("../utils/print-server-info");
28
28
  const xcodeProfile_1 = require("../utils/xcodeProfile");
29
+ function parsePath(pathStr) {
30
+ const hashIndex = pathStr.indexOf("#");
31
+ const queryIndex = pathStr.indexOf("?");
32
+ const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex);
33
+ if (hasQuery || hashIndex > -1) {
34
+ return {
35
+ pathname: pathStr.substring(0, hasQuery ? queryIndex : hashIndex),
36
+ query: hasQuery
37
+ ? pathStr.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined)
38
+ : "",
39
+ hash: hashIndex > -1 ? pathStr.slice(hashIndex) : "",
40
+ };
41
+ }
42
+ return { pathname: pathStr, query: "", hash: "" };
43
+ }
44
+ function pathHasPrefix(pathStr, prefix) {
45
+ if (typeof pathStr !== "string") {
46
+ return false;
47
+ }
48
+ const { pathname } = parsePath(pathStr);
49
+ return pathname === prefix || pathname.startsWith(prefix + "/");
50
+ }
51
+ function removePathPrefix(pathStr, prefix) {
52
+ // If the path doesn't start with the prefix we can return it as is.
53
+ if (!pathHasPrefix(pathStr, prefix)) {
54
+ return pathStr;
55
+ }
56
+ // Remove the prefix from the path via slicing.
57
+ const withoutPrefix = pathStr.slice(prefix.length);
58
+ // If the path without the prefix starts with a `/` we can return it as is.
59
+ if (withoutPrefix.startsWith("/")) {
60
+ return withoutPrefix;
61
+ }
62
+ // If the path without the prefix doesn't start with a `/` we need to add it
63
+ // back to the path to make sure it's a valid path.
64
+ return `/${withoutPrefix}`;
65
+ }
66
+ function normalizedPublicPath(publicPath) {
67
+ const escapedPublicPath = (publicPath === null || publicPath === void 0 ? void 0 : publicPath.replace(/^\/+|\/+$/g, "")) || false;
68
+ if (!escapedPublicPath) {
69
+ return "";
70
+ }
71
+ try {
72
+ if (URL.canParse(escapedPublicPath)) {
73
+ const url = new URL(escapedPublicPath).toString();
74
+ return url.endsWith("/") ? url.slice(0, -1) : url;
75
+ }
76
+ }
77
+ catch (_a) { }
78
+ return `/${escapedPublicPath}`;
79
+ }
29
80
  function serve(options, projectPath, rootPath, serverOptions) {
30
81
  const bundleOptions = (0, webpackCompat_1.resolveBundleOptions)(options, projectPath, rootPath);
31
82
  if (!rootPath) {
32
- // help user to find the rootDir automatically
33
83
  rootPath = (0, find_root_1.findRootDir)(projectPath || process.cwd());
34
84
  }
35
85
  return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
@@ -218,17 +268,28 @@ async function initialize(bundleOptions, projectPath, rootPath) {
218
268
  req.on("error", console.error);
219
269
  res.on("error", console.error);
220
270
  const handleRequest = async () => {
221
- var _a;
271
+ var _a, _b;
222
272
  if (!(req.method === "GET" || req.method === "HEAD")) {
223
273
  res.setHeader("Allow", ["GET", "HEAD"]);
224
274
  res.statusCode = 405;
225
275
  res.end();
226
276
  }
227
277
  const distRoot = path_1.default.resolve(projectPath, ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || "./dist");
278
+ const publicPath = (_b = bundleOptions.config.output) === null || _b === void 0 ? void 0 : _b.publicPath;
228
279
  try {
229
280
  const reqUrl = req.url || "";
230
- const path = url_1.default.parse(reqUrl).pathname || "";
231
- return await serveStatic(req, res, path, { root: distRoot });
281
+ let requestPath = url_1.default.parse(reqUrl).pathname || "";
282
+ if (publicPath && publicPath !== "runtime") {
283
+ const normalizedPrefix = normalizedPublicPath(publicPath);
284
+ const isAbsoluteUrl = normalizedPrefix.startsWith("http://") ||
285
+ normalizedPrefix.startsWith("https://");
286
+ if (!isAbsoluteUrl && normalizedPrefix) {
287
+ if (pathHasPrefix(requestPath, normalizedPrefix)) {
288
+ requestPath = removePathPrefix(requestPath, normalizedPrefix);
289
+ }
290
+ }
291
+ }
292
+ return await serveStatic(req, res, requestPath, { root: distRoot });
232
293
  }
233
294
  catch (err) {
234
295
  res.setHeader("Cache-Control", "private, no-cache, no-store, max-age=0, must-revalidate");
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.TurbopackInternalError = void 0;
37
37
  exports.projectFactory = projectFactory;
38
- const util_1 = require("util");
39
38
  const binding = __importStar(require("../binding"));
40
39
  const common_1 = require("../utils/common");
41
40
  const loaderWorkerPool_1 = require("./loaderWorkerPool");
@@ -55,41 +54,7 @@ async function withErrorCause(fn) {
55
54
  throw new TurbopackInternalError(nativeError);
56
55
  }
57
56
  }
58
- function ensureLoadersHaveSerializableOptions(turbopackRules) {
59
- for (const [glob, rule] of Object.entries(turbopackRules)) {
60
- if (Array.isArray(rule)) {
61
- checkLoaderItems(rule, glob);
62
- }
63
- else {
64
- checkConfigItem(rule, glob);
65
- }
66
- }
67
- function checkConfigItem(rule, glob) {
68
- if (!rule)
69
- return;
70
- if ("loaders" in rule) {
71
- checkLoaderItems(rule.loaders, glob);
72
- }
73
- else {
74
- for (const key in rule) {
75
- const inner = rule[key];
76
- if (typeof inner === "object" && inner) {
77
- checkConfigItem(inner, glob);
78
- }
79
- }
80
- }
81
- }
82
- function checkLoaderItems(loaderItems, glob) {
83
- for (const loaderItem of loaderItems) {
84
- if (typeof loaderItem !== "string" &&
85
- !(0, util_1.isDeepStrictEqual)(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
86
- throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.`);
87
- }
88
- }
89
- }
90
- }
91
57
  async function serializeConfig(config) {
92
- var _a;
93
58
  const configSerializable = { ...config };
94
59
  if (configSerializable.entry) {
95
60
  configSerializable.entry = configSerializable.entry.map((entry) => {
@@ -97,9 +62,6 @@ async function serializeConfig(config) {
97
62
  return rest;
98
63
  });
99
64
  }
100
- if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
101
- ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
102
- }
103
65
  if (configSerializable.optimization) {
104
66
  configSerializable.optimization = { ...configSerializable.optimization };
105
67
  const { modularizeImports } = configSerializable.optimization;
@@ -3,180 +3,241 @@
3
3
  "title": "ProjectOptions",
4
4
  "description": "Top-level project options configuration This represents the root structure of utoopack.json",
5
5
  "type": "object",
6
- "required": [
7
- "config"
8
- ],
9
6
  "properties": {
10
- "config": {
11
- "description": "Main configuration object",
12
- "allOf": [
13
- {
14
- "$ref": "#/definitions/SchemaConfig"
15
- }
16
- ]
17
- },
18
- "projectPath": {
19
- "description": "Project path relative to root",
7
+ "buildId": {
8
+ "description": "The build id.",
20
9
  "type": [
21
10
  "string",
22
11
  "null"
23
12
  ]
24
13
  },
25
- "rootPath": {
26
- "description": "Root path of the project",
14
+ "cacheHandler": {
15
+ "description": "Cache handler configuration",
27
16
  "type": [
28
17
  "string",
29
18
  "null"
30
19
  ]
31
- }
32
- },
33
- "definitions": {
34
- "SchemaConfig": {
35
- "description": "Main configuration structure that mirrors pack_core::config::Config All fields are derived from the original Config structure in pack-core",
36
- "type": "object",
37
- "properties": {
38
- "cacheHandler": {
39
- "description": "Cache handler configuration",
40
- "type": [
41
- "string",
42
- "null"
43
- ]
44
- },
45
- "define": {
46
- "description": "Define variables for build-time replacement",
47
- "type": [
48
- "object",
49
- "null"
50
- ],
51
- "additionalProperties": true
52
- },
53
- "entry": {
54
- "description": "Entry points for the build",
55
- "type": [
56
- "array",
57
- "null"
58
- ],
59
- "items": {
60
- "$ref": "#/definitions/SchemaEntryOptions"
61
- }
62
- },
63
- "experimental": {
64
- "description": "Experimental features",
65
- "anyOf": [
66
- {
67
- "$ref": "#/definitions/SchemaExperimentalConfig"
68
- },
69
- {
70
- "type": "null"
71
- }
72
- ]
73
- },
74
- "externals": {
75
- "description": "External dependencies configuration",
76
- "type": [
77
- "object",
78
- "null"
79
- ],
80
- "additionalProperties": {
81
- "$ref": "#/definitions/SchemaExternalConfig"
82
- }
83
- },
84
- "images": {
85
- "description": "Image processing configuration",
86
- "anyOf": [
87
- {
88
- "$ref": "#/definitions/SchemaImageConfig"
89
- },
90
- {
91
- "type": "null"
92
- }
93
- ]
20
+ },
21
+ "define": {
22
+ "description": "Define variables for build-time replacement",
23
+ "type": [
24
+ "object",
25
+ "null"
26
+ ],
27
+ "additionalProperties": true
28
+ },
29
+ "defineEnv": {
30
+ "description": "A map of environment variables which should get injected at compile time.",
31
+ "anyOf": [
32
+ {
33
+ "$ref": "#/definitions/SchemaDefineEnv"
94
34
  },
95
- "mode": {
96
- "description": "Build mode",
97
- "type": [
98
- "string",
99
- "null"
100
- ]
35
+ {
36
+ "type": "null"
37
+ }
38
+ ]
39
+ },
40
+ "dev": {
41
+ "description": "Whether to run in development mode",
42
+ "type": [
43
+ "boolean",
44
+ "null"
45
+ ]
46
+ },
47
+ "devServer": {
48
+ "description": "Development server configuration",
49
+ "anyOf": [
50
+ {
51
+ "$ref": "#/definitions/SchemaDevServer"
101
52
  },
102
- "module": {
103
- "description": "Module configuration",
104
- "anyOf": [
105
- {
106
- "$ref": "#/definitions/SchemaModuleConfig"
107
- },
108
- {
109
- "type": "null"
110
- }
111
- ]
53
+ {
54
+ "type": "null"
55
+ }
56
+ ]
57
+ },
58
+ "entry": {
59
+ "description": "Entry points for the build",
60
+ "type": [
61
+ "array",
62
+ "null"
63
+ ],
64
+ "items": {
65
+ "$ref": "#/definitions/SchemaEntryOptions"
66
+ }
67
+ },
68
+ "experimental": {
69
+ "description": "Experimental features",
70
+ "anyOf": [
71
+ {
72
+ "$ref": "#/definitions/SchemaExperimentalConfig"
112
73
  },
113
- "optimization": {
114
- "description": "Build optimization settings",
115
- "anyOf": [
116
- {
117
- "$ref": "#/definitions/SchemaOptimizationConfig"
118
- },
119
- {
120
- "type": "null"
121
- }
122
- ]
74
+ {
75
+ "type": "null"
76
+ }
77
+ ]
78
+ },
79
+ "externals": {
80
+ "description": "External dependencies configuration",
81
+ "type": [
82
+ "object",
83
+ "null"
84
+ ],
85
+ "additionalProperties": {
86
+ "$ref": "#/definitions/SchemaExternalConfig"
87
+ }
88
+ },
89
+ "images": {
90
+ "description": "Image processing configuration",
91
+ "anyOf": [
92
+ {
93
+ "$ref": "#/definitions/SchemaImageConfig"
123
94
  },
124
- "output": {
125
- "description": "Output configuration",
126
- "anyOf": [
127
- {
128
- "$ref": "#/definitions/SchemaOutputConfig"
129
- },
130
- {
131
- "type": "null"
132
- }
133
- ]
95
+ {
96
+ "type": "null"
97
+ }
98
+ ]
99
+ },
100
+ "mode": {
101
+ "description": "Build mode",
102
+ "type": [
103
+ "string",
104
+ "null"
105
+ ]
106
+ },
107
+ "module": {
108
+ "description": "Module configuration",
109
+ "anyOf": [
110
+ {
111
+ "$ref": "#/definitions/SchemaModuleConfig"
134
112
  },
135
- "persistentCaching": {
136
- "description": "Enable persistent caching",
137
- "type": [
138
- "boolean",
139
- "null"
140
- ]
113
+ {
114
+ "type": "null"
115
+ }
116
+ ]
117
+ },
118
+ "nodePolyfill": {
119
+ "description": "Enable Node.js polyfills for browser builds",
120
+ "type": [
121
+ "boolean",
122
+ "null"
123
+ ]
124
+ },
125
+ "optimization": {
126
+ "description": "Build optimization settings",
127
+ "anyOf": [
128
+ {
129
+ "$ref": "#/definitions/SchemaOptimizationConfig"
141
130
  },
142
- "resolve": {
143
- "description": "Resolve configuration",
144
- "anyOf": [
145
- {
146
- "$ref": "#/definitions/SchemaResolveConfig"
147
- },
148
- {
149
- "type": "null"
150
- }
151
- ]
131
+ {
132
+ "type": "null"
133
+ }
134
+ ]
135
+ },
136
+ "output": {
137
+ "description": "Output configuration",
138
+ "anyOf": [
139
+ {
140
+ "$ref": "#/definitions/SchemaOutputConfig"
152
141
  },
153
- "sourceMaps": {
154
- "description": "Enable source maps",
155
- "type": [
156
- "boolean",
157
- "null"
158
- ]
142
+ {
143
+ "type": "null"
144
+ }
145
+ ]
146
+ },
147
+ "packPath": {
148
+ "description": "Absolute path for @utoo/pack",
149
+ "type": [
150
+ "string",
151
+ "null"
152
+ ]
153
+ },
154
+ "persistentCaching": {
155
+ "description": "Enable persistent caching",
156
+ "type": [
157
+ "boolean",
158
+ "null"
159
+ ]
160
+ },
161
+ "processEnv": {
162
+ "description": "A map of environment variables to use when compiling code.",
163
+ "type": [
164
+ "object",
165
+ "null"
166
+ ],
167
+ "additionalProperties": {
168
+ "type": "string"
169
+ }
170
+ },
171
+ "projectPath": {
172
+ "description": "A path inside the root_path which contains the app directories.",
173
+ "type": [
174
+ "string",
175
+ "null"
176
+ ]
177
+ },
178
+ "resolve": {
179
+ "description": "Resolve configuration",
180
+ "anyOf": [
181
+ {
182
+ "$ref": "#/definitions/SchemaResolveConfig"
159
183
  },
160
- "styles": {
161
- "description": "Style processing configuration",
162
- "anyOf": [
163
- {
164
- "$ref": "#/definitions/SchemaStyleConfig"
165
- },
166
- {
167
- "type": "null"
168
- }
169
- ]
184
+ {
185
+ "type": "null"
186
+ }
187
+ ]
188
+ },
189
+ "rootPath": {
190
+ "description": "A root path from which all files must be nested under.",
191
+ "type": [
192
+ "string",
193
+ "null"
194
+ ]
195
+ },
196
+ "sourceMaps": {
197
+ "description": "Enable source maps",
198
+ "type": [
199
+ "boolean",
200
+ "null"
201
+ ]
202
+ },
203
+ "stats": {
204
+ "description": "Enable build statistics",
205
+ "type": [
206
+ "boolean",
207
+ "null"
208
+ ]
209
+ },
210
+ "styles": {
211
+ "description": "Style processing configuration",
212
+ "anyOf": [
213
+ {
214
+ "$ref": "#/definitions/SchemaStyleConfig"
170
215
  },
171
- "target": {
172
- "description": "Target environment",
173
- "type": [
174
- "string",
175
- "null"
176
- ]
216
+ {
217
+ "type": "null"
177
218
  }
178
- }
219
+ ]
179
220
  },
221
+ "target": {
222
+ "description": "Target environment",
223
+ "type": [
224
+ "string",
225
+ "null"
226
+ ]
227
+ },
228
+ "watch": {
229
+ "description": "Filesystem watcher options.",
230
+ "anyOf": [
231
+ {
232
+ "$ref": "#/definitions/SchemaWatchOptions"
233
+ },
234
+ {
235
+ "type": "null"
236
+ }
237
+ ]
238
+ }
239
+ },
240
+ "definitions": {
180
241
  "SchemaConfigConditionItem": {
181
242
  "description": "Configuration condition item",
182
243
  "type": "object",
@@ -238,20 +299,80 @@
238
299
  ]
239
300
  },
240
301
  "SchemaCopyItem": {
241
- "description": "Copy item configuration",
302
+ "description": "Copy item configuration Can be either a string (source path) or an object with from and optional to",
303
+ "anyOf": [
304
+ {
305
+ "description": "String variant: source path (destination will be same as source)",
306
+ "type": "string"
307
+ },
308
+ {
309
+ "description": "Object variant: source path and optional destination path",
310
+ "type": "object",
311
+ "required": [
312
+ "from"
313
+ ],
314
+ "properties": {
315
+ "from": {
316
+ "description": "Source path to copy from",
317
+ "type": "string"
318
+ },
319
+ "to": {
320
+ "description": "Destination path to copy to (optional, defaults to same as from)",
321
+ "type": [
322
+ "string",
323
+ "null"
324
+ ]
325
+ }
326
+ }
327
+ }
328
+ ]
329
+ },
330
+ "SchemaDefineEnv": {
331
+ "description": "Environment variables for build-time injection",
242
332
  "type": "object",
243
- "required": [
244
- "from",
245
- "to"
246
- ],
247
333
  "properties": {
248
- "from": {
249
- "description": "Source path to copy from",
250
- "type": "string"
334
+ "client": {
335
+ "description": "Client-side environment variables",
336
+ "type": [
337
+ "array",
338
+ "null"
339
+ ],
340
+ "items": {
341
+ "$ref": "#/definitions/SchemaEnvVar"
342
+ }
251
343
  },
252
- "to": {
253
- "description": "Destination path to copy to",
254
- "type": "string"
344
+ "edge": {
345
+ "description": "Edge-side environment variables",
346
+ "type": [
347
+ "array",
348
+ "null"
349
+ ],
350
+ "items": {
351
+ "$ref": "#/definitions/SchemaEnvVar"
352
+ }
353
+ },
354
+ "nodejs": {
355
+ "description": "Node.js environment variables",
356
+ "type": [
357
+ "array",
358
+ "null"
359
+ ],
360
+ "items": {
361
+ "$ref": "#/definitions/SchemaEnvVar"
362
+ }
363
+ }
364
+ }
365
+ },
366
+ "SchemaDevServer": {
367
+ "description": "Development server configuration",
368
+ "type": "object",
369
+ "properties": {
370
+ "hot": {
371
+ "description": "Enable hot module replacement",
372
+ "type": [
373
+ "boolean",
374
+ "null"
375
+ ]
255
376
  }
256
377
  }
257
378
  },
@@ -262,6 +383,17 @@
262
383
  "import"
263
384
  ],
264
385
  "properties": {
386
+ "html": {
387
+ "description": "HTML generation configuration for this entry",
388
+ "anyOf": [
389
+ {
390
+ "$ref": "#/definitions/SchemaHtmlConfig"
391
+ },
392
+ {
393
+ "type": "null"
394
+ }
395
+ ]
396
+ },
265
397
  "import": {
266
398
  "description": "Import path for the entry point",
267
399
  "type": "string"
@@ -286,6 +418,24 @@
286
418
  }
287
419
  }
288
420
  },
421
+ "SchemaEnvVar": {
422
+ "description": "Environment variable pair",
423
+ "type": "object",
424
+ "required": [
425
+ "name",
426
+ "value"
427
+ ],
428
+ "properties": {
429
+ "name": {
430
+ "description": "Variable name",
431
+ "type": "string"
432
+ },
433
+ "value": {
434
+ "description": "Variable value",
435
+ "type": "string"
436
+ }
437
+ }
438
+ },
289
439
  "SchemaExperimentalConfig": {
290
440
  "description": "Experimental features configuration",
291
441
  "type": "object",
@@ -515,6 +665,58 @@
515
665
  }
516
666
  }
517
667
  },
668
+ "SchemaHtmlConfig": {
669
+ "description": "HTML generation configuration",
670
+ "type": "object",
671
+ "properties": {
672
+ "filename": {
673
+ "description": "Output filename for the generated HTML",
674
+ "type": [
675
+ "string",
676
+ "null"
677
+ ]
678
+ },
679
+ "inject": {
680
+ "description": "Where to inject scripts (true, false, \"body\", \"head\")"
681
+ },
682
+ "meta": {
683
+ "description": "Meta tags configuration",
684
+ "type": [
685
+ "object",
686
+ "null"
687
+ ],
688
+ "additionalProperties": true
689
+ },
690
+ "scriptLoading": {
691
+ "description": "Script loading strategy (\"blocking\", \"defer\", \"module\")",
692
+ "type": [
693
+ "string",
694
+ "null"
695
+ ]
696
+ },
697
+ "template": {
698
+ "description": "Path to the HTML template file",
699
+ "type": [
700
+ "string",
701
+ "null"
702
+ ]
703
+ },
704
+ "templateContent": {
705
+ "description": "Inline HTML template content",
706
+ "type": [
707
+ "string",
708
+ "null"
709
+ ]
710
+ },
711
+ "title": {
712
+ "description": "Title for the generated HTML",
713
+ "type": [
714
+ "string",
715
+ "null"
716
+ ]
717
+ }
718
+ }
719
+ },
518
720
  "SchemaImageConfig": {
519
721
  "description": "Image configuration",
520
722
  "type": "object",
@@ -553,6 +755,18 @@
553
755
  }
554
756
  }
555
757
  },
758
+ "SchemaLoaderItem": {
759
+ "description": "Loader configuration item",
760
+ "anyOf": [
761
+ {
762
+ "description": "Loader name",
763
+ "type": "string"
764
+ },
765
+ {
766
+ "description": "Loader with options"
767
+ }
768
+ ]
769
+ },
556
770
  "SchemaModularizeImportPackageConfig": {
557
771
  "description": "Modularize import package configuration",
558
772
  "type": "object",
@@ -617,7 +831,9 @@
617
831
  "object",
618
832
  "null"
619
833
  ],
620
- "additionalProperties": true
834
+ "additionalProperties": {
835
+ "$ref": "#/definitions/SchemaModuleRule"
836
+ }
621
837
  }
622
838
  }
623
839
  },
@@ -629,6 +845,47 @@
629
845
  "deterministic"
630
846
  ]
631
847
  },
848
+ "SchemaModuleRule": {
849
+ "description": "Module rule configuration",
850
+ "anyOf": [
851
+ {
852
+ "description": "Shorthand for a single loader",
853
+ "type": "string"
854
+ },
855
+ {
856
+ "description": "Full rule configuration",
857
+ "allOf": [
858
+ {
859
+ "$ref": "#/definitions/SchemaRuleConfigItem"
860
+ }
861
+ ]
862
+ },
863
+ {
864
+ "description": "Multiple rule configurations",
865
+ "type": "array",
866
+ "items": {
867
+ "$ref": "#/definitions/SchemaModuleRuleItem"
868
+ }
869
+ }
870
+ ]
871
+ },
872
+ "SchemaModuleRuleItem": {
873
+ "description": "Item in a module rule array",
874
+ "anyOf": [
875
+ {
876
+ "description": "Shorthand for a single loader",
877
+ "type": "string"
878
+ },
879
+ {
880
+ "description": "Full rule configuration",
881
+ "allOf": [
882
+ {
883
+ "$ref": "#/definitions/SchemaRuleConfigItem"
884
+ }
885
+ ]
886
+ }
887
+ ]
888
+ },
632
889
  "SchemaOptimizationConfig": {
633
890
  "description": "Optimization configuration",
634
891
  "type": "object",
@@ -668,6 +925,13 @@
668
925
  }
669
926
  ]
670
927
  },
928
+ "nestedAsyncChunking": {
929
+ "description": "Whether to enable nested async chunking",
930
+ "type": [
931
+ "boolean",
932
+ "null"
933
+ ]
934
+ },
671
935
  "noMangling": {
672
936
  "description": "Whether to disable name mangling",
673
937
  "type": [
@@ -696,6 +960,20 @@
696
960
  }
697
961
  ]
698
962
  },
963
+ "removeUnusedExports": {
964
+ "description": "Whether to remove unused exports",
965
+ "type": [
966
+ "boolean",
967
+ "null"
968
+ ]
969
+ },
970
+ "removeUnusedImports": {
971
+ "description": "Whether to remove unused imports",
972
+ "type": [
973
+ "boolean",
974
+ "null"
975
+ ]
976
+ },
699
977
  "splitChunks": {
700
978
  "description": "Split chunks configuration",
701
979
  "type": [
@@ -722,6 +1000,13 @@
722
1000
  "boolean",
723
1001
  "null"
724
1002
  ]
1003
+ },
1004
+ "wasmAsAsset": {
1005
+ "description": "Whether to bunle wasm as asset. Defaults to false. When false, WASM files will be output as static assets.",
1006
+ "type": [
1007
+ "boolean",
1008
+ "null"
1009
+ ]
725
1010
  }
726
1011
  }
727
1012
  },
@@ -855,6 +1140,42 @@
855
1140
  }
856
1141
  }
857
1142
  },
1143
+ "SchemaRuleConfigItem": {
1144
+ "description": "Full module rule configuration",
1145
+ "type": "object",
1146
+ "required": [
1147
+ "loaders"
1148
+ ],
1149
+ "properties": {
1150
+ "condition": {
1151
+ "description": "Condition for applying the rule",
1152
+ "default": null,
1153
+ "anyOf": [
1154
+ {
1155
+ "$ref": "#/definitions/SchemaConfigConditionItem"
1156
+ },
1157
+ {
1158
+ "type": "null"
1159
+ }
1160
+ ]
1161
+ },
1162
+ "loaders": {
1163
+ "description": "Loaders to apply",
1164
+ "type": "array",
1165
+ "items": {
1166
+ "$ref": "#/definitions/SchemaLoaderItem"
1167
+ }
1168
+ },
1169
+ "renameAs": {
1170
+ "description": "Rename the module as another extension",
1171
+ "default": null,
1172
+ "type": [
1173
+ "string",
1174
+ "null"
1175
+ ]
1176
+ }
1177
+ }
1178
+ },
858
1179
  "SchemaSplitChunkConfig": {
859
1180
  "description": "Split chunk configuration",
860
1181
  "type": "object",
@@ -928,6 +1249,28 @@
928
1249
  }
929
1250
  }
930
1251
  ]
1252
+ },
1253
+ "SchemaWatchOptions": {
1254
+ "description": "Filesystem watcher options",
1255
+ "type": "object",
1256
+ "required": [
1257
+ "enable"
1258
+ ],
1259
+ "properties": {
1260
+ "enable": {
1261
+ "description": "Whether to watch the filesystem for file changes.",
1262
+ "type": "boolean"
1263
+ },
1264
+ "pollInterval": {
1265
+ "description": "Enable polling at a certain interval if the native file watching doesn't work (e.g. docker).",
1266
+ "type": [
1267
+ "integer",
1268
+ "null"
1269
+ ],
1270
+ "format": "uint64",
1271
+ "minimum": 0.0
1272
+ }
1273
+ }
931
1274
  }
932
1275
  }
933
1276
  }
@@ -12,10 +12,60 @@ import { findRootDir } from "../utils/find-root";
12
12
  import { createSelfSignedCertificate } from "../utils/mkcert";
13
13
  import { printServerInfo } from "../utils/print-server-info";
14
14
  import { xcodeProfilingReady } from "../utils/xcodeProfile";
15
+ function parsePath(pathStr) {
16
+ const hashIndex = pathStr.indexOf("#");
17
+ const queryIndex = pathStr.indexOf("?");
18
+ const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex);
19
+ if (hasQuery || hashIndex > -1) {
20
+ return {
21
+ pathname: pathStr.substring(0, hasQuery ? queryIndex : hashIndex),
22
+ query: hasQuery
23
+ ? pathStr.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined)
24
+ : "",
25
+ hash: hashIndex > -1 ? pathStr.slice(hashIndex) : "",
26
+ };
27
+ }
28
+ return { pathname: pathStr, query: "", hash: "" };
29
+ }
30
+ function pathHasPrefix(pathStr, prefix) {
31
+ if (typeof pathStr !== "string") {
32
+ return false;
33
+ }
34
+ const { pathname } = parsePath(pathStr);
35
+ return pathname === prefix || pathname.startsWith(prefix + "/");
36
+ }
37
+ function removePathPrefix(pathStr, prefix) {
38
+ // If the path doesn't start with the prefix we can return it as is.
39
+ if (!pathHasPrefix(pathStr, prefix)) {
40
+ return pathStr;
41
+ }
42
+ // Remove the prefix from the path via slicing.
43
+ const withoutPrefix = pathStr.slice(prefix.length);
44
+ // If the path without the prefix starts with a `/` we can return it as is.
45
+ if (withoutPrefix.startsWith("/")) {
46
+ return withoutPrefix;
47
+ }
48
+ // If the path without the prefix doesn't start with a `/` we need to add it
49
+ // back to the path to make sure it's a valid path.
50
+ return `/${withoutPrefix}`;
51
+ }
52
+ function normalizedPublicPath(publicPath) {
53
+ const escapedPublicPath = (publicPath === null || publicPath === void 0 ? void 0 : publicPath.replace(/^\/+|\/+$/g, "")) || false;
54
+ if (!escapedPublicPath) {
55
+ return "";
56
+ }
57
+ try {
58
+ if (URL.canParse(escapedPublicPath)) {
59
+ const url = new URL(escapedPublicPath).toString();
60
+ return url.endsWith("/") ? url.slice(0, -1) : url;
61
+ }
62
+ }
63
+ catch (_a) { }
64
+ return `/${escapedPublicPath}`;
65
+ }
15
66
  export function serve(options, projectPath, rootPath, serverOptions) {
16
67
  const bundleOptions = resolveBundleOptions(options, projectPath, rootPath);
17
68
  if (!rootPath) {
18
- // help user to find the rootDir automatically
19
69
  rootPath = findRootDir(projectPath || process.cwd());
20
70
  }
21
71
  return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
@@ -204,17 +254,28 @@ export async function initialize(bundleOptions, projectPath, rootPath) {
204
254
  req.on("error", console.error);
205
255
  res.on("error", console.error);
206
256
  const handleRequest = async () => {
207
- var _a;
257
+ var _a, _b;
208
258
  if (!(req.method === "GET" || req.method === "HEAD")) {
209
259
  res.setHeader("Allow", ["GET", "HEAD"]);
210
260
  res.statusCode = 405;
211
261
  res.end();
212
262
  }
213
263
  const distRoot = path.resolve(projectPath, ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || "./dist");
264
+ const publicPath = (_b = bundleOptions.config.output) === null || _b === void 0 ? void 0 : _b.publicPath;
214
265
  try {
215
266
  const reqUrl = req.url || "";
216
- const path = url.parse(reqUrl).pathname || "";
217
- return await serveStatic(req, res, path, { root: distRoot });
267
+ let requestPath = url.parse(reqUrl).pathname || "";
268
+ if (publicPath && publicPath !== "runtime") {
269
+ const normalizedPrefix = normalizedPublicPath(publicPath);
270
+ const isAbsoluteUrl = normalizedPrefix.startsWith("http://") ||
271
+ normalizedPrefix.startsWith("https://");
272
+ if (!isAbsoluteUrl && normalizedPrefix) {
273
+ if (pathHasPrefix(requestPath, normalizedPrefix)) {
274
+ requestPath = removePathPrefix(requestPath, normalizedPrefix);
275
+ }
276
+ }
277
+ }
278
+ return await serveStatic(req, res, requestPath, { root: distRoot });
218
279
  }
219
280
  catch (err) {
220
281
  res.setHeader("Cache-Control", "private, no-cache, no-store, max-age=0, must-revalidate");
@@ -1,4 +1,3 @@
1
- import { isDeepStrictEqual } from "util";
2
1
  import * as binding from "../binding";
3
2
  import { rustifyEnv } from "../utils/common";
4
3
  import { runLoaderWorkerPool } from "./loaderWorkerPool";
@@ -17,41 +16,7 @@ async function withErrorCause(fn) {
17
16
  throw new TurbopackInternalError(nativeError);
18
17
  }
19
18
  }
20
- function ensureLoadersHaveSerializableOptions(turbopackRules) {
21
- for (const [glob, rule] of Object.entries(turbopackRules)) {
22
- if (Array.isArray(rule)) {
23
- checkLoaderItems(rule, glob);
24
- }
25
- else {
26
- checkConfigItem(rule, glob);
27
- }
28
- }
29
- function checkConfigItem(rule, glob) {
30
- if (!rule)
31
- return;
32
- if ("loaders" in rule) {
33
- checkLoaderItems(rule.loaders, glob);
34
- }
35
- else {
36
- for (const key in rule) {
37
- const inner = rule[key];
38
- if (typeof inner === "object" && inner) {
39
- checkConfigItem(inner, glob);
40
- }
41
- }
42
- }
43
- }
44
- function checkLoaderItems(loaderItems, glob) {
45
- for (const loaderItem of loaderItems) {
46
- if (typeof loaderItem !== "string" &&
47
- !isDeepStrictEqual(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
48
- throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. Ensure that options passed are plain JavaScript objects and values.`);
49
- }
50
- }
51
- }
52
- }
53
19
  async function serializeConfig(config) {
54
- var _a;
55
20
  const configSerializable = { ...config };
56
21
  if (configSerializable.entry) {
57
22
  configSerializable.entry = configSerializable.entry.map((entry) => {
@@ -59,9 +24,6 @@ async function serializeConfig(config) {
59
24
  return rest;
60
25
  });
61
26
  }
62
- if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
63
- ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
64
- }
65
27
  if (configSerializable.optimization) {
66
28
  configSerializable.optimization = { ...configSerializable.optimization };
67
29
  const { modularizeImports } = configSerializable.optimization;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.1.14",
3
+ "version": "1.1.16-alpha.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@babel/code-frame": "7.22.5",
41
41
  "@swc/helpers": "0.5.15",
42
- "@utoo/pack-shared": "1.1.14",
42
+ "@utoo/pack-shared": "1.1.16-alpha.0",
43
43
  "@utoo/style-loader": "^1.0.0",
44
44
  "domparser-rs": "^0.0.5",
45
45
  "find-up": "4.1.0",
@@ -86,12 +86,12 @@
86
86
  },
87
87
  "repository": "git@github.com:utooland/utoo.git",
88
88
  "optionalDependencies": {
89
- "@utoo/pack-darwin-arm64": "1.1.14",
90
- "@utoo/pack-darwin-x64": "1.1.14",
91
- "@utoo/pack-linux-arm64-gnu": "1.1.14",
92
- "@utoo/pack-linux-arm64-musl": "1.1.14",
93
- "@utoo/pack-linux-x64-gnu": "1.1.14",
94
- "@utoo/pack-linux-x64-musl": "1.1.14",
95
- "@utoo/pack-win32-x64-msvc": "1.1.14"
89
+ "@utoo/pack-darwin-arm64": "1.1.16-alpha.0",
90
+ "@utoo/pack-darwin-x64": "1.1.16-alpha.0",
91
+ "@utoo/pack-linux-arm64-gnu": "1.1.16-alpha.0",
92
+ "@utoo/pack-linux-arm64-musl": "1.1.16-alpha.0",
93
+ "@utoo/pack-linux-x64-gnu": "1.1.16-alpha.0",
94
+ "@utoo/pack-linux-x64-musl": "1.1.16-alpha.0",
95
+ "@utoo/pack-win32-x64-msvc": "1.1.16-alpha.0"
96
96
  }
97
97
  }