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

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/cjs/binding.d.ts CHANGED
@@ -63,7 +63,7 @@ export interface NapiProjectOptions {
63
63
  * A map of environment variables which should get injected at compile
64
64
  * time.
65
65
  */
66
- processDefineEnv: NapiDefineEnv
66
+ defineEnv: NapiDefineEnv
67
67
  /** The mode in which Next.js is running. */
68
68
  dev: boolean
69
69
  /** The build id. */
@@ -88,7 +88,7 @@ export interface NapiPartialProjectOptions {
88
88
  * A map of environment variables which should get injected at compile
89
89
  * time.
90
90
  */
91
- processDefineEnv?: NapiDefineEnv
91
+ defineEnv?: NapiDefineEnv
92
92
  /** The mode in which Next.js is running. */
93
93
  dev?: boolean
94
94
  /** The build id. */
package/cjs/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/cjs/build.js CHANGED
@@ -4,27 +4,34 @@ exports.build = build;
4
4
  const nanoid_1 = require("nanoid");
5
5
  const project_1 = require("./project");
6
6
  const util_1 = require("./util");
7
+ const webpackCompat_1 = require("./webpackCompat");
7
8
  const xcodeProfile_1 = require("./xcodeProfile");
8
- async function build(projectOptions, projectPath, rootPath) {
9
- var _a, _b, _c, _d;
9
+ function build(options, projectPath, rootPath) {
10
+ const bundleOptions = options.compatMode
11
+ ? (0, webpackCompat_1.compatOptionsFromWebpack)(options)
12
+ : options;
13
+ return buildInternal(bundleOptions, projectPath, rootPath);
14
+ }
15
+ async function buildInternal(bundleOptions, projectPath, rootPath) {
16
+ var _a, _b, _c;
10
17
  (0, util_1.blockStdout)();
11
18
  if (process.env.XCODE_PROFILE) {
12
19
  await (0, xcodeProfile_1.xcodeProfilingReady)();
13
20
  }
14
21
  const createProject = (0, project_1.projectFactory)();
15
22
  const project = await createProject({
16
- processEnv: (_a = projectOptions.processEnv) !== null && _a !== void 0 ? _a : {},
17
- processDefineEnv: (0, util_1.createDefineEnv)({
18
- config: projectOptions.config,
19
- dev: (_b = projectOptions.dev) !== null && _b !== void 0 ? _b : false,
20
- optionDefineEnv: projectOptions.processDefineEnv,
23
+ processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
24
+ defineEnv: (0, util_1.createDefineEnv)({
25
+ config: bundleOptions.config,
26
+ dev: (_b = bundleOptions.dev) !== null && _b !== void 0 ? _b : false,
27
+ optionDefineEnv: bundleOptions.defineEnv,
21
28
  }),
22
- watch: (_c = projectOptions.watch) !== null && _c !== void 0 ? _c : {
29
+ watch: {
23
30
  enable: false,
24
31
  },
25
- dev: (_d = projectOptions.dev) !== null && _d !== void 0 ? _d : false,
26
- buildId: (0, nanoid_1.nanoid)(),
27
- config: projectOptions.config,
32
+ dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
33
+ buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
34
+ config: bundleOptions.config,
28
35
  projectPath: projectPath || process.cwd(),
29
36
  rootPath: rootPath || projectPath || process.cwd(),
30
37
  }, {
package/cjs/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/cjs/dev.js CHANGED
@@ -22,8 +22,15 @@ const url_1 = __importDefault(require("url"));
22
22
  const hmr_1 = require("./hmr");
23
23
  const mkcert_1 = require("./mkcert");
24
24
  const util_1 = require("./util");
25
+ const webpackCompat_1 = require("./webpackCompat");
25
26
  const xcodeProfile_1 = require("./xcodeProfile");
26
- async function serve(options, projectPath, rootPath, serverOptions) {
27
+ function serve(options, projectPath, rootPath, serverOptions) {
28
+ const bundleOptions = options.compatMode
29
+ ? (0, webpackCompat_1.compatOptionsFromWebpack)(options)
30
+ : options;
31
+ return serveInternal(bundleOptions, projectPath, rootPath, serverOptions);
32
+ }
33
+ async function serveInternal(options, projectPath, rootPath, serverOptions) {
27
34
  (0, util_1.blockStdout)();
28
35
  if (process.env.XCODE_PROFILE) {
29
36
  await (0, xcodeProfile_1.xcodeProfilingReady)();
@@ -35,7 +42,7 @@ async function serve(options, projectPath, rootPath, serverOptions) {
35
42
  selfSignedCertificate: (serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.https)
36
43
  ? await (0, mkcert_1.createSelfSignedCertificate)((serverOptions === null || serverOptions === void 0 ? void 0 : serverOptions.hostname) || "localhost")
37
44
  : undefined,
38
- }, options, projectPath, rootPath);
45
+ }, options, projectPath || process.cwd(), rootPath);
39
46
  }
40
47
  async function startServer(serverOptions, bundleOptions, projectPath, rootPath) {
41
48
  let { port, hostname, selfSignedCertificate } = serverOptions;
package/cjs/hmr.js CHANGED
@@ -17,16 +17,16 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
17
17
  const createProject = (0, project_1.projectFactory)();
18
18
  const project = await createProject({
19
19
  processEnv: (_a = bundleOptions.processEnv) !== null && _a !== void 0 ? _a : {},
20
- processDefineEnv: (0, util_1.createDefineEnv)({
20
+ defineEnv: (0, util_1.createDefineEnv)({
21
21
  config: bundleOptions.config,
22
22
  dev: true,
23
- optionDefineEnv: bundleOptions.processDefineEnv,
23
+ optionDefineEnv: bundleOptions.defineEnv,
24
24
  }),
25
25
  watch: {
26
26
  enable: true,
27
27
  },
28
28
  dev: true,
29
- buildId: (0, nanoid_1.nanoid)(),
29
+ buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
30
30
  config: {
31
31
  ...bundleOptions.config,
32
32
  mode: "development",
package/cjs/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/cjs/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serve = exports.build = void 0;
4
- var build_1 = require("./build");
4
+ const build_1 = require("./build");
5
5
  Object.defineProperty(exports, "build", { enumerable: true, get: function () { return build_1.build; } });
6
- var dev_1 = require("./dev");
6
+ const dev_1 = require("./dev");
7
7
  Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return dev_1.serve; } });
8
+ const utoopack = { build: build_1.build, serve: dev_1.serve };
9
+ exports.default = utoopack;
package/cjs/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/cjs/project.js CHANGED
@@ -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 nanoid_1 = require("nanoid");
39
38
  const util_1 = require("util");
40
39
  const binding = __importStar(require("./binding"));
41
40
  const util_2 = require("./util");
@@ -91,7 +90,6 @@ function ensureLoadersHaveSerializableOptions(turbopackRules) {
91
90
  async function serializeConfig(config) {
92
91
  var _a, _b;
93
92
  let configSerializable = { ...config };
94
- configSerializable.generateBuildId = () => (0, nanoid_1.nanoid)();
95
93
  if ((_a = configSerializable.module) === null || _a === void 0 ? void 0 : _a.rules) {
96
94
  ensureLoadersHaveSerializableOptions(configSerializable.module.rules);
97
95
  }
package/cjs/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,250 @@
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(webpackExternal) {
98
+ let externals = {};
99
+ switch (typeof webpackExternal) {
100
+ case "string":
101
+ externals[webpackExternal] = webpackExternal;
102
+ break;
103
+ case "object":
104
+ if (webpackExternal instanceof RegExp) {
105
+ throw "regex enternal not supported yet";
106
+ }
107
+ else if (Array.isArray(webpackExternal)) {
108
+ webpackExternal.forEach((k) => {
109
+ switch (typeof k) {
110
+ case "string":
111
+ externals[k] = k;
112
+ break;
113
+ default:
114
+ throw "non string external item not supported yet";
115
+ }
116
+ });
117
+ }
118
+ else {
119
+ if ("byLayer" in webpackExternal) {
120
+ throw "by layer external item not supported yet";
121
+ }
122
+ Object.entries(webpackExternal).forEach(([k, v]) => {
123
+ switch (typeof v) {
124
+ case "string":
125
+ externals[k] = v;
126
+ break;
127
+ default:
128
+ throw "non string external item not supported yet";
129
+ }
130
+ });
131
+ }
132
+ break;
133
+ case "function":
134
+ throw "functional external not supported yet";
135
+ default:
136
+ break;
137
+ }
138
+ return externals;
139
+ }
140
+ function compatModule(webpackModule) {
141
+ if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
142
+ return;
143
+ }
144
+ const moduleRules = {
145
+ rules: webpackModule.rules.reduce((acc, cur) => {
146
+ var _a, _b;
147
+ switch (typeof cur) {
148
+ case "object":
149
+ if (cur) {
150
+ let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
151
+ if (condition) {
152
+ Object.assign(acc, {
153
+ ["*" + condition]: {
154
+ loaders: typeof cur.use === "string"
155
+ ? [cur.use]
156
+ : typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
157
+ ? Array.isArray(cur.use)
158
+ ? cur.use.map((use) => typeof use === "string"
159
+ ? { loader: use, options: {} }
160
+ : {
161
+ loader: use.loader,
162
+ options: use.options || {},
163
+ })
164
+ : [
165
+ {
166
+ loader: cur.loader,
167
+ options: cur.options || {},
168
+ },
169
+ ]
170
+ : [],
171
+ as: "*.js",
172
+ },
173
+ });
174
+ }
175
+ }
176
+ break;
177
+ default:
178
+ break;
179
+ }
180
+ return acc;
181
+ }, {}),
182
+ };
183
+ return moduleRules;
184
+ }
185
+ function compatResolve(webpackResolve) {
186
+ if (!webpackResolve) {
187
+ return;
188
+ }
189
+ const { alias, extensions } = webpackResolve;
190
+ return {
191
+ alias: alias
192
+ ? Array.isArray(alias)
193
+ ? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
194
+ : Object.entries(alias).reduce((acc, [k, v]) => {
195
+ if (typeof v === "string") {
196
+ Object.assign(acc, { [k]: v });
197
+ }
198
+ else {
199
+ throw "non string alias value not supported yet";
200
+ }
201
+ return acc;
202
+ }, {})
203
+ : undefined,
204
+ extensions,
205
+ };
206
+ }
207
+ function compatOutput(webpackOutput) {
208
+ if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
209
+ throw "non string output filename not supported yet";
210
+ }
211
+ if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
212
+ typeof webpackOutput.chunkFilename !== "string") {
213
+ throw "non string output chunkFilename not supported yet";
214
+ }
215
+ return {
216
+ path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
217
+ filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
218
+ chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
219
+ clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
220
+ };
221
+ }
222
+ function compatTarget(webpackTarget) {
223
+ return webpackTarget
224
+ ? Array.isArray(webpackTarget)
225
+ ? webpackTarget.join(" ")
226
+ : webpackTarget
227
+ : undefined;
228
+ }
229
+ function compatSourceMaps(webpackSourceMaps) {
230
+ return !!webpackSourceMaps;
231
+ }
232
+ function compatOptimization(webpackOptimization) {
233
+ if (!webpackOptimization) {
234
+ return;
235
+ }
236
+ const { moduleIds, minimize,
237
+ // TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
238
+ } = webpackOptimization;
239
+ return {
240
+ moduleIds: moduleIds === "named"
241
+ ? "named"
242
+ : moduleIds === "deterministic"
243
+ ? "deterministic"
244
+ : undefined,
245
+ minify: minimize,
246
+ };
247
+ }
248
+ function compatStats(webpackStats) {
249
+ return !!webpackStats;
250
+ }
package/esm/binding.d.ts CHANGED
@@ -63,7 +63,7 @@ export interface NapiProjectOptions {
63
63
  * A map of environment variables which should get injected at compile
64
64
  * time.
65
65
  */
66
- processDefineEnv: NapiDefineEnv
66
+ defineEnv: NapiDefineEnv
67
67
  /** The mode in which Next.js is running. */
68
68
  dev: boolean
69
69
  /** The build id. */
@@ -88,7 +88,7 @@ export interface NapiPartialProjectOptions {
88
88
  * A map of environment variables which should get injected at compile
89
89
  * time.
90
90
  */
91
- processDefineEnv?: NapiDefineEnv
91
+ defineEnv?: NapiDefineEnv
92
92
  /** The mode in which Next.js is running. */
93
93
  dev?: boolean
94
94
  /** The build id. */
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,247 @@
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(webpackExternal) {
95
+ let externals = {};
96
+ switch (typeof webpackExternal) {
97
+ case "string":
98
+ externals[webpackExternal] = webpackExternal;
99
+ break;
100
+ case "object":
101
+ if (webpackExternal instanceof RegExp) {
102
+ throw "regex enternal not supported yet";
103
+ }
104
+ else if (Array.isArray(webpackExternal)) {
105
+ webpackExternal.forEach((k) => {
106
+ switch (typeof k) {
107
+ case "string":
108
+ externals[k] = k;
109
+ break;
110
+ default:
111
+ throw "non string external item not supported yet";
112
+ }
113
+ });
114
+ }
115
+ else {
116
+ if ("byLayer" in webpackExternal) {
117
+ throw "by layer external item not supported yet";
118
+ }
119
+ Object.entries(webpackExternal).forEach(([k, v]) => {
120
+ switch (typeof v) {
121
+ case "string":
122
+ externals[k] = v;
123
+ break;
124
+ default:
125
+ throw "non string external item not supported yet";
126
+ }
127
+ });
128
+ }
129
+ break;
130
+ case "function":
131
+ throw "functional external not supported yet";
132
+ default:
133
+ break;
134
+ }
135
+ return externals;
136
+ }
137
+ function compatModule(webpackModule) {
138
+ if (!Array.isArray(webpackModule === null || webpackModule === void 0 ? void 0 : webpackModule.rules)) {
139
+ return;
140
+ }
141
+ const moduleRules = {
142
+ rules: webpackModule.rules.reduce((acc, cur) => {
143
+ var _a, _b;
144
+ switch (typeof cur) {
145
+ case "object":
146
+ if (cur) {
147
+ let condition = (_b = (_a = cur.test) === null || _a === void 0 ? void 0 : _a.toString().match(/(\.\w+)/)) === null || _b === void 0 ? void 0 : _b[1];
148
+ if (condition) {
149
+ Object.assign(acc, {
150
+ ["*" + condition]: {
151
+ loaders: typeof cur.use === "string"
152
+ ? [cur.use]
153
+ : typeof (cur === null || cur === void 0 ? void 0 : cur.use) === "object"
154
+ ? Array.isArray(cur.use)
155
+ ? cur.use.map((use) => typeof use === "string"
156
+ ? { loader: use, options: {} }
157
+ : {
158
+ loader: use.loader,
159
+ options: use.options || {},
160
+ })
161
+ : [
162
+ {
163
+ loader: cur.loader,
164
+ options: cur.options || {},
165
+ },
166
+ ]
167
+ : [],
168
+ as: "*.js",
169
+ },
170
+ });
171
+ }
172
+ }
173
+ break;
174
+ default:
175
+ break;
176
+ }
177
+ return acc;
178
+ }, {}),
179
+ };
180
+ return moduleRules;
181
+ }
182
+ function compatResolve(webpackResolve) {
183
+ if (!webpackResolve) {
184
+ return;
185
+ }
186
+ const { alias, extensions } = webpackResolve;
187
+ return {
188
+ alias: alias
189
+ ? Array.isArray(alias)
190
+ ? alias.reduce((acc, cur) => Object.assign(acc, { [cur.name]: cur.alias }), {})
191
+ : Object.entries(alias).reduce((acc, [k, v]) => {
192
+ if (typeof v === "string") {
193
+ Object.assign(acc, { [k]: v });
194
+ }
195
+ else {
196
+ throw "non string alias value not supported yet";
197
+ }
198
+ return acc;
199
+ }, {})
200
+ : undefined,
201
+ extensions,
202
+ };
203
+ }
204
+ function compatOutput(webpackOutput) {
205
+ if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename) && typeof webpackOutput.filename !== "string") {
206
+ throw "non string output filename not supported yet";
207
+ }
208
+ if ((webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename) &&
209
+ typeof webpackOutput.chunkFilename !== "string") {
210
+ throw "non string output chunkFilename not supported yet";
211
+ }
212
+ return {
213
+ path: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.path,
214
+ filename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.filename,
215
+ chunkFilename: webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.chunkFilename,
216
+ clean: !!(webpackOutput === null || webpackOutput === void 0 ? void 0 : webpackOutput.clean),
217
+ };
218
+ }
219
+ function compatTarget(webpackTarget) {
220
+ return webpackTarget
221
+ ? Array.isArray(webpackTarget)
222
+ ? webpackTarget.join(" ")
223
+ : webpackTarget
224
+ : undefined;
225
+ }
226
+ function compatSourceMaps(webpackSourceMaps) {
227
+ return !!webpackSourceMaps;
228
+ }
229
+ function compatOptimization(webpackOptimization) {
230
+ if (!webpackOptimization) {
231
+ return;
232
+ }
233
+ const { moduleIds, minimize,
234
+ // TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
235
+ } = webpackOptimization;
236
+ return {
237
+ moduleIds: moduleIds === "named"
238
+ ? "named"
239
+ : moduleIds === "deterministic"
240
+ ? "deterministic"
241
+ : undefined,
242
+ minify: minimize,
243
+ };
244
+ }
245
+ function compatStats(webpackStats) {
246
+ return !!webpackStats;
247
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "0.0.1-alpha.15",
3
+ "version": "0.0.1-alpha.16",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "exports": {
@@ -60,10 +60,12 @@
60
60
  "styled-jsx": "^5.1.6",
61
61
  "typescript": "^5.8.3",
62
62
  "@types/ws": "^8.18.1",
63
- "@types/webpack": "^5.28.5",
64
63
  "@types/send": "0.14.4",
65
64
  "@types/mime-types": "3.0.1"
66
65
  },
66
+ "peerDependencies": {
67
+ "@types/webpack": "^5.28.5"
68
+ },
67
69
  "engines": {
68
70
  "node": ">= 10"
69
71
  },
@@ -79,12 +81,12 @@
79
81
  },
80
82
  "repository": "git@github.com:umijs/mako.git",
81
83
  "optionalDependencies": {
82
- "@utoo/pack-darwin-arm64": "0.0.1-alpha.15",
83
- "@utoo/pack-darwin-x64": "0.0.1-alpha.15",
84
- "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.15",
85
- "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.15",
86
- "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.15",
87
- "@utoo/pack-linux-x64-musl": "0.0.1-alpha.15",
88
- "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.15"
84
+ "@utoo/pack-darwin-arm64": "0.0.1-alpha.16",
85
+ "@utoo/pack-darwin-x64": "0.0.1-alpha.16",
86
+ "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.16",
87
+ "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.16",
88
+ "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.16",
89
+ "@utoo/pack-linux-x64-musl": "0.0.1-alpha.16",
90
+ "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.16"
89
91
  }
90
92
  }