@origen-ui/admin-cli 1.0.2 → 1.1.0

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 (163) hide show
  1. package/package.json +3 -3
  2. package/templates/current/clean/CHANGELOG.md +53 -0
  3. package/templates/current/clean/component-catalog.json +9 -9
  4. package/templates/current/clean/package.json +41 -41
  5. package/templates/current/clean/scaffold.lock.json +2 -2
  6. package/templates/current/clean/scripts/vite-build-policy.spec.ts +71 -0
  7. package/templates/current/clean/src/App.vue +10 -3
  8. package/templates/current/clean/src/api/client.ts +90 -10
  9. package/templates/current/clean/src/api/generated/data-contracts.ts +268 -0
  10. package/templates/current/clean/src/api/generated/http-client.ts +266 -0
  11. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +147 -0
  12. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +53 -0
  13. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +66 -0
  14. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +171 -0
  15. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +181 -0
  16. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +169 -0
  17. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +170 -0
  18. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +98 -0
  19. package/templates/current/clean/src/app/adminLocale.ts +90 -0
  20. package/templates/current/clean/src/app/createAdminUi.spec.ts +65 -9
  21. package/templates/current/clean/src/app/createAdminUi.ts +14 -29
  22. package/templates/current/clean/src/app/embedded-token.spec.ts +40 -0
  23. package/templates/current/clean/src/app/embedded.spec.ts +135 -0
  24. package/templates/current/clean/src/app/embedded.ts +255 -0
  25. package/templates/current/clean/src/app/localeFormat.ts +52 -0
  26. package/templates/current/clean/src/app/menu.spec.ts +26 -0
  27. package/templates/current/clean/src/app/menu.ts +4 -0
  28. package/templates/current/clean/src/app/menuTypes.ts +1 -0
  29. package/templates/current/clean/src/app/origenUiLocale.spec.ts +6 -5
  30. package/templates/current/clean/src/app/origenUiLocale.ts +3 -58
  31. package/templates/current/clean/src/app/permission.spec.ts +26 -0
  32. package/templates/current/clean/src/app/runtimeConfig.ts +8 -7
  33. package/templates/current/clean/src/env.d.ts +18 -0
  34. package/templates/current/clean/src/features/appearance/components/ThemePanel.vue +21 -17
  35. package/templates/current/clean/src/features/appearance/store/theme.ts +2 -1
  36. package/templates/current/clean/src/features/auth/pages/Login.vue +15 -11
  37. package/templates/current/clean/src/features/auth/store/auth.ts +13 -3
  38. package/templates/current/clean/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
  39. package/templates/current/clean/src/features/security/devtoolsProtection.spec.ts +7 -10
  40. package/templates/current/clean/src/features/security/devtoolsProtection.ts +2 -1
  41. package/templates/current/clean/src/features/system/access/api/admin-repository.spec.ts +14 -0
  42. package/templates/current/clean/src/features/system/access/api/admin-repository.ts +38 -15
  43. package/templates/current/clean/src/features/system/access/api/rbac.ts +37 -27
  44. package/templates/current/clean/src/features/workspace/pages/Empty.vue +4 -1
  45. package/templates/current/clean/src/features/workspace/pages/Profile.vue +13 -11
  46. package/templates/current/clean/src/layouts/AdminLayout.vue +3 -1
  47. package/templates/current/clean/src/layouts/TopBar.vue +26 -8
  48. package/templates/current/clean/src/locales/en-US.json +490 -0
  49. package/templates/current/clean/src/locales/en-US.runtime.ts +20 -0
  50. package/templates/current/clean/src/locales/index.ts +129 -45
  51. package/templates/current/clean/src/locales/messages-types.ts +62 -0
  52. package/templates/current/clean/src/locales/messages.spec.ts +113 -6
  53. package/templates/current/clean/src/locales/vue-i18n.d.ts +5 -0
  54. package/templates/current/clean/src/locales/zh-CN.json +490 -0
  55. package/templates/current/clean/src/locales/zh-CN.runtime.ts +20 -0
  56. package/templates/current/clean/src/locales/zh-TW.json +490 -0
  57. package/templates/current/clean/src/locales/zh-TW.runtime.ts +20 -0
  58. package/templates/current/clean/src/router/bootstrap.ts +22 -7
  59. package/templates/current/clean/src/router/dynamicRoutes.ts +5 -1
  60. package/templates/current/clean/src/router/queryEncryption.spec.ts +30 -4
  61. package/templates/current/clean/src/router/queryEncryption.ts +48 -44
  62. package/templates/current/clean/src/router/useRouteQueryDefaults.spec.ts +2 -1
  63. package/templates/current/clean/src/router/useRouteQueryDefaults.types.ts +2 -1
  64. package/templates/current/clean/src/templates/og-table.ts +81 -37
  65. package/templates/current/clean/src/templates/templates.spec.ts +19 -0
  66. package/templates/current/clean/vite.build-policy.ts +114 -289
  67. package/templates/current/clean/vite.config.ts +4 -5
  68. package/templates/current/examples/CHANGELOG.md +53 -0
  69. package/templates/current/examples/component-catalog.json +9 -9
  70. package/templates/current/examples/package.json +41 -41
  71. package/templates/current/examples/scaffold.lock.json +2 -2
  72. package/templates/current/examples/scripts/vite-build-policy.spec.ts +71 -0
  73. package/templates/current/examples/src/App.vue +10 -3
  74. package/templates/current/examples/src/api/client.ts +90 -10
  75. package/templates/current/examples/src/api/generated/data-contracts.ts +268 -0
  76. package/templates/current/examples/src/api/generated/http-client.ts +266 -0
  77. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +147 -0
  78. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +53 -0
  79. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +66 -0
  80. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +171 -0
  81. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +181 -0
  82. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +169 -0
  83. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +170 -0
  84. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +98 -0
  85. package/templates/current/examples/src/app/adminLocale.ts +90 -0
  86. package/templates/current/examples/src/app/createAdminUi.spec.ts +65 -9
  87. package/templates/current/examples/src/app/createAdminUi.ts +14 -29
  88. package/templates/current/examples/src/app/embedded-token.spec.ts +40 -0
  89. package/templates/current/examples/src/app/embedded.spec.ts +135 -0
  90. package/templates/current/examples/src/app/embedded.ts +255 -0
  91. package/templates/current/examples/src/app/localeFormat.ts +52 -0
  92. package/templates/current/examples/src/app/menu.spec.ts +26 -0
  93. package/templates/current/examples/src/app/menu.ts +4 -0
  94. package/templates/current/examples/src/app/menuTypes.ts +1 -0
  95. package/templates/current/examples/src/app/origenUiLocale.spec.ts +6 -5
  96. package/templates/current/examples/src/app/origenUiLocale.ts +3 -58
  97. package/templates/current/examples/src/app/permission.spec.ts +26 -0
  98. package/templates/current/examples/src/app/runtimeConfig.ts +8 -7
  99. package/templates/current/examples/src/env.d.ts +18 -0
  100. package/templates/current/examples/src/features/appearance/components/ThemePanel.vue +21 -17
  101. package/templates/current/examples/src/features/appearance/store/theme.ts +2 -1
  102. package/templates/current/examples/src/features/auth/pages/Login.vue +15 -11
  103. package/templates/current/examples/src/features/auth/store/auth.ts +13 -3
  104. package/templates/current/examples/src/features/errors/pages/Forbidden.vue +6 -2
  105. package/templates/current/examples/src/features/errors/pages/NotFound.vue +6 -2
  106. package/templates/current/examples/src/features/errors/pages/ServerError.vue +6 -2
  107. package/templates/current/examples/src/features/errors/pages/error-pages.spec.ts +9 -1
  108. package/templates/current/examples/src/features/feature-composables.spec.ts +36 -9
  109. package/templates/current/examples/src/features/security/components/DevtoolsProtectionOverlay.vue +5 -2
  110. package/templates/current/examples/src/features/security/devtoolsProtection.spec.ts +7 -10
  111. package/templates/current/examples/src/features/security/devtoolsProtection.ts +2 -1
  112. package/templates/current/examples/src/features/system/access/api/admin-repository.spec.ts +14 -0
  113. package/templates/current/examples/src/features/system/access/api/admin-repository.ts +38 -15
  114. package/templates/current/examples/src/features/system/access/api/rbac.ts +37 -27
  115. package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts +43 -38
  116. package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +33 -30
  117. package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +81 -69
  118. package/templates/current/examples/src/features/system/menus/pages/MenuList.vue +3 -1
  119. package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +18 -15
  120. package/templates/current/examples/src/features/system/roles/composables/useRoleManagement.ts +49 -53
  121. package/templates/current/examples/src/features/system/roles/pages/RoleList.vue +3 -1
  122. package/templates/current/examples/src/features/system/users/components/UserEditorForm.vue +22 -19
  123. package/templates/current/examples/src/features/system/users/composables/useUserManagement.ts +59 -64
  124. package/templates/current/examples/src/features/system/users/pages/UserList.vue +3 -1
  125. package/templates/current/examples/src/features/workspace/pages/Dashboard.spec.ts +9 -0
  126. package/templates/current/examples/src/features/workspace/pages/Dashboard.vue +54 -26
  127. package/templates/current/examples/src/features/workspace/pages/Empty.vue +4 -1
  128. package/templates/current/examples/src/features/workspace/pages/Profile.vue +13 -11
  129. package/templates/current/examples/src/layouts/AdminLayout.vue +3 -1
  130. package/templates/current/examples/src/layouts/TopBar.vue +26 -8
  131. package/templates/current/examples/src/locales/en-US.json +490 -0
  132. package/templates/current/examples/src/locales/en-US.runtime.ts +20 -0
  133. package/templates/current/examples/src/locales/index.ts +129 -45
  134. package/templates/current/examples/src/locales/messages-types.ts +62 -0
  135. package/templates/current/examples/src/locales/messages.spec.ts +113 -6
  136. package/templates/current/examples/src/locales/vue-i18n.d.ts +5 -0
  137. package/templates/current/examples/src/locales/zh-CN.json +490 -0
  138. package/templates/current/examples/src/locales/zh-CN.runtime.ts +20 -0
  139. package/templates/current/examples/src/locales/zh-TW.json +490 -0
  140. package/templates/current/examples/src/locales/zh-TW.runtime.ts +20 -0
  141. package/templates/current/examples/src/main.ts +31 -5
  142. package/templates/current/examples/src/router/bootstrap.ts +22 -7
  143. package/templates/current/examples/src/router/dynamicRoutes.spec.ts +17 -0
  144. package/templates/current/examples/src/router/dynamicRoutes.ts +5 -1
  145. package/templates/current/examples/src/router/queryEncryption.spec.ts +30 -4
  146. package/templates/current/examples/src/router/queryEncryption.ts +48 -44
  147. package/templates/current/examples/src/router/staticRoutes.ts +1 -1
  148. package/templates/current/examples/src/router/useRouteQueryDefaults.spec.ts +2 -1
  149. package/templates/current/examples/src/router/useRouteQueryDefaults.types.ts +2 -1
  150. package/templates/current/examples/src/templates/og-table.ts +81 -37
  151. package/templates/current/examples/src/templates/templates.spec.ts +19 -0
  152. package/templates/current/examples/vite.build-policy.ts +114 -289
  153. package/templates/current/examples/vite.config.ts +4 -5
  154. package/templates/current/clean/scripts/check-admin-bundle.mjs +0 -214
  155. package/templates/current/clean/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
  156. package/templates/current/clean/src/locales/en-US.ts +0 -55
  157. package/templates/current/clean/src/locales/zh-CN.ts +0 -55
  158. package/templates/current/clean/src/locales/zh-TW.ts +0 -44
  159. package/templates/current/examples/scripts/check-admin-bundle.mjs +0 -214
  160. package/templates/current/examples/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +0 -38
  161. package/templates/current/examples/src/locales/en-US.ts +0 -55
  162. package/templates/current/examples/src/locales/zh-CN.ts +0 -55
  163. package/templates/current/examples/src/locales/zh-TW.ts +0 -44
