@jsenv/core 25.4.1 → 25.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "25.4.1",
3
+ "version": "25.4.5",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -115,7 +115,7 @@
115
115
  "@babel/plugin-transform-react-jsx": "7.16.5",
116
116
  "@babel/plugin-transform-typescript": "7.16.1",
117
117
  "@babel/preset-env": "7.16.5",
118
- "@jsenv/assert": "2.4.1",
118
+ "@jsenv/assert": "2.5.0",
119
119
  "@jsenv/babel-preset": "1.1.2",
120
120
  "@jsenv/eslint-config": "16.0.9",
121
121
  "@jsenv/file-size-impact": "12.1.6",
@@ -15,6 +15,7 @@ export const importUsingChildProcess = async (
15
15
  stderr,
16
16
  } = {},
17
17
  ) => {
18
+ fileUrl = String(fileUrl)
18
19
  const result = await launchAndExecute({
19
20
  stopAfterExecute: true,
20
21
  fileRelativeUrl: String(fileUrl),
@@ -12,10 +12,10 @@ export const babelPluginTransformImportMeta = (api, { importMetaFormat }) => {
12
12
  addDefault,
13
13
  addNamed,
14
14
  } = require("@babel/helper-module-imports")
15
- const { parseExpression } = require("@babel/parser")
16
15
  let babelState
17
16
  const jsValueToAst = (jsValue) => {
18
- const valueAst = parseExpression(jsValue, babelState.opts)
17
+ const { parseExpression } = require("@babel/parser")
18
+ const valueAst = parseExpression(jsValue, babelState.parserOpts)
19
19
  return valueAst
20
20
  }
21
21
  const visitImportMetaProperty = ({
@@ -23,51 +23,44 @@ export const babelPluginTransformImportMeta = (api, { importMetaFormat }) => {
23
23
  replaceWithImport,
24
24
  replaceWithValue,
25
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") {
26
+ if (importMetaFormat === "esmodule") {
27
+ // keep native version
28
+ return
29
+ }
30
+ if (importMetaFormat === "systemjs") {
31
+ // systemjs will handle it
32
+ return
33
+ }
34
+ if (importMetaFormat === "commonjs") {
35
+ if (importMetaPropertyName === "url") {
36
36
  replaceWithImport({
37
37
  from: `@jsenv/core/helpers/import-meta/import-meta-url-commonjs.js`,
38
38
  })
39
39
  return
40
40
  }
41
- if (importMetaFormat === "global") {
42
- replaceWithImport({
43
- from: `@jsenv/core/helpers/import-meta/import-meta-url-global.js`,
41
+ if (importMetaPropertyName === "resolve") {
42
+ throw createParseError({
43
+ message: `import.meta.resolve() not supported with commonjs format`,
44
44
  })
45
- return
46
45
  }
46
+ replaceWithValue(undefined)
47
47
  return
48
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`,
49
+ if (importMetaFormat === "global") {
50
+ if (importMetaPropertyName === "url") {
51
+ replaceWithImport({
52
+ from: `@jsenv/core/helpers/import-meta/import-meta-url-global.js`,
61
53
  })
54
+ return
62
55
  }
63
- if (importMetaFormat === "global") {
56
+ if (importMetaPropertyName === "resolve") {
64
57
  throw createParseError({
65
58
  message: `import.meta.resolve() not supported with global format`,
66
59
  })
67
60
  }
61
+ replaceWithValue(undefined)
68
62
  return
69
63
  }
70
- replaceWithValue(undefined)
71
64
  }
72
65
 
73
66
  return {
@@ -77,31 +70,6 @@ export const babelPluginTransformImportMeta = (api, { importMetaFormat }) => {
77
70
  babelState = state
78
71
  },
79
72
 
80
- // visitor: {
81
- // Program(programPath) {
82
- // const paths = []
83
- // programPath.traverse({
84
- // MetaProperty(metaPropertyPath) {
85
- // const metaPropertyNode = metaPropertyPath.node
86
- // if (!metaPropertyNode.meta) {
87
- // return
88
- // }
89
- // if (metaPropertyNode.meta.name !== "import") {
90
- // return
91
- // }
92
- // if (metaPropertyNode.property.name !== "meta") {
93
- // return
94
- // }
95
- // paths.push(metaPropertyPath)
96
- // },
97
- // })
98
-
99
- // const importAst = addNamespace(programPath, importMetaSpecifier)
100
- // paths.forEach((path) => {
101
- // path.replaceWith(importAst)
102
- // })
103
- // },
104
-
105
73
  visitor: {
106
74
  Program(programPath) {
107
75
  const metaPropertyPathMap = {}
@@ -101,9 +101,7 @@ export const transformJs = async ({
101
101
  ...getMinimalBabelPluginMap(),
102
102
  "transform-import-meta": [
103
103
  babelPluginTransformImportMeta,
104
- {
105
- importMetaFormat,
106
- },
104
+ { importMetaFormat },
107
105
  ],
108
106
  ...babelPluginMap,
109
107
  ...(babelHelpersInjectionAsImport
@@ -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
  )
@@ -20,5 +20,8 @@ export const sameValueInTwoObjects = (object, secondObject) => {
20
20
  }
21
21
 
22
22
  export const sameValuesInTwoArrays = (array, secondArray) => {
23
- return array.every((value) => secondArray.includes(value))
23
+ return (
24
+ array.length === secondArray.length &&
25
+ array.every((value) => secondArray.includes(value))
26
+ )
24
27
  }
@@ -61,8 +61,9 @@ const readJsenvCoreVersionFromPackageFile = async () => {
61
61
  "./package.json",
62
62
  jsenvCoreDirectoryUrl,
63
63
  )
64
- const jsenvCoreVersion = await readFile(jsenvCorePackageFileUrl, {
64
+ const jsenvCorePackage = await readFile(jsenvCorePackageFileUrl, {
65
65
  as: "json",
66
- }).version
67
- return jsenvCoreVersion
66
+ })
67
+ const version = jsenvCorePackage.version
68
+ return version
68
69
  }
@@ -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
- }
@@ -277,7 +277,6 @@ export const createControllableNodeProcess = async ({
277
277
 
278
278
  const sendToProcess = async (childProcess, type, data) => {
279
279
  const source = uneval(data, { functionAllowed: true })
280
-
281
280
  return new Promise((resolve, reject) => {
282
281
  childProcess.send({ type, data: source }, (error) => {
283
282
  if (error) {
@@ -295,12 +294,10 @@ const installProcessOutputListener = (childProcess, callback) => {
295
294
  callback({ type: "log", text: String(chunk) })
296
295
  }
297
296
  childProcess.stdout.on("data", stdoutDataCallback)
298
-
299
297
  const stdErrorDataCallback = (chunk) => {
300
298
  callback({ type: "error", text: String(chunk) })
301
299
  }
302
300
  childProcess.stderr.on("data", stdErrorDataCallback)
303
-
304
301
  return () => {
305
302
  childProcess.stdout.removeListener("data", stdoutDataCallback)
306
303
  childProcess.stderr.removeListener("data", stdoutDataCallback)
@@ -59,8 +59,7 @@ const sendActionFailed = (error) => {
59
59
  sendToParent(
60
60
  ACTION_RESPONSE_EVENT_NAME,
61
61
  // process.send algorithm does not send non enumerable values
62
- // because it works with JSON.stringify I guess so use uneval
63
-
62
+ // so use @jsenv/uneval
64
63
  uneval(
65
64
  {
66
65
  status: ACTION_RESPONSE_STATUS_FAILED,
@@ -91,7 +90,6 @@ const sendToParent = (type, data) => {
91
90
  if (!process.connected) {
92
91
  return
93
92
  }
94
-
95
93
  // this can keep process alive longer than expected
96
94
  // when source is a long string.
97
95
  // It means node process may stay alive longer than expected
@@ -111,11 +109,9 @@ const onceProcessMessage = (type, callback) => {
111
109
  callback(eval(`(${event.data})`))
112
110
  }
113
111
  }
114
-
115
112
  const removeListener = () => {
116
113
  process.removeListener("message", listener)
117
114
  }
118
-
119
115
  process.on("message", listener)
120
116
  return removeListener
121
117
  }