@jsenv/core 27.7.0 → 28.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 (36) hide show
  1. package/dist/js/server_events_client.js +1 -1
  2. package/dist/main.js +504 -457
  3. package/package.json +2 -2
  4. package/src/build/build.js +4 -5
  5. package/src/build/start_build_server.js +2 -2
  6. package/src/dev/start_dev_server.js +3 -3
  7. package/src/execute/execute.js +14 -52
  8. package/src/execute/runtimes/browsers/from_playwright.js +19 -8
  9. package/src/main.js +3 -0
  10. package/src/omega/kitchen.js +9 -14
  11. package/src/omega/omega_server.js +4 -4
  12. package/src/omega/server/file_service.js +11 -11
  13. package/src/ping_server.js +30 -0
  14. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +0 -4
  15. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +1 -1
  16. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +1 -1
  17. package/src/plugins/autoreload/jsenv_plugin_hmr.js +1 -1
  18. package/src/plugins/bundling/jsenv_plugin_bundling.js +1 -3
  19. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +2 -5
  20. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +2 -2
  21. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +4 -8
  22. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +1 -4
  23. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +2 -2
  24. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +12 -26
  25. package/src/plugins/importmap/jsenv_plugin_importmap.js +1 -1
  26. package/src/plugins/minification/jsenv_plugin_minification.js +1 -3
  27. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +9 -7
  28. package/src/plugins/plugin_controller.js +17 -6
  29. package/src/plugins/plugins.js +0 -2
  30. package/src/plugins/server_events/client/server_events_client.js +1 -1
  31. package/src/plugins/toolbar/jsenv_plugin_toolbar.js +1 -3
  32. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +13 -0
  33. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -1
  34. package/src/plugins/url_analysis/html/html_urls.js +2 -2
  35. package/src/test/execute_plan.js +15 -68
  36. package/src/test/execute_test_plan.js +4 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "27.7.0",
3
+ "version": "28.0.0",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -73,7 +73,7 @@
73
73
  "@jsenv/integrity": "0.0.1",
74
74
  "@jsenv/log": "3.1.0",
75
75
  "@jsenv/node-esm-resolution": "0.1.0",
76
- "@jsenv/server": "13.1.0",
76
+ "@jsenv/server": "14.0.0",
77
77
  "@jsenv/sourcemap": "1.0.4",
78
78
  "@jsenv/uneval": "1.6.0",
79
79
  "@jsenv/url-meta": "7.0.0",
