@jsenv/core 22.4.0 → 23.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 (106) hide show
  1. package/dist/jsenv_browser_system.js +331 -256
  2. package/dist/jsenv_browser_system.js.map +55 -33
  3. package/dist/jsenv_compile_proxy.js +186 -108
  4. package/dist/jsenv_compile_proxy.js.map +48 -42
  5. package/dist/jsenv_exploring_redirector.js +148 -71
  6. package/dist/jsenv_exploring_redirector.js.map +26 -20
  7. package/dist/jsenv_toolbar.js +215 -104
  8. package/dist/jsenv_toolbar.js.map +39 -26
  9. package/helpers/new_stylesheet/new_stylesheet.js +411 -0
  10. package/{LICENSE → license} +0 -0
  11. package/main.js +8 -7
  12. package/package.json +23 -19
  13. package/readme.md +9 -6
  14. package/src/buildProject.js +3 -7
  15. package/src/execute.js +23 -10
  16. package/src/executeTestPlan.js +0 -4
  17. package/src/importUsingChildProcess.js +36 -32
  18. package/src/internal/{babel-plugin-replace-expressions.js → babel_plugin_replace_expressions.js} +0 -0
  19. package/src/internal/{babel-plugin-transform-import-meta.js → babel_plugin_transform_import_meta.js} +0 -0
  20. package/src/internal/browser-launcher/executeHtmlFile.js +6 -8
  21. package/src/internal/browser-launcher/jsenv-browser-system.js +3 -0
  22. package/src/internal/building/asset_url_versioning.js +5 -9
  23. package/src/internal/building/buildServiceWorker.js +6 -13
  24. package/src/internal/building/buildUsingRollup.js +41 -4
  25. package/src/internal/building/build_logs.js +11 -0
  26. package/src/internal/building/build_stats.js +7 -1
  27. package/src/internal/building/createJsenvRollupPlugin.js +402 -297
  28. package/src/internal/building/css/parseCssRessource.js +67 -71
  29. package/src/internal/building/css/parseCssUrls.js +2 -2
  30. package/src/internal/building/css/{postcss-urlhash-plugin.js → postcss_plugin_url_visitor.js} +43 -21
  31. package/src/internal/building/css/replaceCssUrls.js +17 -14
  32. package/src/internal/building/css_module.js +47 -0
  33. package/src/internal/building/html/parseHtmlRessource.js +44 -43
  34. package/src/internal/building/import_references.js +81 -0
  35. package/src/internal/building/importmap/parseImportmapRessource.js +5 -2
  36. package/src/internal/building/js/minifyJs.js +30 -3
  37. package/src/internal/building/js/parseJsRessource.js +70 -77
  38. package/src/internal/building/json/parseJsonRessource.js +3 -2
  39. package/src/internal/building/parseRessource.js +11 -8
  40. package/src/internal/building/parsing.utils.js +4 -15
  41. package/src/internal/building/ressource_builder.js +142 -114
  42. package/src/internal/building/ressource_builder_util.js +31 -18
  43. package/src/internal/building/{fetchSourcemap.js → sourcemap_loader.js} +29 -27
  44. package/src/internal/building/svg/parseSvgRessource.js +7 -3
  45. package/src/internal/building/url-versioning.js +2 -1
  46. package/src/internal/building/url_fetcher.js +79 -0
  47. package/src/internal/building/url_loader.js +267 -0
  48. package/src/internal/building/url_trace.js +1 -1
  49. package/src/internal/building/webmanifest/parseWebmanifestRessource.js +9 -4
  50. package/src/internal/compiling/{js-compilation-service/ensureGlobalThisImportBabelPlugin.js → babel_plugin_global_this_as_jsenv_import.js} +4 -2
  51. package/src/internal/compiling/babel_plugin_import_assertions.js +100 -0
  52. package/src/internal/compiling/babel_plugin_new_stylesheet_as_jsenv_import.js +109 -0
  53. package/src/internal/compiling/babel_plugin_transform_import_specifier.js +86 -0
  54. package/src/internal/compiling/babel_plugins.js +2 -0
  55. package/src/internal/compiling/createCompiledFileService.js +46 -15
  56. package/src/internal/compiling/html_source_file_service.js +2 -2
  57. package/src/internal/compiling/js-compilation-service/{transformBabelHelperToImportBabelPlugin.js → babel_plugin_babel_helpers_as_jsenv_imports.js} +1 -1
  58. package/src/internal/compiling/js-compilation-service/{ensureRegeneratorRuntimeImportBabelPlugin.js → babel_plugin_regenerator_runtime_as_jsenv_import.js} +1 -1
  59. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +7 -16
  60. package/src/internal/compiling/js-compilation-service/transformJs.js +0 -2
  61. package/src/internal/compiling/jsenvCompilerForHtml.js +2 -7
  62. package/src/internal/compiling/rollup_plugin_commonjs_named_exports.js +2 -2
  63. package/src/internal/compiling/startCompileServer.js +11 -4
  64. package/src/internal/escapeTemplateStringSpecialCharacters.js +20 -0
  65. package/src/internal/executing/coverage/{babel-plugin-instrument.js → babel_plugin_instrument.js} +17 -6
  66. package/src/internal/executing/coverage/relativeUrlToEmptyCoverage.js +1 -1
  67. package/src/internal/executing/executeConcurrently.js +5 -3
  68. package/src/internal/executing/executePlan.js +16 -2
  69. package/src/internal/executing/generateFileExecutionSteps.js +2 -1
  70. package/src/internal/executing/launchAndExecute.js +43 -69
  71. package/src/internal/executing/writeLog.js +25 -18
  72. package/src/internal/exploring/exploring.css +2 -1
  73. package/src/internal/exploring/exploring.redirector.js +0 -1
  74. package/src/internal/generateGroupMap/generateGroupMap.js +14 -10
  75. package/src/internal/generateGroupMap/jsenvBabelPluginCompatMap.js +30 -0
  76. package/src/internal/generateGroupMap/jsenvPluginCompatMap.js +0 -6
  77. package/src/internal/generateGroupMap/one_runtime_compat.js +9 -38
  78. package/src/internal/generateGroupMap/runtime_compat.js +9 -24
  79. package/src/internal/generateGroupMap/runtime_compat_composition.js +2 -12
  80. package/src/internal/generateGroupMap/runtime_support.js +53 -0
  81. package/src/internal/jsenvInternalFiles.js +0 -1
  82. package/src/internal/node-launcher/createControllableNodeProcess.js +2 -3
  83. package/src/internal/response_validation.js +143 -0
  84. package/src/internal/runtime/createBrowserRuntime/createBrowserRuntime.js +8 -3
  85. package/src/internal/runtime/createBrowserRuntime/createBrowserSystem.js +165 -25
  86. package/src/internal/runtime/createBrowserRuntime/displayErrorInDocument.js +7 -6
  87. package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +124 -68
  88. package/src/internal/runtime/createNodeRuntime/createNodeRuntime.js +8 -86
  89. package/src/internal/runtime/createNodeRuntime/createNodeSystem.js +53 -9
  90. package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +115 -0
  91. package/src/internal/runtime/module-registration.js +86 -136
  92. package/src/internal/runtime/resolveGroup.js +2 -3
  93. package/src/internal/toolbar/compilation/toolbar.compilation.js +15 -17
  94. package/src/internal/toolbar/eventsource/toolbar.eventsource.js +35 -8
  95. package/src/internal/toolbar/toolbar.main.js +7 -4
  96. package/src/internal/url_utils.js +33 -0
  97. package/src/internal/url_utils.test.js +39 -0
  98. package/src/jsonToJavaScriptModule.js +12 -0
  99. package/src/launchBrowser.js +50 -34
  100. package/src/launchNode.js +6 -3
  101. package/src/requireUsingChildProcess.js +36 -32
  102. package/src/startExploring.js +25 -11
  103. package/src/internal/building/transformImportMetaUrlReferences.js +0 -71
  104. package/src/internal/runtime/resolveBrowserGroup.js +0 -5
  105. package/src/internal/runtime/resolveNodeGroup.js +0 -5
  106. package/src/internal/validateResponseStatusIsOk.js +0 -91
