@utoo/pack 1.1.2-alpha.5 → 1.1.2-lingguang

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.
Files changed (51) hide show
  1. package/README.md +2 -2
  2. package/cjs/index.d.ts +7 -6
  3. package/cjs/index.js +6 -5
  4. package/config_schema.json +1 -1
  5. package/esm/index.d.ts +7 -6
  6. package/esm/index.js +6 -5
  7. package/package.json +19 -18
  8. package/cjs/build.d.ts +0 -3
  9. package/cjs/build.js +0 -82
  10. package/cjs/dev.d.ts +0 -43
  11. package/cjs/dev.js +0 -376
  12. package/cjs/find-root.d.ts +0 -4
  13. package/cjs/find-root.js +0 -75
  14. package/cjs/hmr.d.ts +0 -80
  15. package/cjs/hmr.js +0 -286
  16. package/cjs/loaderWorkerPool.d.ts +0 -1
  17. package/cjs/loaderWorkerPool.js +0 -35
  18. package/cjs/mkcert.d.ts +0 -7
  19. package/cjs/mkcert.js +0 -183
  20. package/cjs/project.d.ts +0 -43
  21. package/cjs/project.js +0 -285
  22. package/cjs/types.d.ts +0 -284
  23. package/cjs/types.js +0 -2
  24. package/cjs/util.d.ts +0 -19
  25. package/cjs/util.js +0 -155
  26. package/cjs/webpackCompat.d.ts +0 -7
  27. package/cjs/webpackCompat.js +0 -382
  28. package/cjs/xcodeProfile.d.ts +0 -1
  29. package/cjs/xcodeProfile.js +0 -16
  30. package/esm/build.d.ts +0 -3
  31. package/esm/build.js +0 -79
  32. package/esm/dev.d.ts +0 -43
  33. package/esm/dev.js +0 -360
  34. package/esm/find-root.d.ts +0 -4
  35. package/esm/find-root.js +0 -66
  36. package/esm/hmr.d.ts +0 -80
  37. package/esm/hmr.js +0 -279
  38. package/esm/loaderWorkerPool.d.ts +0 -1
  39. package/esm/loaderWorkerPool.js +0 -32
  40. package/esm/mkcert.d.ts +0 -7
  41. package/esm/mkcert.js +0 -176
  42. package/esm/project.d.ts +0 -43
  43. package/esm/project.js +0 -247
  44. package/esm/types.d.ts +0 -284
  45. package/esm/types.js +0 -1
  46. package/esm/util.d.ts +0 -19
  47. package/esm/util.js +0 -141
  48. package/esm/webpackCompat.d.ts +0 -7
  49. package/esm/webpackCompat.js +0 -375
  50. package/esm/xcodeProfile.d.ts +0 -1
  51. package/esm/xcodeProfile.js +0 -13