@@ -175,7 +175,7 @@ build ${entryPointKeys.length} entry points`)
175
175
  logger,
176
176
  rootDirectoryUrl,
177
177
  urlGraph: rawGraph,
178
- scenario: "build",
178
+ scenarios: { build: true },
179
179
  sourcemaps,
180
180
  sourcemapsSourcesContent,
181
181
  runtimeCompat,
@@ -202,7 +202,6 @@ build ${entryPointKeys.length} entry points`)
202
202
  ...getCorePlugins({
203
203
  rootDirectoryUrl,
204
204
  urlGraph: rawGraph,
205
- scenario: "build",
206
205
  runtimeCompat,
207
206
 
208
207
  urlAnalysis,
@@ -423,7 +422,7 @@ build ${entryPointKeys.length} entry points`)
423
422
  logger,
424
423
  rootDirectoryUrl,
425
424
  urlGraph: finalGraph,
426
- scenario: "build",
425
+ scenarios: { build: true },
427
426
  sourcemaps,
428
427
  sourcemapsSourcesContent,
429
428
  sourcemapsRelativeSources: !versioning,
@@ -1063,7 +1062,7 @@ const applyUrlVersioning = async ({
1063
1062
  logger,
1064
1063
  rootDirectoryUrl: buildDirectoryUrl,
1065
1064
  urlGraph: finalGraph,
1066
- scenario: "build",
1065
+ scenarios: { build: true },
1067
1066
  sourcemaps,
1068
1067
  sourcemapsSourcesContent,
1069
1068
  sourcemapsRelativeSources: true,
@@ -1078,7 +1077,7 @@ const applyUrlVersioning = async ({
1078
1077
  }),
1079
1078
  {
1080
1079
  name: "jsenv:versioning",
1081
- appliesDuring: { build: true },
1080
+ appliesDuring: "build",
1082
1081
  resolveUrl: (reference) => {
1083
1082
  const buildUrl = buildUrls[reference.specifier]
1084
1083
  if (buildUrl) {
@@ -41,7 +41,7 @@ export const startBuildServer = async ({
41
41
  certificate,
42
42
  privateKey,
43
43
  acceptAnyIp,
44
- host,
44
+ hostname,
45
45
  port = 9779,
46
46
  services = [],
47
47
  keepProcessAlive = true,
@@ -163,7 +163,7 @@ export const startBuildServer = async ({
163
163
  certificate,
164
164
  privateKey,
165
165
  acceptAnyIp,
166
- host,
166
+ hostname,
167
167
  port,
168
168
  serverTiming: true,
169
169
  requestWaitingMs: 60_000,
@@ -22,7 +22,7 @@ export const startDevServer = async ({
22
22
  http2 = false,
23
23
  certificate,
24
24
  privateKey,
25
- host,
25
+ hostname,
26
26
  port = 3456,
27
27
  acceptAnyIp,
28
28
  keepProcessAlive = true,
@@ -150,12 +150,12 @@ export const startDevServer = async ({
150
150
  http2,
151
151
  certificate,
152
152
  privateKey,
153
- host,
153
+ hostname,
154
154
  port,
155
155
  services,
156
156
 
157
157
  rootDirectoryUrl,
158
- scenario: "dev",
158
+ scenarios: { dev: true },
159
159
  runtimeCompat,
160
160
 
161
161
  plugins,
@@ -1,9 +1,8 @@
1
1
  import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
2
-
3
2
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
4
3
  import { createLogger } from "@jsenv/log"
5
4
 
6
- import { startOmegaServer } from "@jsenv/core/src/omega/omega_server.js"
5
+ import { pingServer } from "../ping_server.js"
7
6
  import { run } from "./run.js"
8
7
 
9
8
  export const execute = async ({
@@ -11,12 +10,13 @@ export const execute = async ({
11
10
  handleSIGINT = true,
12
11
  logLevel,
13
12
  rootDirectoryUrl,
13
+ devServerOrigin,
14
14
 
15
15
  fileRelativeUrl,
16
16
  allocatedMs,
17
17
  mirrorConsole = true,
18
18
  keepRunning = false,
19
- services,
19
+
20
20
  collectConsole,
21
21
  collectCoverage,
22
22
  coverageTempDirectoryUrl,
@@ -24,21 +24,6 @@ export const execute = async ({
24
24
  runtime,
25
25
  runtimeParams,
26
26
 
27
- scenario = "dev",
28
- plugins = [],
29
- nodeEsmResolution,
30
- fileSystemMagicResolution,
31
- transpilation,
32
- htmlSupervisor = true,
33
- sourcemaps = "inline",
34
- writeGeneratedFiles = false,
35
-
36
- port,
37
- protocol,
38
- http2,
39
- certificate,
40
- privateKey,
41
-
42
27
  ignoreError = false,
43
28
  }) => {
44
29
  const logger = createLogger({ logLevel })
@@ -59,44 +44,21 @@ export const execute = async ({
59
44
  let resultTransformer = (result) => result
60
45
  runtimeParams = {
61
46
  rootDirectoryUrl,
47
+ devServerOrigin,
62
48
  fileRelativeUrl,
63
49
  ...runtimeParams,
64
50
  }
65
- if (runtime.needsServer) {
66
- const server = await startOmegaServer({
67
- signal: executeOperation.signal,
68
- logLevel: "warn",
69
- keepProcessAlive: false,
70
- services,
71
- port,
72
- protocol,
73
- http2,
74
- certificate,
75
- privateKey,
76
-
77
- rootDirectoryUrl,
78
- scenario,
79
- runtimeCompat: { [runtime.name]: runtime.version },
80
-
81
- plugins,
82
-
83
- htmlSupervisor,
84
- nodeEsmResolution,
85
- fileSystemMagicResolution,
86
- transpilation,
87
- sourcemaps,
88
- writeGeneratedFiles,
89
- })
90
- executeOperation.addEndCallback(async () => {
91
- await server.stop("execution done")
92
- })
93
- runtimeParams = {
94
- ...runtimeParams,
95
- server,
51
+ if (runtime.type === "browser") {
52
+ if (!devServerOrigin) {
53
+ throw new TypeError(
54
+ `devServerOrigin is required when running tests on browser(s)`,
55
+ )
96
56
  }
97
- resultTransformer = (result) => {
98
- result.server = server
99
- return result
57
+ const devServerStarted = await pingServer(devServerOrigin)
58
+ if (!devServerStarted) {
59
+ throw new Error(
60
+ `dev server not started at ${devServerOrigin}. It is required to run tests`,
61
+ )
100
62
  }
101
63
  }
102
64
 
@@ -27,7 +27,6 @@ export const createRuntimeFromPlaywright = ({
27
27
  type: "browser",
28
28
  name: browserName,
29
29
  version: browserVersion,
30
- needsServer: true,
31
30
  }
32
31
  let browserAndContextPromise
33
32
  runtime.run = async ({
@@ -35,7 +34,7 @@ export const createRuntimeFromPlaywright = ({
35
34
  logger,
36
35
  rootDirectoryUrl,
37
36
  fileRelativeUrl,
38
- server,
37
+ devServerOrigin,
39
38
 
40
39
  // measurePerformance,
41
40
  collectPerformance,
@@ -98,7 +97,19 @@ export const createRuntimeFromPlaywright = ({
98
97
  }
99
98
  await disconnected
100
99
  }
101
- const page = await browserContext.newPage()
100
+ const coverageInHeaders =
101
+ coverageEnabled &&
102
+ (!coveragePlaywrightAPIAvailable ||
103
+ coverageMethodForBrowsers !== "playwright_api")
104
+ const page = await browserContext.newPage({
105
+ extraHTTPHeaders: {
106
+ ...(coverageInHeaders
107
+ ? {
108
+ "x-coverage-istanbul": JSON.stringify(coverageConfig),
109
+ }
110
+ : {}),
111
+ },
112
+ })
102
113
  const closePage = async () => {
103
114
  try {
104
115
  await page.close()
@@ -128,7 +139,7 @@ export const createRuntimeFromPlaywright = ({
128
139
  (v8CoveragesWithWebUrl) => {
129
140
  const fsUrl = moveUrl({
130
141
  url: v8CoveragesWithWebUrl.url,
131
- from: `${server.origin}/`,
142
+ from: `${devServerOrigin}/`,
132
143
  to: rootDirectoryUrl,
133
144
  preferAbsolute: true,
134
145
  })
@@ -202,7 +213,7 @@ export const createRuntimeFromPlaywright = ({
202
213
  })
203
214
  }
204
215
 
205
- const fileClientUrl = new URL(fileRelativeUrl, `${server.origin}/`).href
216
+ const fileClientUrl = new URL(fileRelativeUrl, `${devServerOrigin}/`).href
206
217
 
207
218
  // https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-console
208
219
  const removeConsoleListener = registerEvent({
@@ -302,7 +313,7 @@ export const createRuntimeFromPlaywright = ({
302
313
  const { exceptionSource } = returnValue
303
314
  const error = evalException(exceptionSource, {
304
315
  rootDirectoryUrl,
305
- server,
316
+ devServerOrigin,
306
317
  transformErrorHook,
307
318
  })
308
319
  cb({
@@ -525,13 +536,13 @@ const registerEvent = ({ object, eventType, callback }) => {
525
536
 
526
537
  const evalException = (
527
538
  exceptionSource,
528
- { rootDirectoryUrl, server, transformErrorHook },
539
+ { rootDirectoryUrl, devServerOrigin, transformErrorHook },
529
540
  ) => {
530
541
  const script = new Script(exceptionSource, { filename: "" })
531
542
  const error = script.runInThisContext()
532
543
  if (error && error instanceof Error) {
533
544
  const remoteRootRegexp = new RegExp(
534
- escapeRegexpSpecialChars(`${server.origin}/`),
545
+ escapeRegexpSpecialChars(`${devServerOrigin}/`),
535
546
  "g",
536
547
  )
537
548
  error.stack = error.stack.replace(remoteRootRegexp, rootDirectoryUrl)
package/src/main.js CHANGED
@@ -21,6 +21,9 @@ export { nodeWorkerThread } from "./execute/runtimes/node/node_worker_thread.js"
21
21
  export { build } from "./build/build.js"
22
22
  export { startBuildServer } from "./build/start_build_server.js"
23
23
 
24
+ // helpers
25
+ export { pingServer } from "./ping_server.js"
26
+
24
27
  // advanced
25
28
  export { execute } from "./execute/execute.js"
26
29
  export { jsenvPluginInjectGlobals } from "./plugins/inject_globals/jsenv_plugin_inject_globals.js"
@@ -28,18 +28,14 @@ export const createKitchen = ({
28
28
  logLevel,
29
29
 
30
30
  rootDirectoryUrl,
31
- scenario,
31
+ scenarios,
32
32
  runtimeCompat,
33
33
  // during dev/test clientRuntimeCompat is a single runtime
34
34
  // during build clientRuntimeCompat is runtimeCompat
35
35
  clientRuntimeCompat = runtimeCompat,
36
36
  urlGraph,
37
37
  plugins,
38
- sourcemaps = {
39
- dev: "inline", // "programmatic" and "file" also allowed
40
- test: "inline",
41
- build: "none",
42
- }[scenario],
38
+ sourcemaps = scenarios.dev ? "inline" : "none", // "programmatic" and "file" also allowed
43
39
  sourcemapsSourcesProtocol,
44
40
  sourcemapsSourcesContent,
45
41
  sourcemapsRelativeSources,
@@ -48,7 +44,7 @@ export const createKitchen = ({
48
44
  const logger = createLogger({ logLevel })
49
45
  const pluginController = createPluginController({
50
46
  plugins,
51
- scenario,
47
+ scenarios,
52
48
  })
53
49
  const jsenvDirectoryUrl = new URL(".jsenv/", rootDirectoryUrl).href
54
50
  const kitchenContext = {
@@ -56,7 +52,7 @@ export const createKitchen = ({
56
52
  logger,
57
53
  rootDirectoryUrl,
58
54
  urlGraph,
59
- scenario,
55
+ scenarios,
60
56
  runtimeCompat,
61
57
  clientRuntimeCompat,
62
58
  isSupportedOnCurrentClients: (feature) => {
@@ -769,12 +765,11 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
769
765
  column: reference.specifierColumn,
770
766
  }
771
767
  urlInfo.contentType = reference.contentType
772
- urlInfo.originalContent =
773
- context.scenario === "build"
774
- ? urlInfo.originalContent === undefined
775
- ? reference.content
776
- : urlInfo.originalContent
777
- : reference.content
768
+ urlInfo.originalContent = context.scenarios.build
769
+ ? urlInfo.originalContent === undefined
770
+ ? reference.content
771
+ : urlInfo.originalContent
772
+ : reference.content
778
773
  urlInfo.content = reference.content
779
774
  }
780
775
  }
@@ -18,14 +18,14 @@ export const startOmegaServer = async ({
18
18
  privateKey,
19
19
  certificate,
20
20
  acceptAnyIp,
21
- host,
21
+ hostname,
22
22
  port = 0,
23
23
  keepProcessAlive = false,
24
24
  onStop = () => {},
25
25
  services = [],
26
26
 
27
27
  rootDirectoryUrl,
28
- scenario,
28
+ scenarios,
29
29
  runtimeCompat,
30
30
 
31
31
  plugins,
@@ -62,7 +62,7 @@ export const startOmegaServer = async ({
62
62
  certificate,
63
63
  privateKey,
64
64
  acceptAnyIp,
65
- host,
65
+ hostname,
66
66
  port,
67
67
  requestWaitingMs: 60_1000,
68
68
  services: [
@@ -87,7 +87,7 @@ export const startOmegaServer = async ({
87
87
  serverEventsDispatcher,
88
88
 
89
89
  rootDirectoryUrl,
90
- scenario,
90
+ scenarios,
91
91
  runtimeCompat,
92
92
 
93
93
  plugins,
@@ -20,7 +20,7 @@ export const createFileService = ({
20
20
  serverEventsDispatcher,
21
21
 
22
22
  rootDirectoryUrl,
23
- scenario,
23
+ scenarios,
24
24
  runtimeCompat,
25
25
 
26
26
  plugins,
@@ -53,7 +53,7 @@ export const createFileService = ({
53
53
  ".jsenv/": false,
54
54
  }
55
55
 
56
- if (scenario === "dev") {
56
+ if (scenarios.dev) {
57
57
  const stopWatchingClientFiles = registerDirectoryLifecycle(
58
58
  rootDirectoryUrl,
59
59
  {
@@ -99,13 +99,13 @@ export const createFileService = ({
99
99
  })
100
100
  urlInfo.isValid = () => watch
101
101
  },
102
- includeOriginalUrls: scenario === "dev",
102
+ includeOriginalUrls: scenarios.dev,
103
103
  })
104
104
  const kitchen = createKitchen({
105
105
  signal,
106
106
  logLevel,
107
107
  rootDirectoryUrl,
108
- scenario,
108
+ scenarios,
109
109
  runtimeCompat,
110
110
  clientRuntimeCompat: {
111
111
  [runtimeName]: runtimeVersion,
@@ -115,7 +115,6 @@ export const createFileService = ({
115
115
  ...plugins,
116
116
  ...getCorePlugins({
117
117
  rootDirectoryUrl,
118
- scenario,
119
118
  runtimeCompat,
120
119
 
121
120
  urlAnalysis,
@@ -156,7 +155,7 @@ export const createFileService = ({
156
155
  allServerEvents[serverEventName]({
157
156
  rootDirectoryUrl,
158
157
  urlGraph,
159
- scenario,
158
+ scenarios,
160
159
  sendServerEvent: (data) => {
161
160
  serverEventsDispatcher.dispatch({
162
161
  type: serverEventName,
@@ -174,7 +173,7 @@ export const createFileService = ({
174
173
 
175
174
  const context = {
176
175
  rootDirectoryUrl,
177
- scenario,
176
+ scenarios,
178
177
  runtimeName,
179
178
  runtimeVersion,
180
179
  urlGraph,
@@ -260,10 +259,11 @@ export const createFileService = ({
260
259
  await kitchen.cook(urlInfo, {
261
260
  request,
262
261
  reference,
263
- outDirectoryUrl:
264
- scenario === "dev"
265
- ? `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/`
266
- : `${rootDirectoryUrl}.jsenv/${scenario}/${runtimeName}@${runtimeVersion}/`,
262
+ outDirectoryUrl: scenarios.dev
263
+ ? `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/`
264
+ : `${rootDirectoryUrl}.jsenv/${
265
+ scenarios.test ? "test" : "build"
266
+ }/${runtimeName}@${runtimeVersion}/`,
267
267
  })
268
268
  let { response } = urlInfo
269
269
  if (response) {
@@ -0,0 +1,30 @@
1
+ import { createServer } from "node:net"
2
+
3
+ export const pingServer = async (url) => {
4
+ const server = createServer()
5
+ const { hostname, port } = new URL(url)
6
+
7
+ try {
8
+ await new Promise((resolve, reject) => {
9
+ server.on("error", reject)
10
+ server.on("listening", () => {
11
+ resolve()
12
+ })
13
+ server.listen(port, hostname)
14
+ })
15
+ } catch (error) {
16
+ if (error && error.code === "EADDRINUSE") {
17
+ return true
18
+ }
19
+ if (error && error.code === "EACCES") {
20
+ return true
21
+ }
22
+ throw error
23
+ }
24
+ await new Promise((resolve, reject) => {
25
+ server.on("error", reject)
26
+ server.on("close", resolve)
27
+ server.close()
28
+ })
29
+ return false
30
+ }
@@ -3,13 +3,9 @@ import { jsenvPluginAutoreloadClient } from "./jsenv_plugin_autoreload_client.js
3
3
  import { jsenvPluginAutoreloadServer } from "./jsenv_plugin_autoreload_server.js"
4
4
 
5
5
  export const jsenvPluginAutoreload = ({
6
- scenario,
7
6
  clientFileChangeCallbackList,
8
7
  clientFilesPruneCallbackList,
9
8
  }) => {
10
- if (scenario === "build") {
11
- return []
12
- }
13
9
  return [
14
10
  jsenvPluginHmr(),
15
11
  jsenvPluginAutoreloadClient(),
@@ -13,7 +13,7 @@ export const jsenvPluginAutoreloadClient = () => {
13
13
 
14
14
  return {
15
15
  name: "jsenv:autoreload_client",
16
- appliesDuring: { dev: true },
16
+ appliesDuring: { dev: true, test: false },
17
17
  transformUrlContent: {
18
18
  html: (htmlUrlInfo, context) => {
19
19
  const htmlAst = parseHtmlString(htmlUrlInfo.content)
@@ -6,7 +6,7 @@ export const jsenvPluginAutoreloadServer = ({
6
6
  }) => {
7
7
  return {
8
8
  name: "jsenv:autoreload_server",
9
- appliesDuring: { dev: true },
9
+ appliesDuring: { dev: true, test: false },
10
10
  serverEvents: {
11
11
  reload: ({ sendServerEvent, rootDirectoryUrl, urlGraph }) => {
12
12
  const formatUrlForClient = (url) => {
@@ -1,7 +1,7 @@
1
1
  export const jsenvPluginHmr = () => {
2
2
  return {
3
3
  name: "jsenv:hmr",
4
- appliesDuring: { dev: true },
4
+ appliesDuring: { dev: true, test: false },
5
5
  redirectUrl: (reference) => {
6
6
  const urlObject = new URL(reference.url)
7
7
  if (!urlObject.searchParams.has("hmr")) {
@@ -18,9 +18,7 @@ export const jsenvPluginBundling = (bundling) => {
18
18
 
19
19
  return {
20
20
  name: "jsenv:bundling",
21
- appliesDuring: {
22
- build: true,
23
- },
21
+ appliesDuring: "build",
24
22
  bundle: {
25
23
  css: bundling.css
26
24
  ? (cssUrlInfos, context) => {
@@ -1,12 +1,9 @@
1
1
  export const jsenvPluginCacheControl = () => {
2
2
  return {
3
3
  name: "jsenv:cache_control",
4
- appliesDuring: {
5
- dev: true,
6
- test: true,
7
- },
4
+ appliesDuring: "dev",
8
5
  augmentResponse: ({ reference }, context) => {
9
- if (context.scenario === "test") {
6
+ if (context.scenarios.test) {
10
7
  // During dev, all files are put into browser cache for 1 hour because:
11
8
  // 1: Browser cache is a temporary directory created by playwright
12
9
  // 2: We assume source files won't be modified while tests are running
@@ -11,7 +11,7 @@ import { createMagicSource } from "@jsenv/sourcemap"
11
11
  import { applyBabelPlugins } from "@jsenv/ast"
12
12
 
13
13
  export const jsenvPluginCommonJsGlobals = () => {
14
- const transformCommonJsGlobals = async (urlInfo, { scenario }) => {
14
+ const transformCommonJsGlobals = async (urlInfo, context) => {
15
15
  if (
16
16
  !urlInfo.content.includes("process.env.NODE_ENV") &&
17
17
  !urlInfo.content.includes("__filename") &&
@@ -22,7 +22,7 @@ export const jsenvPluginCommonJsGlobals = () => {
22
22
  const isJsModule = urlInfo.type === "js_module"
23
23
  const replaceMap = {
24
24
  "process.env.NODE_ENV": `("${
25
- scenario === "dev" || scenario === "test" ? "development" : "production"
25
+ context.scenarios.dev ? "development" : "production"
26
26
  }")`,
27
27
  "global": "globalThis",
28
28
  "__filename": isJsModule
@@ -113,14 +113,10 @@ export const jsenvPluginFileUrls = ({
113
113
  },
114
114
  {
115
115
  name: "jsenv:@fs_resolution",
116
- appliesDuring: {
117
- // during dev and test it's a browser running the code
118
- // so absolute file urls needs to be relativized
119
- dev: true,
120
- test: true,
121
- // during build it's fine to use file:// urls
122
- build: false,
123
- },
116
+ // during dev and test it's a browser running the code
117
+ // so absolute file urls needs to be relativized
118
+ // during build it's fine to use file:// urls
119
+ appliesDuring: "dev",
124
120
  resolveUrl: (reference) => {
125
121
  if (reference.specifier.startsWith("/@fs/")) {
126
122
  const fsRootRelativeUrl = reference.specifier.slice("/@fs/".length)
@@ -43,10 +43,7 @@ export const jsenvPluginHtmlSupervisor = ({
43
43
 
44
44
  return {
45
45
  name: "jsenv:html_supervisor",
46
- appliesDuring: {
47
- dev: true,
48
- test: true,
49
- },
46
+ appliesDuring: "dev",
50
47
  serve: async (request, context) => {
51
48
  if (request.ressource.startsWith("/__get_code_frame__/")) {
52
49
  const { pathname, searchParams } = new URL(request.url)
@@ -16,7 +16,7 @@ export const jsenvPluginImportMetaHot = () => {
16
16
  transformUrlContent: {
17
17
  html: (htmlUrlInfo, context) => {
18
18
  // during build we don't really care to parse html hot dependencies
19
- if (context.scenario === "build") {
19
+ if (context.scenarios.build) {
20
20
  return
21
21
  }
22
22
  const htmlAst = parseHtmlString(htmlUrlInfo.content)
@@ -58,7 +58,7 @@ export const jsenvPluginImportMetaHot = () => {
58
58
  if (importMetaHotPaths.length === 0) {
59
59
  return null
60
60
  }
61
- if (context.scenario === "build") {
61
+ if (context.scenarios.build) {
62
62
  return removeImportMetaHots(urlInfo, importMetaHotPaths)
63
63
  }
64
64
  return injectImportMetaHot(urlInfo, context, importMetaHotClientFileUrl)