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

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 (54) hide show
  1. package/README.md +5 -1
  2. package/dist/browser.d.mts +2 -1
  3. package/dist/browser.mjs +1 -60
  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/dist/demo/docs.mjs +1 -58
  25. package/dist/demo/docs.mjs.gz +0 -0
  26. package/dist/demo/download.d.mts +7 -4
  27. package/dist/demo/download.mjs +1 -4
  28. package/dist/demo/download.mjs.gz +0 -0
  29. package/dist/demo/fullscreen.mjs +1 -1
  30. package/dist/demo/index.d.mts +2 -0
  31. package/dist/demo/index.mjs +1 -1
  32. package/dist/demo/model.mjs +1 -1
  33. package/dist/demo/remote-debug.mjs +1 -1
  34. package/dist/demo/runtime.mjs +6 -6
  35. package/dist/demo/split-pane.mjs +1 -1
  36. package/dist/demo/standalone.d.mts +9 -0
  37. package/dist/demo/standalone.mjs +1 -0
  38. package/dist/demo/tabs.mjs +1 -1
  39. package/dist/loading.mjs +1 -11
  40. package/dist/remote.d.mts +1 -0
  41. package/dist/remote.mjs +1 -1
  42. package/dist/remote.mjs.gz +0 -0
  43. package/dist/vendor/hel-runtime.mjs +50 -0
  44. package/dist/vendor/hel-runtime.mjs.gz +0 -0
  45. package/package.json +25 -7
  46. package/scripts/browser-formats.mjs +355 -0
  47. package/scripts/build-browser.mjs +59 -31
  48. package/scripts/build-protected-esm.mjs +51 -0
  49. package/scripts/cdn-runtime.cjs +30 -0
  50. package/scripts/check-tdz.mjs +322 -322
  51. package/scripts/comps-bundle-obfuscation.cjs +2 -1
  52. package/scripts/package-artifacts.mjs +25 -6
  53. package/scripts/publish-stage.mjs +33 -33
  54. package/scripts/webpack-bundle-obfuscation.cjs +13 -0
@@ -5,8 +5,12 @@ import path from 'node:path'
5
5
  import { createRequire } from 'node:module'
6
6
  import { pathToFileURL, fileURLToPath } from 'node:url'
7
7
  import { spawnSync } from 'node:child_process'
8
+ import { gzipSync } from 'node:zlib'
8
9
  import ts from 'typescript'
9
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'
10
14
 
11
15
  const slash = value => value.replaceAll('\\', '/')
12
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)] : []) : []
@@ -30,14 +34,15 @@ export async function buildPackageArtifacts(root = process.cwd()) {
30
34
  if (!out.startsWith(root + path.sep)) throw new Error('产物必须位于包目录内')
31
35
  const localRequire = createRequire(path.join(root, 'package.json'))
32
36
 
33
- if (config.mode === 'declarations') { cleanDeclarationStyles(out); return }
37
+ if (config.mode === 'declarations') { cleanDeclarationStyles(out); await buildBrowserFormats(root); return }
34
38
 
35
39
  if (config.mode === 'adapter') {
36
40
  for (const file of walk(src)) {
37
41
  const dest = path.join(out, path.relative(src, file))
38
- if (/\.mjs$/.test(file)) await build({ entryPoints: [file], outfile: dest, minify: true, target: 'es2019', format: 'esm', sourcemap: false })
42
+ if (/\.mjs$/.test(file)) await buildProtectedEsm({ entryPoints: [file], outfile: dest, minify: true, target: 'es2019', format: 'esm' }, { root })
39
43
  else if (/\.d\.(ts|mts)$/.test(file)) copy(file, dest)
40
44
  }
45
+ await buildBrowserFormats(root)
41
46
  return
42
47
  }
43
48
 
@@ -132,16 +137,29 @@ export async function buildPackageArtifacts(root = process.cwd()) {
132
137
  const { default: tailwind } = await import(pathToFileURL(localRequire.resolve('@tailwindcss/vite')).href)
133
138
  plugins.push(tailwind())
134
139
  }
140
+ const pluginModule = await import(pathToFileURL(localRequire.resolve('vite-plugin-bundle-obfuscator')).href)
141
+ const finalObfuscator = pluginModule.default.default || pluginModule.default
142
+ plugins.push(...bundleObfuscation.bundleObfuscationPlugins({ root, obfuscatorPlugin: finalObfuscator,
143
+ enabled: process.env.HEL_OBFUSCATE !== '0', library: true, rolldown: config.rolldown === true }), bundleObfuscation.gzipPlugin())
135
144
  await viteBuild({ configFile: false, root, plugins, css: { postcss: { plugins: [] } },
136
145
  build: { outDir: out, emptyOutDir: false, minify: true, sourcemap: false, target: 'es2020',
137
146
  lib: { entry: Object.fromEntries(Object.entries(entries).map(([key, value]) => [key, path.join(root, value)])), formats: ['es'], fileName: (_format, name) => name + '.js' },
138
- rollupOptions: { external: id => !id.startsWith('.') && !path.isAbsolute(id) && !id.startsWith('\0') },
147
+ rollupOptions: { external: id => id !== pkg.name && !id.startsWith(pkg.name + '/') && !id.startsWith('.') && !path.isAbsolute(id) && !id.startsWith('\0') },
139
148
  },
140
149
  })
141
- // Vite library CSS is extracted. Preserve the original design side effect.
142
- if (entries.design) fs.appendFileSync(path.join(out, 'design.js'), `\nimport './${pkg.name.split('/').at(-1)}.css'\n`)
150
+ // Native ESM loads extracted CSS through <link>; bundlers keep the CSS side effect.
151
+ if (entries.design) {
152
+ const design = path.join(out, 'design.js')
153
+ const browserDesign = path.join(out, 'design.browser.js')
154
+ copy(design, browserDesign)
155
+ fs.appendFileSync(design, `\nimport './${pkg.name.split('/').at(-1)}.css'\n`)
156
+ for (const file of [design, browserDesign]) {
157
+ const content = fs.readFileSync(file)
158
+ if (process.env.HEL_GZIP !== '0' && (content.length >= 10240 || fs.existsSync(file + '.gz'))) write(file + '.gz', gzipSync(content))
159
+ }
160
+ }
143
161
  } else {
144
- await build({ absWorkingDir: root, entryPoints: entries, outdir: out, bundle: true, packages: 'external', format: 'esm', platform: 'neutral', target: 'es2022', minify: true, sourcemap: false })
162
+ 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 })
145
163
  }
