@utoo/pack 0.0.1-alpha.46 → 0.0.1-alpha.47

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/build.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = build;
4
+ const child_process_1 = require("child_process");
5
+ const fs_1 = require("fs");
4
6
  const nanoid_1 = require("nanoid");
7
+ const path_1 = require("path");
5
8
  const find_root_1 = require("./find-root");
6
9
  const project_1 = require("./project");
7
10
  const util_1 = require("./util");
@@ -18,7 +21,7 @@ function build(options, projectPath, rootPath) {
18
21
  return buildInternal(bundleOptions, projectPath, rootPath);
19
22
  }
20
23
  async function buildInternal(bundleOptions, projectPath, rootPath) {
21
- var _a, _b, _c;
24
+ var _a, _b, _c, _d;
22
25
  (0, util_1.blockStdout)();
23
26
  if (process.env.XCODE_PROFILE) {
24
27
  await (0, xcodeProfile_1.xcodeProfilingReady)();
@@ -36,7 +39,10 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
36
39
  },
37
40
  dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
38
41
  buildId: bundleOptions.buildId || (0, nanoid_1.nanoid)(),
39
- config: bundleOptions.config,
42
+ config: {
43
+ ...bundleOptions.config,
44
+ stats: Boolean(process.env.ANALYZE) || bundleOptions.config.stats,
45
+ },
40
46
  projectPath: projectPath || process.cwd(),
41
47
  rootPath: rootPath || projectPath || process.cwd(),
42
48
  }, {
@@ -60,6 +66,30 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
60
66
  throw new Error(`Utoopack build failed with ${topLevelErrors.length} errors:\n${topLevelErrors.join("\n")}`);
61
67
  }
62
68
  await project.shutdown();
69
+ if (process.env.ANALYZE) {
70
+ await analyzeBundle(projectPath || process.cwd(), ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || "dist");
71
+ }
63
72
  // TODO: Maybe run tasks in worker is a better way, see
64
73
  // https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
65
74
  }
75
+ async function analyzeBundle(projectPath, outputPath) {
76
+ const statsPath = (0, path_1.join)(projectPath, outputPath, "stats.json");
77
+ if (!(0, fs_1.existsSync)(statsPath)) {
78
+ console.warn(`Stats file not found at ${statsPath}. Make sure to enable stats in your configuration.`);
79
+ return;
80
+ }
81
+ return new Promise((resolve, reject) => {
82
+ const analyzer = (0, child_process_1.spawn)("npx", ["webpack-bundle-analyzer", statsPath], {
83
+ stdio: "inherit",
84
+ shell: true,
85
+ });
86
+ analyzer.on("error", (error) => {
87
+ reject(new Error(`Failed to start bundle analyzer: ${error.message}`));
88
+ });
89
+ analyzer.on("close", () => {
90
+ // The analyzer process has finished, so we can resolve the promise
91
+ // to allow the build process to exit gracefully.
92
+ resolve();
93
+ });
94
+ });
95
+ }
package/esm/build.js CHANGED
@@ -1,4 +1,7 @@
1
+ import { spawn } from "child_process";
2
+ import { existsSync } from "fs";
1
3
  import { nanoid } from "nanoid";
4
+ import { join } from "path";
2
5
  import { findRootDir } from "./find-root";
3
6
  import { projectFactory } from "./project";
4
7
  import { blockStdout, createDefineEnv, formatIssue, isRelevantWarning, } from "./util";
@@ -15,7 +18,7 @@ export function build(options, projectPath, rootPath) {
15
18
  return buildInternal(bundleOptions, projectPath, rootPath);
16
19
  }
17
20
  async function buildInternal(bundleOptions, projectPath, rootPath) {
18
- var _a, _b, _c;
21
+ var _a, _b, _c, _d;
19
22
  blockStdout();
20
23
  if (process.env.XCODE_PROFILE) {
21
24
  await xcodeProfilingReady();
@@ -33,7 +36,10 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
33
36
  },
34
37
  dev: (_c = bundleOptions.dev) !== null && _c !== void 0 ? _c : false,
35
38
  buildId: bundleOptions.buildId || nanoid(),
36
- config: bundleOptions.config,
39
+ config: {
40
+ ...bundleOptions.config,
41
+ stats: Boolean(process.env.ANALYZE) || bundleOptions.config.stats,
42
+ },
37
43
  projectPath: projectPath || process.cwd(),
38
44
  rootPath: rootPath || projectPath || process.cwd(),
39
45
  }, {
@@ -57,6 +63,30 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
57
63
  throw new Error(`Utoopack build failed with ${topLevelErrors.length} errors:\n${topLevelErrors.join("\n")}`);
58
64
  }
59
65
  await project.shutdown();
66
+ if (process.env.ANALYZE) {
67
+ await analyzeBundle(projectPath || process.cwd(), ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || "dist");
68
+ }
60
69
  // TODO: Maybe run tasks in worker is a better way, see
61
70
  // https://github.com/vercel/next.js/blob/512d8283054407ab92b2583ecce3b253c3be7b85/packages/next/src/lib/worker.ts
62
71
  }
72
+ async function analyzeBundle(projectPath, outputPath) {
73
+ const statsPath = join(projectPath, outputPath, "stats.json");
74
+ if (!existsSync(statsPath)) {
75
+ console.warn(`Stats file not found at ${statsPath}. Make sure to enable stats in your configuration.`);
76
+ return;
77
+ }
78
+ return new Promise((resolve, reject) => {
79
+ const analyzer = spawn("npx", ["webpack-bundle-analyzer", statsPath], {
80
+ stdio: "inherit",
81
+ shell: true,
82
+ });
83
+ analyzer.on("error", (error) => {
84
+ reject(new Error(`Failed to start bundle analyzer: ${error.message}`));
85
+ });
86
+ analyzer.on("close", () => {
87
+ // The analyzer process has finished, so we can resolve the promise
88
+ // to allow the build process to exit gracefully.
89
+ resolve();
90
+ });
91
+ });
92
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "0.0.1-alpha.46",
3
+ "version": "0.0.1-alpha.47",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "exports": {
@@ -85,12 +85,12 @@
85
85
  },
86
86
  "repository": "git@github.com:utooland/utoo.git",
87
87
  "optionalDependencies": {
88
- "@utoo/pack-darwin-arm64": "0.0.1-alpha.46",
89
- "@utoo/pack-darwin-x64": "0.0.1-alpha.46",
90
- "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.46",
91
- "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.46",
92
- "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.46",
93
- "@utoo/pack-linux-x64-musl": "0.0.1-alpha.46",
94
- "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.46"
88
+ "@utoo/pack-darwin-arm64": "0.0.1-alpha.47",
89
+ "@utoo/pack-darwin-x64": "0.0.1-alpha.47",
90
+ "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.47",
91
+ "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.47",
92
+ "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.47",
93
+ "@utoo/pack-linux-x64-musl": "0.0.1-alpha.47",
94
+ "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.47"
95
95
  }
96
96
  }