@utoo/pack 1.2.10-alpha.0 → 1.2.10-rc.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.
package/cjs/core/hmr.js CHANGED
@@ -8,7 +8,7 @@ exports.createHotReloader = createHotReloader;
8
8
  const pack_shared_1 = require("@utoo/pack-shared");
9
9
  const nanoid_1 = require("nanoid");
10
10
  const path_1 = __importDefault(require("path"));
11
- const ws_1 = __importDefault(require("ws"));
11
+ const ws_1 = require("ws");
12
12
  const HtmlPlugin_1 = require("../plugins/HtmlPlugin");
13
13
  const common_1 = require("../utils/common");
14
14
  const getInitialAssets_1 = require("../utils/getInitialAssets");
@@ -16,7 +16,7 @@ const htmlEntry_1 = require("../utils/htmlEntry");
16
16
  const normalize_path_1 = require("../utils/normalize-path");
17
17
  const validateEntry_1 = require("../utils/validateEntry");
18
18
  const project_1 = require("./project");
19
- const wsServer = new ws_1.default.Server({ noServer: true });
19
+ const wsServer = new ws_1.WebSocketServer({ noServer: true });
20
20
  const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
21
21
  // Re-export HMR types from pack-shared for backward compatibility
22
22
  var pack_shared_2 = require("@utoo/pack-shared");
@@ -35,6 +35,7 @@ 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 path_1 = require("path");
38
39
  const util_1 = require("util");
39
40
  const binding = __importStar(require("../binding"));
40
41
  const common_1 = require("../utils/common");
