@utoo/pack 1.2.8 → 1.2.10-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/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
  - **Resolve**: Full support for `alias` and `extensions`.
23
23
  - **Styles**: Built-in support for Less, Sass, PostCSS, CSS Modules, and LightningCSS.
24
24
  - **Optimization**: Minification, Tree Shaking, Module Concatenation, and more.
25
- - **Frameworks**: Optimized for React (including `styled-jsx`, `emotion`, `styled-components`).
25
+ - **Frameworks**: Optimized for React (including `styled-jsx`, `styled-components`).
26
26
  - **Tools**: Integrated Bundle Analyzer and Tracing Logs.
27
27
 
28
28
  > [!TIP]
@@ -16,6 +16,7 @@ const common_1 = require("../utils/common");
16
16
  const findRoot_1 = require("../utils/findRoot");
17
17
  const getInitialAssets_1 = require("../utils/getInitialAssets");
18
18
  const htmlEntry_1 = require("../utils/htmlEntry");
19
+ const normalize_path_1 = require("../utils/normalize-path");
19
20
  const validateEntry_1 = require("../utils/validateEntry");
20
21
  const xcodeProfile_1 = require("../utils/xcodeProfile");
21
22
  function build(options, projectPath, rootPath) {
@@ -54,7 +55,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
54
55
  bundleOptions.config.stats ||
55
56
  bundleOptions.config.entry.some((e) => !!e.html),
56
57
  },
57
- projectPath: projectPath || process.cwd(),
58
+ projectPath: (0, normalize_path_1.normalizePath)(resolvedProjectPath),
58
59
  rootPath: rootPath || projectPath || process.cwd(),
59
60
  packPath: (0, common_1.getPackPath)(),
60
61
  }, {
package/cjs/core/hmr.js CHANGED
@@ -13,6 +13,7 @@ const HtmlPlugin_1 = require("../plugins/HtmlPlugin");
13
13
  const common_1 = require("../utils/common");
14
14
  const getInitialAssets_1 = require("../utils/getInitialAssets");
15
15
  const htmlEntry_1 = require("../utils/htmlEntry");
16
+ const normalize_path_1 = require("../utils/normalize-path");
16
17
  const validateEntry_1 = require("../utils/validateEntry");
17
18
  const project_1 = require("./project");
18
19
  const wsServer = new ws_1.default.Server({ noServer: true });
@@ -51,7 +52,7 @@ async function createHotReloader(bundleOptions, projectPath, rootPath) {
51
52
  moduleIds: "named",
52
53
  },
53
54
  },
54
- projectPath: projectPath || process.cwd(),
55
+ projectPath: (0, normalize_path_1.normalizePath)(resolvedProjectPath),
55
56
  rootPath: rootPath || projectPath || process.cwd(),
56
57
  packPath: (0, common_1.getPackPath)(),
57
58
  }, {
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.TurbopackInternalError = void 0;
37
37
  exports.projectFactory = projectFactory;
38
+ const util_1 = require("util");
38
39
  const binding = __importStar(require("../binding"));
39
40
  const common_1 = require("../utils/common");
40
41
  const loaderWorkerPool_1 = require("./loaderWorkerPool");
@@ -80,8 +81,109 @@ async function serializeConfig(config) {
80
81
  ]));
81
82
  }
82
83
  }
84
+ if (configSerializable.module && configSerializable.module.rules) {
85
+ configSerializable.module.rules = serializeModuleRules(configSerializable.module.rules);
86
+ }
83
87
  return JSON.stringify(configSerializable, null, 2);
84
88
  }
