@elliemae/pui-cli 9.0.0-next.52 → 9.0.0-next.61
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/app.tsconfig.json +6 -3
- package/dist/cjs/babel.config.cjs +1 -1
- package/dist/cjs/build/vite.config.js +45 -0
- package/dist/cjs/cli.js +3 -1
- package/dist/cjs/commands/buildcdn.js +74 -0
- package/dist/cjs/commands/lint.js +1 -1
- package/dist/cjs/commands/test.js +0 -1
- package/dist/cjs/commands/tscheck.js +8 -1
- package/dist/cjs/commands/utils.js +8 -8
- package/dist/cjs/commands/vitest.js +0 -1
- package/dist/cjs/index.js +5 -7
- package/dist/cjs/lint-config/eslint.config.js +259 -0
- package/dist/cjs/lint-config/stylelint.config.js +1 -1
- package/dist/cjs/monorepo/utils.cjs +2 -2
- package/dist/cjs/monorepo/utils.js +1 -1
- package/dist/cjs/server/cert.js +45 -0
- package/dist/cjs/server/certs/cert.crt +25 -0
- package/dist/cjs/server/certs/cert.csr +18 -0
- package/dist/cjs/server/certs/cert.ext +7 -0
- package/dist/cjs/server/certs/cert.key +30 -0
- package/dist/cjs/server/certs/cert.pfx +0 -0
- package/dist/cjs/server/certs/rootCA.crt +24 -0
- package/dist/cjs/server/certs/rootCA.key +30 -0
- package/dist/cjs/server/certs/rootCA.srl +1 -0
- package/dist/cjs/server/csp.js +40 -29
- package/dist/cjs/server/index.js +8 -3
- package/dist/cjs/server/logger.js +5 -2
- package/dist/cjs/server/middlewares.js +2 -2
- package/dist/cjs/server/wsServer.js +7 -4
- package/dist/cjs/testing/jest.config.cjs +1 -2
- package/dist/cjs/testing/jest.polyfills.cjs +1 -1
- package/dist/cjs/testing/mocks/iframe.js +24 -0
- package/dist/cjs/testing/mocks/svg.js +0 -11
- package/dist/cjs/testing/resolver.cjs +0 -1
- package/dist/cjs/testing/vitest.config.js +1 -5
- package/dist/cjs/transpile/.swcrc +1 -0
- package/dist/cjs/utils.cjs +1 -1
- package/dist/cjs/utils.js +3 -1
- package/dist/cjs/webpack/csp-plugin.js +79 -0
- package/dist/cjs/webpack/csp.js +158 -0
- package/dist/cjs/webpack/helpers.js +14 -14
- package/dist/cjs/webpack/interceptor-middleware.js +125 -0
- package/dist/cjs/webpack/webpack.dev.babel.js +16 -4
- package/dist/cjs/webpack/webpack.lib.base.babel.js +0 -2
- package/dist/cjs/webpack/webpack.lib.prod.babel.js +3 -1
- package/dist/cjs/webpack/webpack.prod.babel.js +12 -5
- package/dist/cjs/webpack/webpack.storybook.js +1 -1
- package/dist/esm/babel.config.cjs +1 -1
- package/dist/esm/build/vite.config.js +25 -0
- package/dist/esm/cli.js +3 -1
- package/dist/esm/commands/buildcdn.js +43 -0
- package/dist/esm/commands/lint.js +1 -1
- package/dist/esm/commands/test.js +0 -1
- package/dist/esm/commands/tscheck.js +8 -1
- package/dist/esm/commands/utils.js +8 -8
- package/dist/esm/commands/vitest.js +0 -1
- package/dist/esm/index.js +2 -4
- package/dist/esm/lint-config/eslint.config.js +228 -0
- package/dist/esm/lint-config/stylelint.config.js +1 -1
- package/dist/esm/monorepo/utils.cjs +2 -2
- package/dist/esm/monorepo/utils.js +1 -1
- package/dist/esm/server/cert.js +14 -0
- package/dist/esm/server/certs/cert.crt +25 -0
- package/dist/esm/server/certs/cert.csr +18 -0
- package/dist/esm/server/certs/cert.ext +7 -0
- package/dist/esm/server/certs/cert.key +30 -0
- package/dist/esm/server/certs/cert.pfx +0 -0
- package/dist/esm/server/certs/rootCA.crt +24 -0
- package/dist/esm/server/certs/rootCA.key +30 -0
- package/dist/esm/server/certs/rootCA.srl +1 -0
- package/dist/esm/server/csp.js +40 -29
- package/dist/esm/server/index.js +8 -3
- package/dist/esm/server/logger.js +5 -2
- package/dist/esm/server/middlewares.js +2 -2
- package/dist/esm/server/wsServer.js +7 -4
- package/dist/esm/testing/jest.config.cjs +1 -2
- package/dist/esm/testing/jest.polyfills.cjs +1 -1
- package/dist/esm/testing/mocks/iframe.js +4 -0
- package/dist/esm/testing/mocks/svg.js +0 -1
- package/dist/esm/testing/resolver.cjs +0 -1
- package/dist/esm/testing/vitest.config.js +1 -4
- package/dist/esm/transpile/.swcrc +1 -0
- package/dist/esm/utils.cjs +1 -1
- package/dist/esm/utils.js +3 -1
- package/dist/esm/webpack/csp-plugin.js +49 -0
- package/dist/esm/webpack/csp.js +128 -0
- package/dist/esm/webpack/helpers.js +14 -14
- package/dist/esm/webpack/interceptor-middleware.js +105 -0
- package/dist/esm/webpack/webpack.dev.babel.js +16 -4
- package/dist/esm/webpack/webpack.lib.base.babel.js +0 -2
- package/dist/esm/webpack/webpack.lib.prod.babel.js +3 -1
- package/dist/esm/webpack/webpack.prod.babel.js +12 -5
- package/dist/esm/webpack/webpack.storybook.js +1 -1
- package/dist/types/eslint.config.d.ts +3 -0
- package/dist/types/eslint.config.d.ts.map +1 -0
- package/dist/types/lib/build/vite.config.d.ts +3 -0
- package/dist/types/lib/build/vite.config.d.ts.map +1 -0
- package/dist/types/lib/commands/build.d.ts.map +1 -1
- package/dist/types/lib/commands/buildcdn.d.ts +3 -0
- package/dist/types/lib/commands/buildcdn.d.ts.map +1 -0
- package/dist/types/lib/commands/gendoc.d.ts.map +1 -1
- package/dist/types/lib/commands/pack.d.ts.map +1 -1
- package/dist/types/lib/commands/start.d.ts.map +1 -1
- package/dist/types/lib/commands/test.d.ts.map +1 -1
- package/dist/types/lib/commands/tscheck.d.ts.map +1 -1
- package/dist/types/lib/commands/utils.d.ts +2 -1
- package/dist/types/lib/commands/utils.d.ts.map +1 -1
- package/dist/types/lib/commands/vitest.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +1 -2
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/lint-config/eslint.config.d.ts +3 -0
- package/dist/types/lib/lint-config/eslint.config.d.ts.map +1 -0
- package/dist/types/lib/server/cert.d.ts +5 -0
- package/dist/types/lib/server/cert.d.ts.map +1 -0
- package/dist/types/lib/server/csp.d.ts +0 -1
- package/dist/types/lib/server/csp.d.ts.map +1 -1
- package/dist/types/lib/server/logger.d.ts.map +1 -1
- package/dist/types/lib/server/wsServer.d.ts +2 -2
- package/dist/types/lib/server/wsServer.d.ts.map +1 -1
- package/dist/types/lib/testing/jest.config.d.cts +2 -1
- package/dist/types/lib/testing/jest.node.config.d.cts +2 -1
- package/dist/types/lib/testing/mocks/cssModule.d.ts.map +1 -1
- package/dist/types/lib/testing/mocks/html.d.ts.map +1 -1
- package/dist/types/lib/testing/mocks/iframe.d.ts +3 -0
- package/dist/types/lib/testing/mocks/iframe.d.ts.map +1 -0
- package/dist/types/lib/testing/mocks/image.d.ts.map +1 -1
- package/dist/types/lib/testing/mocks/svg.d.ts.map +1 -1
- package/dist/types/lib/testing/resolver.d.cts.map +1 -1
- package/dist/types/lib/testing/vitest.config.d.ts +1 -1
- package/dist/types/lib/testing/vitest.config.d.ts.map +1 -1
- package/dist/types/lib/transpile/esbuild.d.ts.map +1 -1
- package/dist/types/lib/utils.d.cts +1 -1
- package/dist/types/lib/utils.d.cts.map +1 -1
- package/dist/types/lib/utils.d.ts +2 -2
- package/dist/types/lib/utils.d.ts.map +1 -1
- package/dist/types/lib/webpack/csp-plugin.d.ts +33 -0
- package/dist/types/lib/webpack/csp-plugin.d.ts.map +1 -0
- package/dist/types/lib/webpack/csp.d.ts +66 -0
- package/dist/types/lib/webpack/csp.d.ts.map +1 -0
- package/dist/types/lib/webpack/helpers.d.ts +0 -1
- package/dist/types/lib/webpack/helpers.d.ts.map +1 -1
- package/dist/types/lib/webpack/interceptor-middleware.d.ts +11 -0
- package/dist/types/lib/webpack/interceptor-middleware.d.ts.map +1 -0
- package/dist/types/lib/webpack/webpack.base.babel.d.ts.map +1 -1
- package/dist/types/lib/webpack/webpack.dev.babel.d.ts.map +1 -1
- package/dist/types/lib/webpack/webpack.lib.base.babel.d.ts.map +1 -1
- package/dist/types/lib/webpack/webpack.lib.prod.babel.d.ts.map +1 -1
- package/dist/types/lib/webpack/webpack.prod.babel.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/library.tsconfig.json +8 -5
- package/package.json +146 -142
- package/dist/cjs/lint-config/eslint/config.js +0 -186
- package/dist/cjs/lint-config/eslint/react.js +0 -107
- package/dist/cjs/lint-config/eslint/typescript/config.js +0 -97
- package/dist/cjs/testing/setup-test-env.js +0 -6
- package/dist/esm/lint-config/eslint/config.js +0 -155
- package/dist/esm/lint-config/eslint/react.js +0 -76
- package/dist/esm/lint-config/eslint/typescript/config.js +0 -67
- package/dist/esm/testing/setup-test-env.js +0 -5
- package/dist/types/lib/lint-config/eslint/config.d.ts +0 -2
- package/dist/types/lib/lint-config/eslint/config.d.ts.map +0 -1
- package/dist/types/lib/lint-config/eslint/react.d.ts +0 -2
- package/dist/types/lib/lint-config/eslint/react.d.ts.map +0 -1
- package/dist/types/lib/lint-config/eslint/typescript/config.d.ts +0 -2
- package/dist/types/lib/lint-config/eslint/typescript/config.d.ts.map +0 -1
- package/dist/types/lib/testing/setup-test-env.d.ts +0 -2
- package/dist/types/lib/testing/setup-test-env.d.ts.map +0 -1
- package/dist/types/lib/tests/basic.test.d.ts +0 -1
- package/dist/types/lib/tests/basic.test.d.ts.map +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var csp_exports = {};
|
|
30
|
+
__export(csp_exports, {
|
|
31
|
+
CSP: () => CSP
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(csp_exports);
|
|
34
|
+
var crypto = __toESM(require("node:crypto"));
|
|
35
|
+
var cheerio = __toESM(require("cheerio"));
|
|
36
|
+
class CSP {
|
|
37
|
+
static HASH_FUNCTION = "sha256";
|
|
38
|
+
static INLINE_SCRIPT_SELECTOR = "script:not([src])";
|
|
39
|
+
static SOURCED_SCRIPT_SELECTOR = "script[src]";
|
|
40
|
+
$;
|
|
41
|
+
constructor(html) {
|
|
42
|
+
this.$ = cheerio.load(html);
|
|
43
|
+
}
|
|
44
|
+
serializeDom() {
|
|
45
|
+
return this.$.root().html() ?? "";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns a strict Content Security Policy for mittigating XSS.
|
|
49
|
+
* For more details read csp.withgoogle.com.
|
|
50
|
+
* If you modify this CSP, make sure it has not become trivially bypassable by
|
|
51
|
+
* checking the policy using csp-evaluator.withgoogle.com.
|
|
52
|
+
* @param hashes A list of sha-256 hashes of trusted inline scripts.
|
|
53
|
+
* @param cspOptions
|
|
54
|
+
* @param enableTrustedTypes If Trusted Types should be enabled for scripts.
|
|
55
|
+
* @param enableBrowserFallbacks If fallbacks for older browsers should be
|
|
56
|
+
* added. This is will not weaken the policy as modern browsers will ignore
|
|
57
|
+
* the fallbacks.
|
|
58
|
+
* @param enableUnsafeEval If you cannot remove all uses of eval(), you can
|
|
59
|
+
* still set a strict CSP, but you will have to use the 'unsafe-eval'
|
|
60
|
+
* keyword which will make your policy slightly less secure.
|
|
61
|
+
* @param cspOptions.enableBrowserFallbacks
|
|
62
|
+
* @param cspOptions.enableTrustedTypes
|
|
63
|
+
* @param cspOptions.enableUnsafeEval
|
|
64
|
+
* @returns A strict Content Security Policy string.
|
|
65
|
+
*/
|
|
66
|
+
static getStrictCsp(hashes, cspOptions = {
|
|
67
|
+
enableUnsafeEval: false
|
|
68
|
+
}) {
|
|
69
|
+
const strictCspTemplate = {
|
|
70
|
+
// 'strict-dynamic' allows hashed scripts to create new scripts.
|
|
71
|
+
"script-src": [`'strict-dynamic'`, ...hashes ?? []],
|
|
72
|
+
// Restricts `object-src` to disable dangerous plugins like Flash.
|
|
73
|
+
"object-src": [`'none'`],
|
|
74
|
+
// Restricts `base-uri` to block the injection of `<base>` tags. This
|
|
75
|
+
// prevents attackers from changing the locations of scripts loaded from
|
|
76
|
+
// relative URLs.
|
|
77
|
+
"base-uri": [`'self'`]
|
|
78
|
+
};
|
|
79
|
+
if (cspOptions.enableUnsafeEval) {
|
|
80
|
+
strictCspTemplate["script-src"].push(`'unsafe-eval'`);
|
|
81
|
+
}
|
|
82
|
+
return Object.entries(strictCspTemplate).map(([directive, values]) => `${directive} ${values.join(" ")};`).join("");
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Enables a CSP via a meta tag at the beginning of the document.
|
|
86
|
+
* Warning: It's recommended to set CSP as HTTP response header instead of
|
|
87
|
+
* using a meta tag. Injections before the meta tag will not be covered by CSP
|
|
88
|
+
* and meta tags don't support CSP in report-only mode.
|
|
89
|
+
* @param csp A Content Security Policy string.
|
|
90
|
+
*/
|
|
91
|
+
addMetaTag(csp) {
|
|
92
|
+
let metaTag = this.$('meta[http-equiv="Content-Security-Policy"]');
|
|
93
|
+
if (!metaTag.length) {
|
|
94
|
+
metaTag = cheerio.load('<meta http-equiv="Content-Security-Policy">')(
|
|
95
|
+
"meta"
|
|
96
|
+
);
|
|
97
|
+
metaTag.prependTo(this.$("head"));
|
|
98
|
+
}
|
|
99
|
+
metaTag.attr("content", csp);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Replaces all sourced scripts with a single inline script that can be hashed
|
|
103
|
+
*/
|
|
104
|
+
refactorSourcedScriptsForHashBasedCsp() {
|
|
105
|
+
const scriptInfoList = this.$(CSP.SOURCED_SCRIPT_SELECTOR).map((_i, script) => {
|
|
106
|
+
const src = this.$(script).attr("src") ?? "";
|
|
107
|
+
const type = this.$(script).attr("type") ?? "";
|
|
108
|
+
this.$(script).remove();
|
|
109
|
+
return { src, type };
|
|
110
|
+
}).toArray().filter((info) => info.src);
|
|
111
|
+
const loaderScript = CSP.createLoaderScript(scriptInfoList);
|
|
112
|
+
if (!loaderScript) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const newScript = cheerio.load("<script>")("script");
|
|
116
|
+
newScript.text(loaderScript);
|
|
117
|
+
newScript.appendTo(this.$("body"));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns a list of hashes of all inline scripts found in the HTML document.
|
|
121
|
+
* @returns A list of sha-256 hashes of inline scripts.
|
|
122
|
+
*/
|
|
123
|
+
hashAllInlineScripts() {
|
|
124
|
+
return this.$(CSP.INLINE_SCRIPT_SELECTOR).map((_i, elem) => CSP.hashInlineScript(this.$(elem).html() ?? "")).get();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns JS code for dynamically loading sourced (external) scripts.
|
|
128
|
+
* @param scriptInfoList A list of objects containing src and type for scripts that should be loaded
|
|
129
|
+
* @returns JS code for loading scripts.
|
|
130
|
+
*/
|
|
131
|
+
static createLoaderScript(scriptInfoList) {
|
|
132
|
+
if (!scriptInfoList.length) {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
return `
|
|
136
|
+
var scripts = ${JSON.stringify(scriptInfoList)};
|
|
137
|
+
scripts.forEach(function(scriptInfo) {
|
|
138
|
+
var s = document.createElement('script');
|
|
139
|
+
s.src = scriptInfo.src;
|
|
140
|
+
if (scriptInfo.type) {
|
|
141
|
+
s.type = scriptInfo.type;
|
|
142
|
+
}
|
|
143
|
+
s.async = false; // preserve execution order.
|
|
144
|
+
document.body.appendChild(s);
|
|
145
|
+
});
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Calculates a CSP compatible hash of an inline script.
|
|
150
|
+
* @param scriptText Text between opening and closing script tag. Has to
|
|
151
|
+
* include whitespaces and newlines!
|
|
152
|
+
* @returns A sha-256 hash of the script.
|
|
153
|
+
*/
|
|
154
|
+
static hashInlineScript(scriptText) {
|
|
155
|
+
const hash = crypto.createHash(CSP.HASH_FUNCTION).update(scriptText, "utf-8").digest("base64");
|
|
156
|
+
return `'${CSP.HASH_FUNCTION}-${hash}'`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -64,7 +64,7 @@ const getNodeModulesRegEx = (modules) => modules.map(
|
|
|
64
64
|
const excludeNodeModulesExcept = (modules) => {
|
|
65
65
|
const moduleRegExps = getNodeModulesRegEx(modules);
|
|
66
66
|
return function(modulePath) {
|
|
67
|
-
if (
|
|
67
|
+
if (modulePath.includes("node_modules")) {
|
|
68
68
|
for (const moduleRegExp of moduleRegExps)
|
|
69
69
|
if (moduleRegExp.test(modulePath)) return false;
|
|
70
70
|
return true;
|
|
@@ -136,9 +136,9 @@ const getUserMonitoringFileName = () => {
|
|
|
136
136
|
);
|
|
137
137
|
if (!import_node_fs.default.existsSync(userMonLibPath)) return `${libName}.js`;
|
|
138
138
|
const distJSFiles = import_node_fs.default.readdirSync(userMonLibPath);
|
|
139
|
-
return distJSFiles.
|
|
140
|
-
(fName) =>
|
|
141
|
-
)
|
|
139
|
+
return distJSFiles.find(
|
|
140
|
+
(fName) => /emuiUserMonitoring+((?!chunk).)*\.js$/.exec(fName)
|
|
141
|
+
);
|
|
142
142
|
};
|
|
143
143
|
const getAppLoaderFileName = () => {
|
|
144
144
|
const libName = "emuiAppLoader";
|
|
@@ -148,9 +148,9 @@ const getAppLoaderFileName = () => {
|
|
|
148
148
|
);
|
|
149
149
|
if (!import_node_fs.default.existsSync(appLoaderLibPath)) return `${libName}.js`;
|
|
150
150
|
const distJSFiles = import_node_fs.default.readdirSync(appLoaderLibPath);
|
|
151
|
-
return distJSFiles.
|
|
152
|
-
(fName) =>
|
|
153
|
-
)
|
|
151
|
+
return distJSFiles.find(
|
|
152
|
+
(fName) => /emuiAppLoader+((?!chunk).)*\.js$/.exec(fName)
|
|
153
|
+
);
|
|
154
154
|
};
|
|
155
155
|
const getDiagnosticsFileName = () => {
|
|
156
156
|
const libName = "emuiDiagnostics";
|
|
@@ -160,9 +160,9 @@ const getDiagnosticsFileName = () => {
|
|
|
160
160
|
);
|
|
161
161
|
if (!import_node_fs.default.existsSync(libPath)) return `${libName}.js`;
|
|
162
162
|
const distJSFiles = import_node_fs.default.readdirSync(libPath);
|
|
163
|
-
return distJSFiles.
|
|
164
|
-
(fName) =>
|
|
165
|
-
)
|
|
163
|
+
return distJSFiles.find(
|
|
164
|
+
(fName) => /emuiDiagnostics+((?!chunk).)*\.js$/.exec(fName)
|
|
165
|
+
);
|
|
166
166
|
};
|
|
167
167
|
const getENCWLoaderFileName = () => {
|
|
168
168
|
const libName = "emuiEncwLoader";
|
|
@@ -172,13 +172,13 @@ const getENCWLoaderFileName = () => {
|
|
|
172
172
|
);
|
|
173
173
|
if (!import_node_fs.default.existsSync(appLoaderLibPath)) return `${libName}.js`;
|
|
174
174
|
const distJSFiles = import_node_fs.default.readdirSync(appLoaderLibPath);
|
|
175
|
-
return distJSFiles.
|
|
176
|
-
(fName) =>
|
|
177
|
-
)
|
|
175
|
+
return distJSFiles.find(
|
|
176
|
+
(fName) => /emuiEncwLoader+((?!chunk).)*\.js$/.exec(fName)
|
|
177
|
+
);
|
|
178
178
|
};
|
|
179
179
|
const getAppVersion = () => {
|
|
180
180
|
if (!process.env.APP_VERSION) return LATEST_VERSION;
|
|
181
|
-
const match =
|
|
181
|
+
const match = /^v?(\d+\.\d+)\..*$/.exec(process.env.APP_VERSION);
|
|
182
182
|
return match?.[1] ?? LATEST_VERSION;
|
|
183
183
|
};
|
|
184
184
|
const getPaths = (latestVersion = true) => {
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var interceptor_middleware_exports = {};
|
|
20
|
+
__export(interceptor_middleware_exports, {
|
|
21
|
+
addCSPNonceMiddleware: () => addCSPNonceMiddleware,
|
|
22
|
+
interceptorMiddleware: () => interceptorMiddleware
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(interceptor_middleware_exports);
|
|
25
|
+
const VALID_PARAMS = ["isInterceptable", "intercept", "afterSend"];
|
|
26
|
+
const validateParams = (methods) => {
|
|
27
|
+
Object.keys(methods).forEach((k) => {
|
|
28
|
+
if (!VALID_PARAMS.includes(k)) {
|
|
29
|
+
throw new Error(`${k} isn't a valid param (${VALID_PARAMS.join(", ")})`);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
if (!("isInterceptable" in methods)) {
|
|
33
|
+
throw new Error("isInterceptable is a required param (function)");
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const interceptorMiddleware = (fn) => (req, res, next) => {
|
|
37
|
+
const methods = fn(req, res);
|
|
38
|
+
validateParams(methods);
|
|
39
|
+
const originalEnd = res.end;
|
|
40
|
+
const originalWrite = res.write;
|
|
41
|
+
const chunks = [];
|
|
42
|
+
let isIntercepting;
|
|
43
|
+
let isFirstWrite = true;
|
|
44
|
+
function intercept(rawChunk, encoding) {
|
|
45
|
+
if (isFirstWrite) {
|
|
46
|
+
isFirstWrite = false;
|
|
47
|
+
isIntercepting = methods.isInterceptable();
|
|
48
|
+
}
|
|
49
|
+
if (isIntercepting) {
|
|
50
|
+
if (rawChunk) {
|
|
51
|
+
let tempChunk = rawChunk;
|
|
52
|
+
if (rawChunk !== null && !Buffer.isBuffer(tempChunk)) {
|
|
53
|
+
if (!encoding) {
|
|
54
|
+
tempChunk = Buffer.from(rawChunk);
|
|
55
|
+
} else {
|
|
56
|
+
tempChunk = Buffer.from(
|
|
57
|
+
rawChunk,
|
|
58
|
+
encoding
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
chunks.push(tempChunk);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return isIntercepting;
|
|
66
|
+
}
|
|
67
|
+
const newResWrite = (...args) => {
|
|
68
|
+
if (!intercept(args[0], args[1])) {
|
|
69
|
+
return originalWrite.apply(res, args);
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
res.write = newResWrite;
|
|
74
|
+
const afterSend = (oldBody, newBody) => {
|
|
75
|
+
if (typeof methods.afterSend === "function") {
|
|
76
|
+
process.nextTick(() => {
|
|
77
|
+
methods.afterSend?.(oldBody, newBody);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const newResEnd = (...args) => {
|
|
82
|
+
if (intercept(args[0], args[1])) {
|
|
83
|
+
isIntercepting = false;
|
|
84
|
+
const oldBody = Buffer.concat(chunks).toString("utf-8");
|
|
85
|
+
if (methods.intercept) {
|
|
86
|
+
if (typeof methods.intercept !== "function") {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"`send` must be a function with the body to be sent as the only param"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
res.removeHeader("Content-Length");
|
|
92
|
+
methods.intercept(oldBody, (newBody) => {
|
|
93
|
+
args[0] = newBody;
|
|
94
|
+
originalEnd.apply(res, args);
|
|
95
|
+
afterSend(oldBody, newBody);
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
afterSend(oldBody, oldBody);
|
|
99
|
+
originalEnd.apply(res, args);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
originalEnd.apply(res, args);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
res.end = newResEnd;
|
|
106
|
+
next();
|
|
107
|
+
};
|
|
108
|
+
const addCSPNonceMiddleware = (middlewares) => {
|
|
109
|
+
const index = middlewares.findIndex(
|
|
110
|
+
(middleware) => middleware.name === "webpack-dev-middleware"
|
|
111
|
+
);
|
|
112
|
+
middlewares.splice(index, 0, {
|
|
113
|
+
name: "csp-nonce-middleware",
|
|
114
|
+
middleware: interceptorMiddleware((_req, res) => ({
|
|
115
|
+
// Only HTML responses will be intercepted
|
|
116
|
+
isInterceptable() {
|
|
117
|
+
return (res.get("Content-Type") ?? "").includes("text/html");
|
|
118
|
+
},
|
|
119
|
+
// Appends a paragraph at the end of the response body
|
|
120
|
+
intercept(body, send) {
|
|
121
|
+
send(body.replace(/__CSP_NONCE__/g, res.locals.cspNonce));
|
|
122
|
+
}
|
|
123
|
+
}))
|
|
124
|
+
});
|
|
125
|
+
};
|
|
@@ -39,12 +39,15 @@ var import_circular_dependency_plugin = __toESM(require("circular-dependency-plu
|
|
|
39
39
|
var import_mini_css_extract_plugin = __toESM(require("mini-css-extract-plugin"));
|
|
40
40
|
var import_react_refresh_webpack_plugin = __toESM(require("@pmmmwh/react-refresh-webpack-plugin"));
|
|
41
41
|
var import_express_static_gzip = __toESM(require("express-static-gzip"));
|
|
42
|
+
var import_interceptor_middleware = require("./interceptor-middleware.js");
|
|
42
43
|
var import_middlewares = require("../server/middlewares.js");
|
|
43
44
|
var import_appRoutes = require("../server/appRoutes.js");
|
|
44
45
|
var import_helpers = require("./helpers.js");
|
|
45
46
|
var import_webpack_base_babel = require("./webpack.base.babel.js");
|
|
46
47
|
var import_utils = require("../server/utils.js");
|
|
47
48
|
var import_wsServer = require("../server/wsServer.js");
|
|
49
|
+
var import_cert = require("../server/cert.js");
|
|
50
|
+
var import_utils2 = require("../utils.js");
|
|
48
51
|
const import_meta = {};
|
|
49
52
|
const __filename = (0, import_node_url.fileURLToPath)(import_meta.url);
|
|
50
53
|
const {
|
|
@@ -57,6 +60,10 @@ const {
|
|
|
57
60
|
diagnosticsScriptPath,
|
|
58
61
|
encwLoaderScriptPath
|
|
59
62
|
} = (0, import_helpers.getPaths)();
|
|
63
|
+
const serverOptions = {
|
|
64
|
+
type: "https",
|
|
65
|
+
options: (0, import_cert.getCertOptions)()
|
|
66
|
+
};
|
|
60
67
|
const devConfig = {
|
|
61
68
|
mode: "development",
|
|
62
69
|
cache: {
|
|
@@ -100,7 +107,7 @@ const devConfig = {
|
|
|
100
107
|
// Add development plugins
|
|
101
108
|
plugins: [
|
|
102
109
|
new import_html_webpack_plugin.default({
|
|
103
|
-
inject: !(0, import_helpers.isAppLoaderEnabled)()
|
|
110
|
+
inject: !(0, import_helpers.isAppLoaderEnabled)() && process.env.CSP !== "true",
|
|
104
111
|
// Inject all files that are generated by webpack, e.g. bundle.js
|
|
105
112
|
template: !(0, import_helpers.isAppLoaderEnabled)() ? "app/index.html" : "app/index-app-loader.html",
|
|
106
113
|
emui: {
|
|
@@ -111,10 +118,14 @@ const devConfig = {
|
|
|
111
118
|
appLoaderScriptPath,
|
|
112
119
|
diagnosticsScriptPath,
|
|
113
120
|
encwLoaderScriptPath,
|
|
114
|
-
googleTagManager: (0, import_helpers.isGoogleTagManagerEnabled)()
|
|
121
|
+
googleTagManager: (0, import_helpers.isGoogleTagManagerEnabled)(),
|
|
122
|
+
csp: process.env.CSP === "true"
|
|
115
123
|
},
|
|
116
124
|
scriptLoading: "defer"
|
|
117
125
|
}),
|
|
126
|
+
// new CspPlugin(HtmlWebpackPlugin, {
|
|
127
|
+
// enableUnsafeEval: true,
|
|
128
|
+
// }),
|
|
118
129
|
new import_circular_dependency_plugin.default({
|
|
119
130
|
exclude: /a\.(js|ts|jsx|tsx)|node_modules/,
|
|
120
131
|
// exclude node_modules
|
|
@@ -147,11 +158,12 @@ const devConfig = {
|
|
|
147
158
|
hot: true,
|
|
148
159
|
open: [basePath],
|
|
149
160
|
port: process.env.PORT ?? "auto",
|
|
161
|
+
server: (0, import_utils2.isHttps)() ? serverOptions : {},
|
|
150
162
|
setupMiddlewares: (middlewares, devServer) => {
|
|
163
|
+
(0, import_interceptor_middleware.addCSPNonceMiddleware)(middlewares);
|
|
151
164
|
if (devServer.app) {
|
|
152
165
|
(0, import_middlewares.setupDefaultMiddlewares)(devServer.app);
|
|
153
|
-
(0, import_appRoutes.loadRoutes)(devServer.app).
|
|
154
|
-
}).catch((err) => {
|
|
166
|
+
(0, import_appRoutes.loadRoutes)(devServer.app).catch((err) => {
|
|
155
167
|
console.error(err);
|
|
156
168
|
});
|
|
157
169
|
const cdnRouter = (0, import_express_static_gzip.default)("cdn", {});
|
|
@@ -66,13 +66,11 @@ const plugins = [
|
|
|
66
66
|
new import_webpack.default.DefinePlugin({
|
|
67
67
|
APP_CONFIG: (0, import_utils.getAppConfig)()
|
|
68
68
|
}),
|
|
69
|
-
/* eslint-disable indent */
|
|
70
69
|
...copyPluginPatterns.length > 0 ? [
|
|
71
70
|
new import_copy_webpack_plugin.default({
|
|
72
71
|
patterns: copyPluginPatterns
|
|
73
72
|
})
|
|
74
73
|
] : [],
|
|
75
|
-
/* eslint-enable indent */
|
|
76
74
|
new import_webpack.default.optimize.LimitChunkCountPlugin({
|
|
77
75
|
maxChunks: 1
|
|
78
76
|
}),
|
|
@@ -74,7 +74,9 @@ const prodConfig = {
|
|
|
74
74
|
minimizer: [
|
|
75
75
|
new import_esbuild_loader.EsbuildPlugin({
|
|
76
76
|
target: (0, import_browserslist_to_esbuild.default)(),
|
|
77
|
-
css: true
|
|
77
|
+
css: true,
|
|
78
|
+
pure: ["console.log", "console.warn"],
|
|
79
|
+
drop: ["debugger"]
|
|
78
80
|
})
|
|
79
81
|
],
|
|
80
82
|
nodeEnv: "production",
|
|
@@ -57,10 +57,13 @@ const getProdConfig = ({ latestVersion = true } = {}) => {
|
|
|
57
57
|
},
|
|
58
58
|
optimization: {
|
|
59
59
|
moduleIds: "deterministic",
|
|
60
|
+
// realContentHash: false,
|
|
60
61
|
minimizer: [
|
|
61
62
|
new import_esbuild_loader.EsbuildPlugin({
|
|
62
63
|
target: (0, import_browserslist_to_esbuild.default)(),
|
|
63
|
-
css: true
|
|
64
|
+
css: true,
|
|
65
|
+
pure: ["console.log", "console.warn"],
|
|
66
|
+
drop: ["debugger"]
|
|
64
67
|
})
|
|
65
68
|
],
|
|
66
69
|
runtimeChunk: true,
|
|
@@ -74,7 +77,8 @@ const getProdConfig = ({ latestVersion = true } = {}) => {
|
|
|
74
77
|
},
|
|
75
78
|
vendors: {
|
|
76
79
|
name: "vendors",
|
|
77
|
-
test: /[\\/]node_modules[\\/]
|
|
80
|
+
test: /[\\/]node_modules[\\/]/,
|
|
81
|
+
enforce: true
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
}
|
|
@@ -111,7 +115,7 @@ const {
|
|
|
111
115
|
basePath
|
|
112
116
|
} = (0, import_helpers.getPaths)();
|
|
113
117
|
const htmlWebpackPlugin = new import_html_webpack_plugin.default({
|
|
114
|
-
inject: !(0, import_helpers.isAppLoaderEnabled)()
|
|
118
|
+
inject: !(0, import_helpers.isAppLoaderEnabled)() && process.env.CSP !== "true",
|
|
115
119
|
template: !(0, import_helpers.isAppLoaderEnabled)() ? "app/index.html" : "app/index-app-loader.html",
|
|
116
120
|
minify: {
|
|
117
121
|
removeComments: true,
|
|
@@ -133,10 +137,13 @@ const htmlWebpackPlugin = new import_html_webpack_plugin.default({
|
|
|
133
137
|
appLoaderScriptPath,
|
|
134
138
|
diagnosticsScriptPath,
|
|
135
139
|
encwLoaderScriptPath,
|
|
136
|
-
googleTagManager: (0, import_helpers.isGoogleTagManagerEnabled)()
|
|
140
|
+
googleTagManager: (0, import_helpers.isGoogleTagManagerEnabled)(),
|
|
141
|
+
csp: process.env.CSP === "true"
|
|
137
142
|
},
|
|
138
143
|
scriptLoading: "defer"
|
|
139
144
|
});
|
|
140
145
|
const config = (0, import_webpack_base_babel.baseConfig)(getProdConfig());
|
|
141
|
-
if (config.plugins)
|
|
146
|
+
if (config.plugins) {
|
|
147
|
+
config.plugins.push(htmlWebpackPlugin);
|
|
148
|
+
}
|
|
142
149
|
var webpack_prod_babel_default = config;
|
|
@@ -41,7 +41,7 @@ const IS_APP = (0, import_utils.isApp)();
|
|
|
41
41
|
const CWD = process.cwd();
|
|
42
42
|
const getAdditionalPlugins = () => [
|
|
43
43
|
new import_webpack.default.EnvironmentPlugin({
|
|
44
|
-
IS_APP,
|
|
44
|
+
IS_APP: IS_APP ? "true" : "false",
|
|
45
45
|
CWD
|
|
46
46
|
}),
|
|
47
47
|
new import_mini_css_extract_plugin.default({
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
const noncePlugin = () => ({
|
|
3
|
+
name: "add-nonce-attr",
|
|
4
|
+
enforce: "post",
|
|
5
|
+
transformIndexHtml(html) {
|
|
6
|
+
return html.replace(new RegExp("<script", "g"), `<script nonce="__CSP_NONCE__"`).replace(new RegExp("<link", "g"), `<link nonce="__CSP_NONCE__"`);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
var vite_config_default = defineConfig({
|
|
10
|
+
plugins: [noncePlugin()],
|
|
11
|
+
build: {
|
|
12
|
+
emptyOutDir: true,
|
|
13
|
+
sourcemap: true,
|
|
14
|
+
rollupOptions: {
|
|
15
|
+
output: {
|
|
16
|
+
chunkFileNames: "assets/[name].[hash].js",
|
|
17
|
+
entryFileNames: "assets/[name].[hash].js",
|
|
18
|
+
assetFileNames: "assets/[name].[hash][extname]"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
export {
|
|
24
|
+
vite_config_default as default
|
|
25
|
+
};
|
package/dist/esm/cli.js
CHANGED
|
@@ -16,10 +16,11 @@ import { storybookCmd } from "./commands/storybook.js";
|
|
|
16
16
|
import { vitestCmd } from "./commands/vitest.js";
|
|
17
17
|
import { versionCmd } from "./commands/version.js";
|
|
18
18
|
import { tscheckCmd } from "./commands/tscheck.js";
|
|
19
|
+
import { buildCDNCmd } from "./commands/buildcdn.js";
|
|
19
20
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
21
|
envConfig();
|
|
21
22
|
process.env.PATH += path.delimiter + path.join(__dirname, "..", "node_modules", ".bin");
|
|
22
|
-
(async () => {
|
|
23
|
+
void (async () => {
|
|
23
24
|
await yargs(hideBin(process.argv)).command(buildCmd).help().argv;
|
|
24
25
|
await yargs(hideBin(process.argv)).command(packCmd).help().argv;
|
|
25
26
|
await yargs(hideBin(process.argv)).command(startCmd).help().argv;
|
|
@@ -31,5 +32,6 @@ process.env.PATH += path.delimiter + path.join(__dirname, "..", "node_modules",
|
|
|
31
32
|
await yargs(hideBin(process.argv)).command(vitestCmd).help().argv;
|
|
32
33
|
await yargs(hideBin(process.argv)).command(versionCmd).help().argv;
|
|
33
34
|
await yargs(hideBin(process.argv)).command(tscheckCmd).help().argv;
|
|
35
|
+
await yargs(hideBin(process.argv)).command(buildCDNCmd).help().argv;
|
|
34
36
|
await notifyUpdates();
|
|
35
37
|
})();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import fg from "fast-glob";
|
|
4
|
+
import yargs from "yargs";
|
|
5
|
+
import { exec, logInfo, logError, logSuccess } from "./utils.js";
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const buildCDN = async () => {
|
|
8
|
+
const files = await fg(["src/**/*.html"]);
|
|
9
|
+
await Promise.all(
|
|
10
|
+
files.map(async (file) => {
|
|
11
|
+
const srcDir = path.dirname(file);
|
|
12
|
+
const sitePath = srcDir.replace("src/", "");
|
|
13
|
+
const outDir = path.join(process.cwd(), "public", sitePath);
|
|
14
|
+
await exec(
|
|
15
|
+
`vite build -c ${path.resolve(
|
|
16
|
+
__dirname,
|
|
17
|
+
"../build/vite.config.js"
|
|
18
|
+
)} ${srcDir} --outDir ${outDir} --base ${path.join(
|
|
19
|
+
process.env.BASE_PATH ?? "",
|
|
20
|
+
sitePath
|
|
21
|
+
)}`
|
|
22
|
+
);
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
const buildCDNCmd = {
|
|
27
|
+
handler: async () => {
|
|
28
|
+
try {
|
|
29
|
+
logInfo("CDN Build in progress...");
|
|
30
|
+
await buildCDN();
|
|
31
|
+
logSuccess("CDN Build completed");
|
|
32
|
+
} catch (err) {
|
|
33
|
+
logError("Build failed", err);
|
|
34
|
+
yargs().exit(-1, err);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
command: "buildCDN",
|
|
38
|
+
describe: "builds web application for CDN",
|
|
39
|
+
builder: (yargsRef) => yargsRef.options({}).help()
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
buildCDNCmd
|
|
43
|
+
};
|
|
@@ -30,7 +30,7 @@ const lintJS = async (args) => {
|
|
|
30
30
|
const fixIssues = args.fix ? "--fix" : "";
|
|
31
31
|
const debugFlags = args.debug ? "--env-info --debug" : "";
|
|
32
32
|
await exec(
|
|
33
|
-
`eslint ${!getCIEnv() ? "--color" : "--no-color"} ${fixIssues} ${debugFlags} .`
|
|
33
|
+
`eslint --flag unstable_ts_config ${!getCIEnv() ? "--color" : "--no-color"} ${fixIssues} ${debugFlags} .`
|
|
34
34
|
);
|
|
35
35
|
};
|
|
36
36
|
const cmdArgs = {
|
|
@@ -17,7 +17,14 @@ const validateTypescript = async (files = []) => {
|
|
|
17
17
|
skipLibCheck: true
|
|
18
18
|
},
|
|
19
19
|
files,
|
|
20
|
-
include: [
|
|
20
|
+
include: [
|
|
21
|
+
"app",
|
|
22
|
+
"lib",
|
|
23
|
+
"lib/**/*.json",
|
|
24
|
+
"lib/**/*.d.ts",
|
|
25
|
+
"app/**/*.json",
|
|
26
|
+
"app/**/*.d.ts"
|
|
27
|
+
]
|
|
21
28
|
};
|
|
22
29
|
fs.writeFileSync(tmpTsconfigPath, JSON.stringify(tmpTsconfig, null, 2));
|
|
23
30
|
const tscPath = path.resolve(
|