@jsenv/core 40.12.12 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "40.12.12",
3
+ "version": "40.12.14",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,7 +81,7 @@
81
81
  "@jsenv/plugin-minification": "1.7.3",
82
82
  "@jsenv/plugin-supervisor": "1.7.15",
83
83
  "@jsenv/plugin-transpilation": "1.5.70",
84
- "@jsenv/server": "16.3.6",
84
+ "@jsenv/server": "17.0.0",
85
85
  "@jsenv/sourcemap": "1.3.17",
86
86
  "react-table": "7.8.0"
87
87
  },
@@ -66,9 +66,9 @@ import { GRAPH_VISITOR } from "../kitchen/url_graph/url_graph_visitor.js";
66
66
  import { jsenvPluginDirectoryReferenceEffect } from "../plugins/directory_reference_effect/jsenv_plugin_directory_reference_effect.js";
67
67
  import { jsenvPluginInlining } from "../plugins/inlining/jsenv_plugin_inlining.js";
68
68
  import {
69
- createPluginController,
70
- createPluginStore,
71
- } from "../plugins/plugin_controller.js";
69
+ createJsenvPluginsController,
70
+ createJsenvPluginStore,
71
+ } from "../plugins/jsenv_plugins_controller.js";
72
72
  import { getCorePlugins } from "../plugins/plugins.js";
73
73
  import { jsenvPluginReferenceAnalysis } from "../plugins/reference_analysis/jsenv_plugin_reference_analysis.js";
74
74
  import { renderBuildDoneLog } from "./build_content_report.js";
@@ -1109,7 +1109,7 @@ const prepareEntryPointBuild = async (
1109
1109
  });
1110
1110
 
1111
1111
  let _getOtherEntryBuildInfo;