@@ -18,8 +18,13 @@ export const initToolbarEventSource = ({
18
18
  executedFileRelativeUrl,
19
19
  livereloading,
20
20
  }) => {
21
+ const getLivereloadCallback = (originalFileProjectRelativeUrl) => {
22
+ const callbacks = window.parent.__jsenv__.livereloadingCallbacks
23
+ return callbacks[originalFileProjectRelativeUrl]
24
+ }
25
+
21
26
  removeForceHideElement(document.querySelector("#eventsource-indicator"))
22
- connectEventSource(executedFileRelativeUrl)
27
+ connectEventSource({ executedFileRelativeUrl, getLivereloadCallback })
23
28
  livereloadingAvailableOnServer = livereloading
24
29
  if (!livereloadingAvailableOnServer) {
25
30
  disableLivereloadSetting()
@@ -54,11 +59,18 @@ let eventSourceHooks = {}
54
59
  let eventSourceConnection
55
60
  let connectionReadyPromise
56
61
 
57
- const handleFileChange = (file, type) => {
58
- latestChangeMap[file] = type
62
+ const handleFileChange = ({ file, eventType, livereloadCallback }) => {
63
+ latestChangeMap[file] = eventType
59
64
  updateEventSourceIndicator()
65
+
60
66
  if (shouldLivereload()) {
61
- if (
67
+ if (livereloadCallback) {
68
+ livereloadCallback({
69
+ file,
70
+ latestChangeMap,
71
+ reloadPage,
72
+ })
73
+ } else if (
62
74
  file.endsWith(".css") ||
63
75
  file.endsWith(".scss") ||
64
76
  file.endsWith(".sass")
@@ -109,7 +121,10 @@ const reloadChanges = () => {
109
121
  }
110
122
  }
111
123
 
112
- const connectEventSource = (executedFileRelativeUrl) => {
124
+ const connectEventSource = ({
125
+ executedFileRelativeUrl,
126
+ getLivereloadCallback,
127
+ }) => {
113
128
  updateEventSourceIndicator()
114
129
  connectionReadyPromise = createPromiseAndHooks()
115
130
 
@@ -117,13 +132,25 @@ const connectEventSource = (executedFileRelativeUrl) => {
117
132
  executedFileRelativeUrl,
118
133
  {
119
134
  onFileModified: (file) => {
120
- handleFileChange(file, "modified")
135
+ handleFileChange({
136
+ file,
137
+ eventType: "modified",
138
+ livereloadCallback: getLivereloadCallback(file),
139
+ })
121
140
  },
122
141
  onFileRemoved: (file) => {
123
- handleFileChange(file, "removed")
142
+ handleFileChange({
143
+ file,
144
+ eventType: "removed",
145
+ livereloadCallback: getLivereloadCallback(file),
146
+ })
124
147
  },
125
148
  onFileAdded: (file) => {
126
- handleFileChange(file, "added")
149
+ handleFileChange({
150
+ file,
151
+ eventType: "added",
152
+ livereloadCallback: getLivereloadCallback(file),
153
+ })
127
154
  },
128
155
  onConnecting: ({ cancel }) => {
129
156
  eventSourceState = "connecting"
@@ -80,7 +80,10 @@ const renderToolbar = async () => {
80
80
  renderCompilationInToolbar({ compileGroup })
81
81
  // this might become active but we need to detect this somehow
82
82
  deactivateToolbarSection(document.querySelector("#file-list-link"))
83
- initToolbarEventSource({ executedFileRelativeUrl, livereloading })
83
+ initToolbarEventSource({
84
+ executedFileRelativeUrl,
85
+ livereloading,
86
+ })
84
87
 
85
88
  // if user click enter or space quickly while closing toolbar
86
89
  // it will cancel the closing
@@ -188,13 +191,13 @@ const getCompileGroup = ({
188
191
  outDirectoryRelativeUrl,
189
192
  compileServerOrigin,
190
193
  }) => {
191
- const outDirectoryRemoteUrl = String(
194
+ const outDirectoryServerUrl = String(
192
195
  new URL(outDirectoryRelativeUrl, compileServerOrigin),
193
196
  )
194
- if (urlIsInsideOf(executedFileCompiledUrl, outDirectoryRemoteUrl)) {
197
+ if (urlIsInsideOf(executedFileCompiledUrl, outDirectoryServerUrl)) {
195
198
  const afterCompileDirectory = urlToRelativeUrl(
196
199
  executedFileCompiledUrl,
197
- outDirectoryRemoteUrl,
200
+ outDirectoryServerUrl,
198
201
  )
199
202
  const slashIndex = afterCompileDirectory.indexOf("/")
200
203
  const fileRelativeUrl = afterCompileDirectory.slice(slashIndex + 1)
@@ -0,0 +1,33 @@
1
+ import { urlToOrigin, urlToRessource, urlToExtension } from "@jsenv/filesystem"
2
+
3
+ export const setUrlExtension = (url, extension) => {
4
+ const origin = urlToOrigin(url)
5
+ const currentExtension = urlToExtension(url)
6
+ const ressource = urlToRessource(url)
7
+ const [pathname, search] = ressource.split("?")
8
+ const pathnameWithoutExtension = currentExtension
9
+ ? pathname.slice(0, -currentExtension.length)
10
+ : pathname
11
+ const newPathname = `${pathnameWithoutExtension}${extension}`
12
+ return `${origin}${newPathname}${search ? `?${search}` : ""}`
13
+ }
14
+
15
+ export const getUrlSearchParamsDescriptor = (url) => {
16
+ const urlObject = new URL(url)
17
+ const { searchParams } = urlObject
18
+ const searchParamsDescriptor = {}
19
+ Array.from(searchParams.keys()).forEach((key) => {
20
+ const value = searchParams.getAll(key)
21
+ searchParamsDescriptor[key] = value.length === 1 ? value[0] : value
22
+ })
23
+ return searchParamsDescriptor
24
+ }
25
+
26
+ export const setUrlSearchParamsDescriptor = (url, searchParamsDescriptor) => {
27
+ const urlObject = new URL(url)
28
+ const { searchParams } = urlObject
29
+ Object.keys(searchParamsDescriptor).forEach((key) => {
30
+ searchParams.set(key, searchParamsDescriptor[key])
31
+ })
32
+ return String(urlObject)
33
+ }
@@ -0,0 +1,39 @@
1
+ import { assert } from "@jsenv/assert"
2
+
3
+ import { setUrlExtension } from "./url_utils.js"
4
+
5
+ {
6
+ const actual = setUrlExtension(`http://example.com/file.jsx`, ".js")
7
+ const expected = "http://example.com/file.js"
8
+ assert({ actual, expected })
9
+ }
10
+
11
+ {
12
+ const actual = setUrlExtension(`http://example.com/file.mjsx?foo=bar`, ".js")
13
+ const expected = "http://example.com/file.js?foo=bar"
14
+ assert({ actual, expected })
15
+ }
16
+
17
+ {
18
+ const actual = setUrlExtension(`http://example.com/file.?foo=bar`, ".js")
19
+ const expected = "http://example.com/file.js?foo=bar"
20
+ assert({ actual, expected })
21
+ }
22
+
23
+ {
24
+ const actual = setUrlExtension(`http://example.com/file?foo=bar`, ".js")
25
+ const expected = "http://example.com/file.js?foo=bar"
26
+ assert({ actual, expected })
27
+ }
28
+
29
+ {
30
+ const actual = setUrlExtension(`http://example.com/file.js?foo=bar`, ".")
31
+ const expected = "http://example.com/file.?foo=bar"
32
+ assert({ actual, expected })
33
+ }
34
+
35
+ {
36
+ const actual = setUrlExtension(`http://example.com/file.js?foo=bar`, "")
37
+ const expected = "http://example.com/file?foo=bar"
38
+ assert({ actual, expected })
39
+ }
@@ -0,0 +1,12 @@
1
+ export const jsonToJavaScriptModule = async ({ code, url }) => {
2
+ const codeAsJson = JSON.stringify(code)
3
+
4
+ return {
5
+ compiledSource: `export default ${codeAsJson}`,
6
+ contentType: "application/javascript",
7
+ sources: [url],
8
+ sourcesContent: [code],
9
+ assets: [],
10
+ assetsContent: [],
11
+ }
12
+ }
@@ -5,11 +5,12 @@ import {
5
5
  createCancellationToken,
6
6
  createStoppableOperation,
7
7
  } from "@jsenv/cancellation"
8
+ import { createDetailedMessage } from "@jsenv/logger"
8
9
  import { teardownSignal } from "@jsenv/node-signals"
9
10
 
10
11
  import { trackRessources } from "./internal/trackRessources.js"
11
12
  import { fetchUrl } from "./internal/fetchUrl.js"
12
- import { validateResponseStatusIsOk } from "./internal/validateResponseStatusIsOk.js"
13
+ import { validateResponse } from "./internal/response_validation.js"
13
14
  import { trackPageToNotify } from "./internal/browser-launcher/trackPageToNotify.js"
14
15
  import { createSharing } from "./internal/browser-launcher/createSharing.js"
15
16
  import { executeHtmlFile } from "./internal/browser-launcher/executeHtmlFile.js"
@@ -20,8 +21,11 @@ import {
20
21
  } from "./playwright_browser_versions.js"
21
22
 
22
23
  const chromiumSharing = createSharing()
23
-
24
- export const launchChromium = async ({
24
+ export const chromiumRuntime = {
25
+ name: "chromium",
26
+ version: PLAYWRIGHT_CHROMIUM_VERSION,
27
+ }
28
+ chromiumRuntime.launch = async ({
25
29
  browserServerLogLevel,
26
30
  cancellationToken = createCancellationToken(),
27
31
  chromiumExecutablePath,
@@ -91,9 +95,11 @@ export const launchChromium = async ({
91
95
  cancellationToken,
92
96
  ignoreHttpsError: true,
93
97
  })
94
- const { valid, message } = await validateResponseStatusIsOk(browserResponse)
95
- if (!valid) {
96
- throw new Error(message)
98
+ const { isValid, message, details } = await validateResponse(
99
+ browserResponse,
100
+ )
101
+ if (!isValid) {
102
+ throw new Error(createDetailedMessage(message, details))
97
103
  }
98
104
 
99
105
  const browserResponseObject = JSON.parse(browserResponse.body)
@@ -103,8 +109,6 @@ export const launchChromium = async ({
103
109
 
104
110
  return {
105
111
  browser,
106
- runtimeName: "chromium",
107
- runtimeVersion: PLAYWRIGHT_CHROMIUM_VERSION,
108
112
  stop: ressourceTracker.cleanup,
109
113
  ...browserToRuntimeHooks(browser, {
110
114
  browserServerLogLevel,
@@ -124,16 +128,21 @@ export const launchChromium = async ({
124
128
  }),
125
129
  }
126
130
  }
127
-
128
- export const launchChromiumTab = (namedArgs) =>
129
- launchChromium({
130
- share: true,
131
- ...namedArgs,
132
- })
131
+ export const chromiumTabRuntime = {
132
+ ...chromiumRuntime,
133
+ launch: (params) =>
134
+ chromiumRuntime.launch({
135
+ shared: true,
136
+ ...params,
137
+ }),
138
+ }
133
139
 
134
140
  const firefoxSharing = createSharing()
135
-
136
- export const launchFirefox = async ({
141
+ export const firefoxRuntime = {
142
+ name: "firefox",
143
+ version: PLAYWRIGHT_FIREFOX_VERSION,
144
+ }
145
+ firefoxRuntime.launch = async ({
137
146
  cancellationToken = createCancellationToken(),
138
147
  firefoxExecutablePath,
139
148
  browserServerLogLevel,
@@ -179,8 +188,6 @@ export const launchFirefox = async ({
179
188
 
180
189
  return {
181
190
  browser,
182
- runtimeName: "firefox",
183
- runtimeVersion: PLAYWRIGHT_FIREFOX_VERSION,
184
191
  stop: ressourceTracker.cleanup,
185
192
  ...browserToRuntimeHooks(browser, {
186
193
  browserServerLogLevel,
@@ -199,16 +206,21 @@ export const launchFirefox = async ({
199
206
  }),
200
207
  }
201
208
  }
202
-
203
- export const launchFirefoxTab = (namedArgs) =>
204
- launchFirefox({
205
- share: true,
206
- ...namedArgs,
207
- })
209
+ export const firefoxTabRuntime = {
210
+ ...firefoxRuntime,
211
+ launch: (params) =>
212
+ firefoxRuntime.launch({
213
+ shared: true,
214
+ ...params,
215
+ }),
216
+ }
208
217
 
209
218
  const webkitSharing = createSharing()
210
-
211
- export const launchWebkit = async ({
219
+ export const webkitRuntime = {
220
+ name: "webkit",
221
+ version: PLAYWRIGHT_WEBKIT_VERSION,
222
+ }
223
+ webkitRuntime.launch = async ({
212
224
  browserServerLogLevel,
213
225
  cancellationToken = createCancellationToken(),
214
226
  webkitExecutablePath,
@@ -254,8 +266,7 @@ export const launchWebkit = async ({
254
266
 
255
267
  return {
256
268
  browser,
257
- runtimeName: "webkit",
258
- runtimeVersion: PLAYWRIGHT_WEBKIT_VERSION,
269
+
259
270
  stop: ressourceTracker.cleanup,
260
271
  ...browserToRuntimeHooks(browser, {
261
272
  browserServerLogLevel,
@@ -274,12 +285,14 @@ export const launchWebkit = async ({
274
285
  }),
275
286
  }
276
287
  }
277
-
278
- export const launchWebkitTab = (namedArgs) =>
279
- launchWebkit({
280
- share: true,
281
- ...namedArgs,
282
- })
288
+ export const webkitTabRuntime = {
289
+ ...webkitRuntime,
290
+ launch: (params) =>
291
+ webkitRuntime.launch({
292
+ shared: true,
293
+ ...params,
294
+ }),
295
+ }
283
296
 
284
297
  const launchBrowser = async (
285
298
  browserName,
@@ -437,5 +450,8 @@ const isTargetClosedError = (error) => {
437
450
  if (error.message.match(/Protocol error \(.*?\): Browser.*?closed/)) {
438
451
  return true
439
452
  }
453
+ if (error.message.includes("browserContext.close: Browser closed")) {
454
+ return true
455
+ }
440
456
  return false
441
457
  }
package/src/launchNode.js CHANGED
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable import/max-dependencies */
2
- import { Script } from "vm"
3
-
2
+ import { Script } from "node:vm"
4
3
  import cuid from "cuid"
5
4
  import { loggerToLogLevel } from "@jsenv/logger"
6
5
  import { createCancellationToken } from "@jsenv/cancellation"
@@ -17,7 +16,11 @@ import { escapeRegexpSpecialCharacters } from "./internal/escapeRegexpSpecialCha
17
16
  import { createControllableNodeProcess } from "./internal/node-launcher/createControllableNodeProcess.js"
18
17
  import { v8CoverageFromNodeV8Directory } from "./internal/executing/coverage/v8CoverageFromNodeV8Directory.js"
19
18
 
20
- export const launchNode = async ({
19
+ export const nodeRuntime = {
20
+ name: "node",
21
+ version: process.version.slice(1),
22
+ }
23
+ nodeRuntime.launch = async ({
21
24
  logger,
22
25
  logProcessCommand,
23
26
  cancellationToken = createCancellationToken(),
@@ -18,41 +18,45 @@ export const requireUsingChildProcess = async (
18
18
  const result = await launchAndExecute({
19
19
  stopAfterExecute: true,
20
20
  fileRelativeUrl: String(fileUrl),
21
- launch: async () => {
22
- const controllableNodeProcess = await createControllableNodeProcess({
23
- logLevel,
24
- debugPort,
25
- debugMode,
26
- debugModeInheritBreak,
27
- env,
28
- commandLineOptions,
29
- stdin,
30
- stdout,
31
- stderr,
32
- })
21
+ runtime: {
22
+ name: "node",
23
+ version: process.version.slice(1),
24
+ launch: async () => {
25
+ const controllableNodeProcess = await createControllableNodeProcess({
26
+ logLevel,
27
+ debugPort,
28
+ debugMode,
29
+ debugModeInheritBreak,
30
+ env,
31
+ commandLineOptions,
32
+ stdin,
33
+ stdout,
34
+ stderr,
35
+ })
33
36
 
34
- return {
35
- ...controllableNodeProcess,
36
- execute: async () => {
37
- try {
38
- const namespace =
39
- await controllableNodeProcess.requestActionOnChildProcess({
40
- actionType: "execute-using-require",
41
- actionParams: { fileUrl },
42
- })
37
+ return {
38
+ ...controllableNodeProcess,
39
+ execute: async () => {
40
+ try {
41
+ const namespace =
42
+ await controllableNodeProcess.requestActionOnChildProcess({
43
+ actionType: "execute-using-require",
44
+ actionParams: { fileUrl },
45
+ })
43
46
 
44
- return {
45
- status: "ok",
46
- namespace,
47
+ return {
48
+ status: "ok",
49
+ namespace,
50
+ }
51
+ } catch (e) {
52
+ return {
53
+ status: "errored",
54
+ error: e,
55
+ }
47
56
  }
48
- } catch (e) {
49
- return {
50
- status: "errored",
51
- error: e,
52
- }
53
- }
54
- },
55
- }
57
+ },
58
+ }
59
+ },
56
60
  },
57
61
  })
58
62
  if (result.status === "errored") {
@@ -54,6 +54,7 @@ export const startExploring = async ({
54
54
  compileServerPrivateKey,
55
55
  customCompilers,
56
56
  livereloadWatchConfig,
57
+ jsenvDirectoryClean,
57
58
  }) => {
58
59
  const jsenvStartExploringFunction = async ({ jsenvCancellationToken }) => {
59
60
  cancellationToken = composeCancellationToken(
@@ -117,6 +118,7 @@ export const startExploring = async ({
117
118
  babelPluginMap,
118
119
  runtimeSupport: runtimeSupportDuringDev,
119
120
  livereloadWatchConfig,
121
+ jsenvDirectoryClean,
120
122
  })
121
123
 
122
124
  return compileServer
@@ -145,6 +147,19 @@ const createRedirectFilesService = ({ projectDirectoryUrl }) => {
145
147
  projectDirectoryUrl,
146
148
  )
147
149
 
150
+ // unfortunately browser resolves sourcemap to url before redirection (not after).
151
+ // It means browser tries to load source map from "/.jsenv/jsenv-toolbar.js.map"
152
+ // we could also inline sourcemap but it's not yet possible
153
+ // inside buildProject
154
+ const jsenvExploringIndexSourcemapInfo = {
155
+ pathForBrowser: `/.jsenv/jsenv_exploring_index.js.map`,
156
+ pathForServer: `/${jsenvExploringJsBuildRelativeUrlForProject}.map`,
157
+ }
158
+ const jsenvToolbarSourcemapInfo = {
159
+ pathForBrowser: `/.jsenv/jsenv_toolbar.js.map`,
160
+ pathForServer: `/${jsenvToolbarJsBuildRelativeUrlForProject}.map`,
161
+ }
162
+
148
163
  return (request) => {
149
164
  // exploring redirection
150
165
  if (request.ressource === "/") {
@@ -176,6 +191,14 @@ const createRedirectFilesService = ({ projectDirectoryUrl }) => {
176
191
  },
177
192
  }
178
193
  }
194
+ if (request.ressource === jsenvExploringIndexSourcemapInfo.pathForBrowser) {
195
+ return {
196
+ status: 307,
197
+ headers: {
198
+ location: `${request.origin}${jsenvExploringIndexSourcemapInfo.pathForServer}`,
199
+ },
200
+ }
201
+ }
179
202
 
180
203
  // toolbar
181
204
  if (request.ressource === "/.jsenv/toolbar.main.js") {
@@ -187,20 +210,11 @@ const createRedirectFilesService = ({ projectDirectoryUrl }) => {
187
210
  },
188
211
  }
189
212
  }
190
- // unfortunately browser don't resolve sourcemap to url after redirection
191
- // but to url before. It means browser tries to load source map from
192
- // "/.jsenv/jsenv-toolbar.js.map"
193
- // we could also inline sourcemap but it's not yet possible
194
- // inside buildProject
195
- if (
196
- request.ressource ===
197
- `/.jsenv/${jsenvToolbarJsFileInfo.sourcemapFilename}`
198
- ) {
199
- const jsenvToolbarJsBuildSourcemapServerUrl = `${request.origin}/${jsenvToolbarJsBuildRelativeUrlForProject}.map`
213
+ if (request.ressource === jsenvToolbarSourcemapInfo.pathForBrowser) {
200
214
  return {
201
215
  status: 307,
202
216
  headers: {
203
- location: jsenvToolbarJsBuildSourcemapServerUrl,
217
+ location: `${request.origin}${jsenvToolbarSourcemapInfo.pathForServer}`,
204
218
  },
205
219
  }
206
220
  }
@@ -1,71 +0,0 @@
1
- import { resolveUrl } from "@jsenv/filesystem"
2
-
3
- import { referenceToCodeForRollup } from "./ressource_builder.js"
4
-
5
- export const transformImportMetaUrlReferences = async ({
6
- url,
7
- // importerUrl,
8
- code,
9
- ast,
10
- ressourceBuilder,
11
- markBuildRelativeUrlAsUsedByJs,
12
- }) => {
13
- const { default: MagicString } = await import("magic-string")
14
- const magicString = new MagicString(code)
15
-
16
- const { asyncWalk } = await import("estree-walker")
17
-
18
- await asyncWalk(ast, {
19
- enter: async (node) => {
20
- if (!isNewUrlImportMetaUrl(node)) {
21
- return
22
- }
23
- const relativeUrl = node.arguments[0].value
24
-
25
- const ressourceUrl = resolveUrl(relativeUrl, url)
26
-
27
- const reference = await ressourceBuilder.createReferenceFoundInJsModule({
28
- jsUrl: url,
29
- ...(node.loc
30
- ? {
31
- jsLine: node.loc.start.line,
32
- jsColumn: node.loc.start.column,
33
- }
34
- : {}),
35
-
36
- ressourceSpecifier: ressourceUrl,
37
- })
38
- if (reference) {
39
- magicString.overwrite(
40
- node.start,
41
- node.end,
42
- referenceToCodeForRollup(reference),
43
- )
44
- markBuildRelativeUrlAsUsedByJs(reference.ressource.buildRelativeUrl)
45
- }
46
- },
47
- })
48
-
49
- const codeOutput = magicString.toString()
50
- const map = magicString.generateMap({ hires: true })
51
-
52
- return {
53
- code: codeOutput,
54
- map,
55
- }
56
- }
57
-
58
- const isNewUrlImportMetaUrl = (node) => {
59
- return (
60
- node.type === "NewExpression" &&
61
- node.callee.type === "Identifier" &&
62
- node.callee.name === "URL" &&
63
- node.arguments.length === 2 &&
64
- node.arguments[0].type === "Literal" &&
65
- typeof node.arguments[0].value === "string" &&
66
- node.arguments[1].type === "MemberExpression" &&
67
- node.arguments[1].object.type === "MetaProperty" &&
68
- node.arguments[1].property.type === "Identifier" &&
69
- node.arguments[1].property.name === "url"
70
- )
71
- }
@@ -1,5 +0,0 @@
1
- import { detectBrowser } from "./detectBrowser/detectBrowser.js"
2
- import { resolveGroup } from "./resolveGroup.js"
3
-
4
- export const resolveBrowserGroup = (groupMap) =>
5
- resolveGroup(detectBrowser(), groupMap)
@@ -1,5 +0,0 @@
1
- import { detectNode } from "./detectNode/detectNode.js"
2
- import { resolveGroup } from "./resolveGroup.js"
3
-
4
- export const resolveNodeGroup = (groupMap) =>
5
- resolveGroup(detectNode(), groupMap)