@jsenv/core 27.0.0-alpha.6 → 27.0.0-alpha.60
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 +545 -0
- package/dist/event_source_client.js.map +187 -0
- package/dist/html_supervisor_installer.js +1236 -0
- package/dist/html_supervisor_installer.js.map +337 -0
- package/dist/html_supervisor_setup.js +95 -0
- package/dist/html_supervisor_setup.js.map +57 -0
- package/dist/import_meta_hot.js +86 -0
- package/dist/import_meta_hot.js.map +42 -0
- package/main.js +8 -1
- package/package.json +30 -28
- package/readme.md +6 -14
- package/src/build/build.js +943 -555
- package/src/build/build_urls_generator.js +48 -23
- package/src/build/graph_utils.js +31 -0
- package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
- package/src/build/inject_service_worker_urls.js +79 -0
- package/src/build/resync_ressource_hints.js +68 -0
- package/src/build/start_build_server.js +192 -0
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
- package/src/dev/start_dev_server.js +136 -30
- package/src/execute/execute.js +31 -6
- package/src/execute/run.js +19 -56
- package/src/execute/runtimes/browsers/from_playwright.js +207 -147
- package/src/execute/runtimes/node/controllable_file.mjs +26 -10
- package/src/execute/runtimes/node/node_execution_performance.js +67 -0
- package/src/execute/runtimes/node/node_process.js +280 -39
- package/src/jsenv_root_directory_url.js +1 -0
- package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
- package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
- package/src/omega/compat/runtime_compat.js +50 -0
- package/src/omega/errors.js +51 -58
- package/src/omega/fetched_content_compliance.js +24 -0
- package/src/omega/file_url_converter.js +8 -50
- package/src/omega/kitchen.js +482 -304
- package/src/omega/omega_server.js +2 -3
- package/src/omega/server/file_service.js +53 -25
- package/src/omega/server/user_agent.js +4 -2
- package/src/omega/url_graph/url_graph_load.js +22 -7
- package/src/omega/url_graph/url_graph_report.js +98 -48
- package/src/omega/url_graph/url_info_transformations.js +26 -9
- package/src/omega/url_graph.js +80 -16
- package/src/omega/web_workers.js +42 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +46 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +204 -0
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +27 -0
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
- package/src/plugins/bundling/css/bundle_css.js +140 -0
- package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
- package/src/plugins/bundling/js_module/bundle_js_module.js +309 -0
- package/src/plugins/bundling/jsenv_plugin_bundling.js +54 -0
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +34 -0
- package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +54 -41
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
- package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +8 -5
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +242 -0
- package/src/plugins/html_supervisor/client/html_supervisor_setup.js +79 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +83 -61
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +105 -0
- package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +33 -8
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
- package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +39 -33
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +67 -0
- package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
- package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +65 -44
- package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +297 -0
- package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
- package/src/plugins/minification/css/minify_css.js +9 -0
- package/src/plugins/minification/html/minify_html.js +15 -0
- package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
- package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
- package/src/plugins/minification/json/minify_json.js +8 -0
- package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +146 -0
- package/src/{omega → plugins}/plugin_controller.js +42 -11
- package/src/plugins/plugins.js +92 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js +874 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
- package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
- package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +199 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +270 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +55 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js +12 -19
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +45 -27
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +30 -6
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
- package/src/plugins/transpilation/fetch_original_url_info.js +30 -0
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +181 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +80 -0
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -0
- package/src/plugins/url_analysis/css/css_urls.js +49 -0
- package/src/plugins/url_analysis/html/html_urls.js +269 -0
- package/src/plugins/url_analysis/js/js_urls.js +67 -0
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +18 -0
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +17 -0
- package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
- package/src/plugins/url_version/jsenv_plugin_url_version.js +28 -0
- package/src/test/execute_plan.js +30 -18
- package/src/test/execute_test_plan.js +23 -8
- package/src/test/logs_file_execution.js +9 -8
- package/src/build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js +0 -225
- package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
- package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
- package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +0 -374
- package/src/dev/plugins/autoreload/sse_service.js +0 -149
- package/src/execute/runtimes/node/controlled_process.js +0 -316
- package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
- package/src/omega/core_plugins/html_supervisor/client/html_supervisor_installer.js +0 -168
- package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +0 -77
- package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
- package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
- package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
- package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
- package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
- package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
- package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
- package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +0 -77
- package/src/omega/core_plugins/url_version/jsenv_plugin_url_version.js +0 -50
- package/src/omega/core_plugins.js +0 -39
- package/src/omega/runtime_support/runtime_support.js +0 -20
- package/src/omega/url_graph/url_graph_sort.js +0 -29
- package/src/omega/url_mentions/css_url_mentions.js +0 -63
- package/src/omega/url_mentions/html_url_mentions.js +0 -185
- package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
- package/src/omega/url_mentions/parse_url_mentions.js +0 -37
- package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
package/src/omega/kitchen.js
CHANGED
|
@@ -4,47 +4,49 @@ import {
|
|
|
4
4
|
isFileSystemPath,
|
|
5
5
|
fileSystemPathToUrl,
|
|
6
6
|
moveUrl,
|
|
7
|
-
|
|
7
|
+
ensureWindowsDriveLetter,
|
|
8
8
|
} from "@jsenv/filesystem"
|
|
9
|
+
import { createDetailedMessage } from "@jsenv/logger"
|
|
9
10
|
|
|
10
11
|
import { stringifyUrlSite } from "@jsenv/utils/urls/url_trace.js"
|
|
12
|
+
import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
|
|
13
|
+
import { normalizeUrl, setUrlFilename } from "@jsenv/utils/urls/url_utils.js"
|
|
11
14
|
|
|
15
|
+
import { createPluginController } from "../plugins/plugin_controller.js"
|
|
12
16
|
import { createUrlInfoTransformer } from "./url_graph/url_info_transformations.js"
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { fileUrlConverter } from "./file_url_converter.js"
|
|
16
|
-
import { parseUrlMentions } from "./url_mentions/parse_url_mentions.js"
|
|
17
|
+
import { RUNTIME_COMPAT } from "./compat/runtime_compat.js"
|
|
18
|
+
import { defaultRuntimeCompat } from "./compat/default_runtime_compat.js"
|
|
17
19
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
createResolveUrlError,
|
|
21
|
+
createFetchUrlContentError,
|
|
22
|
+
createTransformUrlContentError,
|
|
23
|
+
createFinalizeUrlContentError,
|
|
22
24
|
} from "./errors.js"
|
|
23
|
-
import {
|
|
25
|
+
import { assertFetchedContentCompliance } from "./fetched_content_compliance.js"
|
|
26
|
+
import { isWebWorkerEntryPointReference } from "./web_workers.js"
|
|
24
27
|
|
|
25
28
|
export const createKitchen = ({
|
|
26
29
|
signal,
|
|
27
30
|
logger,
|
|
28
31
|
rootDirectoryUrl,
|
|
29
32
|
urlGraph,
|
|
33
|
+
|
|
30
34
|
plugins,
|
|
31
35
|
scenario,
|
|
32
|
-
|
|
33
36
|
sourcemaps = {
|
|
34
37
|
dev: "inline", // "programmatic" and "file" also allowed
|
|
35
38
|
test: "inline",
|
|
36
39
|
build: "none",
|
|
37
40
|
}[scenario],
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
sourcemapsSourcesContent = {
|
|
42
|
+
// during dev/test, chrome is able to find the sourcemap sources
|
|
43
|
+
// as long as they use file:// protocol in the sourcemap files
|
|
44
|
+
dev: false,
|
|
45
|
+
test: false,
|
|
46
|
+
build: true,
|
|
47
|
+
}[scenario],
|
|
48
|
+
sourcemapsRelativeSources,
|
|
49
|
+
runtimeCompat = defaultRuntimeCompat,
|
|
48
50
|
writeOnFileSystem = true,
|
|
49
51
|
}) => {
|
|
50
52
|
const pluginController = createPluginController({
|
|
@@ -59,105 +61,168 @@ export const createKitchen = ({
|
|
|
59
61
|
sourcemaps,
|
|
60
62
|
urlGraph,
|
|
61
63
|
scenario,
|
|
64
|
+
runtimeCompat,
|
|
65
|
+
isSupportedOnFutureClients: (feature) => {
|
|
66
|
+
return RUNTIME_COMPAT.isSupported(runtimeCompat, feature)
|
|
67
|
+
},
|
|
62
68
|
}
|
|
63
69
|
const createReference = ({
|
|
64
70
|
data = {},
|
|
71
|
+
node,
|
|
65
72
|
trace,
|
|
66
73
|
parentUrl,
|
|
67
74
|
type,
|
|
68
75
|
subtype,
|
|
76
|
+
expectedContentType,
|
|
77
|
+
expectedType,
|
|
78
|
+
expectedSubtype,
|
|
79
|
+
filename,
|
|
80
|
+
integrity,
|
|
81
|
+
crossorigin,
|
|
69
82
|
specifier,
|
|
83
|
+
specifierStart,
|
|
84
|
+
specifierEnd,
|
|
85
|
+
specifierLine,
|
|
86
|
+
specifierColumn,
|
|
87
|
+
baseUrl,
|
|
88
|
+
isOriginalPosition,
|
|
89
|
+
external = false,
|
|
70
90
|
isInline = false,
|
|
91
|
+
injected = false,
|
|
92
|
+
isRessourceHint = false,
|
|
71
93
|
content,
|
|
72
94
|
contentType,
|
|
95
|
+
assert,
|
|
96
|
+
assertNode,
|
|
97
|
+
typePropertyNode,
|
|
73
98
|
}) => {
|
|
99
|
+
if (typeof specifier !== "string") {
|
|
100
|
+
throw new TypeError(`"specifier" must be a string, got ${specifier}`)
|
|
101
|
+
}
|
|
74
102
|
return {
|
|
103
|
+
original: null,
|
|
104
|
+
prev: null,
|
|
105
|
+
next: null,
|
|
75
106
|
data,
|
|
107
|
+
node,
|
|
76
108
|
trace,
|
|
77
109
|
parentUrl,
|
|
78
110
|
type,
|
|
79
111
|
subtype,
|
|
112
|
+
expectedContentType,
|
|
113
|
+
expectedType,
|
|
114
|
+
expectedSubtype,
|
|
115
|
+
filename,
|
|
116
|
+
integrity,
|
|
117
|
+
crossorigin,
|
|
80
118
|
specifier,
|
|
119
|
+
specifierStart,
|
|
120
|
+
specifierEnd,
|
|
121
|
+
specifierLine,
|
|
122
|
+
specifierColumn,
|
|
123
|
+
baseUrl,
|
|
124
|
+
isOriginalPosition,
|
|
125
|
+
external,
|
|
81
126
|
isInline,
|
|
127
|
+
injected,
|
|
128
|
+
isRessourceHint,
|
|
82
129
|
// for inline ressources the reference contains the content
|
|
83
130
|
content,
|
|
84
131
|
contentType,
|
|
132
|
+
timing: {},
|
|
133
|
+
assert,
|
|
134
|
+
assertNode,
|
|
135
|
+
typePropertyNode,
|
|
85
136
|
}
|
|
86
137
|
}
|
|
138
|
+
const mutateReference = (reference, newReference) => {
|
|
139
|
+
reference.next = newReference
|
|
140
|
+
newReference.prev = reference
|
|
141
|
+
newReference.original = reference.original || reference
|
|
142
|
+
}
|
|
87
143
|
const resolveReference = (reference) => {
|
|
88
144
|
try {
|
|
89
|
-
|
|
90
|
-
"
|
|
145
|
+
let resolvedUrl = pluginController.callHooksUntil(
|
|
146
|
+
"resolveUrl",
|
|
91
147
|
reference,
|
|
92
148
|
baseContext,
|
|
93
149
|
)
|
|
94
150
|
if (!resolvedUrl) {
|
|
95
151
|
throw new Error(`NO_RESOLVE`)
|
|
96
152
|
}
|
|
153
|
+
resolvedUrl = normalizeUrl(resolvedUrl)
|
|
97
154
|
reference.url = resolvedUrl
|
|
155
|
+
if (reference.external) {
|
|
156
|
+
reference.generatedUrl = resolvedUrl
|
|
157
|
+
reference.generatedSpecifier = reference.specifier
|
|
158
|
+
return urlGraph.reuseOrCreateUrlInfo(reference.url)
|
|
159
|
+
}
|
|
98
160
|
pluginController.callHooks(
|
|
99
|
-
"
|
|
161
|
+
"redirectUrl",
|
|
100
162
|
reference,
|
|
101
163
|
baseContext,
|
|
102
164
|
(returnValue) => {
|
|
103
|
-
|
|
165
|
+
const normalizedReturnValue = normalizeUrl(returnValue)
|
|
166
|
+
if (normalizedReturnValue === reference.url) {
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
const previousReference = { ...reference }
|
|
170
|
+
reference.url = normalizedReturnValue
|
|
171
|
+
mutateReference(previousReference, reference)
|
|
104
172
|
},
|
|
105
173
|
)
|
|
106
|
-
|
|
107
|
-
// some plugin use URLSearchParams to alter the url search params
|
|
108
|
-
// which can result into "file:///file.css?css_module"
|
|
109
|
-
// becoming "file:///file.css?css_module="
|
|
110
|
-
// we want to get rid of the "=" and consider it's the same url
|
|
111
|
-
if (
|
|
112
|
-
// disable on data urls (would mess up base64 encoding)
|
|
113
|
-
!reference.url.startsWith("data:")
|
|
114
|
-
) {
|
|
115
|
-
reference.url = reference.url.replace(/[=](?=&|$)/g, "")
|
|
116
|
-
}
|
|
174
|
+
|
|
117
175
|
const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url)
|
|
118
|
-
|
|
176
|
+
applyReferenceEffectsOnUrlInfo(reference, urlInfo, baseContext)
|
|
119
177
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
178
|
+
const referenceUrlObject = new URL(reference.url)
|
|
179
|
+
reference.searchParams = referenceUrlObject.searchParams
|
|
180
|
+
reference.generatedUrl = reference.url
|
|
181
|
+
// This hook must touch reference.generatedUrl, NOT reference.url
|
|
182
|
+
// And this is because this hook inject query params used to:
|
|
183
|
+
// - bypass browser cache (?v)
|
|
184
|
+
// - convey information (?hmr)
|
|
185
|
+
// But do not represent an other ressource, it is considered as
|
|
186
|
+
// the same ressource under the hood
|
|
125
187
|
pluginController.callHooks(
|
|
126
|
-
"
|
|
127
|
-
|
|
188
|
+
"transformUrlSearchParams",
|
|
189
|
+
reference,
|
|
128
190
|
baseContext,
|
|
129
191
|
(returnValue) => {
|
|
130
|
-
|
|
192
|
+
Object.keys(returnValue).forEach((key) => {
|
|
193
|
+
referenceUrlObject.searchParams.set(key, returnValue[key])
|
|
194
|
+
})
|
|
195
|
+
reference.generatedUrl = normalizeUrl(referenceUrlObject.href)
|
|
131
196
|
},
|
|
132
197
|
)
|
|
133
|
-
reference.generatedUrl = referencedCopy.url
|
|
134
198
|
const returnValue = pluginController.callHooksUntil(
|
|
135
|
-
"
|
|
136
|
-
|
|
199
|
+
"formatUrl",
|
|
200
|
+
reference,
|
|
137
201
|
baseContext,
|
|
138
202
|
)
|
|
139
203
|
reference.generatedSpecifier = returnValue || reference.generatedUrl
|
|
140
|
-
reference.generatedSpecifier =
|
|
204
|
+
reference.generatedSpecifier = urlSpecifierFormat.encode(reference)
|
|
141
205
|
return urlInfo
|
|
142
206
|
} catch (error) {
|
|
143
|
-
throw
|
|
207
|
+
throw createResolveUrlError({
|
|
144
208
|
pluginController,
|
|
145
209
|
reference,
|
|
146
210
|
error,
|
|
147
211
|
})
|
|
148
212
|
}
|
|
149
213
|
}
|
|
214
|
+
baseContext.resolveReference = resolveReference
|
|
150
215
|
const urlInfoTransformer = createUrlInfoTransformer({
|
|
151
216
|
logger,
|
|
152
217
|
urlGraph,
|
|
153
218
|
sourcemaps,
|
|
154
|
-
|
|
219
|
+
sourcemapsSourcesContent,
|
|
220
|
+
sourcemapsRelativeSources,
|
|
155
221
|
injectSourcemapPlaceholder: ({ urlInfo, specifier }) => {
|
|
156
222
|
const sourcemapReference = createReference({
|
|
157
223
|
trace: `sourcemap comment placeholder for ${urlInfo.url}`,
|
|
158
224
|
type: "sourcemap_comment",
|
|
159
|
-
subtype:
|
|
160
|
-
urlInfo.contentType === "application/javascript" ? "js" : "css",
|
|
225
|
+
subtype: urlInfo.contentType === "text/javascript" ? "js" : "css",
|
|
161
226
|
parentUrl: urlInfo.url,
|
|
162
227
|
specifier,
|
|
163
228
|
})
|
|
@@ -165,19 +230,27 @@ export const createKitchen = ({
|
|
|
165
230
|
sourcemapUrlInfo.type = "sourcemap"
|
|
166
231
|
return [sourcemapReference, sourcemapUrlInfo]
|
|
167
232
|
},
|
|
168
|
-
foundSourcemap: ({
|
|
233
|
+
foundSourcemap: ({
|
|
234
|
+
urlInfo,
|
|
235
|
+
type,
|
|
236
|
+
specifier,
|
|
237
|
+
specifierLine,
|
|
238
|
+
specifierColumn,
|
|
239
|
+
}) => {
|
|
169
240
|
const sourcemapReference = createReference({
|
|
170
241
|
trace: stringifyUrlSite(
|
|
171
242
|
adjustUrlSite(urlInfo, {
|
|
172
243
|
urlGraph,
|
|
173
244
|
url: urlInfo.url,
|
|
174
|
-
line,
|
|
175
|
-
column,
|
|
245
|
+
line: specifierLine,
|
|
246
|
+
column: specifierColumn,
|
|
176
247
|
}),
|
|
177
248
|
),
|
|
178
249
|
type,
|
|
179
250
|
parentUrl: urlInfo.url,
|
|
180
251
|
specifier,
|
|
252
|
+
specifierLine,
|
|
253
|
+
specifierColumn,
|
|
181
254
|
})
|
|
182
255
|
const sourcemapUrlInfo = resolveReference(sourcemapReference)
|
|
183
256
|
sourcemapUrlInfo.type = "sourcemap"
|
|
@@ -185,69 +258,78 @@ export const createKitchen = ({
|
|
|
185
258
|
},
|
|
186
259
|
})
|
|
187
260
|
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return isFeatureSupportedOnRuntimes(runtimeSupport, featureCompat)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const load = async ({ reference, urlInfo, context }) => {
|
|
261
|
+
const fetchUrlContent = async ({ reference, urlInfo, context }) => {
|
|
262
|
+
if (reference.external) {
|
|
263
|
+
urlInfo.external = true
|
|
264
|
+
return
|
|
265
|
+
}
|
|
197
266
|
try {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
267
|
+
const fetchUrlContentReturnValue =
|
|
268
|
+
await pluginController.callAsyncHooksUntil(
|
|
269
|
+
"fetchUrlContent",
|
|
270
|
+
urlInfo,
|
|
271
|
+
context,
|
|
272
|
+
)
|
|
273
|
+
if (!fetchUrlContentReturnValue) {
|
|
274
|
+
logger.warn(
|
|
275
|
+
createDetailedMessage(
|
|
276
|
+
`no plugin has handled the url during "fetchUrlContent" hook -> consider url as external (ignore it)`,
|
|
277
|
+
{
|
|
278
|
+
"url": urlInfo.url,
|
|
279
|
+
"url reference trace": reference.trace,
|
|
280
|
+
},
|
|
281
|
+
),
|
|
282
|
+
)
|
|
283
|
+
urlInfo.external = true
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
if (fetchUrlContentReturnValue.external) {
|
|
287
|
+
urlInfo.external = true
|
|
288
|
+
return
|
|
203
289
|
}
|
|
204
|
-
|
|
205
290
|
const {
|
|
206
|
-
contentType = "application/octet-stream",
|
|
207
|
-
content, // can be a buffer (used for binary files) or a string
|
|
208
|
-
sourcemap,
|
|
209
|
-
// during build urls info are reused and load returns originalContent
|
|
210
|
-
// that we want to keep
|
|
211
|
-
originalContent = content,
|
|
212
291
|
data,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
contentType,
|
|
292
|
+
type,
|
|
293
|
+
subtype,
|
|
294
|
+
contentType = "application/octet-stream",
|
|
216
295
|
originalContent,
|
|
217
296
|
content,
|
|
218
297
|
sourcemap,
|
|
219
|
-
|
|
298
|
+
filename,
|
|
299
|
+
} = fetchUrlContentReturnValue
|
|
300
|
+
urlInfo.type =
|
|
301
|
+
type ||
|
|
302
|
+
reference.expectedType ||
|
|
303
|
+
inferUrlInfoType({
|
|
304
|
+
url: urlInfo.url,
|
|
305
|
+
contentType,
|
|
306
|
+
})
|
|
307
|
+
urlInfo.subtype =
|
|
308
|
+
subtype ||
|
|
309
|
+
reference.expectedSubtype ||
|
|
310
|
+
inferUrlInfoSubtype({
|
|
311
|
+
url: urlInfo.url,
|
|
312
|
+
type: urlInfo.type,
|
|
313
|
+
subtype: urlInfo.subtype,
|
|
314
|
+
})
|
|
315
|
+
urlInfo.contentType = contentType
|
|
316
|
+
// during build urls info are reused and load returns originalContent
|
|
317
|
+
urlInfo.originalContent =
|
|
318
|
+
originalContent === undefined ? content : originalContent
|
|
319
|
+
urlInfo.content = content
|
|
320
|
+
urlInfo.sourcemap = sourcemap
|
|
220
321
|
if (data) {
|
|
221
322
|
Object.assign(urlInfo.data, data)
|
|
222
323
|
}
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
if (type === "js") {
|
|
226
|
-
const urlObject = new URL(urlInfo.url)
|
|
227
|
-
if (urlObject.searchParams.has("worker_type_classic")) {
|
|
228
|
-
urlInfo.type = "js_classic"
|
|
229
|
-
urlInfo.subtype = "worker"
|
|
230
|
-
} else if (
|
|
231
|
-
urlObject.searchParams.has("service_worker_type_classic")
|
|
232
|
-
) {
|
|
233
|
-
urlInfo.type = "js_classic"
|
|
234
|
-
urlInfo.subtype = "service_worker"
|
|
235
|
-
} else if (urlObject.searchParams.has("js_classic")) {
|
|
236
|
-
urlInfo.type = "js_classic"
|
|
237
|
-
} else {
|
|
238
|
-
urlInfo.type = "js_module"
|
|
239
|
-
}
|
|
240
|
-
if (urlObject.searchParams.has("worker")) {
|
|
241
|
-
urlInfo.subtype = "worker"
|
|
242
|
-
} else if (urlObject.searchParams.has("service_worker")) {
|
|
243
|
-
urlInfo.subtype = "service_worker"
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
urlInfo.type = type
|
|
247
|
-
}
|
|
324
|
+
if (filename) {
|
|
325
|
+
urlInfo.filename = filename
|
|
248
326
|
}
|
|
327
|
+
assertFetchedContentCompliance({
|
|
328
|
+
reference,
|
|
329
|
+
urlInfo,
|
|
330
|
+
})
|
|
249
331
|
} catch (error) {
|
|
250
|
-
throw
|
|
332
|
+
throw createFetchUrlContentError({
|
|
251
333
|
pluginController,
|
|
252
334
|
urlInfo,
|
|
253
335
|
reference,
|
|
@@ -255,9 +337,8 @@ export const createKitchen = ({
|
|
|
255
337
|
})
|
|
256
338
|
}
|
|
257
339
|
urlInfo.generatedUrl = determineFileUrlForOutDirectory({
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
url: urlInfo.url,
|
|
340
|
+
urlInfo,
|
|
341
|
+
context,
|
|
261
342
|
})
|
|
262
343
|
await urlInfoTransformer.initTransformations(urlInfo, context)
|
|
263
344
|
}
|
|
@@ -266,34 +347,39 @@ export const createKitchen = ({
|
|
|
266
347
|
reference,
|
|
267
348
|
urlInfo,
|
|
268
349
|
outDirectoryUrl,
|
|
269
|
-
|
|
350
|
+
// during dev/test clientRuntimeCompat is a single runtime
|
|
351
|
+
// during build clientRuntimeCompat is runtimeCompat
|
|
352
|
+
clientRuntimeCompat = runtimeCompat,
|
|
270
353
|
cookDuringCook = cook,
|
|
271
354
|
}) => {
|
|
355
|
+
baseContext.isSupportedOnCurrentClients = (feature) => {
|
|
356
|
+
return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
|
|
357
|
+
}
|
|
272
358
|
const context = {
|
|
273
359
|
...baseContext,
|
|
274
360
|
reference,
|
|
275
361
|
outDirectoryUrl,
|
|
276
|
-
|
|
277
|
-
isSupportedOnRuntime: (featureName, featureCompat) => {
|
|
278
|
-
return isSupported({ runtimeSupport, featureName, featureCompat })
|
|
279
|
-
},
|
|
362
|
+
clientRuntimeCompat,
|
|
280
363
|
cook: (params) => {
|
|
281
364
|
return cookDuringCook({
|
|
282
365
|
outDirectoryUrl,
|
|
283
|
-
|
|
366
|
+
clientRuntimeCompat,
|
|
284
367
|
...params,
|
|
285
368
|
})
|
|
286
369
|
},
|
|
287
|
-
|
|
288
|
-
return
|
|
370
|
+
fetchUrlContent: (params) => {
|
|
371
|
+
return fetchUrlContent({
|
|
289
372
|
context,
|
|
290
373
|
...params,
|
|
291
374
|
})
|
|
292
375
|
},
|
|
293
376
|
}
|
|
294
377
|
|
|
295
|
-
// "
|
|
296
|
-
await
|
|
378
|
+
// "fetchUrlContent" hook
|
|
379
|
+
await fetchUrlContent({ reference, urlInfo, context })
|
|
380
|
+
if (urlInfo.external) {
|
|
381
|
+
return
|
|
382
|
+
}
|
|
297
383
|
|
|
298
384
|
// parsing
|
|
299
385
|
const references = []
|
|
@@ -303,182 +389,155 @@ export const createKitchen = ({
|
|
|
303
389
|
...props,
|
|
304
390
|
})
|
|
305
391
|
references.push(reference)
|
|
306
|
-
|
|
392
|
+
const referencedUrlInfo = resolveReference(reference)
|
|
393
|
+
return [reference, referencedUrlInfo]
|
|
307
394
|
}
|
|
308
395
|
const referenceUtils = {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
url:
|
|
321
|
-
fileName && isFileSystemPath(fileName)
|
|
322
|
-
? fileSystemPathToUrl(fileName)
|
|
323
|
-
: fileName,
|
|
324
|
-
line: callerCallsite.getLineNumber(),
|
|
325
|
-
column: callerCallsite.getColumnNumber(),
|
|
396
|
+
readGeneratedSpecifier: async (reference) => {
|
|
397
|
+
// "formatReferencedUrl" can be async BUT this is an exception
|
|
398
|
+
// for most cases it will be sync. We want to favor the sync signature to keep things simpler
|
|
399
|
+
// The only case where it needs to be async is when
|
|
400
|
+
// the specifier is a `data:*` url
|
|
401
|
+
// in this case we'll wait for the promise returned by
|
|
402
|
+
// "formatReferencedUrl"
|
|
403
|
+
if (reference.generatedSpecifier.then) {
|
|
404
|
+
return reference.generatedSpecifier.then((value) => {
|
|
405
|
+
reference.generatedSpecifier = value
|
|
406
|
+
return value
|
|
326
407
|
})
|
|
327
408
|
}
|
|
409
|
+
return reference.generatedSpecifier
|
|
410
|
+
},
|
|
411
|
+
found: ({ specifierLine, specifierColumn, ...rest }) => {
|
|
412
|
+
const trace = stringifyUrlSite(
|
|
413
|
+
adjustUrlSite(urlInfo, {
|
|
414
|
+
urlGraph,
|
|
415
|
+
url: urlInfo.url,
|
|
416
|
+
line: specifierLine,
|
|
417
|
+
column: specifierColumn,
|
|
418
|
+
}),
|
|
419
|
+
)
|
|
420
|
+
// console.log(trace)
|
|
328
421
|
return addReference({
|
|
329
422
|
trace,
|
|
423
|
+
specifierLine,
|
|
424
|
+
specifierColumn,
|
|
330
425
|
...rest,
|
|
331
426
|
})
|
|
332
427
|
},
|
|
333
|
-
foundInline: ({
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
specifier,
|
|
339
|
-
contentType,
|
|
340
|
-
content,
|
|
341
|
-
}) => {
|
|
342
|
-
const parentUrl = isOriginal ? urlInfo.url : urlInfo.generatedUrl
|
|
343
|
-
const parentContent = isOriginal
|
|
428
|
+
foundInline: ({ isOriginalPosition, line, column, ...rest }) => {
|
|
429
|
+
const parentUrl = isOriginalPosition
|
|
430
|
+
? urlInfo.url
|
|
431
|
+
: urlInfo.generatedUrl
|
|
432
|
+
const parentContent = isOriginalPosition
|
|
344
433
|
? urlInfo.originalContent
|
|
345
434
|
: urlInfo.content
|
|
346
|
-
|
|
435
|
+
return addReference({
|
|
347
436
|
trace: stringifyUrlSite({
|
|
348
437
|
url: parentUrl,
|
|
349
438
|
content: parentContent,
|
|
350
439
|
line,
|
|
351
440
|
column,
|
|
352
441
|
}),
|
|
353
|
-
|
|
354
|
-
specifier,
|
|
355
|
-
isInline: true,
|
|
356
|
-
contentType,
|
|
357
|
-
content,
|
|
358
|
-
})
|
|
359
|
-
inlineUrlInfo.isInline = true
|
|
360
|
-
inlineUrlInfo.inlineUrlSite = {
|
|
361
|
-
url: urlInfo.url,
|
|
362
|
-
content: parentContent,
|
|
442
|
+
isOriginalPosition,
|
|
363
443
|
line,
|
|
364
444
|
column,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return [inlineReference, inlineUrlInfo]
|
|
445
|
+
isInline: true,
|
|
446
|
+
...rest,
|
|
447
|
+
})
|
|
369
448
|
},
|
|
370
|
-
|
|
371
|
-
const index = references.
|
|
372
|
-
(ref) => ref.generatedSpecifier === generatedSpecifier,
|
|
373
|
-
)
|
|
449
|
+
update: (currentReference, newReferenceParams) => {
|
|
450
|
+
const index = references.indexOf(currentReference)
|
|
374
451
|
if (index === -1) {
|
|
375
|
-
throw new Error(
|
|
376
|
-
`Cannot find a reference for the following generatedSpecifier "${generatedSpecifier}"`,
|
|
377
|
-
)
|
|
452
|
+
throw new Error(`reference do not exists`)
|
|
378
453
|
}
|
|
379
|
-
const
|
|
380
|
-
const
|
|
381
|
-
...
|
|
382
|
-
|
|
383
|
-
data: {
|
|
384
|
-
...referenceFound.data,
|
|
385
|
-
...data,
|
|
386
|
-
},
|
|
454
|
+
const previousReference = currentReference
|
|
455
|
+
const nextReference = createReference({
|
|
456
|
+
...previousReference,
|
|
457
|
+
...newReferenceParams,
|
|
387
458
|
})
|
|
388
|
-
references[index] =
|
|
389
|
-
|
|
390
|
-
const newUrlInfo = resolveReference(
|
|
391
|
-
|
|
459
|
+
references[index] = nextReference
|
|
460
|
+
mutateReference(previousReference, nextReference)
|
|
461
|
+
const newUrlInfo = resolveReference(nextReference)
|
|
462
|
+
const currentUrlInfo = context.urlGraph.getUrlInfo(currentReference.url)
|
|
463
|
+
if (
|
|
464
|
+
currentUrlInfo &&
|
|
465
|
+
currentUrlInfo !== newUrlInfo &&
|
|
466
|
+
currentUrlInfo.dependents.size === 0
|
|
467
|
+
) {
|
|
468
|
+
context.urlGraph.deleteUrlInfo(currentReference.url)
|
|
469
|
+
}
|
|
470
|
+
return [nextReference, newUrlInfo]
|
|
392
471
|
},
|
|
393
472
|
becomesInline: (
|
|
394
473
|
reference,
|
|
395
|
-
{
|
|
474
|
+
{
|
|
475
|
+
isOriginalPosition,
|
|
476
|
+
specifier,
|
|
477
|
+
specifierLine,
|
|
478
|
+
specifierColumn,
|
|
479
|
+
contentType,
|
|
480
|
+
content,
|
|
481
|
+
},
|
|
396
482
|
) => {
|
|
397
|
-
const parentUrl =
|
|
398
|
-
|
|
483
|
+
const parentUrl = isOriginalPosition
|
|
484
|
+
? urlInfo.url
|
|
485
|
+
: urlInfo.generatedUrl
|
|
486
|
+
const parentContent = isOriginalPosition
|
|
399
487
|
? urlInfo.originalContent
|
|
400
488
|
: urlInfo.content
|
|
401
|
-
reference
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
489
|
+
return referenceUtils.update(reference, {
|
|
490
|
+
trace: stringifyUrlSite({
|
|
491
|
+
url: parentUrl,
|
|
492
|
+
content: parentContent,
|
|
493
|
+
line: specifierLine,
|
|
494
|
+
column: specifierColumn,
|
|
495
|
+
}),
|
|
496
|
+
isOriginalPosition,
|
|
497
|
+
isInline: true,
|
|
498
|
+
specifier,
|
|
499
|
+
specifierLine,
|
|
500
|
+
specifierColumn,
|
|
501
|
+
contentType,
|
|
502
|
+
content,
|
|
406
503
|
})
|
|
407
|
-
reference.isInline = true
|
|
408
|
-
reference.specifier = specifier
|
|
409
|
-
reference.contentType = contentType
|
|
410
|
-
reference.content = content
|
|
411
|
-
const inlineUrlInfo = resolveReference(reference)
|
|
412
|
-
inlineUrlInfo.isInline = true
|
|
413
|
-
inlineUrlInfo.inlineUrlSite = {
|
|
414
|
-
url: urlInfo.url,
|
|
415
|
-
content: parentContent,
|
|
416
|
-
line,
|
|
417
|
-
column,
|
|
418
|
-
}
|
|
419
|
-
inlineUrlInfo.contentType = contentType
|
|
420
|
-
inlineUrlInfo.content = content
|
|
421
|
-
return reference
|
|
422
504
|
},
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
adjustUrlSite(urlInfo, {
|
|
447
|
-
urlGraph,
|
|
448
|
-
url: urlInfo.url,
|
|
449
|
-
line: urlMention.line,
|
|
450
|
-
column: urlMention.column,
|
|
451
|
-
}),
|
|
452
|
-
),
|
|
453
|
-
type: urlMention.type,
|
|
454
|
-
subtype: urlMention.subtype,
|
|
455
|
-
specifier: urlMention.specifier,
|
|
456
|
-
})
|
|
457
|
-
urlMention.reference = reference
|
|
458
|
-
}
|
|
459
|
-
if (references.length) {
|
|
460
|
-
// "formatReferencedUrl" can be async BUT this is an exception
|
|
461
|
-
// for most cases it will be sync. We want to favor the sync signature to keep things simpler
|
|
462
|
-
// The only case where it needs to be async is when
|
|
463
|
-
// the specifier is a `data:*` url
|
|
464
|
-
// in this case we'll wait for the promise returned by
|
|
465
|
-
// "formatReferencedUrl"
|
|
466
|
-
await Promise.all(
|
|
467
|
-
references.map(async (reference) => {
|
|
468
|
-
if (reference.generatedSpecifier.then) {
|
|
469
|
-
const value = await reference.generatedSpecifier
|
|
470
|
-
reference.generatedSpecifier = value
|
|
471
|
-
}
|
|
472
|
-
}),
|
|
473
|
-
)
|
|
474
|
-
const replaceReturnValue = await replaceUrls((urlMention) => {
|
|
475
|
-
return urlMention.reference.generatedSpecifier
|
|
505
|
+
inject: ({ trace, ...rest }) => {
|
|
506
|
+
if (trace === undefined) {
|
|
507
|
+
const { prepareStackTrace } = Error
|
|
508
|
+
Error.prepareStackTrace = (error, stack) => {
|
|
509
|
+
Error.prepareStackTrace = prepareStackTrace
|
|
510
|
+
return stack
|
|
511
|
+
}
|
|
512
|
+
const { stack } = new Error()
|
|
513
|
+
const callerCallsite = stack[1]
|
|
514
|
+
const fileName = callerCallsite.getFileName()
|
|
515
|
+
trace = stringifyUrlSite({
|
|
516
|
+
url:
|
|
517
|
+
fileName && isFileSystemPath(fileName)
|
|
518
|
+
? fileSystemPathToUrl(fileName)
|
|
519
|
+
: fileName,
|
|
520
|
+
line: callerCallsite.getLineNumber(),
|
|
521
|
+
column: callerCallsite.getColumnNumber(),
|
|
522
|
+
})
|
|
523
|
+
}
|
|
524
|
+
return addReference({
|
|
525
|
+
trace,
|
|
526
|
+
injected: true,
|
|
527
|
+
...rest,
|
|
476
528
|
})
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
529
|
+
},
|
|
530
|
+
findByGeneratedSpecifier: (generatedSpecifier) => {
|
|
531
|
+
const reference = references.find(
|
|
532
|
+
(ref) => ref.generatedSpecifier === generatedSpecifier,
|
|
480
533
|
)
|
|
481
|
-
|
|
534
|
+
if (!reference) {
|
|
535
|
+
throw new Error(
|
|
536
|
+
`No reference found using the following generatedSpecifier: "${generatedSpecifier}"`,
|
|
537
|
+
)
|
|
538
|
+
}
|
|
539
|
+
return reference
|
|
540
|
+
},
|
|
482
541
|
}
|
|
483
542
|
|
|
484
543
|
// "transform" hook
|
|
@@ -486,7 +545,7 @@ export const createKitchen = ({
|
|
|
486
545
|
context.referenceUtils = referenceUtils
|
|
487
546
|
try {
|
|
488
547
|
await pluginController.callAsyncHooks(
|
|
489
|
-
"
|
|
548
|
+
"transformUrlContent",
|
|
490
549
|
urlInfo,
|
|
491
550
|
context,
|
|
492
551
|
async (transformReturnValue) => {
|
|
@@ -497,7 +556,7 @@ export const createKitchen = ({
|
|
|
497
556
|
},
|
|
498
557
|
)
|
|
499
558
|
} catch (error) {
|
|
500
|
-
throw
|
|
559
|
+
throw createTransformUrlContentError({
|
|
501
560
|
pluginController,
|
|
502
561
|
reference,
|
|
503
562
|
urlInfo,
|
|
@@ -509,15 +568,24 @@ export const createKitchen = ({
|
|
|
509
568
|
urlGraph.updateReferences(urlInfo, references)
|
|
510
569
|
|
|
511
570
|
// "finalize" hook
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
571
|
+
try {
|
|
572
|
+
const finalizeReturnValue = await pluginController.callAsyncHooksUntil(
|
|
573
|
+
"finalizeUrlContent",
|
|
574
|
+
urlInfo,
|
|
575
|
+
context,
|
|
576
|
+
)
|
|
577
|
+
await urlInfoTransformer.applyFinalTransformations(
|
|
578
|
+
urlInfo,
|
|
579
|
+
finalizeReturnValue,
|
|
580
|
+
)
|
|
581
|
+
} catch (error) {
|
|
582
|
+
throw createFinalizeUrlContentError({
|
|
583
|
+
pluginController,
|
|
584
|
+
reference,
|
|
585
|
+
urlInfo,
|
|
586
|
+
error,
|
|
587
|
+
})
|
|
588
|
+
}
|
|
521
589
|
|
|
522
590
|
// "cooked" hook
|
|
523
591
|
pluginController.callHooks(
|
|
@@ -541,7 +609,7 @@ export const createKitchen = ({
|
|
|
541
609
|
},
|
|
542
610
|
)
|
|
543
611
|
}
|
|
544
|
-
const cook = async ({ urlInfo, outDirectoryUrl, ...rest }) => {
|
|
612
|
+
const cook = memoizeCook(async ({ urlInfo, outDirectoryUrl, ...rest }) => {
|
|
545
613
|
outDirectoryUrl = outDirectoryUrl ? String(outDirectoryUrl) : undefined
|
|
546
614
|
|
|
547
615
|
const writeFiles = ({ gotError }) => {
|
|
@@ -576,19 +644,96 @@ export const createKitchen = ({
|
|
|
576
644
|
writeFiles({ gotError: true })
|
|
577
645
|
throw e
|
|
578
646
|
}
|
|
579
|
-
}
|
|
647
|
+
})
|
|
580
648
|
|
|
581
649
|
baseContext.cook = cook
|
|
582
650
|
|
|
651
|
+
const prepareEntryPoint = (params) => {
|
|
652
|
+
const entryReference = createReference(params)
|
|
653
|
+
const entryUrlInfo = resolveReference(entryReference)
|
|
654
|
+
return [entryReference, entryUrlInfo]
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const injectReference = (params) => {
|
|
658
|
+
const ref = createReference(params)
|
|
659
|
+
const urlInfo = resolveReference(ref)
|
|
660
|
+
return [ref, urlInfo]
|
|
661
|
+
}
|
|
662
|
+
|
|
583
663
|
return {
|
|
584
664
|
pluginController,
|
|
585
665
|
urlInfoTransformer,
|
|
586
666
|
rootDirectoryUrl,
|
|
587
667
|
jsenvDirectoryUrl,
|
|
588
|
-
|
|
589
|
-
createReference,
|
|
590
|
-
resolveReference,
|
|
668
|
+
baseContext,
|
|
591
669
|
cook,
|
|
670
|
+
prepareEntryPoint,
|
|
671
|
+
injectReference,
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const memoizeCook = (cook) => {
|
|
676
|
+
const pendingDishes = new Map()
|
|
677
|
+
return async (params) => {
|
|
678
|
+
const { urlInfo } = params
|
|
679
|
+
const { url, modifiedTimestamp } = urlInfo
|
|
680
|
+
const pendingDish = pendingDishes.get(url)
|
|
681
|
+
if (pendingDish) {
|
|
682
|
+
if (!modifiedTimestamp) {
|
|
683
|
+
await pendingDish.promise
|
|
684
|
+
return
|
|
685
|
+
}
|
|
686
|
+
if (pendingDish.timestamp > modifiedTimestamp) {
|
|
687
|
+
await pendingDish.promise
|
|
688
|
+
return
|
|
689
|
+
}
|
|
690
|
+
pendingDishes.delete(url)
|
|
691
|
+
}
|
|
692
|
+
const timestamp = Date.now()
|
|
693
|
+
const promise = cook(params)
|
|
694
|
+
pendingDishes.set(url, {
|
|
695
|
+
timestamp,
|
|
696
|
+
promise,
|
|
697
|
+
})
|
|
698
|
+
try {
|
|
699
|
+
await promise
|
|
700
|
+
} finally {
|
|
701
|
+
pendingDishes.delete(url)
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
|
|
707
|
+
Object.assign(urlInfo.data, reference.data)
|
|
708
|
+
Object.assign(urlInfo.timing, reference.timing)
|
|
709
|
+
if (reference.injected) {
|
|
710
|
+
urlInfo.data.injected = true
|
|
711
|
+
}
|
|
712
|
+
if (reference.filename) {
|
|
713
|
+
urlInfo.filename = reference.filename
|
|
714
|
+
}
|
|
715
|
+
if (reference.isInline) {
|
|
716
|
+
urlInfo.isInline = true
|
|
717
|
+
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
|
|
718
|
+
urlInfo.inlineUrlSite = {
|
|
719
|
+
url: parentUrlInfo.url,
|
|
720
|
+
content: reference.isOriginalPosition
|
|
721
|
+
? parentUrlInfo.originalContent
|
|
722
|
+
: parentUrlInfo.content,
|
|
723
|
+
line: reference.specifierLine,
|
|
724
|
+
column: reference.specifierColumn,
|
|
725
|
+
}
|
|
726
|
+
urlInfo.contentType = reference.contentType
|
|
727
|
+
urlInfo.originalContent =
|
|
728
|
+
context === "build"
|
|
729
|
+
? urlInfo.originalContent === undefined
|
|
730
|
+
? reference.content
|
|
731
|
+
: urlInfo.originalContent
|
|
732
|
+
: reference.content
|
|
733
|
+
urlInfo.content = reference.content
|
|
734
|
+
}
|
|
735
|
+
if (isWebWorkerEntryPointReference(reference)) {
|
|
736
|
+
urlInfo.data.isWebWorkerEntryPoint = true
|
|
592
737
|
}
|
|
593
738
|
}
|
|
594
739
|
|
|
@@ -626,54 +771,86 @@ const adjustUrlSite = (urlInfo, { urlGraph, url, line, column }) => {
|
|
|
626
771
|
)
|
|
627
772
|
}
|
|
628
773
|
|
|
629
|
-
const inferUrlInfoType = ({ contentType }) => {
|
|
774
|
+
const inferUrlInfoType = ({ url, contentType }) => {
|
|
630
775
|
if (contentType === "text/html") {
|
|
631
776
|
return "html"
|
|
632
777
|
}
|
|
633
778
|
if (contentType === "text/css") {
|
|
634
779
|
return "css"
|
|
635
780
|
}
|
|
636
|
-
if (contentType === "
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
781
|
+
if (contentType === "text/javascript") {
|
|
782
|
+
const urlObject = new URL(url)
|
|
783
|
+
if (urlObject.searchParams.has("js_classic")) {
|
|
784
|
+
return "js_classic"
|
|
785
|
+
}
|
|
786
|
+
return "js_module"
|
|
641
787
|
}
|
|
642
788
|
if (contentType === "application/importmap+json") {
|
|
643
789
|
return "importmap"
|
|
644
790
|
}
|
|
791
|
+
if (contentType === "application/manifest+json") {
|
|
792
|
+
return "webmanifest"
|
|
793
|
+
}
|
|
794
|
+
if (contentType === "image/svg+xml") {
|
|
795
|
+
return "svg"
|
|
796
|
+
}
|
|
797
|
+
if (CONTENT_TYPE.isJson(contentType)) {
|
|
798
|
+
return "json"
|
|
799
|
+
}
|
|
800
|
+
if (CONTENT_TYPE.isTextual(contentType)) {
|
|
801
|
+
return "text"
|
|
802
|
+
}
|
|
645
803
|
return "other"
|
|
646
804
|
}
|
|
647
805
|
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
806
|
+
const inferUrlInfoSubtype = ({ type, subtype, url }) => {
|
|
807
|
+
if (type === "js_classic" || type === "js_module") {
|
|
808
|
+
const urlObject = new URL(url)
|
|
809
|
+
if (urlObject.searchParams.has("worker")) {
|
|
810
|
+
return "worker"
|
|
811
|
+
}
|
|
812
|
+
if (urlObject.searchParams.has("service_worker")) {
|
|
813
|
+
return "service_worker"
|
|
814
|
+
}
|
|
815
|
+
if (urlObject.searchParams.has("shared_worker")) {
|
|
816
|
+
return "shared_worker"
|
|
817
|
+
}
|
|
818
|
+
// if we are currently inside a worker, all deps are consider inside worker too
|
|
819
|
+
return subtype
|
|
820
|
+
}
|
|
821
|
+
return ""
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const determineFileUrlForOutDirectory = ({ urlInfo, context }) => {
|
|
825
|
+
if (!context.outDirectoryUrl) {
|
|
826
|
+
return urlInfo.url
|
|
827
|
+
}
|
|
828
|
+
if (!urlInfo.url.startsWith("file:")) {
|
|
829
|
+
return urlInfo.url
|
|
655
830
|
}
|
|
656
|
-
|
|
657
|
-
|
|
831
|
+
let url = urlInfo.url
|
|
832
|
+
if (!urlIsInsideOf(urlInfo.url, context.rootDirectoryUrl)) {
|
|
833
|
+
const fsRootUrl = ensureWindowsDriveLetter("file:///", urlInfo.url)
|
|
834
|
+
url = `${context.rootDirectoryUrl}@fs/${url.slice(fsRootUrl.length)}`
|
|
658
835
|
}
|
|
659
|
-
if (
|
|
660
|
-
url =
|
|
836
|
+
if (urlInfo.filename) {
|
|
837
|
+
url = setUrlFilename(url, urlInfo.filename)
|
|
661
838
|
}
|
|
662
839
|
return moveUrl({
|
|
663
|
-
url
|
|
664
|
-
from: rootDirectoryUrl,
|
|
665
|
-
to: outDirectoryUrl,
|
|
840
|
+
url,
|
|
841
|
+
from: context.rootDirectoryUrl,
|
|
842
|
+
to: context.outDirectoryUrl,
|
|
666
843
|
preferAbsolute: true,
|
|
667
844
|
})
|
|
668
845
|
}
|
|
669
846
|
|
|
670
|
-
const
|
|
847
|
+
const urlSpecifierFormat = {
|
|
671
848
|
encode: (reference) => {
|
|
672
849
|
const { generatedSpecifier } = reference
|
|
673
850
|
if (generatedSpecifier.then) {
|
|
674
851
|
return generatedSpecifier.then((value) => {
|
|
675
852
|
reference.generatedSpecifier = value
|
|
676
|
-
return
|
|
853
|
+
return urlSpecifierFormat.encode(reference)
|
|
677
854
|
})
|
|
678
855
|
}
|
|
679
856
|
// allow plugin to return a function to bypas default formatting
|
|
@@ -698,10 +875,11 @@ const specifierFormat = {
|
|
|
698
875
|
},
|
|
699
876
|
}
|
|
700
877
|
const formatters = {
|
|
701
|
-
js_import_export: { encode: JSON.stringify, decode: JSON.parse },
|
|
702
|
-
|
|
878
|
+
"js_import_export": { encode: JSON.stringify, decode: JSON.parse },
|
|
879
|
+
"js_url_specifier": { encode: JSON.stringify, decode: JSON.parse },
|
|
880
|
+
"css_@import": { encode: JSON.stringify, code: JSON.stringify },
|
|
703
881
|
// https://github.com/webpack-contrib/css-loader/pull/627/files
|
|
704
|
-
css_url: {
|
|
882
|
+
"css_url": {
|
|
705
883
|
encode: (url) => {
|
|
706
884
|
// If url is already wrapped in quotes, remove them
|
|
707
885
|
url = formatters.css_url.decode(url)
|