@jsenv/core 35.0.3 → 35.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.
- package/dist/html/explorer.html +107 -107
- package/dist/js/new_stylesheet.js +3 -0
- package/dist/js/s.js.map +3 -3
- package/package.json +1 -1
- package/src/build/build.js +589 -587
- package/src/build/build_urls_generator.js +44 -44
- package/src/build/graph_utils.js +14 -14
- package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
- package/src/build/line_break_unix.js +11 -11
- package/src/build/start_build_server.js +37 -37
- package/src/build/version_generator.js +7 -7
- package/src/build/version_mappings_injection.js +23 -23
- package/src/dev/file_service.js +132 -132
- package/src/dev/start_dev_server.js +56 -56
- package/src/dev/user_agent.js +8 -8
- package/src/helpers/basic_fetch.js +24 -24
- package/src/helpers/command/command.js +28 -28
- package/src/helpers/lookup_package_directory.js +19 -16
- package/src/helpers/ping_server.js +17 -17
- package/src/helpers/require_from_jsenv.js +2 -2
- package/src/helpers/watch_source_files.js +9 -9
- package/src/helpers/web_url_converter.js +10 -10
- package/src/helpers/worker_reload.js +27 -27
- package/src/kitchen/compat/features_compatibility.js +1 -1
- package/src/kitchen/compat/runtime_compat.js +26 -24
- package/src/kitchen/errors.js +75 -75
- package/src/kitchen/fetched_content_compliance.js +8 -8
- package/src/kitchen/kitchen.js +251 -250
- package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
- package/src/kitchen/url_graph/url_graph_loader.js +30 -30
- package/src/kitchen/url_graph/url_graph_report.js +57 -57
- package/src/kitchen/url_graph/url_info_transformations.js +77 -77
- package/src/kitchen/url_graph.js +121 -121
- package/src/kitchen/url_specifier_encoding.js +21 -21
- package/src/kitchen/web_workers.js +5 -5
- package/src/main.js +3 -3
- package/src/plugins/autoreload/client/autoreload.js +96 -96
- package/src/plugins/autoreload/client/reload.js +56 -56
- package/src/plugins/autoreload/client/url_helpers.js +13 -13
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
- package/src/plugins/explorer/client/explorer.html +107 -107
- package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
- package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
- package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
- package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
- package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
- package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
- package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
- package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
- package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
- package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
- package/src/plugins/plugin_controller.js +124 -124
- package/src/plugins/plugins.js +27 -27
- package/src/plugins/ribbon/client/ribbon.js +6 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
- package/src/plugins/server_events/client/connection_manager.js +52 -52
- package/src/plugins/server_events/client/event_source_connection.js +36 -36
- package/src/plugins/server_events/client/events_manager.js +37 -37
- package/src/plugins/server_events/client/server_events_client.js +7 -7
- package/src/plugins/server_events/client/web_socket_connection.js +39 -39
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
- package/src/plugins/server_events/server_events_dispatcher.js +43 -43
- package/src/plugins/supervisor/client/supervisor.js +455 -450
- package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
- package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
- package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
- package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
- package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
- package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
- package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
- package/src/plugins/url_analysis/css/css_urls.js +12 -12
- package/src/plugins/url_analysis/html/html_urls.js +85 -85
- package/src/plugins/url_analysis/js/js_urls.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
- package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
- package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* to enable hot reloading
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { generateInlineContentUrl } from "@jsenv/urls"
|
|
7
|
+
import { generateInlineContentUrl } from "@jsenv/urls";
|
|
8
8
|
import {
|
|
9
9
|
parseHtmlString,
|
|
10
10
|
stringifyHtmlAst,
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
setHtmlNodeText,
|
|
17
17
|
removeHtmlNodeText,
|
|
18
18
|
getHtmlNodeAttribute,
|
|
19
|
-
} from "@jsenv/ast"
|
|
20
|
-
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
19
|
+
} from "@jsenv/ast";
|
|
20
|
+
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
|
|
21
21
|
|
|
22
22
|
export const jsenvPluginHtmlInlineContentAnalysis = ({
|
|
23
23
|
analyzeConvertedScripts,
|
|
@@ -30,7 +30,7 @@ export const jsenvPluginHtmlInlineContentAnalysis = ({
|
|
|
30
30
|
try {
|
|
31
31
|
await context.cook(inlineContentUrlInfo, {
|
|
32
32
|
reference: inlineContentReference,
|
|
33
|
-
})
|
|
33
|
+
});
|
|
34
34
|
} catch (e) {
|
|
35
35
|
if (e.code === "PARSE_ERROR") {
|
|
36
36
|
// When something like <style> or <script> contains syntax error
|
|
@@ -39,34 +39,34 @@ export const jsenvPluginHtmlInlineContentAnalysis = ({
|
|
|
39
39
|
const messageStart =
|
|
40
40
|
inlineContentUrlInfo.type === "css"
|
|
41
41
|
? `Syntax error on css declared inside <style>`
|
|
42
|
-
: `Syntax error on js declared inside <script
|
|
42
|
+
: `Syntax error on js declared inside <script>`;
|
|
43
43
|
|
|
44
44
|
context.logger.error(`${messageStart}: ${e.cause.reasonCode}
|
|
45
|
-
${e.traceMessage}`)
|
|
45
|
+
${e.traceMessage}`);
|
|
46
46
|
} else {
|
|
47
|
-
throw e
|
|
47
|
+
throw e;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
51
|
|
|
52
52
|
return {
|
|
53
53
|
name: "jsenv:html_inline_content_analysis",
|
|
54
54
|
appliesDuring: "*",
|
|
55
55
|
transformUrlContent: {
|
|
56
56
|
html: async (urlInfo, context) => {
|
|
57
|
-
const htmlAst = parseHtmlString(urlInfo.content)
|
|
58
|
-
const mutations = []
|
|
59
|
-
const actions = []
|
|
57
|
+
const htmlAst = parseHtmlString(urlInfo.content);
|
|
58
|
+
const mutations = [];
|
|
59
|
+
const actions = [];
|
|
60
60
|
visitHtmlNodes(htmlAst, {
|
|
61
61
|
style: (styleNode) => {
|
|
62
|
-
const styleNodeText = getHtmlNodeText(styleNode)
|
|
62
|
+
const styleNodeText = getHtmlNodeText(styleNode);
|
|
63
63
|
if (!styleNodeText) {
|
|
64
|
-
return
|
|
64
|
+
return;
|
|
65
65
|
}
|
|
66
66
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
67
67
|
getHtmlNodePosition(styleNode, {
|
|
68
68
|
preferOriginal: true,
|
|
69
|
-
})
|
|
69
|
+
});
|
|
70
70
|
const inlineStyleUrl = generateInlineContentUrl({
|
|
71
71
|
url: urlInfo.url,
|
|
72
72
|
extension: ".css",
|
|
@@ -74,9 +74,9 @@ ${e.traceMessage}`)
|
|
|
74
74
|
column,
|
|
75
75
|
lineEnd,
|
|
76
76
|
columnEnd,
|
|
77
|
-
})
|
|
77
|
+
});
|
|
78
78
|
const debug =
|
|
79
|
-
getHtmlNodeAttribute(styleNode, "jsenv-debug") !== undefined
|
|
79
|
+
getHtmlNodeAttribute(styleNode, "jsenv-debug") !== undefined;
|
|
80
80
|
const [inlineStyleReference, inlineStyleUrlInfo] =
|
|
81
81
|
context.referenceUtils.foundInline({
|
|
82
82
|
node: styleNode,
|
|
@@ -92,27 +92,27 @@ ${e.traceMessage}`)
|
|
|
92
92
|
contentType: "text/css",
|
|
93
93
|
content: styleNodeText,
|
|
94
94
|
debug,
|
|
95
|
-
})
|
|
95
|
+
});
|
|
96
96
|
actions.push(async () => {
|
|
97
97
|
await cookInlineContent({
|
|
98
98
|
context,
|
|
99
99
|
inlineContentUrlInfo: inlineStyleUrlInfo,
|
|
100
100
|
inlineContentReference: inlineStyleReference,
|
|
101
|
-
})
|
|
102
|
-
})
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
103
|
mutations.push(() => {
|
|
104
104
|
setHtmlNodeText(styleNode, inlineStyleUrlInfo.content, {
|
|
105
105
|
indentation: false, // indentation would decrease strack trace precision
|
|
106
|
-
})
|
|
106
|
+
});
|
|
107
107
|
setHtmlNodeAttributes(styleNode, {
|
|
108
108
|
"jsenv-cooked-by": "jsenv:html_inline_content_analysis",
|
|
109
|
-
})
|
|
110
|
-
})
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
111
|
},
|
|
112
112
|
script: (scriptNode) => {
|
|
113
|
-
const scriptNodeText = getHtmlNodeText(scriptNode)
|
|
113
|
+
const scriptNodeText = getHtmlNodeText(scriptNode);
|
|
114
114
|
if (!scriptNodeText) {
|
|
115
|
-
return
|
|
115
|
+
return;
|
|
116
116
|
}
|
|
117
117
|
// If the inline script was already handled by an other plugin, ignore it
|
|
118
118
|
// - we want to preserve inline scripts generated by html supervisor during dev
|
|
@@ -122,17 +122,17 @@ ${e.traceMessage}`)
|
|
|
122
122
|
getHtmlNodeAttribute(scriptNode, "jsenv-injected-by") ===
|
|
123
123
|
"jsenv:js_module_fallback"
|
|
124
124
|
) {
|
|
125
|
-
return
|
|
125
|
+
return;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
const hotAccept =
|
|
129
|
-
getHtmlNodeAttribute(scriptNode, "hot-accept") !== undefined
|
|
129
|
+
getHtmlNodeAttribute(scriptNode, "hot-accept") !== undefined;
|
|
130
130
|
const { type, contentType, extension } =
|
|
131
|
-
analyzeScriptNode(scriptNode)
|
|
131
|
+
analyzeScriptNode(scriptNode);
|
|
132
132
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
133
133
|
getHtmlNodePosition(scriptNode, {
|
|
134
134
|
preferOriginal: true,
|
|
135
|
-
})
|
|
135
|
+
});
|
|
136
136
|
let inlineScriptUrl = generateInlineContentUrl({
|
|
137
137
|
url: urlInfo.url,
|
|
138
138
|
extension: extension || CONTENT_TYPE.asFileExtension(contentType),
|
|
@@ -140,9 +140,9 @@ ${e.traceMessage}`)
|
|
|
140
140
|
column,
|
|
141
141
|
lineEnd,
|
|
142
142
|
columnEnd,
|
|
143
|
-
})
|
|
143
|
+
});
|
|
144
144
|
const debug =
|
|
145
|
-
getHtmlNodeAttribute(scriptNode, "jsenv-debug") !== undefined
|
|
145
|
+
getHtmlNodeAttribute(scriptNode, "jsenv-debug") !== undefined;
|
|
146
146
|
const [inlineScriptReference, inlineScriptUrlInfo] =
|
|
147
147
|
context.referenceUtils.foundInline({
|
|
148
148
|
node: scriptNode,
|
|
@@ -158,13 +158,13 @@ ${e.traceMessage}`)
|
|
|
158
158
|
contentType,
|
|
159
159
|
content: scriptNodeText,
|
|
160
160
|
debug,
|
|
161
|
-
})
|
|
161
|
+
});
|
|
162
162
|
actions.push(async () => {
|
|
163
163
|
await cookInlineContent({
|
|
164
164
|
context,
|
|
165
165
|
inlineContentUrlInfo: inlineScriptUrlInfo,
|
|
166
166
|
inlineContentReference: inlineScriptReference,
|
|
167
|
-
})
|
|
167
|
+
});
|
|
168
168
|
mutations.push(() => {
|
|
169
169
|
const attributes = {
|
|
170
170
|
"jsenv-cooked-by": "jsenv:html_inline_content_analysis",
|
|
@@ -173,34 +173,34 @@ ${e.traceMessage}`)
|
|
|
173
173
|
...(extension
|
|
174
174
|
? { type: type === "js_module" ? "module" : undefined }
|
|
175
175
|
: {}),
|
|
176
|
-
}
|
|
176
|
+
};
|
|
177
177
|
if (hotAccept) {
|
|
178
|
-
removeHtmlNodeText(scriptNode)
|
|
178
|
+
removeHtmlNodeText(scriptNode);
|
|
179
179
|
setHtmlNodeAttributes(scriptNode, {
|
|
180
180
|
...attributes,
|
|
181
|
-
})
|
|
181
|
+
});
|
|
182
182
|
} else {
|
|
183
183
|
setHtmlNodeText(scriptNode, inlineScriptUrlInfo.content, {
|
|
184
184
|
indentation: false, // indentation would decrease stack trace precision
|
|
185
|
-
})
|
|
185
|
+
});
|
|
186
186
|
setHtmlNodeAttributes(scriptNode, {
|
|
187
187
|
...attributes,
|
|
188
|
-
})
|
|
188
|
+
});
|
|
189
189
|
}
|
|
190
|
-
})
|
|
191
|
-
})
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
192
|
},
|
|
193
|
-
})
|
|
193
|
+
});
|
|
194
194
|
if (actions.length > 0) {
|
|
195
|
-
await Promise.all(actions.map((action) => action()))
|
|
195
|
+
await Promise.all(actions.map((action) => action()));
|
|
196
196
|
}
|
|
197
197
|
if (mutations.length === 0) {
|
|
198
|
-
return null
|
|
198
|
+
return null;
|
|
199
199
|
}
|
|
200
|
-
mutations.forEach((mutation) => mutation())
|
|
201
|
-
const htmlModified = stringifyHtmlAst(htmlAst)
|
|
202
|
-
return htmlModified
|
|
200
|
+
mutations.forEach((mutation) => mutation());
|
|
201
|
+
const htmlModified = stringifyHtmlAst(htmlAst);
|
|
202
|
+
return htmlModified;
|
|
203
203
|
},
|
|
204
204
|
},
|
|
205
|
-
}
|
|
206
|
-
}
|
|
205
|
+
};
|
|
206
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsenvPluginHtmlInlineContentAnalysis } from "./jsenv_plugin_html_inline_content_analysis.js"
|
|
2
|
-
import { jsenvPluginJsInlineContentAnalysis } from "./jsenv_plugin_js_inline_content_analysis.js"
|
|
3
|
-
import { jsenvPluginDataUrls } from "./jsenv_plugin_data_urls.js"
|
|
1
|
+
import { jsenvPluginHtmlInlineContentAnalysis } from "./jsenv_plugin_html_inline_content_analysis.js";
|
|
2
|
+
import { jsenvPluginJsInlineContentAnalysis } from "./jsenv_plugin_js_inline_content_analysis.js";
|
|
3
|
+
import { jsenvPluginDataUrls } from "./jsenv_plugin_data_urls.js";
|
|
4
4
|
|
|
5
5
|
export const jsenvPluginInlineContentAnalysis = ({
|
|
6
6
|
fetchInlineUrls = true,
|
|
@@ -12,8 +12,8 @@ export const jsenvPluginInlineContentAnalysis = ({
|
|
|
12
12
|
jsenvPluginHtmlInlineContentAnalysis({ analyzeConvertedScripts }),
|
|
13
13
|
jsenvPluginJsInlineContentAnalysis({ allowEscapeForVersioning }),
|
|
14
14
|
jsenvPluginDataUrls(),
|
|
15
|
-
]
|
|
16
|
-
}
|
|
15
|
+
];
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
const jsenvPluginInlineContentFetcher = () => {
|
|
19
19
|
return {
|
|
@@ -21,14 +21,14 @@ const jsenvPluginInlineContentFetcher = () => {
|
|
|
21
21
|
appliesDuring: "*",
|
|
22
22
|
fetchUrlContent: (urlInfo) => {
|
|
23
23
|
if (!urlInfo.isInline) {
|
|
24
|
-
return null
|
|
24
|
+
return null;
|
|
25
25
|
}
|
|
26
26
|
return {
|
|
27
27
|
// we want to fetch the original content otherwise we might re-cook
|
|
28
28
|
// content already cooked
|
|
29
29
|
content: urlInfo.originalContent,
|
|
30
30
|
contentType: urlInfo.contentType,
|
|
31
|
-
}
|
|
31
|
+
};
|
|
32
32
|
},
|
|
33
|
-
}
|
|
34
|
-
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { generateInlineContentUrl } from "@jsenv/urls"
|
|
2
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
3
|
-
import { applyBabelPlugins } from "@jsenv/ast"
|
|
4
|
-
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
5
|
-
import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js"
|
|
1
|
+
import { generateInlineContentUrl } from "@jsenv/urls";
|
|
2
|
+
import { createMagicSource } from "@jsenv/sourcemap";
|
|
3
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
4
|
+
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
|
|
5
|
+
import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js";
|
|
6
6
|
|
|
7
7
|
export const jsenvPluginJsInlineContentAnalysis = ({
|
|
8
8
|
allowEscapeForVersioning,
|
|
@@ -12,13 +12,13 @@ export const jsenvPluginJsInlineContentAnalysis = ({
|
|
|
12
12
|
js: urlInfo.content,
|
|
13
13
|
url: urlInfo.originalUrl,
|
|
14
14
|
isJsModule: urlInfo.type === "js_module",
|
|
15
|
-
})
|
|
15
|
+
});
|
|
16
16
|
if (inlineContentInfos.length === 0) {
|
|
17
|
-
return null
|
|
17
|
+
return null;
|
|
18
18
|
}
|
|
19
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
19
|
+
const magicSource = createMagicSource(urlInfo.content);
|
|
20
20
|
await inlineContentInfos.reduce(async (previous, inlineContentInfo) => {
|
|
21
|
-
await previous
|
|
21
|
+
await previous;
|
|
22
22
|
const inlineUrl = generateInlineContentUrl({
|
|
23
23
|
url: urlInfo.url,
|
|
24
24
|
extension: CONTENT_TYPE.asFileExtension(inlineContentInfo.contentType),
|
|
@@ -26,8 +26,8 @@ export const jsenvPluginJsInlineContentAnalysis = ({
|
|
|
26
26
|
column: inlineContentInfo.column,
|
|
27
27
|
lineEnd: inlineContentInfo.lineEnd,
|
|
28
28
|
columnEnd: inlineContentInfo.columnEnd,
|
|
29
|
-
})
|
|
30
|
-
let { quote } = inlineContentInfo
|
|
29
|
+
});
|
|
30
|
+
let { quote } = inlineContentInfo;
|
|
31
31
|
if (
|
|
32
32
|
quote === "`" &&
|
|
33
33
|
!context.isSupportedOnCurrentClients("template_literals")
|
|
@@ -35,7 +35,7 @@ export const jsenvPluginJsInlineContentAnalysis = ({
|
|
|
35
35
|
// if quote is "`" and template literals are not supported
|
|
36
36
|
// we'll use a regular string (single or double quote)
|
|
37
37
|
// when rendering the string
|
|
38
|
-
quote = JS_QUOTES.pickBest(inlineContentInfo.content)
|
|
38
|
+
quote = JS_QUOTES.pickBest(inlineContentInfo.content);
|
|
39
39
|
}
|
|
40
40
|
const [inlineReference, inlineUrlInfo] =
|
|
41
41
|
context.referenceUtils.foundInline({
|
|
@@ -47,11 +47,11 @@ export const jsenvPluginJsInlineContentAnalysis = ({
|
|
|
47
47
|
specifier: inlineUrl,
|
|
48
48
|
contentType: inlineContentInfo.contentType,
|
|
49
49
|
content: inlineContentInfo.content,
|
|
50
|
-
})
|
|
51
|
-
inlineUrlInfo.jsQuote = quote
|
|
50
|
+
});
|
|
51
|
+
inlineUrlInfo.jsQuote = quote;
|
|
52
52
|
inlineReference.escape = (value) =>
|
|
53
|
-
JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote })
|
|
54
|
-
await context.cook(inlineUrlInfo, { reference: inlineReference })
|
|
53
|
+
JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote });
|
|
54
|
+
await context.cook(inlineUrlInfo, { reference: inlineReference });
|
|
55
55
|
magicSource.replace({
|
|
56
56
|
start: inlineContentInfo.start,
|
|
57
57
|
end: inlineContentInfo.end,
|
|
@@ -59,10 +59,10 @@ export const jsenvPluginJsInlineContentAnalysis = ({
|
|
|
59
59
|
quote,
|
|
60
60
|
allowEscapeForVersioning,
|
|
61
61
|
}),
|
|
62
|
-
})
|
|
63
|
-
}, Promise.resolve())
|
|
64
|
-
return magicSource.toContentAndSourcemap()
|
|
65
|
-
}
|
|
62
|
+
});
|
|
63
|
+
}, Promise.resolve());
|
|
64
|
+
return magicSource.toContentAndSourcemap();
|
|
65
|
+
};
|
|
66
66
|
|
|
67
67
|
return {
|
|
68
68
|
name: "jsenv:js_inline_content_analysis",
|
|
@@ -71,8 +71,8 @@ export const jsenvPluginJsInlineContentAnalysis = ({
|
|
|
71
71
|
js_classic: parseAndTransformInlineContentCalls,
|
|
72
72
|
js_module: parseAndTransformInlineContentCalls,
|
|
73
73
|
},
|
|
74
|
-
}
|
|
75
|
-
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
76
|
|
|
77
77
|
const parseJsInlineContentInfos = async ({ js, url, isJsModule }) => {
|
|
78
78
|
if (
|
|
@@ -80,7 +80,7 @@ const parseJsInlineContentInfos = async ({ js, url, isJsModule }) => {
|
|
|
80
80
|
!js.includes("new Blob(") &&
|
|
81
81
|
!js.includes("JSON.parse(")
|
|
82
82
|
) {
|
|
83
|
-
return []
|
|
83
|
+
return [];
|
|
84
84
|
}
|
|
85
85
|
const { metadata } = await applyBabelPlugins({
|
|
86
86
|
babelPlugins: [babelPluginMetadataInlineContents],
|
|
@@ -89,92 +89,92 @@ const parseJsInlineContentInfos = async ({ js, url, isJsModule }) => {
|
|
|
89
89
|
type: isJsModule ? "js_module" : "js_classic",
|
|
90
90
|
content: js,
|
|
91
91
|
},
|
|
92
|
-
})
|
|
93
|
-
return metadata.inlineContentInfos
|
|
94
|
-
}
|
|
92
|
+
});
|
|
93
|
+
return metadata.inlineContentInfos;
|
|
94
|
+
};
|
|
95
95
|
|
|
96
96
|
const babelPluginMetadataInlineContents = () => {
|
|
97
97
|
return {
|
|
98
98
|
name: "metadata-inline-contents",
|
|
99
99
|
visitor: {
|
|
100
100
|
Program: (programPath, state) => {
|
|
101
|
-
const inlineContentInfos = []
|
|
101
|
+
const inlineContentInfos = [];
|
|
102
102
|
const onInlineContentInfo = (inlineContentInfo) => {
|
|
103
|
-
inlineContentInfos.push(inlineContentInfo)
|
|
104
|
-
}
|
|
103
|
+
inlineContentInfos.push(inlineContentInfo);
|
|
104
|
+
};
|
|
105
105
|
programPath.traverse({
|
|
106
106
|
NewExpression: (path) => {
|
|
107
107
|
if (isNewInlineContentCall(path)) {
|
|
108
108
|
analyzeNewInlineContentCall(path.node, {
|
|
109
109
|
onInlineContentInfo,
|
|
110
|
-
})
|
|
111
|
-
return
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
112
|
}
|
|
113
113
|
if (isNewBlobCall(path.node)) {
|
|
114
114
|
analyzeNewBlobCall(path.node, {
|
|
115
115
|
onInlineContentInfo,
|
|
116
|
-
})
|
|
117
|
-
return
|
|
116
|
+
});
|
|
117
|
+
return;
|
|
118
118
|
}
|
|
119
119
|
},
|
|
120
120
|
CallExpression: (path) => {
|
|
121
|
-
const node = path.node
|
|
121
|
+
const node = path.node;
|
|
122
122
|
if (isJSONParseCall(node)) {
|
|
123
123
|
analyzeJsonParseCall(node, {
|
|
124
124
|
onInlineContentInfo,
|
|
125
|
-
})
|
|
125
|
+
});
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
|
-
})
|
|
129
|
-
state.file.metadata.inlineContentInfos = inlineContentInfos
|
|
128
|
+
});
|
|
129
|
+
state.file.metadata.inlineContentInfos = inlineContentInfos;
|
|
130
130
|
},
|
|
131
131
|
},
|
|
132
|
-
}
|
|
133
|
-
}
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
134
|
|
|
135
135
|
const isNewInlineContentCall = (path) => {
|
|
136
|
-
const node = path.node
|
|
136
|
+
const node = path.node;
|
|
137
137
|
if (node.callee.type === "Identifier") {
|
|
138
138
|
// terser rename import to use a shorter name
|
|
139
|
-
const name = getOriginalName(path, node.callee.name)
|
|
140
|
-
return name === "InlineContent"
|
|
139
|
+
const name = getOriginalName(path, node.callee.name);
|
|
140
|
+
return name === "InlineContent";
|
|
141
141
|
}
|
|
142
142
|
if (node.callee.id && node.callee.id.type === "Identifier") {
|
|
143
|
-
const name = getOriginalName(path, node.callee.id.name)
|
|
144
|
-
return name === "InlineContent"
|
|
143
|
+
const name = getOriginalName(path, node.callee.id.name);
|
|
144
|
+
return name === "InlineContent";
|
|
145
145
|
}
|
|
146
|
-
return false
|
|
147
|
-
}
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
148
148
|
const analyzeNewInlineContentCall = (node, { onInlineContentInfo }) => {
|
|
149
149
|
analyzeArguments({
|
|
150
150
|
node,
|
|
151
151
|
onInlineContentInfo,
|
|
152
152
|
nodeHoldingContent: node.arguments[0],
|
|
153
153
|
type: "new_inline_content_first_arg",
|
|
154
|
-
})
|
|
155
|
-
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
156
|
|
|
157
157
|
const isNewBlobCall = (node) => {
|
|
158
|
-
return node.callee.type === "Identifier" && node.callee.name === "Blob"
|
|
159
|
-
}
|
|
158
|
+
return node.callee.type === "Identifier" && node.callee.name === "Blob";
|
|
159
|
+
};
|
|
160
160
|
const analyzeNewBlobCall = (node, { onInlineContentInfo }) => {
|
|
161
|
-
const firstArg = node.arguments[0]
|
|
161
|
+
const firstArg = node.arguments[0];
|
|
162
162
|
if (!firstArg) {
|
|
163
|
-
return
|
|
163
|
+
return;
|
|
164
164
|
}
|
|
165
165
|
if (firstArg.type !== "ArrayExpression") {
|
|
166
|
-
return
|
|
166
|
+
return;
|
|
167
167
|
}
|
|
168
168
|
if (firstArg.elements.length !== 1) {
|
|
169
|
-
return
|
|
169
|
+
return;
|
|
170
170
|
}
|
|
171
171
|
analyzeArguments({
|
|
172
172
|
node,
|
|
173
173
|
onInlineContentInfo,
|
|
174
174
|
nodeHoldingContent: firstArg.elements[0],
|
|
175
175
|
type: "new_blob_first_arg",
|
|
176
|
-
})
|
|
177
|
-
}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
178
|
|
|
179
179
|
const analyzeArguments = ({
|
|
180
180
|
node,
|
|
@@ -183,19 +183,19 @@ const analyzeArguments = ({
|
|
|
183
183
|
type,
|
|
184
184
|
}) => {
|
|
185
185
|
if (node.arguments.length !== 2) {
|
|
186
|
-
return
|
|
186
|
+
return;
|
|
187
187
|
}
|
|
188
|
-
const [, secondArg] = node.arguments
|
|
189
|
-
const typePropertyNode = getTypePropertyNode(secondArg)
|
|
188
|
+
const [, secondArg] = node.arguments;
|
|
189
|
+
const typePropertyNode = getTypePropertyNode(secondArg);
|
|
190
190
|
if (!typePropertyNode) {
|
|
191
|
-
return
|
|
191
|
+
return;
|
|
192
192
|
}
|
|
193
|
-
const typePropertyValueNode = typePropertyNode.value
|
|
193
|
+
const typePropertyValueNode = typePropertyNode.value;
|
|
194
194
|
if (typePropertyValueNode.type !== "StringLiteral") {
|
|
195
|
-
return
|
|
195
|
+
return;
|
|
196
196
|
}
|
|
197
|
-
const contentType = typePropertyValueNode.value
|
|
198
|
-
const contentDetails = extractContentDetails(nodeHoldingContent)
|
|
197
|
+
const contentType = typePropertyValueNode.value;
|
|
198
|
+
const contentDetails = extractContentDetails(nodeHoldingContent);
|
|
199
199
|
if (contentDetails) {
|
|
200
200
|
onInlineContentInfo({
|
|
201
201
|
node: nodeHoldingContent,
|
|
@@ -203,45 +203,45 @@ const analyzeArguments = ({
|
|
|
203
203
|
type,
|
|
204
204
|
contentType,
|
|
205
205
|
...contentDetails,
|
|
206
|
-
})
|
|
206
|
+
});
|
|
207
207
|
}
|
|
208
|
-
}
|
|
208
|
+
};
|
|
209
209
|
const extractContentDetails = (node) => {
|
|
210
210
|
if (node.type === "StringLiteral") {
|
|
211
211
|
return {
|
|
212
212
|
nodeType: "StringLiteral",
|
|
213
213
|
quote: node.extra.raw[0],
|
|
214
214
|
content: node.value,
|
|
215
|
-
}
|
|
215
|
+
};
|
|
216
216
|
}
|
|
217
217
|
if (node.type === "TemplateLiteral") {
|
|
218
|
-
const quasis = node.quasis
|
|
218
|
+
const quasis = node.quasis;
|
|
219
219
|
if (quasis.length !== 1) {
|
|
220
|
-
return null
|
|
220
|
+
return null;
|
|
221
221
|
}
|
|
222
|
-
const templateElementNode = quasis[0]
|
|
222
|
+
const templateElementNode = quasis[0];
|
|
223
223
|
return {
|
|
224
224
|
nodeType: "TemplateLiteral",
|
|
225
225
|
quote: "`",
|
|
226
226
|
content: templateElementNode.value.cooked,
|
|
227
|
-
}
|
|
227
|
+
};
|
|
228
228
|
}
|
|
229
|
-
return null
|
|
230
|
-
}
|
|
229
|
+
return null;
|
|
230
|
+
};
|
|
231
231
|
|
|
232
232
|
const isJSONParseCall = (node) => {
|
|
233
|
-
const callee = node.callee
|
|
233
|
+
const callee = node.callee;
|
|
234
234
|
return (
|
|
235
235
|
callee.type === "MemberExpression" &&
|
|
236
236
|
callee.object.type === "Identifier" &&
|
|
237
237
|
callee.object.name === "JSON" &&
|
|
238
238
|
callee.property.type === "Identifier" &&
|
|
239
239
|
callee.property.name === "parse"
|
|
240
|
-
)
|
|
241
|
-
}
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
242
|
const analyzeJsonParseCall = (node, { onInlineContentInfo }) => {
|
|
243
|
-
const firstArgNode = node.arguments[0]
|
|
244
|
-
const contentDetails = extractContentDetails(firstArgNode)
|
|
243
|
+
const firstArgNode = node.arguments[0];
|
|
244
|
+
const contentDetails = extractContentDetails(firstArgNode);
|
|
245
245
|
if (contentDetails) {
|
|
246
246
|
onInlineContentInfo({
|
|
247
247
|
node: firstArgNode,
|
|
@@ -249,9 +249,9 @@ const analyzeJsonParseCall = (node, { onInlineContentInfo }) => {
|
|
|
249
249
|
type: "json_parse_first_arg",
|
|
250
250
|
contentType: "application/json",
|
|
251
251
|
...contentDetails,
|
|
252
|
-
})
|
|
252
|
+
});
|
|
253
253
|
}
|
|
254
|
-
}
|
|
254
|
+
};
|
|
255
255
|
|
|
256
256
|
const getNodePosition = (node) => {
|
|
257
257
|
return {
|
|
@@ -261,54 +261,54 @@ const getNodePosition = (node) => {
|
|
|
261
261
|
column: node.loc.start.column,
|
|
262
262
|
lineEnd: node.loc.end.line,
|
|
263
263
|
columnEnd: node.loc.end.column,
|
|
264
|
-
}
|
|
265
|
-
}
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
266
|
const getOriginalName = (path, name) => {
|
|
267
|
-
const binding = path.scope.getBinding(name)
|
|
267
|
+
const binding = path.scope.getBinding(name);
|
|
268
268
|
if (!binding) {
|
|
269
|
-
return name
|
|
269
|
+
return name;
|
|
270
270
|
}
|
|
271
271
|
if (binding.path.type === "ImportSpecifier") {
|
|
272
|
-
const importedName = binding.path.node.imported.name
|
|
272
|
+
const importedName = binding.path.node.imported.name;
|
|
273
273
|
if (name === importedName) {
|
|
274
|
-
return name
|
|
274
|
+
return name;
|
|
275
275
|
}
|
|
276
|
-
return getOriginalName(path, importedName)
|
|
276
|
+
return getOriginalName(path, importedName);
|
|
277
277
|
}
|
|
278
278
|
if (binding.path.type === "VariableDeclarator") {
|
|
279
|
-
const { node } = binding.path
|
|
280
|
-
const { init } = node
|
|
279
|
+
const { node } = binding.path;
|
|
280
|
+
const { init } = node;
|
|
281
281
|
if (init && init.type === "Identifier") {
|
|
282
|
-
const previousName = init.name
|
|
283
|
-
return getOriginalName(path, previousName)
|
|
282
|
+
const previousName = init.name;
|
|
283
|
+
return getOriginalName(path, previousName);
|
|
284
284
|
}
|
|
285
285
|
if (node.id && node.id.type === "Identifier") {
|
|
286
|
-
const { constantViolations } = binding
|
|
286
|
+
const { constantViolations } = binding;
|
|
287
287
|
if (constantViolations && constantViolations.length > 0) {
|
|
288
|
-
const lastViolation = constantViolations[constantViolations.length - 1]
|
|
288
|
+
const lastViolation = constantViolations[constantViolations.length - 1];
|
|
289
289
|
if (
|
|
290
290
|
lastViolation &&
|
|
291
291
|
lastViolation.node.type === "AssignmentExpression" &&
|
|
292
292
|
lastViolation.node.right.type === "MemberExpression" &&
|
|
293
293
|
lastViolation.node.right.property.type === "Identifier"
|
|
294
294
|
) {
|
|
295
|
-
return lastViolation.node.right.property.name
|
|
295
|
+
return lastViolation.node.right.property.name;
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
|
-
return name
|
|
301
|
-
}
|
|
300
|
+
return name;
|
|
301
|
+
};
|
|
302
302
|
const getTypePropertyNode = (node) => {
|
|
303
303
|
if (node.type !== "ObjectExpression") {
|
|
304
|
-
return null
|
|
304
|
+
return null;
|
|
305
305
|
}
|
|
306
|
-
const { properties } = node
|
|
306
|
+
const { properties } = node;
|
|
307
307
|
return properties.find((property) => {
|
|
308
308
|
return (
|
|
309
309
|
property.type === "ObjectProperty" &&
|
|
310
310
|
property.key.type === "Identifier" &&
|
|
311
311
|
property.key.name === "type"
|
|
312
|
-
)
|
|
313
|
-
})
|
|
314
|
-
}
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
};
|