@utoo/pack-shared 1.2.13-alpha.0 → 1.3.0-alpha.0

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/config.d.ts CHANGED
@@ -14,11 +14,6 @@ export interface LibraryOptions {
14
14
  name?: string;
15
15
  export?: Array<string>;
16
16
  }
17
- export interface DefineEnv {
18
- client: RustifiedEnv;
19
- edge: RustifiedEnv;
20
- nodejs: RustifiedEnv;
21
- }
22
17
  export type RustifiedEnv = {
23
18
  name: string;
24
19
  value: string;
@@ -100,6 +95,20 @@ export type ExternalConfig = string | ExternalAdvanced;
100
95
  * ```
101
96
  */
102
97
  export type ProviderConfig = Record<string, string | [string, string]>;
98
+ /**
99
+ * Development server options (port, host, HTTPS, HMR).
100
+ * Used by the dev server and by config resolution for startup options.
101
+ */
102
+ export interface DevServerConfig {
103
+ /** Enable Hot Module Replacement. */
104
+ hot?: boolean;
105
+ /** Port to listen on. */
106
+ port?: number;
107
+ /** Host to bind (e.g. localhost, 0.0.0.0). */
108
+ host?: string;
109
+ /** Use HTTPS; when true without a certificate, a self-signed cert may be generated. */
110
+ https?: boolean;
111
+ }
103
112
  export interface ConfigComplete {
104
113
  entry: EntryOptions[];
105
114
  mode?: "production" | "development";
@@ -182,14 +191,10 @@ export interface ConfigComplete {
182
191
  importSource?: string;
183
192
  };
184
193
  stats?: boolean;
194
+ pluginRuntimeStrategy?: "workerThreads" | "childProcesses";
185
195
  persistentCaching?: boolean;
186
196
  nodePolyfill?: boolean;
187
- devServer?: {
188
- hot?: boolean;
189
- port?: number;
190
- host?: string;
191
- https?: boolean;
192
- };
197
+ devServer?: DevServerConfig;
193
198
  cacheHandler?: string;
194
199
  experimental?: ExperimentalConfig;
195
200
  }
@@ -232,7 +237,6 @@ export interface BundleOptions {
232
237
  * A map of environment variables to use when compiling code.
233
238
  */
234
239
  processEnv?: Record<string, string>;
235
- defineEnv?: DefineEnv;
236
240
  /**
237
241
  * Whether to watch the filesystem for file changes.
238
242
  */
@@ -253,3 +257,12 @@ export interface BundleOptions {
253
257
  */
254
258
  packPath?: string;
255
259
  }
260
+ /**
261
+ * User config file shape (e.g. utoopack.config.mjs).
262
+ * Bundler options (entry, output, define, ...) at top level,
263
+ * plus optional CLI/runtime options (processEnv, watch, dev, ...).
264
+ */
265
+ export type UserConfig = ConfigComplete & Partial<Pick<BundleOptions, "processEnv" | "watch" | "dev" | "buildId" | "packPath">> & {
266
+ rootPath?: string;
267
+ projectPath?: string;
268
+ };
package/cjs/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ConfigComplete, DefineEnv, RustifiedEnv } from "./config";
1
+ import { RustifiedEnv } from "./config";
2
2
  import { Issue } from "./issue";
3
3
  export declare class ModuleBuildError extends Error {
4
4
  name: string;
@@ -9,12 +9,6 @@ export interface ResultWithIssues {
9
9
  export declare function processIssues(result: ResultWithIssues, throwIssue: boolean, logErrors: boolean): void;
10
10
  export declare function isWellKnownError(issue: Issue): boolean;
11
11
  export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
12
- interface DefineEnvOptions {
13
- config: ConfigComplete;
14
- dev: boolean;
15
- optionDefineEnv?: DefineEnv;
16
- }
17
- export declare function createDefineEnv(options: DefineEnvOptions): DefineEnv;
18
12
  type AnyFunc<T> = (this: T, ...args: any) => any;
19
13
  export declare function debounce<T, F extends AnyFunc<T>>(fn: F, ms: number, maxWait?: number): (this: T, ...passedArgs: Parameters<F>) => void;
20
14
  export {};
package/cjs/utils.js CHANGED
@@ -4,7 +4,6 @@ exports.ModuleBuildError = void 0;
4
4
  exports.processIssues = processIssues;
5
5
  exports.isWellKnownError = isWellKnownError;
6
6
  exports.rustifyEnv = rustifyEnv;
7
- exports.createDefineEnv = createDefineEnv;
8
7
  exports.debounce = debounce;
9
8
  const issue_1 = require("./issue");
10
9
  const styledString_1 = require("./styledString");
@@ -56,36 +55,6 @@ function rustifyEnv(env) {
56
55
  value,
57
56
  }));
58
57
  }
59
- function createDefineEnv(options) {
60
- var _a;
61
- let defineEnv = (_a = options.optionDefineEnv) !== null && _a !== void 0 ? _a : {
62
- client: [],
63
- edge: [],
64
- nodejs: [],
65
- };
66
- function getDefineEnv() {
67
- var _a;
68
- const envs = {
69
- "process.env.NODE_ENV": options.dev ? "development" : "production",
70
- };
71
- const userDefines = (_a = options.config.define) !== null && _a !== void 0 ? _a : {};
72
- for (const key in userDefines) {
73
- envs[key] = userDefines[key];
74
- }
75
- // serialize
76
- const defineEnvStringified = {};
77
- for (const key in defineEnv) {
78
- const value = envs[key];
79
- defineEnvStringified[key] = JSON.stringify(value);
80
- }
81
- return defineEnvStringified;
82
- }
83
- // TODO: future define envs need to extends for more compiler like server or edge.
84
- for (const variant of Object.keys(defineEnv)) {
85
- defineEnv[variant] = rustifyEnv(getDefineEnv());
86
- }
87
- return defineEnv;
88
- }
89
58
  function debounce(fn, ms, maxWait = Infinity) {
90
59
  let timeoutId;
91
60
  // The time the debouncing function was first called during this debounce queue.
@@ -469,6 +469,7 @@ function compatOptimization(webpackOptimization) {
469
469
  return;
470
470
  }
471
471
  const { moduleIds, minimize, concatenateModules, usedExports } = webpackOptimization;
472
+ const enableWebpackUsedExports = usedExports !== false;
472
473
  return {
473
474
  moduleIds: moduleIds === "named"
474
475
  ? "named"
@@ -478,9 +479,9 @@ function compatOptimization(webpackOptimization) {
478
479
  noMangling: webpackOptimization.mangleExports === false,
479
480
  minify: minimize,
480
481
  concatenateModules,
481
- treeShaking: !!usedExports,
482
- removeUnusedExports: !!usedExports,
483
- removeUnusedImports: !!usedExports,
482
+ treeShaking: false,
483
+ removeUnusedExports: enableWebpackUsedExports,
484
+ removeUnusedImports: enableWebpackUsedExports,
484
485
  };
485
486
  }
486
487
  function compatStats(webpackStats) {
package/esm/config.d.ts CHANGED
@@ -14,11 +14,6 @@ export interface LibraryOptions {
14
14
  name?: string;
15
15
  export?: Array<string>;
16
16
  }
17
- export interface DefineEnv {
18
- client: RustifiedEnv;
19
- edge: RustifiedEnv;
20
- nodejs: RustifiedEnv;
21
- }
22
17
  export type RustifiedEnv = {
23
18
  name: string;
24
19
  value: string;
@@ -100,6 +95,20 @@ export type ExternalConfig = string | ExternalAdvanced;
100
95
  * ```
101
96
  */
102
97
  export type ProviderConfig = Record<string, string | [string, string]>;
98
+ /**
99
+ * Development server options (port, host, HTTPS, HMR).
100
+ * Used by the dev server and by config resolution for startup options.
101
+ */
102
+ export interface DevServerConfig {
103
+ /** Enable Hot Module Replacement. */
104
+ hot?: boolean;
105
+ /** Port to listen on. */
106
+ port?: number;
107
+ /** Host to bind (e.g. localhost, 0.0.0.0). */
108
+ host?: string;
109
+ /** Use HTTPS; when true without a certificate, a self-signed cert may be generated. */
110
+ https?: boolean;
111
+ }
103
112
  export interface ConfigComplete {
104
113
  entry: EntryOptions[];
105
114
  mode?: "production" | "development";
@@ -182,14 +191,10 @@ export interface ConfigComplete {
182
191
  importSource?: string;
183
192
  };
184
193
  stats?: boolean;
194
+ pluginRuntimeStrategy?: "workerThreads" | "childProcesses";
185
195
  persistentCaching?: boolean;
186
196
  nodePolyfill?: boolean;
187
- devServer?: {
188
- hot?: boolean;
189
- port?: number;
190
- host?: string;
191
- https?: boolean;
192
- };
197
+ devServer?: DevServerConfig;
193
198
  cacheHandler?: string;
194
199
  experimental?: ExperimentalConfig;
195
200
  }
@@ -232,7 +237,6 @@ export interface BundleOptions {
232
237
  * A map of environment variables to use when compiling code.
233
238
  */
234
239
  processEnv?: Record<string, string>;
235
- defineEnv?: DefineEnv;
236
240
  /**
237
241
  * Whether to watch the filesystem for file changes.
238
242
  */
@@ -253,3 +257,12 @@ export interface BundleOptions {
253
257
  */
254
258
  packPath?: string;
255
259
  }
260
+ /**
261
+ * User config file shape (e.g. utoopack.config.mjs).
262
+ * Bundler options (entry, output, define, ...) at top level,
263
+ * plus optional CLI/runtime options (processEnv, watch, dev, ...).
264
+ */
265
+ export type UserConfig = ConfigComplete & Partial<Pick<BundleOptions, "processEnv" | "watch" | "dev" | "buildId" | "packPath">> & {
266
+ rootPath?: string;
267
+ projectPath?: string;
268
+ };
package/esm/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ConfigComplete, DefineEnv, RustifiedEnv } from "./config";
1
+ import { RustifiedEnv } from "./config";
2
2
  import { Issue } from "./issue";
3
3
  export declare class ModuleBuildError extends Error {
4
4
  name: string;
@@ -9,12 +9,6 @@ export interface ResultWithIssues {
9
9
  export declare function processIssues(result: ResultWithIssues, throwIssue: boolean, logErrors: boolean): void;
10
10
  export declare function isWellKnownError(issue: Issue): boolean;
11
11
  export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
12
- interface DefineEnvOptions {
13
- config: ConfigComplete;
14
- dev: boolean;
15
- optionDefineEnv?: DefineEnv;
16
- }
17
- export declare function createDefineEnv(options: DefineEnvOptions): DefineEnv;
18
12
  type AnyFunc<T> = (this: T, ...args: any) => any;
19
13
  export declare function debounce<T, F extends AnyFunc<T>>(fn: F, ms: number, maxWait?: number): (this: T, ...passedArgs: Parameters<F>) => void;
20
14
  export {};
package/esm/utils.js CHANGED
@@ -47,36 +47,6 @@ export function rustifyEnv(env) {
47
47
  value,
48
48
  }));
49
49
  }
