@melt-js/libs-core 2026.11.15 → 2026.11.16-1
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/README.md +45 -4
- package/dist/browser.d.mts +3 -0
- package/dist/browser.mjs +1 -50
- package/dist/browser.mjs.gz +0 -0
- package/dist/cdn/browser.umd.cjs +2 -0
- package/dist/cdn/browser.umd.cjs.gz +0 -0
- package/dist/cdn/demo-browser.umd.cjs +2 -0
- package/dist/cdn/demo-browser.umd.cjs.gz +0 -0
- package/dist/cdn/demo.umd.cjs +2 -0
- package/dist/cdn/demo.umd.cjs.gz +0 -0
- package/dist/cdn/example-esm.html +1 -0
- package/dist/cdn/example-umd.html +1 -0
- package/dist/cdn/index.umd.cjs +2 -0
- package/dist/cdn/index.umd.cjs.gz +0 -0
- package/dist/cdn/manifest.json +129 -0
- package/dist/cdn/vendor.umd.cjs +50 -0
- package/dist/cdn/vendor.umd.cjs.gz +0 -0
- package/dist/cdn.d.mts +3 -0
- package/dist/cdn.mjs +1 -0
- package/dist/demo/browser.mjs +1 -0
- package/dist/demo/browser.mjs.gz +0 -0
- package/dist/demo/clipboard.d.mts +6 -0
- package/dist/demo/clipboard.mjs +1 -0
- package/{src → dist}/demo/docs.d.mts +28 -25
- package/dist/demo/docs.mjs +1 -0
- package/dist/demo/docs.mjs.gz +0 -0
- package/{src → dist}/demo/download.d.mts +7 -2
- package/dist/demo/download.mjs +1 -0
- package/dist/demo/download.mjs.gz +0 -0
- package/{src → dist}/demo/fullscreen.d.mts +8 -8
- package/dist/demo/fullscreen.mjs +1 -0
- package/dist/demo/index.d.mts +9 -0
- package/dist/demo/index.mjs +1 -0
- package/{src → dist}/demo/model.d.mts +12 -12
- package/dist/demo/model.mjs +1 -0
- package/dist/demo/remote-debug.d.mts +11 -0
- package/dist/demo/remote-debug.mjs +1 -0
- package/{src → dist}/demo/runtime.mjs +92 -104
- package/dist/demo/split-pane.d.mts +8 -0
- package/dist/demo/split-pane.mjs +1 -0
- package/dist/demo/standalone.d.mts +9 -0
- package/dist/demo/standalone.mjs +1 -0
- package/dist/demo/tabs.d.mts +15 -0
- package/dist/demo/tabs.mjs +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -1
- package/dist/loading.mjs +1 -0
- package/dist/remote-address.cjs +2 -0
- package/{src → dist}/remote.d.mts +110 -96
- package/dist/remote.mjs +1 -0
- package/dist/remote.mjs.gz +0 -0
- package/dist/vendor/hel-runtime.mjs +50 -0
- package/dist/vendor/hel-runtime.mjs.gz +0 -0
- package/package.json +41 -25
- package/scripts/browser-formats.mjs +355 -0
- package/scripts/build-browser.mjs +59 -13
- package/scripts/build-protected-esm.mjs +51 -0
- package/scripts/cdn-runtime.cjs +30 -0
- package/scripts/check-tdz.mjs +327 -324
- package/scripts/client-build-security.cjs +48 -0
- package/scripts/component-events.mjs +57 -57
- package/scripts/comps-bundle-obfuscation.cjs +266 -262
- package/scripts/hel-build-paths.cjs +49 -48
- package/scripts/package-artifacts.mjs +206 -0
- package/scripts/package-env.cjs +200 -193
- package/scripts/publish-stage.mjs +50 -42
- package/{src → scripts}/remote-address.cjs +30 -30
- package/scripts/vdoc-parser/NOTICE.md +13 -13
- package/scripts/vdoc-parser/constants.mjs +3 -3
- package/scripts/vdoc-parser/index.d.mts +34 -34
- package/scripts/vdoc-parser/index.mjs +2 -2
- package/scripts/vdoc-parser/parsers/index.mjs +14 -14
- package/scripts/vdoc-parser/parsers/parseCode.mjs +42 -42
- package/scripts/vdoc-parser/parsers/parseCommentBlock.mjs +9 -9
- package/scripts/vdoc-parser/parsers/parseComponentOptions.mjs +12 -12
- package/scripts/vdoc-parser/parsers/parseDefaultValue.mjs +57 -57
- package/scripts/vdoc-parser/parsers/parseDefineProps.mjs +33 -33
- package/scripts/vdoc-parser/parsers/parseExport.mjs +93 -93
- package/scripts/vdoc-parser/parsers/parseFile.mjs +22 -22
- package/scripts/vdoc-parser/parsers/parseFileSync.mjs +22 -22
- package/scripts/vdoc-parser/parsers/parsePropType.mjs +32 -32
- package/scripts/vdoc-parser/parsers/parseProps.mjs +90 -90
- package/scripts/vdoc-parser/parsers/parseSetupScript.mjs +14 -14
- package/scripts/vdoc-parser/parsers/parseSfc.mjs +21 -21
- package/scripts/vdoc-parser/parsers/parseTSTypeLiteral.mjs +48 -48
- package/scripts/vdoc-parser/parsers/parseTypes.mjs +53 -53
- package/scripts/vdoc-parser/parsers/parseTypesFile.mjs +22 -22
- package/scripts/vdoc-parser/parsers/parseTypesFileSync.mjs +22 -22
- package/scripts/vdoc-parser/resolvers/index.mjs +2 -2
- package/scripts/vdoc-parser/resolvers/resolveSpreadElements.mjs +51 -51
- package/scripts/vdoc-parser/utils.mjs +52 -52
- package/scripts/webpack-bundle-obfuscation.cjs +123 -121
- package/demo/index.js +0 -1
- package/dist/hel-deployment.json +0 -8
- package/src/browser.d.mts +0 -2
- package/src/browser.mjs +0 -3
- package/src/demo/docs.mjs +0 -75
- package/src/demo/download.mjs +0 -118
- package/src/demo/fullscreen.mjs +0 -80
- package/src/demo/index.d.mts +0 -4
- package/src/demo/index.mjs +0 -4
- package/src/demo/model.mjs +0 -203
- package/src/remote.mjs +0 -286
- package/tsconfig.json +0 -13
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { extname } from 'node:path';
|
|
4
|
-
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
-
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
-
import { parseTypes } from './parseTypes.mjs';
|
|
7
|
-
export async function parseTypesFile(filePath, options) {
|
|
8
|
-
if (!legalExtsReg.test(filePath)) {
|
|
9
|
-
return Promise.reject(new Error(`[parseTypesFile] Unexcept file extension: ${extname(filePath)}`));
|
|
10
|
-
}
|
|
11
|
-
const source = await readFile(filePath, 'utf8');
|
|
12
|
-
if (vueExtReg.test(filePath)) {
|
|
13
|
-
const script = parseSfc(source);
|
|
14
|
-
if (script?.lang !== 'ts') {
|
|
15
|
-
return Promise.reject(new Error(`[parseTypesFile] script lang should be 'ts' in vue file`));
|
|
16
|
-
}
|
|
17
|
-
if (script) {
|
|
18
|
-
return parseTypes(script.content, options);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return parseTypes(source, options);
|
|
22
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { extname } from 'node:path';
|
|
4
|
+
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
+
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
+
import { parseTypes } from './parseTypes.mjs';
|
|
7
|
+
export async function parseTypesFile(filePath, options) {
|
|
8
|
+
if (!legalExtsReg.test(filePath)) {
|
|
9
|
+
return Promise.reject(new Error(`[parseTypesFile] Unexcept file extension: ${extname(filePath)}`));
|
|
10
|
+
}
|
|
11
|
+
const source = await readFile(filePath, 'utf8');
|
|
12
|
+
if (vueExtReg.test(filePath)) {
|
|
13
|
+
const script = parseSfc(source);
|
|
14
|
+
if (script?.lang !== 'ts') {
|
|
15
|
+
return Promise.reject(new Error(`[parseTypesFile] script lang should be 'ts' in vue file`));
|
|
16
|
+
}
|
|
17
|
+
if (script) {
|
|
18
|
+
return parseTypes(script.content, options);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return parseTypes(source, options);
|
|
22
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { extname } from 'node:path';
|
|
4
|
-
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
-
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
-
import { parseTypes } from './parseTypes.mjs';
|
|
7
|
-
export function parseTypesFileSync(filePath, options) {
|
|
8
|
-
if (!legalExtsReg.test(filePath)) {
|
|
9
|
-
throw new Error(`[parseTypesFileSync] Unexcept file extension: ${extname(filePath)}`);
|
|
10
|
-
}
|
|
11
|
-
const source = readFileSync(filePath, 'utf8');
|
|
12
|
-
if (vueExtReg.test(filePath)) {
|
|
13
|
-
const script = parseSfc(source);
|
|
14
|
-
if (script?.lang !== 'ts') {
|
|
15
|
-
throw new Error(`[parseTypesFileSync] script lang should be 'ts' in vue file`);
|
|
16
|
-
}
|
|
17
|
-
if (script) {
|
|
18
|
-
return parseTypes(script.content, options);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return parseTypes(source, options);
|
|
22
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { extname } from 'node:path';
|
|
4
|
+
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
+
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
+
import { parseTypes } from './parseTypes.mjs';
|
|
7
|
+
export function parseTypesFileSync(filePath, options) {
|
|
8
|
+
if (!legalExtsReg.test(filePath)) {
|
|
9
|
+
throw new Error(`[parseTypesFileSync] Unexcept file extension: ${extname(filePath)}`);
|
|
10
|
+
}
|
|
11
|
+
const source = readFileSync(filePath, 'utf8');
|
|
12
|
+
if (vueExtReg.test(filePath)) {
|
|
13
|
+
const script = parseSfc(source);
|
|
14
|
+
if (script?.lang !== 'ts') {
|
|
15
|
+
throw new Error(`[parseTypesFileSync] script lang should be 'ts' in vue file`);
|
|
16
|
+
}
|
|
17
|
+
if (script) {
|
|
18
|
+
return parseTypes(script.content, options);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return parseTypes(source, options);
|
|
22
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
export { resolveSpreadElements } from './resolveSpreadElements.mjs';
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
export { resolveSpreadElements } from './resolveSpreadElements.mjs';
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { isIdentifier, isExportNamedDeclaration, isVariableDeclaration, isObjectExpression, isCallExpression, isArrowFunctionExpression, } from '@babel/types';
|
|
3
|
-
export function resolveSpreadElements(spreadElements, statements) {
|
|
4
|
-
const inits = [];
|
|
5
|
-
if (!spreadElements.length) {
|
|
6
|
-
return inits;
|
|
7
|
-
}
|
|
8
|
-
const spreadNames = [];
|
|
9
|
-
const spreadCalleeNames = [];
|
|
10
|
-
for (const el of spreadElements) {
|
|
11
|
-
if (isIdentifier(el.argument)) {
|
|
12
|
-
spreadNames.push(el.argument.name);
|
|
13
|
-
}
|
|
14
|
-
else if (isCallExpression(el.argument) && isIdentifier(el.argument.callee)) {
|
|
15
|
-
spreadCalleeNames.push(el.argument.callee.name);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
statements.forEach(statement => {
|
|
19
|
-
if (isExportNamedDeclaration(statement) && isVariableDeclaration(statement.declaration)) {
|
|
20
|
-
if (isVariableDeclaration(statement.declaration)) {
|
|
21
|
-
for (const d of statement.declaration.declarations) {
|
|
22
|
-
if (isIdentifier(d.id)) {
|
|
23
|
-
if (spreadNames.includes(d.id.name) && isObjectExpression(d.init)) {
|
|
24
|
-
inits.push(d.init);
|
|
25
|
-
}
|
|
26
|
-
else if (spreadCalleeNames.includes(d.id.name)
|
|
27
|
-
&& isArrowFunctionExpression(d.init)
|
|
28
|
-
&& isObjectExpression(d.init.body)) {
|
|
29
|
-
inits.push(d.init.body);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (isVariableDeclaration(statement)) {
|
|
36
|
-
for (const d of statement.declarations) {
|
|
37
|
-
if (isIdentifier(d.id)) {
|
|
38
|
-
if (spreadNames.includes(d.id.name) && isObjectExpression(d.init)) {
|
|
39
|
-
inits.push(d.init);
|
|
40
|
-
}
|
|
41
|
-
else if (spreadCalleeNames.includes(d.id.name)
|
|
42
|
-
&& isArrowFunctionExpression(d.init)
|
|
43
|
-
&& isObjectExpression(d.init.body)) {
|
|
44
|
-
inits.push(d.init.body);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return inits;
|
|
51
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { isIdentifier, isExportNamedDeclaration, isVariableDeclaration, isObjectExpression, isCallExpression, isArrowFunctionExpression, } from '@babel/types';
|
|
3
|
+
export function resolveSpreadElements(spreadElements, statements) {
|
|
4
|
+
const inits = [];
|
|
5
|
+
if (!spreadElements.length) {
|
|
6
|
+
return inits;
|
|
7
|
+
}
|
|
8
|
+
const spreadNames = [];
|
|
9
|
+
const spreadCalleeNames = [];
|
|
10
|
+
for (const el of spreadElements) {
|
|
11
|
+
if (isIdentifier(el.argument)) {
|
|
12
|
+
spreadNames.push(el.argument.name);
|
|
13
|
+
}
|
|
14
|
+
else if (isCallExpression(el.argument) && isIdentifier(el.argument.callee)) {
|
|
15
|
+
spreadCalleeNames.push(el.argument.callee.name);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
statements.forEach(statement => {
|
|
19
|
+
if (isExportNamedDeclaration(statement) && isVariableDeclaration(statement.declaration)) {
|
|
20
|
+
if (isVariableDeclaration(statement.declaration)) {
|
|
21
|
+
for (const d of statement.declaration.declarations) {
|
|
22
|
+
if (isIdentifier(d.id)) {
|
|
23
|
+
if (spreadNames.includes(d.id.name) && isObjectExpression(d.init)) {
|
|
24
|
+
inits.push(d.init);
|
|
25
|
+
}
|
|
26
|
+
else if (spreadCalleeNames.includes(d.id.name)
|
|
27
|
+
&& isArrowFunctionExpression(d.init)
|
|
28
|
+
&& isObjectExpression(d.init.body)) {
|
|
29
|
+
inits.push(d.init.body);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if (isVariableDeclaration(statement)) {
|
|
36
|
+
for (const d of statement.declarations) {
|
|
37
|
+
if (isIdentifier(d.id)) {
|
|
38
|
+
if (spreadNames.includes(d.id.name) && isObjectExpression(d.init)) {
|
|
39
|
+
inits.push(d.init);
|
|
40
|
+
}
|
|
41
|
+
else if (spreadCalleeNames.includes(d.id.name)
|
|
42
|
+
&& isArrowFunctionExpression(d.init)
|
|
43
|
+
&& isObjectExpression(d.init.body)) {
|
|
44
|
+
inits.push(d.init.body);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return inits;
|
|
51
|
+
}
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { isCallExpression, isIdentifier, isObjectProperty, isNode, isObjectExpression, } from '@babel/types';
|
|
3
|
-
export function getStatementExportType(type) {
|
|
4
|
-
return type === 'named'
|
|
5
|
-
? 'ExportNamedDeclaration'
|
|
6
|
-
: 'ExportDefaultDeclaration';
|
|
7
|
-
}
|
|
8
|
-
export function getExportDeclaration(statements, statementExportType) {
|
|
9
|
-
return statements.filter(s => s.type === statementExportType);
|
|
10
|
-
}
|
|
11
|
-
export function getCallExpressionArguments(callExpression, calleeName) {
|
|
12
|
-
if (!isNode(callExpression) || !isCallExpression(callExpression))
|
|
13
|
-
return [];
|
|
14
|
-
if (calleeName) {
|
|
15
|
-
return isIdentifier(callExpression.callee) && callExpression.callee.name === calleeName
|
|
16
|
-
? callExpression.arguments
|
|
17
|
-
: [];
|
|
18
|
-
}
|
|
19
|
-
return isIdentifier(callExpression.callee)
|
|
20
|
-
? callExpression.arguments
|
|
21
|
-
: [];
|
|
22
|
-
}
|
|
23
|
-
export function getComponentOptions(declarations) {
|
|
24
|
-
let args;
|
|
25
|
-
for (const d of declarations) {
|
|
26
|
-
if (isCallExpression(d.init)) {
|
|
27
|
-
args = getCallExpressionArguments(d.init);
|
|
28
|
-
}
|
|
29
|
-
else if (isObjectExpression(d.init)) {
|
|
30
|
-
args = [d.init];
|
|
31
|
-
}
|
|
32
|
-
if (args?.length) {
|
|
33
|
-
return args[0];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function getPropertyByExpression(expression, propName) {
|
|
38
|
-
if (!expression)
|
|
39
|
-
return null;
|
|
40
|
-
return expression.properties
|
|
41
|
-
.find(p => isObjectProperty(p)
|
|
42
|
-
&& isIdentifier(p.key)
|
|
43
|
-
&& p.key.name === propName);
|
|
44
|
-
}
|
|
45
|
-
export function lowerFirst(str) {
|
|
46
|
-
if (!str)
|
|
47
|
-
return '';
|
|
48
|
-
return `${str[0].toLowerCase()}${str.slice(1)}`;
|
|
49
|
-
}
|
|
50
|
-
export function isEventProp(name) {
|
|
51
|
-
return /^on[A-Z][a-z]+/.test(name);
|
|
52
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { isCallExpression, isIdentifier, isObjectProperty, isNode, isObjectExpression, } from '@babel/types';
|
|
3
|
+
export function getStatementExportType(type) {
|
|
4
|
+
return type === 'named'
|
|
5
|
+
? 'ExportNamedDeclaration'
|
|
6
|
+
: 'ExportDefaultDeclaration';
|
|
7
|
+
}
|
|
8
|
+
export function getExportDeclaration(statements, statementExportType) {
|
|
9
|
+
return statements.filter(s => s.type === statementExportType);
|
|
10
|
+
}
|
|
11
|
+
export function getCallExpressionArguments(callExpression, calleeName) {
|
|
12
|
+
if (!isNode(callExpression) || !isCallExpression(callExpression))
|
|
13
|
+
return [];
|
|
14
|
+
if (calleeName) {
|
|
15
|
+
return isIdentifier(callExpression.callee) && callExpression.callee.name === calleeName
|
|
16
|
+
? callExpression.arguments
|
|
17
|
+
: [];
|
|
18
|
+
}
|
|
19
|
+
return isIdentifier(callExpression.callee)
|
|
20
|
+
? callExpression.arguments
|
|
21
|
+
: [];
|
|
22
|
+
}
|
|
23
|
+
export function getComponentOptions(declarations) {
|
|
24
|
+
let args;
|
|
25
|
+
for (const d of declarations) {
|
|
26
|
+
if (isCallExpression(d.init)) {
|
|
27
|
+
args = getCallExpressionArguments(d.init);
|
|
28
|
+
}
|
|
29
|
+
else if (isObjectExpression(d.init)) {
|
|
30
|
+
args = [d.init];
|
|
31
|
+
}
|
|
32
|
+
if (args?.length) {
|
|
33
|
+
return args[0];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function getPropertyByExpression(expression, propName) {
|
|
38
|
+
if (!expression)
|
|
39
|
+
return null;
|
|
40
|
+
return expression.properties
|
|
41
|
+
.find(p => isObjectProperty(p)
|
|
42
|
+
&& isIdentifier(p.key)
|
|
43
|
+
&& p.key.name === propName);
|
|
44
|
+
}
|
|
45
|
+
export function lowerFirst(str) {
|
|
46
|
+
if (!str)
|
|
47
|
+
return '';
|
|
48
|
+
return `${str[0].toLowerCase()}${str.slice(1)}`;
|
|
49
|
+
}
|
|
50
|
+
export function isEventProp(name) {
|
|
51
|
+
return /^on[A-Z][a-z]+/.test(name);
|
|
52
|
+
}
|
|
@@ -1,121 +1,123 @@
|
|
|
1
|
-
const { createHash } = require('node:crypto')
|
|
2
|
-
const { createModuleClassifier } = require('./comps-bundle-obfuscation.cjs')
|
|
3
|
-
const defaults = require('./comps-obfuscator-options.cjs')
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
report.
|
|
42
|
-
report.
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
facade
|
|
59
|
-
|
|
60
|
-
proxy
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
report.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
facade
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
config
|
|
116
|
-
|
|
117
|
-
config.
|
|
118
|
-
config.plugins.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
const { createHash } = require('node:crypto')
|
|
2
|
+
const { createModuleClassifier } = require('./comps-bundle-obfuscation.cjs')
|
|
3
|
+
const defaults = require('./comps-obfuscator-options.cjs')
|
|
4
|
+
const { applyWebpackClientSecurity } = require('./client-build-security.cjs')
|
|
5
|
+
const hash = source => createHash('sha256').update(source).digest('hex')
|
|
6
|
+
const excluded = /(?:^|\/)(?:vendor|runtime)(?:[-.\/]|$)/
|
|
7
|
+
|
|
8
|
+
function webpackBundlePolicy({ root, Obfuscator, enabled = true }) {
|
|
9
|
+
const classify = createModuleClassifier(root)
|
|
10
|
+
const settings = { ...defaults, seed: 1, renameGlobals: false, renameProperties: false, sourceMap: false }
|
|
11
|
+
const reports = []
|
|
12
|
+
const reportChunks = new Map()
|
|
13
|
+
const plugin = new Obfuscator(settings, ['**/vendor*.js', 'vendor*.js', '**/runtime*.js', 'runtime*.js'])
|
|
14
|
+
const guard = {
|
|
15
|
+
name: 'hel:webpack-bundle-boundaries', api: { reports, classify },
|
|
16
|
+
apply(compiler) {
|
|
17
|
+
const inspect = compilation => {
|
|
18
|
+
reports.length = 0
|
|
19
|
+
reportChunks.clear()
|
|
20
|
+
for (const chunk of compilation.chunks) {
|
|
21
|
+
const modules = compilation.chunkGraph ? [...compilation.chunkGraph.getChunkModulesIterable(chunk)] : [...chunk.modulesIterable]
|
|
22
|
+
const entries = modules.flatMap(module => module.modules ? [...module.modules] : [module])
|
|
23
|
+
.filter(module => module.resource && !module.externalType)
|
|
24
|
+
.map(module => ({ id: module.resource.replaceAll('\\', '/'), kind: classify(module.resource) }))
|
|
25
|
+
const protectedModules = entries.filter(module => ['own', 'related'].includes(module.kind)).length
|
|
26
|
+
const thirdPartyModules = entries.filter(module => module.kind === 'thirdParty').length
|
|
27
|
+
for (const filename of chunk.files) {
|
|
28
|
+
if (!filename.endsWith('.js')) continue
|
|
29
|
+
if (protectedModules && thirdPartyModules) throw new Error('Mixed business/vendor chunk: ' + filename)
|
|
30
|
+
if (thirdPartyModules && !excluded.test(filename)) throw new Error('Vendor chunk not excluded: ' + filename)
|
|
31
|
+
if (protectedModules && excluded.test(filename)) throw new Error('Protected module in excluded chunk: ' + filename)
|
|
32
|
+
const report = { fileName: filename, modules: entries, protectedModules, thirdPartyModules, excluded: excluded.test(filename), beforeHash: hash(compilation.assets[filename].source()) }
|
|
33
|
+
reports.push(report)
|
|
34
|
+
reportChunks.set(report, chunk)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const verify = compilation => {
|
|
39
|
+
for (const report of reports) {
|
|
40
|
+
const code = compilation.assets[report.fileName].source().toString()
|
|
41
|
+
report.afterHash = hash(code)
|
|
42
|
+
report.identifiers = (code.match(/\b_0x[\da-f]+\b/g) || []).length
|
|
43
|
+
report.obfuscated = report.beforeHash !== report.afterHash
|
|
44
|
+
if (report.excluded && report.obfuscated) throw new Error('Excluded vendor changed: ' + report.fileName)
|
|
45
|
+
if (enabled && report.protectedModules && (!report.obfuscated || !report.identifiers)) throw new Error('Final business chunk is not obfuscated: ' + report.fileName)
|
|
46
|
+
console.log(`[hel:webpack-bundle] ${report.fileName}: protected=${report.protectedModules}, third-party=${report.thirdPartyModules}, _0x=${report.identifiers}`)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// webpack-obfuscator v2 uses emit; v3 uses processAssets DEV_TOOLING.
|
|
50
|
+
// Compression plugins can also use DEV_TOOLING, so pin obfuscation directly
|
|
51
|
+
// after minimizers and before transfer compression, independent of array order.
|
|
52
|
+
const modern = Boolean(compiler.webpack?.Compilation)
|
|
53
|
+
if (modern) {
|
|
54
|
+
compiler.hooks.compilation.tap('hel:webpack-bundle-boundaries', compilation => {
|
|
55
|
+
const stage = compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1
|
|
56
|
+
compilation.hooks.processAssets.tap({ name: 'hel:webpack-before', stage }, () => inspect(compilation))
|
|
57
|
+
if (enabled) {
|
|
58
|
+
const facade = Object.create(compiler)
|
|
59
|
+
facade.hooks = { ...compiler.hooks, compilation: { tap(_name, callback) {
|
|
60
|
+
const proxy = Object.create(compilation)
|
|
61
|
+
proxy.hooks = { ...compilation.hooks, processAssets: Object.fromEntries(
|
|
62
|
+
['tap', 'tapPromise', 'tapAsync'].map(method => [method, (options, handler) => {
|
|
63
|
+
compilation.hooks.processAssets[method]({ ...(typeof options === 'string' ? { name: options } : options), stage: stage + 1 }, handler)
|
|
64
|
+
}]),
|
|
65
|
+
) }
|
|
66
|
+
callback(proxy)
|
|
67
|
+
} } }
|
|
68
|
+
plugin.apply(facade)
|
|
69
|
+
}
|
|
70
|
+
compilation.hooks.processAssets.tap({ name: 'hel:webpack-after', stage: stage + 2 }, () => verify(compilation))
|
|
71
|
+
// RealContentHashPlugin can rename assets and rewrite runtime URLs later.
|
|
72
|
+
// Report final filenames/bytes after all processAssets stages, not stale pre-hash names.
|
|
73
|
+
compilation.hooks.afterProcessAssets.tap('hel:webpack-final-bytes', () => {
|
|
74
|
+
for (const report of reports) {
|
|
75
|
+
const files = [...reportChunks.get(report).files].filter(file => file.endsWith('.js'))
|
|
76
|
+
if (files.length !== 1) throw new Error('Expected one JS asset per audited chunk')
|
|
77
|
+
report.fileName = files[0]
|
|
78
|
+
const code = compilation.assets[report.fileName].source().toString()
|
|
79
|
+
report.afterHash = hash(code)
|
|
80
|
+
report.identifiers = (code.match(/\b_0x[\da-f]+\b/g) || []).length
|
|
81
|
+
if (enabled && report.protectedModules && !report.identifiers) throw new Error('Final business identifiers were lost: ' + report.fileName)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
} else {
|
|
86
|
+
compiler.hooks.emit.tap({ name: 'hel:webpack-before', stage: -200 }, inspect)
|
|
87
|
+
if (enabled) {
|
|
88
|
+
const facade = Object.create(compiler)
|
|
89
|
+
facade.hooks = { ...compiler.hooks, emit: { tap(name, callback) {
|
|
90
|
+
compiler.hooks.emit.tap({ name: typeof name === 'string' ? name : name.name, stage: -190 }, callback)
|
|
91
|
+
} } }
|
|
92
|
+
plugin.apply(facade)
|
|
93
|
+
}
|
|
94
|
+
compiler.hooks.emit.tap({ name: 'hel:webpack-after', stage: -180 }, verify)
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
plugin: guard,
|
|
100
|
+
optimization: {
|
|
101
|
+
// Do not let a concatenated module obscure business/vendor provenance.
|
|
102
|
+
concatenateModules: false,
|
|
103
|
+
runtimeChunk: { name: 'runtime' },
|
|
104
|
+
splitChunks: { chunks: 'all', minSize: 0, cacheGroups: {
|
|
105
|
+
default: false, defaultVendors: false, vendors: false,
|
|
106
|
+
helVendor: { name: 'vendor', chunks: 'all', enforce: true, priority: 100,
|
|
107
|
+
test: module => Boolean(module.resource) && classify(module.resource) === 'thirdParty' },
|
|
108
|
+
} },
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function applyWebpackBundlePolicy(config, { root, Obfuscator, enabled = process.env.HEL_OBFUSCATE !== '0' }) {
|
|
114
|
+
if (process.env.NODE_ENV !== 'production' && config.mode !== 'production') return config
|
|
115
|
+
applyWebpackClientSecurity(config)
|
|
116
|
+
const policy = webpackBundlePolicy({ root, Obfuscator, enabled })
|
|
117
|
+
config.devtool = false
|
|
118
|
+
config.plugins = (config.plugins || []).filter(plugin => plugin?.constructor?.name !== 'LimitChunkCountPlugin')
|
|
119
|
+
config.optimization = { ...config.optimization, ...policy.optimization }
|
|
120
|
+
config.plugins.push(policy.plugin)
|
|
121
|
+
return config
|
|
122
|
+
}
|
|
123
|
+
module.exports = { webpackBundlePolicy, applyWebpackBundlePolicy }
|
package/demo/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../src/demo/index.mjs'
|
package/dist/hel-deployment.json
DELETED
package/src/browser.d.mts
DELETED
package/src/browser.mjs
DELETED