@jsenv/core 39.14.2 → 40.0.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.
Files changed (34) hide show
  1. package/dist/js/directory_listing.js +16 -9
  2. package/dist/js/server_events_client.js +2 -2
  3. package/dist/jsenv_core.js +6974 -10642
  4. package/package.json +22 -19
  5. package/src/build/build.js +122 -93
  6. package/src/build/build_specifier_manager.js +103 -94
  7. package/src/build/build_urls_generator.js +1 -1
  8. package/src/build/{version_mappings_injection.js → mappings_injection.js} +62 -21
  9. package/src/build/start_build_server.js +46 -36
  10. package/src/dev/start_dev_server.js +246 -248
  11. package/src/helpers/watch_source_files.js +50 -36
  12. package/src/kitchen/fetched_content_compliance.js +4 -2
  13. package/src/kitchen/kitchen.js +31 -24
  14. package/src/kitchen/url_graph/references.js +10 -2
  15. package/src/kitchen/url_graph/url_graph.js +3 -0
  16. package/src/kitchen/url_graph/url_graph_visitor.js +3 -0
  17. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +29 -16
  18. package/src/plugins/html_syntax_error_fallback/jsenv_plugin_html_syntax_error_fallback.js +1 -1
  19. package/src/plugins/plugin_controller.js +194 -200
  20. package/src/plugins/plugins.js +5 -0
  21. package/src/plugins/protocol_file/client/directory_listing.jsx +5 -0
  22. package/src/plugins/protocol_file/jsenv_plugin_directory_listing.js +92 -67
  23. package/src/plugins/protocol_file/jsenv_plugin_fs_redirection.js +17 -7
  24. package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +6 -0
  25. package/src/plugins/protocol_http/jsenv_plugin_protocol_http.js +33 -3
  26. package/src/plugins/reference_analysis/html/jsenv_plugin_html_reference_analysis.js +15 -22
  27. package/src/plugins/reference_analysis/js/jsenv_plugin_js_reference_analysis.js +53 -2
  28. package/src/plugins/resolution_node_esm/jsenv_plugin_node_esm_resolution.js +37 -30
  29. package/src/plugins/resolution_node_esm/node_esm_resolver.js +4 -8
  30. package/src/plugins/resolution_web/jsenv_plugin_web_resolution.js +8 -6
  31. package/src/plugins/server_events/client/server_events_client.js +2 -2
  32. package/src/plugins/server_events/jsenv_plugin_server_events.js +18 -16
  33. package/dist/js/ws.js +0 -6863
  34. package/src/helpers/lookup_package_directory.js +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "39.14.2",
3
+ "version": "40.0.0",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -36,12 +36,13 @@
36
36
  "volta": {
37
37
  "node": "22.13.1"
38
38
  },
39
+ "packageManager": "npm@10.9.2",
39
40
  "workspaces": [
40
41
  "./packages/independent/*",
41
42
  "./packages/independent/backend/*",
42
43
  "./packages/independent/frontend/*",
43
44
  "./packages/independent/tooling/*",
44
- "./packages/independent/universal/*",
45
+ "./packages/independent/shared/*",
45
46
  "./packages/internal/*",
46
47
  "./packages/related/*",
47
48
  "./packages/related/cli/*"
@@ -64,31 +65,32 @@
64
65
  "test:ci": "CI=1 npm run test",
65
66
  "test:packages:ci": "CI=1 npm run workspace:test",
66
67
  "test:only_dev_server_errors": "node --conditions=development ./tests/dev_server/errors/dev_errors_snapshots.test.mjs",
67
- "dev": "node --conditions=development ./scripts/dev/dev.mjs",
68
+ "dev": "node --watch --conditions=development ./scripts/dev/dev.mjs",
69
+ "dev:route-inspector": "node --watch --conditions=development ./packages/independent/backend/server/tests/route_inspector/start_server.js",
68
70
  "playwright:install": "npx playwright install-deps && npx playwright install",
69
71
  "https:setup": "npx @jsenv/https-local setup",
70
72
  "prepublishOnly": "npm run build"
71
73
  },
