@jsenv/core 25.4.2 → 25.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "25.4.2",
3
+ "version": "25.4.3",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -139,7 +139,7 @@ export const compileHtml = async ({
139
139
  addHtmlMutation,
140
140
  })
141
141
  }
142
- await visitImportmapScript({
142
+ await visitImportmapScripts({
143
143
  logger,
144
144
  url,
145
145
  compiledUrl,
@@ -245,7 +245,7 @@ const visitRessourceHints = async ({ ressourceHints, addHtmlMutation }) => {
245
245
  )
246
246
  }
247
247
 
248
- const visitImportmapScript = async ({
248
+ const visitImportmapScripts = async ({
249
249
  logger,
250
250
  url,
251
251
  compiledUrl,
@@ -265,14 +265,15 @@ const visitImportmapScript = async ({
265
265
  const type = typeAttribute ? typeAttribute.value : "application/javascript"
266
266
  return type === "importmap"
267
267
  })
268
+ const jsenvImportmap = getDefaultImportmap(compiledUrl, {
269
+ projectDirectoryUrl,
270
+ compileDirectoryUrl,
271
+ })
272
+
268
273
  // in case there is no importmap, force the presence
269
274
  // so that '@jsenv/core/' are still remapped
270
275
  if (importmapScripts.length === 0) {
271
- const defaultImportMap = getDefaultImportmap(compiledUrl, {
272
- projectDirectoryUrl,
273
- compileDirectoryUrl,
274
- })
275
- const defaultImportMapAsText = JSON.stringify(defaultImportMap, null, " ")
276
+ const defaultImportMapAsText = JSON.stringify(jsenvImportmap, null, " ")
276
277
  onHtmlImportmapInfo({
277
278
  url: compiledUrl,
278
279
  text: defaultImportMapAsText,
@@ -324,6 +325,7 @@ const visitImportmapScript = async ({
324
325
  )
325
326
  importmap = {}
326
327
  }
328
+ importmap = composeTwoImportMaps(jsenvImportmap, importmap)
327
329
  const importmapAsText = JSON.stringify(importmap, null, " ")
328
330
  onHtmlImportmapInfo({
329
331
  url: importmapUrl,
@@ -343,10 +345,6 @@ const visitImportmapScript = async ({
343
345
  return
344
346
  }
345
347
 
346
- const jsenvImportmap = getDefaultImportmap(compiledUrl, {
347
- projectDirectoryUrl,
348
- compileDirectoryUrl,
349
- })
350
348
  const htmlImportmap = JSON.parse(
351
349
  getHtmlNodeTextNode(firstImportmapScript).value,
352
350
  )
@@ -18,7 +18,6 @@ export const getDefaultImportmap = (
18
18
  jsenvCoreDirectoryUrl,
19
19
  projectDirectoryUrl,
20
20
  )
21
-
22
21
  let jsenvCoreUrl
23
22
  if (compileDirectoryUrl && urlIsInsideOf(url, compileDirectoryUrl)) {
24
23
  jsenvCoreUrl = resolveUrl(
@@ -28,25 +27,11 @@ export const getDefaultImportmap = (
28
27
  } else {
29
28
  jsenvCoreUrl = jsenvCoreDirectoryUrl
30
29
  }
31
-
30
+ const jsenvCoreRelativeUrl = urlToRelativeUrl(jsenvCoreUrl, url)
32
31
  const importmap = {
33
32
  imports: {
34
- "@jsenv/core/": makeRelativeMapping(jsenvCoreUrl, url),
33
+ "@jsenv/core/": `./${jsenvCoreRelativeUrl}`,
35
34
  },
36
35
  }
37
36
  return importmap
38
37
  }
39
-
40
- // this function just here to ensure relative urls starts with './'
41
- // so that importmap do not consider them as bare specifiers
42
- const makeRelativeMapping = (url, baseUrl) => {
43
- const relativeUrl = urlToRelativeUrl(url, baseUrl)
44
-
45
- if (urlIsInsideOf(url, baseUrl)) {
46
- if (relativeUrl.startsWith("../")) return relativeUrl
47
- if (relativeUrl.startsWith("./")) return relativeUrl
48
- return `./${relativeUrl}`
49
- }
50
-
51
- return relativeUrl
52
- }