From 0ab85ff5aa16be6244681c9f2055ce3d00033be0 Mon Sep 17 00:00:00 2001 From: Remus Mate Date: Sun, 7 May 2023 12:49:04 +1000 Subject: [PATCH 1/3] Compile files and directories whose names start with . --- .changeset/fifty-cougars-begin.md | 5 +++++ .../analysis/__snapshots__/project.test.ts.snap | 9 ++++++++- template/base/tsconfig.build.json | 9 ++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 .changeset/fifty-cougars-begin.md 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/configure/analysis/__snapshots__/project.test.ts.snap b/src/cli/configure/analysis/__snapshots__/project.test.ts.snap index 6aa8ba674..8acefde68 100644 --- a/src/cli/configure/analysis/__snapshots__/project.test.ts.snap +++ b/src/cli/configure/analysis/__snapshots__/project.test.ts.snap @@ -164,7 +164,14 @@ export {}; "data": "{ "exclude": ["**/__mocks__/**/*", "**/*.test.ts", "src/testing/**/*"], "extends": "./tsconfig.json", - "include": ["src/**/*"] + "include": [ + "src/**/*", + // 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 + "src/**/.*", + "src/**/.*/**/*", + "src/**/.*/**/.*" + ] } ", "operation": "A", diff --git a/template/base/tsconfig.build.json b/template/base/tsconfig.build.json index ccce6cf7b..9b4e9a678 100644 --- a/template/base/tsconfig.build.json +++ b/template/base/tsconfig.build.json @@ -1,5 +1,12 @@ { "exclude": ["**/__mocks__/**/*", "**/*.test.ts", "src/testing/**/*"], "extends": "./tsconfig.json", - "include": ["src/**/*"] + "include": [ + "src/**/*", + // 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 + "src/**/.*", + "src/**/.*/**/*", + "src/**/.*/**/.*" + ] } From 2c96e5b6b65950dcc2b7d1c830affcc753299acb Mon Sep 17 00:00:00 2001 From: Remus Mate Date: Thu, 11 May 2023 15:01:59 +1000 Subject: [PATCH 2/3] do the crawling for TypeScript files ourselves, then feed the list to esbuild --- src/cli/build/esbuild.ts | 46 ++++++++++++++++++++++++++++--- src/utils/dir.ts | 3 +- template/base/tsconfig.build.json | 9 +----- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/cli/build/esbuild.ts b/src/cli/build/esbuild.ts index 59722b430..3950a8fb4 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 ts, { 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 { tsc } from './tsc'; @@ -78,11 +81,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: read tsconfig.build.json#exclude + '**/__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)); diff --git a/src/utils/dir.ts b/src/utils/dir.ts index ec4cec21f..33b4c3687 100644 --- a/src/utils/dir.ts +++ b/src/utils/dir.ts @@ -13,10 +13,11 @@ import { isErrorWithCode } from './error'; export const buildPatternToFilepathMap = ( patterns: string[], allFilepaths: string[], + options?: picomatch.PicomatchOptions, ) => Object.fromEntries( patterns.map((pattern) => { - const isMatch = picomatch(pattern); + const isMatch = picomatch(pattern, options); const filepaths = allFilepaths.filter((filepath) => isMatch(filepath)); diff --git a/template/base/tsconfig.build.json b/template/base/tsconfig.build.json index 9b4e9a678..ccce6cf7b 100644 --- a/template/base/tsconfig.build.json +++ b/template/base/tsconfig.build.json @@ -1,12 +1,5 @@ { "exclude": ["**/__mocks__/**/*", "**/*.test.ts", "src/testing/**/*"], "extends": "./tsconfig.json", - "include": [ - "src/**/*", - // 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 - "src/**/.*", - "src/**/.*/**/*", - "src/**/.*/**/.*" - ] + "include": ["src/**/*"] } From ceacf25c5bec723daaa03537566b3a828886dab8 Mon Sep 17 00:00:00 2001 From: Remus Mate Date: Thu, 11 May 2023 18:50:25 +1000 Subject: [PATCH 3/3] update test snapshot --- src/cli/build/esbuild.ts | 2 +- .../analysis/__snapshots__/project.test.ts.snap | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/cli/build/esbuild.ts b/src/cli/build/esbuild.ts index 3950a8fb4..7246637bc 100644 --- a/src/cli/build/esbuild.ts +++ b/src/cli/build/esbuild.ts @@ -110,7 +110,7 @@ export const esbuild = async ( dot: true, ignore: [ '**/*.d.ts', - // TODO: read tsconfig.build.json#exclude + // TODO: use `exclude` from tsconfig '**/__mocks__/**/*', '**/*.test.ts', 'src/testing/**/*', diff --git a/src/cli/configure/analysis/__snapshots__/project.test.ts.snap b/src/cli/configure/analysis/__snapshots__/project.test.ts.snap index 8acefde68..6aa8ba674 100644 --- a/src/cli/configure/analysis/__snapshots__/project.test.ts.snap +++ b/src/cli/configure/analysis/__snapshots__/project.test.ts.snap @@ -164,14 +164,7 @@ export {}; "data": "{ "exclude": ["**/__mocks__/**/*", "**/*.test.ts", "src/testing/**/*"], "extends": "./tsconfig.json", - "include": [ - "src/**/*", - // 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 - "src/**/.*", - "src/**/.*/**/*", - "src/**/.*/**/.*" - ] + "include": ["src/**/*"] } ", "operation": "A",