@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.
- package/README.md +73 -16
- 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 +141 -0
- package/dist/cdn/vendor.umd.cjs +16 -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.d.mts +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 +3 -0
- package/dist/demo/docs.mjs +1 -0
- package/dist/demo/docs.mjs.gz +0 -0
- package/{src → dist}/demo/download.d.mts +10 -2
- package/dist/demo/download.mjs +1 -0
- package/dist/demo/download.mjs.gz +0 -0
- package/dist/demo/fullscreen.mjs +1 -0
- package/dist/demo/highlight.d.mts +2 -0
- package/dist/demo/highlight.mjs +1 -0
- package/dist/demo/index.d.mts +10 -0
- package/dist/demo/index.mjs +1 -0
- package/dist/demo/model.mjs +1 -0
- package/dist/demo/remote-debug.d.mts +9 -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 +12 -0
- package/dist/demo/standalone.mjs +1 -0
- package/dist/demo/standalone.mjs.gz +0 -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/loading.mjs.gz +0 -0
- package/dist/remote-address.cjs +2 -0
- package/{src → dist}/remote.d.mts +20 -2
- package/dist/remote.mjs +1 -0
- package/dist/remote.mjs.gz +0 -0
- package/dist/vendor/hel-runtime.mjs +16 -0
- package/dist/vendor/hel-runtime.mjs.gz +0 -0
- package/package.json +41 -25
- package/scripts/browser-formats.mjs +357 -0
- package/scripts/build-browser.mjs +59 -13
- package/scripts/build-protected-esm.mjs +54 -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/comps-bundle-obfuscation.cjs +269 -262
- package/scripts/comps-obfuscator-options.cjs +7 -1
- package/scripts/hel-build-paths.cjs +49 -48
- package/scripts/obfuscator-split-strings.cjs +22 -0
- package/scripts/package-artifacts.mjs +206 -0
- package/scripts/package-env.cjs +156 -193
- package/scripts/publish-stage.mjs +50 -42
- package/scripts/webpack-bundle-obfuscation.cjs +125 -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
- /package/{src → dist}/demo/fullscreen.d.mts +0 -0
- /package/{src → dist}/demo/model.d.mts +0 -0
- /package/{src → scripts}/remote-address.cjs +0 -0
package/scripts/package-env.cjs
CHANGED
|
@@ -1,193 +1,156 @@
|
|
|
1
|
-
const fs = require('node:fs')
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
values.
|
|
108
|
-
|
|
109
|
-
values
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
put('
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
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
|
+
}
|