72
74
  "dependencies": {
73
75
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
74
- "@jsenv/abort": "4.3.0",
75
- "@jsenv/ast": "6.5.2",
76
- "@jsenv/filesystem": "4.13.4",
77
- "@jsenv/humanize": "1.2.8",
76
+ "@jsenv/abort": "4.3.1",
77
+ "@jsenv/ast": "6.6.0",
78
+ "@jsenv/filesystem": "4.14.0",
79
+ "@jsenv/humanize": "1.3.0",
78
80
  "@jsenv/importmap": "1.2.1",
79
81
  "@jsenv/integrity": "0.0.2",
80
- "@jsenv/js-module-fallback": "1.3.59",
81
- "@jsenv/node-esm-resolution": "1.0.7",
82
- "@jsenv/plugin-bundling": "2.7.25",
83
- "@jsenv/plugin-minification": "1.5.13",
84
- "@jsenv/plugin-supervisor": "1.6.6",
85
- "@jsenv/plugin-transpilation": "1.4.95",
86
- "@jsenv/runtime-compat": "1.3.1",
87
- "@jsenv/server": "15.5.2",
88
- "@jsenv/sourcemap": "1.2.30",
89
- "@jsenv/url-meta": "8.5.3",
90
- "@jsenv/urls": "2.6.0",
91
- "@jsenv/utils": "2.1.2",
82
+ "@jsenv/js-module-fallback": "1.4.0",
83
+ "@jsenv/node-esm-resolution": "1.1.0",
84
+ "@jsenv/plugin-bundling": "2.8.0",
85
+ "@jsenv/plugin-minification": "1.6.0",
86
+ "@jsenv/plugin-supervisor": "1.6.7",
87
+ "@jsenv/plugin-transpilation": "1.5.0",
88
+ "@jsenv/runtime-compat": "1.3.3",
89
+ "@jsenv/server": "16.0.0",
90
+ "@jsenv/sourcemap": "1.3.0",
91
+ "@jsenv/url-meta": "8.5.4",
92
+ "@jsenv/urls": "2.6.1",
93
+ "@jsenv/utils": "2.2.0",
92
94
  "string-width": "7.2.0"
93
95
  },
