@utoo/pack 1.3.2-alpha.0 → 1.3.3-alpha.0

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.
@@ -11,6 +11,7 @@ import { findRootDir } from "../utils/findRoot.js";
11
11
  import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
12
12
  import { processHtmlEntry } from "../utils/htmlEntry.js";
13
13
  import { normalizePath } from "../utils/normalize-path.js";
14
+ import { useWorkerThreads } from "../utils/runtimePluginStratety.js";
14
15
  import { validateEntryPaths } from "../utils/validateEntry.js";
15
16
  import { xcodeProfilingReady } from "../utils/xcodeProfile.js";
16
17
  export function build(options, projectPath, rootPath) {
@@ -22,7 +23,7 @@ export function build(options, projectPath, rootPath) {
22
23
  return buildInternal(bundleOptions, projectPath, rootPath);
23
24
  }
24
25
  async function buildInternal(bundleOptions, projectPath, rootPath) {
25
- var _a, _b, _c, _d, _e, _f;
26
+ var _a, _b, _c, _d, _e, _f, _g, _h;
26
27
  blockStdout();
27
28
  if (process.env.XCODE_PROFILE) {
28
29
  await xcodeProfilingReady();
@@ -43,12 +44,13 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
43
44
  stats: Boolean(process.env.ANALYZE) ||
44
45
  bundleOptions.config.stats ||
45
46
  bundleOptions.config.entry.some((e) => !!e.html),
47
+ pluginRuntimeStrategy: (_d = (_c = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _c === void 0 ? void 0 : _c.pluginRuntimeStrategy) !== null && _d !== void 0 ? _d : (useWorkerThreads() ? "workerThreads" : "childProcesses"),
46
48
  },
47
49
  projectPath: normalizePath(resolvedProjectPath),
48
50
  rootPath: rootPath || projectPath || process.cwd(),
49
51
  packPath: getPackPath(),
50
52
  }, {
51
- persistentCaching: (_c = bundleOptions.config.persistentCaching) !== null && _c !== void 0 ? _c : false,
53
+ persistentCaching: (_e = bundleOptions.config.persistentCaching) !== null && _e !== void 0 ? _e : false,
52
54
  });
53
55
  const entrypoints = await project.writeAllEntrypointsToDisk();
54
56
  handleIssues(entrypoints.issues);
@@ -64,20 +66,20 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
64
66
  ];
65
67
  if (htmlConfigs.length > 0) {
66
68
  const assets = { js: [], css: [] };
67
- const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || path.join(process.cwd(), "dist");
69
+ const outputDir = ((_f = bundleOptions.config.output) === null || _f === void 0 ? void 0 : _f.path) || path.join(process.cwd(), "dist");
68
70
  if (assets.js.length === 0 && assets.css.length === 0) {
69
71
  const discovered = getInitialAssetsFromStats(outputDir);
70
72
  assets.js.push(...discovered.js);
71
73
  assets.css.push(...discovered.css);
72
74
  }
73
- const publicPath = (_e = bundleOptions.config.output) === null || _e === void 0 ? void 0 : _e.publicPath;
75
+ const publicPath = (_g = bundleOptions.config.output) === null || _g === void 0 ? void 0 : _g.publicPath;
74
76
  for (const config of htmlConfigs) {
75
77
  const plugin = new HtmlPlugin(config);
76
78
  await plugin.generate(outputDir, assets, publicPath);
77
79
  }
78
80
  }
79
81
  if (process.env.ANALYZE) {
80
- await analyzeBundle(((_f = bundleOptions.config.output) === null || _f === void 0 ? void 0 : _f.path) || "dist");
82
+ await analyzeBundle(((_h = bundleOptions.config.output) === null || _h === void 0 ? void 0 : _h.path) || "dist");
81
83
  }
82
84
  await project.shutdown();
83
85
  // TODO: Maybe run tasks in worker is a better way, see
@@ -12,7 +12,6 @@ import https from "https";
12
12
  import path from "path";
