@jsenv/core 30.0.0-alpha.1 → 30.0.0
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/main.js +1 -127
- package/package.json +6 -4
- package/src/main.js +0 -2
- package/src/plugins/inject_globals/inject_globals.js +0 -57
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +0 -36
- package/src/plugins/placeholders/jsenv_plugin_placeholders.js +0 -36
- package/src/plugins/placeholders/replace_placeholders.js +0 -25
package/dist/main.js
CHANGED
|
@@ -25903,132 +25903,6 @@ const createBuildFilesService = ({
|
|
|
25903
25903
|
};
|
|
25904
25904
|
const SECONDS_IN_30_DAYS = 60 * 60 * 24 * 30;
|
|
25905
25905
|
|
|
25906
|
-
const injectGlobals = (urlInfo, globals) => {
|
|
25907
|
-
if (urlInfo.type === "html") {
|
|
25908
|
-
return globalInjectorOnHtml(urlInfo, globals);
|
|
25909
|
-
}
|
|
25910
|
-
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
25911
|
-
return globalsInjectorOnJs(urlInfo, globals);
|
|
25912
|
-
}
|
|
25913
|
-
throw new Error(`cannot inject globals into "${urlInfo.type}"`);
|
|
25914
|
-
};
|
|
25915
|
-
const globalInjectorOnHtml = async (urlInfo, globals) => {
|
|
25916
|
-
// ideally we would inject an importmap but browser support is too low
|
|
25917
|
-
// (even worse for worker/service worker)
|
|
25918
|
-
// so for now we inject code into entry points
|
|
25919
|
-
const htmlAst = parseHtmlString(urlInfo.content, {
|
|
25920
|
-
storeOriginalPositions: false
|
|
25921
|
-
});
|
|
25922
|
-
const clientCode = generateClientCodeForGlobals({
|
|
25923
|
-
globals,
|
|
25924
|
-
isWebWorker: false
|
|
25925
|
-
});
|
|
25926
|
-
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
25927
|
-
tagName: "script",
|
|
25928
|
-
textContent: clientCode
|
|
25929
|
-
}), "jsenv:inject_globals");
|
|
25930
|
-
return stringifyHtmlAst(htmlAst);
|
|
25931
|
-
};
|
|
25932
|
-
const globalsInjectorOnJs = async (urlInfo, globals) => {
|
|
25933
|
-
const clientCode = generateClientCodeForGlobals({
|
|
25934
|
-
globals,
|
|
25935
|
-
isWebWorker: urlInfo.subtype === "worker" || urlInfo.subtype === "service_worker" || urlInfo.subtype === "shared_worker"
|
|
25936
|
-
});
|
|
25937
|
-
const magicSource = createMagicSource(urlInfo.content);
|
|
25938
|
-
magicSource.prepend(clientCode);
|
|
25939
|
-
return magicSource.toContentAndSourcemap();
|
|
25940
|
-
};
|
|
25941
|
-
const generateClientCodeForGlobals = ({
|
|
25942
|
-
isWebWorker = false,
|
|
25943
|
-
globals
|
|
25944
|
-
}) => {
|
|
25945
|
-
const globalName = isWebWorker ? "self" : "window";
|
|
25946
|
-
return `Object.assign(${globalName}, ${JSON.stringify(globals, null, " ")});`;
|
|
25947
|
-
};
|
|
25948
|
-
|
|
25949
|
-
const jsenvPluginInjectGlobals = rawAssociations => {
|
|
25950
|
-
let resolvedAssociations;
|
|
25951
|
-
return {
|
|
25952
|
-
name: "jsenv:inject_globals",
|
|
25953
|
-
appliesDuring: "*",
|
|
25954
|
-
init: context => {
|
|
25955
|
-
resolvedAssociations = URL_META.resolveAssociations({
|
|
25956
|
-
injector: rawAssociations
|
|
25957
|
-
}, context.rootDirectoryUrl);
|
|
25958
|
-
},
|
|
25959
|
-
transformUrlContent: async (urlInfo, context) => {
|
|
25960
|
-
const {
|
|
25961
|
-
injector
|
|
25962
|
-
} = URL_META.applyAssociations({
|
|
25963
|
-
url: asUrlWithoutSearch(urlInfo.url),
|
|
25964
|
-
associations: resolvedAssociations
|
|
25965
|
-
});
|
|
25966
|
-
if (!injector) {
|
|
25967
|
-
return null;
|
|
25968
|
-
}
|
|
25969
|
-
if (typeof injector !== "function") {
|
|
25970
|
-
throw new TypeError("injector must be a function");
|
|
25971
|
-
}
|
|
25972
|
-
const globals = await injector(urlInfo, context);
|
|
25973
|
-
if (!globals || Object.keys(globals).length === 0) {
|
|
25974
|
-
return null;
|
|
25975
|
-
}
|
|
25976
|
-
return injectGlobals(urlInfo, globals);
|
|
25977
|
-
}
|
|
25978
|
-
};
|
|
25979
|
-
};
|
|
25980
|
-
|
|
25981
|
-
const replacePlaceholders = (urlInfo, replacements) => {
|
|
25982
|
-
const content = urlInfo.content;
|
|
25983
|
-
const magicSource = createMagicSource(content);
|
|
25984
|
-
Object.keys(replacements).forEach(key => {
|
|
25985
|
-
let index = content.indexOf(key);
|
|
25986
|
-
while (index !== -1) {
|
|
25987
|
-
const start = index;
|
|
25988
|
-
const end = index + key.length;
|
|
25989
|
-
magicSource.replace({
|
|
25990
|
-
start,
|
|
25991
|
-
end,
|
|
25992
|
-
replacement: urlInfo.type === "js_classic" || urlInfo.type === "js_module" || urlInfo.type === "html" ? JSON.stringify(replacements[key], null, " ") : replacements[key]
|
|
25993
|
-
});
|
|
25994
|
-
index = content.indexOf(key, end);
|
|
25995
|
-
}
|
|
25996
|
-
});
|
|
25997
|
-
return magicSource.toContentAndSourcemap();
|
|
25998
|
-
};
|
|
25999
|
-
|
|
26000
|
-
const jsenvPluginPlaceholders = rawAssociations => {
|
|
26001
|
-
let resolvedAssociations;
|
|
26002
|
-
return {
|
|
26003
|
-
name: "jsenv:placeholders",
|
|
26004
|
-
appliesDuring: "*",
|
|
26005
|
-
init: context => {
|
|
26006
|
-
resolvedAssociations = URL_META.resolveAssociations({
|
|
26007
|
-
replacer: rawAssociations
|
|
26008
|
-
}, context.rootDirectoryUrl);
|
|
26009
|
-
},
|
|
26010
|
-
transformUrlContent: async (urlInfo, context) => {
|
|
26011
|
-
const {
|
|
26012
|
-
replacer
|
|
26013
|
-
} = URL_META.applyAssociations({
|
|
26014
|
-
url: asUrlWithoutSearch(urlInfo.url),
|
|
26015
|
-
associations: resolvedAssociations
|
|
26016
|
-
});
|
|
26017
|
-
if (!replacer) {
|
|
26018
|
-
return null;
|
|
26019
|
-
}
|
|
26020
|
-
if (typeof replacer !== "function") {
|
|
26021
|
-
throw new TypeError("replacer must be a function");
|
|
26022
|
-
}
|
|
26023
|
-
const replacements = await replacer(urlInfo, context);
|
|
26024
|
-
if (!replacements || Object.keys(replacements).length === 0) {
|
|
26025
|
-
return null;
|
|
26026
|
-
}
|
|
26027
|
-
return replacePlaceholders(urlInfo, replacements);
|
|
26028
|
-
}
|
|
26029
|
-
};
|
|
26030
|
-
};
|
|
26031
|
-
|
|
26032
25906
|
const execute = async ({
|
|
26033
25907
|
signal = new AbortController().signal,
|
|
26034
25908
|
handleSIGINT = true,
|
|
@@ -26114,4 +25988,4 @@ const execute = async ({
|
|
|
26114
25988
|
}
|
|
26115
25989
|
};
|
|
26116
25990
|
|
|
26117
|
-
export { build, chromium, chromiumIsolatedTab, execute, executeTestPlan, firefox, firefoxIsolatedTab,
|
|
25991
|
+
export { build, chromium, chromiumIsolatedTab, execute, executeTestPlan, firefox, firefoxIsolatedTab, nodeChildProcess, nodeWorkerThread, pingServer, startBuildServer, startDevServer, webkit, webkitIsolatedTab };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "30.0.0
|
|
3
|
+
"version": "30.0.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -102,13 +102,15 @@
|
|
|
102
102
|
"@jsenv/file-size-impact": "13.0.2",
|
|
103
103
|
"@jsenv/https-local": "3.0.1",
|
|
104
104
|
"@jsenv/package-workspace": "0.5.1",
|
|
105
|
-
"@jsenv/plugin-minification": "
|
|
105
|
+
"@jsenv/plugin-minification": "./packages/jsenv-plugin-minification/",
|
|
106
|
+
"@jsenv/plugin-globals": "./packages/jsenv-plugin-globals/",
|
|
107
|
+
"@jsenv/plugin-placeholders": "./packages/jsenv-plugin-placeholders/",
|
|
106
108
|
"@jsenv/performance-impact": "4.1.0",
|
|
107
|
-
"eslint": "8.
|
|
109
|
+
"eslint": "8.30.0",
|
|
108
110
|
"eslint-plugin-html": "7.1.0",
|
|
109
111
|
"eslint-plugin-import": "2.26.0",
|
|
110
112
|
"eslint-plugin-react": "7.31.11",
|
|
111
|
-
"playwright": "1.
|
|
113
|
+
"playwright": "1.29.0",
|
|
112
114
|
"prettier": "2.8.1"
|
|
113
115
|
}
|
|
114
116
|
}
|
package/src/main.js
CHANGED
|
@@ -25,6 +25,4 @@ export { startBuildServer } from "./build/start_build_server.js"
|
|
|
25
25
|
export { pingServer } from "./ping_server.js"
|
|
26
26
|
|
|
27
27
|
// advanced
|
|
28
|
-
export { jsenvPluginInjectGlobals } from "./plugins/inject_globals/jsenv_plugin_inject_globals.js"
|
|
29
|
-
export { jsenvPluginPlaceholders } from "./plugins/placeholders/jsenv_plugin_placeholders.js"
|
|
30
28
|
export { execute } from "./execute/execute.js"
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
2
|
-
import {
|
|
3
|
-
parseHtmlString,
|
|
4
|
-
injectScriptNodeAsEarlyAsPossible,
|
|
5
|
-
createHtmlNode,
|
|
6
|
-
stringifyHtmlAst,
|
|
7
|
-
} from "@jsenv/ast"
|
|
8
|
-
|
|
9
|
-
export const injectGlobals = (urlInfo, globals) => {
|
|
10
|
-
if (urlInfo.type === "html") {
|
|
11
|
-
return globalInjectorOnHtml(urlInfo, globals)
|
|
12
|
-
}
|
|
13
|
-
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
14
|
-
return globalsInjectorOnJs(urlInfo, globals)
|
|
15
|
-
}
|
|
16
|
-
throw new Error(`cannot inject globals into "${urlInfo.type}"`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const globalInjectorOnHtml = async (urlInfo, globals) => {
|
|
20
|
-
// ideally we would inject an importmap but browser support is too low
|
|
21
|
-
// (even worse for worker/service worker)
|
|
22
|
-
// so for now we inject code into entry points
|
|
23
|
-
const htmlAst = parseHtmlString(urlInfo.content, {
|
|
24
|
-
storeOriginalPositions: false,
|
|
25
|
-
})
|
|
26
|
-
const clientCode = generateClientCodeForGlobals({
|
|
27
|
-
globals,
|
|
28
|
-
isWebWorker: false,
|
|
29
|
-
})
|
|
30
|
-
injectScriptNodeAsEarlyAsPossible(
|
|
31
|
-
htmlAst,
|
|
32
|
-
createHtmlNode({
|
|
33
|
-
tagName: "script",
|
|
34
|
-
textContent: clientCode,
|
|
35
|
-
}),
|
|
36
|
-
"jsenv:inject_globals",
|
|
37
|
-
)
|
|
38
|
-
return stringifyHtmlAst(htmlAst)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const globalsInjectorOnJs = async (urlInfo, globals) => {
|
|
42
|
-
const clientCode = generateClientCodeForGlobals({
|
|
43
|
-
globals,
|
|
44
|
-
isWebWorker:
|
|
45
|
-
urlInfo.subtype === "worker" ||
|
|
46
|
-
urlInfo.subtype === "service_worker" ||
|
|
47
|
-
urlInfo.subtype === "shared_worker",
|
|
48
|
-
})
|
|
49
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
50
|
-
magicSource.prepend(clientCode)
|
|
51
|
-
return magicSource.toContentAndSourcemap()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const generateClientCodeForGlobals = ({ isWebWorker = false, globals }) => {
|
|
55
|
-
const globalName = isWebWorker ? "self" : "window"
|
|
56
|
-
return `Object.assign(${globalName}, ${JSON.stringify(globals, null, " ")});`
|
|
57
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { URL_META } from "@jsenv/url-meta"
|
|
2
|
-
import { asUrlWithoutSearch } from "@jsenv/urls"
|
|
3
|
-
|
|
4
|
-
import { injectGlobals } from "./inject_globals.js"
|
|
5
|
-
|
|
6
|
-
export const jsenvPluginInjectGlobals = (rawAssociations) => {
|
|
7
|
-
let resolvedAssociations
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
name: "jsenv:inject_globals",
|
|
11
|
-
appliesDuring: "*",
|
|
12
|
-
init: (context) => {
|
|
13
|
-
resolvedAssociations = URL_META.resolveAssociations(
|
|
14
|
-
{ injector: rawAssociations },
|
|
15
|
-
context.rootDirectoryUrl,
|
|
16
|
-
)
|
|
17
|
-
},
|
|
18
|
-
transformUrlContent: async (urlInfo, context) => {
|
|
19
|
-
const { injector } = URL_META.applyAssociations({
|
|
20
|
-
url: asUrlWithoutSearch(urlInfo.url),
|
|
21
|
-
associations: resolvedAssociations,
|
|
22
|
-
})
|
|
23
|
-
if (!injector) {
|
|
24
|
-
return null
|
|
25
|
-
}
|
|
26
|
-
if (typeof injector !== "function") {
|
|
27
|
-
throw new TypeError("injector must be a function")
|
|
28
|
-
}
|
|
29
|
-
const globals = await injector(urlInfo, context)
|
|
30
|
-
if (!globals || Object.keys(globals).length === 0) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
return injectGlobals(urlInfo, globals)
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { URL_META } from "@jsenv/url-meta"
|
|
2
|
-
import { asUrlWithoutSearch } from "@jsenv/urls"
|
|
3
|
-
|
|
4
|
-
import { replacePlaceholders } from "./replace_placeholders.js"
|
|
5
|
-
|
|
6
|
-
export const jsenvPluginPlaceholders = (rawAssociations) => {
|
|
7
|
-
let resolvedAssociations
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
name: "jsenv:placeholders",
|
|
11
|
-
appliesDuring: "*",
|
|
12
|
-
init: (context) => {
|
|
13
|
-
resolvedAssociations = URL_META.resolveAssociations(
|
|
14
|
-
{ replacer: rawAssociations },
|
|
15
|
-
context.rootDirectoryUrl,
|
|
16
|
-
)
|
|
17
|
-
},
|
|
18
|
-
transformUrlContent: async (urlInfo, context) => {
|
|
19
|
-
const { replacer } = URL_META.applyAssociations({
|
|
20
|
-
url: asUrlWithoutSearch(urlInfo.url),
|
|
21
|
-
associations: resolvedAssociations,
|
|
22
|
-
})
|
|
23
|
-
if (!replacer) {
|
|
24
|
-
return null
|
|
25
|
-
}
|
|
26
|
-
if (typeof replacer !== "function") {
|
|
27
|
-
throw new TypeError("replacer must be a function")
|
|
28
|
-
}
|
|
29
|
-
const replacements = await replacer(urlInfo, context)
|
|
30
|
-
if (!replacements || Object.keys(replacements).length === 0) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
return replacePlaceholders(urlInfo, replacements)
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
2
|
-
|
|
3
|
-
export const replacePlaceholders = (urlInfo, replacements) => {
|
|
4
|
-
const content = urlInfo.content
|
|
5
|
-
const magicSource = createMagicSource(content)
|
|
6
|
-
Object.keys(replacements).forEach((key) => {
|
|
7
|
-
let index = content.indexOf(key)
|
|
8
|
-
while (index !== -1) {
|
|
9
|
-
const start = index
|
|
10
|
-
const end = index + key.length
|
|
11
|
-
magicSource.replace({
|
|
12
|
-
start,
|
|
13
|
-
end,
|
|
14
|
-
replacement:
|
|
15
|
-
urlInfo.type === "js_classic" ||
|
|
16
|
-
urlInfo.type === "js_module" ||
|
|
17
|
-
urlInfo.type === "html"
|
|
18
|
-
? JSON.stringify(replacements[key], null, " ")
|
|
19
|
-
: replacements[key],
|
|
20
|
-
})
|
|
21
|
-
index = content.indexOf(key, end)
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
return magicSource.toContentAndSourcemap()
|
|
25
|
-
}
|