Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add JSON schemas for the manifests generated by Vite #7960

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions packages/vite/schemas/manifest.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://vitejs.dev/schemas/manifest.json",
"title": "Vite Manifest",
"type": "object",
"patternProperties": {
"^.+$": {
nhedger marked this conversation as resolved.
Show resolved Hide resolved
"$ref": "#/$defs/chunk"
}
},
"$defs": {
"chunk": {
"type": "object",
"properties": {
"src": {
"type": "string",
"description": "Source file of the chunk."
},
"file": {
"type": "string",
"description": "A JS filename, relative to the outDir."
},
"css": {
"type": "array",
"description": "CSS files imported by the chunk.",
"items": {
"type": "string",
"description": "A CSS filename, relative to the outDir."
}
},
"assets": {
"type": "array",
"description": "Assets imported by the chunk.",
"items": {
"type": "string",
"description": "An asset filename, relative to the outDir."
}
},
"isEntry": {
"type": "boolean",
"description": "Whether the chunk is an entry."
},
"isDynamicEntry": {
"type": "boolean",
"description": "Whether the chunk is a dynamic entry."
},
"imports": {
"type": "array",
"description": "Imports of the chunk.",
"items": {
"type": "string",
"description": "A key for an existing JS entry in the manifest."
}
},
"dynamicImports": {
"type": "array",
"description": "Dynamic imports of the chunk.",
"items": {
"type": "string",
"description": "A key for an existing JS entry in the manifest."
}
}
},
"additionalProperties": true,
"required": ["file"]
}
}
}
14 changes: 14 additions & 0 deletions packages/vite/schemas/ssr-manifest.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://vitejs.dev/schemas/ssr-manifest.json",
"title": "Vite SSR Manifest",
"type": "object",
"patternProperties": {
"^.+$": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"main.js": {
"file": "test",
"customProperty": "custom value"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"main.js": {
"src": "main.js",
"isEntry": true,
"dynamicImports": ["views/foo.js"],
"css": ["assets/main.b82dbe22.css"],
"assets": ["assets/asset.0ab0f9cd.png"]
},
"views/foo.js": {
"file": "assets/foo.869aea0d.js",
"src": "views/foo.js",
"isDynamicEntry": true,
"imports": ["_shared.83069a53.js"]
},
"_shared.83069a53.js": {
"file": "assets/shared.83069a53.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Ajv2020 from 'ajv/dist/2020'

const schema = require('../../../../packages/vite/schemas/manifest.schema.json')
const ajv = new Ajv2020()
const validate = ajv.compile(schema)

describe('manifest json schema', () => {
test('valid manifest validates against manifest schema', () => {
const manifest = require('./valid.manifest.json')
const result = validate(manifest)
expect(result).toBeTruthy()
})

test('invalid manifest does not validate against manifest schema', () => {
const manifest = require('./invalid.manifest.json')
const result = validate(manifest)
expect(result).toBeFalsy()
})

test('manifest chunks support additional properties', () => {
const manifest = require('./additionalProperties.manifest.json')
const result = validate(manifest)
expect(result).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"main.js": {
"file": "assets/main.4889e940.js",
"src": "main.js",
"isEntry": true,
"dynamicImports": ["views/foo.js"],
"css": ["assets/main.b82dbe22.css"],
"assets": ["assets/asset.0ab0f9cd.png"]
},
"views/foo.js": {
"file": "assets/foo.869aea0d.js",
"src": "views/foo.js",
"isDynamicEntry": true,
"imports": ["_shared.83069a53.js"]
},
"_shared.83069a53.js": {
"file": "assets/shared.83069a53.js"
}
}
1 change: 1 addition & 0 deletions playground/backend-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"devDependencies": {
"sass": "^1.53.0",
"tailwindcss": "^3.1.4",
"ajv": "^8.11.0",
"fast-glob": "^3.2.11"
}
}
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.