@utoo/pack 0.0.1-alpha.41 → 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/cjs/find-root.js CHANGED
@@ -21,7 +21,7 @@ function findRootLockFile(cwd) {
21
21
  cwd,
22
22
  });
23
23
  }
24
- // compitable with tnpm
24
+ // compatible with tnpm
25
25
  function findPackageJson(cwd) {
26
26
  return find_up_1.default.sync(["package.json"], {
27
27
  cwd,
@@ -32,7 +32,7 @@ function isWorkspaceRoot(pkgPath) {
32
32
  const pkgJsonContent = JSON.parse(pkgJson);
33
33
  return Boolean(pkgJsonContent.workspaces);
34
34
  }
35
- // refer from: https://github.com/umijs/mako/blob/next/crates/cli/src/helper/workspace.rs#L153
35
+ // refer from: https://github.com/umijs/mako/blob/next/crates/pm/src/helper/workspace.rs#L153
36
36
  // TODO: 这块逻辑后续跟 utoo-pkg 使用一套方法
37
37
  function findWorkspacesRoot(cwd) {
38
38
  const pkgJson = findPackageJson(cwd);
package/cjs/types.d.ts CHANGED
@@ -132,6 +132,9 @@ export interface ConfigComplete {
132
132
  transform: string | Record<string, string>;
133
133
  preventFullImport?: boolean;
134
134
  skipDefaultConversion?: boolean;
135
+ handleDefaultImport?: boolean;
136
+ handleNamespaceImport?: boolean;
137
+ style?: string;
135
138
  }>;
136
139
  packageImports?: string[];
137
140
  transpilePackages?: string[];
@@ -332,9 +332,7 @@ function compatOptimization(webpackOptimization) {
332
332
  if (!webpackOptimization) {
333
333
  return;
334
334
  }
335
- const { moduleIds, minimize,
336
- // TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
337
- } = webpackOptimization;
335
+ const { moduleIds, minimize, concatenateModules } = webpackOptimization;
338
336
  return {
339
337
  moduleIds: moduleIds === "named"
340
338
  ? "named"
@@ -342,6 +340,7 @@ function compatOptimization(webpackOptimization) {
342
340
  ? "deterministic"
343
341
  : undefined,
344
342
  minify: minimize,
343
+ concatenateModules,
345
344
  };
346
345
  }
347
346
  function compatStats(webpackStats) {
@@ -553,6 +553,50 @@
553
553
  }
554
554
  }
555
555
  },
556
+ "SchemaModularizeImportPackageConfig": {
557
+ "description": "Modularize import package configuration",
558
+ "type": "object",
559
+ "required": [
560
+ "transform"
561
+ ],
562
+ "properties": {
563
+ "handleDefaultImport": {
564
+ "description": "Handle default import",
565
+ "default": false,
566
+ "type": "boolean"
567
+ },
568
+ "handleNamespaceImport": {
569
+ "description": "Handle namespace import",
570
+ "default": false,
571
+ "type": "boolean"
572
+ },
573
+ "preventFullImport": {
574
+ "description": "Prevent full import of the package",
575
+ "default": false,
576
+ "type": "boolean"
577
+ },
578
+ "skipDefaultConversion": {
579
+ "description": "Skip default conversion",
580
+ "default": false,
581
+ "type": "boolean"
582
+ },
583
+ "style": {
584
+ "description": "Style import configuration",
585
+ "type": [
586
+ "string",
587
+ "null"
588
+ ]
589
+ },
590
+ "transform": {
591
+ "description": "Transform configuration",
592
+ "allOf": [
593
+ {
594
+ "$ref": "#/definitions/SchemaTransform"
595
+ }
596
+ ]
597
+ }
598
+ }
599
+ },
556
600
  "SchemaModuleConfig": {
557
601
  "description": "Module configuration",
558
602
  "type": "object",
@@ -609,7 +653,9 @@
609
653
  "object",
610
654
  "null"
611
655
  ],
612
- "additionalProperties": true
656
+ "additionalProperties": {
657
+ "$ref": "#/definitions/SchemaModularizeImportPackageConfig"
658
+ }
613
659
  },
614
660
  "moduleIds": {
615
661
  "description": "Module ID generation strategy",
@@ -856,6 +902,32 @@
856
902
  "description": "Styled components configuration"
857
903
  }
858
904
  }
905
+ },
906
+ "SchemaTransform": {
907
+ "description": "Transform configuration for modularize imports",
908
+ "anyOf": [
909
+ {
910
+ "description": "String transform template",
911
+ "type": "string"
912
+ },
913
+ {
914
+ "description": "Vector of transformation pairs",
915
+ "type": "array",
916
+ "items": {
917
+ "type": "array",
918
+ "items": [
919
+ {
920
+ "type": "string"
921
+ },
922
+ {
923
+ "type": "string"
924
+ }
925
+ ],
926
+ "maxItems": 2,
927
+ "minItems": 2
928
+ }
929
+ }
930
+ ]
859
931
  }