@@ -1,12 +1,16 @@
1
- import type { Plugin, Rollup, UserConfig } from 'vite'
1
+ import type { Plugin, Rolldown, UserConfig } from 'vite'
2
2
  import { writeFile } from 'node:fs/promises'
3
3
  import { resolve } from 'node:path'
4
4
  import process from 'node:process'
5
5
 
6
6
  const packageBuildDirectories = new Set(['dist', 'es', 'esm', 'lib', 'src'])
7
- const splitModuleDirectories = new Set(['components', 'languages', 'locale'])
8
- const ASYNC_COMPONENT_CHUNK_BUCKETS = 4
9
- const INITIAL_CHUNK_BUCKETS = 3
7
+ const MAX_INITIAL_VENDOR_CHUNK_BYTES = 300 * 1024
8
+ const MAX_ASYNC_VENDOR_CHUNK_BYTES = 400 * 1024
9
+
10
+ type AdminCodeSplitting = Exclude<
11
+ NonNullable<Rolldown.OutputOptions['codeSplitting']>,
12
+ boolean
13
+ >
10
14
 
11
15
  function chunkName(value: string): string {
12
16
  return value
@@ -51,294 +55,103 @@ function isStyleModule(id: string): boolean {
51
55
  return /\.(?:css|less|sass|scss|styl)(?:$|\?)/.test(id)
52
56
  }
53
57
 
54
- function moduleUnitKey(id: string): string | undefined {
55
- const location = moduleLocation(id)
56
- if (!location) return undefined
57
- const [directory, moduleName] = location.path
58
- if (!directory || !splitModuleDirectories.has(directory)) return location.name
59
- if (directory === 'components' && moduleName)
60
- return `${location.name}\0${directory}\0${moduleName}`
61
- return `${location.name}\0${directory}`
62
- }
63
-
64
- function stableHash(value: string): string {
65
- let hash = 2_166_136_261
66
- for (let index = 0; index < value.length; index += 1) {
67
- hash ^= value.charCodeAt(index)
68
- hash = Math.imul(hash, 16_777_619)
69
- }
70
- return (hash >>> 0).toString(36)
71
- }
72
-
73
- function dynamicRootLabels(ids: readonly string[]): ReadonlyMap<string, string> {
74
- const used = new Map<string, number>()
75
- const labels = new Map<string, string>()
76
- for (const id of [...ids].sort()) {
77
- const normalized = id.split('?')[0].replaceAll('\\', '/')
78
- const filename = normalized.slice(normalized.lastIndexOf('/') + 1).replace(/\.[^.]+$/, '')
79
- const base = chunkName(filename || 'async') || 'async'
80
- const count = (used.get(base) ?? 0) + 1
81
- used.set(base, count)
82
- labels.set(id, count === 1 ? base : `${base}-${count}`)
83
- }
84
- return labels
85
- }
86
-
87
- function moduleOwners(
88
- meta: Parameters<Rollup.GetManualChunk>[1],
89
- ): ReadonlyMap<string, readonly string[]> {
90
- const ids = [...meta.getModuleIds()].sort()
91
- const ownerSets = new Map<string, Set<string>>()
92
- const entryRoots = ids.filter((id) => meta.getModuleInfo(id)?.isEntry)
93
- const dynamicRoots = [
94
- ...new Set(ids.flatMap((id) => meta.getModuleInfo(id)?.dynamicallyImportedIds ?? [])),
95
- ]
96
- const labels = dynamicRootLabels(dynamicRoots)
97
-
98
- function markStaticClosure(root: string, owner: string): void {
99
- const stack = [root]
100
- while (stack.length > 0) {
101
- const id = stack.pop()!
102
- const info = meta.getModuleInfo(id)
103
- if (!info || info.isExternal) continue
104
- const owners = ownerSets.get(id) ?? new Set<string>()
105
- if (owners.has(owner)) continue
106
- owners.add(owner)
107
- ownerSets.set(id, owners)
108
- stack.push(...info.importedIds)
109
- }
110
- }
111
-
112
- for (const root of entryRoots) markStaticClosure(root, 'entry')
113
- for (const root of dynamicRoots) markStaticClosure(root, labels.get(root) ?? 'async')
114
-
115
- return new Map([...ownerSets].map(([id, owners]) => [id, [...owners].sort()]))
116
- }
117
-
118
- function asyncOwnerLabel(owners: readonly string[]): string {
119
- const asyncOwners = owners.filter((owner) => owner !== 'entry')
120
- if (asyncOwners.length === 0) return 'orphan'
121
- if (asyncOwners.length === 1) return asyncOwners[0]
122
- return `shared-${stableHash(asyncOwners.join('|'))}`
123
- }
124
-
125
- function isInitialOnly(owners: readonly string[]): boolean {
126
- return owners.length === 1 && owners[0] === 'entry'
127
- }
128
-
129
- function stronglyConnectedComponents(units: Map<string, { edges: Set<string> }>): string[][] {
130
- const indices = new Map<string, number>()
131
- const lowLinks = new Map<string, number>()
132
- const stack: string[] = []
133
- const stacked = new Set<string>()
134
- const components: string[][] = []
135
- let index = 0
136
-
137
- function visit(key: string) {
138
- indices.set(key, index)
139
- lowLinks.set(key, index++)
140
- stack.push(key)
141
- stacked.add(key)
142
-
143
- for (const edge of [...(units.get(key)?.edges ?? [])].sort()) {
144
- if (!units.has(edge)) continue
145
- if (!indices.has(edge)) {
146
- visit(edge)
147
- lowLinks.set(key, Math.min(lowLinks.get(key)!, lowLinks.get(edge)!))
148
- } else if (stacked.has(edge)) {
149
- lowLinks.set(key, Math.min(lowLinks.get(key)!, indices.get(edge)!))
150
- }
151
- }
152
-
153
- if (lowLinks.get(key) !== indices.get(key)) return
154
- const component: string[] = []
155
- let member: string
156
- do {
157
- member = stack.pop()!
158
- stacked.delete(member)
159
- component.push(member)
160
- } while (member !== key)
161
- components.push(component.sort())
162
- }
163
-
164
- for (const key of [...units.keys()].sort()) {
165
- if (!indices.has(key)) visit(key)
166
- }
167
- return components
168
- }
169
-
170
- function topologicallyOrderedComponents(units: Map<string, { edges: Set<string> }>): string[][] {
171
- const components = stronglyConnectedComponents(units)
172
- const componentByUnit = new Map<string, number>()
173
- components.forEach((component, index) => {
174
- for (const key of component) componentByUnit.set(key, index)
175
- })
176
-
177
- const edges = components.map(() => new Set<number>())
178
- const indegrees = components.map(() => 0)
179
- for (const [unit, value] of units) {
180
- const from = componentByUnit.get(unit)!
181
- for (const dependency of value.edges) {
182
- const to = componentByUnit.get(dependency)
183
- if (to === undefined || to === from || edges[from].has(to)) continue
184
- edges[from].add(to)
185
- indegrees[to] += 1
186
- }
187
- }
188
-
189
- const available = components
190
- .map((_, index) => index)
191
- .filter((index) => indegrees[index] === 0)
192
- .sort((left, right) => components[left].join('\0').localeCompare(components[right].join('\0')))
193
- const ordered: string[][] = []
194
- while (available.length > 0) {
195
- const index = available.shift()!
196
- ordered.push(components[index])
197
- for (const dependency of edges[index]) {
198
- indegrees[dependency] -= 1
199
- if (indegrees[dependency] === 0) {
200
- available.push(dependency)
201
- available.sort((left, right) =>
202
- components[left].join('\0').localeCompare(components[right].join('\0')),
203
- )
204
- }
205
- }
206
- }
207
- return ordered
58
+ function vendorLocation(id: string) {
59
+ if (id.startsWith('\0') || isStyleModule(id)) return undefined
60
+ return moduleLocation(id)
208
61
  }
209
62
 
210
- function assignBuckets(
211
- units: Map<string, { edges: Set<string>, size: number }>,
212
- bucketCount: number,
213
- ): ReadonlyMap<string, string> {
214
- const components = topologicallyOrderedComponents(units)
215
- const totalSize = components.reduce(
216
- (total, component) => total + component.reduce((size, key) => size + units.get(key)!.size, 0),
217
- 0,
218
- )
219
- const assignments = new Map<string, string>()
220
- let consumedSize = 0
221
- for (const component of components) {
222
- const componentSize = component.reduce((size, key) => size + units.get(key)!.size, 0)
223
- const midpoint = consumedSize + componentSize / 2
224
- const bucket = Math.min(
225
- Math.floor((midpoint * bucketCount) / Math.max(totalSize, 1)),
226
- bucketCount - 1,
227
- )
228
- for (const key of component) assignments.set(key, String(bucket))
229
- consumedSize += componentSize
230
- }
231
- return assignments
63
+ function matchesPackageFamily(id: string, names: readonly string[]): boolean {
64
+ const name = vendorLocation(id)?.name
65
+ return Boolean(name && names.some((candidate) => name === candidate || name.startsWith(`${candidate}/`)))
232
66
  }
233
67
 
234
- function initialChunkAssignments(
235
- meta: Parameters<Rollup.GetManualChunk>[1],
236
- owners: ReadonlyMap<string, readonly string[]>,
237
- ): ReadonlyMap<string, string> {
238
- const units = new Map<string, { edges: Set<string>, size: number }>()
239
- const unitByModule = new Map<string, string>()
240
-
241
- for (const id of [...meta.getModuleIds()].sort()) {
242
- if (!isInitialOnly(owners.get(id) ?? [])) continue
243
- const key = moduleUnitKey(id)
244
- if (!key) continue
245
- const unit = units.get(key) ?? { edges: new Set(), size: 0 }
246
- unit.size += meta.getModuleInfo(id)?.code?.length ?? 1
247
- units.set(key, unit)
248
- unitByModule.set(id, key)
249
- }
250
-
251
- for (const [id, key] of unitByModule) {
252
- for (const importedId of meta.getModuleInfo(id)?.importedIds ?? []) {
253
- const importedKey = unitByModule.get(importedId)
254
- if (importedKey && importedKey !== key) units.get(key)!.edges.add(importedKey)
255
- }
256
- }
257
-
258
- const unitAssignments = assignBuckets(units, INITIAL_CHUNK_BUCKETS)
259
- return new Map([...unitByModule].map(([id, key]) => [id, unitAssignments.get(key) ?? '0']))
68
+ function matchesPackageEntry(id: string, packageName: string, entry: string): boolean {
69
+ const location = vendorLocation(id)
70
+ return location?.name === packageName && location.path[0] === entry
260
71
  }
261
72
 
262
- function asyncComponentAssignments(
263
- meta: Parameters<Rollup.GetManualChunk>[1],
264
- owners: ReadonlyMap<string, readonly string[]>,
265
- ): ReadonlyMap<string, string> {
266
- const modulesByGroup = new Map<string, Map<string, string>>()
267
- const unitsByGroup = new Map<string, Map<string, { edges: Set<string>, size: number }>>()
268
-
269
- for (const id of [...meta.getModuleIds()].sort()) {
270
- const location = moduleLocation(id)
271
- const moduleOwners = owners.get(id) ?? []
272
- if (isInitialOnly(moduleOwners) || location?.path[0] !== 'components' || !location.path[1])
273
- continue
274
- const group = `${asyncOwnerLabel(moduleOwners)}\0${location.name}`
275
- const key = `${group}\0${location.path[1]}`
276
- const units = unitsByGroup.get(group) ?? new Map()
277
- const unit = units.get(key) ?? { edges: new Set<string>(), size: 0 }
278
- unit.size += meta.getModuleInfo(id)?.code?.length ?? 1
279
- units.set(key, unit)
280
- unitsByGroup.set(group, units)
281
- const modules = modulesByGroup.get(group) ?? new Map()
282
- modules.set(id, key)
283
- modulesByGroup.set(group, modules)
284
- }
285
-
286
- const assignments = new Map<string, string>()
287
- for (const [group, modules] of modulesByGroup) {
288
- const units = unitsByGroup.get(group)!
289
- for (const [id, key] of modules) {
290
- for (const importedId of meta.getModuleInfo(id)?.importedIds ?? []) {
291
- const importedKey = modules.get(importedId)
292
- if (importedKey && importedKey !== key) units.get(key)!.edges.add(importedKey)
293
- }
294
- }
295
- const buckets = assignBuckets(units, ASYNC_COMPONENT_CHUNK_BUCKETS)
296
- for (const [id, key] of modules) assignments.set(id, buckets.get(key) ?? '0')
297
- }
298
- return assignments
73
+ function dynamicPackageGroup(
74
+ id: string,
75
+ directory?: 'components' | 'languages' | 'locale',
76
+ ): string | undefined {
77
+ const location = vendorLocation(id)
78
+ if (!location || location.name === 'element-plus') return undefined
79
+ if (directory && location.path[0] !== directory) return undefined
80
+ const suffix = directory === 'components' ? '-components' : directory ? `-${chunkName(directory)}` : ''
81
+ return `vendor-${chunkName(location.name)}${suffix}`
299
82
  }
300
83
 
301
- export function createAdminManualChunks(): Rollup.GetManualChunk {
302
- let owners: ReadonlyMap<string, readonly string[]> | undefined
303
- let initialChunks: ReadonlyMap<string, string> | undefined
304
- let componentChunks: ReadonlyMap<string, string> | undefined
305
- return (id, meta) => {
306
- if (id.startsWith('\0') || isStyleModule(id)) return undefined
307
- const location = moduleLocation(id)
308
- if (!location) return undefined
309
-
310
- owners ??= moduleOwners(meta)
311
- initialChunks ??= initialChunkAssignments(meta, owners)
312
- componentChunks ??= asyncComponentAssignments(meta, owners)
313
- const currentOwners = owners.get(id) ?? []
314
- // These runtime families are shared by the same feature surfaces; keeping
315
- // them together avoids repeated module wrappers across async chunks.
316
- if (location.name === 'vue' || location.name.startsWith('@vue/')) return 'vendor-vue-runtime'
317
- if (location.name === 'vue-i18n' || location.name.startsWith('@intlify/'))
318
- return 'vendor-vue-i18n'
319
- if (location.name.startsWith('@vueuse/')) return 'vendor-vueuse'
320
- if (location.name.startsWith('@floating-ui/') || location.name === '@sxzz/popperjs-es')
321
- return 'vendor-positioning'
322
- if (
323
- location.name === 'og-table' ||
324
- location.name === 'og-table-search' ||
325
- location.name === 'og-search'
326
- ) {
327
- return 'vendor-table-suite'
328
- }
329
- if (isInitialOnly(currentOwners)) return `vendor-initial-${initialChunks.get(id) ?? '0'}`
330
- if (currentOwners.includes('entry')) return undefined
331
- if (location.name === 'element-plus') return undefined
332
-
333
- const owner = asyncOwnerLabel(currentOwners)
334
- const packageName = chunkName(location.name)
335
- const [directory, moduleName] = location.path
336
- if (splitModuleDirectories.has(directory)) {
337
- if (directory === 'components' && moduleName)
338
- return `vendor-${owner}-${packageName}-components-${componentChunks.get(id) ?? '0'}`
339
- return `vendor-${owner}-${packageName}-${chunkName(directory)}`
340
- }
341
- return `vendor-${owner}-${packageName}`
84
+ export function createAdminCodeSplitting(): AdminCodeSplitting {
85
+ return {
86
+ groups: [
87
+ {
88
+ name: 'vendor-vue-runtime',
89
+ test: (id) => matchesPackageFamily(id, ['vue', '@vue']),
90
+ priority: 100,
91
+ },
92
+ {
93
+ name: 'vendor-vue-i18n',
94
+ test: (id) => matchesPackageFamily(id, ['vue-i18n', '@intlify']),
95
+ priority: 95,
96
+ },
97
+ {
98
+ name: 'vendor-vueuse',
99
+ test: (id) => matchesPackageFamily(id, ['@vueuse']),
100
+ priority: 90,
101
+ },
102
+ {
103
+ name: 'vendor-positioning',
104
+ test: (id) => matchesPackageFamily(id, ['@floating-ui', '@sxzz/popperjs-es']),
105
+ priority: 85,
106
+ },
107
+ {
108
+ name: 'vendor-table-suite',
109
+ test: (id) =>
110
+ matchesPackageFamily(id, [
111
+ 'og-table',
112
+ 'og-table-search',
113
+ 'og-search',
114
+ '@origen-ui/table',
115
+ '@origen-ui/table-search',
116
+ '@origen-ui/search',
117
+ ]) ||
118
+ matchesPackageEntry(id, 'origen-ui', 'table') ||
119
+ matchesPackageEntry(id, 'origen-ui', 'table-search') ||
120
+ matchesPackageEntry(id, 'origen-ui', 'search'),
121
+ // Rolldown can otherwise split this mutually dependent family into a
122
+ // circular chunk-evaluation edge before Element Plus initializes.
123
+ priority: 80,
124
+ },
125
+ {
126
+ name: 'vendor-initial',
127
+ test: (id) => Boolean(vendorLocation(id)),
128
+ tags: ['$initial'],
129
+ maxSize: MAX_INITIAL_VENDOR_CHUNK_BYTES,
130
+ priority: 60,
131
+ },
132
+ {
133
+ name: (id) => dynamicPackageGroup(id, 'components'),
134
+ entriesAware: true,
135
+ maxSize: MAX_ASYNC_VENDOR_CHUNK_BYTES,
136
+ priority: 50,
137
+ },
138
+ {
139
+ name: (id) => dynamicPackageGroup(id, 'languages'),
140
+ entriesAware: true,
141
+ priority: 40,
142
+ },
143
+ {
144
+ name: (id) => dynamicPackageGroup(id, 'locale'),
145
+ entriesAware: true,
146
+ priority: 40,
147
+ },
148
+ {
149
+ name: (id) => dynamicPackageGroup(id),
150
+ entriesAware: true,
151
+ maxSize: MAX_ASYNC_VENDOR_CHUNK_BYTES,
152
+ priority: 30,
153
+ },
154
+ ],
342
155
  }
343
156
  }
344
157
 
@@ -347,7 +160,9 @@ function normalizeEmptyChunks(): Plugin {
347
160
  name: 'admin-normalize-empty-chunks',
348
161
  renderChunk(code) {
349
162
  const payload = code.replaceAll(/\/\*[\s\S]*?\*\//g, '').trim()
350
- if (!payload || /^export\s*\{\s*\}\s*;?$/.test(payload)) return 'void 0;\n'
163
+ if (!payload || /^export\s*\{\s*\}\s*;?$/.test(payload)) {
164
+ return { code: 'void 0;\n', map: { mappings: '' } }
165
+ }
351
166
  return null
352
167
  },
353
168
  generateBundle(_options, bundle) {
@@ -382,10 +197,12 @@ export function createAdminBuildOptions(isDebugBuild: boolean): UserConfig['buil
382
197
  return {
383
198
  outDir: 'dist',
384
199
  sourcemap: isDebugBuild,
385
- minify: isDebugBuild ? false : 'esbuild',
200
+ // Keep the oxc minifier: it honours the `oxc.dropConsole` production
201
+ // policy, while overriding the minifier would silently keep console calls.
202
+ minify: !isDebugBuild,
386
203
  target: 'es2020',
387
204
  modulePreload: false,
388
- rollupOptions: {
205
+ rolldownOptions: {
389
206
  onwarn(warning, warn) {
390
207
  if (warning.code === 'EMPTY_BUNDLE') return
391
208
  if (
@@ -397,8 +214,16 @@ export function createAdminBuildOptions(isDebugBuild: boolean): UserConfig['buil
397
214
  warn(warning)
398
215
  },
399
216
  output: {
400
- manualChunks: createAdminManualChunks(),
401
- onlyExplicitManualChunks: true,
217
+ codeSplitting: createAdminCodeSplitting(),
218
+ ...(!isDebugBuild
219
+ ? {
220
+ minify: {
221
+ compress: { dropConsole: true, dropDebugger: true },
222
+ mangle: true,
223
+ codegen: true,
224
+ },
225
+ }
226
+ : {}),
402
227
  },
403
228
  },
404
229
  }
@@ -7,7 +7,7 @@ import { loadEnv } from 'vite'
7
7
  import { defineConfig } from 'vitest/config'
8
8
  // This file is copied to the scaffold root, where the shared policy is copied
9
9
  // with the application source as ./vite.build-policy.ts.
10
- import { createAdminBuildOptions, createAdminBuildPlugins } from './vite.build-policy'
10
+ import { createAdminBuildOptions, createAdminBuildPlugins } from './vite.build-policy.js'
11
11
 
12
12
  export default defineConfig(({ command, mode }) => {
13
13
  const loadedEnv = loadEnv(mode, process.cwd(), '')
@@ -17,10 +17,9 @@ export default defineConfig(({ command, mode }) => {
17
17
  return {
18
18
  plugins: [vue(), vueJsx(), ...createAdminBuildPlugins(), ElementPlus({ useSource: true })],
19
19
  resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
20
- esbuild: {
21
- jsx: 'preserve',
22
- jsxImportSource: 'vue',
23
- ...(command === 'build' && !isDebugBuild ? { drop: ['console', 'debugger'] } : {}),
20
+ oxc: {
21
+ jsx: { runtime: 'automatic', importSource: 'vue' },
22
+ ...(command === 'build' && !isDebugBuild ? { dropConsole: true, dropDebugger: true } : {}),
24
23
  },
25
24
  server: {
26
25
  port: 5175,