94
96
  "devDependencies": {
@@ -104,6 +106,7 @@
104
106
  "@jsenv/monorepo": "workspace:*",
105
107
  "@jsenv/performance-impact": "workspace:*",
106
108
  "@jsenv/plugin-as-js-classic": "workspace:*",
109
+ "@jsenv/router": "workspace:*",
107
110
  "@jsenv/snapshot": "workspace:*",
108
111
  "@jsenv/test": "workspace:*",
109
112
  "@playwright/browser-chromium": "1.50.0",
@@ -21,6 +21,7 @@ import { parseHtml, stringifyHtmlAst } from "@jsenv/ast";
21
21
  import {
22
22
  assertAndNormalizeDirectoryUrl,
23
23
  ensureEmptyDirectory,
24
+ lookupPackageDirectory,
24
25
  writeFileSync,
25
26
  } from "@jsenv/filesystem";
26
27
  import { createLogger, createTaskLog } from "@jsenv/humanize";
@@ -28,7 +29,6 @@ import { jsenvPluginBundling } from "@jsenv/plugin-bundling";
28
29
  import { jsenvPluginMinification } from "@jsenv/plugin-minification";
29
30
  import { jsenvPluginJsModuleFallback } from "@jsenv/plugin-transpilation";
30
31
  import { urlIsInsideOf } from "@jsenv/urls";
31
- import { lookupPackageDirectory } from "../helpers/lookup_package_directory.js";
32
32
  import { watchSourceFiles } from "../helpers/watch_source_files.js";
33
33
  import { jsenvCoreDirectoryUrl } from "../jsenv_core_directory_url.js";
34
34
  import { createKitchen } from "../kitchen/kitchen.js";
@@ -36,6 +36,10 @@ import { createUrlGraphSummary } from "../kitchen/url_graph/url_graph_report.js"
36
36
  import { GRAPH_VISITOR } from "../kitchen/url_graph/url_graph_visitor.js";
37
37
  import { jsenvPluginDirectoryReferenceEffect } from "../plugins/directory_reference_effect/jsenv_plugin_directory_reference_effect.js";
38
38
  import { jsenvPluginInlining } from "../plugins/inlining/jsenv_plugin_inlining.js";
39
+ import {
40
+ createPluginController,
41
+ createPluginStore,
42
+ } from "../plugins/plugin_controller.js";
39
43
  import { getCorePlugins } from "../plugins/plugins.js";
40
44
  import { jsenvPluginReferenceAnalysis } from "../plugins/reference_analysis/jsenv_plugin_reference_analysis.js";
41
45
  import { createBuildSpecifierManager } from "./build_specifier_manager.js";
@@ -300,46 +304,52 @@ build ${entryPointKeys.length} entry points`);
300
304
  build: true,
301
305
  runtimeCompat,
302
306
  initialContext: contextSharedDuringBuild,
303
- plugins: [
304
- ...plugins,
305
- ...(bundling ? [jsenvPluginBundling(bundling)] : []),
306
- ...(minification ? [jsenvPluginMinification(minification)] : []),
307
- {
308
- appliesDuring: "build",
309
- fetchUrlContent: (urlInfo) => {
310
- if (urlInfo.firstReference.original) {
311
- rawRedirections.set(
312
- urlInfo.firstReference.original.url,
313
- urlInfo.firstReference.url,
314
- );
315
- }
316
- },
317
- },
318
- ...getCorePlugins({
319
- rootDirectoryUrl: sourceDirectoryUrl,
320
- runtimeCompat,
321
- referenceAnalysis,
322
- nodeEsmResolution,
323
- magicExtensions,
324
- magicDirectoryIndex,
325
- directoryReferenceEffect,
326
- injections,
327
- transpilation: {
328
- babelHelpersAsImport: !explicitJsModuleConversion,
329
- ...transpilation,
330
- jsModuleFallback: false,
331
- },
332
- inlining: false,
333
- http,
334
- scenarioPlaceholders,
335
- }),
336
- ],
337
307
  sourcemaps,
338
308
  sourcemapsSourcesContent,
339
309
  outDirectoryUrl: outDirectoryUrl
340
310
  ? new URL("craft/", outDirectoryUrl)
341
311
  : undefined,
342
312
  });
313
+ const rawPluginStore = createPluginStore([
314
+ ...plugins,
315
+ ...(bundling ? [jsenvPluginBundling(bundling)] : []),
316
+ ...(minification ? [jsenvPluginMinification(minification)] : []),
317
+ {
318
+ appliesDuring: "build",
319
+ fetchUrlContent: (urlInfo) => {
320
+ if (urlInfo.firstReference.original) {
321
+ rawRedirections.set(
322
+ urlInfo.firstReference.original.url,
323
+ urlInfo.firstReference.url,
324
+ );
325
+ }
326
+ },
327
+ },
328
+ ...getCorePlugins({
329
+ rootDirectoryUrl: sourceDirectoryUrl,
330
+ runtimeCompat,
331
+ referenceAnalysis,
332
+ nodeEsmResolution,
333
+ magicExtensions,
334
+ magicDirectoryIndex,
335
+ directoryReferenceEffect,
336
+ injections,
337
+ transpilation: {
338
+ babelHelpersAsImport: !explicitJsModuleConversion,
339
+ ...transpilation,
340
+ jsModuleFallback: false,
341
+ },
342
+ inlining: false,
343
+ http,
344
+ scenarioPlaceholders,
345
+ }),
346
+ ]);
347
+ const rawPluginController = createPluginController(
348
+ rawPluginStore,
349
+ rawKitchen,
350
+ );
351
+ rawKitchen.setPluginController(rawPluginController);
352
+
343
353
  craft: {
344
354
  const generateSourceGraph = createBuildTask("generate source graph");
345
355
  try {
@@ -384,37 +394,6 @@ build ${entryPointKeys.length} entry points`);
384
394
  build: true,