860
932
  }
861
933
  }
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/esm/find-root.js CHANGED
@@ -12,7 +12,7 @@ export function findRootLockFile(cwd) {
12
12
  cwd,
13
13
  });
14
14
  }
15
- // compitable with tnpm
15
+ // compatible with tnpm
16
16
  export function findPackageJson(cwd) {
17
17
  return findUp.sync(["package.json"], {
18
18
  cwd,
@@ -23,7 +23,7 @@ function isWorkspaceRoot(pkgPath) {
23
23
  const pkgJsonContent = JSON.parse(pkgJson);
24
24
  return Boolean(pkgJsonContent.workspaces);
25
25
  }
26
- // refer from: https://github.com/umijs/mako/blob/next/crates/cli/src/helper/workspace.rs#L153
26
+ // refer from: https://github.com/umijs/mako/blob/next/crates/pm/src/helper/workspace.rs#L153
27
27
  // TODO: 这块逻辑后续跟 utoo-pkg 使用一套方法
28
28
  export function findWorkspacesRoot(cwd) {
29
29
  const pkgJson = findPackageJson(cwd);
package/esm/types.d.ts CHANGED
@@ -132,6 +132,9 @@ export interface ConfigComplete {
132
132
  transform: string | Record<string, string>;
133
133
  preventFullImport?: boolean;
134
134
  skipDefaultConversion?: boolean;
135
+ handleDefaultImport?: boolean;
136
+ handleNamespaceImport?: boolean;
137
+ style?: string;
135
138
  }>;
136
139
  packageImports?: string[];
137
140
  transpilePackages?: string[];
@@ -329,9 +329,7 @@ function compatOptimization(webpackOptimization) {
329
329
  if (!webpackOptimization) {
330
330
  return;
331
331
  }
332
- const { moduleIds, minimize,
333
- // TODO: concatenateModules to be supported, need to upgrade to next.js@15.4
334
- } = webpackOptimization;
332
+ const { moduleIds, minimize, concatenateModules } = webpackOptimization;
335
333
  return {
336
334
  moduleIds: moduleIds === "named"
337
335
  ? "named"
@@ -339,6 +337,7 @@ function compatOptimization(webpackOptimization) {
339
337
  ? "deterministic"
340
338
  : undefined,
341
339
  minify: minimize,
340
+ concatenateModules,
342
341
  };
343
342
  }
344
343
  function compatStats(webpackStats) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "0.0.1-alpha.41",
3
+ "version": "0.0.1-alpha.47",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "exports": {
@@ -83,14 +83,14 @@
83
83
  "version": "napi version",
84
84
  "generate-features-list": "node ./scripts/generate-feature-list.js"
85
85
  },
86
- "repository": "git@github.com:umijs/mako.git",
86
+ "repository": "git@github.com:utooland/utoo.git",
87
87
  "optionalDependencies": {
88
- "@utoo/pack-darwin-arm64": "0.0.1-alpha.41",
89
- "@utoo/pack-darwin-x64": "0.0.1-alpha.41",
90
- "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.41",
91
- "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.41",
92
- "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.41",
93
- "@utoo/pack-linux-x64-musl": "0.0.1-alpha.41",
94
- "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.41"
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
  }