@utoo/pack 1.1.25 → 1.2.0-alpha.1

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.
@@ -1,3 +1,3 @@
1
+ import { BundleOptions } from "../config/types";
1
2
  import { WebpackConfig } from "../config/webpackCompat";
2
- import { BundleOptions } from "../core/types";
3
3
  export declare function build(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string): Promise<void>;
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.build = build;
4
7
  const pack_shared_1 = require("@utoo/pack-shared");
5
8
  const child_process_1 = require("child_process");
6
- const fs_1 = require("fs");
9
+ const fs_1 = __importDefault(require("fs"));
7
10
  const nanoid_1 = require("nanoid");
8
- const path_1 = require("path");
11
+ const path_1 = __importDefault(require("path"));
9
12
  const webpackCompat_1 = require("../config/webpackCompat");
10
13
  const project_1 = require("../core/project");
11
14
  const HtmlPlugin_1 = require("../plugins/HtmlPlugin");
@@ -65,11 +68,13 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
65
68
  : bundleOptions.config.html
66
69
  ? [bundleOptions.config.html]
67
70
  : []),
68
- ...bundleOptions.config.entry.filter((e) => !!e.html).map((e) => e.html),
71
+ ...bundleOptions.config.entry
72
+ .filter((e) => !!e.html)
73
+ .map((e) => e.html),
69
74
  ];
