Skip to content

Commit e91b933

Browse files
authored
chore: extract kuma and me modules (#5094)
Extracts `kuma` and `me` modules to the main wiring root. I also undid using the local `$.sources` token in some modules. Local tokens are often mass exported and can therefore overwrite "global/app" tokens if they are named the same. `sources` usually use labels for registration anyway so we can just use local "throwaway tokens" to register them. --- Whilst doing this, I figured I could move our `htmlVars` unit-test-only-injection and make the `testing` module generic enough to be reused, which I then moved into `@/app/vue/testing.ts` Signed-off-by: John Cowen <john.cowen@konghq.com>
1 parent 7ef9cd0 commit e91b933

7 files changed

Lines changed: 22 additions & 23 deletions

File tree

packages/kuma-gui/src/app/application/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { routes } from './routes'
1313
import I18n from './services/i18n/I18n'
1414
import storage from './services/storage'
1515
import { difference } from '@/app/application/polyfills/Set.prototype.difference'
16-
import { services as kuma } from '@/app/kuma'
1716
import type { ServiceDefinition } from '@kumahq/container'
1817
import type { Component } from 'vue'
1918
import type { RouteRecordRaw } from 'vue-router'
@@ -282,7 +281,6 @@ export const services = (app: Record<string, Token>): ServiceDefinition[] => {
282281
app.sources,
283282
],
284283
}],
285-
...kuma(app),
286284
]
287285
}
288286
export const TOKENS = $

packages/kuma-gui/src/app/control-planes/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ import type { ServiceDefinition } from '@kumahq/container'
1111
type Token = ReturnType<typeof token>
1212

1313
const $ = {
14-
sources: token<ReturnType<typeof sources>>('control-planes.sources'),
1514
ControlPlaneStatus: token<typeof ControlPlaneStatus>('control-planes.components.ControlPlaneStatus'),
1615
ControlPlaneActionGroup: token<typeof ControlPlaneActionGroup>('control-planes.components.ControlPlaneActionGroup'),
1716
}
1817
export const services = (app: Record<string, Token>): ServiceDefinition[] => {
1918
return [
20-
[$.sources, {
19+
[token('control-planes.sources'), {
2120
service: sources,
2221
arguments: [
2322
app.env,

packages/kuma-gui/src/app/kuma/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import KumaTargetRef from '@/app/kuma/components/kuma-target-ref/KumaTargetRef.v
1212
import { ApiError } from '@/app/kuma/services/kuma-api/ApiError'
1313
import KumaApi from '@/app/kuma/services/kuma-api/KumaApi'
1414
import { RestClient } from '@/app/kuma/services/kuma-api/RestClient'
15-
import { services as me } from '@/app/me'
1615
import { useRouter } from '@/app/vue'
1716
import type { ServiceDefinition } from '@kumahq/container'
1817

@@ -155,7 +154,6 @@ const protocolHandler = (can: Can) => {
155154
}
156155
export const services = (app: Record<string, Token>): ServiceDefinition[] => {
157156
return [
158-
...me(app),
159157
[token('kuma.plugins'), {
160158
service: (i18n, can) => {
161159
return [

packages/kuma-gui/src/app/me/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ import { sources } from './sources'
44
import type { ServiceDefinition } from '@kumahq/container'
55

66
type Token = ReturnType<typeof token>
7-
type Sources = ReturnType<typeof sources>
87

9-
const $ = {
10-
sources: token<Sources>('me.sources'),
11-
}
128
export const services = (app: Record<string, Token>): ServiceDefinition[] => {
139
return [
14-
[$.sources, {
10+
[token('me.sources'), {
1511
service: sources,
1612
arguments: [
1713
app.storage,
@@ -22,4 +18,3 @@ export const services = (app: Record<string, Token>): ServiceDefinition[] => {
2218
}],
2319
]
2420
}
25-
export const TOKENS = $
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { defaultKumaHtmlVars as htmlVars } from '@kumahq/config/vite'
21
import { config } from '@vue/test-utils'
32

43
import type { PluginDefinition, ComponentDefinition } from '@/app/vue'
@@ -28,7 +27,4 @@ export const services: ServiceConfigurator = (app) => [
2827
app.plugins,
2928
],
3029
}],
31-
[app.htmlVars, {
32-
service: () => htmlVars,
33-
}],
3430
]

packages/kuma-gui/src/main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import { services as dataplanes } from '@/app/data-planes'
1111
import { services as externalServices } from '@/app/external-services'
1212
import { services as gateways } from '@/app/gateways'
1313
import { services as hostnameGenerators } from '@/app/hostname-generators'
14-
import { TOKENS } from '@/app/kuma'
14+
import { services as kuma, TOKENS as KUMA } from '@/app/kuma'
1515
import { services as legacyDataplanes } from '@/app/legacy-data-planes'
16+
import { services as me } from '@/app/me'
1617
import { services as meshIdentities } from '@/app/mesh-identities'
1718
import { services as meshTrusts } from '@/app/mesh-trusts'
1819
import { services as meshes } from '@/app/meshes'
@@ -28,13 +29,16 @@ async function mountVueApplication() {
2829
const $ = {
2930
...VUE,
3031
...APPLICATION,
31-
...TOKENS,
32+
...KUMA,
3233
}
3334

3435
const get = build(
3536
vue($),
3637
application($),
38+
me($),
3739
//
40+
kuma($),
41+
3842
configuration($),
3943
controlPlanes($),
4044
zones($),

packages/kuma-gui/test-support/main.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@
22
// When running via vitest this file is added first using
33
// vitest's `setupFiles` property, please see `/vite.config.production.ts`
44

5+
import { defaultKumaHtmlVars as htmlVars } from '@kumahq/config/vite'
56
import { get, container, build } from '@kumahq/container'
67
import { beforeEach, afterEach } from 'vitest'
78

8-
import { services as testing } from './index'
99
import { services as application, TOKENS as APPLICATION } from '@/app/application'
10-
import { TOKENS } from '@/app/kuma'
10+
import { services as kuma, TOKENS as KUMA } from '@/app/kuma'
1111
import { services as vue, TOKENS as VUE } from '@/app/vue'
12-
13-
;(async () => {
12+
import { services as testing } from '@/app/vue/testing'
13+
(async () => {
1414
const $ = {
1515
...VUE,
1616
...APPLICATION,
17-
...TOKENS,
17+
...KUMA,
1818
}
1919
build(
2020
application($),
2121
vue($),
2222
testing($),
23+
//
24+
kuma($),
25+
// during testing we don't have access to the index.html vars
26+
// so we inject them here so they are available during unit testing
27+
[
28+
[$.htmlVars, {
29+
service: () => htmlVars,
30+
}],
31+
],
2332
)
2433
// initializes vue-test-utils with any global components and/or plugins etc
2534
get($.app)

0 commit comments

Comments
 (0)