@jsenv/core 27.0.0-alpha.39 → 27.0.0-alpha.41
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/event_source_client.js +549 -0
- package/dist/event_source_client.js.map +188 -0
- package/dist/html_supervisor_installer.js +1145 -0
- package/dist/html_supervisor_installer.js.map +322 -0
- package/dist/html_supervisor_setup.js +92 -0
- package/dist/html_supervisor_setup.js.map +57 -0
- package/package.json +5 -4
- package/src/build/build.js +4 -0
- package/src/jsenv_root_directory_url.js +1 -0
- package/src/omega/kitchen.js +4 -0
- package/src/omega/url_graph/url_info_transformations.js +11 -4
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +10 -5
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +2 -1
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +3 -1
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +14 -9
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +151 -125
- package/src/plugins/plugins.js +8 -1
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +56 -102
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +18 -47
- package/src/plugins/url_references/js/js_urls.js +9 -114
- package/src/plugins/url_references/jsenv_plugin_imports_analysis.js +10 -10
- package/src/plugins/transpilation/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "27.0.0-alpha.
|
|
3
|
+
"version": "27.0.0-alpha.41",
|
|
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": ">=16.13.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
|
"imports": {},
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"@jsenv/node-esm-resolution": "0.0.6",
|
|
68
69
|
"@jsenv/server": "12.6.1",
|
|
69
70
|
"@jsenv/uneval": "1.6.0",
|
|
70
|
-
"@jsenv/utils": "1.
|
|
71
|
+
"@jsenv/utils": "1.6.1",
|
|
71
72
|
"construct-style-sheets-polyfill": "3.1.0",
|
|
72
73
|
"cssnano": "5.1.7",
|
|
73
74
|
"cssnano-preset-default": "5.2.7",
|
|
@@ -107,4 +108,4 @@
|
|
|
107
108
|
"redux": "4.1.2",
|
|
108
109
|
"rollup": "2.70.1"
|
|
109
110
|
}
|
|
110
|
-
}
|
|
111
|
+
}
|
package/src/build/build.js
CHANGED
|
@@ -223,6 +223,9 @@ ${Object.keys(rawGraph.urlInfos).join("\n")}`,
|
|
|
223
223
|
})
|
|
224
224
|
})
|
|
225
225
|
const addToBundlerIfAny = (rawUrlInfo) => {
|
|
226
|
+
// if (rawUrlInfo.dependencies.size === 0) {
|
|
227
|
+
// return
|
|
228
|
+
// }
|
|
226
229
|
const bundler = bundlers[rawUrlInfo.type]
|
|
227
230
|
if (bundler) {
|
|
228
231
|
bundler.urlInfos.push(rawUrlInfo)
|
|
@@ -333,6 +336,7 @@ ${Object.keys(rawGraph.urlInfos).join("\n")}`,
|
|
|
333
336
|
urlGraph: finalGraph,
|
|
334
337
|
scenario: "build",
|
|
335
338
|
sourcemaps,
|
|
339
|
+
sourcemapsRelativeSources: true,
|
|
336
340
|
runtimeCompat,
|
|
337
341
|
plugins: [
|
|
338
342
|
jsenvPluginUrlReferences(),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const jsenvRootDirectoryUrl = new URL("../", import.meta.url).href
|
package/src/omega/kitchen.js
CHANGED
|
@@ -45,6 +45,7 @@ export const createKitchen = ({
|
|
|
45
45
|
test: false,
|
|
46
46
|
build: true,
|
|
47
47
|
}[scenario],
|
|
48
|
+
sourcemapsRelativeSources,
|
|
48
49
|
runtimeCompat = defaultRuntimeCompat,
|
|
49
50
|
writeOnFileSystem = true,
|
|
50
51
|
}) => {
|
|
@@ -214,6 +215,7 @@ export const createKitchen = ({
|
|
|
214
215
|
urlGraph,
|
|
215
216
|
sourcemaps,
|
|
216
217
|
sourcemapsSources,
|
|
218
|
+
sourcemapsRelativeSources,
|
|
217
219
|
injectSourcemapPlaceholder: ({ urlInfo, specifier }) => {
|
|
218
220
|
const sourcemapReference = createReference({
|
|
219
221
|
trace: `sourcemap comment placeholder for ${urlInfo.url}`,
|
|
@@ -629,6 +631,8 @@ export const createKitchen = ({
|
|
|
629
631
|
const prepareEntryPoint = (params) => {
|
|
630
632
|
const entryReference = createReference(params)
|
|
631
633
|
const entryUrlInfo = resolveReference(entryReference)
|
|
634
|
+
// I should likely delete urlInfo.sourcemap
|
|
635
|
+
// otherwise it is reused when page is reloaded
|
|
632
636
|
return [entryReference, entryUrlInfo]
|
|
633
637
|
}
|
|
634
638
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { urlToRelativeUrl } from "@jsenv/filesystem"
|
|
1
2
|
import { composeTwoSourcemaps } from "@jsenv/utils/sourcemap/sourcemap_composition_v3.js"
|
|
2
3
|
import {
|
|
3
4
|
SOURCEMAP,
|
|
@@ -9,6 +10,7 @@ export const createUrlInfoTransformer = ({
|
|
|
9
10
|
logger,
|
|
10
11
|
sourcemaps,
|
|
11
12
|
sourcemapsSources,
|
|
13
|
+
sourcemapsRelativeSources,
|
|
12
14
|
urlGraph,
|
|
13
15
|
injectSourcemapPlaceholder,
|
|
14
16
|
foundSourcemap,
|
|
@@ -142,11 +144,16 @@ export const createUrlInfoTransformer = ({
|
|
|
142
144
|
const sourcemapReference = urlInfo.sourcemapReference
|
|
143
145
|
const sourcemapUrlInfo = urlGraph.getUrlInfo(sourcemapReference.url)
|
|
144
146
|
sourcemapUrlInfo.contentType = "application/json"
|
|
145
|
-
|
|
147
|
+
const sourcemap = urlInfo.sourcemap
|
|
148
|
+
if (sourcemapsRelativeSources) {
|
|
149
|
+
sourcemap.sources = sourcemap.sources.map((source) => {
|
|
150
|
+
const sourceRelative = urlToRelativeUrl(source, urlInfo.url)
|
|
151
|
+
return sourceRelative
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
sourcemapUrlInfo.content = JSON.stringify(sourcemap, null, " ")
|
|
146
155
|
if (sourcemaps === "inline") {
|
|
147
|
-
sourcemapReference.generatedSpecifier = sourcemapToBase64Url(
|
|
148
|
-
urlInfo.sourcemap,
|
|
149
|
-
)
|
|
156
|
+
sourcemapReference.generatedSpecifier = sourcemapToBase64Url(sourcemap)
|
|
150
157
|
}
|
|
151
158
|
if (sourcemaps === "file" || sourcemaps === "inline") {
|
|
152
159
|
urlInfo.content = SOURCEMAP.writeComment({
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { urlIsInsideOf } from "@jsenv/filesystem"
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
parseHtmlString,
|
|
3
5
|
stringifyHtmlAst,
|
|
4
6
|
injectScriptAsEarlyAsPossible,
|
|
5
7
|
createHtmlNode,
|
|
6
8
|
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
9
|
+
import { jsenvRootDirectoryUrl } from "@jsenv/core/src/jsenv_root_directory_url.js"
|
|
7
10
|
|
|
8
|
-
export const jsenvPluginDevSSEClient = () => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export const jsenvPluginDevSSEClient = ({ rootDirectoryUrl }) => {
|
|
12
|
+
const preferSourceFiles =
|
|
13
|
+
rootDirectoryUrl === jsenvRootDirectoryUrl ||
|
|
14
|
+
urlIsInsideOf(rootDirectoryUrl, jsenvRootDirectoryUrl)
|
|
15
|
+
const eventSourceClientFileUrl = preferSourceFiles
|
|
16
|
+
? new URL("./client/event_source_client.js", import.meta.url).href
|
|
17
|
+
: new URL("./dist/event_source_client.js", jsenvRootDirectoryUrl).href
|
|
13
18
|
|
|
14
19
|
return {
|
|
15
20
|
name: "jsenv:dev_sse_client",
|
|
@@ -81,7 +81,8 @@ export const jsenvPluginDevSSEServer = ({
|
|
|
81
81
|
declinedBy: dependentUrl,
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
const { hotAcceptDependencies = [] } = dependentUrlInfo.data
|
|
85
|
+
if (hotAcceptDependencies.includes(urlInfo.url)) {
|
|
85
86
|
instructions.push({
|
|
86
87
|
type: dependentUrlInfo.type,
|
|
87
88
|
boundary: urlToRelativeUrl(dependentUrl, rootDirectoryUrl),
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* - scripts are wrapped to be supervised
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { urlIsInsideOf } from "@jsenv/filesystem"
|
|
8
|
+
|
|
7
9
|
import {
|
|
8
10
|
parseHtmlString,
|
|
9
11
|
stringifyHtmlAst,
|
|
@@ -19,19 +21,22 @@ import {
|
|
|
19
21
|
setHtmlNodeGeneratedText,
|
|
20
22
|
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
21
23
|
import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
|
|
24
|
+
import { jsenvRootDirectoryUrl } from "@jsenv/core/src/jsenv_root_directory_url.js"
|
|
22
25
|
|
|
23
26
|
export const jsenvPluginHtmlSupervisor = ({
|
|
27
|
+
rootDirectoryUrl,
|
|
24
28
|
logs = false,
|
|
25
29
|
measurePerf = false,
|
|
26
|
-
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"./
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
}) => {
|
|
31
|
+
const preferSourceFiles =
|
|
32
|
+
rootDirectoryUrl === jsenvRootDirectoryUrl ||
|
|
33
|
+
urlIsInsideOf(rootDirectoryUrl, jsenvRootDirectoryUrl)
|
|
34
|
+
const htmlSupervisorSetupFileUrl = preferSourceFiles
|
|
35
|
+
? new URL("./client/html_supervisor_setup.js", import.meta.url).href
|
|
36
|
+
: new URL("./dist/html_supervisor_setup.js", jsenvRootDirectoryUrl)
|
|
37
|
+
const htmlSupervisorInstallerFileUrl = preferSourceFiles
|
|
38
|
+
? new URL("./client/html_supervisor_installer.js", import.meta.url).href
|
|
39
|
+
: new URL("./dist/html_supervisor_installer.js", jsenvRootDirectoryUrl)
|
|
35
40
|
|
|
36
41
|
return {
|
|
37
42
|
name: "jsenv:html_supervisor",
|
|
@@ -2,38 +2,30 @@ import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
|
|
|
2
2
|
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
3
3
|
import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
|
|
4
4
|
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
5
|
-
import { getTypePropertyNode } from "@jsenv/utils/js_ast/js_ast.js"
|
|
6
5
|
import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
|
|
7
6
|
|
|
8
7
|
export const jsenvPluginJsInlineContent = ({ allowEscapeForVersioning }) => {
|
|
9
8
|
const parseAndTransformInlineContentCalls = async (urlInfo, context) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
) {
|
|
15
|
-
return null
|
|
16
|
-
}
|
|
17
|
-
const { metadata } = await applyBabelPlugins({
|
|
18
|
-
babelPlugins: [babelPluginMetadataInlineContentCalls],
|
|
19
|
-
urlInfo,
|
|
9
|
+
const inlineContentInfos = await parseJsInlineContentInfos({
|
|
10
|
+
js: urlInfo.content,
|
|
11
|
+
url: (urlInfo.data && urlInfo.data.rawUrl) || urlInfo.url,
|
|
12
|
+
isJsModule: urlInfo.type === "js_module",
|
|
20
13
|
})
|
|
21
|
-
|
|
22
|
-
if (inlineContentCalls.length === 0) {
|
|
14
|
+
if (inlineContentInfos.length === 0) {
|
|
23
15
|
return null
|
|
24
16
|
}
|
|
25
17
|
const magicSource = createMagicSource(urlInfo.content)
|
|
26
|
-
await
|
|
18
|
+
await inlineContentInfos.reduce(async (previous, inlineContentInfo) => {
|
|
27
19
|
await previous
|
|
28
20
|
const inlineUrl = generateInlineContentUrl({
|
|
29
21
|
url: urlInfo.url,
|
|
30
|
-
extension: CONTENT_TYPE.asFileExtension(
|
|
31
|
-
line:
|
|
32
|
-
column:
|
|
33
|
-
lineEnd:
|
|
34
|
-
columnEnd:
|
|
22
|
+
extension: CONTENT_TYPE.asFileExtension(inlineContentInfo.contentType),
|
|
23
|
+
line: inlineContentInfo.line,
|
|
24
|
+
column: inlineContentInfo.column,
|
|
25
|
+
lineEnd: inlineContentInfo.lineEnd,
|
|
26
|
+
columnEnd: inlineContentInfo.columnEnd,
|
|
35
27
|
})
|
|
36
|
-
let { quote } =
|
|
28
|
+
let { quote } = inlineContentInfo
|
|
37
29
|
if (
|
|
38
30
|
quote === "`" &&
|
|
39
31
|
!context.isSupportedOnCurrentClients("template_literals")
|
|
@@ -41,18 +33,18 @@ export const jsenvPluginJsInlineContent = ({ allowEscapeForVersioning }) => {
|
|
|
41
33
|
// if quote is "`" and template literals are not supported
|
|
42
34
|
// we'll use a regular string (single or double quote)
|
|
43
35
|
// when rendering the string
|
|
44
|
-
quote = JS_QUOTES.pickBest(
|
|
36
|
+
quote = JS_QUOTES.pickBest(inlineContentInfo.content)
|
|
45
37
|
}
|
|
46
38
|
const [inlineReference, inlineUrlInfo] =
|
|
47
39
|
context.referenceUtils.foundInline({
|
|
48
40
|
type: "js_inline_content",
|
|
49
|
-
subtype:
|
|
41
|
+
subtype: inlineContentInfo.type, // "new_blob_first_arg", "new_inline_content_first_arg", "json_parse_first_arg"
|
|
50
42
|
isOriginalPosition: urlInfo.content === urlInfo.originalContent,
|
|
51
|
-
line:
|
|
52
|
-
column:
|
|
43
|
+
line: inlineContentInfo.line,
|
|
44
|
+
column: inlineContentInfo.column,
|
|
53
45
|
specifier: inlineUrl,
|
|
54
|
-
contentType:
|
|
55
|
-
content:
|
|
46
|
+
contentType: inlineContentInfo.contentType,
|
|
47
|
+
content: inlineContentInfo.content,
|
|
56
48
|
})
|
|
57
49
|
inlineUrlInfo.jsQuote = quote
|
|
58
50
|
inlineReference.escape = (value) =>
|
|
@@ -62,8 +54,8 @@ export const jsenvPluginJsInlineContent = ({ allowEscapeForVersioning }) => {
|
|
|
62
54
|
urlInfo: inlineUrlInfo,
|
|
63
55
|
})
|
|
64
56
|
magicSource.replace({
|
|
65
|
-
start:
|
|
66
|
-
end:
|
|
57
|
+
start: inlineContentInfo.start,
|
|
58
|
+
end: inlineContentInfo.end,
|
|
67
59
|
replacement: JS_QUOTES.escapeSpecialChars(inlineUrlInfo.content, {
|
|
68
60
|
quote,
|
|
69
61
|
allowEscapeForVersioning,
|
|
@@ -83,78 +75,136 @@ export const jsenvPluginJsInlineContent = ({ allowEscapeForVersioning }) => {
|
|
|
83
75
|
}
|
|
84
76
|
}
|
|
85
77
|
|
|
86
|
-
const
|
|
78
|
+
const parseJsInlineContentInfos = async ({ js, url, isJsModule }) => {
|
|
79
|
+
if (
|
|
80
|
+
!js.includes("InlineContent") &&
|
|
81
|
+
!js.includes("new Blob(") &&
|
|
82
|
+
!js.includes("JSON.parse(")
|
|
83
|
+
) {
|
|
84
|
+
return []
|
|
85
|
+
}
|
|
86
|
+
const { metadata } = await applyBabelPlugins({
|
|
87
|
+
babelPlugins: [babelPluginMetadataInlineContents],
|
|
88
|
+
urlInfo: {
|
|
89
|
+
url,
|
|
90
|
+
type: isJsModule ? "js_module" : "js_classic",
|
|
91
|
+
content: js,
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
return metadata.inlineContentInfos
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const babelPluginMetadataInlineContents = () => {
|
|
87
98
|
return {
|
|
88
|
-
name: "metadata-inline-
|
|
99
|
+
name: "metadata-inline-contents",
|
|
89
100
|
visitor: {
|
|
90
101
|
Program: (programPath, state) => {
|
|
91
|
-
const
|
|
102
|
+
const inlineContentInfos = []
|
|
103
|
+
const onInlineContentInfo = (inlineContentInfo) => {
|
|
104
|
+
inlineContentInfos.push(inlineContentInfo)
|
|
105
|
+
}
|
|
92
106
|
programPath.traverse({
|
|
93
107
|
NewExpression: (path) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
if (isNewInlineContentCall(path)) {
|
|
109
|
+
analyzeNewInlineContentCall(path.node, {
|
|
110
|
+
onInlineContentInfo,
|
|
111
|
+
})
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
if (isNewBlobCall(path.node)) {
|
|
115
|
+
analyzeNewBlobCall(path.node, {
|
|
116
|
+
onInlineContentInfo,
|
|
117
|
+
})
|
|
97
118
|
return
|
|
98
119
|
}
|
|
99
120
|
},
|
|
100
121
|
CallExpression: (path) => {
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
122
|
+
const node = path.node
|
|
123
|
+
if (isJSONParseCall(node)) {
|
|
124
|
+
analyzeJsonParseCall(node, {
|
|
125
|
+
onInlineContentInfo,
|
|
126
|
+
})
|
|
105
127
|
}
|
|
106
128
|
},
|
|
107
129
|
})
|
|
108
|
-
state.file.metadata.
|
|
130
|
+
state.file.metadata.inlineContentInfos = inlineContentInfos
|
|
109
131
|
},
|
|
110
132
|
},
|
|
111
133
|
}
|
|
112
134
|
}
|
|
113
135
|
|
|
114
|
-
const
|
|
115
|
-
const identifier = parseNewIdentifier(path)
|
|
116
|
-
if (!identifier) {
|
|
117
|
-
return null
|
|
118
|
-
}
|
|
136
|
+
const isNewInlineContentCall = (path) => {
|
|
119
137
|
const node = path.node
|
|
138
|
+
if (node.callee.type === "Identifier") {
|
|
139
|
+
// terser rename import to use a shorter name
|
|
140
|
+
const name = getOriginalName(path, node.callee.name)
|
|
141
|
+
return name === "InlineContent"
|
|
142
|
+
}
|
|
143
|
+
if (node.callee.id && node.callee.id.type === "Identifier") {
|
|
144
|
+
const name = getOriginalName(path, node.callee.id.name)
|
|
145
|
+
return name === "InlineContent"
|
|
146
|
+
}
|
|
147
|
+
return false
|
|
148
|
+
}
|
|
149
|
+
const analyzeNewInlineContentCall = (node, { onInlineContentInfo }) => {
|
|
150
|
+
analyzeArguments({
|
|
151
|
+
node,
|
|
152
|
+
onInlineContentInfo,
|
|
153
|
+
nodeHoldingContent: node.arguments[0],
|
|
154
|
+
type: "new_inline_content_first_arg",
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const isNewBlobCall = (node) => {
|
|
159
|
+
return node.callee.type === "Identifier" && node.callee.name === "Blob"
|
|
160
|
+
}
|
|
161
|
+
const analyzeNewBlobCall = (node, { onInlineContentInfo }) => {
|
|
162
|
+
const firstArg = node.arguments[0]
|
|
163
|
+
if (firstArg.type !== "ArrayExpression") {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
if (firstArg.elements.length !== 1) {
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
analyzeArguments({
|
|
170
|
+
node,
|
|
171
|
+
onInlineContentInfo,
|
|
172
|
+
nodeHoldingContent: firstArg.elements[0],
|
|
173
|
+
type: "new_blob_first_arg",
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const analyzeArguments = ({
|
|
178
|
+
node,
|
|
179
|
+
onInlineContentInfo,
|
|
180
|
+
nodeHoldingContent,
|
|
181
|
+
type,
|
|
182
|
+
}) => {
|
|
120
183
|
if (node.arguments.length !== 2) {
|
|
121
|
-
return
|
|
184
|
+
return
|
|
122
185
|
}
|
|
123
|
-
const [
|
|
186
|
+
const [, secondArg] = node.arguments
|
|
124
187
|
const typePropertyNode = getTypePropertyNode(secondArg)
|
|
125
|
-
if (!typePropertyNode
|
|
126
|
-
return
|
|
188
|
+
if (!typePropertyNode) {
|
|
189
|
+
return
|
|
127
190
|
}
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (type === "new_inline_content") {
|
|
132
|
-
nodeHoldingInlineContent = firstArg
|
|
133
|
-
} else if (type === "new_blob") {
|
|
134
|
-
if (firstArg.type !== "ArrayExpression") {
|
|
135
|
-
return null
|
|
136
|
-
}
|
|
137
|
-
if (firstArg.elements.length !== 1) {
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
140
|
-
nodeHoldingInlineContent = firstArg.elements[0]
|
|
191
|
+
const typePropertyValueNode = typePropertyNode.value
|
|
192
|
+
if (typePropertyValueNode.type !== "StringLiteral") {
|
|
193
|
+
return
|
|
141
194
|
}
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
type
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
...inlineContentInfo,
|
|
153
|
-
...getNodePosition(nodeHoldingInlineContent),
|
|
195
|
+
const contentType = typePropertyValueNode.value
|
|
196
|
+
const contentDetails = extractContentDetails(nodeHoldingContent)
|
|
197
|
+
if (contentDetails) {
|
|
198
|
+
onInlineContentInfo({
|
|
199
|
+
node: nodeHoldingContent,
|
|
200
|
+
...getNodePosition(nodeHoldingContent),
|
|
201
|
+
type,
|
|
202
|
+
contentType,
|
|
203
|
+
...contentDetails,
|
|
204
|
+
})
|
|
154
205
|
}
|
|
155
206
|
}
|
|
156
|
-
|
|
157
|
-
const extractInlineContentInfo = (node) => {
|
|
207
|
+
const extractContentDetails = (node) => {
|
|
158
208
|
if (node.type === "StringLiteral") {
|
|
159
209
|
return {
|
|
160
210
|
nodeType: "StringLiteral",
|
|
@@ -177,55 +227,6 @@ const extractInlineContentInfo = (node) => {
|
|
|
177
227
|
return null
|
|
178
228
|
}
|
|
179
229
|
|
|
180
|
-
const parseNewIdentifier = (path) => {
|
|
181
|
-
const node = path.node
|
|
182
|
-
if (node.callee.type === "Identifier") {
|
|
183
|
-
// terser rename import to use a shorter name
|
|
184
|
-
const name = getOriginalName(path, node.callee.name)
|
|
185
|
-
if (name === "InlineContent") {
|
|
186
|
-
return {
|
|
187
|
-
type: "new_inline_content",
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (name === "Blob") {
|
|
191
|
-
return {
|
|
192
|
-
type: "new_blob",
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return null
|
|
196
|
-
}
|
|
197
|
-
if (node.callee.id) {
|
|
198
|
-
// terser might combine new InlineContent('') declaration and usage
|
|
199
|
-
if (node.callee.id.type !== "Identifier") {
|
|
200
|
-
return null
|
|
201
|
-
}
|
|
202
|
-
const name = getOriginalName(path, node.callee.id.name)
|
|
203
|
-
if (name === "InlineContent") {
|
|
204
|
-
return {
|
|
205
|
-
type: "new_inline_content",
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return null
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const analyzeJsonParseCall = (path) => {
|
|
213
|
-
const node = path.node
|
|
214
|
-
if (!isJSONParseCall(node)) {
|
|
215
|
-
return null
|
|
216
|
-
}
|
|
217
|
-
const inlineContentInfo = extractInlineContentInfo(node.arguments[0])
|
|
218
|
-
if (!inlineContentInfo) {
|
|
219
|
-
return null
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
type: "json_parse_first_arg",
|
|
223
|
-
contentType: "application/json",
|
|
224
|
-
...inlineContentInfo,
|
|
225
|
-
...getNodePosition(node.arguments[0]),
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
230
|
const isJSONParseCall = (node) => {
|
|
230
231
|
const callee = node.callee
|
|
231
232
|
return (
|
|
@@ -236,6 +237,19 @@ const isJSONParseCall = (node) => {
|
|
|
236
237
|
callee.property.name === "parse"
|
|
237
238
|
)
|
|
238
239
|
}
|
|
240
|
+
const analyzeJsonParseCall = (node, { onInlineContentInfo }) => {
|
|
241
|
+
const firstArgNode = node.arguments[0]
|
|
242
|
+
const contentDetails = extractContentDetails(firstArgNode)
|
|
243
|
+
if (contentDetails) {
|
|
244
|
+
onInlineContentInfo({
|
|
245
|
+
node: firstArgNode,
|
|
246
|
+
...getNodePosition(firstArgNode),
|
|
247
|
+
type: "json_parse_first_arg",
|
|
248
|
+
contentType: "application/json",
|
|
249
|
+
...contentDetails,
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
}
|
|
239
253
|
|
|
240
254
|
const getNodePosition = (node) => {
|
|
241
255
|
return {
|
|
@@ -247,7 +261,6 @@ const getNodePosition = (node) => {
|
|
|
247
261
|
columnEnd: node.loc.end.column,
|
|
248
262
|
}
|
|
249
263
|
}
|
|
250
|
-
|
|
251
264
|
const getOriginalName = (path, name) => {
|
|
252
265
|
const binding = path.scope.getBinding(name)
|
|
253
266
|
if (!binding) {
|
|
@@ -268,3 +281,16 @@ const getOriginalName = (path, name) => {
|
|
|
268
281
|
}
|
|
269
282
|
return name
|
|
270
283
|
}
|
|
284
|
+
const getTypePropertyNode = (node) => {
|
|
285
|
+
if (node.type !== "ObjectExpression") {
|
|
286
|
+
return null
|
|
287
|
+
}
|
|
288
|
+
const { properties } = node
|
|
289
|
+
return properties.find((property) => {
|
|
290
|
+
return (
|
|
291
|
+
property.type === "ObjectProperty" &&
|
|
292
|
+
property.key.type === "Identifier" &&
|
|
293
|
+
property.key.name === "type"
|
|
294
|
+
)
|
|
295
|
+
})
|
|
296
|
+
}
|
package/src/plugins/plugins.js
CHANGED
|
@@ -45,7 +45,14 @@ export const getCorePlugins = ({
|
|
|
45
45
|
return [
|
|
46
46
|
jsenvPluginUrlReferences(),
|
|
47
47
|
jsenvPluginTranspilation(transpilation),
|
|
48
|
-
...(htmlSupervisor
|
|
48
|
+
...(htmlSupervisor
|
|
49
|
+
? [
|
|
50
|
+
jsenvPluginHtmlSupervisor({
|
|
51
|
+
rootDirectoryUrl,
|
|
52
|
+
...htmlSupervisor,
|
|
53
|
+
}),
|
|
54
|
+
]
|
|
55
|
+
: []), // before inline as it turns inline <script> into <script src>
|
|
49
56
|
jsenvPluginInline(), // before "file urls" to resolve and load inline urls
|
|
50
57
|
jsenvPluginImportmap(), // before node esm to handle bare specifiers before node esm
|
|
51
58
|
jsenvPluginFileUrls(),
|