50
- export function createDefineEnv(options) {
51
- var _a;
52
- let defineEnv = (_a = options.optionDefineEnv) !== null && _a !== void 0 ? _a : {
53
- client: [],
54
- edge: [],
55
- nodejs: [],
56
- };
57
- function getDefineEnv() {
58
- var _a;
59
- const envs = {
60
- "process.env.NODE_ENV": options.dev ? "development" : "production",
61
- };
62
- const userDefines = (_a = options.config.define) !== null && _a !== void 0 ? _a : {};
63
- for (const key in userDefines) {
64
- envs[key] = userDefines[key];
65
- }
66
- // serialize
67
- const defineEnvStringified = {};
68
- for (const key in defineEnv) {
69
- const value = envs[key];
70
- defineEnvStringified[key] = JSON.stringify(value);
71
- }
72
- return defineEnvStringified;
73
- }
74
- // TODO: future define envs need to extends for more compiler like server or edge.
75
- for (const variant of Object.keys(defineEnv)) {
76
- defineEnv[variant] = rustifyEnv(getDefineEnv());
77
- }
78
- return defineEnv;
79
- }
80
50
  export function debounce(fn, ms, maxWait = Infinity) {
81
51
  let timeoutId;
82
52
  // The time the debouncing function was first called during this debounce queue.
@@ -466,6 +466,7 @@ function compatOptimization(webpackOptimization) {
466
466
  return;
467
467
  }
468
468
  const { moduleIds, minimize, concatenateModules, usedExports } = webpackOptimization;
469
+ const enableWebpackUsedExports = usedExports !== false;
469
470
  return {
470
471
  moduleIds: moduleIds === "named"
471
472
  ? "named"
@@ -475,9 +476,9 @@ function compatOptimization(webpackOptimization) {
475
476
  noMangling: webpackOptimization.mangleExports === false,
476
477
  minify: minimize,
477
478
  concatenateModules,
478
- treeShaking: !!usedExports,
479
- removeUnusedExports: !!usedExports,
480
- removeUnusedImports: !!usedExports,
479
+ treeShaking: false,
480
+ removeUnusedExports: enableWebpackUsedExports,
481
+ removeUnusedImports: enableWebpackUsedExports,
481
482
  };
482
483
  }
483
484
  function compatStats(webpackStats) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack-shared",
3
- "version": "1.2.13-alpha.0",
3
+ "version": "1.3.0-alpha.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "esm/index.d.ts",