@utoo/pack 1.1.8-rc.1 → 1.1.8-rc.3

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.
@@ -47,18 +47,7 @@ const find_root_1 = require("../utils/find-root");
47
47
  const html_entry_1 = require("../utils/html-entry");
48
48
  const xcodeProfile_1 = require("../utils/xcodeProfile");
49
49
  function build(options, projectPath, rootPath) {
50
- let bundleOptions;
51
- if (options.webpackMode) {
52
- let webpackConfig = options;
53
- if (!webpackConfig.entry) {
54
- const loadedConfig = (0, webpackCompat_1.readWebpackConfig)(projectPath, rootPath);
55
- webpackConfig = { ...webpackConfig, ...loadedConfig };
56
- }
57
- bundleOptions = (0, webpackCompat_1.compatOptionsFromWebpack)(webpackConfig);
58
- }
59
- else {
60
- bundleOptions = options;
61
- }
50
+ const bundleOptions = (0, webpackCompat_1.resolveBundleOptions)(options, projectPath, rootPath);
62
51
  if (!rootPath) {
63
52
  // help user to find the rootDir automatically.
64
53
  rootPath = (0, find_root_1.findRootDir)(projectPath || process.cwd());
@@ -27,18 +27,7 @@ const mkcert_1 = require("../utils/mkcert");
27
27
  const print_server_info_1 = require("../utils/print-server-info");
28
28
  const xcodeProfile_1 = require("../utils/xcodeProfile");
29
29
  function serve(options, projectPath, rootPath, serverOptions) {
30
- let bundleOptions;
31
- if (options.webpackMode) {
32
- let webpackConfig = options;
33
- if (!webpackConfig.entry) {
34
- const loadedConfig = (0, webpackCompat_1.readWebpackConfig)(projectPath, rootPath);
35
- webpackConfig = { ...webpackConfig, ...loadedConfig };
36
- }
37
- bundleOptions = (0, webpackCompat_1.compatOptionsFromWebpack)(webpackConfig);
38
- }
39
- else {
40
- bundleOptions = options;
41
- }
30
+ const bundleOptions = (0, webpackCompat_1.resolveBundleOptions)(options, projectPath, rootPath);
42
31
  if (!rootPath) {
43
32
  // help user to find the rootDir automatically
44
33
  rootPath = (0, find_root_1.findRootDir)(projectPath || process.cwd());
@@ -4,16 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readWebpackConfig = readWebpackConfig;
7
+ const fs_1 = __importDefault(require("fs"));
7
8
  const path_1 = __importDefault(require("path"));
8
9
  function readWebpackConfig(projectPath, rootPath) {
9
10
  const projectPathOutOfRoot = projectPath === undefined
10
11
  ? process.cwd()
11
12
  : path_1.default.join(rootPath !== null && rootPath !== void 0 ? rootPath : "", projectPath);
13
+ const { env, argv } = parseArgs();
12
14
  try {
13
- const configPath = require.resolve("webpack.config", {
14
- paths: [projectPathOutOfRoot],
15
- });
16
- return require(configPath);
15
+ const configPath = path_1.default.resolve(projectPathOutOfRoot, "./webpack.config");
16
+ const configFile = [".js", ".cjs"]
17
+ .map((ext) => configPath + ext)
18
+ .find(fs_1.default.existsSync);
19
+ const config = require(configFile || configPath);
20
+ if (typeof config === "function") {
21
+ return config(env, argv);
22
+ }
23
+ return config;
17
24
  }
18
25
  catch (error) {
19
26
  if (error && error.code === "MODULE_NOT_FOUND") {
@@ -22,3 +29,27 @@ function readWebpackConfig(projectPath, rootPath) {
22
29
  throw error;
23
30
  }
24
31
  }
32
+ function parseArgs() {
33
+ const env = {};
34
+ const argv = {};
35
+ process.argv.forEach((arg) => {
36
+ if (arg.startsWith("--env")) {
37
+ if (arg.startsWith("--env.")) {
38
+ const [key, val] = arg.substring(6).split("=");
39
+ env[key] = val === undefined ? true : val;
40
+ }
41
+ else if (arg === "--env") {
42
+ // noop
43
+ }
44
+ else {
45
+ const [key, val] = arg.substring(5).split("=");
46
+ env[key] = val === undefined ? true : val;
47
+ }
48
+ }
49
+ if (arg.startsWith("--")) {
50
+ const [key, val] = arg.substring(2).split("=");
51
+ argv[key] = val === undefined ? true : val;
52
+ }
53
+ });
54
+ return { env, argv };
55
+ }
@@ -1,2 +1,4 @@
1
+ import { type BundleOptions, type WebpackConfig } from "@utoo/pack-shared";
1
2
  export { compatOptionsFromWebpack, type WebpackConfig, } from "@utoo/pack-shared";
2
3
  export { readWebpackConfig } from "./readWebpackConfig";
4
+ export declare function resolveBundleOptions(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string): BundleOptions;
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readWebpackConfig = exports.compatOptionsFromWebpack = void 0;
4
- var pack_shared_1 = require("@utoo/pack-shared");
5
- Object.defineProperty(exports, "compatOptionsFromWebpack", { enumerable: true, get: function () { return pack_shared_1.compatOptionsFromWebpack; } });
6
- var readWebpackConfig_1 = require("./readWebpackConfig");
7
- Object.defineProperty(exports, "readWebpackConfig", { enumerable: true, get: function () { return readWebpackConfig_1.readWebpackConfig; } });
4
+ exports.resolveBundleOptions = resolveBundleOptions;
5
+ const pack_shared_1 = require("@utoo/pack-shared");
6
+ const readWebpackConfig_1 = require("./readWebpackConfig");
7
+ var pack_shared_2 = require("@utoo/pack-shared");
8
+ Object.defineProperty(exports, "compatOptionsFromWebpack", { enumerable: true, get: function () { return pack_shared_2.compatOptionsFromWebpack; } });
9
+ var readWebpackConfig_2 = require("./readWebpackConfig");
10
+ Object.defineProperty(exports, "readWebpackConfig", { enumerable: true, get: function () { return readWebpackConfig_2.readWebpackConfig; } });
11
+ function resolveBundleOptions(options, projectPath, rootPath) {
12
+ if (options.webpackMode) {
13
+ let webpackConfig = options;
14
+ const loadedConfig = (0, readWebpackConfig_1.readWebpackConfig)(projectPath, rootPath);
15
+ webpackConfig = { ...loadedConfig, ...webpackConfig };
16
+ try {
17
+ return (0, pack_shared_1.compatOptionsFromWebpack)(webpackConfig);
18
+ }
19
+ catch (e) {
20
+ throw new Error("Error converting webpack config: " + e);
21
+ }
22
+ }
23
+ else {
24
+ return options;
25
+ }
26
+ }
@@ -3,7 +3,7 @@ import { spawn } from "child_process";
3
3
  import fs, { existsSync } from "fs";
4
4
  import { nanoid } from "nanoid";
5
5
  import { join } from "path";
6
- import { compatOptionsFromWebpack, readWebpackConfig, } from "../config/webpackCompat";
6
+ import { resolveBundleOptions } from "../config/webpackCompat";
7
7
  import { projectFactory } from "../core/project";
8
8
  import { HtmlPlugin } from "../plugins/HtmlPlugin";
9
9
  import { blockStdout, createDefineEnv, getPackPath } from "../utils/common";
@@ -11,18 +11,7 @@ import { findRootDir } from "../utils/find-root";
11
11
  import { processHtmlEntry } from "../utils/html-entry";
12
12
  import { xcodeProfilingReady } from "../utils/xcodeProfile";
13
13
  export function build(options, projectPath, rootPath) {
14
- let bundleOptions;
15
- if (options.webpackMode) {
16
- let webpackConfig = options;
17
- if (!webpackConfig.entry) {
18
- const loadedConfig = readWebpackConfig(projectPath, rootPath);
19
- webpackConfig = { ...webpackConfig, ...loadedConfig };
20
- }
21
- bundleOptions = compatOptionsFromWebpack(webpackConfig);
22
- }
23
- else {
24
- bundleOptions = options;
25
- }
14
+ const bundleOptions = resolveBundleOptions(options, projectPath, rootPath);
26
15
  if (!rootPath) {
27
16
  // help user to find the rootDir automatically.
28
17
  rootPath = findRootDir(projectPath || process.cwd());
@@ -5,7 +5,7 @@ import { isIPv6 } from "net";
5
5
  import path from "path";
6
6
  import send from "send";
7
7
  import url from "url";
8
- import { compatOptionsFromWebpack, readWebpackConfig, } from "../config/webpackCompat";
8
+ import { resolveBundleOptions } from "../config/webpackCompat";
9
9
  import { createHotReloader } from "../core/hmr";
10
10
  import { blockStdout, getPackPath } from "../utils/common";
11
11
  import { findRootDir } from "../utils/find-root";
@@ -13,18 +13,7 @@ import { createSelfSignedCertificate } from "../utils/mkcert";
13
13
  import { printServerInfo } from "../utils/print-server-info";
14
14
  import { xcodeProfilingReady } from "../utils/xcodeProfile";
15
15
  export function serve(options, projectPath, rootPath, serverOptions) {
16
- let bundleOptions;
17
- if (options.webpackMode) {
18
- let webpackConfig = options;
19
- if (!webpackConfig.entry) {
20
- const loadedConfig = readWebpackConfig(projectPath, rootPath);
21
- webpackConfig = { ...webpackConfig, ...loadedConfig };
22
- }
23
- bundleOptions = compatOptionsFromWebpack(webpackConfig);
24
- }
25
- else {
26
- bundleOptions = options;
27
- }
16
+ const bundleOptions = resolveBundleOptions(options, projectPath, rootPath);
28
17
  if (!rootPath) {
29
18
  // help user to find the rootDir automatically
30
19
  rootPath = findRootDir(projectPath || process.cwd());
@@ -1,13 +1,20 @@
1
+ import fs from "fs";
1
2
  import path from "path";
2
3
  export function readWebpackConfig(projectPath, rootPath) {
3
4
  const projectPathOutOfRoot = projectPath === undefined
4
5
  ? process.cwd()
5
6
  : path.join(rootPath !== null && rootPath !== void 0 ? rootPath : "", projectPath);
7
+ const { env, argv } = parseArgs();
6
8
  try {
7
- const configPath = require.resolve("webpack.config", {
8
- paths: [projectPathOutOfRoot],
9
- });
10
- return require(configPath);
9
+ const configPath = path.resolve(projectPathOutOfRoot, "./webpack.config");
10
+ const configFile = [".js", ".cjs"]
11
+ .map((ext) => configPath + ext)
12
+ .find(fs.existsSync);
13
+ const config = require(configFile || configPath);
14
+ if (typeof config === "function") {
15
+ return config(env, argv);
16
+ }
17
+ return config;
11
18
  }
12
19
  catch (error) {
13
20
  if (error && error.code === "MODULE_NOT_FOUND") {
@@ -16,3 +23,27 @@ export function readWebpackConfig(projectPath, rootPath) {
16
23
  throw error;
17
24
  }
18
25
  }
26
+ function parseArgs() {
27
+ const env = {};
28
+ const argv = {};
29
+ process.argv.forEach((arg) => {
30
+ if (arg.startsWith("--env")) {
31
+ if (arg.startsWith("--env.")) {
32
+ const [key, val] = arg.substring(6).split("=");
33
+ env[key] = val === undefined ? true : val;
34
+ }
35
+ else if (arg === "--env") {
36
+ // noop
37
+ }
38
+ else {
39
+ const [key, val] = arg.substring(5).split("=");
40
+ env[key] = val === undefined ? true : val;
41
+ }
42
+ }
43
+ if (arg.startsWith("--")) {
44
+ const [key, val] = arg.substring(2).split("=");
45
+ argv[key] = val === undefined ? true : val;
46
+ }
47
+ });
48
+ return { env, argv };
49
+ }
@@ -1,2 +1,4 @@
1
+ import { type BundleOptions, type WebpackConfig } from "@utoo/pack-shared";
1
2
  export { compatOptionsFromWebpack, type WebpackConfig, } from "@utoo/pack-shared";
2
3
  export { readWebpackConfig } from "./readWebpackConfig";
4
+ export declare function resolveBundleOptions(options: BundleOptions | WebpackConfig, projectPath?: string, rootPath?: string): BundleOptions;
@@ -1,2 +1,20 @@
1
+ import { compatOptionsFromWebpack, } from "@utoo/pack-shared";
2
+ import { readWebpackConfig } from "./readWebpackConfig";
1
3
  export { compatOptionsFromWebpack, } from "@utoo/pack-shared";
2
4
  export { readWebpackConfig } from "./readWebpackConfig";
5
+ export function resolveBundleOptions(options, projectPath, rootPath) {
6
+ if (options.webpackMode) {
7
+ let webpackConfig = options;
8
+ const loadedConfig = readWebpackConfig(projectPath, rootPath);
9
+ webpackConfig = { ...loadedConfig, ...webpackConfig };
10
+ try {
11
+ return compatOptionsFromWebpack(webpackConfig);
12
+ }
13
+ catch (e) {
14
+ throw new Error("Error converting webpack config: " + e);
15
+ }
16
+ }
17
+ else {
18
+ return options;
19
+ }
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.1.8-rc.1",
3
+ "version": "1.1.8-rc.3",
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": "^0.0.8",
42
+ "@utoo/pack-shared": "1.1.8-rc.3",
43
43
  "@utoo/style-loader": "^1.0.0",
44
44
  "domparser-rs": "^0.0.5",
45
45
  "find-up": "4.1.0",
@@ -88,12 +88,12 @@
88
88
  },
89
89
  "repository": "git@github.com:utooland/utoo.git",
90
90
  "optionalDependencies": {
91
- "@utoo/pack-darwin-arm64": "1.1.8-rc.1",
92
- "@utoo/pack-darwin-x64": "1.1.8-rc.1",
93
- "@utoo/pack-linux-arm64-gnu": "1.1.8-rc.1",
94
- "@utoo/pack-linux-arm64-musl": "1.1.8-rc.1",
95
- "@utoo/pack-linux-x64-gnu": "1.1.8-rc.1",
96
- "@utoo/pack-linux-x64-musl": "1.1.8-rc.1",
97
- "@utoo/pack-win32-x64-msvc": "1.1.8-rc.1"
91
+ "@utoo/pack-darwin-arm64": "1.1.8-rc.3",
92
+ "@utoo/pack-darwin-x64": "1.1.8-rc.3",
93
+ "@utoo/pack-linux-arm64-gnu": "1.1.8-rc.3",
94
+ "@utoo/pack-linux-arm64-musl": "1.1.8-rc.3",
95
+ "@utoo/pack-linux-x64-gnu": "1.1.8-rc.3",
96
+ "@utoo/pack-linux-x64-musl": "1.1.8-rc.3",
97
+ "@utoo/pack-win32-x64-msvc": "1.1.8-rc.3"
98
98
  }
99
99
  }