@jsenv/core 20.0.0 → 20.0.4

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.
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "20.0.0",
3
+ "version": "20.0.4",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,7 +11,8 @@
11
11
  "node": ">=14.9.0"
12
12
  },
13
13
  "publishConfig": {
14
- "access": "public"
14
+ "access": "public",
15
+ "registry": "https://registry.npmjs.org"
15
16
  },
16
17
  "type": "module",
17
18
  "exports": {
@@ -28,7 +29,7 @@
28
29
  "/main.js"
29
30
  ],
30
31
  "scripts": {
31
- "eslint-check": "node ./node_modules/eslint/bin/eslint.js . --ext=.js,.mjs",
32
+ "eslint-check": "node ./node_modules/eslint/bin/eslint.js . --ext=.js,.mjs,.html",
32
33
  "generate-importmap": "node ./script/importmap/generate_importmap.js",
33
34
  "build": "node ./script/build/build.js",
34
35
  "dist": "npm run build",
@@ -60,7 +60,7 @@ export const buildProject = async ({
60
60
  importPaths = {},
61
61
 
62
62
  urlVersioning = true,
63
- lineBreakNormalization = process.platform === "win32" && !minify,
63
+ lineBreakNormalization = process.platform === "win32",
64
64
  // when jsConcatenation is disabled rollup becomes almost useless
65
65
  // except it can still do tree shaking
66
66
  jsConcatenation = true,
@@ -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 })
@@ -38,6 +38,7 @@ import {
38
38
  parseSrcset,
39
39
  stringifySrcset,
40
40
  } from "@jsenv/core/src/internal/compiling/compileHtml.js"
41
+ import { setJavaScriptSourceMappingUrl } from "@jsenv/core/src/internal/sourceMappingURLUtils.js"
41
42
  import {
42
43
  getTargetAsBase64Url,
43
44
  targetIsReferencedOnlyByRessourceHint,
@@ -258,8 +259,14 @@ const moduleScriptSrcVisitor = (script, { format, notifyReferenceFound }) => {
258
259
  // here put a warning if we cannot inline importmap because it would mess
259
260
  // the remapping (note that it's feasible) but not yet supported
260
261
  removeHtmlNodeAttribute(script, srcAttribute)
261
- const { targetBuildBuffer } = script.target
262
- setHtmlNodeText(script, targetBuildBuffer)
262
+ const { targetBuildBuffer } = remoteScriptReference.target
263
+ const jsString = String(targetBuildBuffer)
264
+
265
+ const codeWithSourcemapComment = setJavaScriptSourceMappingUrl(
266
+ jsString,
267
+ `${remoteScriptReference.target.targetFileName}.map`
268
+ )
269
+ setHtmlNodeText(script, codeWithSourcemapComment)
263
270
  return
264
271
  }
265
272
 
@@ -669,6 +676,10 @@ const shouldInline = ({ reference, htmlNode }) => {
669
676
  return true
670
677
  }
671
678
 
679
+ return readAndRemoveForceInline(htmlNode)
680
+ }
681
+
682
+ const readAndRemoveForceInline = (htmlNode) => {
672
683
  const jsenvForceInlineAttribute = getHtmlNodeAttributeByName(
673
684
  htmlNode,
674
685
  "data-jsenv-force-inline",
@@ -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
package/dist/.DS_Store DELETED
Binary file
@@ -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
- }