@jsenv/core 25.4.1 → 25.4.2
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 +2 -2
- package/src/importUsingChildProcess.js +1 -0
- package/src/internal/compiling/babel_plugin_transform_import_meta.js +23 -55
- package/src/internal/compiling/js-compilation-service/transformJs.js +1 -3
- package/src/internal/node_launcher/createControllableNodeProcess.js +0 -3
- package/src/internal/node_runtime/nodeControllableFile.mjs +1 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "25.4.
|
|
3
|
+
"version": "25.4.2",
|
|
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.
|
|
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",
|
|
@@ -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
|
|
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 (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
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 (
|
|
42
|
-
|
|
43
|
-
|
|
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 (
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
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 (
|
|
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
|
|
@@ -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
|
-
//
|
|
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
|
}
|