@mterminal/manifest-validator 0.1.0 → 0.2.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/src/index.test.ts +44 -0
- package/src/index.ts +12 -2
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ interface PanelContribution {
|
|
|
22
22
|
id: string;
|
|
23
23
|
title: string;
|
|
24
24
|
icon?: string;
|
|
25
|
-
location: 'sidebar' | 'sidebar.bottom' | 'bottombar'
|
|
25
|
+
location: 'sidebar' | 'sidebar.bottom' | 'bottombar' | `workspace-section.${string}`;
|
|
26
26
|
initialCollapsed?: boolean;
|
|
27
27
|
}
|
|
28
28
|
interface StatusBarContribution {
|
package/dist/index.js
CHANGED
|
@@ -161,7 +161,9 @@ function readContributes(v, errors) {
|
|
|
161
161
|
if (!isObject(x)) return false;
|
|
162
162
|
if (typeof x.id !== "string" || typeof x.title !== "string") return false;
|
|
163
163
|
const loc = x.location;
|
|
164
|
-
|
|
164
|
+
const isBuiltinSlot = loc === "sidebar" || loc === "sidebar.bottom" || loc === "bottombar";
|
|
165
|
+
const isWorkspaceSectionSlot = typeof loc === "string" && loc.startsWith("workspace-section.") && loc.length > "workspace-section.".length;
|
|
166
|
+
if (!isBuiltinSlot && !isWorkspaceSectionSlot) {
|
|
165
167
|
errors.push(`panel "${String(x.id)}" has invalid location "${String(loc)}"`);
|
|
166
168
|
return false;
|
|
167
169
|
}
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -95,6 +95,50 @@ describe('validateManifest', () => {
|
|
|
95
95
|
expect(result.ok).toBe(false)
|
|
96
96
|
})
|
|
97
97
|
|
|
98
|
+
it('accepts panels with built-in location slots', () => {
|
|
99
|
+
const m: any = baseManifest()
|
|
100
|
+
m.mterminal.contributes = {
|
|
101
|
+
panels: [
|
|
102
|
+
{ id: 'p1', title: 'one', location: 'sidebar' },
|
|
103
|
+
{ id: 'p2', title: 'two', location: 'sidebar.bottom' },
|
|
104
|
+
{ id: 'p3', title: 'three', location: 'bottombar' },
|
|
105
|
+
],
|
|
106
|
+
}
|
|
107
|
+
const result = validateManifest(m)
|
|
108
|
+
expect(result.ok).toBe(true)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('accepts panels mounted in a workspace-section.<id> slot', () => {
|
|
112
|
+
const m: any = baseManifest()
|
|
113
|
+
m.mterminal.contributes = {
|
|
114
|
+
panels: [
|
|
115
|
+
{ id: 'p', title: 'remote', location: 'workspace-section.remote-ssh' },
|
|
116
|
+
],
|
|
117
|
+
}
|
|
118
|
+
const result = validateManifest(m)
|
|
119
|
+
expect(result.ok).toBe(true)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('rejects panel with unknown location', () => {
|
|
123
|
+
const m: any = baseManifest()
|
|
124
|
+
m.mterminal.contributes = {
|
|
125
|
+
panels: [{ id: 'p', title: 't', location: 'nowhere' }],
|
|
126
|
+
}
|
|
127
|
+
const result = validateManifest(m)
|
|
128
|
+
expect(result.ok).toBe(false)
|
|
129
|
+
if (!result.ok)
|
|
130
|
+
expect(result.errors.join('\n')).toMatch(/invalid location "nowhere"/)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('rejects panel with empty workspace-section suffix', () => {
|
|
134
|
+
const m: any = baseManifest()
|
|
135
|
+
m.mterminal.contributes = {
|
|
136
|
+
panels: [{ id: 'p', title: 't', location: 'workspace-section.' }],
|
|
137
|
+
}
|
|
138
|
+
const result = validateManifest(m)
|
|
139
|
+
expect(result.ok).toBe(false)
|
|
140
|
+
})
|
|
141
|
+
|
|
98
142
|
it('accepts theme-only declarative manifest', () => {
|
|
99
143
|
const m: any = baseManifest()
|
|
100
144
|
delete m.main
|
package/src/index.ts
CHANGED
|
@@ -32,7 +32,11 @@ export interface PanelContribution {
|
|
|
32
32
|
id: string
|
|
33
33
|
title: string
|
|
34
34
|
icon?: string
|
|
35
|
-
location:
|
|
35
|
+
location:
|
|
36
|
+
| 'sidebar'
|
|
37
|
+
| 'sidebar.bottom'
|
|
38
|
+
| 'bottombar'
|
|
39
|
+
| `workspace-section.${string}`
|
|
36
40
|
initialCollapsed?: boolean
|
|
37
41
|
}
|
|
38
42
|
|
|
@@ -369,7 +373,13 @@ function readContributes(v: unknown, errors: string[]): ExtensionManifest['contr
|
|
|
369
373
|
if (!isObject(x)) return false
|
|
370
374
|
if (typeof x.id !== 'string' || typeof x.title !== 'string') return false
|
|
371
375
|
const loc = x.location
|
|
372
|
-
|
|
376
|
+
const isBuiltinSlot =
|
|
377
|
+
loc === 'sidebar' || loc === 'sidebar.bottom' || loc === 'bottombar'
|
|
378
|
+
const isWorkspaceSectionSlot =
|
|
379
|
+
typeof loc === 'string' &&
|
|
380
|
+
loc.startsWith('workspace-section.') &&
|
|
381
|
+
loc.length > 'workspace-section.'.length
|
|
382
|
+
if (!isBuiltinSlot && !isWorkspaceSectionSlot) {
|
|
373
383
|
errors.push(`panel "${String(x.id)}" has invalid location "${String(loc)}"`)
|
|
374
384
|
return false
|
|
375
385
|
}
|