@jsenv/core 32.2.0 → 32.2.2
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.
|
@@ -7467,6 +7467,8 @@ const createUrlInfo = url => {
|
|
|
7467
7467
|
// "html", "css", "js_classic", "js_module", "importmap", "json", "webmanifest", ...
|
|
7468
7468
|
subtype: undefined,
|
|
7469
7469
|
// "worker", "service_worker", "shared_worker" for js, otherwise undefined
|
|
7470
|
+
typeHint: undefined,
|
|
7471
|
+
subtypeHint: undefined,
|
|
7470
7472
|
contentType: "",
|
|
7471
7473
|
// "text/html", "text/css", "text/javascript", "application/json", ...
|
|
7472
7474
|
url,
|
|
@@ -7488,7 +7490,8 @@ const createUrlInfo = url => {
|
|
|
7488
7490
|
// maybe move to inlineUrlSite?
|
|
7489
7491
|
|
|
7490
7492
|
timing: {},
|
|
7491
|
-
headers: {}
|
|
7493
|
+
headers: {},
|
|
7494
|
+
debug: false
|
|
7492
7495
|
};
|
|
7493
7496
|
// Object.preventExtensions(urlInfo) // useful to ensure all properties are declared here
|
|
7494
7497
|
return urlInfo;
|
|
@@ -9067,8 +9070,8 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
9067
9070
|
}
|
|
9068
9071
|
urlInfo.contentType = contentType;
|
|
9069
9072
|
urlInfo.headers = headers;
|
|
9070
|
-
urlInfo.type = type || reference.expectedType || inferUrlInfoType(
|
|
9071
|
-
urlInfo.subtype = subtype || reference.expectedSubtype || "";
|
|
9073
|
+
urlInfo.type = type || reference.expectedType || inferUrlInfoType(urlInfo);
|
|
9074
|
+
urlInfo.subtype = subtype || reference.expectedSubtype || urlInfo.subtypeHint || "";
|
|
9072
9075
|
// during build urls info are reused and load returns originalUrl/originalContent
|
|
9073
9076
|
urlInfo.originalUrl = originalUrl || urlInfo.originalUrl;
|
|
9074
9077
|
if (originalContent !== urlInfo.originalContent) {
|
|
@@ -9491,6 +9494,15 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
|
|
|
9491
9494
|
urlInfo.originalContent = context.build ? urlInfo.originalContent === undefined ? reference.content : urlInfo.originalContent : reference.content;
|
|
9492
9495
|
urlInfo.content = reference.content;
|
|
9493
9496
|
}
|
|
9497
|
+
if (reference.debug) {
|
|
9498
|
+
urlInfo.debug = true;
|
|
9499
|
+
}
|
|
9500
|
+
if (reference.expectedType) {
|
|
9501
|
+
urlInfo.typeHint = reference.expectedType;
|
|
9502
|
+
}
|
|
9503
|
+
if (reference.expectedSubtype) {
|
|
9504
|
+
urlInfo.subtypeHint = reference.expectedSubtype;
|
|
9505
|
+
}
|
|
9494
9506
|
};
|
|
9495
9507
|
const adjustUrlSite = (urlInfo, {
|
|
9496
9508
|
urlGraph,
|
|
@@ -9524,7 +9536,10 @@ const adjustUrlSite = (urlInfo, {
|
|
|
9524
9536
|
column
|
|
9525
9537
|
}, urlInfo);
|
|
9526
9538
|
};
|
|
9527
|
-
const inferUrlInfoType =
|
|
9539
|
+
const inferUrlInfoType = urlInfo => {
|
|
9540
|
+
const {
|
|
9541
|
+
contentType
|
|
9542
|
+
} = urlInfo;
|
|
9528
9543
|
if (contentType === "text/html") {
|
|
9529
9544
|
return "html";
|
|
9530
9545
|
}
|
|
@@ -9532,6 +9547,7 @@ const inferUrlInfoType = contentType => {
|
|
|
9532
9547
|
return "css";
|
|
9533
9548
|
}
|
|
9534
9549
|
if (contentType === "text/javascript") {
|
|
9550
|
+
if (urlInfo.typeHint === "js_classic") return "js_classic";
|
|
9535
9551
|
return "js_module";
|
|
9536
9552
|
}
|
|
9537
9553
|
if (contentType === "application/importmap+json") {
|
|
@@ -17174,21 +17190,19 @@ const jsenvPluginUrlResolution = ({
|
|
|
17174
17190
|
Object.keys(urlResolution).forEach(urlType => {
|
|
17175
17191
|
const resolver = urlResolution[urlType];
|
|
17176
17192
|
if (typeof resolver !== "object") {
|
|
17177
|
-
throw new Error(`
|
|
17178
|
-
"${urlType}" resolution value must be an object, got ${resolver}`);
|
|
17193
|
+
throw new Error(`urlResolution values must be objects, got ${resolver} on "${urlType}"`);
|
|
17179
17194
|
}
|
|
17180
17195
|
let {
|
|
17181
17196
|
web,
|
|
17182
17197
|
node_esm,
|
|
17183
17198
|
...rest
|
|
17184
17199
|
} = resolver;
|
|
17185
|
-
const
|
|
17186
|
-
if (
|
|
17187
|
-
throw new
|
|
17188
|
-
"${urlType}" resolution key must be "web" or "node_esm", found "${Object.keys(rest)[0]}"`);
|
|
17200
|
+
const unexpectedKeys = Object.keys(rest);
|
|
17201
|
+
if (unexpectedKeys.length) {
|
|
17202
|
+
throw new TypeError(`${unexpectedKeys.join(",")}: there is no such configuration on "${urlType}"`);
|
|
17189
17203
|
}
|
|
17190
17204
|
if (node_esm === undefined) {
|
|
17191
|
-
node_esm = urlType === "js_import"
|
|
17205
|
+
node_esm = urlType === "js_import";
|
|
17192
17206
|
}
|
|
17193
17207
|
if (web === undefined) {
|
|
17194
17208
|
web = true;
|
|
@@ -17208,11 +17222,20 @@ const jsenvPluginUrlResolution = ({
|
|
|
17208
17222
|
resolvers[urlType] = resolveUrlUsingWebResolution;
|
|
17209
17223
|
}
|
|
17210
17224
|
});
|
|
17225
|
+
const nodeEsmResolverDefault = createNodeEsmResolver({
|
|
17226
|
+
runtimeCompat,
|
|
17227
|
+
preservesSymlink: true
|
|
17228
|
+
});
|
|
17211
17229
|
if (!resolvers.js_module) {
|
|
17212
|
-
resolvers.js_module =
|
|
17213
|
-
|
|
17214
|
-
|
|
17215
|
-
|
|
17230
|
+
resolvers.js_module = nodeEsmResolverDefault;
|
|
17231
|
+
}
|
|
17232
|
+
if (!resolvers.js_classic) {
|
|
17233
|
+
resolvers.js_classic = (reference, context) => {
|
|
17234
|
+
if (reference.subtype === "self_import_scripts_arg") {
|
|
17235
|
+
return nodeEsmResolverDefault(reference, context);
|
|
17236
|
+
}
|
|
17237
|
+
return resolveUrlUsingWebResolution(reference);
|
|
17238
|
+
};
|
|
17216
17239
|
}
|
|
17217
17240
|
if (!resolvers["*"]) {
|
|
17218
17241
|
resolvers["*"] = resolveUrlUsingWebResolution;
|
|
@@ -17230,17 +17253,13 @@ const jsenvPluginUrlResolution = ({
|
|
|
17230
17253
|
if (reference.type === "sourcemap_comment") {
|
|
17231
17254
|
return resolveUrlUsingWebResolution(reference);
|
|
17232
17255
|
}
|
|
17233
|
-
let
|
|
17234
|
-
let subtype;
|
|
17235
|
-
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl);
|
|
17256
|
+
let urlType;
|
|
17236
17257
|
if (reference.injected) {
|
|
17237
|
-
|
|
17238
|
-
subtype = reference.expectedSubtype;
|
|
17258
|
+
urlType = reference.expectedType;
|
|
17239
17259
|
} else {
|
|
17240
|
-
|
|
17241
|
-
|
|
17260
|
+
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl);
|
|
17261
|
+
urlType = parentUrlInfo ? parentUrlInfo.type : "entry_point";
|
|
17242
17262
|
}
|
|
17243
|
-
const urlType = subtype === "self_import_scripts_arg" ? "js_import_script" : type;
|
|
17244
17263
|
const resolver = resolvers[urlType] || resolvers["*"];
|
|
17245
17264
|
return resolver(reference, context);
|
|
17246
17265
|
},
|
package/package.json
CHANGED
package/src/kitchen/kitchen.js
CHANGED
|
@@ -377,9 +377,9 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
377
377
|
}
|
|
378
378
|
urlInfo.contentType = contentType
|
|
379
379
|
urlInfo.headers = headers
|
|
380
|
-
urlInfo.type =
|
|
381
|
-
|
|
382
|
-
|
|
380
|
+
urlInfo.type = type || reference.expectedType || inferUrlInfoType(urlInfo)
|
|
381
|
+
urlInfo.subtype =
|
|
382
|
+
subtype || reference.expectedSubtype || urlInfo.subtypeHint || ""
|
|
383
383
|
// during build urls info are reused and load returns originalUrl/originalContent
|
|
384
384
|
urlInfo.originalUrl = originalUrl || urlInfo.originalUrl
|
|
385
385
|
if (originalContent !== urlInfo.originalContent) {
|
|
@@ -860,6 +860,16 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
|
|
|
860
860
|
: reference.content
|
|
861
861
|
urlInfo.content = reference.content
|
|
862
862
|
}
|
|
863
|
+
|
|
864
|
+
if (reference.debug) {
|
|
865
|
+
urlInfo.debug = true
|
|
866
|
+
}
|
|
867
|
+
if (reference.expectedType) {
|
|
868
|
+
urlInfo.typeHint = reference.expectedType
|
|
869
|
+
}
|
|
870
|
+
if (reference.expectedSubtype) {
|
|
871
|
+
urlInfo.subtypeHint = reference.expectedSubtype
|
|
872
|
+
}
|
|
863
873
|
}
|
|
864
874
|
|
|
865
875
|
const adjustUrlSite = (urlInfo, { urlGraph, url, line, column }) => {
|
|
@@ -902,7 +912,8 @@ const adjustUrlSite = (urlInfo, { urlGraph, url, line, column }) => {
|
|
|
902
912
|
)
|
|
903
913
|
}
|
|
904
914
|
|
|
905
|
-
const inferUrlInfoType = (
|
|
915
|
+
const inferUrlInfoType = (urlInfo) => {
|
|
916
|
+
const { contentType } = urlInfo
|
|
906
917
|
if (contentType === "text/html") {
|
|
907
918
|
return "html"
|
|
908
919
|
}
|
|
@@ -910,6 +921,7 @@ const inferUrlInfoType = (contentType) => {
|
|
|
910
921
|
return "css"
|
|
911
922
|
}
|
|
912
923
|
if (contentType === "text/javascript") {
|
|
924
|
+
if (urlInfo.typeHint === "js_classic") return "js_classic"
|
|
913
925
|
return "js_module"
|
|
914
926
|
}
|
|
915
927
|
if (contentType === "application/importmap+json") {
|
package/src/kitchen/url_graph.js
CHANGED
|
@@ -260,6 +260,8 @@ const createUrlInfo = (url) => {
|
|
|
260
260
|
implicitUrls: new Set(),
|
|
261
261
|
type: undefined, // "html", "css", "js_classic", "js_module", "importmap", "json", "webmanifest", ...
|
|
262
262
|
subtype: undefined, // "worker", "service_worker", "shared_worker" for js, otherwise undefined
|
|
263
|
+
typeHint: undefined,
|
|
264
|
+
subtypeHint: undefined,
|
|
263
265
|
contentType: "", // "text/html", "text/css", "text/javascript", "application/json", ...
|
|
264
266
|
url,
|
|
265
267
|
originalUrl: undefined,
|
|
@@ -283,6 +285,7 @@ const createUrlInfo = (url) => {
|
|
|
283
285
|
|
|
284
286
|
timing: {},
|
|
285
287
|
headers: {},
|
|
288
|
+
debug: false,
|
|
286
289
|
}
|
|
287
290
|
// Object.preventExtensions(urlInfo) // useful to ensure all properties are declared here
|
|
288
291
|
return urlInfo
|
|
@@ -50,22 +50,20 @@ export const jsenvPluginUrlResolution = ({
|
|
|
50
50
|
const resolver = urlResolution[urlType]
|
|
51
51
|
if (typeof resolver !== "object") {
|
|
52
52
|
throw new Error(
|
|
53
|
-
`
|
|
54
|
-
"${urlType}" resolution value must be an object, got ${resolver}`,
|
|
53
|
+
`urlResolution values must be objects, got ${resolver} on "${urlType}"`,
|
|
55
54
|
)
|
|
56
55
|
}
|
|
57
56
|
let { web, node_esm, ...rest } = resolver
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
throw new
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
}"`,
|
|
57
|
+
const unexpectedKeys = Object.keys(rest)
|
|
58
|
+
if (unexpectedKeys.length) {
|
|
59
|
+
throw new TypeError(
|
|
60
|
+
`${unexpectedKeys.join(
|
|
61
|
+
",",
|
|
62
|
+
)}: there is no such configuration on "${urlType}"`,
|
|
65
63
|
)
|
|
66
64
|
}
|
|
67
65
|
if (node_esm === undefined) {
|
|
68
|
-
node_esm = urlType === "js_import"
|
|
66
|
+
node_esm = urlType === "js_import"
|
|
69
67
|
}
|
|
70
68
|
if (web === undefined) {
|
|
71
69
|
web = true
|
|
@@ -83,11 +81,20 @@ export const jsenvPluginUrlResolution = ({
|
|
|
83
81
|
}
|
|
84
82
|
})
|
|
85
83
|
|
|
84
|
+
const nodeEsmResolverDefault = createNodeEsmResolver({
|
|
85
|
+
runtimeCompat,
|
|
86
|
+
preservesSymlink: true,
|
|
87
|
+
})
|
|
86
88
|
if (!resolvers.js_module) {
|
|
87
|
-
resolvers.js_module =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
resolvers.js_module = nodeEsmResolverDefault
|
|
90
|
+
}
|
|
91
|
+
if (!resolvers.js_classic) {
|
|
92
|
+
resolvers.js_classic = (reference, context) => {
|
|
93
|
+
if (reference.subtype === "self_import_scripts_arg") {
|
|
94
|
+
return nodeEsmResolverDefault(reference, context)
|
|
95
|
+
}
|
|
96
|
+
return resolveUrlUsingWebResolution(reference, context)
|
|
97
|
+
}
|
|
91
98
|
}
|
|
92
99
|
if (!resolvers["*"]) {
|
|
93
100
|
resolvers["*"] = resolveUrlUsingWebResolution
|
|
@@ -107,19 +114,13 @@ export const jsenvPluginUrlResolution = ({
|
|
|
107
114
|
if (reference.type === "sourcemap_comment") {
|
|
108
115
|
return resolveUrlUsingWebResolution(reference, context)
|
|
109
116
|
}
|
|
110
|
-
|
|
111
|
-
let type
|
|
112
|
-
let subtype
|
|
113
|
-
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
|
|
117
|
+
let urlType
|
|
114
118
|
if (reference.injected) {
|
|
115
|
-
|
|
116
|
-
subtype = reference.expectedSubtype
|
|
119
|
+
urlType = reference.expectedType
|
|
117
120
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
|
|
122
|
+
urlType = parentUrlInfo ? parentUrlInfo.type : "entry_point"
|
|
120
123
|
}
|
|
121
|
-
const urlType =
|
|
122
|
-
subtype === "self_import_scripts_arg" ? "js_import_script" : type
|
|
123
124
|
const resolver = resolvers[urlType] || resolvers["*"]
|
|
124
125
|
return resolver(reference, context)
|
|
125
126
|
},
|