From d04bea0f761606d93c0150558ba0e85ec377b729 Mon Sep 17 00:00:00 2001 From: Sukaato Date: Wed, 20 Mar 2024 12:18:06 +0100 Subject: [PATCH] fix(compiler): Allow OutputTargetCustom to be called on devMode --- src/compiler/output-targets/index.ts | 2 ++ src/compiler/output-targets/output-custom.ts | 17 ++++++++--------- src/compiler/output-targets/output-docs.ts | 4 ---- src/declarations/stencil-public-compiler.ts | 10 +++++++++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/compiler/output-targets/index.ts b/src/compiler/output-targets/index.ts index d6b680cd42f3..e88d7641f049 100644 --- a/src/compiler/output-targets/index.ts +++ b/src/compiler/output-targets/index.ts @@ -6,6 +6,7 @@ import { outputCollection } from './dist-collection'; import { outputCustomElements } from './dist-custom-elements'; import { outputHydrateScript } from './dist-hydrate-script'; import { outputLazy } from './dist-lazy/lazy-output'; +import { outputCustom } from './output-custom'; import { outputDocs } from './output-docs'; import { outputLazyLoader } from './output-lazy-loader'; import { outputTypes } from './output-types'; @@ -45,6 +46,7 @@ export const generateOutputTargets = async ( // since it validates files were created await outputDocs(config, compilerCtx, buildCtx); await outputTypes(config, compilerCtx, buildCtx); + await outputCustom(config, compilerCtx, buildCtx); timeSpan.finish('generate outputs finished'); }; diff --git a/src/compiler/output-targets/output-custom.ts b/src/compiler/output-targets/output-custom.ts index 2fe17c622cc9..e590247b55aa 100644 --- a/src/compiler/output-targets/output-custom.ts +++ b/src/compiler/output-targets/output-custom.ts @@ -1,15 +1,14 @@ import { catchError, isOutputTargetCustom } from '@utils'; import type * as d from '../../declarations'; +import { generateDocData } from '../docs/generate-doc-data'; -export const outputCustom = async ( - config: d.ValidatedConfig, - compilerCtx: d.CompilerCtx, - buildCtx: d.BuildCtx, - docs: d.JsonDocs, - outputTargets: d.OutputTarget[], -) => { - const customOutputTargets = outputTargets.filter(isOutputTargetCustom); +export const outputCustom = async (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => { + const task = config.devMode ? 'run' : 'build'; + const docsData = await generateDocData(config, compilerCtx, buildCtx); + const customOutputTargets = config.outputTargets + .filter(isOutputTargetCustom) + .filter((o) => (o.task === undefined ? true : o.task === task)); if (customOutputTargets.length === 0) { return; } @@ -18,7 +17,7 @@ export const outputCustom = async ( customOutputTargets.map(async (o) => { const timespan = buildCtx.createTimeSpan(`generating ${o.name} started`); try { - await o.generator(config, compilerCtx, buildCtx, docs); + await o.generator(config, compilerCtx, buildCtx, docsData); } catch (e: any) { catchError(buildCtx.diagnostics, e); } diff --git a/src/compiler/output-targets/output-docs.ts b/src/compiler/output-targets/output-docs.ts index b01d7bd451b9..ac12b47b934d 100644 --- a/src/compiler/output-targets/output-docs.ts +++ b/src/compiler/output-targets/output-docs.ts @@ -1,5 +1,4 @@ import { - isOutputTargetCustom, isOutputTargetDocsCustom, isOutputTargetDocsJson, isOutputTargetDocsReadme, @@ -12,7 +11,6 @@ import { generateDocData } from '../docs/generate-doc-data'; import { generateJsonDocs } from '../docs/json'; import { generateReadmeDocs } from '../docs/readme'; import { generateVscodeDocs } from '../docs/vscode'; -import { outputCustom } from './output-custom'; /** * Generate documentation-related output targets @@ -30,7 +28,6 @@ export const outputDocs = async ( } const docsOutputTargets = config.outputTargets.filter( (o) => - isOutputTargetCustom(o) || isOutputTargetDocsReadme(o) || isOutputTargetDocsJson(o) || isOutputTargetDocsCustom(o) || @@ -51,6 +48,5 @@ export const outputDocs = async ( generateJsonDocs(config, compilerCtx, docsData, docsOutputTargets), generateVscodeDocs(compilerCtx, docsData, docsOutputTargets), generateCustomDocs(config, docsData, docsOutputTargets), - outputCustom(config, compilerCtx, buildCtx, docsData, docsOutputTargets), ]); }; diff --git a/src/declarations/stencil-public-compiler.ts b/src/declarations/stencil-public-compiler.ts index d638add9ddec..841e6e012ee8 100644 --- a/src/declarations/stencil-public-compiler.ts +++ b/src/declarations/stencil-public-compiler.ts @@ -1,5 +1,6 @@ import type { ConfigFlags } from '../cli/config-flags'; import type { PrerenderUrlResults, PrintLine } from '../internal'; +import type { BuildCtx, CompilerCtx } from './stencil-private'; import type { JsonDocs } from './stencil-public-docs'; export * from './stencil-public-docs'; @@ -2233,8 +2234,15 @@ export interface OutputTargetHydrate extends OutputTargetBase { export interface OutputTargetCustom extends OutputTargetBase { type: 'custom'; name: string; + /** + * Indicate in wich mode the output target has to be executed. + * By default if nothing is specified it run for both. + * - `"run"`: Executed in dev mode on every change in your code + * - `"build"`: Executed only on build + */ + task?: 'run' | 'build'; validate?: (config: Config, diagnostics: Diagnostic[]) => void; - generator: (config: Config, compilerCtx: any, buildCtx: any, docs: any) => Promise; + generator: (config: Config, compilerCtx: CompilerCtx, buildCtx: BuildCtx, docs: JsonDocs) => Promise; copy?: CopyTask[]; }