385
395
  runtimeCompat,
386
396
  initialContext: contextSharedDuringBuild,
387
- initialPluginsMeta: rawKitchen.pluginController.pluginsMeta,
388
- plugins: [
389
- jsenvPluginReferenceAnalysis({
390
- ...referenceAnalysis,
391
- fetchInlineUrls: false,
392
- // inlineContent: false,
393
- }),
394
- jsenvPluginDirectoryReferenceEffect(directoryReferenceEffect),
395
- ...(lineBreakNormalization
396
- ? [jsenvPluginLineBreakNormalization()]
397
- : []),
398
- jsenvPluginJsModuleFallback({
399
- remapImportSpecifier: (specifier, parentUrl) => {
400
- return buildSpecifierManager.remapPlaceholder(specifier, parentUrl);
401
- },
402
- }),
403
- jsenvPluginInlining(),
404
- {
405
- name: "jsenv:optimize",
406
- appliesDuring: "build",
407
- transformUrlContent: async (urlInfo) => {
408
- await rawKitchen.pluginController.callAsyncHooks(
409
- "optimizeUrlContent",
410
- urlInfo,
411
- (optimizeReturnValue) => {
412
- urlInfo.mutateContent(optimizeReturnValue);
413
- },
414
- );
415
- },
416
- },
417
- ],
418
397
  sourcemaps,
419
398
  sourcemapsComment: "relative",
420
399
  sourcemapsSourcesContent,
@@ -422,7 +401,6 @@ build ${entryPointKeys.length} entry points`);
422
401
  ? new URL("shape/", outDirectoryUrl)
423
402
  : undefined,
424
403
  });
425
-
426
404
  const buildSpecifierManager = createBuildSpecifierManager({
427
405
  rawKitchen,
428
406
  finalKitchen,
@@ -443,9 +421,43 @@ build ${entryPointKeys.length} entry points`);
443
421
  }) &&
444
422
  rawKitchen.context.isSupportedOnCurrentClients("importmap"),
445
423
  });
