fix(vite): fix watch schema for build executor to object or boolean i… (#14756)

This commit is contained in:
Chau Tran 2023-02-02 09:58:37 -06:00 committed by GitHub
parent f794a1f436
commit 259d4b29cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 9 deletions

View File

@ -81,8 +81,8 @@
},
"watch": {
"description": "Enable re-building when files change.",
"type": "object",
"default": null
"oneOf": [{ "type": "boolean" }, { "type": "object" }],
"default": false
}
},
"definitions": {},

View File

@ -15,13 +15,14 @@ export default async function* viteBuildExecutor(
options: ViteBuildExecutorOptions,
context: ExecutorContext
) {
const normalizedOptions = normalizeOptions(options);
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
const buildConfig = mergeConfig(
getViteSharedConfig(options, false, context),
getViteSharedConfig(normalizedOptions, false, context),
{
build: getViteBuildOptions(options, context),
build: getViteBuildOptions(normalizedOptions, context),
}
);
@ -37,7 +38,7 @@ export default async function* viteBuildExecutor(
) {
await copyAssets(
{
outputPath: options.outputPath,
outputPath: normalizedOptions.outputPath,
assets: [
{
input: projectRoot,
@ -79,3 +80,16 @@ function runInstance(options: InlineConfig) {
...options,
});
}
function normalizeOptions(options: ViteBuildExecutorOptions) {
const normalizedOptions = { ...options };
// coerce watch to null or {} to match with Vite's watch config
if (options.watch === false) {
normalizedOptions.watch = null;
} else if (options.watch === true) {
normalizedOptions.watch = {};
}
return normalizedOptions;
}

View File

@ -12,5 +12,5 @@ export interface ViteBuildExecutorOptions {
logLevel?: 'info' | 'warn' | 'error' | 'silent';
mode?: string;
ssr?: boolean | string;
watch?: object | null;
watch?: object | boolean;
}

View File

@ -121,8 +121,15 @@
},
"watch": {
"description": "Enable re-building when files change.",
"type": "object",
"default": null
"oneOf": [
{
"type": "boolean"
},
{
"type": "object"
}
],
"default": false
}
},
"definitions": {},

View File

@ -142,7 +142,7 @@ export function getViteBuildOptions(
manifest: options.manifest,
ssrManifest: options.ssrManifest,
ssr: options.ssr,
watch: options.watch,
watch: options.watch as BuildOptions['watch'],
};
}