@utoo/pack 0.0.1-alpha.15 → 0.0.1-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/binding.d.ts CHANGED
@@ -9,12 +9,6 @@ export declare class ExternalObject<T> {
9
9
  [K: symbol]: T
10
10
  }
11
11
  }
12
- export interface TransformOutput {
13
- code: string
14
- map?: string
15
- output?: string
16
- diagnostics: Array<string>
17
- }
18
12
  export interface NapiEndpointConfig {
19
13
 
20
14
  }
@@ -63,7 +57,7 @@ export interface NapiProjectOptions {
63
57
  * A map of environment variables which should get injected at compile
64
58
  * time.
65
59
  */
66
- processDefineEnv: NapiDefineEnv
60
+ defineEnv: NapiDefineEnv
67
61
  /** The mode in which Next.js is running. */
68
62
  dev: boolean
69
63
  /** The build id. */
@@ -88,7 +82,7 @@ export interface NapiPartialProjectOptions {
88
82
  * A map of environment variables which should get injected at compile
89
83
  * time.
90
84
  */
91
- processDefineEnv?: NapiDefineEnv
85
+ defineEnv?: NapiDefineEnv
92
86
  /** The mode in which Next.js is running. */
93
87
  dev?: boolean
94
88
  /** The build id. */
@@ -136,7 +130,7 @@ export interface NapiEntrypoints {
136
130
  }
137
131
  export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
138
132
  export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
139
- export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: string, func: (...args: any[]) => any): { __napiType: "RootTask" }
133
+ export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: RcStr, func: (...args: any[]) => any): { __napiType: "RootTask" }
140
134
  export interface HmrIdentifiers {
141
135
  identifiers: Array<string>
142
136
  }