446
- finalKitchen.pluginController.pushPlugin(
424
+ const finalPluginStore = createPluginStore([
425
+ jsenvPluginReferenceAnalysis({
426
+ ...referenceAnalysis,
427
+ fetchInlineUrls: false,
428
+ // inlineContent: false,
429
+ }),
430
+ jsenvPluginDirectoryReferenceEffect(directoryReferenceEffect),
431
+ ...(lineBreakNormalization ? [jsenvPluginLineBreakNormalization()] : []),
432
+ jsenvPluginJsModuleFallback({
433
+ remapImportSpecifier: (specifier, parentUrl) => {
434
+ return buildSpecifierManager.remapPlaceholder(specifier, parentUrl);
435
+ },
436
+ }),
437
+ jsenvPluginInlining(),
438
+ {
439
+ name: "jsenv:optimize",
440
+ appliesDuring: "build",
441
+ transformUrlContent: async (urlInfo) => {
442
+ await rawKitchen.pluginController.callAsyncHooks(
443
+ "optimizeUrlContent",
444
+ urlInfo,
445
+ (optimizeReturnValue) => {
446
+ urlInfo.mutateContent(optimizeReturnValue);
447
+ },
448
+ );
449
+ },
450
+ },
447
451
  buildSpecifierManager.jsenvPluginMoveToBuildDirectory,
452
+ ]);
453
+ const finalPluginController = createPluginController(
454
+ finalPluginStore,
455
+ finalKitchen,
456
+ {
457
+ initialPuginsMeta: rawKitchen.pluginController.pluginsMeta,
458
+ },
448
459
  );
460
+ finalKitchen.setPluginController(finalPluginController);
449
461
 
450
462
  const bundlers = {};
451
463
  bundle: {
@@ -613,27 +625,16 @@ build ${entryPointKeys.length} entry points`);
613
625
 
614
626
  refine: {
615
627
  finalKitchen.context.buildStep = "refine";
628
+
629
+ const htmlRefineSet = new Set();
630
+ const registerHtmlRefine = (htmlRefine) => {
631
+ htmlRefineSet.add(htmlRefine);
632
+ };
633
+
616
634
  replace_placeholders: {
617
635
  await buildSpecifierManager.replacePlaceholders();
618
636
  }
619
- cleanup_jsenv_attributes_from_html: {
620
- GRAPH_VISITOR.forEach(finalKitchen.graph, (urlInfo) => {
621
- if (!urlInfo.url.startsWith("file:")) {
622
- return;
623
- }
624
- if (urlInfo.type === "html") {
625
- const htmlAst = parseHtml({
626
- html: urlInfo.content,
627
- url: urlInfo.url,
628
- storeOriginalPositions: false,
629
- });
630
- urlInfo.content = stringifyHtmlAst(htmlAst, {
631
- cleanupJsenvAttributes: true,
632
- cleanupPositionAttributes: true,
633
- });
634
- }
635
- });
636
- }
637
+
637
638
  /*
638
639
  * Update <link rel="preload"> and friends after build (once we know everything)
639
640
  * - Used to remove resource hint targeting an url that is no longer used:
@@ -641,14 +642,42 @@ build ${entryPointKeys.length} entry points`);
641
642
  * - because of import assertions transpilation (file is inlined into JS)
642
643
  */
643
644
  resync_resource_hints: {
644
- const resync = buildSpecifierManager.prepareResyncResourceHints();
645
- if (resync) {
646
- const resyncTask = createBuildTask("resync resource hints");
647
- resync();
648
- buildOperation.throwIfAborted();
649
- resyncTask.done();
650
- }
645
+ buildSpecifierManager.prepareResyncResourceHints({
646
+ registerHtmlRefine,
647
+ });
648
+ }
649
+
650
+ mutate_html: {
651
+ GRAPH_VISITOR.forEach(finalKitchen.graph, (urlInfo) => {
652
+ if (!urlInfo.url.startsWith("file:")) {
653
+ return;
654
+ }
655
+ if (urlInfo.type !== "html") {
656
+ return;
657
+ }
658
+ const htmlAst = parseHtml({
659
+ html: urlInfo.content,
660
+ url: urlInfo.url,
661
+ storeOriginalPositions: false,
662
+ });
663
+ for (const htmlRefine of htmlRefineSet) {
664
+ const htmlMutationCallbackSet = new Set();
665
+ const registerHtmlMutation = (callback) => {
666
+ htmlMutationCallbackSet.add(callback);
667
+ };
668
+ htmlRefine(htmlAst, { registerHtmlMutation });
669
+ for (const htmlMutationCallback of htmlMutationCallbackSet) {
670
+ htmlMutationCallback();
671
+ }
672
+ }
673
+ // cleanup jsenv attributes from html as a last step
674
+ urlInfo.content = stringifyHtmlAst(htmlAst, {
675
+ cleanupJsenvAttributes: true,
676
+ cleanupPositionAttributes: true,
677
+ });
678
+ });
651
679
  }
680
+
652
681
  inject_urls_in_service_workers: {
653
682
  const inject = buildSpecifierManager.prepareServiceWorkerUrlInjection();
654
683
  if (inject) {