@jsenv/core 40.12.13 → 40.12.14
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/dist/build/build.js +259 -469
- package/dist/client/import_meta_css/import_meta_css_build.js +41 -12
- package/dist/client/import_meta_css/import_meta_css_dev.js +43 -31
- package/dist/start_build_server/start_build_server.js +7 -7
- package/dist/start_dev_server/start_dev_server.js +247 -448
- package/package.json +2 -2
- package/src/build/build.js +16 -15
- package/src/build/build_specifier_manager.js +11 -10
- package/src/build/mappings_injection.js +12 -11
- package/src/build/start_build_server.js +9 -9
- package/src/dev/start_dev_server.js +26 -26
- package/src/kitchen/errors.js +11 -11
- package/src/kitchen/kitchen.js +29 -21
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +1 -1
- package/src/plugins/autoreload_on_server_restart/jsenv_plugin_autoreload_on_server_restart.js +1 -1
- package/src/plugins/chrome_devtools_json/jsenv_plugin_chrome_devtools_json.js +1 -1
- package/src/plugins/import_meta_css/client/import_meta_css_build.js +41 -12
- package/src/plugins/import_meta_css/client/import_meta_css_dev.js +43 -31
- package/src/plugins/import_meta_css/jsenv_plugin_import_meta_css.js +70 -17
- package/src/plugins/jsenv_plugins_controller.js +197 -0
- package/src/plugins/protocol_file/jsenv_plugin_directory_listing.js +1 -1
- package/src/plugins/server_events/jsenv_plugin_server_events.js +1 -1
- package/src/plugins/plugin_controller.js +0 -458
package/dist/build/build.js
CHANGED
|
@@ -7,7 +7,7 @@ import { readFileSync, existsSync, readdirSync, lstatSync, realpathSync } from "
|
|
|
7
7
|
import { lookupPackageDirectory, registerDirectoryLifecycle, urlToRelativeUrl, createDetailedMessage, stringifyUrlSite, generateContentFrame, validateResponseIntegrity, urlIsOrIsInsideOf, ensureWindowsDriveLetter, setUrlFilename, moveUrl, getCallerPosition, urlToBasename, urlToExtension, asSpecifierWithoutSearch, asUrlWithoutSearch, injectQueryParamsIntoSpecifier, bufferToEtag, isFileSystemPath, urlToPathname, setUrlBasename, urlToFileSystemPath, writeFileSync, createLogger, URL_META, applyNodeEsmResolution, normalizeUrl, ANSI, RUNTIME_COMPAT, CONTENT_TYPE, readPackageAtOrNull, urlToFilename, DATA_URL, errorToHTML, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, readCustomConditionsFromProcessArgs, readEntryStatSync, ensurePathnameTrailingSlash, compareFileUrls, applyFileSystemMagicResolution, getExtensionsToTry, setUrlExtension, isSpecifierForNodeBuiltin, injectQueryParams, renderDetails, humanizeDuration, humanizeFileSize, renderTable, renderBigSection, distributePercentages, humanizeMemory, comparePathnames, UNICODE, escapeRegexpSpecialChars, injectQueryParamIntoSpecifierWithoutEncoding, renderUrlOrRelativeUrlFilename, assertAndNormalizeDirectoryUrl, Abort, raceProcessTeardownEvents, startMonitoringCpuUsage, startMonitoringMemoryUsage, inferRuntimeCompatFromClosestPackage, browserDefaultRuntimeCompat, nodeDefaultRuntimeCompat, clearDirectorySync, createTaskLog, createLookupPackageDirectory, ensureEmptyDirectory, updateJsonFileSync, createDynamicLog } from "./jsenv_core_packages.js";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
9
|
import { generateSourcemapFileUrl, createMagicSource, composeTwoSourcemaps, generateSourcemapDataUrl, SOURCEMAP } from "@jsenv/sourcemap";
|
|
10
|
-
import {
|
|
10
|
+
import { createPluginsController } from "@jsenv/server/src/plugins_controller.js";
|
|
11
11
|
import { jsenvPluginSupervisor } from "@jsenv/plugin-supervisor";
|
|
12
12
|
import { WebSocketResponse, pickContentType } from "@jsenv/server";
|
|
13
13
|
import { randomUUID, createHash } from "node:crypto";
|
|
@@ -133,7 +133,7 @@ const watchSourceFiles = (
|
|
|
133
133
|
const jsenvCoreDirectoryUrl = new URL("../", import.meta.url);
|
|
134
134
|
|
|
135
135
|
const createResolveUrlError = ({
|
|
136
|
-
|
|
136
|
+
jsenvPluginsController,
|
|
137
137
|
reference,
|
|
138
138
|
error,
|
|
139
139
|
}) => {
|
|
@@ -151,7 +151,7 @@ ${reason}`,
|
|
|
151
151
|
{
|
|
152
152
|
...detailsFromFirstReference(reference),
|
|
153
153
|
...details,
|
|
154
|
-
...detailsFromPluginController(
|
|
154
|
+
...detailsFromPluginController(jsenvPluginsController),
|
|
155
155
|
},
|
|
156
156
|
),
|
|
157
157
|
);
|
|
@@ -196,7 +196,7 @@ ${reason}`,
|
|
|
196
196
|
};
|
|
197
197
|
|
|
198
198
|
const createFetchUrlContentError = ({
|
|
199
|
-
|
|
199
|
+
jsenvPluginsController,
|
|
200
200
|
urlInfo,
|
|
201
201
|
error,
|
|
202
202
|
}) => {
|
|
@@ -215,7 +215,7 @@ ${reason}`,
|
|
|
215
215
|
{
|
|
216
216
|
...detailsFromFirstReference(reference),
|
|
217
217
|
...details,
|
|
218
|
-
...detailsFromPluginController(
|
|
218
|
+
...detailsFromPluginController(jsenvPluginsController),
|
|
219
219
|
},
|
|
220
220
|
),
|
|
221
221
|
);
|
|
@@ -271,7 +271,7 @@ ${reason}`,
|
|
|
271
271
|
};
|
|
272
272
|
|
|
273
273
|
const createTransformUrlContentError = ({
|
|
274
|
-
|
|
274
|
+
jsenvPluginsController,
|
|
275
275
|
urlInfo,
|
|
276
276
|
error,
|
|
277
277
|
}) => {
|
|
@@ -300,7 +300,7 @@ ${error.message}`,
|
|
|
300
300
|
? `${reference.trace.url}:${reference.trace.line}:${reference.trace.column}`
|
|
301
301
|
: reference.trace.message,
|
|
302
302
|
...detailsFromFirstReference(reference),
|
|
303
|
-
...detailsFromPluginController(
|
|
303
|
+
...detailsFromPluginController(jsenvPluginsController),
|
|
304
304
|
},
|
|
305
305
|
),
|
|
306
306
|
);
|
|
@@ -332,7 +332,7 @@ ${reason}`,
|
|
|
332
332
|
{
|
|
333
333
|
...detailsFromFirstReference(reference),
|
|
334
334
|
...details,
|
|
335
|
-
...detailsFromPluginController(
|
|
335
|
+
...detailsFromPluginController(jsenvPluginsController),
|
|
336
336
|
},
|
|
337
337
|
),
|
|
338
338
|
);
|
|
@@ -356,7 +356,7 @@ ${reason}`,
|
|
|
356
356
|
};
|
|
357
357
|
|
|
358
358
|
const createFinalizeUrlContentError = ({
|
|
359
|
-
|
|
359
|
+
jsenvPluginsController,
|
|
360
360
|
urlInfo,
|
|
361
361
|
error,
|
|
362
362
|
}) => {
|
|
@@ -368,7 +368,7 @@ ${reference.trace.message}`,
|
|
|
368
368
|
{
|
|
369
369
|
...detailsFromFirstReference(reference),
|
|
370
370
|
...detailsFromValueThrown(error),
|
|
371
|
-
...detailsFromPluginController(
|
|
371
|
+
...detailsFromPluginController(jsenvPluginsController),
|
|
372
372
|
},
|
|
373
373
|
),
|
|
374
374
|
);
|
|
@@ -458,8 +458,8 @@ const getFirstReferenceInProject = (reference) => {
|
|
|
458
458
|
return getFirstReferenceInProject(firstReference);
|
|
459
459
|
};
|
|
460
460
|
|
|
461
|
-
const detailsFromPluginController = (
|
|
462
|
-
const currentPlugin =
|
|
461
|
+
const detailsFromPluginController = (jsenvPluginsController) => {
|
|
462
|
+
const currentPlugin = jsenvPluginsController.getCurrentPlugin();
|
|
463
463
|
if (!currentPlugin) {
|
|
464
464
|
return null;
|
|
465
465
|
}
|
|
@@ -3031,14 +3031,14 @@ const createKitchen = ({
|
|
|
3031
3031
|
},
|
|
3032
3032
|
graph: null,
|
|
3033
3033
|
urlInfoTransformer: null,
|
|
3034
|
-
|
|
3034
|
+
jsenvPluginsController: null,
|
|
3035
3035
|
};
|
|
3036
3036
|
const kitchenContext = kitchen.context;
|
|
3037
3037
|
kitchenContext.kitchen = kitchen;
|
|
3038
3038
|
|
|
3039
|
-
let
|
|
3040
|
-
kitchen.
|
|
3041
|
-
|
|
3039
|
+
let jsenvPluginsController;
|
|
3040
|
+
kitchen.setJsenvPluginsController = (value) => {
|
|
3041
|
+
jsenvPluginsController = kitchen.jsenvPluginsController = value;
|
|
3042
3042
|
};
|
|
3043
3043
|
|
|
3044
3044
|
const graph = createUrlGraph({
|
|
@@ -3047,7 +3047,11 @@ const createKitchen = ({
|
|
|
3047
3047
|
kitchen,
|
|
3048
3048
|
});
|
|
3049
3049
|
graph.urlInfoCreatedEventEmitter.on((urlInfoCreated) => {
|
|
3050
|
-
|
|
3050
|
+
jsenvPluginsController.callHooks(
|
|
3051
|
+
"urlInfoCreated",
|
|
3052
|
+
urlInfoCreated,
|
|
3053
|
+
() => {},
|
|
3054
|
+
);
|
|
3051
3055
|
});
|
|
3052
3056
|
kitchen.graph = graph;
|
|
3053
3057
|
|
|
@@ -3221,7 +3225,7 @@ const createKitchen = ({
|
|
|
3221
3225
|
setReferenceUrl(reference.url);
|
|
3222
3226
|
break resolve;
|
|
3223
3227
|
}
|
|
3224
|
-
const resolvedUrl =
|
|
3228
|
+
const resolvedUrl = jsenvPluginsController.callHooksUntil(
|
|
3225
3229
|
"resolveReference",
|
|
3226
3230
|
reference,
|
|
3227
3231
|
);
|
|
@@ -3235,7 +3239,7 @@ const createKitchen = ({
|
|
|
3235
3239
|
setReferenceUrl(normalizedUrl);
|
|
3236
3240
|
if (reference.debug) {
|
|
3237
3241
|
logger.debug(`url resolved by "${
|
|
3238
|
-
|
|
3242
|
+
jsenvPluginsController.getLastPluginUsed().name
|
|
3239
3243
|
}"
|
|
3240
3244
|
${ANSI.color(reference.specifier, ANSI.GREY)} ->
|
|
3241
3245
|
${ANSI.color(reference.url, ANSI.YELLOW)}
|
|
@@ -3249,7 +3253,7 @@ ${ANSI.color(reference.url, ANSI.YELLOW)}
|
|
|
3249
3253
|
// - side_effect_file references injected in entry points or at the top of files
|
|
3250
3254
|
break redirect;
|
|
3251
3255
|
}
|
|
3252
|
-
|
|
3256
|
+
jsenvPluginsController.callHooks(
|
|
3253
3257
|
"redirectReference",
|
|
3254
3258
|
reference,
|
|
3255
3259
|
(returnValue, plugin, setReference) => {
|
|
@@ -3294,7 +3298,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3294
3298
|
return reference;
|
|
3295
3299
|
} catch (error) {
|
|
3296
3300
|
throw createResolveUrlError({
|
|
3297
|
-
|
|
3301
|
+
jsenvPluginsController,
|
|
3298
3302
|
reference,
|
|
3299
3303
|
error,
|
|
3300
3304
|
});
|
|
@@ -3321,7 +3325,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3321
3325
|
// But do not represent an other resource, it is considered as
|
|
3322
3326
|
// the same resource under the hood
|
|
3323
3327
|
const searchParamTransformationMap = new Map();
|
|
3324
|
-
|
|
3328
|
+
jsenvPluginsController.callHooks(
|
|
3325
3329
|
"transformReferenceSearchParams",
|
|
3326
3330
|
reference,
|
|
3327
3331
|
(returnValue) => {
|
|
@@ -3349,7 +3353,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3349
3353
|
}
|
|
3350
3354
|
}
|
|
3351
3355
|
{
|
|
3352
|
-
const returnValue =
|
|
3356
|
+
const returnValue = jsenvPluginsController.callHooksUntil(
|
|
3353
3357
|
"formatReference",
|
|
3354
3358
|
reference,
|
|
3355
3359
|
);
|
|
@@ -3370,7 +3374,10 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3370
3374
|
const fetchUrlContent = async (urlInfo) => {
|
|
3371
3375
|
try {
|
|
3372
3376
|
const fetchUrlContentReturnValue =
|
|
3373
|
-
await
|
|
3377
|
+
await jsenvPluginsController.callAsyncHooksUntil(
|
|
3378
|
+
"fetchUrlContent",
|
|
3379
|
+
urlInfo,
|
|
3380
|
+
);
|
|
3374
3381
|
if (!fetchUrlContentReturnValue) {
|
|
3375
3382
|
logger.warn(
|
|
3376
3383
|
createDetailedMessage(
|
|
@@ -3469,7 +3476,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3469
3476
|
});
|
|
3470
3477
|
} catch (error) {
|
|
3471
3478
|
throw createFetchUrlContentError({
|
|
3472
|
-
|
|
3479
|
+
jsenvPluginsController,
|
|
3473
3480
|
urlInfo,
|
|
3474
3481
|
error,
|
|
3475
3482
|
});
|
|
@@ -3479,7 +3486,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3479
3486
|
|
|
3480
3487
|
const transformUrlContent = async (urlInfo) => {
|
|
3481
3488
|
try {
|
|
3482
|
-
await
|
|
3489
|
+
await jsenvPluginsController.callAsyncHooks(
|
|
3483
3490
|
"transformUrlContent",
|
|
3484
3491
|
urlInfo,
|
|
3485
3492
|
(transformReturnValue) => {
|
|
@@ -3491,7 +3498,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3491
3498
|
);
|
|
3492
3499
|
} catch (error) {
|
|
3493
3500
|
const transformError = createTransformUrlContentError({
|
|
3494
|
-
|
|
3501
|
+
jsenvPluginsController,
|
|
3495
3502
|
urlInfo,
|
|
3496
3503
|
error,
|
|
3497
3504
|
});
|
|
@@ -3503,14 +3510,15 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
|
|
|
3503
3510
|
const finalizeUrlContent = async (urlInfo) => {
|
|
3504
3511
|
try {
|
|
3505
3512
|
await urlInfo.applyContentTransformationCallbacks();
|
|
3506
|
-
const finalizeReturnValue =
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3513
|
+
const finalizeReturnValue =
|
|
3514
|
+
await jsenvPluginsController.callAsyncHooksUntil(
|
|
3515
|
+
"finalizeUrlContent",
|
|
3516
|
+
urlInfo,
|
|
3517
|
+
);
|
|
3510
3518
|
urlInfoTransformer.endTransformations(urlInfo, finalizeReturnValue);
|
|
3511
3519
|
} catch (error) {
|
|
3512
3520
|
throw createFinalizeUrlContentError({
|
|
3513
|
-
|
|
3521
|
+
jsenvPluginsController,
|
|
3514
3522
|
urlInfo,
|
|
3515
3523
|
error,
|
|
3516
3524
|
});
|
|
@@ -3591,7 +3599,7 @@ ${urlInfo.firstReference.trace.message}`;
|
|
|
3591
3599
|
}
|
|
3592
3600
|
|
|
3593
3601
|
// "cooked" hook
|
|
3594
|
-
|
|
3602
|
+
jsenvPluginsController.callHooks("cooked", urlInfo, (cookedReturnValue) => {
|
|
3595
3603
|
if (typeof cookedReturnValue === "function") {
|
|
3596
3604
|
const removeCallback = urlInfo.graph.urlInfoDereferencedEventEmitter.on(
|
|
3597
3605
|
(urlInfoDereferenced, lastReferenceFromOther) => {
|
|
@@ -4223,9 +4231,9 @@ const replacePlaceholders = (html, replacers) => {
|
|
|
4223
4231
|
});
|
|
4224
4232
|
};
|
|
4225
4233
|
|
|
4226
|
-
const
|
|
4227
|
-
const
|
|
4228
|
-
const
|
|
4234
|
+
const createJsenvPluginStore = async (plugins) => {
|
|
4235
|
+
const allServerRoutes = [];
|
|
4236
|
+
const allServerPlugins = [];
|
|
4229
4237
|
const pluginArray = [];
|
|
4230
4238
|
|
|
4231
4239
|
const pluginPromises = [];
|
|
@@ -4248,16 +4256,17 @@ const createPluginStore = async (plugins) => {
|
|
|
4248
4256
|
if (!plugin.name) {
|
|
4249
4257
|
plugin.name = "anonymous";
|
|
4250
4258
|
}
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
for (const
|
|
4254
|
-
|
|
4259
|
+
const { serverRoutes } = plugin;
|
|
4260
|
+
if (serverRoutes) {
|
|
4261
|
+
for (const serverRoute of serverRoutes) {
|
|
4262
|
+
allServerRoutes.push(serverRoute);
|
|
4255
4263
|
}
|
|
4256
4264
|
}
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4265
|
+
const { serverPlugins } = plugin;
|
|
4266
|
+
if (serverPlugins) {
|
|
4267
|
+
const serverPlugins = plugin.serverPlugins;
|
|
4268
|
+
for (const serverPlugin of serverPlugins) {
|
|
4269
|
+
allServerPlugins.push(serverPlugin);
|
|
4261
4270
|
}
|
|
4262
4271
|
}
|
|
4263
4272
|
pluginArray.push(plugin);
|
|
@@ -4270,283 +4279,120 @@ const createPluginStore = async (plugins) => {
|
|
|
4270
4279
|
|
|
4271
4280
|
return {
|
|
4272
4281
|
pluginArray,
|
|
4273
|
-
|
|
4274
|
-
|
|
4282
|
+
allServerRoutes,
|
|
4283
|
+
allServerPlugins,
|
|
4275
4284
|
};
|
|
4276
4285
|
};
|
|
4277
4286
|
|
|
4278
|
-
const
|
|
4287
|
+
const createJsenvPluginsController = async (
|
|
4279
4288
|
pluginStore,
|
|
4280
4289
|
kitchen,
|
|
4281
|
-
{
|
|
4290
|
+
{ meta } = {},
|
|
4282
4291
|
) => {
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4292
|
+
kitchen.context.getPluginMeta = (id) => pluginsController.getPluginMeta(id);
|
|
4293
|
+
const pluginsController = await createPluginsController({
|
|
4294
|
+
plugins: pluginStore.pluginArray,
|
|
4295
|
+
pluginDescription: JSENV_PLUGIN_DESCRIPTION,
|
|
4296
|
+
filterPlugin: (plugin) => testAppliesDuring(plugin, kitchen),
|
|
4297
|
+
getInitPluginArgs: (plugin) => [kitchen.context, { plugin }],
|
|
4298
|
+
getEffectArgs: ({ otherPlugins }) => [
|
|
4299
|
+
{ kitchenContext: kitchen.context, otherPlugins },
|
|
4300
|
+
],
|
|
4301
|
+
meta,
|
|
4302
|
+
});
|
|
4303
|
+
return pluginsController;
|
|
4304
|
+
};
|
|
4288
4305
|
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
// 2. [MINOR REASON] it should increase perf as there is less work to do
|
|
4292
|
-
const hookSetMap = new Map();
|
|
4293
|
-
const pluginCandidates = pluginStore.pluginArray;
|
|
4294
|
-
const activePluginArray = [];
|
|
4295
|
-
const pluginWithEffectCandidateForActivationArray = [];
|
|
4296
|
-
for (const pluginCandidate of pluginCandidates) {
|
|
4297
|
-
if (!testAppliesDuring(pluginCandidate, kitchen)) {
|
|
4298
|
-
pluginCandidate.destroy?.();
|
|
4299
|
-
continue;
|
|
4300
|
-
}
|
|
4301
|
-
const initPluginResult = await initPlugin(pluginCandidate, kitchen);
|
|
4302
|
-
if (!initPluginResult) {
|
|
4303
|
-
pluginCandidate.destroy?.();
|
|
4304
|
-
continue;
|
|
4305
|
-
}
|
|
4306
|
-
if (pluginCandidate.effect) {
|
|
4307
|
-
pluginWithEffectCandidateForActivationArray.push(pluginCandidate);
|
|
4308
|
-
} else {
|
|
4309
|
-
activePluginArray.push(pluginCandidate);
|
|
4310
|
-
}
|
|
4311
|
-
}
|
|
4306
|
+
const hook = { type: "hook" };
|
|
4307
|
+
const nonHook = {};
|
|
4312
4308
|
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
kitchenContext: kitchen.context,
|
|
4317
|
-
otherPlugins: activePluginArray,
|
|
4318
|
-
});
|
|
4319
|
-
if (!returnValue) {
|
|
4320
|
-
continue;
|
|
4321
|
-
}
|
|
4322
|
-
activePluginArray.push(pluginWithEffectCandidateForActivation);
|
|
4323
|
-
activeEffectSet.add({
|
|
4324
|
-
plugin: pluginWithEffectCandidateForActivation,
|
|
4325
|
-
cleanup: typeof returnValue === "function" ? returnValue : () => {},
|
|
4326
|
-
});
|
|
4309
|
+
const assertUrlReturnValue = (valueReturned, urlInfo, { hook }) => {
|
|
4310
|
+
if (valueReturned instanceof URL) {
|
|
4311
|
+
return valueReturned.href;
|
|
4327
4312
|
}
|
|
4328
|
-
|
|
4329
|
-
return pluginCandidates.indexOf(a) - pluginCandidates.indexOf(b);
|
|
4330
|
-
});
|
|
4331
|
-
for (const activePlugin of activePluginArray) {
|
|
4332
|
-
for (const key of Object.keys(activePlugin)) {
|
|
4333
|
-
if (key === "meta") {
|
|
4334
|
-
const value = activePlugin[key];
|
|
4335
|
-
if (typeof value !== "object" || value === null) {
|
|
4336
|
-
console.warn(`plugin.meta must be an object, got ${value}`);
|
|
4337
|
-
continue;
|
|
4338
|
-
}
|
|
4339
|
-
Object.assign(pluginsMeta, value);
|
|
4340
|
-
// any extension/modification on plugin.meta
|
|
4341
|
-
// won't be taken into account so we freeze object
|
|
4342
|
-
// to throw in case it happen
|
|
4343
|
-
Object.freeze(value);
|
|
4344
|
-
continue;
|
|
4345
|
-
}
|
|
4346
|
-
if (
|
|
4347
|
-
key === "name" ||
|
|
4348
|
-
key === "appliesDuring" ||
|
|
4349
|
-
key === "init" ||
|
|
4350
|
-
key === "serverEvents" ||
|
|
4351
|
-
key === "mustStayFirst" ||
|
|
4352
|
-
key === "devServerRoutes" ||
|
|
4353
|
-
key === "devServerServices" ||
|
|
4354
|
-
key === "effect"
|
|
4355
|
-
) {
|
|
4356
|
-
continue;
|
|
4357
|
-
}
|
|
4358
|
-
const isHook = HOOK_NAMES.includes(key);
|
|
4359
|
-
if (!isHook) {
|
|
4360
|
-
console.warn(
|
|
4361
|
-
`Unexpected "${key}" property on "${activePlugin.name}" plugin`,
|
|
4362
|
-
);
|
|
4363
|
-
continue;
|
|
4364
|
-
}
|
|
4365
|
-
const hookName = key;
|
|
4366
|
-
const hookValue = activePlugin[hookName];
|
|
4367
|
-
if (hookValue) {
|
|
4368
|
-
let hookSet = hookSetMap.get(hookName);
|
|
4369
|
-
if (!hookSet) {
|
|
4370
|
-
hookSet = new Set();
|
|
4371
|
-
hookSetMap.set(hookName, hookSet);
|
|
4372
|
-
}
|
|
4373
|
-
const hook = {
|
|
4374
|
-
plugin: activePlugin,
|
|
4375
|
-
name: hookName,
|
|
4376
|
-
value: hookValue,
|
|
4377
|
-
};
|
|
4378
|
-
// if (position === "start") {
|
|
4379
|
-
// let i = 0;
|
|
4380
|
-
// while (i < group.length) {
|
|
4381
|
-
// const before = group[i];
|
|
4382
|
-
// if (!before.plugin.mustStayFirst) {
|
|
4383
|
-
// break;
|
|
4384
|
-
// }
|
|
4385
|
-
// i++;
|
|
4386
|
-
// }
|
|
4387
|
-
// group.splice(i, 0, hook);
|
|
4388
|
-
// } else {
|
|
4389
|
-
hookSet.add(hook);
|
|
4390
|
-
}
|
|
4391
|
-
}
|
|
4392
|
-
}
|
|
4393
|
-
|
|
4394
|
-
let lastPluginUsed = null;
|
|
4395
|
-
let currentPlugin = null;
|
|
4396
|
-
let currentHookName = null;
|
|
4397
|
-
const callHook = (hook, info) => {
|
|
4398
|
-
const hookFn = getHookFunction(hook, info);
|
|
4399
|
-
if (!hookFn) {
|
|
4400
|
-
return null;
|
|
4401
|
-
}
|
|
4402
|
-
let startTimestamp;
|
|
4403
|
-
if (info.timing) {
|
|
4404
|
-
startTimestamp = performance.now();
|
|
4405
|
-
}
|
|
4406
|
-
lastPluginUsed = hook.plugin;
|
|
4407
|
-
currentPlugin = hook.plugin;
|
|
4408
|
-
currentHookName = hook.name;
|
|
4409
|
-
let valueReturned = hookFn(info);
|
|
4410
|
-
if (info.timing) {
|
|
4411
|
-
info.timing[`${hook.name}-${hook.plugin.name.replace("jsenv:", "")}`] =
|
|
4412
|
-
performance.now() - startTimestamp;
|
|
4413
|
-
}
|
|
4414
|
-
valueReturned = assertAndNormalizeReturnValue(hook, valueReturned, info);
|
|
4415
|
-
currentPlugin = null;
|
|
4416
|
-
currentHookName = null;
|
|
4417
|
-
return valueReturned;
|
|
4418
|
-
};
|
|
4419
|
-
const callAsyncHook = async (hook, info) => {
|
|
4420
|
-
const hookFn = getHookFunction(hook, info);
|
|
4421
|
-
if (!hookFn) {
|
|
4422
|
-
return null;
|
|
4423
|
-
}
|
|
4424
|
-
|
|
4425
|
-
let startTimestamp;
|
|
4426
|
-
if (info.timing) {
|
|
4427
|
-
startTimestamp = performance.now();
|
|
4428
|
-
}
|
|
4429
|
-
lastPluginUsed = hook.plugin;
|
|
4430
|
-
currentPlugin = hook.plugin;
|
|
4431
|
-
currentHookName = hook.name;
|
|
4432
|
-
let valueReturned = await hookFn(info);
|
|
4433
|
-
if (info.timing) {
|
|
4434
|
-
info.timing[`${hook.name}-${hook.plugin.name.replace("jsenv:", "")}`] =
|
|
4435
|
-
performance.now() - startTimestamp;
|
|
4436
|
-
}
|
|
4437
|
-
valueReturned = assertAndNormalizeReturnValue(hook, valueReturned, info);
|
|
4438
|
-
currentPlugin = null;
|
|
4439
|
-
currentHookName = null;
|
|
4313
|
+
if (typeof valueReturned === "string") {
|
|
4440
4314
|
return valueReturned;
|
|
4441
|
-
}
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
}
|
|
4455
|
-
}
|
|
4456
|
-
};
|
|
4457
|
-
const callAsyncHooks = async (hookName, info, callback, options) => {
|
|
4458
|
-
const hookSet = hookSetMap.get(hookName);
|
|
4459
|
-
if (!hookSet) {
|
|
4460
|
-
return;
|
|
4461
|
-
}
|
|
4462
|
-
for (const hook of hookSet) {
|
|
4463
|
-
const returnValue = await callAsyncHook(hook, info);
|
|
4464
|
-
if (returnValue && callback) {
|
|
4465
|
-
await callback(returnValue, hook.plugin);
|
|
4466
|
-
}
|
|
4467
|
-
}
|
|
4468
|
-
};
|
|
4469
|
-
const callHooksUntil = (hookName, info) => {
|
|
4470
|
-
const hookSet = hookSetMap.get(hookName);
|
|
4471
|
-
if (!hookSet) {
|
|
4472
|
-
return null;
|
|
4315
|
+
}
|
|
4316
|
+
throw new Error(
|
|
4317
|
+
`Unexpected value returned by hook "${hook.plugin.name}.${hook.name}()": it must be a string; got ${valueReturned}`,
|
|
4318
|
+
);
|
|
4319
|
+
};
|
|
4320
|
+
const assertContentReturnValue = (valueReturned, urlInfo, { hook }) => {
|
|
4321
|
+
if (typeof valueReturned === "string" || Buffer.isBuffer(valueReturned)) {
|
|
4322
|
+
return { content: valueReturned };
|
|
4323
|
+
}
|
|
4324
|
+
if (typeof valueReturned === "object") {
|
|
4325
|
+
const { content, body } = valueReturned;
|
|
4326
|
+
if (urlInfo.url.startsWith("ignore:")) {
|
|
4327
|
+
return valueReturned;
|
|
4473
4328
|
}
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
return returnValue;
|
|
4329
|
+
if (typeof content !== "string" && !Buffer.isBuffer(content) && !body) {
|
|
4330
|
+
if (Object.hasOwn(valueReturned, "contentInjections")) {
|
|
4331
|
+
return valueReturned;
|
|
4478
4332
|
}
|
|
4333
|
+
throw new Error(
|
|
4334
|
+
`Unexpected "content" returned by hook "${hook.plugin.name}.${hook.name}()": it must be a string or a buffer; got ${content}`,
|
|
4335
|
+
);
|
|
4479
4336
|
}
|
|
4480
|
-
return
|
|
4481
|
-
}
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
}
|
|
4487
|
-
if (hookSet.size === 0) {
|
|
4488
|
-
return null;
|
|
4489
|
-
}
|
|
4490
|
-
const iterator = hookSet.values()[Symbol.iterator]();
|
|
4491
|
-
let result;
|
|
4492
|
-
const visit = async () => {
|
|
4493
|
-
const { done, value: hook } = iterator.next();
|
|
4494
|
-
if (done) {
|
|
4495
|
-
return;
|
|
4496
|
-
}
|
|
4497
|
-
const returnValue = await callAsyncHook(hook, info);
|
|
4498
|
-
if (returnValue) {
|
|
4499
|
-
result = returnValue;
|
|
4500
|
-
return;
|
|
4501
|
-
}
|
|
4502
|
-
await visit();
|
|
4503
|
-
};
|
|
4504
|
-
await visit();
|
|
4505
|
-
return result;
|
|
4506
|
-
};
|
|
4337
|
+
return valueReturned;
|
|
4338
|
+
}
|
|
4339
|
+
throw new Error(
|
|
4340
|
+
`Unexpected value returned by hook "${hook.plugin.name}.${hook.name}()": it must be a string, a buffer or an object; got ${valueReturned}`,
|
|
4341
|
+
);
|
|
4342
|
+
};
|
|
4507
4343
|
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
}
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4344
|
+
const JSENV_PLUGIN_DESCRIPTION = {
|
|
4345
|
+
name: "jsenv plugin",
|
|
4346
|
+
properties: {
|
|
4347
|
+
// non-hook properties (silently skipped)
|
|
4348
|
+
appliesDuring: nonHook,
|
|
4349
|
+
serverEvents: nonHook,
|
|
4350
|
+
mustStayFirst: nonHook,
|
|
4351
|
+
serverRoutes: nonHook,
|
|
4352
|
+
serverPlugins: nonHook,
|
|
4353
|
+
// hooks
|
|
4354
|
+
init: hook,
|
|
4355
|
+
resolveReference: {
|
|
4356
|
+
type: "hook",
|
|
4357
|
+
assertAndNormalize: assertUrlReturnValue,
|
|
4358
|
+
},
|
|
4359
|
+
redirectReference: {
|
|
4360
|
+
type: "hook",
|
|
4361
|
+
assertAndNormalize: assertUrlReturnValue,
|
|
4362
|
+
},
|
|
4363
|
+
transformReferenceSearchParams: hook,
|
|
4364
|
+
formatReference: hook,
|
|
4365
|
+
urlInfoCreated: hook,
|
|
4366
|
+
fetchUrlContent: {
|
|
4367
|
+
type: "hook",
|
|
4368
|
+
assertAndNormalize: assertContentReturnValue,
|
|
4369
|
+
},
|
|
4370
|
+
transformUrlContent: {
|
|
4371
|
+
type: "hook",
|
|
4372
|
+
assertAndNormalize: assertContentReturnValue,
|
|
4373
|
+
},
|
|
4374
|
+
finalizeUrlContent: {
|
|
4375
|
+
type: "hook",
|
|
4376
|
+
assertAndNormalize: assertContentReturnValue,
|
|
4377
|
+
},
|
|
4378
|
+
bundle: hook,
|
|
4379
|
+
optimizeBuildUrlContent: {
|
|
4380
|
+
type: "hook",
|
|
4381
|
+
assertAndNormalize: assertContentReturnValue,
|
|
4382
|
+
},
|
|
4383
|
+
cooked: hook,
|
|
4384
|
+
augmentResponse: hook,
|
|
4385
|
+
destroy: hook,
|
|
4386
|
+
effect: hook,
|
|
4387
|
+
refineBuildUrlContent: hook,
|
|
4388
|
+
refineBuild: hook,
|
|
4389
|
+
// serverRoutes and serverPlugins are nonHook above
|
|
4390
|
+
},
|
|
4391
|
+
};
|
|
4545
4392
|
|
|
4546
4393
|
const testAppliesDuring = (plugin, kitchen) => {
|
|
4547
4394
|
const { appliesDuring } = plugin;
|
|
4548
4395
|
if (appliesDuring === undefined) {
|
|
4549
|
-
// console.debug(`"appliesDuring" is undefined on ${pluginEntry.name}`)
|
|
4550
4396
|
return true;
|
|
4551
4397
|
}
|
|
4552
4398
|
if (appliesDuring === "*") {
|
|
@@ -4572,112 +4418,12 @@ const testAppliesDuring = (plugin, kitchen) => {
|
|
|
4572
4418
|
return true;
|
|
4573
4419
|
}
|
|
4574
4420
|
}
|
|
4575
|
-
// throw new Error(`"appliesDuring" is empty`)
|
|
4576
4421
|
return false;
|
|
4577
4422
|
}
|
|
4578
4423
|
throw new TypeError(
|
|
4579
4424
|
`"appliesDuring" must be an object or a string, got ${appliesDuring}`,
|
|
4580
4425
|
);
|
|
4581
4426
|
};
|
|
4582
|
-
const initPlugin = async (plugin, kitchen) => {
|
|
4583
|
-
const { init } = plugin;
|
|
4584
|
-
if (!init) {
|
|
4585
|
-
return true;
|
|
4586
|
-
}
|
|
4587
|
-
const initReturnValue = await init(kitchen.context, { plugin });
|
|
4588
|
-
if (initReturnValue === false) {
|
|
4589
|
-
return false;
|
|
4590
|
-
}
|
|
4591
|
-
if (typeof initReturnValue === "function" && !plugin.destroy) {
|
|
4592
|
-
plugin.destroy = initReturnValue;
|
|
4593
|
-
}
|
|
4594
|
-
return true;
|
|
4595
|
-
};
|
|
4596
|
-
const getHookFunction = (
|
|
4597
|
-
hook,
|
|
4598
|
-
// can be undefined, reference, or urlInfo
|
|
4599
|
-
info = {},
|
|
4600
|
-
) => {
|
|
4601
|
-
const hookValue = hook.value;
|
|
4602
|
-
if (typeof hookValue === "object") {
|
|
4603
|
-
const hookForType = hookValue[info.type] || hookValue["*"];
|
|
4604
|
-
if (!hookForType) {
|
|
4605
|
-
return null;
|
|
4606
|
-
}
|
|
4607
|
-
return hookForType;
|
|
4608
|
-
}
|
|
4609
|
-
return hookValue;
|
|
4610
|
-
};
|
|
4611
|
-
|
|
4612
|
-
const assertAndNormalizeReturnValue = (hook, returnValue, info) => {
|
|
4613
|
-
// all hooks are allowed to return null/undefined as a signal of "I don't do anything"
|
|
4614
|
-
if (returnValue === null || returnValue === undefined) {
|
|
4615
|
-
return returnValue;
|
|
4616
|
-
}
|
|
4617
|
-
for (const returnValueAssertion of returnValueAssertions) {
|
|
4618
|
-
if (!returnValueAssertion.appliesTo.includes(hook.name)) {
|
|
4619
|
-
continue;
|
|
4620
|
-
}
|
|
4621
|
-
const assertionResult = returnValueAssertion.assertion(returnValue, info, {
|
|
4622
|
-
hook,
|
|
4623
|
-
});
|
|
4624
|
-
if (assertionResult !== undefined) {
|
|
4625
|
-
// normalization
|
|
4626
|
-
returnValue = assertionResult;
|
|
4627
|
-
break;
|
|
4628
|
-
}
|
|
4629
|
-
}
|
|
4630
|
-
return returnValue;
|
|
4631
|
-
};
|
|
4632
|
-
const returnValueAssertions = [
|
|
4633
|
-
{
|
|
4634
|
-
name: "url_assertion",
|
|
4635
|
-
appliesTo: ["resolveReference", "redirectReference"],
|
|
4636
|
-
assertion: (valueReturned, urlInfo, { hook }) => {
|
|
4637
|
-
if (valueReturned instanceof URL) {
|
|
4638
|
-
return valueReturned.href;
|
|
4639
|
-
}
|
|
4640
|
-
if (typeof valueReturned === "string") {
|
|
4641
|
-
return undefined;
|
|
4642
|
-
}
|
|
4643
|
-
throw new Error(
|
|
4644
|
-
`Unexpected value returned by "${hook.plugin.name}" plugin: it must be a string; got ${valueReturned}`,
|
|
4645
|
-
);
|
|
4646
|
-
},
|
|
4647
|
-
},
|
|
4648
|
-
{
|
|
4649
|
-
name: "content_assertion",
|
|
4650
|
-
appliesTo: [
|
|
4651
|
-
"fetchUrlContent",
|
|
4652
|
-
"transformUrlContent",
|
|
4653
|
-
"finalizeUrlContent",
|
|
4654
|
-
"optimizeBuildUrlContent",
|
|
4655
|
-
],
|
|
4656
|
-
assertion: (valueReturned, urlInfo, { hook }) => {
|
|
4657
|
-
if (typeof valueReturned === "string" || Buffer.isBuffer(valueReturned)) {
|
|
4658
|
-
return { content: valueReturned };
|
|
4659
|
-
}
|
|
4660
|
-
if (typeof valueReturned === "object") {
|
|
4661
|
-
const { content, body } = valueReturned;
|
|
4662
|
-
if (urlInfo.url.startsWith("ignore:")) {
|
|
4663
|
-
return undefined;
|
|
4664
|
-
}
|
|
4665
|
-
if (typeof content !== "string" && !Buffer.isBuffer(content) && !body) {
|
|
4666
|
-
if (Object.hasOwn(valueReturned, "contentInjections")) {
|
|
4667
|
-
return undefined;
|
|
4668
|
-
}
|
|
4669
|
-
throw new Error(
|
|
4670
|
-
`Unexpected "content" returned by "${hook.plugin.name}" ${hook.name} hook: it must be a string or a buffer; got ${content}`,
|
|
4671
|
-
);
|
|
4672
|
-
}
|
|
4673
|
-
return undefined;
|
|
4674
|
-
}
|
|
4675
|
-
throw new Error(
|
|
4676
|
-
`Unexpected value returned by "${hook.plugin.name}" ${hook.name} hook: it must be a string, a buffer or an object; got ${valueReturned}`,
|
|
4677
|
-
);
|
|
4678
|
-
},
|
|
4679
|
-
},
|
|
4680
|
-
];
|
|
4681
4427
|
|
|
4682
4428
|
/*
|
|
4683
4429
|
* https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
|
|
@@ -6732,7 +6478,7 @@ const jsenvPluginDirectoryListing = ({
|
|
|
6732
6478
|
};
|
|
6733
6479
|
},
|
|
6734
6480
|
},
|
|
6735
|
-
|
|
6481
|
+
serverRoutes: [
|
|
6736
6482
|
{
|
|
6737
6483
|
endpoint:
|
|
6738
6484
|
"GET /.internal/directory_content.websocket?directory=:directory",
|
|
@@ -7916,11 +7662,7 @@ const jsenvPluginImportMetaCss = () => {
|
|
|
7916
7662
|
appliesDuring: "*",
|
|
7917
7663
|
transformUrlContent: {
|
|
7918
7664
|
js_module: async (urlInfo) => {
|
|
7919
|
-
if (
|
|
7920
|
-
!urlInfo.content.includes("import.meta.css") ||
|
|
7921
|
-
// there is already our installImportMetaCssBuild in the file
|
|
7922
|
-
urlInfo.content.includes("installImportMetaCssBuild")
|
|
7923
|
-
) {
|
|
7665
|
+
if (!urlInfo.content.includes("import.meta.css")) {
|
|
7924
7666
|
return null;
|
|
7925
7667
|
}
|
|
7926
7668
|
const { metadata } = await applyBabelPlugins({
|
|
@@ -7934,22 +7676,70 @@ const jsenvPluginImportMetaCss = () => {
|
|
|
7934
7676
|
if (!usesImportMetaCss) {
|
|
7935
7677
|
return null;
|
|
7936
7678
|
}
|
|
7679
|
+
if (urlInfo.context.build) {
|
|
7680
|
+
const rootDirectoryUrl = urlInfo.context.rootDirectoryUrl;
|
|
7681
|
+
const relativeUrl = urlInfo.originalUrl.slice(
|
|
7682
|
+
rootDirectoryUrl.length - 1,
|
|
7683
|
+
);
|
|
7684
|
+
const { code } = await applyBabelPlugins({
|
|
7685
|
+
babelPlugins: [
|
|
7686
|
+
[babelPluginRewriteImportMetaCssAssignment, { relativeUrl }],
|
|
7687
|
+
],
|
|
7688
|
+
input: urlInfo.content,
|
|
7689
|
+
inputIsJsModule: true,
|
|
7690
|
+
inputUrl: urlInfo.originalUrl,
|
|
7691
|
+
outputUrl: urlInfo.generatedUrl,
|
|
7692
|
+
});
|
|
7693
|
+
return injectImportMetaCss(urlInfo, {
|
|
7694
|
+
content: code,
|
|
7695
|
+
importFrom: importMetaCssBuildClientFileUrl,
|
|
7696
|
+
importName: "installImportMetaCssBuild",
|
|
7697
|
+
importAs: "__installImportMetaCssBuild__",
|
|
7698
|
+
});
|
|
7699
|
+
}
|
|
7937
7700
|
return injectImportMetaCss(urlInfo, {
|
|
7938
|
-
|
|
7939
|
-
|
|
7940
|
-
|
|
7941
|
-
|
|
7942
|
-
|
|
7943
|
-
: "installImportMetaCssDev",
|
|
7944
|
-
importAs: urlInfo.context.build
|
|
7945
|
-
? "__installImportMetaCssBuild__"
|
|
7946
|
-
: "__installImportMetaCssDev__",
|
|
7701
|
+
content: urlInfo.content,
|
|
7702
|
+
importFrom: importMetaCssDevClientFileUrl,
|
|
7703
|
+
importName: "installImportMetaCssDev",
|
|
7704
|
+
importAs: "__installImportMetaCssDev__",
|
|
7705
|
+
hot: true,
|
|
7947
7706
|
});
|
|
7948
7707
|
},
|
|
7949
7708
|
},
|
|
7950
7709
|
};
|
|
7951
7710
|
};
|
|
7952
7711
|
|
|
7712
|
+
const babelPluginRewriteImportMetaCssAssignment = (
|
|
7713
|
+
{ types: t },
|
|
7714
|
+
{ relativeUrl },
|
|
7715
|
+
) => {
|
|
7716
|
+
return {
|
|
7717
|
+
name: "rewrite-import-meta-css-assignment",
|
|
7718
|
+
visitor: {
|
|
7719
|
+
AssignmentExpression(path) {
|
|
7720
|
+
const { left, right } = path.node;
|
|
7721
|
+
if (left.type !== "MemberExpression") {
|
|
7722
|
+
return;
|
|
7723
|
+
}
|
|
7724
|
+
const { object, property } = left;
|
|
7725
|
+
if (object.type !== "MetaProperty") {
|
|
7726
|
+
return;
|
|
7727
|
+
}
|
|
7728
|
+
if (object.meta.name !== "import" || object.property.name !== "meta") {
|
|
7729
|
+
return;
|
|
7730
|
+
}
|
|
7731
|
+
if (property.name !== "css") {
|
|
7732
|
+
return;
|
|
7733
|
+
}
|
|
7734
|
+
path.node.right = t.arrayExpression([
|
|
7735
|
+
right,
|
|
7736
|
+
t.stringLiteral(relativeUrl),
|
|
7737
|
+
]);
|
|
7738
|
+
},
|
|
7739
|
+
},
|
|
7740
|
+
};
|
|
7741
|
+
};
|
|
7742
|
+
|
|
7953
7743
|
const babelPluginMetadataUsesImportMetaCss = () => {
|
|
7954
7744
|
return {
|
|
7955
7745
|
name: "metadata-uses-import-meta-css",
|
|
@@ -7981,7 +7771,10 @@ const babelPluginMetadataUsesImportMetaCss = () => {
|
|
|
7981
7771
|
};
|
|
7982
7772
|
};
|
|
7983
7773
|
|
|
7984
|
-
const injectImportMetaCss = (
|
|
7774
|
+
const injectImportMetaCss = (
|
|
7775
|
+
urlInfo,
|
|
7776
|
+
{ content, importFrom, importName, importAs, hot },
|
|
7777
|
+
) => {
|
|
7985
7778
|
const importMetaCssClientFileReference = urlInfo.dependencies.inject({
|
|
7986
7779
|
parentUrl: urlInfo.url,
|
|
7987
7780
|
type: "js_import",
|
|
@@ -7990,14 +7783,16 @@ const injectImportMetaCss = (urlInfo, { importFrom, importName, importAs }) => {
|
|
|
7990
7783
|
});
|
|
7991
7784
|
let importVariableName;
|
|
7992
7785
|
let importBeforeFrom;
|
|
7993
|
-
if (importAs !== importName) {
|
|
7786
|
+
if (importAs && importAs !== importName) {
|
|
7994
7787
|
importBeforeFrom = `{ ${importName} as ${importAs} }`;
|
|
7995
7788
|
importVariableName = importAs;
|
|
7996
7789
|
} else {
|
|
7997
7790
|
importBeforeFrom = `{ ${importName} } }`;
|
|
7998
7791
|
importVariableName = importName;
|
|
7999
7792
|
}
|
|
8000
|
-
|
|
7793
|
+
|
|
7794
|
+
const prelude = hot
|
|
7795
|
+
? `import ${importBeforeFrom} from ${importMetaCssClientFileReference.generatedSpecifier};
|
|
8001
7796
|
|
|
8002
7797
|
const remove = ${importVariableName}(import.meta);
|
|
8003
7798
|
if (import.meta.hot) {
|
|
@@ -8006,9 +7801,13 @@ if (import.meta.hot) {
|
|
|
8006
7801
|
});
|
|
8007
7802
|
}
|
|
8008
7803
|
|
|
7804
|
+
`
|
|
7805
|
+
: `import ${importBeforeFrom} from ${importMetaCssClientFileReference.generatedSpecifier};
|
|
7806
|
+
|
|
7807
|
+
${importVariableName}(import.meta);
|
|
7808
|
+
|
|
8009
7809
|
`;
|
|
8010
7810
|
|
|
8011
|
-
let content = urlInfo.content;
|
|
8012
7811
|
return {
|
|
8013
7812
|
content: `${prelude.replace(/\n/g, "")}${content}`,
|
|
8014
7813
|
};
|
|
@@ -8742,7 +8541,7 @@ const jsenvPluginAutoreloadServer = ({
|
|
|
8742
8541
|
);
|
|
8743
8542
|
},
|
|
8744
8543
|
},
|
|
8745
|
-
|
|
8544
|
+
serverRoutes: [
|
|
8746
8545
|
{
|
|
8747
8546
|
endpoint: "GET /.internal/graph.json",
|
|
8748
8547
|
description:
|
|
@@ -9034,7 +8833,7 @@ const jsenvPluginChromeDevtoolsJson = () => {
|
|
|
9034
8833
|
return {
|
|
9035
8834
|
name: "jsenv_plugin_chrome_devtools_json",
|
|
9036
8835
|
appliesDuring: "dev",
|
|
9037
|
-
|
|
8836
|
+
serverRoutes: [
|
|
9038
8837
|
{
|
|
9039
8838
|
endpoint: "GET /.well-known/appspecific/com.chrome.devtools.json",
|
|
9040
8839
|
declarationSource: import.meta.url,
|
|
@@ -9054,7 +8853,7 @@ const jsenvPluginChromeDevtoolsJson = () => {
|
|
|
9054
8853
|
|
|
9055
8854
|
const jsenvPluginAutoreloadOnServerRestart = () => {
|
|
9056
8855
|
const autoreloadOnRestartClientFileUrl = import.meta
|
|
9057
|
-
.resolve("@jsenv/server/src/
|
|
8856
|
+
.resolve("@jsenv/server/src/plugins/autoreload_on_server_restart/client/autoreload_on_server_restart.js");
|
|
9058
8857
|
|
|
9059
8858
|
return {
|
|
9060
8859
|
name: "jsenv:autoreload_on_server_restart",
|
|
@@ -9787,25 +9586,27 @@ const logsDefault = {
|
|
|
9787
9586
|
// https://bundlers.tooling.report/hashing/avoid-cascade/
|
|
9788
9587
|
|
|
9789
9588
|
|
|
9589
|
+
// we nevery minify those because they are already very small
|
|
9590
|
+
// and would hurt the readability of something that can be critical to debug
|
|
9790
9591
|
const injectGlobalMappings = async (urlInfo, mappings) => {
|
|
9791
9592
|
if (urlInfo.type === "html") {
|
|
9792
|
-
const minification = Boolean(
|
|
9793
|
-
|
|
9794
|
-
);
|
|
9593
|
+
// const minification = Boolean(
|
|
9594
|
+
// urlInfo.context.getPluginMeta("willMinifyJsClassic"),
|
|
9595
|
+
// );
|
|
9795
9596
|
const content = generateClientCodeForMappings(mappings, {
|
|
9796
9597
|
globalName: "window",
|
|
9797
|
-
minification,
|
|
9598
|
+
minification: false,
|
|
9798
9599
|
});
|
|
9799
9600
|
await prependContent(urlInfo, { type: "js_classic", content });
|
|
9800
9601
|
return;
|
|
9801
9602
|
}
|
|
9802
9603
|
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
9803
|
-
const minification = Boolean(
|
|
9804
|
-
|
|
9805
|
-
);
|
|
9604
|
+
// const minification = Boolean(
|
|
9605
|
+
// urlInfo.context.getPluginMeta("willMinifyJsClassic"),
|
|
9606
|
+
// );
|
|
9806
9607
|
const content = generateClientCodeForMappings(mappings, {
|
|
9807
9608
|
globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
|
|
9808
|
-
minification,
|
|
9609
|
+
minification: false,
|
|
9809
9610
|
});
|
|
9810
9611
|
await prependContent(urlInfo, { type: "js_classic", content });
|
|
9811
9612
|
return;
|
|
@@ -9816,11 +9617,6 @@ const generateClientCodeForMappings = (
|
|
|
9816
9617
|
versionMappings,
|
|
9817
9618
|
{ globalName, minification },
|
|
9818
9619
|
) => {
|
|
9819
|
-
if (minification) {
|
|
9820
|
-
return `;(function(){var m = ${JSON.stringify(
|
|
9821
|
-
versionMappings,
|
|
9822
|
-
)}; ${globalName}.__v__ = function (s) { return m[s] || s }; })();`;
|
|
9823
|
-
}
|
|
9824
9620
|
return `;(function() {
|
|
9825
9621
|
var __versionMappings__ = {
|
|
9826
9622
|
${stringifyParams(versionMappings, " ")}
|
|
@@ -9837,12 +9633,7 @@ const injectImportmapMappings = (urlInfo, getMappings) => {
|
|
|
9837
9633
|
url: urlInfo.url,
|
|
9838
9634
|
storeOriginalPositions: false,
|
|
9839
9635
|
});
|
|
9840
|
-
//
|
|
9841
|
-
// it means at this point we know HTML has no importmap in it
|
|
9842
|
-
// we can safely inject one
|
|
9843
|
-
const importmapMinification = Boolean(
|
|
9844
|
-
urlInfo.context.getPluginMeta("willMinifyJson"),
|
|
9845
|
-
);
|
|
9636
|
+
// Boolean(urlInfo.context.getPluginMeta("willMinifyJson"));
|
|
9846
9637
|
const importmapNode = findHtmlNode(htmlAst, (node) => {
|
|
9847
9638
|
return (
|
|
9848
9639
|
node.tagName === "script" &&
|
|
@@ -9850,9 +9641,6 @@ const injectImportmapMappings = (urlInfo, getMappings) => {
|
|
|
9850
9641
|
);
|
|
9851
9642
|
});
|
|
9852
9643
|
const generateMappingText = (mappings) => {
|
|
9853
|
-
if (importmapMinification) {
|
|
9854
|
-
return JSON.stringify({ imports: mappings });
|
|
9855
|
-
}
|
|
9856
9644
|
return JSON.stringify({ imports: mappings }, null, " ");
|
|
9857
9645
|
};
|
|
9858
9646
|
|
|
@@ -9998,14 +9786,15 @@ const createBuildSpecifierManager = ({
|
|
|
9998
9786
|
const bundleInfoMap = new Map();
|
|
9999
9787
|
|
|
10000
9788
|
const applyBundling = async ({ bundler, urlInfosToBundle }) => {
|
|
10001
|
-
const urlInfosBundled =
|
|
10002
|
-
|
|
10003
|
-
|
|
10004
|
-
|
|
10005
|
-
|
|
10006
|
-
|
|
10007
|
-
|
|
10008
|
-
|
|
9789
|
+
const urlInfosBundled =
|
|
9790
|
+
await rawKitchen.jsenvPluginsController.callAsyncHook(
|
|
9791
|
+
{
|
|
9792
|
+
plugin: bundler.plugin,
|
|
9793
|
+
hookName: "bundle",
|
|
9794
|
+
value: bundler.bundleFunction,
|
|
9795
|
+
},
|
|
9796
|
+
urlInfosToBundle,
|
|
9797
|
+
);
|
|
10009
9798
|
for (const url of Object.keys(urlInfosBundled)) {
|
|
10010
9799
|
const urlInfoBundled = urlInfosBundled[url];
|
|
10011
9800
|
const contentSideEffects = [];
|
|
@@ -11196,9 +10985,9 @@ const isWrappedByQuote = (content, start, end) => {
|
|
|
11196
10985
|
// https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
|
|
11197
10986
|
const generateVersion = (parts, length) => {
|
|
11198
10987
|
const hash = createHash("sha256");
|
|
11199
|
-
|
|
10988
|
+
for (const part of parts) {
|
|
11200
10989
|
hash.update(part);
|
|
11201
|
-
}
|
|
10990
|
+
}
|
|
11202
10991
|
return hash.digest("hex").slice(0, length);
|
|
11203
10992
|
};
|
|
11204
10993
|
|
|
@@ -12585,7 +12374,7 @@ const prepareEntryPointBuild = async (
|
|
|
12585
12374
|
});
|
|
12586
12375
|
|
|
12587
12376
|
let _getOtherEntryBuildInfo;
|
|
12588
|
-
const
|
|
12377
|
+
const rawJsenvPluginStore = await createJsenvPluginStore([
|
|
12589
12378
|
...(mappings ? [jsenvPluginMappings(mappings)] : []),
|
|
12590
12379
|
{
|
|
12591
12380
|
name: "jsenv:other_entry_point_build_during_craft",
|
|
@@ -12631,11 +12420,11 @@ const prepareEntryPointBuild = async (
|
|
|
12631
12420
|
packageSideEffects,
|
|
12632
12421
|
}),
|
|
12633
12422
|
]);
|
|
12634
|
-
const
|
|
12635
|
-
|
|
12423
|
+
const rawJsenvPluginsController = await createJsenvPluginsController(
|
|
12424
|
+
rawJsenvPluginStore,
|
|
12636
12425
|
rawKitchen,
|
|
12637
12426
|
);
|
|
12638
|
-
rawKitchen.
|
|
12427
|
+
rawKitchen.setJsenvPluginsController(rawJsenvPluginsController);
|
|
12639
12428
|
|
|
12640
12429
|
const rawRootUrlInfo = rawKitchen.graph.rootUrlInfo;
|
|
12641
12430
|
let entryReference;
|
|
@@ -12703,7 +12492,7 @@ const prepareEntryPointBuild = async (
|
|
|
12703
12492
|
rawKitchen.graph.getUrlInfo(entryReference.url).type === "html" &&
|
|
12704
12493
|
rawKitchen.context.isSupportedOnCurrentClients("importmap"),
|
|
12705
12494
|
});
|
|
12706
|
-
const
|
|
12495
|
+
const finalJsenvPluginStore = await createJsenvPluginStore([
|
|
12707
12496
|
jsenvPluginReferenceAnalysis({
|
|
12708
12497
|
...referenceAnalysis,
|
|
12709
12498
|
fetchInlineUrls: false,
|
|
@@ -12725,7 +12514,7 @@ const prepareEntryPointBuild = async (
|
|
|
12725
12514
|
name: "jsenv:optimize",
|
|
12726
12515
|
appliesDuring: "build",
|
|
12727
12516
|
transformUrlContent: async (urlInfo) => {
|
|
12728
|
-
await rawKitchen.
|
|
12517
|
+
await rawKitchen.jsenvPluginsController.callAsyncHooks(
|
|
12729
12518
|
"optimizeBuildUrlContent",
|
|
12730
12519
|
urlInfo,
|
|
12731
12520
|
(optimizeReturnValue) => {
|
|
@@ -12736,18 +12525,18 @@ const prepareEntryPointBuild = async (
|
|
|
12736
12525
|
},
|
|
12737
12526
|
buildSpecifierManager.jsenvPluginMoveToBuildDirectory,
|
|
12738
12527
|
]);
|
|
12739
|
-
const
|
|
12740
|
-
|
|
12528
|
+
const finalJsenvPluginsController = await createJsenvPluginsController(
|
|
12529
|
+
finalJsenvPluginStore,
|
|
12741
12530
|
finalKitchen,
|
|
12742
12531
|
{
|
|
12743
|
-
|
|
12532
|
+
meta: rawKitchen.jsenvPluginsController.getMeta(),
|
|
12744
12533
|
},
|
|
12745
12534
|
);
|
|
12746
|
-
finalKitchen.
|
|
12535
|
+
finalKitchen.setJsenvPluginsController(finalJsenvPluginsController);
|
|
12747
12536
|
|
|
12748
12537
|
bundle: {
|
|
12749
12538
|
const bundlerMap = new Map();
|
|
12750
|
-
for (const plugin of rawKitchen.
|
|
12539
|
+
for (const plugin of rawKitchen.jsenvPluginsController.activePlugins) {
|
|
12751
12540
|
const bundle = plugin.bundle;
|
|
12752
12541
|
if (!bundle) {
|
|
12753
12542
|
continue;
|
|
@@ -12957,7 +12746,8 @@ const prepareEntryPointBuild = async (
|
|
|
12957
12746
|
{
|
|
12958
12747
|
const refineBuildUrlContentCallbackSet = new Set();
|
|
12959
12748
|
const refineBuildCallbackSet = new Set();
|
|
12960
|
-
for (const plugin of rawKitchen.
|
|
12749
|
+
for (const plugin of rawKitchen.jsenvPluginsController
|
|
12750
|
+
.activePlugins) {
|
|
12961
12751
|
const refineBuildUrlContent = plugin.refineBuildUrlContent;
|
|
12962
12752
|
if (refineBuildUrlContent) {
|
|
12963
12753
|
refineBuildUrlContentCallbackSet.add(refineBuildUrlContent);
|