1112
- const rawPluginStore = await createPluginStore([
1112
+ const rawJsenvPluginStore = await createJsenvPluginStore([
1113
1113
  ...(mappings ? [jsenvPluginMappings(mappings)] : []),
1114
1114
  {
1115
1115
  name: "jsenv:other_entry_point_build_during_craft",
@@ -1155,11 +1155,11 @@ const prepareEntryPointBuild = async (
1155
1155
  packageSideEffects,
1156
1156
  }),
1157
1157
  ]);
1158
- const rawPluginController = await createPluginController(
1159
- rawPluginStore,
1158
+ const rawJsenvPluginsController = await createJsenvPluginsController(
1159
+ rawJsenvPluginStore,
1160
1160
  rawKitchen,
1161
1161
  );
1162
- rawKitchen.setPluginController(rawPluginController);
1162
+ rawKitchen.setJsenvPluginsController(rawJsenvPluginsController);
1163
1163
 
1164
1164
  const rawRootUrlInfo = rawKitchen.graph.rootUrlInfo;
1165
1165
  let entryReference;
@@ -1227,7 +1227,7 @@ const prepareEntryPointBuild = async (
1227
1227
  rawKitchen.graph.getUrlInfo(entryReference.url).type === "html" &&
1228
1228
  rawKitchen.context.isSupportedOnCurrentClients("importmap"),
1229
1229
  });
1230
- const finalPluginStore = await createPluginStore([
1230
+ const finalJsenvPluginStore = await createJsenvPluginStore([
1231
1231
  jsenvPluginReferenceAnalysis({
1232
1232
  ...referenceAnalysis,
1233
1233
  fetchInlineUrls: false,
@@ -1249,7 +1249,7 @@ const prepareEntryPointBuild = async (
1249
1249
  name: "jsenv:optimize",
1250
1250
  appliesDuring: "build",
1251
1251
  transformUrlContent: async (urlInfo) => {
1252
- await rawKitchen.pluginController.callAsyncHooks(
1252
+ await rawKitchen.jsenvPluginsController.callAsyncHooks(
1253
1253
  "optimizeBuildUrlContent",
1254
1254
  urlInfo,
1255
1255
  (optimizeReturnValue) => {
@@ -1260,18 +1260,18 @@ const prepareEntryPointBuild = async (
1260
1260
  },
1261
1261
  buildSpecifierManager.jsenvPluginMoveToBuildDirectory,
1262
1262
  ]);
1263
- const finalPluginController = await createPluginController(
1264
- finalPluginStore,
1263
+ const finalJsenvPluginsController = await createJsenvPluginsController(
1264
+ finalJsenvPluginStore,
1265
1265
  finalKitchen,
1266
1266
  {
1267
- initialPuginsMeta: rawKitchen.pluginController.pluginsMeta,
1267
+ meta: rawKitchen.jsenvPluginsController.getMeta(),
1268
1268
  },
1269
1269
  );
1270
- finalKitchen.setPluginController(finalPluginController);
1270
+ finalKitchen.setJsenvPluginsController(finalJsenvPluginsController);
1271
1271
 
1272
1272
  bundle: {
1273
1273
  const bundlerMap = new Map();
1274
- for (const plugin of rawKitchen.pluginController.activePlugins) {
1274
+ for (const plugin of rawKitchen.jsenvPluginsController.activePlugins) {
1275
1275
  const bundle = plugin.bundle;
1276
1276
  if (!bundle) {
1277
1277
  continue;
@@ -1483,7 +1483,8 @@ const prepareEntryPointBuild = async (
1483
1483
  refine_hook: {
1484
1484
  const refineBuildUrlContentCallbackSet = new Set();
1485
1485
  const refineBuildCallbackSet = new Set();
1486
- for (const plugin of rawKitchen.pluginController.activePlugins) {
1486
+ for (const plugin of rawKitchen.jsenvPluginsController
1487
+ .activePlugins) {
1487
1488
  const refineBuildUrlContent = plugin.refineBuildUrlContent;
1488
1489
  if (refineBuildUrlContent) {
1489
1490
  refineBuildUrlContentCallbackSet.add(refineBuildUrlContent);
@@ -117,14 +117,15 @@ export const createBuildSpecifierManager = ({
117
117
  const bundleInfoMap = new Map();
118
118
 
119
119
  const applyBundling = async ({ bundler, urlInfosToBundle }) => {
120
- const urlInfosBundled = await rawKitchen.pluginController.callAsyncHook(
121
- {
122
- plugin: bundler.plugin,
123
- hookName: "bundle",
124
- value: bundler.bundleFunction,
125
- },
126
- urlInfosToBundle,
127
- );
120
+ const urlInfosBundled =
121
+ await rawKitchen.jsenvPluginsController.callAsyncHook(
122
+ {
123
+ plugin: bundler.plugin,
124
+ hookName: "bundle",
125
+ value: bundler.bundleFunction,
126
+ },
127
+ urlInfosToBundle,
128
+ );
128
129
  for (const url of Object.keys(urlInfosBundled)) {
129
130
  const urlInfoBundled = urlInfosBundled[url];
130
131
  const contentSideEffects = [];
@@ -1315,9 +1316,9 @@ const isWrappedByQuote = (content, start, end) => {
1315
1316
  // https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
1316
1317
  const generateVersion = (parts, length) => {
1317
1318
  const hash = createHash("sha256");
1318
- parts.forEach((part) => {
1319
+ for (const part of parts) {
1319
1320
  hash.update(part);
1320
- });
1321
+ }
1321
1322
  return hash.digest("hex").slice(0, length);
1322
1323
  };
1323
1324
 
@@ -15,25 +15,27 @@ import {
15
15
  import { isWebWorkerUrlInfo } from "@jsenv/core/src/kitchen/web_workers.js";
16
16
  import { prependContent } from "../kitchen/prepend_content.js";
17
17
 
18
+ // we nevery minify those because they are already very small
19
+ // and would hurt the readability of something that can be critical to debug
18
20
  export const injectGlobalMappings = async (urlInfo, mappings) => {
19
21
  if (urlInfo.type === "html") {
20
- const minification = Boolean(
21
- urlInfo.context.getPluginMeta("willMinifyJsClassic"),
22
- );
22
+ // const minification = Boolean(
23
+ // urlInfo.context.getPluginMeta("willMinifyJsClassic"),
24
+ // );
23
25
  const content = generateClientCodeForMappings(mappings, {
24
26
  globalName: "window",
25
- minification,
27
+ minification: false,
26
28
  });
27
29
  await prependContent(urlInfo, { type: "js_classic", content });
28
30
  return;
29
31
  }
30
32
  if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
31
- const minification = Boolean(
32
- urlInfo.context.getPluginMeta("willMinifyJsClassic"),
33
- );
33
+ // const minification = Boolean(
34
+ // urlInfo.context.getPluginMeta("willMinifyJsClassic"),
35
+ // );
34
36
  const content = generateClientCodeForMappings(mappings, {
35
37
  globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
36
- minification,
38
+ minification: false,
37
39
  });
38
40
  await prependContent(urlInfo, { type: "js_classic", content });
39
41
  return;
@@ -68,9 +70,8 @@ export const injectImportmapMappings = (urlInfo, getMappings) => {
68
70
  // jsenv_plugin_importmap.js is removing importmap during build
69
71
  // it means at this point we know HTML has no importmap in it
70
72
  // we can safely inject one
71
- const importmapMinification = Boolean(
72
- urlInfo.context.getPluginMeta("willMinifyJson"),
73
- );
73
+ const importmapMinification = false;
74
+ // Boolean(urlInfo.context.getPluginMeta("willMinifyJson"));
74
75
  const importmapNode = findHtmlNode(htmlAst, (node) => {
75
76
  return (
76
77
  node.tagName === "script" &&
@@ -17,13 +17,12 @@ import { Abort, raceProcessTeardownEvents } from "@jsenv/abort";
17
17
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
18
18
  import { createLogger, createTaskLog } from "@jsenv/humanize";
19
19
  import {
20
- createFileSystemFetch,
21
20
  jsenvAccessControlAllowedHeaders,
22
- jsenvServiceCORS,
23
- jsenvServiceErrorHandler,
21
+ serverPluginCORS,
22
+ serverPluginErrorHandler,
23
+ serverPluginStaticFiles,
24
24
  startServer,
25
25
  } from "@jsenv/server";
26
- import { urlToExtension, urlToPathname } from "@jsenv/urls";
27
26
  import { existsSync } from "node:fs";
28
27
 
29
28
  /**
@@ -37,7 +36,7 @@ export const startBuildServer = async ({
37
36
  buildMainFilePath = "index.html",
38
37
  port = 9779,
39
38
  routes,
40
- services = [],
39
+ serverPlugins = [],
41
40
  acceptAnyIp,
42
41
  hostname,
43
42
  https,
@@ -122,8 +121,8 @@ export const startBuildServer = async ({
122
121
  serverTiming: true,
123
122
  requestWaitingMs: 60_000,
124
123
  routes,
125
- services: [
126
- jsenvServiceCORS({
124
+ plugins: [
125
+ serverPluginCORS({
127
126
  accessControlAllowRequestOrigin: true,
128
127
  accessControlAllowRequestMethod: true,
129
128
  accessControlAllowRequestHeaders: true,
@@ -131,13 +130,13 @@ export const startBuildServer = async ({
131
130
  accessControlAllowCredentials: true,
132
131
  timingAllowOrigin: true,
133
132
  }),
134
- ...services,
135
- jsenvBuildFileService({
136
- buildDirectoryUrl,
137
- buildMainFilePath,
133
+ ...serverPlugins,
134
+ serverPluginStaticFiles({
135
+ directoryUrl: buildDirectoryUrl,
136
+ mainFilePath: buildMainFilePath,
138
137
  }),
139
- jsenvServiceErrorHandler({
140
- sendErrorDetails: true,
138
+ serverPluginErrorHandler({
139
+ sendErrorDetails: false,
141
140
  }),
142
141
  ],
143
142
  });
@@ -158,48 +157,3 @@ export const startBuildServer = async ({
158
157
  },
159
158
  };
160
159
  };
161
-
162
- const jsenvBuildFileService = ({ buildDirectoryUrl, buildMainFilePath }) => {
163
- return {
164
- name: "jsenv:build_files",
165
- routes: [
166
- {
167
- endpoint: "GET *",
168
- description: "Serve static files.",
169
- fetch: (request, helpers) => {
170
- const urlIsVersioned = new URL(request.url).searchParams.has("v");
171
- if (buildMainFilePath && request.resource === "/") {
172
- request = {
173
- ...request,
174
- resource: `/${buildMainFilePath}`,
175
- };
176
- }
177
- const urlObject = new URL(
178
- request.resource.slice(1),
179
- buildDirectoryUrl,
180
- );
181
- return createFileSystemFetch(buildDirectoryUrl, {
182
- cacheControl: urlIsVersioned
183
- ? `private,max-age=${SECONDS_IN_30_DAYS},immutable`
184
- : "private,max-age=0,must-revalidate",
185
- etagEnabled: true,
186
- compressionEnabled: true,
187
- rootDirectoryUrl: buildDirectoryUrl,
188
- canReadDirectory: true,
189
- ENOENTFallback: () => {
190
- if (
191
- !urlToExtension(urlObject) &&
192
- !urlToPathname(urlObject).endsWith("/")
193
- ) {
194
- return new URL(buildMainFilePath, buildDirectoryUrl);
195
- }
196
- return null;
197
- },
198
- })(request, helpers);
199
- },
200
- },
201
- ],
202
- };
203
- };
204
-
205
- const SECONDS_IN_30_DAYS = 60 * 60 * 24 * 30;
@@ -7,12 +7,12 @@ import { createLogger, createTaskLog, formatError } from "@jsenv/humanize";
7
7
  import {
8
8
  composeTwoResponses,
9
9
  jsenvAccessControlAllowedHeaders,
10
- jsenvServiceCORS,
11
- jsenvServiceErrorHandler,
12
10
  serveDirectory,
11
+ serverPluginCORS,
12
+ serverPluginErrorHandler,
13
13
  startServer,
14
14
  } from "@jsenv/server";
15
- import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js";
15
+ import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/plugins/filesystem/filesystem_error_to_response.js";
16
16
  import { URL_META } from "@jsenv/url-meta";
17
17
  import { urlIsOrIsInsideOf, urlToRelativeUrl } from "@jsenv/urls";
18
18
  import { existsSync, readFileSync } from "node:fs";
@@ -24,9 +24,9 @@ import { jsenvCoreDirectoryUrl } from "../jsenv_core_directory_url.js";
24
24
  import { createKitchen } from "../kitchen/kitchen.js";
25
25
  import { createPackageDirectory } from "../kitchen/package_directory.js";
26
26
  import {
27
- createPluginController,
28
- createPluginStore,
29
- } from "../plugins/plugin_controller.js";
27
+ createJsenvPluginsController,
28
+ createJsenvPluginStore,
29
+ } from "../plugins/jsenv_plugins_controller.js";
30
30
  import { getCorePlugins } from "../plugins/plugins.js";
31
31
  import { jsenvPluginServerEvents } from "../plugins/server_events/jsenv_plugin_server_events.js";
32
32
  import { parseUserAgentHeader } from "./user_agent.js";
@@ -69,7 +69,7 @@ export const startDevServer = async ({
69
69
  logLevel = EXECUTED_BY_TEST_PLAN ? "warn" : "info",
70
70
  serverLogLevel = "warn",
71
71
  serverRouterLogLevel = "warn",
72
- services = [],
72
+ serverPlugins = [],
73
73
 
74
74
  signal = new AbortController().signal,
75
75
  handleSIGINT = true,
@@ -176,10 +176,10 @@ export const startDevServer = async ({
176
176
  const serverStopAbortSignal = serverStopAbortController.signal;
177
177
  const kitchenCache = new Map();
178
178
 
179
- const finalServices = [];
179
+ const finalServerPlugins = [];
180
180
  // x-server-inspect service
181
181
  {
182
- finalServices.push({
182
+ finalServerPlugins.push({
183
183
  name: "jsenv:server_header",
184
184
  routes: [
185
185
  {
@@ -205,8 +205,8 @@ export const startDevServer = async ({
205
205
  }
206
206
  // cors service
207
207
  {
208
- finalServices.push(
209
- jsenvServiceCORS({
208
+ finalServerPlugins.push(
209
+ serverPluginCORS({
210
210
  accessControlAllowRequestOrigin: true,
211
211
  accessControlAllowRequestMethod: true,
212
212
  accessControlAllowRequestHeaders: true,
@@ -219,9 +219,9 @@ export const startDevServer = async ({
219
219
  }),
220
220
  );
221
221
  }
222
- // custom services
222
+ // custom server plugins
223
223
  {
224
- finalServices.push(...services);
224
+ finalServerPlugins.push(...serverPlugins);
225
225
  }
226
226
  // file_service
227
227
  {
@@ -251,7 +251,7 @@ export const startDevServer = async ({
251
251
  sourceDirectoryUrl,
252
252
  });
253
253
 
254
- const devServerPluginStore = await createPluginStore([
254
+ const devServerJsenvPluginStore = await createJsenvPluginStore([
255
255
  jsenvPluginServerEvents({ clientAutoreload }),
256
256
  ...plugins,
257
257
  ...getCorePlugins({
@@ -411,28 +411,28 @@ export const startDevServer = async ({
411
411
  );
412
412
  },
413
413
  );
414
- const devServerPluginController = await createPluginController(
415
- devServerPluginStore,
414
+ const devServerJsenvPluginController = await createJsenvPluginsController(
415
+ devServerJsenvPluginStore,
416
416
  kitchen,
417
417
  );
418
- kitchen.setPluginController(devServerPluginController);
418
+ kitchen.setJsenvPluginsController(devServerJsenvPluginController);
419
419
 
420
420
  serverStopCallbackSet.add(() => {
421
- devServerPluginController.callHooks("destroy", kitchen.context);
421
+ devServerJsenvPluginController.callHooks("destroy", kitchen.context);
422
422
  });
423
423
  kitchenCache.set(runtimeId, kitchen);
424
424
  onKitchenCreated(kitchen);
425
425
  return kitchen;
426
426
  };
427
427
 
428
- finalServices.push({
428
+ finalServerPlugins.push({
429
429
  name: "jsenv:dev_server_routes",
430
430
  augmentRouteFetchSecondArg: async (request) => {
431
431
  const kitchen = await getOrCreateKitchen(request);
432
432
  return { kitchen };
433
433
  },
434
434
  routes: [
435
- ...devServerPluginStore.allDevServerRoutes,
435
+ ...devServerJsenvPluginStore.allServerRoutes,
436
436
  {
437
437
  endpoint: "GET *",
438
438
  description: "Serve project files.",
@@ -545,7 +545,7 @@ export const startDevServer = async ({
545
545
  reference,
546
546
  urlInfo,
547
547
  };
548
- kitchen.pluginController.callHooks(
548
+ kitchen.jsenvPluginsController.callHooks(
549
549
  "augmentResponse",
550
550
  augmentResponseInfo,
551
551
  (returnValue) => {
@@ -632,11 +632,11 @@ export const startDevServer = async ({
632
632
  },
633
633
  ],
634
634
  });
635
- finalServices.push(...devServerPluginStore.allDevServerServices);
635
+ finalServerPlugins.push(...devServerJsenvPluginStore.allServerPlugins);
636
636
  }
637
637
  // jsenv error handler service
638
638
  {
639
- finalServices.push({
639
+ finalServerPlugins.push({
640
640
  name: "jsenv:omega_error_handler",
641
641
  handleError: (error) => {
642
642
  const getResponseForError = () => {
@@ -673,8 +673,8 @@ export const startDevServer = async ({
673
673
  }
674
674
  // default error handler
675
675
  {
676
- finalServices.push(
677
- jsenvServiceErrorHandler({
676
+ finalServerPlugins.push(
677
+ serverPluginErrorHandler({
678
678
  sendErrorDetails: true,
679
679
  }),
680
680
  );
@@ -696,7 +696,7 @@ export const startDevServer = async ({
696
696
  hostname,
697
697
  port,
698
698
  requestWaitingMs: 60_000,
699
- services: finalServices,
699
+ plugins: finalServerPlugins,
700
700
  });
701
701
  server.stoppedPromise.then((reason) => {
702
702
  onStop();
@@ -3,7 +3,7 @@ import { stringifyUrlSite } from "@jsenv/urls";
3
3
  import { pathToFileURL } from "node:url";
4
4
 
5
5
  export const createResolveUrlError = ({
6
- pluginController,
6
+ jsenvPluginsController,
7
7
  reference,
8
8
  error,
9
9
  }) => {
@@ -21,7 +21,7 @@ ${reason}`,
21
21
  {
22
22
  ...detailsFromFirstReference(reference),
23
23
  ...details,
24
- ...detailsFromPluginController(pluginController),
24
+ ...detailsFromPluginController(jsenvPluginsController),
25
25
  },
26
26
  ),
27
27
  );
@@ -66,7 +66,7 @@ ${reason}`,
66
66
  };
67
67
 
68
68
  export const createFetchUrlContentError = ({
69
- pluginController,
69
+ jsenvPluginsController,
70
70
  urlInfo,
71
71
  error,
72
72
  }) => {
@@ -85,7 +85,7 @@ ${reason}`,
85
85
  {
86
86
  ...detailsFromFirstReference(reference),
87
87
  ...details,
88
- ...detailsFromPluginController(pluginController),
88
+ ...detailsFromPluginController(jsenvPluginsController),
89
89
  },
90
90
  ),
91
91
  );
@@ -141,7 +141,7 @@ ${reason}`,
141
141
  };
142
142
 
143
143
  export const createTransformUrlContentError = ({
144
- pluginController,
144
+ jsenvPluginsController,
145
145
  urlInfo,
146
146
  error,
147
147
  }) => {
@@ -170,7 +170,7 @@ ${error.message}`,
170
170
  ? `${reference.trace.url}:${reference.trace.line}:${reference.trace.column}`
171
171
  : reference.trace.message,
172
172
  ...detailsFromFirstReference(reference),
173
- ...detailsFromPluginController(pluginController),
173
+ ...detailsFromPluginController(jsenvPluginsController),
174
174
  },
175
175
  ),
176
176
  );
@@ -202,7 +202,7 @@ ${reason}`,
202
202
  {
203
203
  ...detailsFromFirstReference(reference),
204
204
  ...details,
205
- ...detailsFromPluginController(pluginController),
205
+ ...detailsFromPluginController(jsenvPluginsController),
206
206
  },
207
207
  ),
208
208
  );
@@ -226,7 +226,7 @@ ${reason}`,
226
226
  };
227
227
 
228
228
  export const createFinalizeUrlContentError = ({
229
- pluginController,
229
+ jsenvPluginsController,
230
230
  urlInfo,
231
231
  error,
232
232
  }) => {
@@ -238,7 +238,7 @@ ${reference.trace.message}`,
238
238
  {
239
239
  ...detailsFromFirstReference(reference),
240
240
  ...detailsFromValueThrown(error),
241
- ...detailsFromPluginController(pluginController),
241
+ ...detailsFromPluginController(jsenvPluginsController),
242
242
  },
243
243
  ),
244
244
  );
@@ -328,8 +328,8 @@ const getFirstReferenceInProject = (reference) => {
328
328
  return getFirstReferenceInProject(firstReference);
329
329
  };
330
330
 
331
- const detailsFromPluginController = (pluginController) => {
332
- const currentPlugin = pluginController.getCurrentPlugin();
331
+ const detailsFromPluginController = (jsenvPluginsController) => {
332
+ const currentPlugin = jsenvPluginsController.getCurrentPlugin();
333
333
  if (!currentPlugin) {
334
334
  return null;
335
335
  }