@jsenv/core 27.0.0-alpha.63 → 27.0.0-alpha.66
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/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
- package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -0
- package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
- package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
- package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
- package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
- package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
- package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
- package/dist/babel_helpers/asyncIterator/asyncIterator.js +78 -0
- package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
- package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
- package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
- package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
- package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
- package/dist/babel_helpers/classCallCheck/classCallCheck.js +5 -0
- package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
- package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
- package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
- package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
- package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
- package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
- package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
- package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
- package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
- package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
- package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
- package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
- package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
- package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
- package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
- package/dist/babel_helpers/construct/construct.js +15 -0
- package/dist/babel_helpers/createClass/createClass.js +18 -0
- package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
- package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
- package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
- package/dist/babel_helpers/createSuper/createSuper.js +22 -0
- package/dist/babel_helpers/decorate/decorate.js +622 -0
- package/dist/babel_helpers/defaults/defaults.js +14 -0
- package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
- package/dist/babel_helpers/defineProperty/defineProperty.js +19 -0
- package/dist/babel_helpers/extends/extends.js +16 -0
- package/dist/babel_helpers/get/get.js +21 -0
- package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
- package/dist/babel_helpers/inherits/inherits.js +21 -0
- package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
- package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
- package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
- package/dist/babel_helpers/instanceof/instanceof.js +7 -0
- package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
- package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
- package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
- package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
- package/dist/babel_helpers/iterableToArray/iterableToArray.js +3 -0
- package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
- package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
- package/dist/babel_helpers/jsx/jsx.js +49 -0
- package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
- package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
- package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
- package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
- package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
- package/dist/babel_helpers/objectSpread/objectSpread.js +22 -0
- package/dist/babel_helpers/objectSpread2/objectSpread2.js +41 -0
- package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
- package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
- package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
- package/dist/babel_helpers/readOnlyError/readOnlyError.js +4 -0
- package/dist/babel_helpers/readme.md +8 -0
- package/dist/babel_helpers/set/set.js +51 -0
- package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
- package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
- package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -0
- package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
- package/dist/babel_helpers/superPropBase/superPropBase.js +10 -0
- package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
- package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
- package/dist/babel_helpers/tdz/tdz.js +4 -0
- package/dist/babel_helpers/temporalRef/temporalRef.js +5 -0
- package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
- package/dist/babel_helpers/toArray/toArray.js +5 -0
- package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
- package/dist/babel_helpers/toPrimitive/toPrimitive.js +14 -0
- package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
- package/dist/babel_helpers/typeof/typeof.js +7 -0
- package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
- package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
- package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
- package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
- package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
- package/dist/html/explorer.html +557 -0
- package/dist/js/controllable_file.mjs +227 -0
- package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
- package/dist/js/global_this.js +32 -0
- package/dist/js/html_supervisor_installer.js +522 -0
- package/dist/js/html_supervisor_setup.js +79 -0
- package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
- package/dist/js/inline_content.js +8 -0
- package/dist/js/new_stylesheet.js +409 -0
- package/dist/js/regenerator_runtime.js +721 -0
- package/dist/js/s.js +429 -0
- package/dist/main.js +13383 -0
- package/dist/other/jsenv.png +0 -0
- package/main.js +1 -0
- package/package.json +18 -14
- package/src/build/build.js +175 -69
- package/src/build/build_urls_generator.js +18 -2
- package/src/build/inject_global_version_mappings.js +18 -5
- package/src/build/inject_service_worker_urls.js +1 -1
- package/src/build/resync_ressource_hints.js +56 -9
- package/src/build/start_build_server.js +38 -29
- package/src/dev/plugins/explorer/client/explorer.html +1 -1
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
- package/src/dev/start_dev_server.js +18 -4
- package/src/execute/execute.js +3 -0
- package/src/execute/runtimes/browsers/from_playwright.js +10 -0
- package/src/execute/runtimes/node/node_process.js +8 -0
- package/src/omega/errors.js +10 -7
- package/src/omega/kitchen.js +251 -340
- package/src/omega/server/file_service.js +34 -17
- package/src/omega/url_graph/url_graph_load.js +10 -17
- package/src/omega/url_graph/url_graph_report.js +2 -2
- package/src/omega/url_graph/url_info_transformations.js +1 -4
- package/src/omega/url_graph.js +7 -3
- package/src/omega/url_specifier_encoding.js +59 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
- package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +178 -53
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +1 -1
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
- package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +51 -42
- package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -4
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +3 -5
- package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -4
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -4
- package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +16 -2
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
- package/src/plugins/plugin_controller.js +17 -3
- package/src/plugins/plugins.js +15 -15
- package/src/plugins/transpilation/as_js_classic/client/s.js +362 -807
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +20 -10
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +302 -0
- package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_workers_type_module_as_classic.js → jsenv_plugin_as_js_classic_workers.js} +2 -2
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -2
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -2
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +2 -0
- package/src/plugins/url_analysis/html/html_urls.js +3 -0
- package/src/plugins/url_analysis/js/js_urls.js +2 -1
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +94 -1
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
- package/src/test/execute_plan.js +34 -13
- package/src/test/execute_test_plan.js +2 -0
- package/src/test/logs_file_execution.js +47 -38
- package/dist/event_source_client.js.map +0 -188
- package/dist/html_supervisor_installer.js +0 -1236
- package/dist/html_supervisor_installer.js.map +0 -337
- package/dist/html_supervisor_setup.js +0 -95
- package/dist/html_supervisor_setup.js.map +0 -57
- package/dist/import_meta_hot.js.map +0 -42
- package/src/jsenv_root_directory_url.js +0 -1
- package/src/omega/compat/default_runtime_compat.js +0 -11
- package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
- package/src/plugins/transpilation/as_js_classic/client/s.js.md +0 -1
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +0 -270
- package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
- package/src/plugins/transpilation/fetch_original_url_info.js +0 -30
|
@@ -1,66 +1,191 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs"
|
|
2
|
-
import {
|
|
1
|
+
import { readFileSync, readdirSync, realpathSync, statSync } from "node:fs"
|
|
2
|
+
import { pathToFileURL } from "node:url"
|
|
3
|
+
import {
|
|
4
|
+
urlIsInsideOf,
|
|
5
|
+
urlToRelativeUrl,
|
|
6
|
+
urlToExtension,
|
|
7
|
+
urlToFilename,
|
|
8
|
+
} from "@jsenv/filesystem"
|
|
3
9
|
|
|
10
|
+
import { applyFileSystemMagicResolution } from "@jsenv/node-esm-resolution"
|
|
11
|
+
import { ensurePathnameTrailingSlash } from "@jsenv/utils/urls/url_utils.js"
|
|
4
12
|
import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
|
|
5
13
|
|
|
6
|
-
export const jsenvPluginFileUrls = (
|
|
7
|
-
|
|
8
|
-
|
|
14
|
+
export const jsenvPluginFileUrls = ({
|
|
15
|
+
magicExtensions = ["inherit", ".js"],
|
|
16
|
+
magicDirectoryIndex = true,
|
|
17
|
+
preservesSymlink = true,
|
|
18
|
+
directoryReferenceAllowed = false,
|
|
19
|
+
}) => {
|
|
20
|
+
const getExtensionsToTry = (magicExtensions, importer) => {
|
|
21
|
+
const extensionsSet = new Set()
|
|
22
|
+
magicExtensions.forEach((magicExtension) => {
|
|
23
|
+
if (magicExtension === "inherit") {
|
|
24
|
+
const importerExtension = urlToExtension(importer)
|
|
25
|
+
extensionsSet.add(importerExtension)
|
|
26
|
+
} else {
|
|
27
|
+
extensionsSet.add(magicExtension)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
return Array.from(extensionsSet.values())
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
name: "jsenv:file_url_resolution",
|
|
36
|
+
appliesDuring: "*",
|
|
37
|
+
redirectUrl: (reference) => {
|
|
38
|
+
// http, https, data, about, ...
|
|
39
|
+
if (!reference.url.startsWith("file:")) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
if (reference.isInline) {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
const urlObject = new URL(reference.url)
|
|
46
|
+
let stat
|
|
47
|
+
try {
|
|
48
|
+
stat = statSync(urlObject)
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e.code === "ENOENT") {
|
|
51
|
+
stat = null
|
|
52
|
+
} else {
|
|
53
|
+
throw e
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const { search, hash } = urlObject
|
|
57
|
+
const resolveSymlink = (fileUrl) => {
|
|
58
|
+
const realPath = realpathSync(new URL(fileUrl))
|
|
59
|
+
const realFileUrl = `${pathToFileURL(realPath)}${search}${hash}`
|
|
60
|
+
return realFileUrl
|
|
61
|
+
}
|
|
9
62
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
63
|
+
let { pathname } = urlObject
|
|
64
|
+
const pathnameUsesTrailingSlash = pathname.endsWith("/")
|
|
65
|
+
urlObject.search = ""
|
|
66
|
+
urlObject.hash = ""
|
|
67
|
+
// force trailing slash on directories and remove eventual trailing slash on files
|
|
68
|
+
if (stat && stat.isDirectory()) {
|
|
69
|
+
reference.expectedType = "directory"
|
|
70
|
+
if (!pathnameUsesTrailingSlash) {
|
|
71
|
+
urlObject.pathname = `${pathname}/`
|
|
72
|
+
}
|
|
73
|
+
if (directoryReferenceAllowed) {
|
|
74
|
+
return preservesSymlink
|
|
75
|
+
? urlObject.href
|
|
76
|
+
: resolveSymlink(urlObject.href)
|
|
77
|
+
}
|
|
78
|
+
// give a chane to magic resolution if enabled
|
|
79
|
+
} else if (pathnameUsesTrailingSlash) {
|
|
80
|
+
// a warning would be great because it's strange to reference a file with a trailing slash
|
|
81
|
+
urlObject.pathname = pathname.slice(0, -1)
|
|
82
|
+
}
|
|
83
|
+
const url = urlObject.href
|
|
84
|
+
const filesystemResolution = applyFileSystemMagicResolution(url, {
|
|
85
|
+
fileStat: stat,
|
|
86
|
+
magicDirectoryIndex,
|
|
87
|
+
magicExtensions: getExtensionsToTry(
|
|
88
|
+
magicExtensions,
|
|
89
|
+
reference.parentUrl,
|
|
90
|
+
),
|
|
91
|
+
})
|
|
92
|
+
if (!filesystemResolution.found) {
|
|
93
|
+
return null
|
|
94
|
+
}
|
|
95
|
+
const fileUrlRaw = filesystemResolution.url
|
|
96
|
+
const fileUrl = `${fileUrlRaw}${search}${hash}`
|
|
97
|
+
return preservesSymlink ? fileUrl : resolveSymlink(fileUrl)
|
|
98
|
+
},
|
|
20
99
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
100
|
+
{
|
|
101
|
+
name: "jsenv:filesystem_resolution",
|
|
102
|
+
appliesDuring: "*",
|
|
103
|
+
resolveUrl: {
|
|
104
|
+
filesystem: (reference, context) => {
|
|
105
|
+
const { parentUrl } = reference
|
|
106
|
+
const parentUrlInfo = context.urlGraph.getUrlInfo(parentUrl)
|
|
107
|
+
const baseUrl =
|
|
108
|
+
parentUrlInfo && parentUrlInfo.type === "directory"
|
|
109
|
+
? ensurePathnameTrailingSlash(parentUrl)
|
|
110
|
+
: parentUrl
|
|
111
|
+
return new URL(reference.specifier, baseUrl).href
|
|
112
|
+
},
|
|
113
|
+
},
|
|
27
114
|
},
|
|
28
|
-
|
|
29
|
-
|
|
115
|
+
{
|
|
116
|
+
name: "jsenv:@fs_resolution",
|
|
117
|
+
appliesDuring: {
|
|
118
|
+
// during dev and test it's a browser running the code
|
|
119
|
+
// so absolute file urls needs to be relativized
|
|
120
|
+
dev: true,
|
|
121
|
+
test: true,
|
|
122
|
+
// during build it's fine to use file:// urls
|
|
123
|
+
build: false,
|
|
124
|
+
},
|
|
125
|
+
resolveUrl: (reference) => {
|
|
126
|
+
if (reference.specifier.startsWith("/@fs/")) {
|
|
127
|
+
const fsRootRelativeUrl = reference.specifier.slice("/@fs/".length)
|
|
128
|
+
return `file:///${fsRootRelativeUrl}`
|
|
129
|
+
}
|
|
30
130
|
return null
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
131
|
+
},
|
|
132
|
+
formatUrl: (reference, context) => {
|
|
133
|
+
if (!reference.generatedUrl.startsWith("file:")) {
|
|
134
|
+
return null
|
|
135
|
+
}
|
|
136
|
+
if (urlIsInsideOf(reference.generatedUrl, context.rootDirectoryUrl)) {
|
|
137
|
+
return `/${urlToRelativeUrl(
|
|
138
|
+
reference.generatedUrl,
|
|
139
|
+
context.rootDirectoryUrl,
|
|
140
|
+
)}`
|
|
141
|
+
}
|
|
142
|
+
return `/@fs/${reference.generatedUrl.slice("file:///".length)}`
|
|
143
|
+
},
|
|
39
144
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
145
|
+
{
|
|
146
|
+
name: "jsenv:file_url_fetching",
|
|
147
|
+
appliesDuring: "*",
|
|
148
|
+
fetchUrlContent: (urlInfo, context) => {
|
|
149
|
+
if (!urlInfo.url.startsWith("file:")) {
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
const urlObject = new URL(urlInfo.url)
|
|
153
|
+
if (context.reference.expectedType === "directory") {
|
|
154
|
+
if (directoryReferenceAllowed) {
|
|
155
|
+
const directoryEntries = readdirSync(urlObject)
|
|
156
|
+
let filename
|
|
157
|
+
if (context.reference.type === "filesystem") {
|
|
158
|
+
const parentUrlInfo = context.urlGraph.getUrlInfo(
|
|
159
|
+
context.reference.parentUrl,
|
|
160
|
+
)
|
|
161
|
+
filename = `${parentUrlInfo.filename}${context.reference.specifier}/`
|
|
162
|
+
} else {
|
|
163
|
+
filename = `${urlToFilename(urlInfo.url)}/`
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
type: "directory",
|
|
167
|
+
contentType: "application/json",
|
|
168
|
+
content: JSON.stringify(directoryEntries, null, " "),
|
|
169
|
+
filename,
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const error = new Error("found a directory on filesystem")
|
|
173
|
+
error.code = "EISDIR"
|
|
174
|
+
throw error
|
|
175
|
+
}
|
|
176
|
+
const fileBuffer = readFileSync(urlObject)
|
|
177
|
+
const contentType = CONTENT_TYPE.fromUrlExtension(urlInfo.url)
|
|
178
|
+
if (CONTENT_TYPE.isTextual(contentType)) {
|
|
179
|
+
return {
|
|
180
|
+
contentType,
|
|
181
|
+
content: String(fileBuffer),
|
|
182
|
+
}
|
|
183
|
+
}
|
|
55
184
|
return {
|
|
56
185
|
contentType,
|
|
57
|
-
content:
|
|
186
|
+
content: fileBuffer,
|
|
58
187
|
}
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
contentType,
|
|
62
|
-
content: fileBuffer,
|
|
63
|
-
}
|
|
188
|
+
},
|
|
64
189
|
},
|
|
65
|
-
|
|
190
|
+
]
|
|
66
191
|
}
|
|
@@ -185,7 +185,7 @@ export const installHtmlSupervisor = ({ logs, measurePerf }) => {
|
|
|
185
185
|
dequeue()
|
|
186
186
|
}
|
|
187
187
|
if (
|
|
188
|
-
document.readyState !== "
|
|
188
|
+
document.readyState !== "interactive" &&
|
|
189
189
|
document.readyState !== "complete"
|
|
190
190
|
) {
|
|
191
191
|
document.addEventListener("readystatechange", () => {
|
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
* - scripts are wrapped to be supervised
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { urlIsInsideOf } from "@jsenv/filesystem"
|
|
8
|
-
|
|
9
7
|
import {
|
|
10
8
|
parseHtmlString,
|
|
11
9
|
stringifyHtmlAst,
|
|
@@ -21,22 +19,20 @@ import {
|
|
|
21
19
|
setHtmlNodeGeneratedText,
|
|
22
20
|
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
23
21
|
import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
|
|
24
|
-
import { jsenvRootDirectoryUrl } from "@jsenv/core/src/jsenv_root_directory_url.js"
|
|
25
22
|
|
|
26
23
|
export const jsenvPluginHtmlSupervisor = ({
|
|
27
|
-
rootDirectoryUrl,
|
|
28
24
|
logs = false,
|
|
29
25
|
measurePerf = false,
|
|
30
26
|
}) => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
const htmlSupervisorSetupFileUrl = new URL(
|
|
28
|
+
"./client/html_supervisor_setup.js?js_classic",
|
|
29
|
+
import.meta.url,
|
|
30
|
+
).href
|
|
31
|
+
|
|
32
|
+
const htmlSupervisorInstallerFileUrl = new URL(
|
|
33
|
+
"./client/html_supervisor_installer.js",
|
|
34
|
+
import.meta.url,
|
|
35
|
+
).href
|
|
40
36
|
|
|
41
37
|
return {
|
|
42
38
|
name: "jsenv:html_supervisor",
|
|
@@ -2,11 +2,11 @@ export const jsenvPluginHttpUrls = () => {
|
|
|
2
2
|
return {
|
|
3
3
|
name: "jsenv:http_urls",
|
|
4
4
|
appliesDuring: "*",
|
|
5
|
-
fetchUrlContent: (urlInfo) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
5
|
+
// fetchUrlContent: (urlInfo) => {
|
|
6
|
+
// if (urlInfo.url.startsWith("http") || urlInfo.url.startsWith("https")) {
|
|
7
|
+
// return { shouldHandle: false }
|
|
8
|
+
// }
|
|
9
|
+
// return null
|
|
10
|
+
// },
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import { urlIsInsideOf } from "@jsenv/filesystem"
|
|
2
|
-
|
|
3
1
|
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
4
2
|
import { parseHtmlString } from "@jsenv/utils/html_ast/html_ast.js"
|
|
5
3
|
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
6
|
-
import { jsenvRootDirectoryUrl } from "@jsenv/core/src/jsenv_root_directory_url.js"
|
|
7
4
|
import { collectHotDataFromHtmlAst } from "./html_hot_dependencies.js"
|
|
8
5
|
import { babelPluginMetadataImportMetaHot } from "./babel_plugin_metadata_import_meta_hot.js"
|
|
9
6
|
|
|
10
|
-
export const jsenvPluginImportMetaHot = (
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
? new URL("./client/import_meta_hot.js", import.meta.url).href
|
|
16
|
-
: new URL("./dist/import_meta_hot.js", jsenvRootDirectoryUrl).href
|
|
7
|
+
export const jsenvPluginImportMetaHot = () => {
|
|
8
|
+
const importMetaHotClientFileUrl = new URL(
|
|
9
|
+
"./client/import_meta_hot.js",
|
|
10
|
+
import.meta.url,
|
|
11
|
+
).href
|
|
17
12
|
|
|
18
13
|
return {
|
|
19
14
|
name: "jsenv:import_meta_hot",
|
|
@@ -130,9 +130,8 @@ export const jsenvPluginImportmap = () => {
|
|
|
130
130
|
contentType: "application/importmap+json",
|
|
131
131
|
content: textNode.value,
|
|
132
132
|
})
|
|
133
|
-
await context.cook({
|
|
133
|
+
await context.cook(inlineImportmapUrlInfo, {
|
|
134
134
|
reference: inlineImportmapReference,
|
|
135
|
-
urlInfo: inlineImportmapUrlInfo,
|
|
136
135
|
})
|
|
137
136
|
setHtmlNodeGeneratedText(importmap, {
|
|
138
137
|
generatedText: inlineImportmapUrlInfo.content,
|
|
@@ -154,9 +153,8 @@ export const jsenvPluginImportmap = () => {
|
|
|
154
153
|
const importmapUrlInfo = context.urlGraph.getUrlInfo(
|
|
155
154
|
importmapReference.url,
|
|
156
155
|
)
|
|
157
|
-
await context.cook({
|
|
156
|
+
await context.cook(importmapUrlInfo, {
|
|
158
157
|
reference: importmapReference,
|
|
159
|
-
urlInfo: importmapUrlInfo,
|
|
160
158
|
})
|
|
161
159
|
onHtmlImportmapParsed(
|
|
162
160
|
JSON.parse(importmapUrlInfo.content),
|
|
@@ -11,56 +11,65 @@ export const jsenvPluginInjectGlobals = (globals = {}) => {
|
|
|
11
11
|
if (Object.keys(globals).length === 0) {
|
|
12
12
|
return []
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
const globalInjectorOnHtmlEntryPoint = (urlInfo) => {
|
|
16
|
-
if (!urlInfo.data.isEntryPoint) {
|
|
17
|
-
return null
|
|
18
|
-
}
|
|
19
|
-
// ideally we would inject an importmap but browser support is too low
|
|
20
|
-
// (even worse for worker/service worker)
|
|
21
|
-
// so for now we inject code into entry points
|
|
22
|
-
const htmlAst = parseHtmlString(urlInfo.content, {
|
|
23
|
-
storeOriginalPositions: false,
|
|
24
|
-
})
|
|
25
|
-
injectScriptAsEarlyAsPossible(
|
|
26
|
-
htmlAst,
|
|
27
|
-
createHtmlNode({
|
|
28
|
-
"tagName": "script",
|
|
29
|
-
"textContent": generateClientCodeForGlobals({
|
|
30
|
-
globals,
|
|
31
|
-
isWebWorker: false,
|
|
32
|
-
}),
|
|
33
|
-
"injected-by": "jsenv:inject_globals",
|
|
34
|
-
}),
|
|
35
|
-
)
|
|
36
|
-
return stringifyHtmlAst(htmlAst)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const globalsInjectorOnJsEntryPoints = (urlInfo) => {
|
|
40
|
-
if (!urlInfo.data.isEntryPoint && !urlInfo.data.isWebWorkerEntryPoint) {
|
|
41
|
-
return null
|
|
42
|
-
}
|
|
43
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
44
|
-
magicSource.append(
|
|
45
|
-
generateClientCodeForGlobals({
|
|
46
|
-
globals,
|
|
47
|
-
isWebWorker: isWebWorkerUrlInfo(urlInfo),
|
|
48
|
-
}),
|
|
49
|
-
)
|
|
50
|
-
return magicSource.toContentAndSourcemap()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
14
|
return {
|
|
54
15
|
name: "jsenv:inject_globals",
|
|
55
16
|
appliesDuring: "*",
|
|
56
17
|
transformUrlContent: {
|
|
57
|
-
html:
|
|
58
|
-
js_classic:
|
|
59
|
-
js_module:
|
|
18
|
+
html: injectGlobals,
|
|
19
|
+
js_classic: injectGlobals,
|
|
20
|
+
js_module: injectGlobals,
|
|
60
21
|
},
|
|
61
22
|
}
|
|
62
23
|
}
|
|
63
24
|
|
|
25
|
+
export const injectGlobals = (urlInfo, globals) => {
|
|
26
|
+
if (urlInfo.type === "html") {
|
|
27
|
+
return globalInjectorOnHtmlEntryPoint(urlInfo, globals)
|
|
28
|
+
}
|
|
29
|
+
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
30
|
+
return globalsInjectorOnJsEntryPoints(urlInfo, globals)
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`cannot inject globals into "${urlInfo.type}"`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const globalInjectorOnHtmlEntryPoint = async (urlInfo, globals) => {
|
|
36
|
+
if (!urlInfo.data.isEntryPoint) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
// ideally we would inject an importmap but browser support is too low
|
|
40
|
+
// (even worse for worker/service worker)
|
|
41
|
+
// so for now we inject code into entry points
|
|
42
|
+
const htmlAst = parseHtmlString(urlInfo.content, {
|
|
43
|
+
storeOriginalPositions: false,
|
|
44
|
+
})
|
|
45
|
+
const clientCode = generateClientCodeForGlobals({
|
|
46
|
+
globals,
|
|
47
|
+
isWebWorker: false,
|
|
48
|
+
})
|
|
49
|
+
injectScriptAsEarlyAsPossible(
|
|
50
|
+
htmlAst,
|
|
51
|
+
createHtmlNode({
|
|
52
|
+
"tagName": "script",
|
|
53
|
+
"textContent": clientCode,
|
|
54
|
+
"injected-by": "jsenv:inject_globals",
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
57
|
+
return stringifyHtmlAst(htmlAst)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const globalsInjectorOnJsEntryPoints = async (urlInfo, globals) => {
|
|
61
|
+
if (!urlInfo.data.isEntryPoint && !urlInfo.data.isWebWorkerEntryPoint) {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
const clientCode = generateClientCodeForGlobals({
|
|
65
|
+
globals,
|
|
66
|
+
isWebWorker: isWebWorkerUrlInfo(urlInfo),
|
|
67
|
+
})
|
|
68
|
+
const magicSource = createMagicSource(urlInfo.content)
|
|
69
|
+
magicSource.prepend(clientCode)
|
|
70
|
+
return magicSource.toContentAndSourcemap()
|
|
71
|
+
}
|
|
72
|
+
|
|
64
73
|
const generateClientCodeForGlobals = ({ isWebWorker = false, globals }) => {
|
|
65
74
|
const globalName = isWebWorker ? "self" : "window"
|
|
66
75
|
return `Object.assign(${globalName}, ${JSON.stringify(globals, null, " ")});`
|
|
@@ -35,10 +35,7 @@ export const jsenvPluginDataUrls = () => {
|
|
|
35
35
|
}
|
|
36
36
|
return (async () => {
|
|
37
37
|
const urlInfo = context.urlGraph.getUrlInfo(reference.url)
|
|
38
|
-
await context.cook({
|
|
39
|
-
reference,
|
|
40
|
-
urlInfo,
|
|
41
|
-
})
|
|
38
|
+
await context.cook(urlInfo, { reference })
|
|
42
39
|
if (urlInfo.originalContent === urlInfo.content) {
|
|
43
40
|
return reference.generatedUrl
|
|
44
41
|
}
|
|
@@ -54,9 +54,8 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
54
54
|
contentType: "text/css",
|
|
55
55
|
content: textNode.value,
|
|
56
56
|
})
|
|
57
|
-
await context.cook({
|
|
57
|
+
await context.cook(inlineStyleUrlInfo, {
|
|
58
58
|
reference: inlineStyleReference,
|
|
59
|
-
urlInfo: inlineStyleUrlInfo,
|
|
60
59
|
})
|
|
61
60
|
setHtmlNodeGeneratedText(node, {
|
|
62
61
|
generatedText: inlineStyleUrlInfo.content,
|
|
@@ -77,7 +76,7 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
77
76
|
// - we want to avoid cooking twice a script during build
|
|
78
77
|
const generatedBy = getHtmlNodeAttributeByName(node, "generated-by")
|
|
79
78
|
if (generatedBy) {
|
|
80
|
-
if (generatedBy.value === "jsenv:
|
|
79
|
+
if (generatedBy.value === "jsenv:as_js_classic_html") {
|
|
81
80
|
if (!analyzeConvertedScripts) {
|
|
82
81
|
return
|
|
83
82
|
}
|
|
@@ -135,9 +134,8 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
135
134
|
content: textNode.value,
|
|
136
135
|
})
|
|
137
136
|
|
|
138
|
-
await context.cook({
|
|
137
|
+
await context.cook(inlineScriptUrlInfo, {
|
|
139
138
|
reference: inlineScriptReference,
|
|
140
|
-
urlInfo: inlineScriptUrlInfo,
|
|
141
139
|
})
|
|
142
140
|
setHtmlNodeGeneratedText(node, {
|
|
143
141
|
generatedText: inlineScriptUrlInfo.content,
|
|
@@ -25,10 +25,7 @@ export const jsenvPluginInlineQueryParam = () => {
|
|
|
25
25
|
}
|
|
26
26
|
return (async () => {
|
|
27
27
|
const urlInfo = context.urlGraph.getUrlInfo(reference.url)
|
|
28
|
-
await context.cook({
|
|
29
|
-
reference,
|
|
30
|
-
urlInfo,
|
|
31
|
-
})
|
|
28
|
+
await context.cook(urlInfo, { reference })
|
|
32
29
|
const specifier = DataUrl.stringify({
|
|
33
30
|
mediaType: urlInfo.contentType,
|
|
34
31
|
base64Flag: true,
|
|
@@ -49,10 +49,7 @@ export const jsenvPluginJsInlineContent = ({ allowEscapeForVersioning }) => {
|
|
|
49
49
|
inlineUrlInfo.jsQuote = quote
|
|
50
50
|
inlineReference.escape = (value) =>
|
|
51
51
|
JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote })
|
|
52
|
-
await context.cook({
|
|
53
|
-
reference: inlineReference,
|
|
54
|
-
urlInfo: inlineUrlInfo,
|
|
55
|
-
})
|
|
52
|
+
await context.cook(inlineUrlInfo, { reference: inlineReference })
|
|
56
53
|
magicSource.replace({
|
|
57
54
|
start: inlineContentInfo.start,
|
|
58
55
|
end: inlineContentInfo.end,
|
|
@@ -13,12 +13,13 @@ import {
|
|
|
13
13
|
applyNodeEsmResolution,
|
|
14
14
|
defaultLookupPackageScope,
|
|
15
15
|
defaultReadPackageJson,
|
|
16
|
+
readCustomConditionsFromProcessArgs,
|
|
16
17
|
} from "@jsenv/node-esm-resolution"
|
|
17
18
|
|
|
18
19
|
export const jsenvPluginNodeEsmResolution = ({
|
|
19
20
|
rootDirectoryUrl,
|
|
20
|
-
|
|
21
|
-
packageConditions
|
|
21
|
+
runtimeCompat,
|
|
22
|
+
packageConditions,
|
|
22
23
|
filesInvalidatingCache = ["package.json", "package-lock.json"],
|
|
23
24
|
}) => {
|
|
24
25
|
const packageScopesCache = new Map()
|
|
@@ -64,6 +65,7 @@ export const jsenvPluginNodeEsmResolution = ({
|
|
|
64
65
|
|
|
65
66
|
return [
|
|
66
67
|
jsenvPluginNodeEsmResolver({
|
|
68
|
+
runtimeCompat,
|
|
67
69
|
packageConditions,
|
|
68
70
|
lookupPackageScope,
|
|
69
71
|
readPackageJson,
|
|
@@ -76,10 +78,18 @@ export const jsenvPluginNodeEsmResolution = ({
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
const jsenvPluginNodeEsmResolver = ({
|
|
81
|
+
runtimeCompat,
|
|
79
82
|
packageConditions,
|
|
80
83
|
lookupPackageScope,
|
|
81
84
|
readPackageJson,
|
|
82
85
|
}) => {
|
|
86
|
+
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node")
|
|
87
|
+
// https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
88
|
+
packageConditions = packageConditions || [
|
|
89
|
+
...readCustomConditionsFromProcessArgs(),
|
|
90
|
+
nodeRuntimeEnabled ? "node" : "browser",
|
|
91
|
+
"import",
|
|
92
|
+
]
|
|
83
93
|
return {
|
|
84
94
|
name: "jsenv:node_esm_resolve",
|
|
85
95
|
appliesDuring: "*",
|
|
@@ -138,6 +148,10 @@ const jsenvPluginNodeModulesVersionInUrls = ({
|
|
|
138
148
|
return null
|
|
139
149
|
}
|
|
140
150
|
const packageVersion = readPackageJson(packageUrl).version
|
|
151
|
+
if (!packageVersion) {
|
|
152
|
+
// example where it happens: https://github.com/babel/babel/blob/2ce56e832c2dd7a7ed92c89028ba929f874c2f5c/packages/babel-runtime/helpers/esm/package.json#L2
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
141
155
|
return {
|
|
142
156
|
v: packageVersion,
|
|
143
157
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const jsenvPluginNodeRuntime = ({ runtimeCompat }) => {
|
|
2
|
+
const nodeFound = Object.keys(runtimeCompat).includes("node")
|
|
3
|
+
if (!nodeFound) {
|
|
4
|
+
return []
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// what do we need to do?
|
|
8
|
+
return {
|
|
9
|
+
name: "jsenv:node_runtime",
|
|
10
|
+
appliesDuring: "*",
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -159,6 +159,9 @@ const flattenAndFilterPlugins = (pluginsRaw, { scenario }) => {
|
|
|
159
159
|
return
|
|
160
160
|
}
|
|
161
161
|
if (typeof pluginEntry === "object" && pluginEntry !== null) {
|
|
162
|
+
if (!pluginEntry.name) {
|
|
163
|
+
pluginEntry.name = "anonymous"
|
|
164
|
+
}
|
|
162
165
|
const { appliesDuring } = pluginEntry
|
|
163
166
|
if (appliesDuring === undefined) {
|
|
164
167
|
console.warn(`"appliesDuring" is undefined on ${pluginEntry.name}`)
|
|
@@ -168,9 +171,20 @@ const flattenAndFilterPlugins = (pluginsRaw, { scenario }) => {
|
|
|
168
171
|
plugins.push(pluginEntry)
|
|
169
172
|
return
|
|
170
173
|
}
|
|
174
|
+
if (typeof appliesDuring === "string") {
|
|
175
|
+
if (!["dev", "build", "test"].includes(appliesDuring)) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`"appliesDuring" must be "dev", "test" or "build", got ${appliesDuring}`,
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
if (appliesDuring === scenario) {
|
|
181
|
+
plugins.push(pluginEntry)
|
|
182
|
+
}
|
|
183
|
+
return
|
|
184
|
+
}
|
|
171
185
|
if (typeof appliesDuring !== "object") {
|
|
172
186
|
throw new Error(
|
|
173
|
-
`"appliesDuring" must be an object or
|
|
187
|
+
`"appliesDuring" must be an object or a string, got ${appliesDuring}`,
|
|
174
188
|
)
|
|
175
189
|
}
|
|
176
190
|
if (appliesDuring[scenario]) {
|
|
@@ -252,8 +266,8 @@ const returnValueAssertions = [
|
|
|
252
266
|
return { content: valueReturned }
|
|
253
267
|
}
|
|
254
268
|
if (typeof valueReturned === "object") {
|
|
255
|
-
const {
|
|
256
|
-
if (
|
|
269
|
+
const { shouldHandle, content } = valueReturned
|
|
270
|
+
if (shouldHandle === false) {
|
|
257
271
|
return undefined
|
|
258
272
|
}
|
|
259
273
|
if (typeof content !== "string" && !Buffer.isBuffer(content)) {
|