@utoo/pack 0.0.1-alpha.18 → 0.0.1-alpha.2

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.
@@ -1,341 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compatOptionsFromWebpack = compatOptionsFromWebpack;
4
- function compatOptionsFromWebpack(webpackConfig) {
5
- const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
6
- return {
7
- config: {
8
- entry: compatEntry(entry),
9
- mode: compatMode(mode),
10
- module: compatModule(module),
11
- resolve: compatResolve(resolve),
12
- externals: compatExternals(externals),
13
- output: compatOutput(output),
14
- target: compatTarget(target),
15
- sourceMaps: compatSourceMaps(devtool),
16
- optimization: compatOptimization(optimization),
17
- define: compatFromWebpackPlugin(plugins, compatDefine),
18
- stats: compatStats(stats),
19
- },
20
- buildId: webpackConfig.name,
21
- };
22
- }
23
- function compatMode(webpackMode) {
24
- return webpackMode
25
- ? webpackMode === "none"
26
- ? "production"
27
- : webpackMode
28
- : "production";
29
- }
30
- function compatEntry(webpackEntry) {
31
- const entry = [];
32
- switch (typeof webpackEntry) {
33
- case "string":
34
- entry.push({ import: webpackEntry });
35
- break;
36
- case "object":
37
- if (Array.isArray(webpackEntry)) {
38
- webpackEntry.forEach((e) => entry.push({
39
- import: e,
40
- }));
41
- }
42
- else {
43
- Object.entries(webpackEntry).forEach(([k, v]) => {
44
- var _a;
45
- switch (typeof v) {
46
- case "string":
47
- entry.push({ name: k, import: v });
48
- break;
49
- case "object":
50
- if (!Array.isArray(v)) {
51
- switch (typeof v.import) {
52
- case "string":
53
- entry.push({
54
- name: k,
55
- import: v.import,
56
- library: ((_a = v.library) === null || _a === void 0 ? void 0 : _a.type) === "umd"
57
- ? {
58
- name: typeof v.library.name === "string"
59
- ? v.library.name
60
- : undefined,
61
- export: typeof v.library.export === "string"
62
- ? [v.library.export]
63
- : v.library.export,
64
- }
65
- : undefined,
66
- });
67
- break;
68
- default:
69
- break;
70
- }
71
- }
72
- else {
73
- throw "multi entry items for one entry not supported yet";
74
- }
75
- break;
76
- default:
77
- throw "non string and non object entry path not supported yet";
78
- }
79
- });
80
- }
81
- break;
82
- case "function":
83
- throw "functional entry not supported yet";
84
- default:
85
- throw "entry config not compatible now";
86
- }
87
- return entry;
88
- }
89
- function compatFromWebpackPlugin(webpackPlugins, picker) {
90
- const plugin = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.find((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
91
- return picker(plugin);
92
- }
93
- compatDefine.pluginName = "DefinePlugin";
94
- function compatDefine(maybeWebpackPluginInstance) {
95
- return maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
96
- }
97
- function compatExternals(webpackExternals) {
98
- if (!webpackExternals) {
99
- return undefined;
100
- }
101
- let externals = {};
102
- switch (typeof webpackExternals) {
103
- case "string": {
104
- // Single string external: "lodash" -> { "lodash": "lodash" }
105
- externals[webpackExternals] = webpackExternals;
106
- break;
107
- }
108
- case "object": {
109
- if (Array.isArray(webpackExternals)) {
110
- // Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
111
- externals = webpackExternals.reduce((acc, external) => {
112
- if (typeof external === "string") {
113
- acc[external] = external;
114
- }
115
- else if (typeof external === "object" && external !== null) {
116
- Object.assign(acc, compatExternals(external));
117
- }
118
- return acc;
119
- }, {});
120
- }
121
- else if (webpackExternals instanceof RegExp) {
122
- throw "regex external not supported yet";
123
- }
124
- else {
125
- if ("byLayer" in webpackExternals) {
126
- throw "by layer external item not supported yet";
127
- }
128
- Object.entries(webpackExternals).forEach(([key, value]) => {
129
- if (typeof value === "string") {
130
- // Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
131
- if (value.includes("@") &&
132
- (value.startsWith("script ") || value.includes("://"))) {
133
- const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
134
- if (match) {
135
- const [, globalName, scriptUrl] = match;
136
- // Use utoo-pack string format: "script globalName@url"
137
- externals[key] = `script ${globalName}@${scriptUrl}`;
138
- }
139
- else {
140
- externals[key] = value;
141
- }
142
- }
143
- else {
144
- // Simple string mapping: { "react": "React" }
145
- externals[key] = value;
146
- }
147
- }
148
- else if (Array.isArray(value)) {
149
- // Array format handling
150
- if (value.length >= 2) {
151
- const [first, second] = value;
152
- // Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
153
- if (typeof first === "string" &&
154
- first.includes("://") &&
155
- typeof second === "string") {
156
- // Use utoo-pack object format for script
157
- externals[key] = {
158
- root: second,
159
- type: "script",
160
- script: first,
161
- };
162
- }
163
- else if (typeof first === "string" &&
164
- typeof second === "string") {
165
- // Handle type prefix formats
166
- if (first.startsWith("commonjs")) {
167
- externals[key] = `commonjs ${second}`;
168
- }
169
- else if (first === "module") {
170
- externals[key] = `esm ${second}`;
171
- }
172
- else if (first === "var" ||
173
- first === "global" ||
174
- first === "window") {
175
- externals[key] = second;
176
- }
177
- else if (first === "script") {
178
- // Script type without URL in array format - treat as regular script prefix
179
- externals[key] = `script ${second}`;
180
- }
181
- else {
182
- externals[key] = `${first} ${second}`;
183
- }
184
- }
185
- else {
186
- externals[key] = value[0] || key;
187
- }
188
- }
189
- else {
190
- externals[key] = value[0] || key;
191
- }
192
- }
193
- else if (typeof value === "object" && value !== null) {
194
- // Object format: handle complex configurations
195
- if ("root" in value || "commonjs" in value || "amd" in value) {
196
- // Standard webpack externals object format
197
- if (value.commonjs) {
198
- externals[key] = `commonjs ${value.commonjs}`;
199
- }
200
- else if (value.root) {
201
- externals[key] = value.root;
202
- }
203
- else if (value.amd) {
204
- externals[key] = value.amd;
205
- }
206
- else {
207
- externals[key] = key;
208
- }
209
- }
210
- else {
211
- // Treat as utoo-pack specific configuration (might already be in correct format)
212
- externals[key] = value;
213
- }
214
- }
215
- else {
216
- // Fallback to key name
217
- externals[key] = key;
218
- }
219
- });
220
- }
221
- break;
222
- }
223
- case "function": {
224
- throw "functional external not supported yet";
225
- }
226
- default:
227
- break;
228
- }
229
- return externals;
230
- }
231
- function compatModule(webpackModule) {
232
- if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
233
- return;
234
- }
235
- const moduleRules = {
236
- rules: webpackModule.rules.reduce((acc, cur) => {
237
- var _a, _b;
238
- switch (typeof cur) {
239
- case "object":
240
- if (cur) {
241
- let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
242
- if (condition) {
243
- Object.assign(acc, {
244
- ["*" + condition]: {
245
- loaders: typeof cur.use === "string"
246
- ? [cur.use]
247
- : typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
248
- ? Array.isArray(cur.use)
249
- ? cur.use.map((use) => typeof use === "string"
250
- ? { loader: use, options: {} }
251
- : {
252
- loader: use.loader,
253
- options: use.options || {},
254
- })
255
- : [
256
- {
257
- loader: cur.loader,
258
- options: cur.options || {},
259
- },
260
- ]
261
- : [],
262
- as: "*.js",
263
- },
264
- });
265
- }
266
- }
267
- break;
268
- default:
269
- break;
270
- }
271
- return acc;
272
- }, {}),
273
- };
274
- return moduleRules;
275
- }
276
- function compatResolve(webpackResolve) {
277
- if (!webpackResolve) {
278
- return;
279
- }
280
- const { alias, extensions } = webpackResolve;
281
- return {
282
- alias: alias
283
- ? Array.isArray(alias)
284
- ? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
285
- : Object.entries(alias).reduce((acc, [k, v]) => {
286
- if (typeof v === "string") {
287
- Object.assign(acc, { [k]: v });
288
- }
289
- else {
290
- throw "non string alias value not supported yet";
291
- }
292
- return acc;
293
- }, {})
294
- : undefined,
295
- extensions,
296
- };
297
- }
298
- function compatOutput(webpackOutput) {
299
- if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
300
- throw "non string output filename not supported yet";
301
- }
302
- if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
303
- typeof webpackOutput.chunkFilename !== "string") {
304
- throw "non string output chunkFilename not supported yet";
305
- }
306
- return {
307
- path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
308
- filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
309
- chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
310
- clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
311
- };
312
- }
313
- function compatTarget(webpackTarget) {
314
- return webpackTarget
315
- ? Array.isArray(webpackTarget)
316
- ? webpackTarget.join(" ")
317
- : webpackTarget
318
- : undefined;
319
- }
320
- function compatSourceMaps(webpackSourceMaps) {
321
- return !!webpackSourceMaps;
322
- }
323
- function compatOptimization(webpackOptimization) {
324
- if (!webpackOptimization) {
325
- return;
326
- }
327
- const { moduleIds, minimize,
328
- // TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
329
- } = webpackOptimization;
330
- return {
331
- moduleIds: moduleIds === "named"
332
- ? "named"
333
- : moduleIds === "deterministic"
334
- ? "deterministic"
335
- : undefined,
336
- minify: minimize,
337
- };
338
- }
339
- function compatStats(webpackStats) {
340
- return !!webpackStats;
341
- }
package/esm/dev.d.ts DELETED
@@ -1,44 +0,0 @@
1
- import { IncomingMessage, ServerResponse } from "http";
2
- import send from "send";
3
- import { Duplex, Writable } from "stream";
4
- import { BundleOptions } from "./types";
5
- import { WebpackConfig } from "./webpackCompat";
6
- export declare function serve(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
7
- export declare function serve(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
8
- export interface SelfSignedCertificate {
9
- key: string;
10
- cert: string;
11
- rootCA?: string;
12
- }
13
- export interface StartServerOptions {
14
- port: number;
15
- https?: boolean;
16
- hostname?: string;
17
- selfSignedCertificate?: SelfSignedCertificate;
18
- }
19
- export type RequestHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
20
- export type UpgradeHandler = (req: IncomingMessage, socket: Duplex, head: Buffer) => Promise<void>;
21
- export type ServerInitResult = {
22
- requestHandler: RequestHandler;
23
- upgradeHandler: UpgradeHandler;
24
- closeUpgraded: () => void;
25
- };
26
- export declare function startServer(serverOptions: StartServerOptions, bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<void>;
27
- export declare function initialize(bundleOptions: BundleOptions, projectPath: string, rootPath?: string): Promise<ServerInitResult>;
28
- export declare function pipeToNodeResponse(readable: ReadableStream<Uint8Array>, res: ServerResponse, waitUntilForEnd?: Promise<unknown>): Promise<void>;
29
- export declare function createAbortController(response: Writable): AbortController;
30
- export declare function isAbortError(e: any): e is Error & {
31
- name: "AbortError";
32
- };
33
- export declare const ResponseAbortedName = "ResponseAborted";
34
- export declare class ResponseAborted extends Error {
35
- readonly name = "ResponseAborted";
36
- }
37
- export declare class DetachedPromise<T = any> {
38
- readonly resolve: (value: T | PromiseLike<T>) => void;
39
- readonly reject: (reason: any) => void;
40
- readonly promise: Promise<T>;
41
- constructor();
42
- }
43
- export declare function serveStatic(req: IncomingMessage, res: ServerResponse, path: string, opts?: Parameters<typeof send>[2]): Promise<void>;
44
- export declare function formatHostname(hostname: string): string;