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": { "watch": {
"description": "Enable re-building when files change.", "description": "Enable re-building when files change.",
"type": "object", "oneOf": [{ "type": "boolean" }, { "type": "object" }],
"default": null "default": false
} }
}, },
"definitions": {}, "definitions": {},

View File

@ -15,13 +15,14 @@ export default async function* viteBuildExecutor(
options: ViteBuildExecutorOptions, options: ViteBuildExecutorOptions,
context: ExecutorContext context: ExecutorContext
) { ) {
const normalizedOptions = normalizeOptions(options);
const projectRoot = const projectRoot =
context.projectsConfigurations.projects[context.projectName].root; context.projectsConfigurations.projects[context.projectName].root;
const buildConfig = mergeConfig( 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( await copyAssets(
{ {
outputPath: options.outputPath, outputPath: normalizedOptions.outputPath,
assets: [ assets: [
{ {
input: projectRoot, input: projectRoot,
@ -79,3 +80,16 @@ function runInstance(options: InlineConfig) {
...options, ...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'; logLevel?: 'info' | 'warn' | 'error' | 'silent';
mode?: string; mode?: string;
ssr?: boolean | string; ssr?: boolean | string;
watch?: object | null; watch?: object | boolean;
} }

View File

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

View File

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