13
13
  import { resolveBundleOptions, } from "../config/webpackCompat.js";
14
14
  import { createHotReloader } from "../core/hmr.js";
15
- import { createHttpProxyMiddleware } from "../core/proxy-hono.js";
16
15
  import { blockStdout, getPackPath } from "../utils/common.js";
17
16
  import { findRootDir } from "../utils/findRoot.js";
18
17
  import { createSelfSignedCertificate } from "../utils/mkcert.js";
@@ -133,7 +132,7 @@ export function serve(options, projectPath, rootPath, serverOptions) {
133
132
  }
134
133
  const HMR_PATH = "/turbopack-hmr";
135
134
  async function runDev(options, projectPath, rootPath, serverOptions) {
136
- var _a, _b, _d, _e, _f, _g;
135
+ var _a, _b, _d, _e;
137
136
  blockStdout();
138
137
  process.title = "utoopack-dev-server";
139
138
  if (process.env.XCODE_PROFILE) {
@@ -185,10 +184,6 @@ async function runDev(options, projectPath, rootPath, serverOptions) {
185
184
  console.error("HMR WebSocket error", err);
186
185
  },
187
186
  })));
188
- const proxyRules = (_g = (_f = bundleOptions.config) === null || _f === void 0 ? void 0 : _f.devServer) === null || _g === void 0 ? void 0 : _g.proxy;
189
- if (proxyRules && proxyRules.length > 0) {
190
- app.use("*", createHttpProxyMiddleware(proxyRules));
191
- }
192
187
  // GET handles HEAD automatically in Hono; serveStatic serves both
193
188
  app.get("/*", serveStatic({
194
189
  root: distRoot,
package/esm/core/hmr.js CHANGED
@@ -7,6 +7,7 @@ import { debounce, getPackPath, processIssues } from "../utils/common.js";
7
7
  import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
8
8
  import { processHtmlEntry } from "../utils/htmlEntry.js";
9
9
  import { normalizePath } from "../utils/normalize-path.js";
10
+ import { useWorkerThreads } from "../utils/runtimePluginStratety.js";
10
11
  import { validateEntryPaths } from "../utils/validateEntry.js";
11
12
  import { projectFactory } from "./project.js";
12
13
  const wsServer = new WebSocketServer({ noServer: true });
@@ -15,7 +16,7 @@ const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
15
16
  export { HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
16
17
  export const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
17
18
  export async function createHotReloader(bundleOptions, projectPath, rootPath) {
18
- var _a, _b;
19
+ var _a, _b, _c, _d;
19
20
  const resolvedProjectPath = projectPath || process.cwd();
20
21
  processHtmlEntry(bundleOptions.config, resolvedProjectPath);
21
22
  validateEntryPaths(bundleOptions.config, resolvedProjectPath);
@@ -38,12 +39,13 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
38
39
  minify: false,
39
40
  moduleIds: "named",
40
41
  },
42
+ pluginRuntimeStrategy: (_c = (_b = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.config) === null || _b === void 0 ? void 0 : _b.pluginRuntimeStrategy) !== null && _c !== void 0 ? _c : (useWorkerThreads() ? "workerThreads" : "childProcesses"),
41
43
  },
42
44
  projectPath: normalizePath(resolvedProjectPath),
43
45
  rootPath: rootPath || projectPath || process.cwd(),
44
46
  packPath: getPackPath(),
45
47
  }, {
46
- persistentCaching: (_b = bundleOptions.config.persistentCaching) !== null && _b !== void 0 ? _b : false,
48
+ persistentCaching: (_d = bundleOptions.config.persistentCaching) !== null && _d !== void 0 ? _d : false,
47
49
  });
48
50
  const entrypointsSubscription = project.entrypointsSubscribe();
49
51
  let currentEntriesHandlingResolve;
@@ -0,0 +1 @@
1
+ export declare function useWorkerThreads(): boolean;
@@ -0,0 +1,7 @@
1
+ import semver from "semver";
2
+ export function useWorkerThreads() {
3
+ const WORKER_THREADS_SAFE_RANGE = ">=24.13.1 <25.0.0 || >=25.4.0";
4
+ return semver.satisfies(process.version, WORKER_THREADS_SAFE_RANGE, {
5
+ includePrerelease: true,
6
+ });
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.3.2-alpha.0",
3
+ "version": "1.3.3-alpha.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -41,14 +41,14 @@
41
41
  "@hono/node-server": "^1.19.11",
42
42
  "@hono/node-ws": "^1.3.0",
43
43
  "@swc/helpers": "0.5.15",
44
- "@utoo/pack-shared": "1.3.2-alpha.0",
45
- "@utoo/style-loader": "^1.0.0",
44
+ "@utoo/pack-shared": "1.3.3-alpha.0",
46
45
  "domparser-rs": "^0.0.7",
47
46
  "find-up": "4.1.0",
48
47
  "get-port": "^7.1.0",
49
48
  "hono": "^4.12.5",
50
49
  "nanoid": "^3.3.11",
51
50
  "picocolors": "^1.1.1",
51
+ "semver": "^7.7.1",
52
52
  "send": "0.17.1",
53
53
  "ws": "^8.18.1"
54
54
  },
@@ -58,7 +58,8 @@
58
58
  "postcss": "8.4.31",
59
59
  "resolve-url-loader": "^5.0.0",
60
60
  "sass": "1.54.0",
61
- "sass-loader": "^13.2.0"
61
+ "sass-loader": "^13.2.0",
62
+ "styled-jsx": "^5.1.6"
62
63
  },
