diff --git a/.changeset/fifty-cougars-begin.md b/.changeset/fifty-cougars-begin.md new file mode 100644 index 000000000..e9fb53fe0 --- /dev/null +++ b/.changeset/fifty-cougars-begin.md @@ -0,0 +1,5 @@ +--- +'skuba': patch +--- + +build: When using esbuild, ensure files and directories whose names start with . are also compiled diff --git a/src/cli/build/esbuild.ts b/src/cli/build/esbuild.ts index 9adba21b2..8d75dbc7d 100644 --- a/src/cli/build/esbuild.ts +++ b/src/cli/build/esbuild.ts @@ -1,10 +1,13 @@ +import path from 'path'; import { inspect } from 'util'; import tsconfigPaths from '@esbuild-plugins/tsconfig-paths'; import { build } from 'esbuild'; import { ModuleKind, ModuleResolutionKind, ScriptTarget } from 'typescript'; +import { buildPatternToFilepathMap, crawlDirectory } from '../../utils/dir'; import { createLogger } from '../../utils/logging'; +import { getEntryPointFromManifest } from '../../utils/manifest'; import { parseTscArgs } from './args'; import { readTsconfig, tsc } from './tsc'; @@ -35,11 +38,46 @@ export const esbuild = async ( return; } - const { fileNames: entryPoints, options: compilerOptions } = - parsedCommandLine; + const { options: compilerOptions } = parsedCommandLine; - log.debug(log.bold('Files')); - entryPoints.forEach((filepath) => log.debug(filepath)); + const entryPoint = await getEntryPointFromManifest(); + if (!entryPoint) { + return; + } + + const pathSegments = entryPoint.split(path.sep); + const srcDir = pathSegments.length > 1 ? pathSegments[0] : ''; + const resolvedSrcDir = path.resolve(tscArgs.dirname, srcDir); + + const allFiles = await crawlDirectory(resolvedSrcDir); + // TODO: use extensions from eslint-config-seek + const tsExtensions = ['ts', 'tsx', 'cts', 'mts']; + const filesByPattern = buildPatternToFilepathMap( + [ + `**/*.@(${tsExtensions.join('|')})`, + // Must be explicit about including dotfiles otherwise TypeScript ignores them + // https://github.com/microsoft/TypeScript/blob/v5.0.4/src/compiler/utilities.ts#L8828-L8830 + `**/.*.@(${tsExtensions.join('|')})`, + `**/.*/**/*.@(${tsExtensions.join('|')})`, + `**/.*/**/.*.@(${tsExtensions.join('|')})`, + ], + allFiles, + { + cwd: resolvedSrcDir, + dot: true, + ignore: [ + '**/*.d.ts', + // TODO: use `exclude` from tsconfig + '**/__mocks__/**/*', + '**/*.test.ts', + 'src/testing/**/*', + ], + }, + ); + + const entryPoints = Array.from( + new Set(Object.values(filesByPattern).flat()), + ).map((filename) => path.resolve(resolvedSrcDir, filename)); log.debug(log.bold('Compiler options')); log.debug(inspect(compilerOptions));