89
+ // converts regexes to a `RegexComponents` object so that it can be JSON-serialized when passed to
90
+ // Turbopack
91
+ function serializeRuleCondition(cond) {
92
+ function regexComponents(regex) {
93
+ return {
94
+ source: regex.source,
95
+ flags: regex.flags,
96
+ };
97
+ }
98
+ if (typeof cond === "string") {
99
+ return cond;
100
+ }
101
+ else if ("all" in cond) {
102
+ return { ...cond, all: cond.all.map(serializeRuleCondition) };
103
+ }
104
+ else if ("any" in cond) {
105
+ return { ...cond, any: cond.any.map(serializeRuleCondition) };
106
+ }
107
+ else if ("not" in cond) {
108
+ return { ...cond, not: serializeRuleCondition(cond.not) };
109
+ }
110
+ else {
111
+ return {
112
+ ...cond,
113
+ path: cond.path == null
114
+ ? undefined
115
+ : cond.path instanceof RegExp
116
+ ? {
117
+ type: "regex",
118
+ value: regexComponents(cond.path),
119
+ }
120
+ : { type: "glob", value: cond.path },
121
+ content: cond.content && regexComponents(cond.content),
122
+ query: cond.query == null
123
+ ? undefined
124
+ : cond.query instanceof RegExp
125
+ ? {
126
+ type: "regex",
127
+ value: regexComponents(cond.query),
128
+ }
129
+ : { type: "constant", value: cond.query },
130
+ contentType: cond.contentType == null
131
+ ? undefined
132
+ : cond.contentType instanceof RegExp
133
+ ? {
134
+ type: "regex",
135
+ value: regexComponents(cond.contentType),
136
+ }
137
+ : { type: "glob", value: cond.contentType },
138
+ };
139
+ }
140
+ }
141
+ // Note: Returns an updated `turbopackRules` with serialized conditions. Does not mutate in-place.
142
+ function serializeModuleRules(turbopackRules) {
143
+ const serializedRules = {};
144
+ for (const [glob, rule] of Object.entries(turbopackRules)) {
145
+ if (Array.isArray(rule)) {
146
+ serializedRules[glob] = rule.map((item) => {
147
+ if (typeof item !== "string" &&
148
+ ("loaders" in item || "type" in item || "condition" in item)) {
149
+ return serializeConfigItem(item, glob);
150
+ }
151
+ else {
152
+ checkLoaderItem(item, glob);
153
+ return item;
154
+ }
155
+ });
156
+ }
157
+ else {
158
+ serializedRules[glob] = serializeConfigItem(rule, glob);
159
+ }
160
+ }
161
+ return serializedRules;
162
+ function serializeConfigItem(rule, glob) {
163
+ if (!rule)
164
+ return rule;
165
+ if (rule.loaders) {
166
+ for (const item of rule.loaders) {
167
+ checkLoaderItem(item, glob);
168
+ }
169
+ }
170
+ let serializedRule = rule;
171
+ if (rule.condition != null) {
172
+ serializedRule = {
173
+ ...rule,
174
+ condition: serializeRuleCondition(rule.condition),
175
+ };
176
+ }
177
+ return serializedRule;
178
+ }
179
+ function checkLoaderItem(loaderItem, glob) {
180
+ if (typeof loaderItem !== "string" &&
181
+ !(0, util_1.isDeepStrictEqual)(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
182
+ throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. ` +
183
+ "Ensure that options passed are plain JavaScript objects and values.");
184
+ }
185
+ }
186
+ }
85
187
  async function rustifyPartialProjectOptions(options) {
86
188
  return {
87
189
  ...options,
@@ -0,0 +1 @@
1
+ export declare function normalizePath(file: string): string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizePath = normalizePath;
7
+ const path_1 = __importDefault(require("path"));
8
+ function normalizePath(file) {
9
+ return path_1.default.sep === "\\" ? file.replace(/\\/g, "/") : file;
10
+ }
@@ -1021,6 +1021,13 @@
1021
1021
  "null"
1022
1022
  ]
1023
1023
  },
1024
+ "chunkLoadingGlobal": {
1025
+ "description": "The global variable name used by the runtime for loading chunks. Default: 'TURBOPACK'",
1026
+ "type": [
1027
+ "string",
1028
+ "null"
1029
+ ]
1030
+ },
1024
1031
  "clean": {
1025
1032
  "description": "Whether to clean output directory before build",
1026
1033
  "type": [
@@ -1038,6 +1045,13 @@
1038
1045
  "$ref": "#/definitions/SchemaCopyItem"
1039
1046
  }
1040
1047
  },
1048
+ "entryRootExport": {
1049
+ "description": "Expose entry module exports to global scope with the specified name. When set, all named exports from the entry module will be available on window/globalThis under the specified name. If set to empty string, will use package.json name. Default: None (no exposure)",
1050
+ "type": [
1051
+ "string",
1052
+ "null"
1053
+ ]
1054
+ },
1041
1055
  "filename": {
1042
1056
  "description": "Filename pattern for main files",
1043
1057
  "type": [
@@ -1207,9 +1221,6 @@
1207
1221
  "description": "Style configuration",
1208
1222
  "type": "object",
1209
1223
  "properties": {
1210
- "emotion": {
1211
- "description": "Emotion transform configuration"
1212
- },
1213
1224
  "inlineCss": {
1214
1225
  "description": "Inline CSS configuration"
1215
1226
  },
@@ -1261,6 +1272,16 @@
1261
1272
  "description": "Whether to watch the filesystem for file changes.",
1262
1273
  "type": "boolean"
1263
1274
  },
1275
+ "ignored": {
1276
+ "description": "Paths to ignore when watching for file changes. By default, ignores: node_modules",
1277
+ "type": [
1278
+ "array",
1279
+ "null"
1280
+ ],
1281
+ "items": {
1282
+ "type": "string"
1283
+ }
1284
+ },
1264
1285
  "pollInterval": {
1265
1286
  "description": "Enable polling at a certain interval if the native file watching doesn't work (e.g. docker).",
1266
1287
  "type": [
@@ -10,6 +10,7 @@ import { blockStdout, createDefineEnv, getPackPath } from "../utils/common";
10
10
  import { findRootDir } from "../utils/findRoot";
11
11
  import { getInitialAssetsFromStats } from "../utils/getInitialAssets";
12
12
  import { processHtmlEntry } from "../utils/htmlEntry";
13
+ import { normalizePath } from "../utils/normalize-path";
13
14
  import { validateEntryPaths } from "../utils/validateEntry";
14
15
  import { xcodeProfilingReady } from "../utils/xcodeProfile";
15
16
  export function build(options, projectPath, rootPath) {
@@ -48,7 +49,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
48
49
  bundleOptions.config.stats ||
49
50
  bundleOptions.config.entry.some((e) => !!e.html),
50
51
  },
51
- projectPath: projectPath || process.cwd(),
52
+ projectPath: normalizePath(resolvedProjectPath),
52
53
  rootPath: rootPath || projectPath || process.cwd(),
53
54
  packPath: getPackPath(),
54
55
  }, {
package/esm/core/hmr.js CHANGED
@@ -6,6 +6,7 @@ import { HtmlPlugin } from "../plugins/HtmlPlugin";
6
6
  import { createDefineEnv, debounce, getPackPath, processIssues, } from "../utils/common";
7
7
  import { getInitialAssetsFromStats } from "../utils/getInitialAssets";
8
8
  import { processHtmlEntry } from "../utils/htmlEntry";
9
+ import { normalizePath } from "../utils/normalize-path";
9
10
  import { validateEntryPaths } from "../utils/validateEntry";
10
11
  import { projectFactory } from "./project";
11
12
  const wsServer = new ws.Server({ noServer: true });
@@ -43,7 +44,7 @@ export async function createHotReloader(bundleOptions, projectPath, rootPath) {
43
44
  moduleIds: "named",
44
45
  },
45
46
  },
46
- projectPath: projectPath || process.cwd(),
47
+ projectPath: normalizePath(resolvedProjectPath),
47
48
  rootPath: rootPath || projectPath || process.cwd(),
48
49
  packPath: getPackPath(),
49
50
  }, {
@@ -1,3 +1,4 @@
1
+ import { isDeepStrictEqual } from "util";
1
2
  import * as binding from "../binding";
2
3
  import { rustifyEnv } from "../utils/common";
3
4
  import { runLoaderWorkerPool } from "./loaderWorkerPool";
@@ -42,8 +43,109 @@ async function serializeConfig(config) {
42
43
  ]));
43
44
  }
44
45
  }
46
+ if (configSerializable.module && configSerializable.module.rules) {
47
+ configSerializable.module.rules = serializeModuleRules(configSerializable.module.rules);
48
+ }
45
49
  return JSON.stringify(configSerializable, null, 2);
46
50
  }
51
+ // converts regexes to a `RegexComponents` object so that it can be JSON-serialized when passed to
52
+ // Turbopack
53
+ function serializeRuleCondition(cond) {
54
+ function regexComponents(regex) {
55
+ return {
56
+ source: regex.source,
57
+ flags: regex.flags,
58
+ };
59
+ }
60
+ if (typeof cond === "string") {
61
+ return cond;
62
+ }
63
+ else if ("all" in cond) {
64
+ return { ...cond, all: cond.all.map(serializeRuleCondition) };
65
+ }
66
+ else if ("any" in cond) {
67
+ return { ...cond, any: cond.any.map(serializeRuleCondition) };
68
+ }
69
+ else if ("not" in cond) {
70
+ return { ...cond, not: serializeRuleCondition(cond.not) };
71
+ }
72
+ else {
73
+ return {
74
+ ...cond,
75
+ path: cond.path == null
76
+ ? undefined
77
+ : cond.path instanceof RegExp
78
+ ? {
79
+ type: "regex",
80
+ value: regexComponents(cond.path),
81
+ }
82
+ : { type: "glob", value: cond.path },
83
+ content: cond.content && regexComponents(cond.content),
84
+ query: cond.query == null
85
+ ? undefined
86
+ : cond.query instanceof RegExp
87
+ ? {
88
+ type: "regex",
89
+ value: regexComponents(cond.query),
90
+ }
91
+ : { type: "constant", value: cond.query },
92
+ contentType: cond.contentType == null
93
+ ? undefined
94
+ : cond.contentType instanceof RegExp
95
+ ? {
96
+ type: "regex",
97
+ value: regexComponents(cond.contentType),
98
+ }
99
+ : { type: "glob", value: cond.contentType },
100
+ };
101
+ }
102
+ }
103
+ // Note: Returns an updated `turbopackRules` with serialized conditions. Does not mutate in-place.
104
+ function serializeModuleRules(turbopackRules) {
105
+ const serializedRules = {};
106
+ for (const [glob, rule] of Object.entries(turbopackRules)) {
107
+ if (Array.isArray(rule)) {
108
+ serializedRules[glob] = rule.map((item) => {
109
+ if (typeof item !== "string" &&
110
+ ("loaders" in item || "type" in item || "condition" in item)) {
111
+ return serializeConfigItem(item, glob);
112
+ }
113
+ else {
114
+ checkLoaderItem(item, glob);
115
+ return item;
116
+ }
117
+ });
118
+ }
119
+ else {
120
+ serializedRules[glob] = serializeConfigItem(rule, glob);
121
+ }
122
+ }
123
+ return serializedRules;
124
+ function serializeConfigItem(rule, glob) {
125
+ if (!rule)
126
+ return rule;
127
+ if (rule.loaders) {
128
+ for (const item of rule.loaders) {
129
+ checkLoaderItem(item, glob);
130
+ }
131
+ }
132
+ let serializedRule = rule;
133
+ if (rule.condition != null) {
134
+ serializedRule = {
135
+ ...rule,
136
+ condition: serializeRuleCondition(rule.condition),
137
+ };
138
+ }
139
+ return serializedRule;
140
+ }
141
+ function checkLoaderItem(loaderItem, glob) {
142
+ if (typeof loaderItem !== "string" &&
143
+ !isDeepStrictEqual(loaderItem, JSON.parse(JSON.stringify(loaderItem)))) {
144
+ throw new Error(`loader ${loaderItem.loader} for match "${glob}" does not have serializable options. ` +
145
+ "Ensure that options passed are plain JavaScript objects and values.");
146
+ }
147
+ }
148
+ }
47
149
  async function rustifyPartialProjectOptions(options) {
48
150
  return {
49
151
  ...options,
@@ -0,0 +1 @@
1
+ export declare function normalizePath(file: string): string;
@@ -0,0 +1,4 @@
1
+ import path from "path";
2
+ export function normalizePath(file) {
3
+ return path.sep === "\\" ? file.replace(/\\/g, "/") : file;
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.2.8",
3
+ "version": "1.2.10-alpha.0",
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.2.8",
42
+ "@utoo/pack-shared": "1.2.10-alpha.0",
43
43
  "@utoo/style-loader": "^1.0.0",
44
44
  "domparser-rs": "^0.0.7",
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.2.8",
90
- "@utoo/pack-darwin-x64": "1.2.8",
91
- "@utoo/pack-linux-arm64-gnu": "1.2.8",
92
- "@utoo/pack-linux-arm64-musl": "1.2.8",
93
- "@utoo/pack-linux-x64-gnu": "1.2.8",
94
- "@utoo/pack-linux-x64-musl": "1.2.8",
95
- "@utoo/pack-win32-x64-msvc": "1.2.8"
89
+ "@utoo/pack-darwin-arm64": "1.2.10-alpha.0",
90
+ "@utoo/pack-darwin-x64": "1.2.10-alpha.0",
91
+ "@utoo/pack-linux-arm64-gnu": "1.2.10-alpha.0",
92
+ "@utoo/pack-linux-arm64-musl": "1.2.10-alpha.0",
93
+ "@utoo/pack-linux-x64-gnu": "1.2.10-alpha.0",
94
+ "@utoo/pack-linux-x64-musl": "1.2.10-alpha.0",
95
+ "@utoo/pack-win32-x64-msvc": "1.2.10-alpha.0"
96
96
  }
97
97
  }