@melt-js/libs-core 2026.11.15 → 2026.11.16-2

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 (85) hide show
  1. package/README.md +73 -16
  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 +141 -0
  16. package/dist/cdn/vendor.umd.cjs +16 -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.d.mts +1 -0
  21. package/dist/demo/browser.mjs +1 -0
  22. package/dist/demo/browser.mjs.gz +0 -0
  23. package/dist/demo/clipboard.d.mts +6 -0
  24. package/dist/demo/clipboard.mjs +1 -0
  25. package/{src → dist}/demo/docs.d.mts +3 -0
  26. package/dist/demo/docs.mjs +1 -0
  27. package/dist/demo/docs.mjs.gz +0 -0
  28. package/{src → dist}/demo/download.d.mts +10 -2
  29. package/dist/demo/download.mjs +1 -0
  30. package/dist/demo/download.mjs.gz +0 -0
  31. package/dist/demo/fullscreen.mjs +1 -0
  32. package/dist/demo/highlight.d.mts +2 -0
  33. package/dist/demo/highlight.mjs +1 -0
  34. package/dist/demo/index.d.mts +10 -0
  35. package/dist/demo/index.mjs +1 -0
  36. package/dist/demo/model.mjs +1 -0
  37. package/dist/demo/remote-debug.d.mts +9 -0
  38. package/dist/demo/remote-debug.mjs +1 -0
  39. package/{src → dist}/demo/runtime.mjs +92 -104
  40. package/dist/demo/split-pane.d.mts +8 -0
  41. package/dist/demo/split-pane.mjs +1 -0
  42. package/dist/demo/standalone.d.mts +12 -0
  43. package/dist/demo/standalone.mjs +1 -0
  44. package/dist/demo/standalone.mjs.gz +0 -0
  45. package/dist/demo/tabs.d.mts +15 -0
  46. package/dist/demo/tabs.mjs +1 -0
  47. package/{src/index.ts → dist/index.d.ts} +1 -1
  48. package/dist/loading.mjs +1 -0
  49. package/dist/loading.mjs.gz +0 -0
  50. package/dist/remote-address.cjs +2 -0
  51. package/{src → dist}/remote.d.mts +20 -2
  52. package/dist/remote.mjs +1 -0
  53. package/dist/remote.mjs.gz +0 -0
  54. package/dist/vendor/hel-runtime.mjs +16 -0
  55. package/dist/vendor/hel-runtime.mjs.gz +0 -0
  56. package/package.json +41 -25
  57. package/scripts/browser-formats.mjs +357 -0
  58. package/scripts/build-browser.mjs +59 -13
  59. package/scripts/build-protected-esm.mjs +54 -0
  60. package/scripts/cdn-runtime.cjs +30 -0
  61. package/scripts/check-tdz.mjs +327 -324
  62. package/scripts/client-build-security.cjs +48 -0
  63. package/scripts/comps-bundle-obfuscation.cjs +269 -262
  64. package/scripts/comps-obfuscator-options.cjs +7 -1
  65. package/scripts/hel-build-paths.cjs +49 -48
  66. package/scripts/obfuscator-split-strings.cjs +22 -0
  67. package/scripts/package-artifacts.mjs +206 -0
  68. package/scripts/package-env.cjs +156 -193
  69. package/scripts/publish-stage.mjs +50 -42
  70. package/scripts/webpack-bundle-obfuscation.cjs +125 -121
  71. package/demo/index.js +0 -1
  72. package/dist/hel-deployment.json +0 -8
  73. package/src/browser.d.mts +0 -2
  74. package/src/browser.mjs +0 -3
  75. package/src/demo/docs.mjs +0 -75
  76. package/src/demo/download.mjs +0 -118
  77. package/src/demo/fullscreen.mjs +0 -80
  78. package/src/demo/index.d.mts +0 -4
  79. package/src/demo/index.mjs +0 -4
  80. package/src/demo/model.mjs +0 -203
  81. package/src/remote.mjs +0 -286
  82. package/tsconfig.json +0 -13
  83. /package/{src → dist}/demo/fullscreen.d.mts +0 -0
  84. /package/{src → dist}/demo/model.d.mts +0 -0
  85. /package/{src → scripts}/remote-address.cjs +0 -0