@@ -1,375 +0,0 @@
1
- import path from "path";
2
- export function readWebpackConfig(projectPath, rootPath) {
3
- const projectPathOutOfRoot = projectPath === undefined
4
- ? process.cwd()
5
- : path.join(rootPath !== null && rootPath !== void 0 ? rootPath : "", projectPath);
6
- const configPath = path.join(projectPathOutOfRoot, "webpack.config.js");
7
- return require(configPath);
8
- }
9
- export function compatOptionsFromWebpack(webpackConfig, projectPath, rootPath) {
10
- const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig.entry
11
- ? webpackConfig
12
- : readWebpackConfig(projectPath, rootPath);
13
- return {
14
- config: {
15
- entry: compatEntry(entry),
16
- mode: compatMode(mode),
17
- module: compatModule(module),
18
- resolve: compatResolve(resolve),
19
- externals: compatExternals(externals),
20
- output: compatOutput(output),
21
- target: compatTarget(target),
22
- sourceMaps: compatSourceMaps(devtool),
23
- optimization: compatOptimization(optimization),
24
- define: compatFromWebpackPlugin(plugins, compatDefine),
25
- stats: compatStats(stats),
26
- },
27
- buildId: webpackConfig.name,
28
- };
29
- }
30
- function compatMode(webpackMode) {
31
- return webpackMode
32
- ? webpackMode === "none"
33
- ? "production"
34
- : webpackMode
35
- : "production";
36
- }
37
- function compatEntry(webpackEntry) {
38
- const entry = [];
39
- switch (typeof webpackEntry) {
40
- case "string":
41
- entry.push({ import: webpackEntry });
42
- break;
43
- case "object":
44
- if (Array.isArray(webpackEntry)) {
45
- webpackEntry.forEach((e) => entry.push({
46
- import: e,
47
- }));
48
- }
49
- else {
50
- Object.entries(webpackEntry).forEach(([k, v]) => {
51
- var _a;
52
- switch (typeof v) {
53
- case "string":
54
- entry.push({ name: k, import: v });
55
- break;
56
- case "object":
57
- if (!Array.isArray(v)) {
58
- switch (typeof v.import) {
59
- case "string":
60
- entry.push({
61
- name: k,
62
- import: v.import,
63
- library: ((_a = v.library) === null || _a === void 0 ? void 0 : _a.type) === "umd"
64
- ? {
65
- name: typeof v.library.name === "string"
66
- ? v.library.name
67
- : undefined,
68
- export: typeof v.library.export === "string"
69
- ? [v.library.export]
70
- : v.library.export,
71
- }
72
- : undefined,
73
- });
74
- break;
75
- default:
76
- break;
77
- }
78
- }
79
- else {
80
- if (v.length === 0) {
81
- throw "entry value items is empty";
82
- }
83
- else if (v.length === 1) {
84
- entry.push({ name: k, import: v[0] });
85
- }
86
- else {
87
- throw "multi entry items for one entry not supported yet";
88
- }
89
- }
90
- break;
91
- default:
92
- throw "non string and non object entry path not supported yet";
93
- }
94
- });
95
- }
96
- break;
97
- case "function":
98
- throw "functional entry not supported yet";
99
- default:
100
- throw "entry config not compatible now";
101
- }
102
- return entry;
103
- }
104
- function compatFromWebpackPlugin(webpackPlugins, picker) {
105
- const plugin = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.find((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
106
- return picker(plugin);
107
- }
108
- compatDefine.pluginName = "DefinePlugin";
109
- function compatDefine(maybeWebpackPluginInstance) {
110
- const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
111
- if (!definitions || typeof definitions !== "object") {
112
- return definitions;
113
- }
114
- const processedDefinitions = {};
115
- for (const [key, value] of Object.entries(definitions)) {
116
- if (typeof value === "object" && value !== null) {
117
- processedDefinitions[key] = JSON.stringify(value);
118
- }
119
- else {
120
- processedDefinitions[key] = value;
121
- }
122
- }
123
- return processedDefinitions;
124
- }
125
- function compatExternals(webpackExternals) {
126
- if (!webpackExternals) {
127
- return undefined;
128
- }
129
- let externals = {};
130
- switch (typeof webpackExternals) {
131
- case "string": {
132
- // Single string external: "lodash" -> { "lodash": "lodash" }
133
- externals[webpackExternals] = webpackExternals;
134
- break;
135
- }
136
- case "object": {
137
- if (Array.isArray(webpackExternals)) {
138
- // Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
139
- externals = webpackExternals.reduce((acc, external) => {
140
- if (typeof external === "string") {
141
- acc[external] = external;
142
- }
143
- else if (typeof external === "object" && external !== null) {
144
- Object.assign(acc, compatExternals(external));
145
- }
146
- return acc;
147
- }, {});
148
- }
149
- else if (webpackExternals instanceof RegExp) {
150
- throw "regex external not supported yet";
151
- }
152
- else {
153
- if ("byLayer" in webpackExternals) {
154
- throw "by layer external item not supported yet";
155
- }
156
- Object.entries(webpackExternals).forEach(([key, value]) => {
157
- if (typeof value === "string") {
158
- // Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
159
- if (value.includes("@") &&
160
- (value.startsWith("script ") || value.includes("://"))) {
161
- const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
162
- if (match) {
163
- const [, globalName, scriptUrl] = match;
164
- // Use utoo-pack string format: "script globalName@url"
165
- externals[key] = `script ${globalName}@${scriptUrl}`;
166
- }
167
- else {
168
- externals[key] = value;
169
- }
170
- }
171
- else {
172
- // Simple string mapping: { "react": "React" }
173
- externals[key] = value;
174
- }
175
- }
176
- else if (Array.isArray(value)) {
177
- // Array format handling
178
- if (value.length >= 2) {
179
- const [first, second] = value;
180
- // Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
181
- if (typeof first === "string" &&
182
- first.includes("://") &&
183
- typeof second === "string") {
184
- // Use utoo-pack object format for script
185
- externals[key] = {
186
- root: second,
187
- type: "script",
188
- script: first,
189
- };
190
- }
191
- else if (typeof first === "string" &&
192
- typeof second === "string") {
193
- // Handle type prefix formats
194
- if (first.startsWith("commonjs")) {
195
- externals[key] = `commonjs ${second}`;
196
- }
197
- else if (first === "module") {
198
- externals[key] = `esm ${second}`;
199
- }
200
- else if (first === "var" ||
201
- first === "global" ||
202
- first === "window") {
203
- externals[key] = second;
204
- }
205
- else if (first === "script") {
206
- // Script type without URL in array format - treat as regular script prefix
207
- externals[key] = `script ${second}`;
208
- }
209
- else {
210
- externals[key] = `${first} ${second}`;
211
- }
212
- }
213
- else {
214
- externals[key] = value[0] || key;
215
- }
216
- }
217
- else {
218
- externals[key] = value[0] || key;
219
- }
220
- }
221
- else if (typeof value === "object" && value !== null) {
222
- // Object format: handle complex configurations
223
- if ("root" in value || "commonjs" in value || "amd" in value) {
224
- // Standard webpack externals object format
225
- if (value.commonjs) {
226
- externals[key] = `commonjs ${value.commonjs}`;
227
- }
228
- else if (value.root) {
229
- externals[key] = value.root;
230
- }
231
- else if (value.amd) {
232
- externals[key] = value.amd;
233
- }
234
- else {
235
- externals[key] = key;
236
- }
237
- }
238
- else {
239
- // Treat as utoo-pack specific configuration (might already be in correct format)
240
- externals[key] = value;
241
- }
242
- }
243
- else {
244
- // Fallback to key name
245
- externals[key] = key;
246
- }
247
- });
248
- }
249
- break;
250
- }
251
- case "function": {
252
- throw "functional external not supported yet";
253
- }
254
- default:
255
- break;
256
- }
257
- return externals;
258
- }
259
- function compatModule(webpackModule) {
260
- if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
261
- return;
262
- }
263
- const moduleRules = {
264
- rules: webpackModule.rules.reduce((acc, cur) => {
265
- var _a, _b;
266
- switch (typeof cur) {
267
- case "object":
268
- if (cur) {
269
- let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
270
- if (condition) {
271
- Object.assign(acc, {
272
- ["*" + condition]: {
273
- loaders: typeof cur.use === "string"
274
- ? [cur.use]
275
- : typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
276
- ? Array.isArray(cur.use)
277
- ? cur.use.map((use) => typeof use === "string"
278
- ? { loader: use, options: {} }
279
- : {
280
- loader: use.loader,
281
- options: use.options || {},
282
- })
283
- : [
284
- {
285
- loader: cur.loader,
286
- options: cur.options || {},
287
- },
288
- ]
289
- : [],
290
- as: "*.js",
291
- },
292
- });
293
- }
294
- }
295
- break;
296
- default:
297
- break;
298
- }
299
- return acc;
300
- }, {}),
301
- };
302
- return moduleRules;
303
- }
304
- function compatResolve(webpackResolve) {
305
- if (!webpackResolve) {
306
- return;
307
- }
308
- const { alias, extensions } = webpackResolve;
309
- return {
310
- alias: alias
311
- ? Array.isArray(alias)
312
- ? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
313
- : Object.entries(alias).reduce((acc, [k, v]) => {
314
- if (typeof v === "string") {
315
- // Handle alias keys ending with $ by removing the $
316
- const aliasKey = k.endsWith("$") ? k.slice(0, -1) : k;
317
- Object.assign(acc, { [aliasKey]: v });
318
- }
319
- else {
320
- throw "non string alias value not supported yet";
321
- }
322
- return acc;
323
- }, {})
324
- : undefined,
325
- extensions,
326
- };
327
- }
328
- function compatOutput(webpackOutput) {
329
- if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
330
- throw "non string output filename not supported yet";
331
- }
332
- if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
333
- typeof webpackOutput.chunkFilename !== "string") {
334
- throw "non string output chunkFilename not supported yet";
335
- }
336
- if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.publicPath) &&
337
- typeof webpackOutput.publicPath !== "string") {
338
- throw "non string output publicPath not supported yet";
339
- }
340
- return {
341
- path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
342
- filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
343
- chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
344
- clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
345
- publicPath: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.publicPath,
346
- };
347
- }
348
- function compatTarget(webpackTarget) {
349
- return webpackTarget
350
- ? Array.isArray(webpackTarget)
351
- ? webpackTarget.join(" ")
352
- : webpackTarget
353
- : undefined;
354
- }
355
- function compatSourceMaps(webpackSourceMaps) {
356
- return !!webpackSourceMaps;
357
- }
358
- function compatOptimization(webpackOptimization) {
359
- if (!webpackOptimization) {
360
- return;
361
- }
362
- const { moduleIds, minimize, concatenateModules } = webpackOptimization;
363
- return {
364
- moduleIds: moduleIds === "named"
365
- ? "named"
366
- : moduleIds === "deterministic"
367
- ? "deterministic"
368
- : undefined,
369
- minify: minimize,
370
- concatenateModules,
371
- };
372
- }
373
- function compatStats(webpackStats) {
374
- return !!webpackStats;
375
- }
@@ -1 +0,0 @@
1
- export declare function xcodeProfilingReady(): Promise<void>;
@@ -1,13 +0,0 @@
1
- export async function xcodeProfilingReady() {
2
- await new Promise((resolve) => {
3
- const readline = require("readline");
4
- const rl = readline.createInterface({
5
- input: process.stdin,
6
- output: process.stdout,
7
- });
8
- rl.question(`Xcode profile enabled. Current process ${process.title} (${process.pid}) . Press Enter to continue...\n`, () => {
9
- rl.close();
10
- resolve();
11
- });
12
- });
13
- }