Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only typecheck relevant packages when building with webpack #2371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/warm-rice-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'modular-scripts': minor
---

When building with webpack, only typecheck the package being built and its
dependants
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export async function buildStandalone(
// so --preserve-modules has no effect here

const stats = await buildWebpack(
target,
esbuildTargetFactory,
isApp,
importInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { Paths } from '../common-scripts/determineTargetPaths';
import type { ImportInfo } from '../../utils/importInfo';

export default async function buildWebpack(
target: string,
esbuildTargetFactory: string[],
isApp: boolean,
importInfo: ImportInfo,
Expand All @@ -23,6 +24,7 @@ export default async function buildWebpack(
paths: Paths,
): Promise<StatsCompilation> {
const webpackConfig: Configuration = await getConfig(
target,
true,
esbuildTargetFactory,
isApp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createAppPluginConfig } from './appConfig';
import { createDevelopmentPluginConfig } from './developmentConfig';
import { createProductionPluginConfig } from './productionConfig';
import getClientEnvironment from '../../../common-scripts/getClientEnvironment';
import { selectWorkspaces } from '../../../../utils/selectWorkspaces';
import type { Paths } from '../../../common-scripts/determineTargetPaths';

// Some apps do not need the benefits of saving a web request, so not inlining the chunk
Expand All @@ -21,18 +22,36 @@ const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
// Get environment variables to inject into our app.

export default function createPluginConfig(
export default async function createPluginConfig(
target: string,
isApp: boolean,
isEnvProduction: boolean,
shouldUseSourceMap: boolean,
useTypeScript: boolean,
styleImports: Set<string>,
paths: Paths,
indexPath: string | false,
): Configuration {
): Promise<Configuration> {
const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
const isEnvDevelopment = !isEnvProduction;

// Typecheck package to build and descendants
const packagesToTypecheck = await selectWorkspaces({
targets: [target],
ancestors: false,
descendants: true,
changed: false,
});

const pathsToTypecheck = packagesToTypecheck.map((pkg) => {
return {
file: `../${pkg}/src/**/*.{ts,tsx}`,
};
});
// For some reason the above doesn't work for the package we're building itself
// so we add it separately
pathsToTypecheck.push({ file: `**/src/**/*.{ts,tsx}` });

const basePlugins: Configuration = {
plugins: [
// This gives some necessary context to module not found errors, such as
Expand Down Expand Up @@ -112,10 +131,7 @@ export default function createPluginConfig(
// as micromatch doesn't match
// '../cra-template-typescript/template/src/App.tsx'
// otherwise.
include: [
{ file: '../**/src/**/*.{ts,tsx}' },
{ file: '**/src/**/*.{ts,tsx}' },
],
include: pathsToTypecheck,
exclude: [
{ file: '**/src/**/__tests__/**' },
{ file: '**/src/**/?(*.){spec|test}.*' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const imageInlineSizeLimit = parseInt(
* @returns Promise containing webpack configuration
*/
export default async function getWebpackConfig(
target: string,
isEnvProduction: boolean,
esbuildTargetFactory: string[],
isApp: boolean,
Expand Down Expand Up @@ -91,7 +92,8 @@ export default async function getWebpackConfig(
// If an index is provided, this is its path. Otherwise false.
const indexPath = fs.existsSync(targetPaths.appHtml) && targetPaths.appHtml;
// Plugin configuration
const pluginConfig = createPluginConfig(
const pluginConfig = await createPluginConfig(
target,
isApp,
isEnvProduction,
shouldUseSourceMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DEFAULT_PORT = portEnv ? parseInt(portEnv, 10) : 3000;
const HOST = process.env.HOST || '0.0.0.0';

export default function startWebpack(
target: string,
esbuildTargetFactory: string[],
isApp: boolean,
importInfo: ImportInfo,
Expand Down Expand Up @@ -50,6 +51,7 @@ export default function startWebpack(
}

const config = await getConfig(
target,
false,
esbuildTargetFactory,
isApp,
Expand Down
1 change: 1 addition & 0 deletions packages/modular-scripts/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ async function start(packageName: string): Promise<void> {

logger.debug(`Using target: ${browserTarget.join(', ')}`);
startWebpack(
target,
esbuildTargetFactory,
!isEsmView,
importInfo,
Expand Down