Skip to content

Commit

Permalink
chore(types): propagate ValidatedConfig for outputTargets (#3585)
Browse files Browse the repository at this point in the history
this commit propagates the `ValidatedConfig` type to areas of the
codebase that drops the number of `strictNullChecks` violations related
to the `outputTargets` field.

this commit does not update subfield-related violations of an
`OutputTarget` subtype.
  • Loading branch information
rwaskiewicz authored Sep 7, 2022
1 parent f30db9c commit 965323b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/compiler/bundle/server-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Plugin } from 'rollup';
import { isOutputTargetHydrate } from '../output-targets/output-utils';
import { isAbsolute } from 'path';

export const serverPlugin = (config: d.Config, platform: string): Plugin => {
export const serverPlugin = (config: d.ValidatedConfig, platform: string): Plugin => {
const isHydrateBundle = platform === 'hydrate';
const serverVarid = `@removed-server-code`;

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/output-targets/output-lazy-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isOutputTargetDistLazyLoader, relativeImport } from './output-utils';
import { join, relative } from 'path';
import { generatePreamble, normalizePath } from '@utils';

export const outputLazyLoader = async (config: d.Config, compilerCtx: d.CompilerCtx) => {
export const outputLazyLoader = async (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx) => {
const outputTargets = config.outputTargets.filter(isOutputTargetDistLazyLoader);
if (outputTargets.length === 0) {
return;
Expand All @@ -14,7 +14,7 @@ export const outputLazyLoader = async (config: d.Config, compilerCtx: d.Compiler
};

const generateLoader = async (
config: d.Config,
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
outputTarget: d.OutputTargetDistLazyLoader
) => {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const runPluginLoad = async (pluginCtx: PluginCtx, id: string) => {
};

export const runPluginTransforms = async (
config: d.Config,
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx,
id: string,
Expand Down
14 changes: 9 additions & 5 deletions src/compiler/style/global-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { isOutputTargetDistGlobalStyles } from '../output-targets/output-utils';
import { optimizeCss } from './optimize-css';
import { runPluginTransforms } from '../plugin/plugin';

export const generateGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
export const generateGlobalStyles = async (
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx
) => {
const outputTargets = config.outputTargets.filter(isOutputTargetDistGlobalStyles);
if (outputTargets.length === 0) {
return;
Expand All @@ -17,7 +21,7 @@ export const generateGlobalStyles = async (config: d.Config, compilerCtx: d.Comp
}
};

const buildGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
const buildGlobalStyles = async (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
let globalStylePath = config.globalStyle;
if (!globalStylePath) {
return null;
Expand Down Expand Up @@ -65,7 +69,7 @@ const buildGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx, b
return null;
};

const canSkipGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
const canSkipGlobalStyles = async (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
if (!compilerCtx.cachedGlobalStyle) {
return false;
}
Expand Down Expand Up @@ -104,7 +108,7 @@ const canSkipGlobalStyles = async (config: d.Config, compilerCtx: d.CompilerCtx,
};

const hasChangedImportFile = async (
config: d.Config,
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx,
filePath: string,
Expand All @@ -120,7 +124,7 @@ const hasChangedImportFile = async (
};

const hasChangedImportContent = async (
config: d.Config,
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx,
filePath: string,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transpile/run-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { updateStencilTypesImports } from '../types/stencil-types';
import { validateTranspiledComponents } from './validate-components';

export const runTsProgram = async (
config: d.Config,
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx,
tsBuilder: ts.BuilderProgram
Expand Down
6 changes: 3 additions & 3 deletions src/testing/testing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ export function expectFilesDoNotExist(fs: InMemoryFileSystem, filePaths: string[
}
}

export function getAppScriptUrl(config: d.Config, browserUrl: string) {
export function getAppScriptUrl(config: d.ValidatedConfig, browserUrl: string) {
const appFileName = `${config.fsNamespace}.esm.js`;
return getAppUrl(config, browserUrl, appFileName);
}

export function getAppStyleUrl(config: d.Config, browserUrl: string) {
export function getAppStyleUrl(config: d.ValidatedConfig, browserUrl: string) {
if (config.globalStyle) {
const appFileName = `${config.fsNamespace}.css`;
return getAppUrl(config, browserUrl, appFileName);
}
return null;
}

function getAppUrl(config: d.Config, browserUrl: string, appFileName: string) {
function getAppUrl(config: d.ValidatedConfig, browserUrl: string, appFileName: string) {
const wwwOutput = config.outputTargets.find(isOutputTargetWww);
if (wwwOutput) {
const appBuildDir = wwwOutput.buildDir;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const hasDependency = (buildCtx: d.BuildCtx, depName: string): boolean =>

export const getDynamicImportFunction = (namespace: string) => `__sc_import_${namespace.replace(/\s|-/g, '_')}`;

export const readPackageJson = async (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
export const readPackageJson = async (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
try {
const pkgJson = await compilerCtx.fs.readFile(config.packageJsonFilePath);

Expand Down

0 comments on commit 965323b

Please sign in to comment.