@@ -32,7 +32,13 @@ module.exports = {
32
32
  stringArrayEncoding: ['base64'],
33
33
  // Keep base64 image data URLs intact, including those embedded in CSS url(...).
34
34
  reservedStrings: ['data:image/[^;,\\s]+(?:;[^;,]*)*;base64,'],
35
- splitStrings: false,
35
+ // Split medium/long literals into 5-char chunks before they land in the string array.
36
+ // Keeps string-array entries short, so the plaintext cannot be read back by grepping the bundle.
37
+ // import()/require() specifiers and asset URLs stay whole via ignoreImports + reservedStrings.
38
+ // This is the comps/demo/tpl granularity; libs packages resolve to 10 in obfuscator-split-strings.cjs
39
+ // because their public ESM/UMD is downloaded by hosts and a 5-char split grows it by 40%-85%.
40
+ splitStrings: true,
41
+ splitStringsChunkLength: 5,
36
42
  numbersToExpressions: false,
37
43
  unicodeEscapeSequence: false,
38
44
  sourceMap: false,
@@ -1,48 +1,49 @@
1
- const fs = require('node:fs')
2
- const path = require('node:path')
3
-
4
- function normalizeAssetUrl(value) {
5
- if (typeof value !== 'string') return value
6
- const origin = value.match(/^(?:https?:)?\/\/[^/\\]+/i)?.[0] || ''
7
- return origin + value.slice(origin.length).replace(/\\/g, '/').replace(/\/{2,}/g, '/')
8
- }
9
-
10
- function normalizeSrcMap(srcMap) {
11
- for (const [key, value] of Object.entries(srcMap)) {
12
- if (key.endsWith('List') && Array.isArray(value)) {
13
- if (key === 'headAssetList' || key === 'bodyAssetList') {
14
- for (const asset of value) {
15
- for (const attr of ['src', 'href']) {
16
- if (asset.attrs?.[attr]) asset.attrs[attr] = normalizeAssetUrl(asset.attrs[attr])
17
- }
18
- }
19
- } else srcMap[key] = [...new Set(value.map(normalizeAssetUrl))]
20
- } else if (typeof value === 'string' && /(?:Path|Src|Index)$/.test(key)) srcMap[key] = normalizeAssetUrl(value)
21
- }
22
- // hel-dev-utils trims the trailing slash, turning the root homePage into an empty string.
23
- if (!srcMap.webDirPath && srcMap.htmlIndexSrc === '/index.html') srcMap.webDirPath = '/'
24
- }
25
-
26
- // Accept the caller's directly declared hel-dev-utils dependency; no cross-package lookup.
27
- module.exports = function withHelBuildPaths(helDevUtils) {
28
- const adapted = { ...helDevUtils }
29
- for (const factory of ['createVueSubApp', 'createReactSubApp', 'createLibSubApp']) {
30
- adapted[factory] = (...args) => {
31
- const appInfo = helDevUtils[factory](...args)
32
- if (process.env.HEL_RELATIVE_PATH === '1' && process.env.HEL_APP_HOME_PAGE === '/' && appInfo.homePage === '/') {
33
- appInfo.getPublicPathOrUrl = () => '/'
34
- }
35
- return appInfo
36
- }
37
- }
38
- adapted.extractHelMetaJson = async options => {
39
- if (process.env.HEL_RELATIVE_PATH !== '1') return helDevUtils.extractHelMetaJson(options)
40
- const meta = await helDevUtils.extractHelMetaJson({ ...options, writeMetaJsonToDist: false })
41
- normalizeSrcMap(meta.version.src_map)
42
- if (options.writeMetaJsonToDist !== false) {
43
- fs.writeFileSync(path.join(options.buildDirFullPath, 'hel-meta.json'), JSON.stringify(meta, null, 2))
44
- }
45
- return meta
46
- }
47
- return adapted
48
- }
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+
4
+ function normalizeAssetUrl(value) {
5
+ if (typeof value !== 'string') return value
6
+ const origin = value.match(/^(?:https?:)?\/\/[^/\\]+/i)?.[0] || ''
7
+ return origin + value.slice(origin.length).replace(/\\/g, '/').replace(/\/{2,}/g, '/')
8
+ }
9
+
10
+ function normalizeSrcMap(srcMap) {
11
+ for (const [key, value] of Object.entries(srcMap)) {
12
+ if (key.endsWith('List') && Array.isArray(value)) {
13
+ if (key === 'headAssetList' || key === 'bodyAssetList') {
14
+ for (const asset of value) {
15
+ for (const attr of ['src', 'href']) {
16
+ if (asset.attrs?.[attr]) asset.attrs[attr] = normalizeAssetUrl(asset.attrs[attr])
17
+ }
18
+ }
19
+ } else srcMap[key] = [...new Set(value.map(normalizeAssetUrl))]
20
+ } else if (typeof value === 'string' && /(?:Path|Src|Index)$/.test(key)) srcMap[key] = normalizeAssetUrl(value)
21
+ }
22
+ // hel-dev-utils trims the trailing slash, turning the root homePage into an empty string.
23
+ if (!srcMap.webDirPath && srcMap.htmlIndexSrc === '/index.html') srcMap.webDirPath = '/'
24
+ }
25
+
26
+ // Accept the caller's directly declared hel-dev-utils dependency; no cross-package lookup.
27
+ module.exports = function withHelBuildPaths(helDevUtils) {
28
+ const adapted = { ...helDevUtils }
29
+ for (const factory of ['createVueSubApp', 'createReactSubApp', 'createLibSubApp']) {
30
+ adapted[factory] = (...args) => {
31
+ const appInfo = helDevUtils[factory](...args)
32
+ if (process.env.HEL_RELATIVE_PATH === '1' && process.env.HEL_APP_HOME_PAGE === '/' && appInfo.homePage === '/') {
33
+ appInfo.getPublicPathOrUrl = () => '/'
34
+ }
35
+ return appInfo
36
+ }
37
+ }
38
+ adapted.extractHelMetaJson = async options => {
39
+ // Windows separators also occur in absolute CDN builds. Normalize both
40
+ // modes so unpkg receives the same valid URLs as the static deploy rewriter.
41
+ const meta = await helDevUtils.extractHelMetaJson({ ...options, writeMetaJsonToDist: false })
42
+ normalizeSrcMap(meta.version.src_map)
43
+ if (options.writeMetaJsonToDist !== false) {
44
+ fs.writeFileSync(path.join(options.buildDirFullPath, 'hel-meta.json'), JSON.stringify(meta, null, 2))
45
+ }
46
+ return meta
47
+ }
48
+ return adapted
49
+ }
@@ -0,0 +1,22 @@
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+
4
+ // `splitStringsChunkLength` granularity, resolved per package family.
5
+ // libs packages publish shared ESM/UMD straight to hosts, so a coarse 10-character split keeps
6
+ // the public bundle close to the unsplit size; comps/demo/tpl keep the finer 5-character split.
7
+ const LIBS_CHUNK_LENGTH = 10
8
+ const DEFAULT_CHUNK_LENGTH = 5
9
+
10
+ function packageNameOf(root) {
11
+ try {
12
+ return JSON.parse(fs.readFileSync(path.join(path.resolve(root), 'package.json'), 'utf8')).name || ''
13
+ } catch {
14
+ return ''
15
+ }
16
+ }
17
+
18
+ function splitStringsChunkLength(root) {
19
+ return /^@melt-js\/libs-/.test(packageNameOf(root)) ? LIBS_CHUNK_LENGTH : DEFAULT_CHUNK_LENGTH
20
+ }
21
+
22
+ module.exports = { splitStringsChunkLength, packageNameOf }
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env node
2
+ // Package-local publication artifacts. Never searches the workspace or builds siblings.
3
+ import fs from 'node:fs'
4
+ import path from 'node:path'
5
+ import { createRequire } from 'node:module'
6
+ import { pathToFileURL, fileURLToPath } from 'node:url'
7
+ import { spawnSync } from 'node:child_process'
8
+ import { gzipSync } from 'node:zlib'
9
+ import ts from 'typescript'
10
+ import { build } from 'esbuild'
11
+ import { buildBrowserFormats } from './browser-formats.mjs'
12
+ import { buildProtectedEsm } from './build-protected-esm.mjs'
13
+ import bundleObfuscation from './comps-bundle-obfuscation.cjs'
14
+
15
+ const slash = value => value.replaceAll('\\', '/')
16
+ const walk = dir => fs.existsSync(dir) ? fs.readdirSync(dir, { withFileTypes: true }).flatMap(entry => entry.isDirectory() && entry.name !== 'node_modules' ? walk(path.join(dir, entry.name)) : entry.isFile() ? [path.join(dir, entry.name)] : []) : []
17
+ const write = (file, content) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, content) }
18
+ const copy = (from, to) => { fs.mkdirSync(path.dirname(to), { recursive: true }); fs.copyFileSync(from, to) }
19
+
20
+ export function cleanDeclarationStyles(directory) {
21
+ for (const file of walk(directory).filter(file => /\.d\.(ts|mts)$/.test(file))) {
22
+ const text = fs.readFileSync(file, 'utf8')
23
+ fs.writeFileSync(file, text.replace(/^\s*import\s*['"][^'"\n]+\.(?:css|scss|less)['"];?\s*$/gm, ''))
24
+ }
25
+ }
26
+
27
+ export async function buildPackageArtifacts(root = process.cwd()) {
28
+ root = path.resolve(root)
29
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
30
+ const config = pkg.releaseArtifacts
31
+ if (!config) throw new Error(`${pkg.name}: 缺少 releaseArtifacts 配置`)
32
+ const src = path.join(root, 'src')
33
+ const out = path.resolve(root, config.outDir)
34
+ if (!out.startsWith(root + path.sep)) throw new Error('产物必须位于包目录内')
35
+ const localRequire = createRequire(path.join(root, 'package.json'))
36
+
37
+ if (config.mode === 'declarations') { cleanDeclarationStyles(out); await buildBrowserFormats(root); return }
38
+
39
+ if (config.mode === 'adapter') {
40
+ // Preserve old artifacts outside the publish tree, including stale maps/files.
41
+ const history = path.join(root, '.tmp/release-artifact-history', Date.now() + '-' + process.pid)
42
+ for (const file of walk(out)) {
43
+ const archived = path.join(history, path.relative(out, file))
44
+ fs.mkdirSync(path.dirname(archived), { recursive: true })
45
+ fs.renameSync(file, archived)
46
+ }
47
+ for (const file of walk(src)) {
48
+ const dest = path.join(out, path.relative(src, file))
49
+ if (/\.mjs$/.test(file)) await buildProtectedEsm({ entryPoints: [file], outfile: dest, minify: true, target: 'es2019', format: 'esm' }, { root })
50
+ else if (/\.d\.(ts|mts)$/.test(file)) copy(file, dest)
51
+ }
52
+ await buildBrowserFormats(root)
53
+ return
54
+ }
55
+
56
+ const typeOut = path.join(out, 'types')
57
+ const previousOutputs = config.mode === 'library' ? [out] : ['types', 'assets', 'subpaths'].map(dir => path.join(out, dir))
58
+ if (previousOutputs.some(dir => walk(dir).length)) {
59
+ const history = path.join(root, '.tmp/release-artifact-history', Date.now() + '-' + process.pid)
60
+ fs.mkdirSync(history, { recursive: true })
61
+ // File-by-file moves also work when a Windows editor holds the directory open.
62
+ for (const file of previousOutputs.flatMap(walk)) {
63
+ const archived = path.join(history, path.relative(out, file))
64
+ fs.mkdirSync(path.dirname(archived), { recursive: true })
65
+ fs.renameSync(file, archived)
66
+ }
67
+ }
68
+ const sourceConfig = path.join(root, 'tsconfig.json')
69
+ const parsed = fs.existsSync(sourceConfig) ? ts.getParsedCommandLineOfConfigFile(sourceConfig, {}, { ...ts.sys, onUnRecoverableConfigFileDiagnostic: diagnostic => { throw new Error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')) } }) : { options: {} }
70
+ const compilerOptions = {
71
+ ...parsed.options, rootDir: src, outDir: typeOut, noEmit: false, declaration: true,
72
+ emitDeclarationOnly: true, declarationMap: false, sourceMap: false, noCheck: true,
73
+ composite: false, incremental: false, allowJs: true, skipLibCheck: true, preserveSymlinks: true,
74
+ }
75
+ delete compilerOptions.tsBuildInfoFile
76
+ const allDeclarations = walk(src).filter(file => /\.d\.(ts|mts)$/.test(file))
77
+ const entryTypes = String(pkg.types || '').replace(/^\.?\/?hel_proxy_es\/types\//, 'src/')
78
+ const sourceTypes = path.resolve(root, entryTypes)
79
+ const typeEntry = fs.existsSync(sourceTypes) ? sourceTypes : sourceTypes.replace(/\.d\.ts$/, '.ts')
80
+ const inputs = config.mode === 'library'
81
+ ? [...Object.values(config.entries).map(file => path.resolve(root, file)), ...allDeclarations]
82
+ : config.declarationDir ? [] : [...(pkg.types ? [typeEntry] : []), ...Object.values(config.proxies || {}).map(entry => path.resolve(root, entry.source)), ...allDeclarations]
83
+ if (config.vue && inputs.length) {
84
+ const tempConfig = path.join(root, '.tmp/release-tsconfig.json')
85
+ write(tempConfig, JSON.stringify({ extends: fs.existsSync(sourceConfig) ? sourceConfig : undefined,
86
+ compilerOptions: { rootDir: src, outDir: typeOut, noEmit: false, declaration: true, emitDeclarationOnly: true,
87
+ declarationMap: false, sourceMap: false, noCheck: true, composite: false, incremental: false, allowJs: true, preserveSymlinks: true },
88
+ files: inputs.map(slash), include: [],
89
+ exclude: ['**/node_modules/**'],
90
+ }, null, 2))
91
+ const require = createRequire(import.meta.url)
92
+ const result = spawnSync(process.execPath, [require.resolve('vue-tsc/bin/vue-tsc.js'), '-p', tempConfig], { cwd: root, stdio: 'inherit' })
93
+ if (result.status !== 0) throw new Error(`${pkg.name}: 声明生成失败`)
94
+ } else if (inputs.length) {
95
+ const program = ts.createProgram(inputs, compilerOptions)
96
+ const result = program.emit()
97
+ if (result.emitSkipped || result.diagnostics.length) throw new Error(ts.formatDiagnosticsWithColorAndContext(result.diagnostics, { getCurrentDirectory: () => root, getCanonicalFileName: x => x, getNewLine: () => '\n' }))
98
+ }
99
+ // Declaration inputs are not copied by tsc. Preserve their dependency closure.
100
+ if (!config.declarationDir) for (const file of allDeclarations) copy(file, path.join(typeOut, path.relative(src, file)))
101
+ if (config.declarationDir) {
102
+ for (const file of walk(path.join(root, config.declarationDir))) copy(file, path.join(typeOut, path.relative(path.join(root, config.declarationDir), file)))
103
+ }
104
+ cleanDeclarationStyles(typeOut)
105
+ // Resolve package-local aliases in emitted declarations to the published tree.
106
+ for (const file of walk(typeOut).filter(file => /\.d\.(ts|mts)$/.test(file))) {
107
+ const relative = path.relative(typeOut, file).replace(/\.d\.ts$/, '.ts')
108
+ const source = path.join(src, relative)
109
+ const text = fs.readFileSync(file, 'utf8').replace(/(['"])([^'"\n]+)\1/g, (match, quote, specifier) => {
110
+ if (specifier.startsWith('.') || (!specifier.startsWith('#') && !specifier.startsWith('@/') && !specifier.startsWith(pkg.name + '/'))) return match
111
+ const resolved = ts.resolveModuleName(specifier, source, parsed.options, ts.sys).resolvedModule?.resolvedFileName
112
+ if (!resolved || !resolved.startsWith(src + path.sep)) {
113
+ if (specifier.startsWith(pkg.name + '/')) return match
114
+ throw new Error(`${file}: 无法解析本包类型别名 ${specifier}`)
115
+ }
116
+ let target = slash(path.relative(path.dirname(file), path.join(typeOut, path.relative(src, resolved))))
117
+ target = target.replace(/(?:\.d)?\.tsx?$/, '.js')
118
+ return quote + (target.startsWith('.') ? target : './' + target) + quote
119
+ })
120
+ const portable = text.replace(/(['"])(\.[^'"\n]+)\1/g, (match, quote, specifier) => {
121
+ if (/\.(?:[cm]?js|[cm]?ts|tsx|vue|json)$/.test(specifier)) return match
122
+ const target = path.resolve(path.dirname(file), specifier)
123
+ if (fs.existsSync(target + '.d.ts')) return quote + specifier + '.js' + quote
124
+ if (fs.existsSync(path.join(target, 'index.d.ts'))) return quote + specifier.replace(/\/$/, '') + '/index.js' + quote
125
+ return match
126
+ })
127
+ fs.writeFileSync(file, portable)
128
+ }
129
+ // Schemas and style resources are data, never a reason to ship implementation sources.
130
+ for (const file of walk(src).filter(file => config.mode === 'library' || config.styles
131
+ ? /\.(json|css|scss|less|svg|woff2?|ttf|png|jpe?g|gif)$/.test(file)
132
+ : /propsSchema\.json$/.test(file))) {
133
+ copy(file, path.join(out, 'assets', path.relative(src, file)))
134
+ if (/\.json$/.test(file)) copy(file, path.join(typeOut, path.relative(src, file)))
135
+ }
136
+
137
+ if (config.mode === 'library') {
138
+ const entries = config.entries
139
+ if (config.vite) {
140
+ const { build: viteBuild } = await import(pathToFileURL(localRequire.resolve('vite')).href)
141
+ const { default: vue } = await import(pathToFileURL(localRequire.resolve('@vitejs/plugin-vue')).href)
142
+ const plugins = [vue()]
143
+ if (config.tailwind) {
144
+ const { default: tailwind } = await import(pathToFileURL(localRequire.resolve('@tailwindcss/vite')).href)
145
+ plugins.push(tailwind())
146
+ }
147
+ const pluginModule = await import(pathToFileURL(localRequire.resolve('vite-plugin-bundle-obfuscator')).href)
148
+ const finalObfuscator = pluginModule.default.default || pluginModule.default
149
+ plugins.push(...bundleObfuscation.bundleObfuscationPlugins({ root, obfuscatorPlugin: finalObfuscator,
150
+ enabled: process.env.HEL_OBFUSCATE !== '0', library: true, rolldown: config.rolldown === true }), bundleObfuscation.gzipPlugin())
151
+ await viteBuild({ configFile: false, root, plugins, esbuild: { legalComments: 'none' }, css: { postcss: { plugins: [] } },
152
+ build: { outDir: out, emptyOutDir: false, minify: true, sourcemap: false, target: 'es2020',
153
+ lib: { entry: Object.fromEntries(Object.entries(entries).map(([key, value]) => [key, path.join(root, value)])), formats: ['es'], fileName: (_format, name) => name + '.js' },
154
+ rollupOptions: { external: id => id !== pkg.name && !id.startsWith(pkg.name + '/') && !id.startsWith('.') && !path.isAbsolute(id) && !id.startsWith('\0') },
155
+ },
156
+ })
157
+ // Native ESM loads extracted CSS through <link>; bundlers keep the CSS side effect.
158
+ if (entries.design) {
159
+ const design = path.join(out, 'design.js')
160
+ const browserDesign = path.join(out, 'design.browser.js')
161
+ copy(design, browserDesign)
162
+ fs.appendFileSync(design, `\nimport './${pkg.name.split('/').at(-1)}.css'\n`)
163
+ for (const file of [design, browserDesign]) {
164
+ const content = fs.readFileSync(file)
165
+ if (process.env.HEL_GZIP !== '0' && (content.length >= 10240 || fs.existsSync(file + '.gz'))) write(file + '.gz', gzipSync(content))
166
+ }
167
+ }
168
+ } else {
169
+ await buildProtectedEsm({ absWorkingDir: root, entryPoints: entries, outdir: out, bundle: true, packages: 'external', define: { 'import.meta.env.DEV': 'false', 'import.meta.env.PROD': 'true' }, format: 'esm', platform: 'neutral', target: 'es2022', minify: true }, { root })
170
+ }
171
+ if (config.bin) {
172
+ await build({ absWorkingDir: root, entryPoints: [config.bin], outfile: path.join(out, 'cli.mjs'), bundle: true, packages: 'external', platform: 'node', format: 'esm', target: 'node22', minify: true, legalComments: 'none', banner: { js: '#!/usr/bin/env node' } })
173
+ }
174
+ }
175
+ if (config.resolver) {
176
+ await build({ absWorkingDir: root, entryPoints: [config.resolver], outfile: path.join(out, 'resolver.js'), bundle: true, packages: 'external', platform: 'node', format: 'esm', minify: true, legalComments: 'none',
177
+ plugins: [{ name: 'package-name', setup(builder) { builder.onLoad({ filter: /resolver\.ts$/ }, args => ({ loader: 'ts', contents: fs.readFileSync(args.path, 'utf8').replace("createRequire(import.meta.url)('./package.json').name", JSON.stringify(pkg.name)) })) } }],
178
+ })
179
+ const program = ts.createProgram([path.join(root, config.resolver)], { ...compilerOptions, rootDir: root, outDir: path.join(typeOut, '__tools') })
180
+ if (program.emit().emitSkipped) throw new Error('resolver 声明生成失败')
181
+ }
182
+ if (config.proxies) {
183
+ const program = ts.createProgram(inputs, { ...parsed.options, noCheck: true })
184
+ const checker = program.getTypeChecker()
185
+ for (const [name, entry] of Object.entries(config.proxies)) {
186
+ const source = program.getSourceFile(path.join(root, entry.source))
187
+ const symbol = source && checker.getSymbolAtLocation(source)
188
+ if (!symbol) throw new Error(`${pkg.name}: 无法读取子路径 ${entry.source}`)
189
+ const names = checker.getExportsOfModule(symbol).filter(symbol => {
190
+ const declarations = symbol.declarations || []
191
+ if (declarations.every(d => ts.isInterfaceDeclaration(d) || ts.isTypeAliasDeclaration(d) || (ts.isExportSpecifier(d) && (d.isTypeOnly || d.parent.parent.isTypeOnly)))) return false
192
+ const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
193
+ return Boolean(target.flags & ts.SymbolFlags.Value)
194
+ }).map(symbol => symbol.name)
195
+ const body = [`import lib from '../entry.js'`, `const namespace = lib[${JSON.stringify(entry.namespace)}]`]
196
+ for (const key of names) body.push(key === 'default'
197
+ ? `export default namespace["default"]`
198
+ : `export const ${key} = namespace[${JSON.stringify(key)}]`)
199
+ write(path.join(out, 'subpaths', name + '.js'), body.join('\n') + '\n')
200
+ }
201
+ }
202
+ await buildBrowserFormats(root)
203
+ console.log(`[package-artifacts] ${pkg.name}: ${out}`)
204
+ }
205
+
206
+ if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) await buildPackageArtifacts()