@utoo/pack 0.0.1-alpha.14 → 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/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.14",
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.14",
83
- "@utoo/pack-darwin-x64": "0.0.1-alpha.14",
84
- "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.14",
85
- "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.14",
86
- "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.14",
87
- "@utoo/pack-linux-x64-musl": "0.0.1-alpha.14",
88
- "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.14"
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
  }