70
75
  if (htmlConfigs.length > 0) {
71
76
  const assets = { js: [], css: [] };
72
- const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || (0, path_1.join)(process.cwd(), "dist");
77
+ const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || path_1.default.join(process.cwd(), "dist");
73
78
  if (assets.js.length === 0 && assets.css.length === 0) {
74
79
  const discovered = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
75
80
  assets.js.push(...discovered.js);
@@ -89,8 +94,8 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
89
94
  // https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
90
95
  }
91
96
  async function analyzeBundle(outputPath) {
92
- const statsPath = (0, path_1.join)(outputPath, "stats.json");
93
- if (!(0, fs_1.existsSync)(statsPath)) {
97
+ const statsPath = path_1.default.join(outputPath, "stats.json");
98
+ if (!fs_1.default.existsSync(statsPath)) {
94
99
  console.warn(`Stats file not found at ${statsPath}. Make sure to enable stats in your configuration.`);
95
100
  return;
96
101
  }
@@ -1,8 +1,8 @@
1
1
  import { IncomingMessage, ServerResponse } from "http";
2
2
  import send from "send";
3
3
  import { Duplex, Writable } from "stream";
4
+ import { BundleOptions } from "../config/types";
4
5
  import { WebpackConfig } from "../config/webpackCompat";
5
- import { BundleOptions } from "../core/types";
6
6
  export declare function serve(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
7
7
  export interface SelfSignedCertificate {
8
8
  key: string;
package/cjs/core/hmr.d.ts CHANGED
@@ -1,57 +1,9 @@
1
+ import { type HMR_ACTION_TYPES } from "@utoo/pack-shared";
1
2
  import { IncomingMessage } from "http";
2
3
  import { Duplex } from "stream";
3
- import { BundleOptions, Project, Update as TurbopackUpdate } from "./types";
4
- export declare const enum HMR_ACTIONS_SENT_TO_BROWSER {
5
- RELOAD = "reload",
6
- CLIENT_CHANGES = "clientChanges",
7
- SERVER_ONLY_CHANGES = "serverOnlyChanges",
8
- SYNC = "sync",
9
- BUILT = "built",
10
- BUILDING = "building",
11
- TURBOPACK_MESSAGE = "turbopack-message",
12
- TURBOPACK_CONNECTED = "turbopack-connected"
13
- }
14
- export interface TurbopackMessageAction {
15
- action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE;
16
- data: TurbopackUpdate | TurbopackUpdate[];
17
- }
18
- export interface TurbopackConnectedAction {
19
- action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED;
20
- data: {
21
- sessionId: number;
22
- };
23
- }
24
- interface BuildingAction {
25
- action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING;
26
- }
27
- export interface CompilationError {
28
- moduleName?: string;
29
- message: string;
30
- details?: string;
31
- moduleTrace?: Array<{
32
- moduleName?: string;
33
- }>;
34
- stack?: string;
35
- }
36
- export interface SyncAction {
37
- action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC;
38
- hash: string;
39
- errors: ReadonlyArray<CompilationError>;
40
- warnings: ReadonlyArray<CompilationError>;
41
- updatedModules?: ReadonlyArray<string>;
42
- }
43
- export interface BuiltAction {
44
- action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT;
45
- hash: string;
46
- errors: ReadonlyArray<CompilationError>;
47
- warnings: ReadonlyArray<CompilationError>;
48
- updatedModules?: ReadonlyArray<string>;
49
- }
50
- export interface ReloadAction {
51
- action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD;
52
- data: string;
53
- }
54
- export type HMR_ACTION_TYPES = TurbopackMessageAction | TurbopackConnectedAction | BuildingAction | SyncAction | BuiltAction | ReloadAction;
4
+ import { BundleOptions } from "../config/types";
5
+ import { Project, Update as TurbopackUpdate } from "./types";
6
+ export { type BuildingAction, type BuiltAction, type CompilationError, type HMR_ACTION_TYPES, HMR_ACTIONS_SENT_TO_BROWSER, type ReloadAction, type SyncAction, type TurbopackConnectedAction, type TurbopackMessageAction, } from "@utoo/pack-shared";
55
7
  export interface WebpackStats {
56
8
  hash?: string;
57
9
  startTime?: number;
@@ -85,4 +37,3 @@ export type ClientState = {
85
37
  export type SendHmr = (id: string, payload: HMR_ACTION_TYPES) => void;
86
38
  export declare const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
87
39
  export declare function createHotReloader(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<HotReloaderInterface>;
88
- export {};
package/cjs/core/hmr.js CHANGED
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FAST_REFRESH_RUNTIME_RELOAD = void 0;
6
+ exports.FAST_REFRESH_RUNTIME_RELOAD = exports.HMR_ACTIONS_SENT_TO_BROWSER = void 0;
7
7
  exports.createHotReloader = createHotReloader;
8
+ const pack_shared_1 = require("@utoo/pack-shared");
8
9
  const nanoid_1 = require("nanoid");
9
- const path_1 = require("path");
10
+ const path_1 = __importDefault(require("path"));
10
11
  const ws_1 = __importDefault(require("ws"));
11
12
  const HtmlPlugin_1 = require("../plugins/HtmlPlugin");
12
13
  const common_1 = require("../utils/common");
@@ -16,6 +17,9 @@ const validateEntry_1 = require("../utils/validateEntry");
16
17
  const project_1 = require("./project");
17
18
  const wsServer = new ws_1.default.Server({ noServer: true });
18
19
  const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
20
+ // Re-export HMR types from pack-shared for backward compatibility
21
+ var pack_shared_2 = require("@utoo/pack-shared");
22
+ Object.defineProperty(exports, "HMR_ACTIONS_SENT_TO_BROWSER", { enumerable: true, get: function () { return pack_shared_2.HMR_ACTIONS_SENT_TO_BROWSER; } });
19
23
  exports.FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
20
24
  async function createHotReloader(bundleOptions, projectPath, rootPath) {
21
25
  var _a;
@@ -75,7 +79,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
75
79
  state.hmrPayloads.clear();
76
80
  if (state.turbopackUpdates.length > 0) {
77
81
  sendToClient(client, {
78
- action: "turbopack-message" /* HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE */,
82
+ action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE,
79
83
  data: state.turbopackUpdates,
80
84
  });
81
85
  state.turbopackUpdates.length = 0;
@@ -117,7 +121,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
117
121
  // `hotReloader.send` since that would force every connected client to
118
122
  // reload, only this client is out of date.
119
123
  const reloadAction = {
120
- action: "reload" /* HMR_ACTIONS_SENT_TO_BROWSER.RELOAD */,
124
+ action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.RELOAD,
121
125
  data: `error in HMR event subscription for ${id}: ${e}`,
122
126
  };
123
127
  sendToClient(client, reloadAction);
@@ -156,7 +160,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
156
160
  .map((e) => e.html),
157
161
  ];
158
162
  if (htmlConfigs.length > 0) {
159
- const outputDir = ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || (0, path_1.join)(process.cwd(), "dist");
163
+ const outputDir = ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || path_1.default.join(process.cwd(), "dist");
160
164
  const publicPath = (_b = bundleOptions.config.output) === null || _b === void 0 ? void 0 : _b.publicPath;
161
165
  if (assets.js.length === 0 && assets.css.length === 0) {
162
166
  const discovered = (0, getInitialAssets_1.getInitialAssetsFromStats)(outputDir);
@@ -235,14 +239,14 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
235
239
  }
236
240
  });
237
241
  const turbopackConnected = {
238
- action: "turbopack-connected" /* HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED */,
242
+ action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
239
243
  data: { sessionId },
240
244
  };
241
245
  sendToClient(client, turbopackConnected);
242
246
  const errors = [];
243
247
  (async function () {
244
248
  const sync = {
245
- action: "sync" /* HMR_ACTIONS_SENT_TO_BROWSER.SYNC */,
249
+ action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
246
250
  errors,
247
251
  warnings: [],
248
252
  hash: "",
@@ -285,7 +289,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
285
289
  for await (const updateMessage of project.updateInfoSubscribe(30)) {
286
290
  switch (updateMessage.updateType) {
287
291
  case "start": {
288
- hotReloader.send({ action: "building" /* HMR_ACTIONS_SENT_TO_BROWSER.BUILDING */ });
292
+ hotReloader.send({ action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.BUILDING });
289
293
  break;
290
294
  }
291
295
  case "end": {
@@ -298,7 +302,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
298
302
  }
299
303
  const clientErrors = new Map(errors);
300
304
  sendToClient(client, {
301
- action: "built" /* HMR_ACTIONS_SENT_TO_BROWSER.BUILT */,
305
+ action: pack_shared_1.HMR_ACTIONS_SENT_TO_BROWSER.BUILT,
302
306
  hash: String(++hmrHash),
303
307
  errors: [...clientErrors.values()],
304
308
  warnings: [],
@@ -58,7 +58,6 @@ export interface ProjectOptions extends BundleOptions {
58
58
  */
59
59
  projectPath: string;
60
60
  }
61
- export { BundleOptions };
62
61
  export interface Project {
63
62
  update(options: Partial<ProjectOptions>): Promise<void>;
64
63
  entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
package/cjs/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export default utoopack;
11
11
  export * from "./config/types";
12
12
  export * from "./config/webpackCompat";
13
13
  export * from "./core/types";
14
+ export { BaseUpdate, EcmascriptMergedUpdate, IssuesUpdate, PartialUpdate, Update, } from "./core/types";
14
15
  export * from "./utils/findRoot";
15
16
  export type WebpackConfig = webpackCompat.WebpackConfig;
16
17
  declare namespace utoopack {
@@ -8,8 +8,8 @@ exports.findPackageJson = findPackageJson;
8
8
  exports.findWorkspacesRoot = findWorkspacesRoot;
9
9
  exports.findRootDir = findRootDir;
10
10
  const find_up_1 = __importDefault(require("find-up"));
11
- const fs_1 = require("fs");
12
- const path_1 = require("path");
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const path_1 = __importDefault(require("path"));
13
13
  function findRootLockFile(cwd) {
14
14
  return find_up_1.default.sync([
15
15
  "pnpm-lock.yaml",
@@ -28,7 +28,7 @@ function findPackageJson(cwd) {
28
28
  });
29
29
  }
30
30
  function isWorkspaceRoot(pkgPath) {
31
- const pkgJson = (0, fs_1.readFileSync)(pkgPath, "utf-8");
31
+ const pkgJson = fs_1.default.readFileSync(pkgPath, "utf-8");
32
32
  const pkgJsonContent = JSON.parse(pkgJson);
33
33
  return Boolean(pkgJsonContent.workspaces);
34
34
  }
@@ -41,8 +41,8 @@ function findWorkspacesRoot(cwd) {
41
41
  const pkgJsonFiles = [pkgJson];
42
42
  while (true) {
43
43
  const lastPkgJson = pkgJsonFiles[pkgJsonFiles.length - 1];
44
- const currentDir = (0, path_1.dirname)(lastPkgJson);
45
- const parentDir = (0, path_1.dirname)(currentDir);
44
+ const currentDir = path_1.default.dirname(lastPkgJson);
45
+ const parentDir = path_1.default.dirname(currentDir);
46
46
  if (parentDir === currentDir)
47
47
  break;
48
48
  if (isWorkspaceRoot(lastPkgJson))
@@ -52,7 +52,7 @@ function findWorkspacesRoot(cwd) {
52
52
  break;
53
53
  pkgJsonFiles.push(newPkgJson);
54
54
  }
55
- return (0, path_1.dirname)(pkgJsonFiles[pkgJsonFiles.length - 1]);
55
+ return path_1.default.dirname(pkgJsonFiles[pkgJsonFiles.length - 1]);
56
56
  }
57
57
  function findRootDir(cwd) {
58
58
  const lockFile = findRootLockFile(cwd);
@@ -61,9 +61,9 @@ function findRootDir(cwd) {
61
61
  const lockFiles = [lockFile];
62
62
  while (true) {
63
63
  const lastLockFile = lockFiles[lockFiles.length - 1];
64
- const currentDir = (0, path_1.dirname)(lastLockFile);
65
- const parentDir = (0, path_1.dirname)(currentDir);
66
- // dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
64
+ const currentDir = path_1.default.dirname(lastLockFile);
65
+ const parentDir = path_1.default.dirname(currentDir);
66
+ // path.dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
67
67
  if (parentDir === currentDir)
68
68
  break;
69
69
  const newLockFile = findRootLockFile(parentDir);
@@ -71,5 +71,5 @@ function findRootDir(cwd) {
71
71
  break;
72
72
  lockFiles.push(newLockFile);
73
73
  }
74
- return (0, path_1.dirname)(lockFiles[lockFiles.length - 1]);
74
+ return path_1.default.dirname(lockFiles[lockFiles.length - 1]);
75
75
  }
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getInitialAssetsFromStats = getInitialAssetsFromStats;
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const path_1 = require("path");
8
+ const path_1 = __importDefault(require("path"));
9
9
  function getInitialAssetsFromStats(outputDir) {
10
10
  const assets = { js: [], css: [] };
11
- const statsPath = (0, path_1.join)(outputDir, "stats.json");
11
+ const statsPath = path_1.default.join(outputDir, "stats.json");
12
12
  if (fs_1.default.existsSync(statsPath)) {
13
13
  try {
14
14
  const stats = JSON.parse(fs_1.default.readFileSync(statsPath, "utf-8"));
@@ -1,3 +1,3 @@
1
+ import { BundleOptions } from "../config/types";
1
2
  import { WebpackConfig } from "../config/webpackCompat";
2
- import { BundleOptions } from "../core/types";
3
3
  export declare function build(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  import { handleIssues } from "@utoo/pack-shared";
2
2
  import { spawn } from "child_process";
3
- import { existsSync } from "fs";
3
+ import fs from "fs";
4
4
  import { nanoid } from "nanoid";
5
- import { join } from "path";
5
+ import path from "path";
6
6
  import { resolveBundleOptions } from "../config/webpackCompat";
7
7
  import { projectFactory } from "../core/project";
8
8
  import { HtmlPlugin } from "../plugins/HtmlPlugin";
@@ -62,11 +62,13 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
62
62
  : bundleOptions.config.html
63
63
  ? [bundleOptions.config.html]
64
64
  : []),
65
- ...bundleOptions.config.entry.filter((e) => !!e.html).map((e) => e.html),
65
+ ...bundleOptions.config.entry
66
+ .filter((e) => !!e.html)
67
+ .map((e) => e.html),
66
68
  ];
67
69
  if (htmlConfigs.length > 0) {
68
70
  const assets = { js: [], css: [] };
69
- const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || join(process.cwd(), "dist");
71
+ const outputDir = ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || path.join(process.cwd(), "dist");
70
72
  if (assets.js.length === 0 && assets.css.length === 0) {
71
73
  const discovered = getInitialAssetsFromStats(outputDir);
72
74
  assets.js.push(...discovered.js);
@@ -86,8 +88,8 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
86
88
  // https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
87
89
  }
88
90
  async function analyzeBundle(outputPath) {
89
- const statsPath = join(outputPath, "stats.json");
90
- if (!existsSync(statsPath)) {
91
+ const statsPath = path.join(outputPath, "stats.json");
92
+ if (!fs.existsSync(statsPath)) {
91
93
  console.warn(`Stats file not found at ${statsPath}. Make sure to enable stats in your configuration.`);
92
94
  return;
93
95
  }
@@ -1,8 +1,8 @@
1
1
  import { IncomingMessage, ServerResponse } from "http";
2
2
  import send from "send";
3
3
  import { Duplex, Writable } from "stream";
4
+ import { BundleOptions } from "../config/types";
4
5
  import { WebpackConfig } from "../config/webpackCompat";
5
- import { BundleOptions } from "../core/types";
6
6
  export declare function serve(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string, serverOptions?: StartServerOptions): Promise<void>;
7
7
  export interface SelfSignedCertificate {
8
8
  key: string;
package/esm/core/hmr.d.ts CHANGED
@@ -1,57 +1,9 @@
1
+ import { type HMR_ACTION_TYPES } from "@utoo/pack-shared";
1
2
  import { IncomingMessage } from "http";
2
3
  import { Duplex } from "stream";
3
- import { BundleOptions, Project, Update as TurbopackUpdate } from "./types";
4
- export declare const enum HMR_ACTIONS_SENT_TO_BROWSER {
5
- RELOAD = "reload",
6
- CLIENT_CHANGES = "clientChanges",
7
- SERVER_ONLY_CHANGES = "serverOnlyChanges",
8
- SYNC = "sync",
9
- BUILT = "built",
10
- BUILDING = "building",
11
- TURBOPACK_MESSAGE = "turbopack-message",
12
- TURBOPACK_CONNECTED = "turbopack-connected"
13
- }
14
- export interface TurbopackMessageAction {
15
- action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE;
16
- data: TurbopackUpdate | TurbopackUpdate[];
17
- }
18
- export interface TurbopackConnectedAction {
19
- action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED;
20
- data: {
21
- sessionId: number;
22
- };
23
- }
24
- interface BuildingAction {
25
- action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING;
26
- }
27
- export interface CompilationError {
28
- moduleName?: string;
29
- message: string;
30
- details?: string;
31
- moduleTrace?: Array<{
32
- moduleName?: string;
33
- }>;
34
- stack?: string;
35
- }
36
- export interface SyncAction {
37
- action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC;
38
- hash: string;
39
- errors: ReadonlyArray<CompilationError>;
40
- warnings: ReadonlyArray<CompilationError>;
41
- updatedModules?: ReadonlyArray<string>;
42
- }
43
- export interface BuiltAction {
44
- action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT;
45
- hash: string;
46
- errors: ReadonlyArray<CompilationError>;
47
- warnings: ReadonlyArray<CompilationError>;
48
- updatedModules?: ReadonlyArray<string>;
49
- }
50
- export interface ReloadAction {
51
- action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD;
52
- data: string;
53
- }
54
- export type HMR_ACTION_TYPES = TurbopackMessageAction | TurbopackConnectedAction | BuildingAction | SyncAction | BuiltAction | ReloadAction;
4
+ import { BundleOptions } from "../config/types";
5
+ import { Project, Update as TurbopackUpdate } from "./types";
6
+ export { type BuildingAction, type BuiltAction, type CompilationError, type HMR_ACTION_TYPES, HMR_ACTIONS_SENT_TO_BROWSER, type ReloadAction, type SyncAction, type TurbopackConnectedAction, type TurbopackMessageAction, } from "@utoo/pack-shared";
55
7
  export interface WebpackStats {
56
8
  hash?: string;
57
9
  startTime?: number;
@@ -85,4 +37,3 @@ export type ClientState = {
85
37
  export type SendHmr = (id: string, payload: HMR_ACTION_TYPES) => void;
86
38
  export declare const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
87
39
  export declare function createHotReloader(bundleOptions: BundleOptions, projectPath?: string, rootPath?: string): Promise<HotReloaderInterface>;
88
- export {};
package/esm/core/hmr.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
1
2
  import { nanoid } from "nanoid";
2
- import { join } from "path";
3
+ import path from "path";
3
4
  import ws from "ws";
4
5
  import { HtmlPlugin } from "../plugins/HtmlPlugin";
5
6
  import { createDefineEnv, debounce, getPackPath, processIssues, } from "../utils/common";
@@ -9,6 +10,8 @@ import { validateEntryPaths } from "../utils/validateEntry";
9
10
  import { projectFactory } from "./project";
10
11
  const wsServer = new ws.Server({ noServer: true });
11
12
  const sessionId = Math.floor(Number.MAX_SAFE_INTEGER * Math.random());
13
+ // Re-export HMR types from pack-shared for backward compatibility
14
+ export { HMR_ACTIONS_SENT_TO_BROWSER, } from "@utoo/pack-shared";
12
15
  export const FAST_REFRESH_RUNTIME_RELOAD = "Fast Refresh had to perform a full reload due to a runtime error.";
13
16
  export async function createHotReloader(bundleOptions, projectPath, rootPath) {
14
17
  var _a;
@@ -68,7 +71,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
68
71
  state.hmrPayloads.clear();
69
72
  if (state.turbopackUpdates.length > 0) {
70
73
  sendToClient(client, {
71
- action: "turbopack-message" /* HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE */,
74
+ action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE,
72
75
  data: state.turbopackUpdates,
73
76
  });
74
77
  state.turbopackUpdates.length = 0;
@@ -110,7 +113,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
110
113
  // `hotReloader.send` since that would force every connected client to
111
114
  // reload, only this client is out of date.
112
115
  const reloadAction = {
113
- action: "reload" /* HMR_ACTIONS_SENT_TO_BROWSER.RELOAD */,
116
+ action: HMR_ACTIONS_SENT_TO_BROWSER.RELOAD,
114
117
  data: `error in HMR event subscription for ${id}: ${e}`,
115
118
  };
116
119
  sendToClient(client, reloadAction);
@@ -149,7 +152,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
149
152
  .map((e) => e.html),
150
153
  ];
151
154
  if (htmlConfigs.length > 0) {
152
- const outputDir = ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || join(process.cwd(), "dist");
155
+ const outputDir = ((_a = bundleOptions.config.output) === null || _a === void 0 ? void 0 : _a.path) || path.join(process.cwd(), "dist");
153
156
  const publicPath = (_b = bundleOptions.config.output) === null || _b === void 0 ? void 0 : _b.publicPath;
154
157
  if (assets.js.length === 0 && assets.css.length === 0) {
155
158
  const discovered = getInitialAssetsFromStats(outputDir);
@@ -228,14 +231,14 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
228
231
  }
229
232
  });
230
233
  const turbopackConnected = {
231
- action: "turbopack-connected" /* HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED */,
234
+ action: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
232
235
  data: { sessionId },
233
236
  };
234
237
  sendToClient(client, turbopackConnected);
235
238
  const errors = [];
236
239
  (async function () {
237
240
  const sync = {
238
- action: "sync" /* HMR_ACTIONS_SENT_TO_BROWSER.SYNC */,
241
+ action: HMR_ACTIONS_SENT_TO_BROWSER.SYNC,
239
242
  errors,
240
243
  warnings: [],
241
244
  hash: "",
@@ -278,7 +281,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
278
281
  for await (const updateMessage of project.updateInfoSubscribe(30)) {
279
282
  switch (updateMessage.updateType) {
280
283
  case "start": {
281
- hotReloader.send({ action: "building" /* HMR_ACTIONS_SENT_TO_BROWSER.BUILDING */ });
284
+ hotReloader.send({ action: HMR_ACTIONS_SENT_TO_BROWSER.BUILDING });
282
285
  break;
283
286
  }
284
287
  case "end": {
@@ -291,7 +294,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
291
294
  }
292
295
  const clientErrors = new Map(errors);
293
296
  sendToClient(client, {
294
- action: "built" /* HMR_ACTIONS_SENT_TO_BROWSER.BUILT */,
297
+ action: HMR_ACTIONS_SENT_TO_BROWSER.BUILT,
295
298
  hash: String(++hmrHash),
296
299
  errors: [...clientErrors.values()],
297
300
  warnings: [],
@@ -58,7 +58,6 @@ export interface ProjectOptions extends BundleOptions {
58
58
  */
59
59
  projectPath: string;
60
60
  }
61
- export { BundleOptions };
62
61
  export interface Project {
63
62
  update(options: Partial<ProjectOptions>): Promise<void>;
64
63
  entrypointsSubscribe(): AsyncIterableIterator<TurbopackResult<RawEntrypoints>>;
package/esm/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export default utoopack;
11
11
  export * from "./config/types";
12
12
  export * from "./config/webpackCompat";
13
13
  export * from "./core/types";
14
+ export { BaseUpdate, EcmascriptMergedUpdate, IssuesUpdate, PartialUpdate, Update, } from "./core/types";
14
15
  export * from "./utils/findRoot";
15
16
  export type WebpackConfig = webpackCompat.WebpackConfig;
16
17
  declare namespace utoopack {
@@ -1,6 +1,6 @@
1
1
  import findUp from "find-up";
2
- import { readFileSync } from "fs";
3
- import { dirname } from "path";
2
+ import fs from "fs";
3
+ import path from "path";
4
4
  export function findRootLockFile(cwd) {
5
5
  return findUp.sync([
6
6
  "pnpm-lock.yaml",
@@ -19,7 +19,7 @@ export function findPackageJson(cwd) {
19
19
  });
20
20
  }
21
21
  function isWorkspaceRoot(pkgPath) {
22
- const pkgJson = readFileSync(pkgPath, "utf-8");
22
+ const pkgJson = fs.readFileSync(pkgPath, "utf-8");
23
23
  const pkgJsonContent = JSON.parse(pkgJson);
24
24
  return Boolean(pkgJsonContent.workspaces);
25
25
  }
@@ -32,8 +32,8 @@ export function findWorkspacesRoot(cwd) {
32
32
  const pkgJsonFiles = [pkgJson];
33
33
  while (true) {
34
34
  const lastPkgJson = pkgJsonFiles[pkgJsonFiles.length - 1];
35
- const currentDir = dirname(lastPkgJson);
36
- const parentDir = dirname(currentDir);
35
+ const currentDir = path.dirname(lastPkgJson);
36
+ const parentDir = path.dirname(currentDir);
37
37
  if (parentDir === currentDir)
38
38
  break;
39
39
  if (isWorkspaceRoot(lastPkgJson))
@@ -43,7 +43,7 @@ export function findWorkspacesRoot(cwd) {
43
43
  break;
44
44
  pkgJsonFiles.push(newPkgJson);
45
45
  }
46
- return dirname(pkgJsonFiles[pkgJsonFiles.length - 1]);
46
+ return path.dirname(pkgJsonFiles[pkgJsonFiles.length - 1]);
47
47
  }
48
48
  export function findRootDir(cwd) {
49
49
  const lockFile = findRootLockFile(cwd);
@@ -52,9 +52,9 @@ export function findRootDir(cwd) {
52
52
  const lockFiles = [lockFile];
53
53
  while (true) {
54
54
  const lastLockFile = lockFiles[lockFiles.length - 1];
55
- const currentDir = dirname(lastLockFile);
56
- const parentDir = dirname(currentDir);
57
- // dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
55
+ const currentDir = path.dirname(lastLockFile);
56
+ const parentDir = path.dirname(currentDir);
57
+ // path.dirname('/')==='/' so if we happen to reach the FS root (as might happen in a container we need to quit to avoid looping forever
58
58
  if (parentDir === currentDir)
59
59
  break;
60
60
  const newLockFile = findRootLockFile(parentDir);
@@ -62,5 +62,5 @@ export function findRootDir(cwd) {
62
62
  break;
63
63
  lockFiles.push(newLockFile);
64
64
  }
65
- return dirname(lockFiles[lockFiles.length - 1]);
65
+ return path.dirname(lockFiles[lockFiles.length - 1]);
66
66
  }
@@ -1,8 +1,8 @@
1
1
  import fs from "fs";
2
- import { join } from "path";
2
+ import path from "path";
3
3
  export function getInitialAssetsFromStats(outputDir) {
4
4
  const assets = { js: [], css: [] };
5
- const statsPath = join(outputDir, "stats.json");
5
+ const statsPath = path.join(outputDir, "stats.json");
6
6
  if (fs.existsSync(statsPath)) {
7
7
  try {
8
8
  const stats = JSON.parse(fs.readFileSync(statsPath, "utf-8"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.1.25",
3
+ "version": "1.2.0-alpha.1",
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.1.25",
42
+ "@utoo/pack-shared": "1.2.0-alpha.1",
43
43
  "@utoo/style-loader": "^1.0.0",
44
44
  "domparser-rs": "^0.0.5",
45
45
  "find-up": "4.1.0",
@@ -86,12 +86,12 @@
86
86
  },
87
87
  "repository": "git@github.com:utooland/utoo.git",
88
88
  "optionalDependencies": {
89
- "@utoo/pack-darwin-arm64": "1.1.25",
90
- "@utoo/pack-darwin-x64": "1.1.25",
91
- "@utoo/pack-linux-arm64-gnu": "1.1.25",
92
- "@utoo/pack-linux-arm64-musl": "1.1.25",
93
- "@utoo/pack-linux-x64-gnu": "1.1.25",
94
- "@utoo/pack-linux-x64-musl": "1.1.25",
95
- "@utoo/pack-win32-x64-msvc": "1.1.25"
89
+ "@utoo/pack-darwin-arm64": "1.2.0-alpha.1",
90
+ "@utoo/pack-darwin-x64": "1.2.0-alpha.1",
91
+ "@utoo/pack-linux-arm64-gnu": "1.2.0-alpha.1",
92
+ "@utoo/pack-linux-arm64-musl": "1.2.0-alpha.1",
93
+ "@utoo/pack-linux-x64-gnu": "1.2.0-alpha.1",
94
+ "@utoo/pack-linux-x64-musl": "1.2.0-alpha.1",
95
+ "@utoo/pack-win32-x64-msvc": "1.2.0-alpha.1"
96
96
  }
97
97
  }