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