146
164
  if (config.bin) {
147
165
  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, banner: { js: '#!/usr/bin/env node' } })
@@ -174,6 +192,7 @@ export async function buildPackageArtifacts(root = process.cwd()) {
174
192
  write(path.join(out, 'subpaths', name + '.js'), body.join('\n') + '\n')
175
193
  }
176
194
  }
195
+ await buildBrowserFormats(root)
177
196
  console.log(`[package-artifacts] ${pkg.name}: ${out}`)
178
197
  }
179
198
 
@@ -1,36 +1,36 @@
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'))
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
18
  const args = process.argv.slice(2)
19
19
  if (args.some(arg => arg !== '--dry-run')) throw new Error('用法:hel-publish-stage [--dry-run]')
20
20
  const dryRun = args.includes('--dry-run')
21
- if (pkg.private) {
22
- throw new Error('[publish:stage] 当前 package.json 是 private,请在要发布的包目录里执行')
23
- }
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')
21
+ if (pkg.private) {
22
+ throw new Error('[publish:stage] 当前 package.json 是 private,请在要发布的包目录里执行')
23
+ }
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
34
 
35
35
  if (dryRun) {
36
36
  console.log(`[publish:stage] dry-run: ${pkg.name}@${pkg.version} packed; 未上传或修改版本。保留产物:${path.join(tmp, tgz)}`)
@@ -42,12 +42,12 @@ try {
42
42
  } catch {
43
43
  npmStage = 'pnpm --registry=https://registry.npmjs.org --package=npm@11 dlx npm'
44
44
  }
45
-
45
+
46
46
  run(
47
47
  `${npmStage} stage publish "${path.join(tmp, tgz)}" --registry=https://registry.npmjs.org --access public`,
48
- )
48
+ )
49
49
  console.log(`[publish:stage] ${pkg.name}@${pkg.version} staged`)
50
50
  }
51
- } finally {
51
+ } finally {
52
52
  if (!dryRun) fs.rmSync(tmp, { recursive: true, force: true })
53
- }
53
+ }
@@ -111,6 +111,19 @@ function webpackBundlePolicy({ root, Obfuscator, enabled = true }) {
111
111
 
112
112
  function applyWebpackBundlePolicy(config, { root, Obfuscator, enabled = process.env.HEL_OBFUSCATE !== '0' }) {
113
113
  if (process.env.NODE_ENV !== 'production' && config.mode !== 'production') return config
114
+ // Deployment base candidates are build inputs. Only the selected publicPath/remote slots belong in client code.
115
+ // Vue CLI serializes the full process.env object for dependencies using dynamic environment access.
116
+ const deploymentBase = /^(?:VUE_APP_|REACT_APP_|VITE_)(?:SFTP|GITHUB|UNPKG)_PUBLIC_URL$/
117
+ for (const plugin of config.plugins || []) {
118
+ if (plugin?.constructor?.name !== 'DefinePlugin') continue
119
+ const definitions = plugin.definitions || {}
120
+ for (const key of Object.keys(definitions['process.env'] || {})) {
121
+ if (deploymentBase.test(key)) delete definitions['process.env'][key]
122
+ }
123
+ for (const key of Object.keys(definitions)) {
124
+ if (deploymentBase.test(key.replace(/^process\.env\./, ''))) delete definitions[key]
125
+ }
126
+ }
114
127
  const policy = webpackBundlePolicy({ root, Obfuscator, enabled })
115
128
  config.devtool = false
116
129
  config.plugins = (config.plugins || []).filter(plugin => plugin?.constructor?.name !== 'LimitChunkCountPlugin')