Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/fifty-cougars-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': patch
---

build: When using esbuild, ensure files and directories whose names start with . are also compiled
46 changes: 42 additions & 4 deletions src/cli/build/esbuild.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));
Expand Down