@jsenv/core 37.1.1 → 37.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12108,6 +12108,16 @@ const createPluginController = (kitchenContext) => {
12108
12108
  });
12109
12109
  };
12110
12110
 
12111
+ const getPluginMeta = (id) => {
12112
+ for (const plugin of plugins) {
12113
+ const { meta } = plugin;
12114
+ if (meta && meta[id] !== undefined) {
12115
+ return meta[id];
12116
+ }
12117
+ }
12118
+ return undefined;
12119
+ };
12120
+
12111
12121
  return {
12112
12122
  plugins,
12113
12123
  pushPlugin,
@@ -12121,6 +12131,8 @@ const createPluginController = (kitchenContext) => {
12121
12131
  callAsyncHooks,
12122
12132
  callAsyncHooksUntil,
12123
12133
 
12134
+ getPluginMeta,
12135
+
12124
12136
  getLastPluginUsed: () => lastPluginUsed,
12125
12137
  getCurrentPlugin: () => currentPlugin,
12126
12138
  getCurrentHookName: () => currentHookName,
@@ -13150,6 +13162,7 @@ const createKitchen = ({
13150
13162
  inlineContentClientFileUrl,
13151
13163
  isSupportedOnCurrentClients: memoizeIsSupported(clientRuntimeCompat),
13152
13164
  isSupportedOnFutureClients: memoizeIsSupported(runtimeCompat),
13165
+ getPluginMeta: null,
13153
13166
  sourcemaps,
13154
13167
  outDirectoryUrl,
13155
13168
  },
@@ -13169,6 +13182,9 @@ const createKitchen = ({
13169
13182
 
13170
13183
  const pluginController = createPluginController(kitchenContext);
13171
13184
  kitchen.pluginController = pluginController;
13185
+ kitchenContext.getPluginMeta = memoizeGetPluginMeta(
13186
+ pluginController.getPluginMeta,
13187
+ );
13172
13188
  plugins.forEach((pluginEntry) => {
13173
13189
  pluginController.pushPlugin(pluginEntry);
13174
13190
  });
@@ -13695,6 +13711,19 @@ const memoizeCook = (cook) => {
13695
13711
  };
13696
13712
  };
13697
13713
 
13714
+ const memoizeGetPluginMeta = (getPluginMeta) => {
13715
+ const cache = new Map();
13716
+ return (id) => {
13717
+ const fromCache = cache.get(id);
13718
+ if (fromCache) {
13719
+ return fromCache;
13720
+ }
13721
+ const value = getPluginMeta(id);
13722
+ cache.set(id, value);
13723
+ return value;
13724
+ };
13725
+ };
13726
+
13698
13727
  const memoizeIsSupported = (runtimeCompat) => {
13699
13728
  const cache = new Map();
13700
13729
  return (feature, featureCompat) => {
@@ -18703,7 +18732,10 @@ const jsenvPluginRibbon = ({
18703
18732
  appliesDuring: "dev",
18704
18733
  transformUrlContent: {
18705
18734
  html: (urlInfo) => {
18706
- if (urlInfo.data.isJsenvToolbar || urlInfo.data.noribbon) {
18735
+ if (
18736
+ urlInfo.url ===
18737
+ urlInfo.context.getPluginMeta("jsenvToolbarHtmlClientFileUrl")
18738
+ ) {
18707
18739
  return null;
18708
18740
  }
18709
18741
  const { ribbon } = URL_META.applyAssociations({
@@ -19044,7 +19076,9 @@ const injectVersionMappingsAsGlobal = async (
19044
19076
  type: "js_classic",
19045
19077
  content: generateClientCodeForVersionMappings(versionMappings, {
19046
19078
  globalName: "window",
19047
- minification: urlInfo.context.minification,
19079
+ minification: Boolean(
19080
+ urlInfo.context.getPluginMeta("willMinifyJsClassic"),
19081
+ ),
19048
19082
  }),
19049
19083
  });
19050
19084
  return;
@@ -19054,7 +19088,9 @@ const injectVersionMappingsAsGlobal = async (
19054
19088
  type: "js_classic",
19055
19089
  content: generateClientCodeForVersionMappings(versionMappings, {
19056
19090
  globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
19057
- minification: urlInfo.context.minification,
19091
+ minification: Boolean(
19092
+ urlInfo.context.getPluginMeta("willMinifyJsClassic"),
19093
+ ),
19058
19094
  }),
19059
19095
  });
19060
19096
  return;
@@ -19087,12 +19123,15 @@ const injectVersionMappingsAsImportmap = (urlInfo, versionMappings) => {
19087
19123
  // jsenv_plugin_importmap.js is removing importmap during build
19088
19124
  // it means at this point we know HTML has no importmap in it
19089
19125
  // we can safely inject one
19126
+ const importmapMinification = Boolean(
19127
+ urlInfo.context.getPluginMeta("willMinifyJson"),
19128
+ );
19090
19129
  injectHtmlNodeAsEarlyAsPossible(
19091
19130
  htmlAst,
19092
19131
  createHtmlNode({
19093
19132
  tagName: "script",
19094
19133
  type: "importmap",
19095
- textContent: urlInfo.context.minification
19134
+ textContent: importmapMinification
19096
19135
  ? JSON.stringify({ imports: versionMappings })
19097
19136
  : JSON.stringify({ imports: versionMappings }, null, " "),
19098
19137
  }),
@@ -19847,9 +19886,6 @@ build ${entryPointKeys.length} entry points`);
19847
19886
  return true;
19848
19887
  return false;
19849
19888
  })(),
19850
- minification: plugins.some(
19851
- (plugin) => plugin.name === "jsenv:minification",
19852
- ),
19853
19889
  };
19854
19890
  const rawKitchen = createKitchen({
19855
19891
  signal,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "37.1.1",
3
+ "version": "37.1.2",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -298,9 +298,6 @@ build ${entryPointKeys.length} entry points`);
298
298
  return true;
299
299
  return false;
300
300
  })(),
301
- minification: plugins.some(
302
- (plugin) => plugin.name === "jsenv:minification",
303
- ),
304
301
  };
305
302
  const rawKitchen = createKitchen({
306
303
  signal,
@@ -19,7 +19,9 @@ export const injectVersionMappingsAsGlobal = async (
19
19
  type: "js_classic",
20
20
  content: generateClientCodeForVersionMappings(versionMappings, {
21
21
  globalName: "window",
22
- minification: urlInfo.context.minification,
22
+ minification: Boolean(
23
+ urlInfo.context.getPluginMeta("willMinifyJsClassic"),
24
+ ),
23
25
  }),
24
26
  });
25
27
  return;
@@ -29,7 +31,9 @@ export const injectVersionMappingsAsGlobal = async (
29
31
  type: "js_classic",
30
32
  content: generateClientCodeForVersionMappings(versionMappings, {
31
33
  globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
32
- minification: urlInfo.context.minification,
34
+ minification: Boolean(
35
+ urlInfo.context.getPluginMeta("willMinifyJsClassic"),
36
+ ),
33
37
  }),
34
38
  });
35
39
  return;
@@ -62,12 +66,15 @@ export const injectVersionMappingsAsImportmap = (urlInfo, versionMappings) => {
62
66
  // jsenv_plugin_importmap.js is removing importmap during build
63
67
  // it means at this point we know HTML has no importmap in it
64
68
  // we can safely inject one
69
+ const importmapMinification = Boolean(
70
+ urlInfo.context.getPluginMeta("willMinifyJson"),
71
+ );
65
72
  injectHtmlNodeAsEarlyAsPossible(
66
73
  htmlAst,
67
74
  createHtmlNode({
68
75
  tagName: "script",
69
76
  type: "importmap",
70
- textContent: urlInfo.context.minification
77
+ textContent: importmapMinification
71
78
  ? JSON.stringify({ imports: versionMappings })
72
79
  : JSON.stringify({ imports: versionMappings }, null, " "),
73
80
  }),
@@ -70,6 +70,7 @@ export const createKitchen = ({
70
70
  inlineContentClientFileUrl,
71
71
  isSupportedOnCurrentClients: memoizeIsSupported(clientRuntimeCompat),
72
72
  isSupportedOnFutureClients: memoizeIsSupported(runtimeCompat),
73
+ getPluginMeta: null,
73
74
  sourcemaps,
74
75
  outDirectoryUrl,
75
76
  },
@@ -89,6 +90,9 @@ export const createKitchen = ({
89
90
 
90
91
  const pluginController = createPluginController(kitchenContext);
91
92
  kitchen.pluginController = pluginController;
93
+ kitchenContext.getPluginMeta = memoizeGetPluginMeta(
94
+ pluginController.getPluginMeta,
95
+ );
92
96
  plugins.forEach((pluginEntry) => {
93
97
  pluginController.pushPlugin(pluginEntry);
94
98
  });
@@ -615,6 +619,19 @@ const memoizeCook = (cook) => {
615
619
  };
616
620
  };
617
621
 
622
+ const memoizeGetPluginMeta = (getPluginMeta) => {
623
+ const cache = new Map();
624
+ return (id) => {
625
+ const fromCache = cache.get(id);
626
+ if (fromCache) {
627
+ return fromCache;
628
+ }
629
+ const value = getPluginMeta(id);
630
+ cache.set(id, value);
631
+ return value;
632
+ };
633
+ };
634
+
618
635
  const memoizeIsSupported = (runtimeCompat) => {
619
636
  const cache = new Map();
620
637
  return (feature, featureCompat) => {
@@ -251,6 +251,16 @@ export const createPluginController = (kitchenContext) => {
251
251
  });
252
252
  };
253
253
 
254
+ const getPluginMeta = (id) => {
255
+ for (const plugin of plugins) {
256
+ const { meta } = plugin;
257
+ if (meta && meta[id] !== undefined) {
258
+ return meta[id];
259
+ }
260
+ }
261
+ return undefined;
262
+ };
263
+
254
264
  return {
255
265
  plugins,
256
266
  pushPlugin,
@@ -264,6 +274,8 @@ export const createPluginController = (kitchenContext) => {
264
274
  callAsyncHooks,
265
275
  callAsyncHooksUntil,
266
276
 
277
+ getPluginMeta,
278
+
267
279
  getLastPluginUsed: () => lastPluginUsed,
268
280
  getCurrentPlugin: () => currentPlugin,
269
281
  getCurrentHookName: () => currentHookName,
@@ -25,7 +25,10 @@ export const jsenvPluginRibbon = ({
25
25
  appliesDuring: "dev",
26
26
  transformUrlContent: {
27
27
  html: (urlInfo) => {
28
- if (urlInfo.data.isJsenvToolbar || urlInfo.data.noribbon) {
28
+ if (
29
+ urlInfo.url ===
30
+ urlInfo.context.getPluginMeta("jsenvToolbarHtmlClientFileUrl")
31
+ ) {
29
32
  return null;
30
33
  }
31
34
  const { ribbon } = URL_META.applyAssociations({