@jsenv/core 29.4.5 → 29.6.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/dist/main.js CHANGED
@@ -7574,8 +7574,9 @@ const stringifyHtmlAst = (htmlAst, {
7574
7574
  "original-href-position": undefined,
7575
7575
  "inlined-from-src": undefined,
7576
7576
  "inlined-from-href": undefined,
7577
- "jsenv-plugin-owner": undefined,
7578
- "jsenv-plugin-action": undefined,
7577
+ "jsenv-cooked-by": undefined,
7578
+ "jsenv-inlined-by": undefined,
7579
+ "jsenv-injected-by": undefined,
7579
7580
  "jsenv-debug": undefined
7580
7581
  });
7581
7582
  }
@@ -7693,17 +7694,15 @@ const createHtmlNode = ({
7693
7694
  };
7694
7695
  const injectHtmlNode = (htmlAst, node, jsenvPluginName = "jsenv") => {
7695
7696
  setHtmlNodeAttributes(node, {
7696
- "jsenv-plugin-owner": jsenvPluginName,
7697
- "jsenv-plugin-action": "injected"
7697
+ "jsenv-injected-by": jsenvPluginName
7698
7698
  });
7699
7699
  const htmlHtmlNode = findChild(htmlAst, node => node.nodeName === "html");
7700
7700
  const bodyNode = findChild(htmlHtmlNode, node => node.nodeName === "body");
7701
- return insertAfter(node, bodyNode);
7701
+ return insertHtmlNodeAfter(node, bodyNode);
7702
7702
  };
7703
7703
  const injectScriptNodeAsEarlyAsPossible = (htmlAst, scriptNode, jsenvPluginName = "jsenv") => {
7704
7704
  setHtmlNodeAttributes(scriptNode, {
7705
- "jsenv-plugin-owner": jsenvPluginName,
7706
- "jsenv-plugin-action": "injected"
7705
+ "jsenv-injected-by": jsenvPluginName
7707
7706
  });
7708
7707
  const isJsModule = analyzeScriptNode(scriptNode).type === "js_module";
7709
7708
  if (isJsModule) {
@@ -7717,35 +7716,35 @@ const injectScriptNodeAsEarlyAsPossible = (htmlAst, scriptNode, jsenvPluginName
7717
7716
  let after = firstImportmapScript;
7718
7717
  for (const nextSibling of nextSiblings) {
7719
7718
  if (nextSibling.nodeName === "script") {
7720
- return insertBefore(scriptNode, importmapParent, nextSibling);
7719
+ return insertHtmlNodeBefore(scriptNode, importmapParent, nextSibling);
7721
7720
  }
7722
7721
  if (nextSibling.nodeName === "link") {
7723
7722
  after = nextSibling;
7724
7723
  }
7725
7724
  }
7726
- return insertAfter(scriptNode, importmapParent, after);
7725
+ return insertHtmlNodeAfter(scriptNode, importmapParent, after);
7727
7726
  }
7728
7727
  }
7729
7728
  const headNode = findChild(htmlAst, node => node.nodeName === "html").childNodes[0];
7730
7729
  let after = headNode.childNodes[0];
7731
7730
  for (const child of headNode.childNodes) {
7732
7731
  if (child.nodeName === "script") {
7733
- return insertBefore(scriptNode, headNode, child);
7732
+ return insertHtmlNodeBefore(scriptNode, headNode, child);
7734
7733
  }
7735
7734
  if (child.nodeName === "link") {
7736
7735
  after = child;
7737
7736
  }
7738
7737
  }
7739
- return insertAfter(scriptNode, headNode, after);
7738
+ return insertHtmlNodeAfter(scriptNode, headNode, after);
7740
7739
  };
7741
- const insertBefore = (nodeToInsert, futureParentNode, futureNextSibling) => {
7740
+ const insertHtmlNodeBefore = (nodeToInsert, futureParentNode, futureNextSibling) => {
7742
7741
  const {
7743
7742
  childNodes = []
7744
7743
  } = futureParentNode;
7745
7744
  const futureIndex = futureNextSibling ? childNodes.indexOf(futureNextSibling) : 0;
7746
7745
  injectWithWhitespaces(nodeToInsert, futureParentNode, futureIndex);
7747
7746
  };
7748
- const insertAfter = (nodeToInsert, futureParentNode, futurePrevSibling) => {
7747
+ const insertHtmlNodeAfter = (nodeToInsert, futureParentNode, futurePrevSibling) => {
7749
7748
  const {
7750
7749
  childNodes = []
7751
7750
  } = futureParentNode;
@@ -7788,7 +7787,14 @@ const findChild = ({
7788
7787
  childNodes = []
7789
7788
  }, predicate) => childNodes.find(predicate);
7790
7789
  const stringifyAttributes = object => {
7791
- return Object.keys(object).map(key => `${key}=${valueToHtmlAttributeValue(object[key])}`).join(" ");
7790
+ let string = "";
7791
+ Object.keys(object).forEach(key => {
7792
+ const value = object[key];
7793
+ if (value === undefined) return;
7794
+ if (string !== "") string += " ";
7795
+ string += `${key}=${valueToHtmlAttributeValue(value)}`;
7796
+ });
7797
+ return string;
7792
7798
  };
7793
7799
  const valueToHtmlAttributeValue = value => {
7794
7800
  if (typeof value === "string") {
@@ -8579,8 +8585,18 @@ const analyzeUrlNodeType = (secondArgNode, {
8579
8585
  if (!isJsModule && isContextMetaUrlFromSystemJs(secondArgNode)) {
8580
8586
  return "context.meta.url";
8581
8587
  }
8582
- if (!isJsModule && isDocumentCurrentScriptSrc(secondArgNode)) {
8583
- return "document.currentScript.src";
8588
+ if (!isJsModule) {
8589
+ if (isDocumentCurrentScriptSrc(secondArgNode)) {
8590
+ return "document.currentScript.src";
8591
+ }
8592
+ // new URL('specifier', document.currentScript.src)
8593
+ // becomes
8594
+ // var _currentUrl = document.currentScript.src
8595
+ // new URL('specifier', currentUrl)
8596
+ // (search for scope.generateUidIdentifier("currentUrl")
8597
+ if (secondArgNode.type === "Identifier") {
8598
+ return "document.currentScript.src";
8599
+ }
8584
8600
  }
8585
8601
  return null;
8586
8602
  };
@@ -11666,8 +11682,8 @@ const visitHtmlUrls = ({
11666
11682
  }) => {
11667
11683
  const value = getHtmlNodeAttribute(node, attributeName);
11668
11684
  if (value) {
11669
- const jsenvPluginOwner = getHtmlNodeAttribute(node, "jsenv-plugin-owner");
11670
- if (jsenvPluginOwner === "jsenv:importmap") {
11685
+ const jsenvInlinedBy = getHtmlNodeAttribute(node, "jsenv-inlined-by");
11686
+ if (jsenvInlinedBy === "jsenv:importmap") {
11671
11687
  // during build the importmap is inlined
11672
11688
  // and shoud not be considered as a dependency anymore
11673
11689
  return null;
@@ -12117,8 +12133,7 @@ const jsenvPluginHtmlInlineContent = ({
12117
12133
  mutations.push(() => {
12118
12134
  setHtmlNodeText(styleNode, inlineStyleUrlInfo.content);
12119
12135
  setHtmlNodeAttributes(styleNode, {
12120
- "jsenv-plugin-owner": "jsenv:html_inline_content",
12121
- "jsenv-plugin-action": "content_cooked"
12136
+ "jsenv-cooked-by": "jsenv:html_inline_content"
12122
12137
  });
12123
12138
  });
12124
12139
  },
@@ -12130,11 +12145,10 @@ const jsenvPluginHtmlInlineContent = ({
12130
12145
  // If the inline script was already handled by an other plugin, ignore it
12131
12146
  // - we want to preserve inline scripts generated by html supervisor during dev
12132
12147
  // - we want to avoid cooking twice a script during build
12133
- const jsenvPluginOwner = getHtmlNodeAttribute(scriptNode, "jsenv-plugin-owner");
12134
- if (jsenvPluginOwner === "jsenv:as_js_classic_html" && !analyzeConvertedScripts) {
12148
+ if (!analyzeConvertedScripts && getHtmlNodeAttribute(scriptNode, "jsenv-injected-by") === "jsenv:as_js_classic_html") {
12135
12149
  return;
12136
12150
  }
12137
- if (jsenvPluginOwner === "jsenv:supervisor") {
12151
+ if (getHtmlNodeAttribute(scriptNode, "jsenv-cooked-by") === "jsenv:supervisor" || getHtmlNodeAttribute(scriptNode, "jsenv-injected-by") === "jsenv:supervisor") {
12138
12152
  return;
12139
12153
  }
12140
12154
  const {
@@ -12183,8 +12197,7 @@ const jsenvPluginHtmlInlineContent = ({
12183
12197
  mutations.push(() => {
12184
12198
  setHtmlNodeText(scriptNode, inlineScriptUrlInfo.content);
12185
12199
  setHtmlNodeAttributes(scriptNode, {
12186
- "jsenv-plugin-owner": "jsenv:html_inline_content",
12187
- "jsenv-plugin-action": "content_cooked",
12200
+ "jsenv-cooked-by": "jsenv:html_inline_content",
12188
12201
  ...(extension ? {
12189
12202
  type: type === "js_module" ? "module" : undefined
12190
12203
  } : {})
@@ -16494,7 +16507,8 @@ const jsenvPluginAsJsClassicConversion = ({
16494
16507
  type: "js_classic",
16495
16508
  originalUrl: jsModuleUrlInfo.originalUrl,
16496
16509
  originalContent: jsModuleUrlInfo.originalContent,
16497
- sourcemap
16510
+ sourcemap,
16511
+ data: jsModuleUrlInfo.data
16498
16512
  };
16499
16513
  }
16500
16514
  };
@@ -16812,6 +16826,7 @@ const bundleJsModules = async ({
16812
16826
  logger,
16813
16827
  rootDirectoryUrl,
16814
16828
  buildDirectoryUrl,
16829
+ assetsDirectory,
16815
16830
  urlGraph,
16816
16831
  runtimeCompat,
16817
16832
  sourcemaps
@@ -16829,6 +16844,7 @@ const bundleJsModules = async ({
16829
16844
  logger,
16830
16845
  rootDirectoryUrl,
16831
16846
  buildDirectoryUrl,
16847
+ assetsDirectory,
16832
16848
  urlGraph,
16833
16849
  jsModuleUrlInfos,
16834
16850
  runtimeCompat,
@@ -16844,6 +16860,7 @@ const rollupPluginJsenv = ({
16844
16860
  // logger,
16845
16861
  rootDirectoryUrl,
16846
16862
  buildDirectoryUrl,
16863
+ assetsDirectory,
16847
16864
  urlGraph,
16848
16865
  jsModuleUrlInfos,
16849
16866
  sourcemaps,
@@ -16923,7 +16940,7 @@ const rollupPluginJsenv = ({
16923
16940
  originalUrl,
16924
16941
  type: format === "esm" ? "js_module" : "common_js",
16925
16942
  data: {
16926
- generatedBy: "rollup",
16943
+ bundlerName: "rollup",
16927
16944
  bundleRelativeUrl: rollupFileInfo.fileName,
16928
16945
  usesImport: rollupFileInfo.imports.length > 0 || rollupFileInfo.dynamicImports.length > 0,
16929
16946
  isDynamicEntry: rollupFileInfo.isDynamicEntry
@@ -16968,7 +16985,7 @@ const rollupPluginJsenv = ({
16968
16985
  }
16969
16986
  }
16970
16987
  const name = nameFromUrlInfo || `${chunkInfo.name}.js`;
16971
- return insideJs ? `js/${name}` : `${name}`;
16988
+ return insideJs ? `${assetsDirectory}js/${name}` : `${name}`;
16972
16989
  },
16973
16990
  manualChunks: id => {
16974
16991
  if (babelHelpersChunk) {
@@ -17076,6 +17093,7 @@ const buildWithRollup = async ({
17076
17093
  logger,
17077
17094
  rootDirectoryUrl,
17078
17095
  buildDirectoryUrl,
17096
+ assetsDirectory,
17079
17097
  urlGraph,
17080
17098
  jsModuleUrlInfos,
17081
17099
  runtimeCompat,
@@ -17094,6 +17112,7 @@ const buildWithRollup = async ({
17094
17112
  logger,
17095
17113
  rootDirectoryUrl,
17096
17114
  buildDirectoryUrl,
17115
+ assetsDirectory,
17097
17116
  urlGraph,
17098
17117
  jsModuleUrlInfos,
17099
17118
  runtimeCompat,
@@ -17263,7 +17282,8 @@ const jsenvPluginAsJsClassicLibrary = ({
17263
17282
  type: "js_classic",
17264
17283
  originalUrl: urlInfo.originalUrl,
17265
17284
  originalContent: jsModuleUrlInfo.originalContent,
17266
- sourcemap
17285
+ sourcemap,
17286
+ data: jsModuleUrlInfo.data
17267
17287
  };
17268
17288
  }
17269
17289
  };
@@ -18030,8 +18050,7 @@ const jsenvPluginImportmap = () => {
18030
18050
  });
18031
18051
  setHtmlNodeText(importmap, inlineImportmapUrlInfo.content);
18032
18052
  setHtmlNodeAttributes(importmap, {
18033
- "jsenv-plugin-owner": "jsenv:importmap",
18034
- "jsenv-plugin-action": "content_cooked"
18053
+ "jsenv-cooked-by": "jsenv:importmap"
18035
18054
  });
18036
18055
  onHtmlImportmapParsed(JSON.parse(inlineImportmapUrlInfo.content), htmlUrlInfo.url);
18037
18056
  };
@@ -18050,8 +18069,7 @@ const jsenvPluginImportmap = () => {
18050
18069
  setHtmlNodeText(importmap, importmapUrlInfo.content);
18051
18070
  setHtmlNodeAttributes(importmap, {
18052
18071
  "src": undefined,
18053
- "jsenv-plugin-owner": "jsenv:importmap",
18054
- "jsenv-plugin-action": "inlined",
18072
+ "jsenv-inlined-by": "jsenv:importmap",
18055
18073
  "inlined-from-src": src
18056
18074
  });
18057
18075
  const {
@@ -19725,10 +19743,7 @@ const jsenvPluginSupervisor = ({
19725
19743
  if (type !== "js_classic" && type !== "js_module") {
19726
19744
  return;
19727
19745
  }
19728
- const jsenvPluginOwner = getHtmlNodeAttribute(node, "jsenv-plugin-owner");
19729
- if (jsenvPluginOwner !== undefined) {
19730
- return;
19731
- }
19746
+ if (getHtmlNodeAttribute(node, "jsenv-cooked-by") || getHtmlNodeAttribute(node, "jsenv-inlined-by") || getHtmlNodeAttribute(node, "jsenv-injected-by")) return;
19732
19747
  const noSupervisor = getHtmlNodeAttribute(node, "no-supervisor");
19733
19748
  if (noSupervisor !== undefined) {
19734
19749
  return;
@@ -19802,15 +19817,13 @@ const jsenvPluginSupervisor = ({
19802
19817
  }
19803
19818
  if (src) {
19804
19819
  setHtmlNodeAttributes(node, {
19805
- "jsenv-plugin-owner": "jsenv:supervisor",
19806
- "jsenv-plugin-action": "inlined",
19820
+ "jsenv-inlined-by": "jsenv:supervisor",
19807
19821
  "src": undefined,
19808
19822
  "inlined-from-src": src
19809
19823
  });
19810
19824
  } else {
19811
19825
  setHtmlNodeAttributes(node, {
19812
- "jsenv-plugin-owner": "jsenv:supervisor",
19813
- "jsenv-plugin-action": "content_cooked"
19826
+ "jsenv-cooked-by": "jsenv:supervisor"
19814
19827
  });
19815
19828
  }
19816
19829
  });
@@ -20229,7 +20242,8 @@ const jsenvPluginAsModules = () => {
20229
20242
  contentType: "text/javascript",
20230
20243
  type: "js_module",
20231
20244
  originalUrl: jsonUrlInfo.originalUrl,
20232
- originalContent: jsonUrlInfo.originalContent
20245
+ originalContent: jsonUrlInfo.originalContent,
20246
+ data: jsonUrlInfo.data
20233
20247
  };
20234
20248
  }
20235
20249
  };
@@ -20275,7 +20289,8 @@ const jsenvPluginAsModules = () => {
20275
20289
  contentType: "text/javascript",
20276
20290
  type: "js_module",
20277
20291
  originalUrl: cssUrlInfo.originalUrl,
20278
- originalContent: cssUrlInfo.originalContent
20292
+ originalContent: cssUrlInfo.originalContent,
20293
+ data: cssUrlInfo.data
20279
20294
  };
20280
20295
  }
20281
20296
  };
@@ -20319,7 +20334,8 @@ export default inlineContent.text`,
20319
20334
  contentType: "text/javascript",
20320
20335
  type: "js_module",
20321
20336
  originalUrl: textUrlInfo.originalUrl,
20322
- originalContent: textUrlInfo.originalContent
20337
+ originalContent: textUrlInfo.originalContent,
20338
+ data: textUrlInfo.data
20323
20339
  };
20324
20340
  }
20325
20341
  };
@@ -21411,7 +21427,7 @@ const bundleCss = async ({
21411
21427
  cssUrlInfos.forEach(cssUrlInfo => {
21412
21428
  bundledCssUrlInfos[cssUrlInfo.url] = {
21413
21429
  data: {
21414
- generatedBy: "parcel"
21430
+ bundlerName: "parcel"
21415
21431
  },
21416
21432
  contentType: "text/css",
21417
21433
  content: cssBundleInfos[cssUrlInfo.url].bundleContent
@@ -22444,8 +22460,7 @@ const jsenvPluginExplorer = ({
22444
22460
 
22445
22461
  const jsenvPluginRibbon = ({
22446
22462
  rootDirectoryUrl,
22447
- htmlInclude = "**/*.html",
22448
- devAndBuild = false
22463
+ htmlInclude = "**/*.html"
22449
22464
  }) => {
22450
22465
  const ribbonClientFileUrl = new URL("./js/ribbon.js", import.meta.url);
22451
22466
  const associations = URL_META.resolveAssociations({
@@ -22455,12 +22470,9 @@ const jsenvPluginRibbon = ({
22455
22470
  }, rootDirectoryUrl);
22456
22471
  return {
22457
22472
  name: "jsenv:ribbon",
22458
- appliesDuring: "*",
22473
+ appliesDuring: "dev",
22459
22474
  transformUrlContent: {
22460
22475
  html: (urlInfo, context) => {
22461
- if (context.scenarios.build && !devAndBuild) {
22462
- return null;
22463
- }
22464
22476
  const {
22465
22477
  ribbon
22466
22478
  } = URL_META.applyAssociations({
@@ -22511,7 +22523,7 @@ const getCorePlugins = ({
22511
22523
  clientFileChangeCallbackList,
22512
22524
  clientFilesPruneCallbackList,
22513
22525
  explorer,
22514
- ribbon = false
22526
+ ribbon = true
22515
22527
  } = {}) => {
22516
22528
  if (explorer === true) {
22517
22529
  explorer = {};
@@ -22533,11 +22545,6 @@ const getCorePlugins = ({
22533
22545
  if (ribbon === true) {
22534
22546
  ribbon = {};
22535
22547
  }
22536
- if (ribbon === "dev_and_build") {
22537
- ribbon = {
22538
- devAndBuild: true
22539
- };
22540
- }
22541
22548
  return [jsenvPluginUrlAnalysis({
22542
22549
  rootDirectoryUrl,
22543
22550
  ...urlAnalysis
@@ -22619,8 +22626,9 @@ const memoizeByFirstArgument = compute => {
22619
22626
  return fnWithMemoization;
22620
22627
  };
22621
22628
 
22622
- const createBuilUrlsGenerator = ({
22623
- buildDirectoryUrl
22629
+ const createBuildUrlsGenerator = ({
22630
+ buildDirectoryUrl,
22631
+ assetsDirectory
22624
22632
  }) => {
22625
22633
  const cache = {};
22626
22634
  const getUrlName = (url, urlInfo) => {
@@ -22638,6 +22646,7 @@ const createBuilUrlsGenerator = ({
22638
22646
  }) => {
22639
22647
  const directoryPath = determineDirectoryPath({
22640
22648
  buildDirectoryUrl,
22649
+ assetsDirectory,
22641
22650
  urlInfo,
22642
22651
  parentUrlInfo
22643
22652
  });
@@ -22692,6 +22701,7 @@ const splitFileExtension = filename => {
22692
22701
  };
22693
22702
  const determineDirectoryPath = ({
22694
22703
  buildDirectoryUrl,
22704
+ assetsDirectory,
22695
22705
  urlInfo,
22696
22706
  parentUrlInfo
22697
22707
  }) => {
@@ -22705,6 +22715,7 @@ const determineDirectoryPath = ({
22705
22715
  if (urlInfo.isInline) {
22706
22716
  const parentDirectoryPath = determineDirectoryPath({
22707
22717
  buildDirectoryUrl,
22718
+ assetsDirectory,
22708
22719
  urlInfo: parentUrlInfo
22709
22720
  });
22710
22721
  return parentDirectoryPath;
@@ -22716,25 +22727,26 @@ const determineDirectoryPath = ({
22716
22727
  return "";
22717
22728
  }
22718
22729
  if (urlInfo.type === "html") {
22719
- return "html/";
22730
+ return `${assetsDirectory}html/`;
22720
22731
  }
22721
22732
  if (urlInfo.type === "css") {
22722
- return "css/";
22733
+ return `${assetsDirectory}css/`;
22723
22734
  }
22724
22735
  if (urlInfo.type === "js_module" || urlInfo.type === "js_classic") {
22725
- return "js/";
22736
+ return `${assetsDirectory}js/`;
22726
22737
  }
22727
22738
  if (urlInfo.type === "json") {
22728
- return "json/";
22739
+ return `${assetsDirectory}json/`;
22729
22740
  }
22730
- return "other/";
22741
+ return `${assetsDirectory}other/`;
22731
22742
  };
22732
22743
 
22733
22744
  // https://bundlers.tooling.report/hashing/avoid-cascade/
22734
22745
  const injectVersionMappings = async ({
22735
22746
  urlInfo,
22736
22747
  kitchen,
22737
- versionMappings
22748
+ versionMappings,
22749
+ minification
22738
22750
  }) => {
22739
22751
  const injector = injectors[urlInfo.type];
22740
22752
  if (injector) {
@@ -22742,7 +22754,8 @@ const injectVersionMappings = async ({
22742
22754
  content,
22743
22755
  sourcemap
22744
22756
  } = await injector(urlInfo, {
22745
- versionMappings
22757
+ versionMappings,
22758
+ minification
22746
22759
  });
22747
22760
  kitchen.urlInfoTransformer.applyFinalTransformations(urlInfo, {
22748
22761
  content,
@@ -22750,18 +22763,10 @@ const injectVersionMappings = async ({
22750
22763
  });
22751
22764
  }
22752
22765
  };
22753
- const jsInjector = (urlInfo, {
22754
- versionMappings
22755
- }) => {
22756
- const magicSource = createMagicSource(urlInfo.content);
22757
- magicSource.prepend(generateClientCodeForVersionMappings(versionMappings, {
22758
- globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window"
22759
- }));
22760
- return magicSource.toContentAndSourcemap();
22761
- };
22762
22766
  const injectors = {
22763
22767
  html: (urlInfo, {
22764
- versionMappings
22768
+ versionMappings,
22769
+ minification
22765
22770
  }) => {
22766
22771
  // ideally we would inject an importmap but browser support is too low
22767
22772
  // (even worse for worker/service worker)
@@ -22772,19 +22777,51 @@ const injectors = {
22772
22777
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
22773
22778
  tagName: "script",
22774
22779
  textContent: generateClientCodeForVersionMappings(versionMappings, {
22775
- globalName: "window"
22780
+ globalName: "window",
22781
+ minify: minification || minification.js_classic
22776
22782
  })
22777
22783
  }), "jsenv:versioning");
22778
22784
  return {
22779
22785
  content: stringifyHtmlAst(htmlAst)
22780
22786
  };
22781
22787
  },
22782
- js_classic: jsInjector,
22783
- js_module: jsInjector
22788
+ js_classic: (urlInfo, {
22789
+ versionMappings,
22790
+ minification
22791
+ }) => {
22792
+ return jsInjector(urlInfo, {
22793
+ versionMappings,
22794
+ minify: minification || minification.js_classic
22795
+ });
22796
+ },
22797
+ js_module: (urlInfo, {
22798
+ versionMappings,
22799
+ minification
22800
+ }) => {
22801
+ return jsInjector(urlInfo, {
22802
+ versionMappings,
22803
+ minify: minification || minification.js_module
22804
+ });
22805
+ }
22806
+ };
22807
+ const jsInjector = (urlInfo, {
22808
+ versionMappings,
22809
+ minify
22810
+ }) => {
22811
+ const magicSource = createMagicSource(urlInfo.content);
22812
+ magicSource.prepend(generateClientCodeForVersionMappings(versionMappings, {
22813
+ globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
22814
+ minify
22815
+ }));
22816
+ return magicSource.toContentAndSourcemap();
22784
22817
  };
22785
22818
  const generateClientCodeForVersionMappings = (versionMappings, {
22786
- globalName
22819
+ globalName,
22820
+ minify
22787
22821
  }) => {
22822
+ if (minify) {
22823
+ return `;(function(){var m = ${JSON.stringify(versionMappings)}; ${globalName}.__v__ = function (s) { return m[s] || s }; })();`;
22824
+ }
22788
22825
  return `
22789
22826
  ;(function() {
22790
22827
 
@@ -22886,8 +22923,10 @@ const defaultRuntimeCompat = {
22886
22923
  * Describe entry point paths and control their names in the build directory
22887
22924
  * @param {object} buildParameters.runtimeCompat
22888
22925
  * Code generated will be compatible with these runtimes
22889
- * @param {string="/"} buildParameters.baseUrl
22890
- * All urls in build file contents are prefixed with this url
22926
+ * @param {string} [buildParameters.assetsDirectory=""]
22927
+ * Directory where asset files will be written
22928
+ * @param {string|url} [buildParameters.base=""]
22929
+ * Urls in build file contents will be prefixed with this string
22891
22930
  * @param {boolean|object} [buildParameters.minification=true]
22892
22931
  * Minify build file contents
22893
22932
  * @param {boolean} [buildParameters.versioning=true]
@@ -22908,11 +22947,12 @@ const build = async ({
22908
22947
  signal = new AbortController().signal,
22909
22948
  handleSIGINT = true,
22910
22949
  logLevel = "info",
22950
+ runtimeCompat = defaultRuntimeCompat,
22911
22951
  rootDirectoryUrl,
22912
22952
  buildDirectoryUrl,
22953
+ assetsDirectory = "",
22954
+ base = runtimeCompat.node ? "./" : "/",
22913
22955
  entryPoints = {},
22914
- baseUrl = "/",
22915
- runtimeCompat = defaultRuntimeCompat,
22916
22956
  plugins = [],
22917
22957
  sourcemaps = false,
22918
22958
  sourcemapsSourcesContent,
@@ -22922,21 +22962,20 @@ const build = async ({
22922
22962
  directoryReferenceAllowed,
22923
22963
  transpilation = {},
22924
22964
  bundling = true,
22925
- minification = true,
22926
- versioning = true,
22965
+ minification = !runtimeCompat.node,
22966
+ versioning = !runtimeCompat.node,
22927
22967
  versioningMethod = "search_param",
22928
22968
  // "filename", "search_param"
22929
22969
  lineBreakNormalization = process.platform === "win32",
22930
- ribbon,
22931
22970
  clientFiles = {
22932
22971
  "./src/": true
22933
22972
  },
22934
22973
  cooldownBetweenFileEvents,
22935
22974
  watch = false,
22936
- buildDirectoryClean = true,
22975
+ directoryToClean,
22937
22976
  writeOnFileSystem = true,
22938
22977
  writeGeneratedFiles = false,
22939
- assetManifest = true,
22978
+ assetManifest = versioningMethod === "filename",
22940
22979
  assetManifestFileRelativeUrl = "asset-manifest.json"
22941
22980
  }) => {
22942
22981
  const operation = Abort.startOperation();
@@ -22956,6 +22995,28 @@ const build = async ({
22956
22995
  if (!["filename", "search_param"].includes(versioningMethod)) {
22957
22996
  throw new Error(`Unexpected "versioningMethod": must be "filename", "search_param"; got ${versioning}`);
22958
22997
  }
22998
+ if (assetsDirectory && assetsDirectory[assetsDirectory.length - 1] !== "/") {
22999
+ assetsDirectory = `${assetsDirectory}/`;
23000
+ }
23001
+ if (directoryToClean === undefined) {
23002
+ if (assetsDirectory === undefined) {
23003
+ directoryToClean = buildDirectoryUrl;
23004
+ } else {
23005
+ directoryToClean = new URL(assetsDirectory, buildDirectoryUrl).href;
23006
+ }
23007
+ }
23008
+ const asFormattedBuildUrl = (generatedUrl, reference) => {
23009
+ if (base === "./") {
23010
+ const urlRelativeToParent = urlToRelativeUrl(generatedUrl, reference.parentUrl === rootDirectoryUrl ? buildDirectoryUrl : reference.parentUrl);
23011
+ if (urlRelativeToParent[0] !== ".") {
23012
+ // ensure "./" on relative url (otherwise it could be a "bare specifier")
23013
+ return `./${urlRelativeToParent}`;
23014
+ }
23015
+ return urlRelativeToParent;
23016
+ }
23017
+ const urlRelativeToBuildDirectory = urlToRelativeUrl(generatedUrl, buildDirectoryUrl);
23018
+ return `${base}${urlRelativeToBuildDirectory}`;
23019
+ };
22959
23020
  const runBuild = async ({
22960
23021
  signal,
22961
23022
  logLevel
@@ -23017,16 +23078,16 @@ build ${entryPointKeys.length} entry points`);
23017
23078
  jsClassicFallback: false
23018
23079
  },
23019
23080
  minification,
23020
- bundling,
23021
- ribbon
23081
+ bundling
23022
23082
  })],
23023
23083
  sourcemaps,
23024
23084
  sourcemapsSourcesContent,
23025
23085
  writeGeneratedFiles,
23026
23086
  outDirectoryUrl: new URL(`.jsenv/build/`, rootDirectoryUrl)
23027
23087
  });
23028
- const buildUrlsGenerator = createBuilUrlsGenerator({
23029
- buildDirectoryUrl
23088
+ const buildUrlsGenerator = createBuildUrlsGenerator({
23089
+ buildDirectoryUrl,
23090
+ assetsDirectory
23030
23091
  });
23031
23092
  const buildDirectoryRedirections = new Map();
23032
23093
  const associateBuildUrlAndRawUrl = (buildUrl, rawUrl, reason) => {
@@ -23068,8 +23129,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23068
23129
  const getUrl = () => {
23069
23130
  if (reference.type === "filesystem") {
23070
23131
  const parentRawUrl = buildDirectoryRedirections.get(reference.parentUrl);
23071
- const baseUrl = ensurePathnameTrailingSlash(parentRawUrl);
23072
- return new URL(reference.specifier, baseUrl).href;
23132
+ const parentUrl = ensurePathnameTrailingSlash(parentRawUrl);
23133
+ return new URL(reference.specifier, parentUrl).href;
23073
23134
  }
23074
23135
  if (reference.specifier[0] === "/") {
23075
23136
  return new URL(reference.specifier.slice(1), buildDirectoryUrl).href;
@@ -23220,16 +23281,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23220
23281
  generatedUrlObject.searchParams.delete("as_text_module");
23221
23282
  generatedUrlObject.hash = "";
23222
23283
  const generatedUrl = generatedUrlObject.href;
23223
- let specifier;
23224
- if (baseUrl === "./") {
23225
- const relativeUrl = urlToRelativeUrl(generatedUrl, reference.parentUrl === rootDirectoryUrl ? buildDirectoryUrl : reference.parentUrl);
23226
- // ensure "./" on relative url (otherwise it could be a "bare specifier")
23227
- specifier = relativeUrl[0] === "." ? relativeUrl : `./${relativeUrl}`;
23228
- } else {
23229
- // if a file is in the same directory we could prefer the relative notation
23230
- // but to keep things simple let's keep the "absolutely relative" to baseUrl for now
23231
- specifier = `${baseUrl}${urlToRelativeUrl(generatedUrl, buildDirectoryUrl)}`;
23232
- }
23284
+ const specifier = asFormattedBuildUrl(generatedUrl, reference);
23233
23285
  buildUrls.set(specifier, reference.generatedUrl);
23234
23286
  return specifier;
23235
23287
  },
@@ -23326,6 +23378,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23326
23378
  });
23327
23379
  entryUrls.push(entryUrlInfo.url);
23328
23380
  entryUrlInfo.filename = entryPoints[key];
23381
+ entryUrlInfo.isEntryPoint = true;
23329
23382
  rawUrlGraphLoader.load(entryUrlInfo, {
23330
23383
  reference: entryReference
23331
23384
  });
@@ -23457,7 +23510,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23457
23510
  value: bundler.bundleFunction
23458
23511
  }, urlInfosToBundle, {
23459
23512
  ...rawGraphKitchen.kitchenContext,
23460
- buildDirectoryUrl
23513
+ buildDirectoryUrl,
23514
+ assetsDirectory
23461
23515
  });
23462
23516
  Object.keys(bundlerGeneratedUrlInfos).forEach(url => {
23463
23517
  const rawUrlInfo = rawGraph.getUrlInfo(url);
@@ -23495,7 +23549,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23495
23549
  bundleRedirections.set(bundlerGeneratedUrlInfo.originalUrl, buildUrl);
23496
23550
  associateBuildUrlAndRawUrl(buildUrl, bundlerGeneratedUrlInfo.originalUrl, "bundle");
23497
23551
  } else {
23498
- // chunk generated by rollup to share code
23552
+ bundleUrlInfo.data.generatedToShareCode = true;
23499
23553
  }
23500
23554
  } else {
23501
23555
  associateBuildUrlAndRawUrl(buildUrl, url, "bundle");
@@ -23730,9 +23784,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23730
23784
  const versionedUrl = versionedUrlMap.get(reference.url);
23731
23785
  if (!versionedUrl) {
23732
23786
  // happens for sourcemap
23733
- return `${baseUrl}${urlToRelativeUrl(referencedUrlInfo.url, buildDirectoryUrl)}`;
23787
+ return urlToRelativeUrl(referencedUrlInfo.url, reference.parentUrl);
23734
23788
  }
23735
- const versionedSpecifier = `${baseUrl}${urlToRelativeUrl(versionedUrl, buildDirectoryUrl)}`;
23789
+ const versionedSpecifier = asFormattedBuildUrl(versionedUrl, reference);
23736
23790
  versionMappings[reference.specifier] = versionedSpecifier;
23737
23791
  versioningRedirections.set(reference.url, versionedUrl);
23738
23792
  buildUrls.set(versionedSpecifier, versionedUrl);
@@ -23795,7 +23849,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23795
23849
  await injectVersionMappings({
23796
23850
  urlInfo,
23797
23851
  kitchen: finalGraphKitchen,
23798
- versionMappings: versionMappingsNeeded
23852
+ versionMappings: versionMappingsNeeded,
23853
+ minification
23799
23854
  });
23800
23855
  });
23801
23856
  }
@@ -23843,6 +23898,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23843
23898
  storeOriginalPositions: false
23844
23899
  });
23845
23900
  const mutations = [];
23901
+ const hintsToInject = {};
23846
23902
  visitHtmlNodes(htmlAst, {
23847
23903
  link: node => {
23848
23904
  const href = getHtmlNodeAttribute(node, "href");
@@ -23877,6 +23933,12 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23877
23933
  href: buildSpecifierBeforeRedirect
23878
23934
  });
23879
23935
  });
23936
+ for (const dependencyUrl of buildUrlInfo.dependencies) {
23937
+ const dependencyUrlInfo = finalGraph.urlInfoMap.get(dependencyUrl);
23938
+ if (dependencyUrlInfo.data.generatedToShareCode) {
23939
+ hintsToInject[dependencyUrl] = node;
23940
+ }
23941
+ }
23880
23942
  };
23881
23943
  if (href.startsWith("file:")) {
23882
23944
  let url = href;
@@ -23899,6 +23961,27 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
23899
23961
  }
23900
23962
  }
23901
23963
  });
23964
+ Object.keys(hintsToInject).forEach(urlToHint => {
23965
+ const hintNode = hintsToInject[urlToHint];
23966
+ const urlFormatted = versioningRedirections.get(urlToHint) || urlToHint;
23967
+ const specifierBeforeRedirect = findKey(buildUrls, urlFormatted);
23968
+ const found = findHtmlNode(htmlAst, htmlNode => {
23969
+ return htmlNode.nodeName === "link" && getHtmlNodeAttribute(htmlNode, "href") === specifierBeforeRedirect;
23970
+ });
23971
+ if (!found) {
23972
+ mutations.push(() => {
23973
+ const nodeToInsert = createHtmlNode({
23974
+ tagName: "link",
23975
+ href: specifierBeforeRedirect,
23976
+ rel: getHtmlNodeAttribute(hintNode, "rel"),
23977
+ as: getHtmlNodeAttribute(hintNode, "as"),
23978
+ type: getHtmlNodeAttribute(hintNode, "type"),
23979
+ crossorigin: getHtmlNodeAttribute(hintNode, "crossorigin")
23980
+ });
23981
+ insertHtmlNodeAfter(nodeToInsert, hintNode.parentNode, hintNode);
23982
+ });
23983
+ }
23984
+ });
23902
23985
  if (mutations.length > 0) {
23903
23986
  mutations.forEach(mutation => mutation());
23904
23987
  await finalGraphKitchen.urlInfoTransformer.applyFinalTransformations(urlInfo, {
@@ -24002,8 +24085,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
24002
24085
  }
24003
24086
  });
24004
24087
  if (writeOnFileSystem) {
24005
- if (buildDirectoryClean) {
24006
- await ensureEmptyDirectory(buildDirectoryUrl);
24088
+ if (directoryToClean) {
24089
+ await ensureEmptyDirectory(directoryToClean);
24007
24090
  }
24008
24091
  const buildRelativeUrls = Object.keys(buildFileContents);
24009
24092
  buildRelativeUrls.forEach(buildRelativeUrl => {
@@ -24762,7 +24845,7 @@ const startDevServer = async ({
24762
24845
  transpilation,
24763
24846
  explorer = true,
24764
24847
  // see jsenv_plugin_explorer.js
24765
- ribbon = false,
24848
+ ribbon = true,
24766
24849
  // toolbar = false,
24767
24850
 
24768
24851
  sourcemaps = "inline",