63
64
  "devDependencies": {
64
65
  "@napi-rs/cli": "^2.18.0",
@@ -66,9 +67,9 @@
66
67
  "@types/mime": "^3.0.4",
67
68
  "@types/mime-types": "3.0.1",
68
69
  "@types/node": "^20.3.0",
70
+ "@types/semver": "^7.7.1",
69
71
  "@types/send": "0.14.4",
70
72
  "@types/ws": "^8.18.1",
71
- "styled-jsx": "^5.1.6",
72
73
  "typescript": "^5.8.3"
73
74
  },
74
75
  "engines": {
@@ -90,12 +91,12 @@
90
91
  },
91
92
  "repository": "git@github.com:utooland/utoo.git",
92
93
  "optionalDependencies": {
93
- "@utoo/pack-darwin-arm64": "1.3.2-alpha.0",
94
- "@utoo/pack-darwin-x64": "1.3.2-alpha.0",
95
- "@utoo/pack-linux-arm64-gnu": "1.3.2-alpha.0",
96
- "@utoo/pack-linux-arm64-musl": "1.3.2-alpha.0",
97
- "@utoo/pack-linux-x64-gnu": "1.3.2-alpha.0",
98
- "@utoo/pack-linux-x64-musl": "1.3.2-alpha.0",
99
- "@utoo/pack-win32-x64-msvc": "1.3.2-alpha.0"
94
+ "@utoo/pack-darwin-arm64": "1.3.3-alpha.0",
95
+ "@utoo/pack-darwin-x64": "1.3.3-alpha.0",
96
+ "@utoo/pack-linux-arm64-gnu": "1.3.3-alpha.0",
97
+ "@utoo/pack-linux-arm64-musl": "1.3.3-alpha.0",
98
+ "@utoo/pack-linux-x64-gnu": "1.3.3-alpha.0",
99
+ "@utoo/pack-linux-x64-musl": "1.3.3-alpha.0",
100
+ "@utoo/pack-win32-x64-msvc": "1.3.3-alpha.0"
100
101
  }
101
102
  }
@@ -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 "../config/types";
5
- import { WebpackConfig } from "../config/webpackCompat";
6
- export declare function serve(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
7
- export interface SelfSignedCertificate {
8
- key: string;
9
- cert: string;
10
- rootCA?: string;
11
- }
12
- export interface StartServerOptions {
13
- port: number;
14
- https?: boolean;
15
- hostname?: string;
16
- logServerInfo?: boolean;
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;