@@ -166,16 +160,18 @@ export declare function projectUpdateInfoSubscribe(project: { __napiType: "Proje
166
160
  export interface StackFrame {
167
161
  isServer: boolean
168
162
  isInternal?: boolean
169
- originalFile?: string
170
- file: string
163
+ originalFile?: RcStr
164
+ file: RcStr
165
+ /** 1-indexed, unlike source map tokens */
171
166
  line?: number
167
+ /** 1-indexed, unlike source map tokens */
172
168
  column?: number
173
- methodName?: string
169
+ methodName?: RcStr
174
170
  }
175
171
  export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
176
172
  export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
177
- export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
178
- export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: string): string | null
173
+ export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
174
+ export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
179
175
  export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
180
176
  export interface NapiIssue {
181
177
  severity: string
@@ -186,7 +182,7 @@ export interface NapiIssue {
186
182
  detail?: any
187
183
  source?: NapiIssueSource
188
184
  documentationLink: string
189
- subIssues: Array<NapiIssue>
185
+ importTraces: any
190
186
  }
191
187
  export interface NapiIssueSource {
192
188
  source: NapiSource
package/esm/build.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  import { BundleOptions } from "./types";
2
- export declare function build(projectOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<void>;
2
+ import { WebpackConfig } from "./webpackCompat";
3
+ export declare function build(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<void>;
4
+ export declare function build(webpackConfig: WebpackConfig, projectPath?: string, rootPath?: string): Promise<void>;
package/esm/build.js CHANGED
@@ -1,27 +1,34 @@
1
1
  import { nanoid } from "nanoid";
2
2
  import { projectFactory } from "./project";
3
3
  import { blockStdout, createDefineEnv, formatIssue, isRelevantWarning, } from "./util";
4
+ import { compatOptionsFromWebpack } from "./webpackCompat";
4
5
  import { xcodeProfilingReady } from "./xcodeProfile";
5
- export async function build(projectOptions, projectPath, rootPath) {
6
- var _a, _b, _c, _d;
6
+ export function build(options, projectPath, rootPath) {
7
+ const bundleOptions = options.compatMode
8
+ ? compatOptionsFromWebpack(options)
9
+ : options;
10
+ return buildInternal(bundleOptions, projectPath, rootPath);
11
+ }
12
+ async function buildInternal(bundleOptions, projectPath, rootPath) {
13
+ var _a, _b, _c;
7
14
  blockStdout();
8
15
  if (process.env.XCODE_PROFILE) {
9
16
  await xcodeProfilingReady();
10
17
  }
11
18
  const createProject = projectFactory();
12
19
  const project = await createProject({
13
- processEnv: (_a = projectOptions.processEnv) !== null && _a !== void 0 ? _a : {},
14
- processDefineEnv: createDefineEnv({
15
- config: projectOptions.config,
16
- dev: (_b = projectOptions.dev) !== null && _b !== void 0 ? _b : false,
17
- optionDefineEnv: projectOptions.processDefineEnv,
20
+ processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
21
+ defineEnv: createDefineEnv({
22
+ config: bundleOptions.config,
23
+ dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
24
+ optionDefineEnv: bundleOptions.defineEnv,
18
25
  }),
19
- watch: (_c = projectOptions.watch) !== null && _c !== void 0 ? _c : {
26
+ watch: {
20
27
  enable: false,
21
28
  },
22
- dev: (_d = projectOptions.dev) !== null && _d !== void 0 ? _d : false,
23
- buildId: nanoid(),
24
- config: projectOptions.config,
29
+ dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
30
+ buildId: bundleOptions.buildId || nanoid(),
31
+ config: bundleOptions.config,
25
32
  projectPath: projectPath || process.cwd(),
26
33
  rootPath: rootPath || projectPath || process.cwd(),
27
34
  }, {
package/esm/dev.d.ts CHANGED
@@ -2,7 +2,9 @@ import { IncomingMessage, ServerResponse } from "http";
2
2
  import send from "send";
3
3
  import { Duplex, Writable } from "stream";
4
4
  import { BundleOptions } from "./types";
5
- export declare function serve(options: BundleOptions, projectPath: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
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>;
6
8
  export interface SelfSignedCertificate {
7
9
  key: string;
8
10
  cert: string;
package/esm/dev.js CHANGED
@@ -8,8 +8,15 @@ import url from "url";
8
8
  import { createHotReloader } from "./hmr";
9
9
  import { createSelfSignedCertificate } from "./mkcert";
10
10
  import { blockStdout } from "./util";
11
+ import { compatOptionsFromWebpack } from "./webpackCompat";
11
12
  import { xcodeProfilingReady } from "./xcodeProfile";
12
- export async function serve(options, projectPath, rootPath, serverOptions) {
13
+ export function serve(options, projectPath, rootPath, serverOptions) {
14
+ const bundleOptions = options.compatMode
15
+ ? compatOptionsFromWebpack(options)
16
+ : options;
17
+ return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
18
+ }
19
+ async function serveInternal(options, projectPath, rootPath, serverOptions) {
13
20
  blockStdout();
14
21
  if (process.env.XCODE_PROFILE) {
15
22
  await xcodeProfilingReady();
@@ -21,7 +28,7 @@ export async function serve(options, projectPath, rootPath, serverOptions) {
21
28
  selfSignedCertificate: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.https)
22
29
  ? await createSelfSignedCertificate((serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.hostname) || "localhost")
23
30
  : undefined,
24
- }, options, projectPath, rootPath);
31
+ }, options, projectPath || process.cwd(), rootPath);
25
32
  }
26
33
  export async function startServer(serverOptions, bundleOptions, projectPath, rootPath) {
27
34
  let { port, hostname, selfSignedCertificate } = serverOptions;
package/esm/hmr.js CHANGED
@@ -10,16 +10,16 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
10
10
  const createProject = projectFactory();
11
11
  const project = await createProject({
12
12
  processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
13
- processDefineEnv: createDefineEnv({
13
+ defineEnv: createDefineEnv({
14
14
  config: bundleOptions.config,
15
15
  dev: true,
16
- optionDefineEnv: bundleOptions.processDefineEnv,
16
+ optionDefineEnv: bundleOptions.defineEnv,
17
17
  }),
18
18
  watch: {
19
19
  enable: true,
20
20
  },
21
21
  dev: true,
22
- buildId: nanoid(),
22
+ buildId: bundleOptions.buildId || nanoid(),
23
23
  config: {
24
24
  ...bundleOptions.config,
25
25
  mode: "development",
package/esm/index.d.ts CHANGED
@@ -1,2 +1,14 @@
1
- export { build } from "./build";
2
- export { serve } from "./dev";
1
+ import { build } from "./build";
2
+ import { serve } from "./dev";
3
+ import * as webpackCompat from "./webpackCompat";
4
+ export { build };
5
+ export { serve };
6
+ declare const utoopack: {
7
+ build: typeof build;
8
+ serve: typeof serve;
9
+ };
10
+ export default utoopack;
11
+ export type WebpackConfig = webpackCompat.WebpackConfig;
12
+ declare namespace utoopack {
13
+ type WebpackConfig = webpackCompat.WebpackConfig;
14
+ }
package/esm/index.js CHANGED
@@ -1,2 +1,6 @@
1
- export { build } from "./build";
2
- export { serve } from "./dev";
1
+ import { build } from "./build";
2
+ import { serve } from "./dev";
3
+ export { build };
4
+ export { serve };
5
+ const utoopack = { build, serve };
6
+ export default utoopack;
package/esm/project.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare class TurbopackInternalError extends Error {
5
5
  name: string;
6
6
  constructor(cause: Error);
7
7
  }
8
- export declare function projectFactory(): (options: ProjectOptions, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
8
+ export declare function projectFactory(): (options: Required<ProjectOptions>, turboEngineOptions: binding.NapiTurboEngineOptions) => Promise<{
9
9
  readonly _nativeProject: {
10
10
  __napiType: "Project";
11
11
  };
package/esm/project.js CHANGED
@@ -1,4 +1,3 @@
1
- import { nanoid } from "nanoid";
2
1
  import { isDeepStrictEqual } from "util";
3
2
  import * as binding from "./binding";
4
3
  import { rustifyEnv } from "./util";
@@ -53,7 +52,6 @@ function ensureLoadersHaveSerializableOptions(turbopackRules) {
53
52
  async function serializeConfig(config) {
54
53
  var _a, _b;
55
54
  let configSerializable = { ...config };
56
- configSerializable.generateBuildId = () => nanoid();
57
55
  if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
58
56
  ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
59
57
  }
package/esm/types.d.ts CHANGED
@@ -65,7 +65,6 @@ export interface DefineEnv {
65
65
  }
66
66
  export interface ExperimentalConfig {
67
67
  }
68
- export type TurbopackRuleConfigItemOrShortcut = TurbopackRuleConfigItem;
69
68
  export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
70
69
  [condition: string]: TurbopackRuleConfigItem;
71
70
  } | false;
@@ -81,7 +80,7 @@ export type TurbopackRuleConfigItemOptions = {
81
80
  as?: string;
82
81
  };
83
82
  export interface ModuleOptions {
84
- rules?: Record<string, TurbopackRuleConfigItemOrShortcut>;
83
+ rules?: Record<string, TurbopackRuleConfigItem>;
85
84
  }
86
85
  export interface ResolveOptions {
87
86
  alias?: Record<string, string | string[] | Record<string, string | string[]>>;
@@ -152,6 +151,7 @@ export interface ConfigComplete {
152
151
  images?: {
153
152
  inlineLimit?: number;
154
153
  };
154
+ stats?: boolean;
155
155
  experimental?: ExperimentalConfig;
156
156
  persistentCaching?: boolean;
157
157
  cacheHandler?: string;
@@ -205,23 +205,23 @@ export interface ProjectOptions {
205
205
  /**
206
206
  * A map of environment variables to use when compiling code.
207
207
  */
208
- processEnv: Record<string, string>;
209
- processDefineEnv: DefineEnv;
208
+ processEnv?: Record<string, string>;
209
+ defineEnv?: DefineEnv;
210
210
  /**
211
211
  * Whether to watch the filesystem for file changes.
212
212
  */
213
- watch: {
213
+ watch?: {
214
214
  enable: boolean;
215
215
  pollIntervalMs?: number;
216
216
  };
217
217
  /**
218
218
  * The mode of utoo-pack.
219
219
  */
220
- dev: boolean;
220
+ dev?: boolean;
221
221
  /**
222
222
  * The build id.
223
223
  */
224
- buildId: string;
224
+ buildId?: string;
225
225
  }
226
226
  export type BundleOptions = Omit<ProjectOptions, "rootPath" | "projectPath">;
227
227
  export interface Project {
@@ -0,0 +1,6 @@
1
+ import type webpack from "webpack";
2
+ import { BundleOptions } from "./types";
3
+ export type WebpackConfig = Pick<webpack.Configuration, "name" | "entry" | "mode" | "module" | "resolve" | "externals" | "output" | "target" | "devtool" | "optimization" | "plugins" | "stats"> & {
4
+ compatMode: true;
5
+ };
6
+ export declare function compatOptionsFromWebpack(webpackConfig: WebpackConfig): BundleOptions;
@@ -0,0 +1,338 @@
1
+ export function compatOptionsFromWebpack(webpackConfig) {
2
+ const { entry, mode, module, resolve, externals, output, target, devtool, optimization, plugins, stats, } = webpackConfig;
3
+ return {
4
+ config: {
5
+ entry: compatEntry(entry),
6
+ mode: compatMode(mode),
7
+ module: compatModule(module),
8
+ resolve: compatResolve(resolve),
9
+ externals: compatExternals(externals),
10
+ output: compatOutput(output),
11
+ target: compatTarget(target),
12
+ sourceMaps: compatSourceMaps(devtool),
13
+ optimization: compatOptimization(optimization),
14
+ define: compatFromWebpackPlugin(plugins, compatDefine),
15
+ stats: compatStats(stats),
16
+ },
17
+ buildId: webpackConfig.name,
18
+ };
19
+ }
20
+ function compatMode(webpackMode) {
21
+ return webpackMode
22
+ ? webpackMode === "none"
23
+ ? "production"
24
+ : webpackMode
25
+ : "production";
26
+ }
27
+ function compatEntry(webpackEntry) {
28
+ const entry = [];
29
+ switch (typeof webpackEntry) {
30
+ case "string":
31
+ entry.push({ import: webpackEntry });
32
+ break;
33
+ case "object":
34
+ if (Array.isArray(webpackEntry)) {
35
+ webpackEntry.forEach((e) => entry.push({
36
+ import: e,
37
+ }));
38
+ }
39
+ else {
40
+ Object.entries(webpackEntry).forEach(([k, v]) => {
41
+ var _a;
42
+ switch (typeof v) {
43
+ case "string":
44
+ entry.push({ name: k, import: v });
45
+ break;
46
+ case "object":
47
+ if (!Array.isArray(v)) {
48
+ switch (typeof v.import) {
49
+ case "string":
50
+ entry.push({
51
+ name: k,
52
+ import: v.import,
53
+ library: ((_a = v.library) === null || _a === void 0 ? void 0 : _a.type) === "umd"
54
+ ? {
55
+ name: typeof v.library.name === "string"
56
+ ? v.library.name
57
+ : undefined,
58
+ export: typeof v.library.export === "string"
59
+ ? [v.library.export]
60
+ : v.library.export,
61
+ }
62
+ : undefined,
63
+ });
64
+ break;
65
+ default:
66
+ break;
67
+ }
68
+ }
69
+ else {
70
+ throw "multi entry items for one entry not supported yet";
71
+ }
72
+ break;
73
+ default:
74
+ throw "non string and non object entry path not supported yet";
75
+ }
76
+ });
77
+ }
78
+ break;
79
+ case "function":
80
+ throw "functional entry not supported yet";
81
+ default:
82
+ throw "entry config not compatible now";
83
+ }
84
+ return entry;
85
+ }
86
+ function compatFromWebpackPlugin(webpackPlugins, picker) {
87
+ const plugin = webpackPlugins === null || webpackPlugins === void 0 ? void 0 : webpackPlugins.find((p) => p && typeof p === "object" && p.constructor.name === picker.pluginName);
88
+ return picker(plugin);
89
+ }
90
+ compatDefine.pluginName = "DefinePlugin";
91
+ function compatDefine(maybeWebpackPluginInstance) {
92
+ return maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
93
+ }
94
+ function compatExternals(webpackExternals) {
95
+ if (!webpackExternals) {
96
+ return undefined;
97
+ }
98
+ let externals = {};
99
+ switch (typeof webpackExternals) {
100
+ case "string": {
101
+ // Single string external: "lodash" -> { "lodash": "lodash" }
102
+ externals[webpackExternals] = webpackExternals;
103
+ break;
104
+ }
105
+ case "object": {
106
+ if (Array.isArray(webpackExternals)) {
107
+ // Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
108
+ externals = webpackExternals.reduce((acc, external) => {
109
+ if (typeof external === "string") {
110
+ acc[external] = external;
111
+ }
112
+ else if (typeof external === "object" && external !== null) {
113
+ Object.assign(acc, compatExternals(external));
114
+ }
115
+ return acc;
116
+ }, {});
117
+ }
118
+ else if (webpackExternals instanceof RegExp) {
119
+ throw "regex external not supported yet";
120
+ }
121
+ else {
122
+ if ("byLayer" in webpackExternals) {
123
+ throw "by layer external item not supported yet";
124
+ }
125
+ Object.entries(webpackExternals).forEach(([key, value]) => {
126
+ if (typeof value === "string") {
127
+ // Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
128
+ if (value.includes("@") &&
129
+ (value.startsWith("script ") || value.includes("://"))) {
130
+ const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
131
+ if (match) {
132
+ const [, globalName, scriptUrl] = match;
133
+ // Use utoo-pack string format: "script globalName@url"
134
+ externals[key] = `script ${globalName}@${scriptUrl}`;
135
+ }
136
+ else {
137
+ externals[key] = value;
138
+ }
139
+ }
140
+ else {
141
+ // Simple string mapping: { "react": "React" }
142
+ externals[key] = value;
143
+ }
144
+ }
145
+ else if (Array.isArray(value)) {
146
+ // Array format handling
147
+ if (value.length >= 2) {
148
+ const [first, second] = value;
149
+ // Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
150
+ if (typeof first === "string" &&
151
+ first.includes("://") &&
152
+ typeof second === "string") {
153
+ // Use utoo-pack object format for script
154
+ externals[key] = {
155
+ root: second,
156
+ type: "script",
157
+ script: first,
158
+ };
159
+ }
160
+ else if (typeof first === "string" &&
161
+ typeof second === "string") {
162
+ // Handle type prefix formats
163
+ if (first.startsWith("commonjs")) {
164
+ externals[key] = `commonjs ${second}`;
165
+ }
166
+ else if (first === "module") {
167
+ externals[key] = `esm ${second}`;
168
+ }
169
+ else if (first === "var" ||
170
+ first === "global" ||
171
+ first === "window") {
172
+ externals[key] = second;
173
+ }
174
+ else if (first === "script") {
175
+ // Script type without URL in array format - treat as regular script prefix
176
+ externals[key] = `script ${second}`;
177
+ }
178
+ else {
179
+ externals[key] = `${first} ${second}`;
180
+ }
181
+ }
182
+ else {
183
+ externals[key] = value[0] || key;
184
+ }
185
+ }
186
+ else {
187
+ externals[key] = value[0] || key;
188
+ }
189
+ }
190
+ else if (typeof value === "object" && value !== null) {
191
+ // Object format: handle complex configurations
192
+ if ("root" in value || "commonjs" in value || "amd" in value) {
193
+ // Standard webpack externals object format
194
+ if (value.commonjs) {
195
+ externals[key] = `commonjs ${value.commonjs}`;
196
+ }
197
+ else if (value.root) {
198
+ externals[key] = value.root;
199
+ }
200
+ else if (value.amd) {
201
+ externals[key] = value.amd;
202
+ }
203
+ else {
204
+ externals[key] = key;
205
+ }
206
+ }
207
+ else {
208
+ // Treat as utoo-pack specific configuration (might already be in correct format)
209
+ externals[key] = value;
210
+ }
211
+ }
212
+ else {
213
+ // Fallback to key name
214
+ externals[key] = key;
215
+ }
216
+ });
217
+ }
218
+ break;
219
+ }
220
+ case "function": {
221
+ throw "functional external not supported yet";
222
+ }
223
+ default:
224
+ break;
225
+ }
226
+ return externals;
227
+ }
228
+ function compatModule(webpackModule) {
229
+ if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
230
+ return;
231
+ }
232
+ const moduleRules = {
233
+ rules: webpackModule.rules.reduce((acc, cur) => {
234
+ var _a, _b;
235
+ switch (typeof cur) {
236
+ case "object":
237
+ if (cur) {
238
+ let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
239
+ if (condition) {
240
+ Object.assign(acc, {
241
+ ["*" + condition]: {
242
+ loaders: typeof cur.use === "string"
243
+ ? [cur.use]
244
+ : typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
245
+ ? Array.isArray(cur.use)
246
+ ? cur.use.map((use) => typeof use === "string"
247
+ ? { loader: use, options: {} }
248
+ : {
249
+ loader: use.loader,
250
+ options: use.options || {},
251
+ })
252
+ : [
253
+ {
254
+ loader: cur.loader,
255
+ options: cur.options || {},
256
+ },
257
+ ]
258
+ : [],
259
+ as: "*.js",
260
+ },
261
+ });
262
+ }
263
+ }
264
+ break;
265
+ default:
266
+ break;
267
+ }
268
+ return acc;
269
+ }, {}),
270
+ };
271
+ return moduleRules;
272
+ }
273
+ function compatResolve(webpackResolve) {
274
+ if (!webpackResolve) {
275
+ return;
276
+ }
277
+ const { alias, extensions } = webpackResolve;
278
+ return {
279
+ alias: alias
280
+ ? Array.isArray(alias)
281
+ ? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
282
+ : Object.entries(alias).reduce((acc, [k, v]) => {
283
+ if (typeof v === "string") {
284
+ Object.assign(acc, { [k]: v });
285
+ }
286
+ else {
287
+ throw "non string alias value not supported yet";
288
+ }
289
+ return acc;
290
+ }, {})
291
+ : undefined,
292
+ extensions,
293
+ };
294
+ }
295
+ function compatOutput(webpackOutput) {
296
+ if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
297
+ throw "non string output filename not supported yet";
298
+ }
299
+ if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
300
+ typeof webpackOutput.chunkFilename !== "string") {
301
+ throw "non string output chunkFilename not supported yet";
302
+ }
303
+ return {
304
+ path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
305
+ filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
306
+ chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
307
+ clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
308
+ };
309
+ }
310
+ function compatTarget(webpackTarget) {
311
+ return webpackTarget
312
+ ? Array.isArray(webpackTarget)
313
+ ? webpackTarget.join(" ")
314
+ : webpackTarget
315
+ : undefined;
316
+ }
317
+ function compatSourceMaps(webpackSourceMaps) {
318
+ return !!webpackSourceMaps;
319
+ }
320
+ function compatOptimization(webpackOptimization) {
321
+ if (!webpackOptimization) {
322
+ return;
323
+ }
324
+ const { moduleIds, minimize,
325
+ // TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
326
+ } = webpackOptimization;
327
+ return {
328
+ moduleIds: moduleIds === "named"
329
+ ? "named"
330
+ : moduleIds === "deterministic"
331
+ ? "deterministic"
332
+ : undefined,
333
+ minify: minimize,
334
+ };
335
+ }
336
+ function compatStats(webpackStats) {
337
+ return !!webpackStats;
338
+ }