@jsenv/core 25.2.1 → 25.4.1
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/dist/browser_runtime/asset-manifest.json +2 -2
- package/dist/browser_runtime/{browser_runtime_91c5a3b8.js → browser_runtime_0e3396a1.js} +15 -16
- package/dist/browser_runtime/{browser_runtime_91c5a3b8.js.map → browser_runtime_0e3396a1.js.map} +13 -13
- package/dist/build_manifest.js +5 -5
- package/dist/compile_proxy/asset-manifest.json +2 -2
- package/dist/compile_proxy/compile_proxy.html__inline__20_f4285042.js.map +343 -0
- package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_ab528227.html} +358 -397
- package/dist/redirector/asset-manifest.json +2 -2
- package/dist/redirector/redirector.html__inline__12_404b8295.js.map +349 -0
- package/dist/redirector/{redirector_3e9a97b9.html → redirector_6df2620a.html} +369 -407
- package/dist/toolbar/asset-manifest.json +2 -2
- package/dist/toolbar/toolbar.main_279b3a68.js.map +764 -0
- package/dist/toolbar/{toolbar_361afb84.html → toolbar_0a91ca3b.html} +1509 -1583
- package/dist/toolbar_injector/asset-manifest.json +2 -2
- package/dist/toolbar_injector/{toolbar_injector_fac1e995.js → toolbar_injector_34f6ad8e.js} +18 -15
- package/dist/toolbar_injector/{toolbar_injector_fac1e995.js.map → toolbar_injector_34f6ad8e.js.map} +15 -15
- package/package.json +16 -12
- package/readme.md +54 -54
- package/src/buildProject.js +31 -26
- package/src/dev_server.js +111 -92
- package/src/execute.js +3 -8
- package/src/internal/browser_launcher/{browser_runtime_report.js → browser_runtime_profile.js} +21 -15
- package/src/internal/browser_launcher/executeHtmlFile.js +22 -14
- package/src/internal/browser_launcher/from_playwright.js +6 -4
- package/src/internal/browser_runtime/browser_runtime.js +12 -14
- package/src/internal/browser_runtime/createBrowserRuntime.js +7 -6
- package/src/internal/browser_utils/fetchAndEvalUsingFetch.js +1 -1
- package/src/internal/browser_utils/fetchJson.js +1 -1
- package/src/internal/browser_utils/{fetch-browser.js → fetch_browser.js} +0 -2
- package/src/internal/building/buildUsingRollup.js +41 -57
- package/src/internal/building/html/parseHtmlRessource.js +2 -1
- package/src/internal/building/rollup_plugin_jsenv.js +28 -8
- package/src/internal/compiling/babel_parse_error.js +9 -0
- package/src/internal/{babel_plugin_transform_import_meta.js → compiling/babel_plugin_transform_import_meta.js} +58 -9
- package/src/internal/compiling/compileFile.js +2 -2
- package/src/internal/compiling/compileHtml.js +1 -1
- package/src/internal/compiling/createCompiledFileService.js +25 -74
- package/src/internal/compiling/js-compilation-service/transformJs.js +153 -23
- package/src/internal/compiling/jsenvCompilerForHtml.js +29 -32
- package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -2
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -4
- package/src/internal/compiling/jsenv_directory/comparison_utils.js +24 -0
- package/src/internal/compiling/{compile-directory/compile-asset.js → jsenv_directory/compile_asset.js} +0 -0
- package/src/internal/compiling/jsenv_directory/compile_context.js +68 -0
- package/src/internal/compiling/jsenv_directory/compile_profile.js +218 -0
- package/src/internal/compiling/{compile-directory/createLockRegistry.js → jsenv_directory/file_lock_registry.js} +0 -0
- package/src/internal/compiling/{compile-directory/createLockRegistry.test.js → jsenv_directory/file_lock_registry.test.js} +2 -1
- package/src/internal/compiling/{compile-directory → jsenv_directory}/fs-optimized-for-cache.js +0 -0
- package/src/internal/compiling/{compile-directory → jsenv_directory}/getOrGenerateCompiledFile.js +2 -2
- package/src/internal/compiling/jsenv_directory/jsenv_directory.js +174 -0
- package/src/internal/compiling/{compile-directory → jsenv_directory}/updateMeta.js +1 -1
- package/src/internal/compiling/{compile-directory → jsenv_directory}/validateCache.js +0 -0
- package/src/internal/compiling/sse_service/sse_service.js +369 -0
- package/src/internal/compiling/startCompileServer.js +157 -804
- package/src/internal/compiling/transformResultToCompilationResult.js +2 -2
- package/src/internal/dev_server/exploring/exploring.js +10 -8
- package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +92 -78
- package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
- package/src/internal/dev_server/toolbar/toolbar.html +46 -16
- package/src/internal/dev_server/toolbar/toolbar.injector.js +17 -15
- package/src/internal/dev_server/toolbar/toolbar.main.js +12 -16
- package/src/internal/executing/executeConcurrently.js +1 -1
- package/src/internal/executing/executePlan.js +2 -3
- package/src/internal/{generateGroupMap → features}/babel_plugins_compatibility.js +8 -8
- package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +20 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +23 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +25 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +37 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +9 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +14 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detection.js +89 -0
- package/src/internal/{browser_feature_detection → features/browser_feature_detection}/compile_proxy.html +1 -1
- package/src/internal/features/browser_feature_detection/execute_with_script_module.js +24 -0
- package/src/internal/features/features_compat_from_runtime.js +38 -0
- package/src/internal/features/features_compat_from_runtime_support.js +31 -0
- package/src/internal/{generateGroupMap → features}/features_compatibility.js +3 -3
- package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_dynamic_import.mjs +0 -0
- package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_top_level_await.mjs +0 -0
- package/src/internal/{node_feature_detection/nodeSupportsDynamicImport.js → features/node_feature_detection/node_feature_detect_dynamic_import.js} +0 -0
- package/src/internal/{node_feature_detection/nodeSupportsTopLevelAwait.js → features/node_feature_detection/node_feature_detect_top_level_await.js} +0 -0
- package/src/internal/features/node_feature_detection/node_feature_detection.js +66 -0
- package/src/internal/jsenv_remote_directory.js +1 -1
- package/src/internal/node_launcher/createControllableNodeProcess.js +4 -3
- package/src/internal/node_launcher/node_runtime_report.js +15 -9
- package/src/internal/node_runtime/fetchSource.js +2 -4
- package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
- package/src/internal/redirector/redirector.html +40 -0
- package/src/internal/{generateGroupMap/jsenvRuntimeSupport.js → runtime_support/jsenv_runtime_support.js} +0 -0
- package/src/internal/{generateGroupMap → runtime_support}/runtime_support.js +0 -0
- package/src/internal/url_conversion.js +12 -17
- package/src/launchNode.js +29 -41
- package/dist/compile_proxy/compile_proxy.html__inline__20_809f35f7.js.map +0 -392
- package/dist/redirector/redirector.html__inline__15_e391410e.js.map +0 -397
- package/dist/toolbar/toolbar.main_6c1b3d82.js.map +0 -802
- package/src/internal/CONSTANTS.js +0 -11
- package/src/internal/browser_feature_detection/browser_feature_detection.js +0 -274
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +0 -242
- package/src/internal/dev_server/redirector/redirector.html +0 -48
- package/src/internal/generateGroupMap/generateGroupMap.js +0 -65
- package/src/internal/generateGroupMap/one_runtime_compat.js +0 -38
- package/src/internal/generateGroupMap/runtime_compat.js +0 -34
- package/src/internal/generateGroupMap/runtime_compat_composition.js +0 -76
- package/src/internal/generateGroupMap/shake_babel_plugin_map.js +0 -21
- package/src/internal/integrity/integrity_algorithms.js +0 -26
- package/src/internal/integrity/integrity_parsing.js +0 -50
- package/src/internal/integrity/integrity_update.js +0 -23
- package/src/internal/integrity/integrity_validation.js +0 -49
- package/src/internal/node_feature_detection/node_feature_detection.js +0 -117
- package/src/internal/node_runtime/detectNode.js +0 -3
- package/src/internal/runtime/computeCompileIdFromGroupId.js +0 -30
- package/src/internal/runtime/resolveGroup.js +0 -13
- package/src/internal/runtime/resolveRuntimeGroup.js +0 -11
|
@@ -10,7 +10,7 @@ import { filterV8Coverage } from "@jsenv/core/src/internal/executing/coverage_ut
|
|
|
10
10
|
import { composeTwoFileByFileIstanbulCoverages } from "@jsenv/core/src/internal/executing/coverage_utils/istanbul_coverage_composition.js"
|
|
11
11
|
import { evalSource } from "../node_runtime/evalSource.js"
|
|
12
12
|
import { escapeRegexpSpecialCharacters } from "../escapeRegexpSpecialCharacters.js"
|
|
13
|
-
import {
|
|
13
|
+
import { getBrowserRuntimeProfile } from "./browser_runtime_profile.js"
|
|
14
14
|
|
|
15
15
|
export const executeHtmlFile = async (
|
|
16
16
|
fileRelativeUrl,
|
|
@@ -20,7 +20,7 @@ export const executeHtmlFile = async (
|
|
|
20
20
|
projectDirectoryUrl,
|
|
21
21
|
compileServerOrigin,
|
|
22
22
|
compileServerId,
|
|
23
|
-
|
|
23
|
+
jsenvDirectoryRelativeUrl,
|
|
24
24
|
page,
|
|
25
25
|
|
|
26
26
|
// measurePerformance,
|
|
@@ -30,6 +30,7 @@ export const executeHtmlFile = async (
|
|
|
30
30
|
coverageForceIstanbul,
|
|
31
31
|
coveragePlaywrightAPIAvailable,
|
|
32
32
|
transformErrorHook,
|
|
33
|
+
forceSource,
|
|
33
34
|
forceCompilation,
|
|
34
35
|
},
|
|
35
36
|
) => {
|
|
@@ -56,36 +57,42 @@ export const executeHtmlFile = async (
|
|
|
56
57
|
|
|
57
58
|
const coverageHandledFromOutside =
|
|
58
59
|
coveragePlaywrightAPIAvailable && !coverageForceIstanbul
|
|
59
|
-
const
|
|
60
|
+
const browserRuntimeProfile = await getBrowserRuntimeProfile({
|
|
60
61
|
page,
|
|
61
|
-
coverageHandledFromOutside,
|
|
62
62
|
compileServerId,
|
|
63
63
|
runtime,
|
|
64
|
+
// js coverage
|
|
65
|
+
// When instrumentation CAN be handed by playwright
|
|
66
|
+
// https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions
|
|
67
|
+
// coverageHandledFromOutside is true and "transform-instrument" becomes non mandatory
|
|
68
|
+
coverageHandledFromOutside,
|
|
69
|
+
forceSource,
|
|
70
|
+
forceCompilation,
|
|
64
71
|
})
|
|
65
72
|
|
|
66
73
|
try {
|
|
67
74
|
let executionResult
|
|
68
|
-
const {
|
|
75
|
+
const { compileId } = browserRuntimeProfile
|
|
69
76
|
executeOperation.throwIfAborted()
|
|
70
|
-
if (
|
|
71
|
-
executionResult = await
|
|
77
|
+
if (compileId) {
|
|
78
|
+
executionResult = await executeCompiledVersion({
|
|
72
79
|
projectDirectoryUrl,
|
|
73
80
|
compileServerOrigin,
|
|
74
81
|
fileRelativeUrl,
|
|
75
82
|
page,
|
|
83
|
+
jsenvDirectoryRelativeUrl,
|
|
84
|
+
compileId,
|
|
76
85
|
collectCoverage,
|
|
77
|
-
coverageIgnorePredicate,
|
|
78
86
|
transformErrorHook,
|
|
79
87
|
})
|
|
80
88
|
} else {
|
|
81
|
-
executionResult = await
|
|
89
|
+
executionResult = await executeSource({
|
|
82
90
|
projectDirectoryUrl,
|
|
83
91
|
compileServerOrigin,
|
|
84
92
|
fileRelativeUrl,
|
|
85
93
|
page,
|
|
86
|
-
outDirectoryRelativeUrl,
|
|
87
|
-
compileId,
|
|
88
94
|
collectCoverage,
|
|
95
|
+
coverageIgnorePredicate,
|
|
89
96
|
transformErrorHook,
|
|
90
97
|
})
|
|
91
98
|
}
|
|
@@ -238,7 +245,7 @@ const executeCompiledVersion = async ({
|
|
|
238
245
|
compileServerOrigin,
|
|
239
246
|
fileRelativeUrl,
|
|
240
247
|
page,
|
|
241
|
-
|
|
248
|
+
jsenvDirectoryRelativeUrl,
|
|
242
249
|
compileId,
|
|
243
250
|
collectCoverage,
|
|
244
251
|
transformErrorHook,
|
|
@@ -259,7 +266,7 @@ const executeCompiledVersion = async ({
|
|
|
259
266
|
})
|
|
260
267
|
}
|
|
261
268
|
|
|
262
|
-
const compileDirectoryRelativeUrl = `${
|
|
269
|
+
const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
|
|
263
270
|
const compileDirectoryRemoteUrl = resolveUrl(
|
|
264
271
|
compileDirectoryRelativeUrl,
|
|
265
272
|
compileServerOrigin,
|
|
@@ -268,11 +275,12 @@ const executeCompiledVersion = async ({
|
|
|
268
275
|
await page.goto(fileClientUrl, { timeout: 0 })
|
|
269
276
|
|
|
270
277
|
const executionResult = await page.evaluate(
|
|
278
|
+
/* eslint-disable no-undef */
|
|
271
279
|
/* istanbul ignore next */
|
|
272
280
|
() => {
|
|
273
|
-
// eslint-disable-next-line no-undef
|
|
274
281
|
return window.__jsenv__.executionResultPromise
|
|
275
282
|
},
|
|
283
|
+
/* eslint-enable no-undef */
|
|
276
284
|
)
|
|
277
285
|
|
|
278
286
|
const { fileExecutionResultMap } = executionResult
|
|
@@ -33,7 +33,8 @@ export const createRuntimeFromPlaywright = ({
|
|
|
33
33
|
|
|
34
34
|
projectDirectoryUrl,
|
|
35
35
|
compileServerOrigin,
|
|
36
|
-
|
|
36
|
+
compileServerId,
|
|
37
|
+
jsenvDirectoryRelativeUrl,
|
|
37
38
|
|
|
38
39
|
collectPerformance,
|
|
39
40
|
measurePerformance,
|
|
@@ -130,7 +131,8 @@ export const createRuntimeFromPlaywright = ({
|
|
|
130
131
|
|
|
131
132
|
projectDirectoryUrl,
|
|
132
133
|
compileServerOrigin,
|
|
133
|
-
|
|
134
|
+
compileServerId,
|
|
135
|
+
jsenvDirectoryRelativeUrl,
|
|
134
136
|
|
|
135
137
|
collectPerformance,
|
|
136
138
|
measurePerformance,
|
|
@@ -264,7 +266,7 @@ const createExecuteHook = ({
|
|
|
264
266
|
projectDirectoryUrl,
|
|
265
267
|
compileServerOrigin,
|
|
266
268
|
compileServerId,
|
|
267
|
-
|
|
269
|
+
jsenvDirectoryRelativeUrl,
|
|
268
270
|
|
|
269
271
|
collectPerformance,
|
|
270
272
|
measurePerformance,
|
|
@@ -287,7 +289,7 @@ const createExecuteHook = ({
|
|
|
287
289
|
projectDirectoryUrl,
|
|
288
290
|
compileServerOrigin,
|
|
289
291
|
compileServerId,
|
|
290
|
-
|
|
292
|
+
jsenvDirectoryRelativeUrl,
|
|
291
293
|
|
|
292
294
|
page,
|
|
293
295
|
measurePerformance,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
2
|
|
|
3
3
|
import { installBrowserErrorStackRemapping } from "../error-stack-remapping/installBrowserErrorStackRemapping.js"
|
|
4
|
-
import { fetchUrl } from "../browser_utils/
|
|
4
|
+
import { fetchUrl } from "../browser_utils/fetch_browser.js"
|
|
5
5
|
import { fetchAndEvalUsingFetch } from "../browser_utils/fetchAndEvalUsingFetch.js"
|
|
6
6
|
import { unevalException } from "../unevalException.js"
|
|
7
7
|
import { memoize } from "../memoize.js"
|
|
@@ -165,26 +165,27 @@ const onExecutionError = (
|
|
|
165
165
|
|
|
166
166
|
const getBrowserRuntime = memoize(async () => {
|
|
167
167
|
const compileServerOrigin = document.location.origin
|
|
168
|
-
const
|
|
169
|
-
`${compileServerOrigin}
|
|
168
|
+
const compileServerResponse = await fetchUrl(
|
|
169
|
+
`${compileServerOrigin}/__jsenv_compile_profile__`,
|
|
170
170
|
)
|
|
171
|
-
const
|
|
172
|
-
const {
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
|
|
171
|
+
const compileServerMeta = await compileServerResponse.json()
|
|
172
|
+
const { jsenvDirectoryRelativeUrl, errorStackRemapping } = compileServerMeta
|
|
173
|
+
const jsenvDirectoryServerUrl = `${compileServerOrigin}/${jsenvDirectoryRelativeUrl}`
|
|
174
|
+
const afterJsenvDirectory = document.location.href.slice(
|
|
175
|
+
jsenvDirectoryServerUrl.length,
|
|
176
|
+
)
|
|
177
|
+
const parts = afterJsenvDirectory.split("/")
|
|
176
178
|
const compileId = parts[0]
|
|
177
179
|
|
|
178
180
|
const browserRuntime = await createBrowserRuntime({
|
|
179
181
|
compileServerOrigin,
|
|
180
|
-
|
|
182
|
+
jsenvDirectoryRelativeUrl,
|
|
181
183
|
compileId,
|
|
182
184
|
})
|
|
183
185
|
|
|
184
186
|
if (errorStackRemapping && Error.captureStackTrace) {
|
|
185
187
|
const { sourcemapMainFileRelativeUrl, sourcemapMappingFileRelativeUrl } =
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
compileServerMeta
|
|
188
189
|
await fetchAndEvalUsingFetch(
|
|
189
190
|
`${compileServerOrigin}/${sourcemapMainFileRelativeUrl}`,
|
|
190
191
|
)
|
|
@@ -195,7 +196,6 @@ const getBrowserRuntime = memoize(async () => {
|
|
|
195
196
|
const { getErrorOriginalStackString } = installBrowserErrorStackRemapping({
|
|
196
197
|
SourceMapConsumer,
|
|
197
198
|
})
|
|
198
|
-
|
|
199
199
|
const errorTransform = async (error) => {
|
|
200
200
|
// code can throw something else than an error
|
|
201
201
|
// in that case return it unchanged
|
|
@@ -204,13 +204,11 @@ const getBrowserRuntime = memoize(async () => {
|
|
|
204
204
|
error.stack = originalStack
|
|
205
205
|
return error
|
|
206
206
|
}
|
|
207
|
-
|
|
208
207
|
const executeFile = browserRuntime.executeFile
|
|
209
208
|
browserRuntime.executeFile = (file, options = {}) => {
|
|
210
209
|
return executeFile(file, { errorTransform, ...options })
|
|
211
210
|
}
|
|
212
211
|
}
|
|
213
|
-
|
|
214
212
|
return browserRuntime
|
|
215
213
|
})
|
|
216
214
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { normalizeImportMap } from "@jsenv/importmap/src/normalizeImportMap.js"
|
|
4
4
|
|
|
5
5
|
// do not use memoize from @jsenv/filesystem to avoid pulling @jsenv/filesystem code into the browser build
|
|
6
|
-
import { fetchUrl } from "../browser_utils/
|
|
6
|
+
import { fetchUrl } from "../browser_utils/fetch_browser.js"
|
|
7
7
|
import { createImportResolverForImportmap } from "../import-resolution/import-resolver-importmap.js"
|
|
8
8
|
import { memoize } from "../memoize.js"
|
|
9
9
|
import { measureAsyncFnPerf } from "../perf_browser.js"
|
|
@@ -15,7 +15,7 @@ const memoizedCreateBrowserSystem = memoize(createBrowserSystem)
|
|
|
15
15
|
|
|
16
16
|
export const createBrowserRuntime = async ({
|
|
17
17
|
compileServerOrigin,
|
|
18
|
-
|
|
18
|
+
jsenvDirectoryRelativeUrl,
|
|
19
19
|
compileId,
|
|
20
20
|
}) => {
|
|
21
21
|
const fetchSource = (url, { contentTypeExpected }) => {
|
|
@@ -33,10 +33,11 @@ export const createBrowserRuntime = async ({
|
|
|
33
33
|
return json
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
36
|
+
const compileServerMetaUrl = String(
|
|
37
|
+
new URL("__jsenv_compile_profile__", `${compileServerOrigin}/`),
|
|
38
|
+
)
|
|
39
|
+
const { importDefaultExtension } = await fetchJson(compileServerMetaUrl)
|
|
40
|
+
const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
|
|
40
41
|
// if there is an importmap in the document we use it instead of fetching.
|
|
41
42
|
// systemjs style with systemjs-importmap
|
|
42
43
|
const importmapScript = document.querySelector(
|
|
@@ -9,82 +9,60 @@ import {
|
|
|
9
9
|
import { createDetailedMessage } from "@jsenv/logger"
|
|
10
10
|
|
|
11
11
|
import { humanizeUrl } from "@jsenv/core/src/internal/building/url_trace.js"
|
|
12
|
-
|
|
13
|
-
isNodePartOfSupportedRuntimes,
|
|
14
|
-
isBrowserPartOfSupportedRuntimes,
|
|
15
|
-
} from "@jsenv/core/src/internal/generateGroupMap/runtime_support.js"
|
|
16
|
-
import { createRuntimeCompat } from "@jsenv/core/src/internal/generateGroupMap/runtime_compat.js"
|
|
12
|
+
|
|
17
13
|
import { createRollupPlugins } from "./rollup_plugin_jsenv.js"
|
|
18
14
|
|
|
19
15
|
export const buildUsingRollup = async ({
|
|
20
16
|
buildOperation,
|
|
21
17
|
logger,
|
|
22
18
|
|
|
23
|
-
projectDirectoryUrl,
|
|
24
19
|
entryPoints,
|
|
25
|
-
|
|
26
|
-
compileDirectoryRelativeUrl,
|
|
27
|
-
jsenvDirectoryRelativeUrl,
|
|
20
|
+
projectDirectoryUrl,
|
|
28
21
|
buildDirectoryUrl,
|
|
29
22
|
buildDirectoryClean,
|
|
30
|
-
assetManifestFile
|
|
23
|
+
assetManifestFile,
|
|
31
24
|
assetManifestFileRelativeUrl,
|
|
32
|
-
sourcemapExcludeSources,
|
|
33
|
-
writeOnFileSystem,
|
|
34
|
-
|
|
35
|
-
format,
|
|
36
|
-
systemJsUrl,
|
|
37
|
-
globalName,
|
|
38
|
-
globals,
|
|
39
|
-
babelPluginMap,
|
|
40
|
-
runtimeSupport,
|
|
41
25
|
|
|
42
26
|
urlMappings,
|
|
43
27
|
importResolutionMethod,
|
|
44
28
|
importMapFileRelativeUrl,
|
|
45
29
|
importDefaultExtension,
|
|
46
30
|
externalImportSpecifiers,
|
|
47
|
-
importPaths,
|
|
48
31
|
preservedUrls,
|
|
32
|
+
importPaths,
|
|
33
|
+
|
|
34
|
+
format,
|
|
35
|
+
systemJsUrl,
|
|
36
|
+
globalName,
|
|
37
|
+
globals,
|
|
49
38
|
workers,
|
|
50
39
|
serviceWorkers,
|
|
51
40
|
serviceWorkerFinalizer,
|
|
52
41
|
classicWorkers,
|
|
53
42
|
classicServiceWorkers,
|
|
54
43
|
|
|
44
|
+
node,
|
|
45
|
+
browser,
|
|
46
|
+
compileServer,
|
|
47
|
+
compileProfile,
|
|
48
|
+
compileId,
|
|
49
|
+
|
|
55
50
|
urlVersioning,
|
|
56
51
|
lineBreakNormalization,
|
|
57
|
-
jsConcatenation,
|
|
58
|
-
cssConcatenation,
|
|
59
52
|
useImportMapToMaximizeCacheReuse,
|
|
60
53
|
preserveEntrySignatures,
|
|
61
54
|
treeshake,
|
|
55
|
+
jsConcatenation,
|
|
56
|
+
cssConcatenation,
|
|
62
57
|
|
|
63
58
|
minify,
|
|
59
|
+
minifyHtmlOptions,
|
|
64
60
|
minifyJsOptions,
|
|
65
61
|
minifyCssOptions,
|
|
66
|
-
minifyHtmlOptions,
|
|
67
|
-
}) => {
|
|
68
|
-
const node = isNodePartOfSupportedRuntimes(runtimeSupport)
|
|
69
|
-
const browser = isBrowserPartOfSupportedRuntimes(runtimeSupport)
|
|
70
|
-
|
|
71
|
-
const runtimeCompatMap = createRuntimeCompat({
|
|
72
|
-
runtimeSupport,
|
|
73
|
-
featureNames: ["import_assertion_type_json", "import_assertion_type_css"],
|
|
74
|
-
})
|
|
75
|
-
const importAssertionsSupport = {
|
|
76
|
-
json:
|
|
77
|
-
format === "esmodule" &&
|
|
78
|
-
!runtimeCompatMap.missingFeatureNames.includes(
|
|
79
|
-
"import_assertion_type_json",
|
|
80
|
-
),
|
|
81
|
-
css:
|
|
82
|
-
format === "esmodule" &&
|
|
83
|
-
!runtimeCompatMap.missingFeatureNames.includes(
|
|
84
|
-
"import_assertion_type_json",
|
|
85
|
-
),
|
|
86
|
-
}
|
|
87
62
|
|
|
63
|
+
writeOnFileSystem,
|
|
64
|
+
sourcemapExcludeSources,
|
|
65
|
+
}) => {
|
|
88
66
|
const {
|
|
89
67
|
rollupPlugins,
|
|
90
68
|
getLastErrorMessage,
|
|
@@ -97,18 +75,10 @@ export const buildUsingRollup = async ({
|
|
|
97
75
|
|
|
98
76
|
projectDirectoryUrl,
|
|
99
77
|
entryPoints,
|
|
100
|
-
compileServerOrigin,
|
|
101
|
-
compileDirectoryRelativeUrl,
|
|
102
|
-
jsenvDirectoryRelativeUrl,
|
|
103
78
|
buildDirectoryUrl,
|
|
104
79
|
|
|
105
80
|
format,
|
|
106
81
|
systemJsUrl,
|
|
107
|
-
babelPluginMap,
|
|
108
|
-
node,
|
|
109
|
-
browser,
|
|
110
|
-
importAssertionsSupport,
|
|
111
|
-
|
|
112
82
|
urlMappings,
|
|
113
83
|
importResolutionMethod,
|
|
114
84
|
importMapFileRelativeUrl,
|
|
@@ -122,6 +92,12 @@ export const buildUsingRollup = async ({
|
|
|
122
92
|
classicWorkers,
|
|
123
93
|
classicServiceWorkers,
|
|
124
94
|
|
|
95
|
+
node,
|
|
96
|
+
browser,
|
|
97
|
+
compileServer,
|
|
98
|
+
compileProfile,
|
|
99
|
+
compileId,
|
|
100
|
+
|
|
125
101
|
urlVersioning,
|
|
126
102
|
lineBreakNormalization,
|
|
127
103
|
jsConcatenation,
|
|
@@ -140,7 +116,7 @@ export const buildUsingRollup = async ({
|
|
|
140
116
|
logger,
|
|
141
117
|
|
|
142
118
|
rollupPlugins,
|
|
143
|
-
|
|
119
|
+
compileProfile,
|
|
144
120
|
format,
|
|
145
121
|
globals,
|
|
146
122
|
globalName,
|
|
@@ -246,7 +222,7 @@ const useRollup = async ({
|
|
|
246
222
|
buildOperation,
|
|
247
223
|
logger,
|
|
248
224
|
rollupPlugins,
|
|
249
|
-
|
|
225
|
+
compileProfile,
|
|
250
226
|
format,
|
|
251
227
|
globals,
|
|
252
228
|
globalName,
|
|
@@ -319,10 +295,18 @@ const useRollup = async ({
|
|
|
319
295
|
// experimentalTopLevelAwait: true,
|
|
320
296
|
// https://rollupjs.org/guide/en/#outputgeneratedcode
|
|
321
297
|
generatedCode: {
|
|
322
|
-
arrowFunctions:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
298
|
+
arrowFunctions:
|
|
299
|
+
compileProfile &&
|
|
300
|
+
!compileProfile.missingFeatures["transform-arrow-functions"],
|
|
301
|
+
constBindings:
|
|
302
|
+
compileProfile &&
|
|
303
|
+
!compileProfile.missingFeatures["transform-block-scoping"],
|
|
304
|
+
objectShorthand:
|
|
305
|
+
compileProfile &&
|
|
306
|
+
!compileProfile.missingFeatures["transform-shorthand-properties"],
|
|
307
|
+
reservedNamesAsProps:
|
|
308
|
+
compileProfile &&
|
|
309
|
+
!compileProfile.missingFeatures["transform-reserved-words"],
|
|
326
310
|
},
|
|
327
311
|
// https://rollupjs.org/guide/en#output-dir
|
|
328
312
|
dir: urlToFileSystemPath(buildDirectoryUrl),
|
|
@@ -17,6 +17,8 @@ Or be sure to also reference this url somewhere in the html file like
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { urlToFilename, urlToRelativeUrl, resolveUrl } from "@jsenv/filesystem"
|
|
20
|
+
import { applyAlgoToRepresentationData } from "@jsenv/integrity"
|
|
21
|
+
|
|
20
22
|
|
|
21
23
|
import {
|
|
22
24
|
parseHtmlString,
|
|
@@ -48,7 +50,6 @@ import { collectNodesMutations } from "../parsing.utils.js"
|
|
|
48
50
|
|
|
49
51
|
import { collectSvgMutations } from "../svg/parseSvgRessource.js"
|
|
50
52
|
import { moveCssUrls } from "../css/moveCssUrls.js"
|
|
51
|
-
import { applyAlgoToRepresentationData } from "../../integrity/integrity_algorithms.js"
|
|
52
53
|
|
|
53
54
|
export const parseHtmlRessource = async (
|
|
54
55
|
htmlRessource,
|
|
@@ -32,6 +32,7 @@ import { createImportResolverForImportmap } from "@jsenv/core/src/internal/impor
|
|
|
32
32
|
import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
|
|
33
33
|
import { createJsenvRemoteDirectory } from "@jsenv/core/src/internal/jsenv_remote_directory.js"
|
|
34
34
|
import { setUrlSearchParamsDescriptor } from "@jsenv/core/src/internal/url_utils.js"
|
|
35
|
+
import { shakeBabelPluginMap } from "@jsenv/core/src/internal/compiling/jsenv_directory/compile_profile.js"
|
|
35
36
|
|
|
36
37
|
import {
|
|
37
38
|
formatBuildStartLog,
|
|
@@ -56,9 +57,6 @@ export const createRollupPlugins = async ({
|
|
|
56
57
|
|
|
57
58
|
projectDirectoryUrl,
|
|
58
59
|
entryPoints,
|
|
59
|
-
compileServerOrigin,
|
|
60
|
-
compileDirectoryRelativeUrl,
|
|
61
|
-
jsenvDirectoryRelativeUrl,
|
|
62
60
|
buildDirectoryUrl,
|
|
63
61
|
|
|
64
62
|
urlMappings,
|
|
@@ -73,12 +71,13 @@ export const createRollupPlugins = async ({
|
|
|
73
71
|
serviceWorkerFinalizer,
|
|
74
72
|
classicWorkers,
|
|
75
73
|
classicServiceWorkers,
|
|
76
|
-
|
|
77
74
|
format,
|
|
78
75
|
systemJsUrl,
|
|
79
|
-
|
|
76
|
+
|
|
80
77
|
node,
|
|
81
|
-
|
|
78
|
+
compileServer,
|
|
79
|
+
compileProfile,
|
|
80
|
+
compileId,
|
|
82
81
|
|
|
83
82
|
urlVersioning,
|
|
84
83
|
lineBreakNormalization,
|
|
@@ -91,6 +90,29 @@ export const createRollupPlugins = async ({
|
|
|
91
90
|
minifyCssOptions,
|
|
92
91
|
minifyHtmlOptions,
|
|
93
92
|
}) => {
|
|
93
|
+
const compileServerOrigin = compileServer.origin
|
|
94
|
+
// For now the compilation is forced during build because this plugin
|
|
95
|
+
// was coded assuming build always requires to be compiled.
|
|
96
|
+
// Ideally jsenv should also be able to build a project using source files
|
|
97
|
+
// and in that case compileProfile and compileId are null
|
|
98
|
+
// the babel plugin map is useless (we can just fetch the source file directly)
|
|
99
|
+
const jsenvDirectoryRelativeUrl = compileServer.jsenvDirectoryRelativeUrl
|
|
100
|
+
const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
|
|
101
|
+
const babelPluginMap = shakeBabelPluginMap({
|
|
102
|
+
babelPluginMap: compileServer.babelPluginMap,
|
|
103
|
+
compileProfile,
|
|
104
|
+
})
|
|
105
|
+
const importAssertionsSupport = {
|
|
106
|
+
json:
|
|
107
|
+
format === "esmodule" &&
|
|
108
|
+
compileProfile &&
|
|
109
|
+
!compileProfile.missingFeatures["import_assertion_type_json"],
|
|
110
|
+
css:
|
|
111
|
+
format === "esmodule" &&
|
|
112
|
+
compileProfile &&
|
|
113
|
+
!compileProfile.missingFeatures["import_assertion_type_css"],
|
|
114
|
+
}
|
|
115
|
+
|
|
94
116
|
const jsenvRemoteDirectory = createJsenvRemoteDirectory({
|
|
95
117
|
projectDirectoryUrl,
|
|
96
118
|
jsenvDirectoryRelativeUrl,
|
|
@@ -433,7 +455,6 @@ export const createRollupPlugins = async ({
|
|
|
433
455
|
asCompiledServerUrl(importMapInfoFromHtml.htmlUrl),
|
|
434
456
|
)
|
|
435
457
|
importMapUrl = applyUrlMappings(importMapUrl)
|
|
436
|
-
|
|
437
458
|
if (!urlIsInsideOf(importMapUrl, compileDirectoryServerUrl)) {
|
|
438
459
|
logger.warn(
|
|
439
460
|
formatImportmapOutsideCompileDirectory({
|
|
@@ -442,7 +463,6 @@ export const createRollupPlugins = async ({
|
|
|
442
463
|
}),
|
|
443
464
|
)
|
|
444
465
|
}
|
|
445
|
-
|
|
446
466
|
fetchImportMap = () => {
|
|
447
467
|
return fetchImportMapFromUrl(
|
|
448
468
|
importMapUrl,
|
|
@@ -4,23 +4,75 @@
|
|
|
4
4
|
|
|
5
5
|
import { require } from "@jsenv/core/src/internal/require.js"
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { createParseError } from "./babel_parse_error.js"
|
|
8
|
+
|
|
9
|
+
export const babelPluginTransformImportMeta = (api, { importMetaFormat }) => {
|
|
8
10
|
const {
|
|
9
11
|
addNamespace,
|
|
10
12
|
addDefault,
|
|
11
13
|
addNamed,
|
|
12
14
|
} = require("@babel/helper-module-imports")
|
|
13
15
|
const { parseExpression } = require("@babel/parser")
|
|
14
|
-
|
|
15
|
-
const { replaceImportMeta } = pluginOptions
|
|
16
|
-
|
|
17
16
|
let babelState
|
|
18
17
|
const jsValueToAst = (jsValue) => {
|
|
19
18
|
const valueAst = parseExpression(jsValue, babelState.opts)
|
|
20
19
|
return valueAst
|
|
21
20
|
}
|
|
21
|
+
const visitImportMetaProperty = ({
|
|
22
|
+
importMetaPropertyName,
|
|
23
|
+
replaceWithImport,
|
|
24
|
+
replaceWithValue,
|
|
25
|
+
}) => {
|
|
26
|
+
if (importMetaPropertyName === "url") {
|
|
27
|
+
if (importMetaFormat === "esmodule") {
|
|
28
|
+
// keep native version
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
if (importMetaFormat === "systemjs") {
|
|
32
|
+
// systemjs will handle it
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
if (importMetaFormat === "commonjs") {
|
|
36
|
+
replaceWithImport({
|
|
37
|
+
from: `@jsenv/core/helpers/import-meta/import-meta-url-commonjs.js`,
|
|
38
|
+
})
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (importMetaFormat === "global") {
|
|
42
|
+
replaceWithImport({
|
|
43
|
+
from: `@jsenv/core/helpers/import-meta/import-meta-url-global.js`,
|
|
44
|
+
})
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if (importMetaPropertyName === "resolve") {
|
|
50
|
+
if (importMetaFormat === "esmodule") {
|
|
51
|
+
// keep native version
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (importMetaFormat === "systemjs") {
|
|
55
|
+
// systemjs will handle it
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
if (importMetaFormat === "commonjs") {
|
|
59
|
+
throw createParseError({
|
|
60
|
+
message: `import.meta.resolve() not supported with commonjs format`,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
if (importMetaFormat === "global") {
|
|
64
|
+
throw createParseError({
|
|
65
|
+
message: `import.meta.resolve() not supported with global format`,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
replaceWithValue(undefined)
|
|
71
|
+
}
|
|
22
72
|
|
|
23
73
|
return {
|
|
74
|
+
name: "transform-import-meta",
|
|
75
|
+
|
|
24
76
|
pre: (state) => {
|
|
25
77
|
babelState = state
|
|
26
78
|
},
|
|
@@ -53,7 +105,6 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
|
|
|
53
105
|
visitor: {
|
|
54
106
|
Program(programPath) {
|
|
55
107
|
const metaPropertyPathMap = {}
|
|
56
|
-
|
|
57
108
|
programPath.traverse({
|
|
58
109
|
MemberExpression(path) {
|
|
59
110
|
const { node } = path
|
|
@@ -61,12 +112,10 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
|
|
|
61
112
|
if (object.type !== "MetaProperty") {
|
|
62
113
|
return
|
|
63
114
|
}
|
|
64
|
-
|
|
65
115
|
const { property: objectProperty } = object
|
|
66
116
|
if (objectProperty.name !== "meta") {
|
|
67
117
|
return
|
|
68
118
|
}
|
|
69
|
-
|
|
70
119
|
const { property } = node
|
|
71
120
|
const { name } = property
|
|
72
121
|
if (name in metaPropertyPathMap) {
|
|
@@ -76,9 +125,9 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
|
|
|
76
125
|
}
|
|
77
126
|
},
|
|
78
127
|
})
|
|
79
|
-
|
|
80
128
|
Object.keys(metaPropertyPathMap).forEach((importMetaPropertyName) => {
|
|
81
|
-
|
|
129
|
+
visitImportMetaProperty({
|
|
130
|
+
importMetaPropertyName,
|
|
82
131
|
replaceWithImport: ({ namespace, name, from, nameHint }) => {
|
|
83
132
|
let importAst
|
|
84
133
|
if (namespace) {
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
} from "@jsenv/filesystem"
|
|
8
8
|
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js"
|
|
9
9
|
|
|
10
|
-
import { getOrGenerateCompiledFile } from "./
|
|
11
|
-
import { updateMeta } from "./
|
|
10
|
+
import { getOrGenerateCompiledFile } from "./jsenv_directory/getOrGenerateCompiledFile.js"
|
|
11
|
+
import { updateMeta } from "./jsenv_directory/updateMeta.js"
|
|
12
12
|
|
|
13
13
|
export const compileFile = async ({
|
|
14
14
|
logger,
|