@utoo/pack 1.2.9 → 1.2.10-rc.1
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/core/project.js +102 -0
- package/esm/core/project.js +102 -0
- package/package.json +9 -9
package/cjs/core/project.js
CHANGED
|
@@ -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,
|
package/esm/core/project.js
CHANGED
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10-rc.1",
|
|
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.
|
|
42
|
+
"@utoo/pack-shared": "1.2.10-rc.1",
|
|
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.
|
|
90
|
-
"@utoo/pack-darwin-x64": "1.2.
|
|
91
|
-
"@utoo/pack-linux-arm64-gnu": "1.2.
|
|
92
|
-
"@utoo/pack-linux-arm64-musl": "1.2.
|
|
93
|
-
"@utoo/pack-linux-x64-gnu": "1.2.
|
|
94
|
-
"@utoo/pack-linux-x64-musl": "1.2.
|
|
95
|
-
"@utoo/pack-win32-x64-msvc": "1.2.
|
|
89
|
+
"@utoo/pack-darwin-arm64": "1.2.10-rc.1",
|
|
90
|
+
"@utoo/pack-darwin-x64": "1.2.10-rc.1",
|
|
91
|
+
"@utoo/pack-linux-arm64-gnu": "1.2.10-rc.1",
|
|
92
|
+
"@utoo/pack-linux-arm64-musl": "1.2.10-rc.1",
|
|
93
|
+
"@utoo/pack-linux-x64-gnu": "1.2.10-rc.1",
|
|
94
|
+
"@utoo/pack-linux-x64-musl": "1.2.10-rc.1",
|
|
95
|
+
"@utoo/pack-win32-x64-msvc": "1.2.10-rc.1"
|
|
96
96
|
}
|
|
97
97
|
}
|