Skip to content

Commit

Permalink
fix(vite): fix watch schema for build executor to object or boolean i… (
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Feb 2, 2023
1 parent f794a1f commit 259d4b2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/generated/packages/vite/executors/build.json
Expand Up @@ -81,8 +81,8 @@
},
"watch": {
"description": "Enable re-building when files change.",
"type": "object",
"default": null
"oneOf": [{ "type": "boolean" }, { "type": "object" }],
"default": false
}
},
"definitions": {},
Expand Down
20 changes: 17 additions & 3 deletions packages/vite/src/executors/build/build.impl.ts
Expand Up @@ -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),
}
);

Expand All @@ -37,7 +38,7 @@ export default async function* viteBuildExecutor(
) {
await copyAssets(
{
outputPath: options.outputPath,
outputPath: normalizedOptions.outputPath,
assets: [
{
input: projectRoot,
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion packages/vite/src/executors/build/schema.d.ts
Expand Up @@ -12,5 +12,5 @@ export interface ViteBuildExecutorOptions {
logLevel?: 'info' | 'warn' | 'error' | 'silent';
mode?: string;
ssr?: boolean | string;
watch?: object | null;
watch?: object | boolean;
}
11 changes: 9 additions & 2 deletions packages/vite/src/executors/build/schema.json
Expand Up @@ -121,8 +121,15 @@
},
"watch": {
"description": "Enable re-building when files change.",
"type": "object",
"default": null
"oneOf": [
{
"type": "boolean"
},
{
"type": "object"
}
],
"default": false
}
},
"definitions": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/utils/options-utils.ts
Expand Up @@ -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'],
};
}

Expand Down

1 comment on commit 259d4b2

@vercel
Copy link

@vercel vercel bot commented on 259d4b2 Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.