@jsenv/core 37.1.0 → 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.
@@ -9996,17 +9996,21 @@ const babelPluginReplaceTopLevelThis = () => {
9996
9996
 
9997
9997
 
9998
9998
  const jsenvPluginAsJsModule = () => {
9999
+ const markAsJsModuleProxy = (reference) => {
10000
+ reference.expectedType = "js_module";
10001
+ if (!reference.filename) {
10002
+ const filename = urlToFilename$1(reference.url);
10003
+ const [basename] = splitFileExtension$1(filename);
10004
+ reference.filename = `${basename}.mjs`;
10005
+ }
10006
+ };
10007
+
9999
10008
  return {
10000
10009
  name: "jsenv:as_js_module",
10001
10010
  appliesDuring: "*",
10002
10011
  redirectReference: (reference) => {
10003
10012
  if (reference.searchParams.has("as_js_module")) {
10004
- reference.expectedType = "js_module";
10005
- if (!reference.filename) {
10006
- const filename = urlToFilename$1(reference.url);
10007
- const [basename] = splitFileExtension$1(filename);
10008
- reference.filename = `${basename}.mjs`;
10009
- }
10013
+ markAsJsModuleProxy(reference);
10010
10014
  }
10011
10015
  },
10012
10016
  fetchUrlContent: async (urlInfo) => {
@@ -11694,6 +11698,9 @@ const createUrlInfo = (url, context) => {
11694
11698
  }
11695
11699
  return null;
11696
11700
  };
11701
+ urlInfo.findDependent = (callback) => {
11702
+ return GRAPH_VISITOR.findDependent(urlInfo, callback);
11703
+ };
11697
11704
  urlInfo.isSearchParamVariantOf = (otherUrlInfo) => {
11698
11705
  if (urlInfo.searchParams.size === 0) {
11699
11706
  return false;
@@ -12101,6 +12108,16 @@ const createPluginController = (kitchenContext) => {
12101
12108
  });
12102
12109
  };
12103
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
+
12104
12121
  return {
12105
12122
  plugins,
12106
12123
  pushPlugin,
@@ -12114,6 +12131,8 @@ const createPluginController = (kitchenContext) => {
12114
12131
  callAsyncHooks,
12115
12132
  callAsyncHooksUntil,
12116
12133
 
12134
+ getPluginMeta,
12135
+
12117
12136
  getLastPluginUsed: () => lastPluginUsed,
12118
12137
  getCurrentPlugin: () => currentPlugin,
12119
12138
  getCurrentHookName: () => currentHookName,
@@ -13143,6 +13162,7 @@ const createKitchen = ({
13143
13162
  inlineContentClientFileUrl,
13144
13163
  isSupportedOnCurrentClients: memoizeIsSupported(clientRuntimeCompat),
13145
13164
  isSupportedOnFutureClients: memoizeIsSupported(runtimeCompat),
13165
+ getPluginMeta: null,
13146
13166
  sourcemaps,
13147
13167
  outDirectoryUrl,
13148
13168
  },
@@ -13162,6 +13182,9 @@ const createKitchen = ({
13162
13182
 
13163
13183
  const pluginController = createPluginController(kitchenContext);
13164
13184
  kitchen.pluginController = pluginController;
13185
+ kitchenContext.getPluginMeta = memoizeGetPluginMeta(
13186
+ pluginController.getPluginMeta,
13187
+ );
13165
13188
  plugins.forEach((pluginEntry) => {
13166
13189
  pluginController.pushPlugin(pluginEntry);
13167
13190
  });
@@ -13688,6 +13711,19 @@ const memoizeCook = (cook) => {
13688
13711
  };
13689
13712
  };
13690
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
+
13691
13727
  const memoizeIsSupported = (runtimeCompat) => {
13692
13728
  const cache = new Map();
13693
13729
  return (feature, featureCompat) => {
@@ -17021,6 +17057,10 @@ const jsenvPluginNodeEsmResolution = (resolutionConfig = {}) => {
17021
17057
  if (reference.subtype === "self_import_scripts_arg") {
17022
17058
  return nodeEsmResolverDefault(reference);
17023
17059
  }
17060
+ if (reference.type === "js_import") {
17061
+ // happens for ?as_js_module
17062
+ return nodeEsmResolverDefault(reference);
17063
+ }
17024
17064
  return null;
17025
17065
  };
17026
17066
  }
@@ -18692,7 +18732,10 @@ const jsenvPluginRibbon = ({
18692
18732
  appliesDuring: "dev",
18693
18733
  transformUrlContent: {
18694
18734
  html: (urlInfo) => {
18695
- if (urlInfo.data.isJsenvToolbar || urlInfo.data.noribbon) {
18735
+ if (
18736
+ urlInfo.url ===
18737
+ urlInfo.context.getPluginMeta("jsenvToolbarHtmlClientFileUrl")
18738
+ ) {
18696
18739
  return null;
18697
18740
  }
18698
18741
  const { ribbon } = URL_META.applyAssociations({
@@ -19033,7 +19076,9 @@ const injectVersionMappingsAsGlobal = async (
19033
19076
  type: "js_classic",
19034
19077
  content: generateClientCodeForVersionMappings(versionMappings, {
19035
19078
  globalName: "window",
19036
- minification: urlInfo.context.minification,
19079
+ minification: Boolean(
19080
+ urlInfo.context.getPluginMeta("willMinifyJsClassic"),
19081
+ ),
19037
19082
  }),
19038
19083
  });
19039
19084
  return;
@@ -19043,7 +19088,9 @@ const injectVersionMappingsAsGlobal = async (
19043
19088
  type: "js_classic",
19044
19089
  content: generateClientCodeForVersionMappings(versionMappings, {
19045
19090
  globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
19046
- minification: urlInfo.context.minification,
19091
+ minification: Boolean(
19092
+ urlInfo.context.getPluginMeta("willMinifyJsClassic"),
19093
+ ),
19047
19094
  }),
19048
19095
  });
19049
19096
  return;
@@ -19076,12 +19123,15 @@ const injectVersionMappingsAsImportmap = (urlInfo, versionMappings) => {
19076
19123
  // jsenv_plugin_importmap.js is removing importmap during build
19077
19124
  // it means at this point we know HTML has no importmap in it
19078
19125
  // we can safely inject one
19126
+ const importmapMinification = Boolean(
19127
+ urlInfo.context.getPluginMeta("willMinifyJson"),
19128
+ );
19079
19129
  injectHtmlNodeAsEarlyAsPossible(
19080
19130
  htmlAst,
19081
19131
  createHtmlNode({
19082
19132
  tagName: "script",
19083
19133
  type: "importmap",
19084
- textContent: urlInfo.context.minification
19134
+ textContent: importmapMinification
19085
19135
  ? JSON.stringify({ imports: versionMappings })
19086
19136
  : JSON.stringify({ imports: versionMappings }, null, " "),
19087
19137
  }),
@@ -19836,9 +19886,6 @@ build ${entryPointKeys.length} entry points`);
19836
19886
  return true;
19837
19887
  return false;
19838
19888
  })(),
19839
- minification: plugins.some(
19840
- (plugin) => plugin.name === "jsenv:minification",
19841
- ),
19842
19889
  };
19843
19890
  const rawKitchen = createKitchen({
19844
19891
  signal,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "37.1.0",
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) => {
@@ -7,6 +7,7 @@ import {
7
7
  import { createEventEmitter } from "../../helpers/event_emitter.js";
8
8
  import { urlSpecifierEncoding } from "./url_specifier_encoding.js";
9
9
  import { createDependencies } from "./references.js";
10
+ import { GRAPH_VISITOR } from "./url_graph_visitor.js";
10
11
 
11
12
  export const createUrlGraph = ({
12
13
  rootDirectoryUrl,
@@ -266,6 +267,9 @@ const createUrlInfo = (url, context) => {
266
267
  }
267
268
  return null;
268
269
  };
270
+ urlInfo.findDependent = (callback) => {
271
+ return GRAPH_VISITOR.findDependent(urlInfo, callback);
272
+ };
269
273
  urlInfo.isSearchParamVariantOf = (otherUrlInfo) => {
270
274
  if (urlInfo.searchParams.size === 0) {
271
275
  return false;
@@ -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,
@@ -48,6 +48,10 @@ export const jsenvPluginNodeEsmResolution = (resolutionConfig = {}) => {
48
48
  if (reference.subtype === "self_import_scripts_arg") {
49
49
  return nodeEsmResolverDefault(reference);
50
50
  }
51
+ if (reference.type === "js_import") {
52
+ // happens for ?as_js_module
53
+ return nodeEsmResolverDefault(reference);
54
+ }
51
55
  return null;
52
56
  };
53
57
  }
@@ -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({