@jsenv/core 20.0.1 → 20.0.5

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/.DS_Store ADDED
Binary file
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "20.0.1",
3
+ "version": "20.0.5",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,8 +11,7 @@
11
11
  "node": ">=14.9.0"
12
12
  },
13
13
  "publishConfig": {
14
- "access": "public",
15
- "registry": "https://registry.npmjs.org"
14
+ "access": "public"
16
15
  },
17
16
  "type": "module",
18
17
  "exports": {
@@ -112,6 +112,11 @@ export const buildProject = async ({
112
112
  `unexpected format: ${format}. Must be "esmodule", "systemjs", "commonjs" or "global".`,
113
113
  )
114
114
  }
115
+ if (typeof runtimeSupport !== "object" || runtimeSupport === null) {
116
+ throw new TypeError(
117
+ `runtimeSupport must be an object, got ${runtimeSupport}`,
118
+ )
119
+ }
115
120
 
116
121
  projectDirectoryUrl = assertProjectDirectoryUrl({ projectDirectoryUrl })
117
122
  await assertProjectDirectoryExists({ projectDirectoryUrl })
@@ -387,7 +387,7 @@ export const createAssetBuilder = (
387
387
  return
388
388
  }
389
389
 
390
- const targetBuildBuffer = buildFileInfo.code
390
+ const targetBuildBuffer = Buffer.from(buildFileInfo.code)
391
391
  const targetFileName = buildFileInfo.fileName
392
392
  const targetBuildRelativeUrl =
393
393
  buildManifest[targetFileName] || targetFileName
@@ -543,7 +543,7 @@ export const createAssetBuilder = (
543
543
  const transform = assetTransformMap[targetUrl]
544
544
  if (typeof transform !== "function") {
545
545
  target.targetBuildEnd(
546
- target.targetBuffer,
546
+ target.targetBuildBuffer || target.targetBuffer,
547
547
  target.targetBuildRelativeUrl,
548
548
  )
549
549
  return
@@ -1,49 +1,9 @@
1
- import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
2
-
3
- import { setJavaScriptSourceMappingUrl } from "@jsenv/core/src/internal/sourceMappingURLUtils.js"
4
-
5
- export const createBuildFileContents = ({ rollupBuild, buildDirectoryUrl }) => {
1
+ export const createBuildFileContents = ({ rollupBuild }) => {
6
2
  const buildFileContents = {}
7
3
  Object.keys(rollupBuild).forEach((buildRelativeUrl) => {
8
- const rollupFileInfo = rollupBuild[buildRelativeUrl]
9
- const fileBuildUrl = resolveUrl(buildRelativeUrl, buildDirectoryUrl)
10
-
11
- if (rollupFileInfo.type === "asset") {
12
- buildFileContents[buildRelativeUrl] = rollupFileInfo.source
13
- return
14
- }
15
-
16
- const { code, map } = rollupFileInfo
17
-
18
- if (!map) {
19
- buildFileContents[buildRelativeUrl] = code
20
- return
21
- }
22
-
23
- const sourcemapBuildRelativeUrl = `${buildRelativeUrl}.map`
24
- const sourcemapRollupFileInfo = rollupBuild[sourcemapBuildRelativeUrl]
25
- if (sourcemapRollupFileInfo) {
26
- // already in rollup build, sourcemap will be found
27
- buildFileContents[buildRelativeUrl] = code
28
- return
29
- }
30
-
31
- const sourcemapBuildUrl = resolveUrl(
32
- sourcemapBuildRelativeUrl,
33
- buildDirectoryUrl,
34
- )
35
- const fileSourcemapString = JSON.stringify(map, null, " ")
36
- buildFileContents[sourcemapBuildRelativeUrl] = fileSourcemapString
4
+ const { type, source, code } = rollupBuild[buildRelativeUrl]
37
5
 
38
- const sourcemapBuildUrlRelativeToFileBuildUrl = urlToRelativeUrl(
39
- sourcemapBuildUrl,
40
- fileBuildUrl,
41
- )
42
- const codeWithSourcemapComment = setJavaScriptSourceMappingUrl(
43
- code,
44
- sourcemapBuildUrlRelativeToFileBuildUrl,
45
- )
46
- buildFileContents[buildRelativeUrl] = codeWithSourcemapComment
6
+ buildFileContents[buildRelativeUrl] = type === "asset" ? source : code
47
7
  })
48
8
  return buildFileContents
49
9
  }
@@ -44,6 +44,7 @@ import { minifyJs } from "./js/minifyJs.js"
44
44
  import { createImportResolverForNode } from "../import-resolution/import-resolver-node.js"
45
45
  import { createImportResolverForImportmap } from "../import-resolution/import-resolver-importmap.js"
46
46
  import { getDefaultImportMap } from "../import-resolution/importmap-default.js"
47
+ import { injectSourcemapInRollupBuild } from "./rollup_build_sourcemap.js"
47
48
  import { createBuildFileContents } from "./build_file_contents.js"
48
49
  import { createBuildStats } from "./build_stats.js"
49
50
 
@@ -901,12 +902,14 @@ building ${entryFileRelativeUrls.length} entry files...`)
901
902
  ...jsModuleBuild,
902
903
  ...assetBuild,
903
904
  }
905
+ rollupBuild = injectSourcemapInRollupBuild(rollupBuild, {
906
+ buildDirectoryUrl,
907
+ })
904
908
  rollupBuild = sortObjectByPathnames(rollupBuild)
905
909
  buildManifest = sortObjectByPathnames(buildManifest)
906
910
  buildMappings = sortObjectByPathnames(buildMappings)
907
911
  buildFileContents = createBuildFileContents({
908
912
  rollupBuild,
909
- buildDirectoryUrl,
910
913
  })
911
914
  const buildDuration = Date.now() - buildStartMs
912
915
  buildStats = createBuildStats({
@@ -38,6 +38,12 @@ import {
38
38
  parseSrcset,
39
39
  stringifySrcset,
40
40
  } from "@jsenv/core/src/internal/compiling/compileHtml.js"
41
+ import {
42
+ getJavaScriptSourceMappingUrl,
43
+ setJavaScriptSourceMappingUrl,
44
+ getCssSourceMappingUrl,
45
+ setCssSourceMappingUrl,
46
+ } from "@jsenv/core/src/internal/sourceMappingURLUtils.js"
41
47
  import {
42
48
  getTargetAsBase64Url,
43
49
  targetIsReferencedOnlyByRessourceHint,
@@ -145,7 +151,11 @@ export const parseHtmlAsset = async (
145
151
  }
146
152
  }
147
153
 
148
- const regularScriptSrcVisitor = (script, { notifyReferenceFound }) => {
154
+ const regularScriptSrcVisitor = (
155
+ script,
156
+ { notifyReferenceFound },
157
+ htmlTarget,
158
+ ) => {
149
159
  const typeAttribute = getHtmlNodeAttributeByName(script, "type")
150
160
  if (
151
161
  typeAttribute &&
@@ -171,8 +181,21 @@ const regularScriptSrcVisitor = (script, { notifyReferenceFound }) => {
171
181
 
172
182
  if (shouldInline({ reference: remoteScriptReference, htmlNode: script })) {
173
183
  removeHtmlNodeAttribute(script, srcAttribute)
174
- const { targetBuildBuffer } = remoteScriptReference.target
175
- setHtmlNodeText(script, targetBuildBuffer)
184
+ const { target } = remoteScriptReference
185
+ const { targetBuildBuffer } = target
186
+ let jsString = String(targetBuildBuffer)
187
+
188
+ const sourcemapRelativeUrl = getJavaScriptSourceMappingUrl(jsString)
189
+ if (sourcemapRelativeUrl) {
190
+ const { targetBuildRelativeUrl } = target
191
+ const jsBuildUrl = resolveUrl(targetBuildRelativeUrl, "file:///")
192
+ const sourcemapBuildUrl = resolveUrl(sourcemapRelativeUrl, jsBuildUrl)
193
+ const htmlUrl = resolveUrl(htmlTarget.targetFileNamePattern, "file:///")
194
+ const sourcemapInlineUrl = urlToRelativeUrl(sourcemapBuildUrl, htmlUrl)
195
+ jsString = setJavaScriptSourceMappingUrl(jsString, sourcemapInlineUrl)
196
+ }
197
+
198
+ setHtmlNodeText(script, jsString)
176
199
  return
177
200
  }
178
201
 
@@ -258,8 +281,19 @@ const moduleScriptSrcVisitor = (script, { format, notifyReferenceFound }) => {
258
281
  // here put a warning if we cannot inline importmap because it would mess
259
282
  // the remapping (note that it's feasible) but not yet supported
260
283
  removeHtmlNodeAttribute(script, srcAttribute)
261
- const { targetBuildBuffer } = script.target
262
- setHtmlNodeText(script, targetBuildBuffer)
284
+ const { target } = remoteScriptReference
285
+ const { targetBuildBuffer } = target
286
+ let jsString = String(targetBuildBuffer)
287
+
288
+ // at this stage, for some reason the sourcemap url is not in the js
289
+ // (it will be added sshortly after by "injectSourcemapInRollupBuild")
290
+ // but we know that a script type module have a sourcemap
291
+ // and will be next to html file
292
+ // with these assumptions we can force the sourcemap url
293
+ const sourcemapUrl = `${target.targetBuildRelativeUrl}.map`
294
+ jsString = setJavaScriptSourceMappingUrl(jsString, sourcemapUrl)
295
+
296
+ setHtmlNodeText(script, jsString)
263
297
  return
264
298
  }
265
299
 
@@ -426,7 +460,11 @@ const importmapScriptTextNodeVisitor = (
426
460
  }
427
461
  }
428
462
 
429
- const linkStylesheetHrefVisitor = (link, { notifyReferenceFound }) => {
463
+ const linkStylesheetHrefVisitor = (
464
+ link,
465
+ { notifyReferenceFound },
466
+ htmlTarget,
467
+ ) => {
430
468
  const hrefAttribute = getHtmlNodeAttributeByName(link, "href")
431
469
  if (!hrefAttribute) {
432
470
  return null
@@ -450,8 +488,19 @@ const linkStylesheetHrefVisitor = (link, { notifyReferenceFound }) => {
450
488
  }
451
489
 
452
490
  if (shouldInline({ reference: cssReference, htmlNode: link })) {
453
- const { targetBuildBuffer } = cssReference.target
454
- replaceHtmlNode(link, `<style>${targetBuildBuffer}</style>`)
491
+ const { target } = cssReference
492
+ const { targetBuildBuffer } = target
493
+ let cssString = String(targetBuildBuffer)
494
+ const sourcemapRelativeUrl = getCssSourceMappingUrl(cssString)
495
+ if (sourcemapRelativeUrl) {
496
+ const { targetBuildRelativeUrl } = target
497
+ const cssBuildUrl = resolveUrl(targetBuildRelativeUrl, "file:///")
498
+ const sourcemapBuildUrl = resolveUrl(sourcemapRelativeUrl, cssBuildUrl)
499
+ const htmlUrl = resolveUrl(htmlTarget.targetFileNamePattern, "file:///")
500
+ const sourcemapInlineUrl = urlToRelativeUrl(sourcemapBuildUrl, htmlUrl)
501
+ cssString = setCssSourceMappingUrl(cssString, sourcemapInlineUrl)
502
+ }
503
+ replaceHtmlNode(link, `<style>${cssString}</style>`)
455
504
  return
456
505
  }
457
506
 
@@ -669,6 +718,10 @@ const shouldInline = ({ reference, htmlNode }) => {
669
718
  return true
670
719
  }
671
720
 
721
+ return readAndRemoveForceInline(htmlNode)
722
+ }
723
+
724
+ const readAndRemoveForceInline = (htmlNode) => {
672
725
  const jsenvForceInlineAttribute = getHtmlNodeAttributeByName(
673
726
  htmlNode,
674
727
  "data-jsenv-force-inline",
@@ -0,0 +1,54 @@
1
+ import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
2
+
3
+ import { setJavaScriptSourceMappingUrl } from "@jsenv/core/src/internal/sourceMappingURLUtils.js"
4
+
5
+ export const injectSourcemapInRollupBuild = (
6
+ rollupBuild,
7
+ { buildDirectoryUrl },
8
+ ) => {
9
+ const rollupBuildWithSourcemap = {}
10
+
11
+ Object.keys(rollupBuild).forEach((buildRelativeUrl) => {
12
+ const rollupFileInfo = rollupBuild[buildRelativeUrl]
13
+ const { type, code, map } = rollupFileInfo
14
+
15
+ if (type === "asset" || !map) {
16
+ rollupBuildWithSourcemap[buildRelativeUrl] = rollupFileInfo
17
+ return
18
+ }
19
+
20
+ const sourcemapBuildRelativeUrl = `${buildRelativeUrl}.map`
21
+ const sourcemapRollupFileInfo = rollupBuild[sourcemapBuildRelativeUrl]
22
+ if (sourcemapRollupFileInfo) {
23
+ rollupBuildWithSourcemap[buildRelativeUrl] = rollupFileInfo
24
+ return
25
+ }
26
+
27
+ const fileBuildUrl = resolveUrl(buildRelativeUrl, buildDirectoryUrl)
28
+ const sourcemapBuildUrl = resolveUrl(
29
+ sourcemapBuildRelativeUrl,
30
+ buildDirectoryUrl,
31
+ )
32
+ const fileSourcemapString = JSON.stringify(map, null, " ")
33
+ const sourcemapBuildUrlRelativeToFileBuildUrl = urlToRelativeUrl(
34
+ sourcemapBuildUrl,
35
+ fileBuildUrl,
36
+ )
37
+ const codeWithSourcemapComment = setJavaScriptSourceMappingUrl(
38
+ code,
39
+ sourcemapBuildUrlRelativeToFileBuildUrl,
40
+ )
41
+
42
+ rollupBuildWithSourcemap[sourcemapBuildRelativeUrl] = {
43
+ type: "asset",
44
+ fileName: sourcemapBuildRelativeUrl,
45
+ source: fileSourcemapString,
46
+ }
47
+ rollupBuildWithSourcemap[buildRelativeUrl] = {
48
+ ...rollupFileInfo,
49
+ code: codeWithSourcemapComment,
50
+ }
51
+ })
52
+
53
+ return rollupBuildWithSourcemap
54
+ }
@@ -286,9 +286,13 @@ export const replaceHtmlNode = (
286
286
 
287
287
  if (inheritAttributes) {
288
288
  newNode.attrs = [
289
- // inherit script attributes except src, type, href
289
+ // inherit script attributes except src, type, href, rel
290
290
  ...node.attrs.filter(
291
- ({ name }) => name !== "type" && name !== "src" && name !== "href",
291
+ ({ name }) =>
292
+ name !== "type" &&
293
+ name !== "src" &&
294
+ name !== "href" &&
295
+ name !== "rel",
292
296
  ),
293
297
  ...newNode.attrs,
294
298
  ]
@@ -9,13 +9,11 @@ import {
9
9
  COMPILE_ID_BUILD_COMMONJS_FILES,
10
10
  } from "../CONSTANTS.js"
11
11
  import { compileFile } from "./compileFile.js"
12
- import { jsenvCompilerForDynamicBuild } from "./jsenvCompilerForDynamicBuild.js"
13
12
  import { jsenvCompilerForHtml } from "./jsenvCompilerForHtml.js"
14
13
  import { jsenvCompilerForImportmap } from "./jsenvCompilerForImportmap.js"
15
14
  import { jsenvCompilerForJavaScript } from "./jsenvCompilerForJavaScript.js"
16
15
 
17
16
  const jsenvCompilers = {
18
- ...jsenvCompilerForDynamicBuild,
19
17
  ...jsenvCompilerForJavaScript,
20
18
  ...jsenvCompilerForHtml,
21
19
  ...jsenvCompilerForImportmap,
@@ -28,6 +26,7 @@ export const createCompiledFileService = ({
28
26
  projectDirectoryUrl,
29
27
  outDirectoryRelativeUrl,
30
28
 
29
+ runtimeSupport,
31
30
  transformTopLevelAwait,
32
31
  moduleOutFormat,
33
32
  importMetaFormat,
@@ -35,6 +34,8 @@ export const createCompiledFileService = ({
35
34
  groupMap,
36
35
  convertMap,
37
36
  customCompilers,
37
+ urlMappings,
38
+
38
39
  jsenvToolbarInjection,
39
40
 
40
41
  projectFileRequestedCallback,
@@ -113,15 +114,18 @@ export const createCompiledFileService = ({
113
114
  compileId,
114
115
  outDirectoryRelativeUrl,
115
116
 
117
+ urlMappings,
118
+
116
119
  moduleOutFormat,
117
120
  importMetaFormat,
118
121
  groupMap,
119
122
  babelPluginMap,
120
123
  convertMap,
121
124
  transformTopLevelAwait,
125
+ runtimeSupport,
126
+
122
127
  writeOnFilesystem,
123
128
  sourcemapExcludeSources,
124
-
125
129
  jsenvToolbarInjection,
126
130
  }
127
131
  const compilerCandidates = { ...jsenvCompilers, ...customCompilers }
@@ -242,6 +242,7 @@ export const startCompileServer = async ({
242
242
 
243
243
  importDefaultExtension,
244
244
 
245
+ runtimeSupport,
245
246
  transformTopLevelAwait,
246
247
  groupMap: compileServerGroupMap,
247
248
  babelPluginMap,
@@ -1,3 +1,4 @@
1
+ <!DOCTYPE html>
1
2
  <html>
2
3
  <head>
3
4
  <title>Jsenv toolbar</title>
@@ -37,7 +37,7 @@ export const startExploring = async ({
37
37
  explorableConfig = jsenvExplorableConfig,
38
38
  projectDirectoryUrl,
39
39
  jsenvDirectoryRelativeUrl,
40
- outDirectoryName = 'out-dev',
40
+ outDirectoryName = "out-dev",
41
41
  jsenvToolbar = true,
42
42
  livereloading = true,
43
43
  inlineImportMapIntoHTML = true,
@@ -47,11 +47,12 @@ export const startExploring = async ({
47
47
  compileServerLogLevel,
48
48
  compileServerCanReadFromFilesystem,
49
49
  compileServerCanWriteOnFilesystem,
50
- // ideally instead of rest, we should enumerate all
51
- // params to help vscode autocompletion.
52
- // it also helps to see what is available wihout having to open
53
- // startCompileServer
54
- ...rest
50
+ compileServerPort,
51
+ compileServerProtocol,
52
+ compileServerCertificate,
53
+ compileServerPrivateKey,
54
+ customCompilers,
55
+ livereloadWatchConfig,
55
56
  }) => {
56
57
  const jsenvStartExploringFunction = async ({ jsenvCancellationToken }) => {
57
58
  cancellationToken = composeCancellationToken(
@@ -100,6 +101,7 @@ export const startExploring = async ({
100
101
  "service:exploring-data": (request) => serveExploringData(request),
101
102
  "service:explorables": (request) => serveExplorableListAsJson(request),
102
103
  },
104
+ customCompilers,
103
105
  jsenvDirectoryRelativeUrl,
104
106
  outDirectoryName,
105
107
  inlineImportMapIntoHTML,
@@ -107,8 +109,12 @@ export const startExploring = async ({
107
109
  compileServerLogLevel,
108
110
  compileServerCanReadFromFilesystem,
109
111
  compileServerCanWriteOnFilesystem,
112
+ compileServerPort,
113
+ compileServerProtocol,
114
+ compileServerCertificate,
115
+ compileServerPrivateKey,
110
116
  runtimeSupport: runtimeSupportDuringDev,
111
- ...rest,
117
+ livereloadWatchConfig,
112
118
  })
113
119
 
114
120
  return compileServer
@@ -1,204 +0,0 @@
1
- import {
2
- resolveDirectoryUrl,
3
- resolveUrl,
4
- urlIsInsideOf,
5
- urlToRelativeUrl,
6
- urlToBasename,
7
- urlToFilename,
8
- } from "@jsenv/filesystem"
9
- import { urlToContentType } from "@jsenv/server"
10
-
11
- import { jsenvCoreDirectoryUrl } from "../jsenvCoreDirectoryUrl.js"
12
- import {
13
- COMPILE_ID_BUILD_GLOBAL,
14
- COMPILE_ID_BUILD_GLOBAL_FILES,
15
- COMPILE_ID_BUILD_COMMONJS,
16
- COMPILE_ID_BUILD_COMMONJS_FILES,
17
- COMPILE_ID_OTHERWISE,
18
- } from "../CONSTANTS.js"
19
- import { buildUsingRollup } from "../building/buildUsingRollup.js"
20
- import { buildToCompilationResult } from "../building/buildToCompilationResult.js"
21
- import { transformResultToCompilationResult } from "./transformResultToCompilationResult.js"
22
- import { transformJs } from "./js-compilation-service/transformJs.js"
23
- import { compileIdToBabelPluginMap } from "./jsenvCompilerForJavaScript.js"
24
-
25
- const compileDynamicBuildFile = ({ compileId, originalFileUrl, ...rest }) => {
26
- const contentType = urlToContentType(originalFileUrl)
27
-
28
- if (
29
- contentType !== "application/javascript" &&
30
- contentType !== "text/javascript"
31
- ) {
32
- return null
33
- }
34
-
35
- if (
36
- compileId === COMPILE_ID_BUILD_GLOBAL ||
37
- compileId === COMPILE_ID_BUILD_COMMONJS
38
- ) {
39
- return handleDynamicBuild({
40
- compileId,
41
- originalFileUrl,
42
- ...rest,
43
- })
44
- }
45
-
46
- if (
47
- compileId === COMPILE_ID_BUILD_GLOBAL_FILES ||
48
- compileId === COMPILE_ID_BUILD_COMMONJS_FILES
49
- ) {
50
- return handleDynamicBuildFile({
51
- compileId,
52
- originalFileUrl,
53
- ...rest,
54
- })
55
- }
56
-
57
- return null
58
- }
59
-
60
- export const jsenvCompilerForDynamicBuild = {
61
- "jsenv-compiler-dynamic-build": compileDynamicBuildFile,
62
- }
63
-
64
- const handleDynamicBuild = ({
65
- cancellationToken,
66
- logger,
67
-
68
- projectDirectoryUrl,
69
- compileId,
70
- originalFileUrl,
71
- compiledFileUrl,
72
- outDirectoryRelativeUrl,
73
- compileServerOrigin,
74
-
75
- babelPluginMap,
76
- }) => {
77
- const format = compileId === COMPILE_ID_BUILD_GLOBAL ? "global" : "commonjs"
78
-
79
- // might want to put this to false while working on jsenv
80
- // to that cache gets verified
81
- const isJenvInternalFile =
82
- false &&
83
- urlIsInsideOf(
84
- originalFileUrl,
85
- resolveUrl("./src/internal/", jsenvCoreDirectoryUrl),
86
- )
87
-
88
- return {
89
- writeOnFilesystem: true,
90
- useFilesystemAsCache: true,
91
- compileCacheSourcesValidation: !isJenvInternalFile,
92
- compileCacheAssetsValidation: !isJenvInternalFile,
93
- compile: async () => {
94
- const compileIdForFiles =
95
- format === "global"
96
- ? COMPILE_ID_BUILD_GLOBAL_FILES
97
- : COMPILE_ID_BUILD_COMMONJS_FILES
98
-
99
- const originalFileRelativeUrl = urlToRelativeUrl(
100
- originalFileUrl,
101
- projectDirectoryUrl,
102
- )
103
- const buildRelativeUrl =
104
- format === "commonjs"
105
- ? `${urlToBasename(originalFileUrl)}.cjs`
106
- : urlToFilename(originalFileUrl)
107
-
108
- const entryPointMap = {
109
- [`./${originalFileRelativeUrl}`]: `./${buildRelativeUrl}`,
110
- }
111
-
112
- const compileDirectoryRelativeUrl = `${outDirectoryRelativeUrl}${compileIdForFiles}/`
113
-
114
- const build = await buildUsingRollup({
115
- cancellationToken,
116
- logger,
117
-
118
- entryPointMap,
119
- projectDirectoryUrl,
120
- compileDirectoryRelativeUrl,
121
- compileServerOrigin,
122
- externalImportSpecifiers: [],
123
- babelPluginMap,
124
-
125
- format,
126
- node: format === "commonjs",
127
- browser: format !== "commonjs",
128
- // buildDirectoryUrl is just theorical because of writeOnFileSystem: false
129
- // but still important to know where the files will be written
130
- buildDirectoryUrl: resolveDirectoryUrl("./", compiledFileUrl),
131
- writeOnFileSystem: false,
132
- sourcemapExcludeSources: true,
133
- assetManifestFile: false,
134
- })
135
-
136
- const sourcemapFileUrl = `${compiledFileUrl}.map`
137
-
138
- return buildToCompilationResult(build, {
139
- mainFileName: buildRelativeUrl,
140
- projectDirectoryUrl,
141
- originalFileUrl,
142
- compiledFileUrl,
143
- sourcemapFileUrl,
144
- })
145
- },
146
- }
147
- }
148
-
149
- const handleDynamicBuildFile = ({
150
- projectDirectoryUrl,
151
- originalFileUrl,
152
- compiledFileUrl,
153
- compileId,
154
- groupMap,
155
- babelPluginMap,
156
- convertMap,
157
- transformTopLevelAwait,
158
- writeOnFilesystem,
159
- sourcemapExcludeSources,
160
- }) => {
161
- return {
162
- compile: async (originalFileContent) => {
163
- const transformResult = await transformJs({
164
- projectDirectoryUrl,
165
- code: originalFileContent,
166
- url: originalFileUrl,
167
- urlAfterTransform: compiledFileUrl,
168
- babelPluginMap: compileIdToBabelPluginMap(getWorstCompileId(groupMap), {
169
- groupMap,
170
- babelPluginMap,
171
- }),
172
- convertMap,
173
- transformTopLevelAwait,
174
- // we are compiling for rollup, do not transform into systemjs format
175
- moduleOutFormat: "esmodule",
176
- importMetaFormat:
177
- // eslint-disable-next-line no-nested-ternary
178
- compileId === COMPILE_ID_BUILD_GLOBAL_FILES
179
- ? "global"
180
- : compileId === COMPILE_ID_BUILD_COMMONJS_FILES
181
- ? "commonjs"
182
- : "esmodule",
183
- })
184
- const sourcemapFileUrl = `${compiledFileUrl}.map`
185
-
186
- return transformResultToCompilationResult(transformResult, {
187
- projectDirectoryUrl,
188
- originalFileContent,
189
- originalFileUrl,
190
- compiledFileUrl,
191
- sourcemapFileUrl,
192
- sourcemapMethod: writeOnFilesystem ? "comment" : "inline",
193
- sourcemapExcludeSources,
194
- })
195
- },
196
- }
197
- }
198
-
199
- const getWorstCompileId = (groupMap) => {
200
- if (COMPILE_ID_OTHERWISE in groupMap) {
201
- return COMPILE_ID_OTHERWISE
202
- }
203
- return Object.keys(groupMap)[Object.keys(groupMap).length - 1]
204
- }