@@ -275,7 +276,7 @@ function projectFactory() {
275
276
  constructor(nativeProject) {
276
277
  this._nativeProject = nativeProject;
277
278
  if (typeof binding.registerWorkerScheduler === "function") {
278
- (0, loaderWorkerPool_1.runLoaderWorkerPool)(binding, require.resolve("@utoo/pack/cjs/binding.js"));
279
+ (0, loaderWorkerPool_1.runLoaderWorkerPool)(binding, (0, path_1.resolve)((0, common_1.getPackPath)(), "./binding.js"));
279
280
  }
280
281
  }
281
282
  async update(options) {
@@ -1,3 +1,8 @@
1
1
  export { createDefineEnv, debounce, isWellKnownError, ModuleBuildError, processIssues, rustifyEnv, } from "@utoo/pack-shared";
2
2
  export declare function blockStdout(): void;
3
+ /**
4
+ * Pack 根目录(pack 包所在目录)。
5
+ * - CJS:使用 __dirname。
6
+ * - ESM:在构建后由脚本注入 __dirname(基于 import.meta.url),此处仅用 __dirname 以保持 CJS 产物不含 import.meta,避免 Node 将 .js 判为 ESM。
7
+ */
3
8
  export declare function getPackPath(): string;
@@ -27,6 +27,11 @@ function blockStdout() {
27
27
  process.stderr._handle.setBlocking(true);
28
28
  }
29
29
  }
30
+ /**
31
+ * Pack 根目录(pack 包所在目录)。
32
+ * - CJS:使用 __dirname。
33
+ * - ESM:在构建后由脚本注入 __dirname(基于 import.meta.url),此处仅用 __dirname 以保持 CJS 产物不含 import.meta,避免 Node 将 .js 判为 ESM。
34
+ */
30
35
  function getPackPath() {
31
36
  return path_1.default.resolve(__dirname, "..");
32
37
  }
@@ -9,8 +9,8 @@ const node_child_process_1 = require("node:child_process");
9
9
  const node_crypto_1 = require("node:crypto");
10
10
  const node_fs_1 = __importDefault(require("node:fs"));
11
11
  const node_path_1 = __importDefault(require("node:path"));
12
+ const web_1 = require("node:stream/web");
12
13
  const os_1 = __importDefault(require("os"));
13
- const { WritableStream } = require("node:stream/web");
14
14
  const MKCERT_VERSION = "v1.4.4";
15
15
  function getBinaryName() {
16
16
  const platform = process.platform;
@@ -43,7 +43,7 @@ async function downloadBinary() {
43
43
  }
44
44
  console.log(`Download response was successful, writing to disk`);
45
45
  const binaryWriteStream = node_fs_1.default.createWriteStream(binaryPath);
46
- await response.body.pipeTo(new WritableStream({
46
+ await response.body.pipeTo(new web_1.WritableStream({
47
47
  write(chunk) {
48
48
  return new Promise((resolve, reject) => {
49
49
  binaryWriteStream.write(chunk, (error) => {
@@ -3,16 +3,16 @@ import { spawn } from "child_process";
3
3
  import fs from "fs";
4
4
  import { nanoid } from "nanoid";
5
5
  import path from "path";
6
- import { resolveBundleOptions } from "../config/webpackCompat";
7
- import { projectFactory } from "../core/project";
8
- import { HtmlPlugin } from "../plugins/HtmlPlugin";
9
- import { blockStdout, createDefineEnv, getPackPath } from "../utils/common";
10
- import { findRootDir } from "../utils/findRoot";
11
- import { getInitialAssetsFromStats } from "../utils/getInitialAssets";
12
- import { processHtmlEntry } from "../utils/htmlEntry";
13
- import { normalizePath } from "../utils/normalize-path";
14
- import { validateEntryPaths } from "../utils/validateEntry";
15
- import { xcodeProfilingReady } from "../utils/xcodeProfile";
6
+ import { resolveBundleOptions } from "../config/webpackCompat.js";
7
+ import { projectFactory } from "../core/project.js";
8
+ import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
9
+ import { blockStdout, createDefineEnv, getPackPath } from "../utils/common.js";
10
+ import { findRootDir } from "../utils/findRoot.js";
11
+ import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
12
+ import { processHtmlEntry } from "../utils/htmlEntry.js";
13
+ import { normalizePath } from "../utils/normalize-path.js";
14
+ import { validateEntryPaths } from "../utils/validateEntry.js";
15
+ import { xcodeProfilingReady } from "../utils/xcodeProfile.js";
16
16
  export function build(options, projectPath, rootPath) {
17
17
  const bundleOptions = resolveBundleOptions(options, projectPath, rootPath);
18
18
  if (!rootPath) {
@@ -5,13 +5,13 @@ import { isIPv6 } from "net";
5
5
  import path from "path";
6
6
  import send from "send";
7
7
  import url from "url";
8
- import { resolveBundleOptions } from "../config/webpackCompat";
9
- import { createHotReloader } from "../core/hmr";
10
- import { blockStdout, getPackPath } from "../utils/common";
11
- import { findRootDir } from "../utils/findRoot";
12
- import { createSelfSignedCertificate } from "../utils/mkcert";
13
- import { printServerInfo } from "../utils/printServerInfo";
14
- import { xcodeProfilingReady } from "../utils/xcodeProfile";
8
+ import { resolveBundleOptions } from "../config/webpackCompat.js";
9
+ import { createHotReloader } from "../core/hmr.js";
10
+ import { blockStdout, getPackPath } from "../utils/common.js";
11
+ import { findRootDir } from "../utils/findRoot.js";
12
+ import { createSelfSignedCertificate } from "../utils/mkcert.js";
13
+ import { printServerInfo } from "../utils/printServerInfo.js";
14
+ import { xcodeProfilingReady } from "../utils/xcodeProfile.js";
15
15
  function parsePath(pathStr) {
16
16
  const hashIndex = pathStr.indexOf("#");
17
17
  const queryIndex = pathStr.indexOf("?");
@@ -1,7 +1,7 @@
1
1
  import { compatOptionsFromWebpack, } from "@utoo/pack-shared";
2
- import { readWebpackConfig } from "./readWebpackConfig";
2
+ import { readWebpackConfig } from "./readWebpackConfig.js";
3
3
  export { compatOptionsFromWebpack, } from "@utoo/pack-shared";
4
- export { readWebpackConfig } from "./readWebpackConfig";
4
+ export { readWebpackConfig } from "./readWebpackConfig.js";
5
5
  export function resolveBundleOptions(options, projectPath, rootPath) {
6
6
  if (options.webpackMode) {
7
7
  let webpackConfig = options;
package/esm/core/hmr.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
2
2
  import { nanoid } from "nanoid";
3
3
  import path from "path";
4
- import ws from "ws";
5
- import { HtmlPlugin } from "../plugins/HtmlPlugin";
6
- import { createDefineEnv, debounce, getPackPath, processIssues, } from "../utils/common";
7
- import { getInitialAssetsFromStats } from "../utils/getInitialAssets";
8
- import { processHtmlEntry } from "../utils/htmlEntry";
9
- import { normalizePath } from "../utils/normalize-path";
10
- import { validateEntryPaths } from "../utils/validateEntry";
11
- import { projectFactory } from "./project";
12
- const wsServer = new ws.Server({ noServer: true });
4
+ import { WebSocketServer } from "ws";
5
+ import { HtmlPlugin } from "../plugins/HtmlPlugin.js";
6
+ import { createDefineEnv, debounce, getPackPath, processIssues, } from "../utils/common.js";
7
+ import { getInitialAssetsFromStats } from "../utils/getInitialAssets.js";
8
+ import { processHtmlEntry } from "../utils/htmlEntry.js";
9
+ import { normalizePath } from "../utils/normalize-path.js";
10
+ import { validateEntryPaths } from "../utils/validateEntry.js";
11
+ import { projectFactory } from "./project.js";
12
+ const wsServer = new WebSocketServer({ noServer: true });
13
13
  const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
14
14
  // Re-export HMR types from pack-shared for backward compatibility
15
15
  export { HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
@@ -1,7 +1,8 @@
1
+ import { resolve } from "path";
1
2
  import { isDeepStrictEqual } from "util";
2
- import * as binding from "../binding";
3
- import { rustifyEnv } from "../utils/common";
4
- import { runLoaderWorkerPool } from "./loaderWorkerPool";
3
+ import * as binding from "../binding.js";
4
+ import { getPackPath, rustifyEnv } from "../utils/common.js";
5
+ import { runLoaderWorkerPool } from "./loaderWorkerPool.js";
5
6
  export class TurbopackInternalError extends Error {
6
7
  constructor(cause) {
7
8
  super(cause.message);
@@ -237,7 +238,7 @@ export function projectFactory() {
237
238
  constructor(nativeProject) {
238
239
  this._nativeProject = nativeProject;
239
240
  if (typeof binding.registerWorkerScheduler === "function") {
240
- runLoaderWorkerPool(binding, require.resolve("@utoo/pack/cjs/binding.js"));
241
+ runLoaderWorkerPool(binding, resolve(getPackPath(), "./binding.js"));
241
242
  }
242
243
  }
243
244
  async update(options) {
package/esm/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { build } from "./commands/build";
2
- import { serve } from "./commands/dev";
1
+ import { build } from "./commands/build.js";
2
+ import { serve } from "./commands/dev.js";
3
3
  export { build };
4
4
  export { serve };
5
5
  const utoopack = { build, serve };
6
6
  export default utoopack;
7
- export * from "./config/types";
8
- export * from "./config/webpackCompat";
9
- export * from "./core/types";
10
- export * from "./utils/findRoot";
7
+ export * from "./config/types.js";
8
+ export * from "./config/webpackCompat.js";
9
+ export * from "./core/types.js";
10
+ export * from "./utils/findRoot.js";
@@ -1,3 +1,8 @@
1
1
  export { createDefineEnv, debounce, isWellKnownError, ModuleBuildError, processIssues, rustifyEnv, } from "@utoo/pack-shared";
2
2
  export declare function blockStdout(): void;
3
+ /**
4
+ * Pack 根目录(pack 包所在目录)。
5
+ * - CJS:使用 __dirname。
6
+ * - ESM:在构建后由脚本注入 __dirname(基于 import.meta.url),此处仅用 __dirname 以保持 CJS 产物不含 import.meta,避免 Node 将 .js 判为 ESM。
7
+ */
3
8
  export declare function getPackPath(): string;
@@ -1,4 +1,6 @@
1
1
  import path from "path";
2
+ import { fileURLToPath } from "node:url";
3
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
2
4
  export { createDefineEnv, debounce, isWellKnownError, ModuleBuildError, processIssues, rustifyEnv, } from "@utoo/pack-shared";
3
5
  // ref:
4
6
  // https://github.com/vercel/next.js/pull/51883
@@ -13,6 +15,11 @@ export function blockStdout() {
13
15
  process.stderr._handle.setBlocking(true);
14
16
  }
15
17
  }
18
+ /**
19
+ * Pack 根目录(pack 包所在目录)。
20
+ * - CJS:使用 __dirname。
21
+ * - ESM:在构建后由脚本注入 __dirname(基于 import.meta.url),此处仅用 __dirname 以保持 CJS 产物不含 import.meta,避免 Node 将 .js 判为 ESM。
22
+ */
16
23
  export function getPackPath() {
17
24
  return path.resolve(__dirname, "..");
18
25
  }
@@ -2,8 +2,8 @@ import { execSync } from "node:child_process";
2
2
  import { createPrivateKey, X509Certificate } from "node:crypto";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
+ import { WritableStream } from "node:stream/web";
5
6
  import os from "os";
6
- const { WritableStream } = require("node:stream/web");
7
7
  const MKCERT_VERSION = "v1.4.4";
8
8
  function getBinaryName() {
9
9
  const platform = process.platform;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.2.10-alpha.0",
3
+ "version": "1.2.10-rc.2",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -39,7 +39,7 @@
39
39
  "dependencies": {
40
40
  "@babel/code-frame": "7.22.5",
41
41
  "@swc/helpers": "0.5.15",
42
- "@utoo/pack-shared": "1.2.10-alpha.0",
42
+ "@utoo/pack-shared": "1.2.10-rc.2",
43
43
  "@utoo/style-loader": "^1.0.0",
44
44
  "domparser-rs": "^0.0.7",
45
45
  "find-up": "4.1.0",
@@ -74,7 +74,7 @@
74
74
  "build": "npm run build:binding && npm run build:cjs && npm run build:esm",
75
75
  "build:js": "npm run build:cjs && npm run build:esm",
76
76
  "build:cjs": "rm -rf cjs && tsc -p ./tsconfig.json --module commonjs --outDir cjs && cp src/*.d.ts cjs/",
77
- "build:esm": "rm -rf esm && tsc -p ./tsconfig.json --module esnext --outDir esm && cp src/*.d.ts esm/",
77
+ "build:esm": "rm -rf esm && tsc -p ./tsconfig.json --module esnext --outDir esm && cp src/*.d.ts esm/ && node ../../scripts/add-esm-extensions.cjs && node scripts/inject-esm-dirname.cjs",
78
78
  "build:local": "npm run build:binding:local && npx turbo run build --filter=@utoo/pack-shared && npm run build:cjs && npm run build:esm && cp src/*.node cjs/ && cp src/*.node esm/",
79
79
  "artifacts": "napi artifacts --dir ./src --dist npm",
80
80
  "build:binding": "napi build src --platform --release -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts",
@@ -86,12 +86,12 @@
86
86
  },
87
87
  "repository": "git@github.com:utooland/utoo.git",
88
88
  "optionalDependencies": {
89
- "@utoo/pack-darwin-arm64": "1.2.10-alpha.0",
90
- "@utoo/pack-darwin-x64": "1.2.10-alpha.0",
91
- "@utoo/pack-linux-arm64-gnu": "1.2.10-alpha.0",
92
- "@utoo/pack-linux-arm64-musl": "1.2.10-alpha.0",
93
- "@utoo/pack-linux-x64-gnu": "1.2.10-alpha.0",
94
- "@utoo/pack-linux-x64-musl": "1.2.10-alpha.0",
95
- "@utoo/pack-win32-x64-msvc": "1.2.10-alpha.0"
89
+ "@utoo/pack-darwin-arm64": "1.2.10-rc.2",
90
+ "@utoo/pack-darwin-x64": "1.2.10-rc.2",
91
+ "@utoo/pack-linux-arm64-gnu": "1.2.10-rc.2",
92
+ "@utoo/pack-linux-arm64-musl": "1.2.10-rc.2",
93
+ "@utoo/pack-linux-x64-gnu": "1.2.10-rc.2",
94
+ "@utoo/pack-linux-x64-musl": "1.2.10-rc.2",
95
+ "@utoo/pack-win32-x64-msvc": "1.2.10-rc.2"
96
96
  }
97
97
  }