@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
@@ -1,193 +1,156 @@
1
- const fs = require('node:fs')
2
- const path = require('node:path')
3
- const { createRequire } = require('node:module')
4
- const dotenv = require('dotenv')
5
- const { expand } = require('dotenv-expand')
6
- const { packageRef, packageUrl } = require('../src/remote-address.cjs')
7
-
8
- const PUBLIC_ENV_KEYS = ['SFTP_PUBLIC_URL', 'GITHUB_PUBLIC_URL', 'UNPKG_PUBLIC_URL']
9
- const WORKSPACE_ENV_KEYS = [...PUBLIC_ENV_KEYS, 'HEL_RELATIVE_PATH']
10
- const TARGETS = ['local', 'sftp', 'github', 'unpkg']
11
- const trim = value => String(value || '').trim().replace(/\/+$/, '')
12
-
13
- function readEnvFile(file) {
14
- return fs.existsSync(file) ? dotenv.parse(fs.readFileSync(file)) : {}
15
- }
16
-
17
- function readPackageFiles(cwd, mode) {
18
- // The root orchestrator copies only public bases here. Never read a parent directory.
19
- return Object.assign({}, ...[
20
- '.env.defaults', '.env.workspace.local', '.env', '.env.local', `.env.${mode}`, `.env.${mode}.local`,
21
- ].map(name => readEnvFile(path.join(cwd, name))))
22
- }
23
-
24
- function remoteSlots(env) {
25
- return Object.keys(env).filter(key => /^[A-Z][A-Z\d_]*_PACKAGE$/.test(key) && !/^(?:DEPLOY_|VITE_|VUE_APP_|REACT_APP_|HEL_)/.test(key))
26
- .map(key => key.slice(0, -8))
27
- }
28
-
29
- function resolveTarget(value, mode) {
30
- const target = String(value || 'auto').toLowerCase()
31
- if (target === 'auto') return ['development', 'mock'].includes(mode) ? 'local' : 'unpkg'
32
- if (!TARGETS.includes(target)) throw new Error(`[hel-env] Unknown remote target: ${target}`)
33
- return target
34
- }
35
-
36
- // Resolve metadata from an installed dependency, never from a sibling/source checkout.
37
- function installedVersion(cwd, packageName) {
38
- const fromPackage = createRequire(path.join(cwd, 'package.json'))
39
- try {
40
- return JSON.parse(fs.readFileSync(fromPackage.resolve(packageName + '/package.json'), 'utf8')).version
41
- } catch (error) {
42
- if (!['ERR_PACKAGE_PATH_NOT_EXPORTED', 'MODULE_NOT_FOUND'].includes(error.code)) throw error
43
- }
44
- let directory = path.dirname(fromPackage.resolve(packageName))
45
- for (;;) {
46
- const manifest = path.join(directory, 'package.json')
47
- if (fs.existsSync(manifest)) {
48
- const pkg = JSON.parse(fs.readFileSync(manifest, 'utf8'))
49
- if (pkg.name === packageName) return pkg.version
50
- }
51
- const parent = path.dirname(directory)
52
- if (parent === directory) throw new Error(`[hel-env] Cannot resolve installed version of ${packageName}; set the dependency's VERSION explicitly`)
53
- directory = parent
54
- }
55
- }
56
-
57
- function resolveRemoteUrl(env, slot, target) {
58
- const packageName = env[`${slot}_PACKAGE`]
59
- if (target === 'local') {
60
- const url = trim(env[`${slot}_LOCAL_URL`])
61
- if (!url) throw new Error(`[hel-env] ${slot}_LOCAL_URL is required for local development`)
62
- return url
63
- }
64
- const base = trim(env[`${target.toUpperCase()}_PUBLIC_URL`])
65
- let version = env[`DEPLOY_${slot}_VERSION`] || env[`${slot}_VERSION`] || 'latest'
66
- if (target === 'unpkg' && version === 'installed') version = installedVersion(env.HEL_ENV_PACKAGE || process.cwd(), packageName)
67
- const output = env[`${slot}_OUTPUT_DIR`] || 'hel_dist'
68
- const entry = env[`${slot}_ENTRY`] || 'hel-meta.json'
69
- try {
70
- const parsed = packageRef(packageName)
71
- parsed.version = version
72
- const url = packageUrl(parsed, {
73
- type: target === 'sftp' ? 'custom' : target, base,
74
- projectName: target === 'unpkg' ? undefined : env[`${slot}_PROJECT`],
75
- // Static deployments update project directories; unpkg versions are npm versions.
76
- versioned: target === 'unpkg',
77
- })
78
- url.pathname += '/' + output + '/' + entry
79
- return url.href
80
- } catch (error) { throw new Error(`[hel-env] ${slot}: ${error.message}`) }
81
- }
82
-
83
- function assertSameOrigin(url, base, slot) {
84
- if (new URL(url).origin !== new URL(base).origin) {
85
- throw new Error(`[hel-env] ${slot} must use the deployment origin ${new URL(base).origin}: ${url}`)
86
- }
87
- }
88
-
89
- // Keep the deployment directory while allowing the same static files on another origin.
90
- function resolveBuildHomePage(env, homePage = env.HEL_APP_HOME_PAGE) {
91
- if (env.HEL_RELATIVE_PATH !== '1') return homePage
92
- if (/^(?:https?:)?\/\//i.test(homePage || '')) return new URL(homePage, 'https://hel.invalid').pathname
93
- return homePage || '/'
94
- }
95
-
96
- function loadPackageEnv({ cwd = process.cwd(), mode = 'development', env = process.env, target, localBuild = false } = {}) {
97
- const inherited = { ...env }
98
- // Recompute our own defaults on reload, but preserve values changed by cross-env.
99
- const generated = JSON.parse(inherited.HEL_ENV_GENERATED || '{}')
100
- for (const [key, value] of Object.entries(generated)) {
101
- if (inherited[key] === value) delete inherited[key]
102
- }
103
- delete inherited.HEL_ENV_GENERATED
104
- delete inherited.HEL_ENV_DERIVED_KEYS
105
- delete inherited.HEL_ENV_PACKAGE
106
- const values = Object.assign({}, readPackageFiles(cwd, mode), inherited)
107
- values.HEL_ENV_PACKAGE = path.resolve(cwd)
108
- expand({ parsed: values, processEnv: { ...values } })
109
- values.UNPKG_PUBLIC_URL ||= 'https://unpkg.com'
110
- const derived = new Set()
111
- const put = (key, value) => {
112
- if (!value) return
113
- if (!values[key]) { values[key] = String(value); derived.add(key) }
114
- }
115
- const deployTarget = values.HEL_DEPLOY_TARGET
116
- const runtimeMode = values.NODE_ENV || mode
117
- const selected = resolveTarget(deployTarget || target || values.REMOTE_TARGET, runtimeMode)
118
- localBuild ||= values.HEL_LOCAL_BUILD === '1'
119
- const port = inherited.PORT || inherited.DEV_PORT || inherited.VITE_PORT || values.PORT || values.DEV_PORT
120
- const previewPort = values.PREVIEW_PORT || port
121
- if (port && (!/^\d+$/.test(String(port)) || +port < 1 || +port > 65535)) throw new Error('[hel-env] DEV_PORT must be between 1 and 65535')
122
- if (port) values.DEV_PORT = String(port)
123
- put('PORT', port)
124
- put('VITE_PORT', port)
125
- put('VUE_APP_PORT', port)
126
- put('REACT_APP_PORT', port)
127
- put('VITE_PREVIEW_PORT', previewPort)
128
- put('VUE_APP_PREVIEW_PORT', previewPort)
129
- put('VITE_DEV_ORIGIN', values.DEV_ORIGIN || (port ? `http://localhost:${port}` : ''))
130
- put('VUE_APP_DEV_ORIGIN', values.VITE_DEV_ORIGIN)
131
- for (const key of PUBLIC_ENV_KEYS) {
132
- // Only these public bases are exposed to browser code, never SFTP credentials.
133
- put(`VITE_${key}`, values[key])
134
- put(`VUE_APP_${key}`, values[key])
135
- }
136
- for (const slot of remoteSlots(values)) {
137
- const slotTarget = resolveTarget(deployTarget || target || values[`${slot}_TARGET`] || selected, runtimeMode)
138
- const keys = [`VITE_${slot}_HOST`, `VUE_APP_${slot}_HOST`, `REACT_APP_${slot}_HOST`, `HEL_${slot}_HOST`]
139
- const overrides = [...keys, `VUE_APP_${slot}_ENTRY`, `VITE_${slot}_ENTRY`, `${slot}_URL`]
140
- .map(key => values[key]).filter(Boolean)
141
- if (new Set(overrides).size > 1) throw new Error(`[hel-env] Conflicting ${slot} address overrides`)
142
- const explicit = overrides[0]
143
- const expected = !explicit || deployTarget
144
- ? localBuild && !deployTarget && values[`${slot}_BUNDLED_PATH`]
145
- ? './' + values[`${slot}_BUNDLED_PATH`]
146
- : resolveRemoteUrl(values, slot, slotTarget)
147
- : explicit
148
- const resolved = explicit || expected
149
- if (deployTarget) {
150
- assertSameOrigin(resolved, values[`${deployTarget.toUpperCase()}_PUBLIC_URL`] || expected, slot)
151
- if (resolved !== expected) throw new Error(`[hel-env] ${slot} must match the deployment package/version URL: ${expected}`)
152
- }
153
- for (const key of keys) put(key, resolved)
154
- if (values[`${slot}_ENTRY`] === 'index.html') {
155
- put(`VUE_APP_${slot}_ENTRY`, resolved)
156
- put(`VITE_${slot}_ENTRY`, resolved)
157
- }
158
- put(`VITE_${slot}_LOCAL_URL`, values[`${slot}_LOCAL_URL`])
159
- put(`VUE_APP_${slot}_LOCAL_URL`, values[`${slot}_LOCAL_URL`])
160
- }
161
- if (localBuild && values.VITE_DEV_ORIGIN) put('HEL_APP_HOME_PAGE', values.VITE_DEV_ORIGIN)
162
- if (runtimeMode === 'production' && !localBuild) {
163
- const homePage = resolveBuildHomePage(values)
164
- if (homePage) values.HEL_APP_HOME_PAGE = homePage
165
- }
166
- if (deployTarget) put('VUE_APP_PUBLISH_MODE', deployTarget)
167
- values.HEL_ENV_PACKAGE = path.resolve(cwd)
168
- const computed = Object.fromEntries(Object.entries(values).filter(([key, value]) =>
169
- !key.startsWith('HEL_ENV_') && inherited[key] !== value && !(key === 'HEL_APP_HOME_PAGE' && inherited[key])))
170
- values.HEL_ENV_DERIVED_KEYS = Object.keys(computed).join(',')
171
- values.HEL_ENV_GENERATED = JSON.stringify(computed)
172
- return values
173
- }
174
-
175
- function inferMode(env = process.env, argv = process.argv) {
176
- const modeIndex = argv.indexOf('--mode')
177
- const inline = argv.find(arg => arg.startsWith('--mode='))
178
- if (modeIndex >= 0 && argv[modeIndex + 1]) return argv[modeIndex + 1]
179
- if (inline) return inline.slice(7)
180
- if (env.HEL_ENV_MODE) return env.HEL_ENV_MODE
181
- if (env.NODE_ENV) return env.NODE_ENV
182
- return /^(?:build|preview|prepublish)/.test(env.npm_lifecycle_event || '') ? 'production' : 'development'
183
- }
184
-
185
- function applyPackageEnv({ cwd = process.cwd(), mode = inferMode() } = {}) {
186
- const values = loadPackageEnv({ cwd, mode })
187
- const preview = /^(?:preview|serve:dist)/.test(process.env.npm_lifecycle_event || '')
188
- if (preview && !process.env.PORT && values.PREVIEW_PORT) values.PORT = values.PREVIEW_PORT
189
- Object.assign(process.env, values)
190
- return values
191
- }
192
-
193
- module.exports = { applyPackageEnv, inferMode, PUBLIC_ENV_KEYS, WORKSPACE_ENV_KEYS, readEnvFile, readPackageFiles, remoteSlots, resolveTarget, resolveRemoteUrl, resolveBuildHomePage, loadPackageEnv }
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
+ const dotenv = require('dotenv')
4
+ const { expand } = require('dotenv-expand')
5
+ const { packageRef, packageUrl } = require('./remote-address.cjs')
6
+
7
+ const PUBLIC_ENV_KEYS = ['SFTP_PUBLIC_URL', 'GITHUB_PUBLIC_URL', 'UNPKG_PUBLIC_URL']
8
+ const WORKSPACE_ENV_KEYS = [...PUBLIC_ENV_KEYS, 'HEL_RELATIVE_PATH']
9
+ const TARGETS = ['local', 'sftp', 'github', 'unpkg']
10
+
11
+ function readEnvFile(file) {
12
+ return fs.existsSync(file) ? dotenv.parse(fs.readFileSync(file)) : {}
13
+ }
14
+
15
+ function readPackageFiles(cwd, mode) {
16
+ // The root orchestrator copies only public bases here. Never read a parent directory.
17
+ const names = ['.env.defaults', '.env.workspace.local', '.env', `.env.${mode}`, '.env.local', `.env.${mode}.local`]
18
+ return Object.assign({}, ...names.filter(Boolean).map(name => readEnvFile(path.join(cwd, name))))
19
+ }
20
+
21
+ // Validate/stamp the actual keys declared in env files; never derive other keys or URLs.
22
+ function remoteEntries(env) {
23
+ return Object.entries(env).filter(([key, value]) =>
24
+ /^(?:VITE_|VUE_APP_|REACT_APP_|HEL_).+_(?:HOST|ENTRY)$/.test(key) && typeof value === 'string' && value !== '')
25
+ }
26
+
27
+ function resolveTarget(value, mode) {
28
+ const target = String(value || 'auto').toLowerCase()
29
+ if (target === 'auto') return ['development', 'mock'].includes(mode) ? 'local' : 'sftp'
30
+ if (!TARGETS.includes(target)) throw new Error(`[hel-env] Unknown remote target: ${target}`)
31
+ return target
32
+ }
33
+
34
+ function validateRemoteEntries(env) {
35
+ for (const [key, value] of remoteEntries(env)) {
36
+ if (value.startsWith('./') || value.startsWith('/')) {
37
+ if (env.HEL_DEPLOY_TARGET) throw new Error('[hel-env] ' + key + ': deployment requires an absolute HTTP(S) entry')
38
+ continue
39
+ }
40
+ let url
41
+ try { url = new URL(value) } catch { throw new Error('[hel-env] ' + key + ': configure a complete HTTP(S) entry in the package env file') }
42
+ if (!/^https?:$/.test(url.protocol)) throw new Error('[hel-env] ' + key + ': entry must use HTTP(S)')
43
+ if (env.HEL_DEPLOY_TARGET && /^(?:localhost|127\.0\.0\.1|\[::1\])$/.test(url.hostname)) {
44
+ throw new Error('[hel-env] ' + key + ': deployment entry cannot point to localhost')
45
+ }
46
+ }
47
+ }
48
+
49
+ // Keep the deployment directory while allowing the same static files on another origin.
50
+ function resolveBuildHomePage(env, homePage = env.HEL_APP_HOME_PAGE) {
51
+ if (env.HEL_RELATIVE_PATH !== '1') return homePage
52
+ if (/^(?:https?:)?\/\//i.test(homePage || '')) return new URL(homePage, 'https://hel.invalid').pathname
53
+ return homePage || '/'
54
+ }
55
+
56
+ function loadPackageEnv({ cwd = process.cwd(), mode = 'development', env = process.env, target, localBuild = false } = {}) {
57
+ const inherited = { ...env }
58
+ // Recompute our own defaults on reload, but preserve values changed by cross-env.
59
+ const generated = JSON.parse(inherited.HEL_ENV_GENERATED || '{}')
60
+ for (const [key, value] of Object.entries(generated)) {
61
+ if (inherited[key] === value) delete inherited[key]
62
+ }
63
+ delete inherited.HEL_ENV_GENERATED
64
+ delete inherited.HEL_ENV_DERIVED_KEYS
65
+ delete inherited.HEL_ENV_PACKAGE
66
+ const defaults = { ...readPackageFiles(cwd, mode), ...inherited }
67
+ const runtimeMode = defaults.NODE_ENV || mode
68
+ const deployTarget = defaults.HEL_DEPLOY_TARGET
69
+ const requestedTarget = deployTarget || target || defaults.REMOTE_TARGET
70
+ const selected = resolveTarget(requestedTarget, runtimeMode)
71
+ localBuild ||= defaults.HEL_LOCAL_BUILD === '1'
72
+ const values = { UNPKG_PUBLIC_URL: 'https://unpkg.com', ...defaults }
73
+ values.HEL_ENV_PACKAGE = path.resolve(cwd)
74
+ // Manifest mappings spell out both the consumer key and each candidate key.
75
+ // No suffix convention is used to invent configuration keys or URL paths.
76
+ const manifest = path.join(cwd, 'package.json')
77
+ const entryMap = fs.existsSync(manifest) ? JSON.parse(fs.readFileSync(manifest, 'utf8')).config?.remoteEntries || {} : {}
78
+ const overrides = { ...readEnvFile(path.join(cwd, '.env.local')), ...readEnvFile(path.join(cwd, `.env.${mode}.local`)), ...inherited }
79
+ for (const [entryKey, candidates] of Object.entries(entryMap)) {
80
+ if (Object.hasOwn(overrides, entryKey)) continue
81
+ const candidateKey = candidates[selected]
82
+ if (!candidateKey || !values[candidateKey]?.trim()) {
83
+ throw new Error(`[hel-env] ${entryKey}: no explicit ${selected} entry declared in package.json config.remoteEntries and .env`)
84
+ }
85
+ for (const match of values[candidateKey].matchAll(/\$\{([A-Z][A-Z0-9_]*)\}/g)) {
86
+ if (!values[match[1]]) throw new Error(`[hel-env] ${entryKey}: configure ${match[1]} in .env.local or sync the shared workspace roots`)
87
+ }
88
+ values[entryKey] = values[candidateKey]
89
+ }
90
+ expand({ parsed: values, processEnv: { ...values } })
91
+ values.UNPKG_PUBLIC_URL ||= 'https://unpkg.com'
92
+ const derived = new Set()
93
+ const put = (key, value) => {
94
+ if (!value) return
95
+ if (!values[key]) { values[key] = String(value); derived.add(key) }
96
+ }
97
+ const port = inherited.PORT || inherited.DEV_PORT || inherited.VITE_PORT || values.PORT || values.DEV_PORT
98
+ const previewPort = values.PREVIEW_PORT || port
99
+ if (port && (!/^\d+$/.test(String(port)) || +port < 1 || +port > 65535)) throw new Error('[hel-env] DEV_PORT must be between 1 and 65535')
100
+ if (port) values.DEV_PORT = String(port)
101
+ put('PORT', port)
102
+ put('VITE_PORT', port)
103
+ put('VUE_APP_PORT', port)
104
+ put('REACT_APP_PORT', port)
105
+ put('VITE_PREVIEW_PORT', previewPort)
106
+ put('VUE_APP_PREVIEW_PORT', previewPort)
107
+ put('VITE_DEV_ORIGIN', values.DEV_ORIGIN || (port ? `http://localhost:${port}` : ''))
108
+ put('VUE_APP_DEV_ORIGIN', values.VITE_DEV_ORIGIN)
109
+ validateRemoteEntries(values)
110
+ if (localBuild && values.VITE_DEV_ORIGIN) put('HEL_APP_HOME_PAGE', values.VITE_DEV_ORIGIN)
111
+ if (runtimeMode === 'production' && !localBuild) {
112
+ let defaultHomePage = values.HEL_APP_HOME_PAGE
113
+ // A native build/publish:stage has no deployment orchestrator to supply the
114
+ // output directory. Keep the package/version prefix when dropping the origin.
115
+ if (!defaultHomePage && values.HEL_RELATIVE_PATH === '1' && selected === 'unpkg') {
116
+ const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'))
117
+ if (pkg.unpkg && pkg.version) {
118
+ const url = packageUrl(packageRef(`${pkg.name}@${pkg.version}`), { base: values.UNPKG_PUBLIC_URL })
119
+ url.pathname += '/' + path.posix.dirname(pkg.unpkg.replace(/^\.\//, ''))
120
+ defaultHomePage = url.href
121
+ }
122
+ }
123
+ const homePage = resolveBuildHomePage(values, defaultHomePage)
124
+ if (homePage) values.HEL_APP_HOME_PAGE = homePage
125
+ }
126
+ if (deployTarget) put('VUE_APP_PUBLISH_MODE', deployTarget)
127
+ values.HEL_ENV_PACKAGE = path.resolve(cwd)
128
+ const computed = Object.fromEntries(Object.entries(values).filter(([key, value]) =>
129
+ !key.startsWith('HEL_ENV_') && inherited[key] !== value && !(key === 'HEL_APP_HOME_PAGE' && inherited[key])))
130
+ values.HEL_ENV_DERIVED_KEYS = Object.keys(computed).join(',')
131
+ values.HEL_ENV_GENERATED = JSON.stringify(computed)
132
+ return values
133
+ }
134
+
135
+ function inferMode(env = process.env, argv = process.argv) {
136
+ const modeIndex = argv.indexOf('--mode')
137
+ const inline = argv.find(arg => arg.startsWith('--mode='))
138
+ if (modeIndex >= 0 && argv[modeIndex + 1]) return argv[modeIndex + 1]
139
+ if (inline) return inline.slice(7)
140
+ if (env.HEL_ENV_MODE) return env.HEL_ENV_MODE
141
+ if (env.NODE_ENV) return env.NODE_ENV
142
+ return /^(?:build|preview|prepublish)/.test(env.npm_lifecycle_event || '') ? 'production' : 'development'
143
+ }
144
+
145
+ function applyPackageEnv({ cwd = process.cwd(), mode = inferMode() } = {}) {
146
+ const values = loadPackageEnv({ cwd, mode })
147
+ for (const [key, value] of Object.entries(JSON.parse(process.env.HEL_ENV_GENERATED || '{}'))) {
148
+ if (process.env[key] === value && !Object.hasOwn(values, key)) delete process.env[key]
149
+ }
150
+ const preview = /^(?:preview|serve:dist)/.test(process.env.npm_lifecycle_event || '')
151
+ if (preview && !process.env.PORT && values.PREVIEW_PORT) values.PORT = values.PREVIEW_PORT
152
+ Object.assign(process.env, values)
153
+ return values
154
+ }
155
+
156
+ module.exports = { applyPackageEnv, inferMode, PUBLIC_ENV_KEYS, WORKSPACE_ENV_KEYS, readEnvFile, readPackageFiles, remoteEntries, resolveTarget, resolveBuildHomePage, loadPackageEnv }
@@ -1,45 +1,53 @@
1
1
  #!/usr/bin/env node
2
- import { execSync } from 'node:child_process'
3
- import fs from 'node:fs'
4
- import os from 'node:os'
5
- import path from 'node:path'
6
-
7
- // 统一的 stage 发布入口:先 pnpm pack 再 npm stage publish。
8
- //
9
- // 为什么不能直接 `npx npm stage publish`:
10
- // npm 不认识 workspace: 协议,会把 `workspace:*` 原样写进 tarball 的 package.json,
11
- // 消费方安装时直接报 EUNSUPPORTEDPROTOCOL(例如 2026.11.8-1 的 ele-pure-full)。
12
- // pnpm pack 会把 workspace:* 改写成实际版本,再由 npm 把 tarball 送上 stage。
13
- //
14
- // prepublishOnly 的守卫(版本号 / hel-meta / localhost 资源地址)不会被 tarball 流程触发,
15
- // 这里显式跑一次,避免绕过 comps-* / libs-* 的发布前检查。
16
-
17
- const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
18
- if (pkg.private) {
19
- throw new Error('[publish:stage] 当前 package.json 是 private,请在要发布的包目录里执行')
20
- }
21
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hel-stage-'))
22
- const run = (command) => execSync(command, { stdio: 'inherit' })
23
- let npmStage = 'npm'
24
- try {
25
- execSync('npm stage --help', { stdio: 'ignore' })
26
- } catch {
27
- npmStage = 'pnpm --registry=https://registry.npmjs.org --package=npm@11 dlx npm'
2
+ import { execSync } from 'node:child_process'
3
+ import fs from 'node:fs'
4
+ import os from 'node:os'
5
+ import path from 'node:path'
6
+
7
+ // 统一的 stage 发布入口:先 pnpm pack 再 npm stage publish。
8
+ //
9
+ // 为什么不能直接 `npx npm stage publish`:
10
+ // npm 不认识 workspace: 协议,会把 `workspace:*` 原样写进 tarball 的 package.json,
11
+ // 消费方安装时直接报 EUNSUPPORTEDPROTOCOL(例如 2026.11.8-1 的 ele-pure-full)。
12
+ // pnpm pack 会把 workspace:* 改写成实际版本,再由 npm 把 tarball 送上 stage。
13
+ //
14
+ // prepublishOnly 的守卫(版本号 / hel-meta / localhost 资源地址)不会被 tarball 流程触发,
15
+ // 这里显式跑一次,避免绕过 comps-* / libs-* 的发布前检查。
16
+
17
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'))
18
+ const args = process.argv.slice(2)
19
+ if (args.some(arg => arg !== '--dry-run')) throw new Error('用法:hel-publish-stage [--dry-run]')
20
+ const dryRun = args.includes('--dry-run')
21
+ if (pkg.private) {
22
+ throw new Error('[publish:stage] 当前 package.json 是 private,请在要发布的包目录里执行')
28
23
  }
29
-
30
- try {
31
- if (pkg.scripts && pkg.scripts.prepublishOnly) {
32
- run('pnpm run prepublishOnly')
33
- }
34
-
35
- run(`pnpm pack --pack-destination "${tmp}"`)
36
- const tgz = fs.readdirSync(tmp).find((file) => file.endsWith('.tgz'))
37
- if (!tgz) throw new Error('pnpm pack 没有产出 tarball')
38
-
39
- run(
24
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hel-stage-'))
25
+ const run = (command) => execSync(command, { stdio: 'inherit' })
26
+ try {
27
+ if (pkg.scripts && pkg.scripts.prepublishOnly) {
28
+ run('pnpm run prepublishOnly')
29
+ }
30
+
31
+ run(`pnpm pack --pack-destination "${tmp}"`)
32
+ const tgz = fs.readdirSync(tmp).find((file) => file.endsWith('.tgz'))
33
+ if (!tgz) throw new Error('pnpm pack 没有产出 tarball')
34
+
35
+ if (dryRun) {
36
+ console.log(`[publish:stage] dry-run: ${pkg.name}@${pkg.version} packed; 未上传或修改版本。保留产物:${path.join(tmp, tgz)}`)
37
+ process.exitCode = 0
38
+ } else {
39
+ let npmStage = 'npm'
40
+ try {
41
+ execSync('npm stage --help', { stdio: 'ignore' })
42
+ } catch {
43
+ npmStage = 'pnpm --registry=https://registry.npmjs.org --package=npm@11 dlx npm'
44
+ }
45
+
46
+ run(
40
47
  `${npmStage} stage publish "${path.join(tmp, tgz)}" --registry=https://registry.npmjs.org --access public`,
41
- )
42
- console.log(`[publish:stage] ${pkg.name}@${pkg.version} staged`)
43
- } finally {
44
- fs.rmSync(tmp, { recursive: true, force: true })
45
- }
48
+ )
49
+ console.log(`[publish:stage] ${pkg.name}@${pkg.version} staged`)
50
+ }
51
+ } finally {
52
+ if (!dryRun) fs.rmSync(tmp, { recursive: true, force: true })
53
+ }