Skip to content

Commit

Permalink
Add definition paths from TS config to the program
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Sep 25, 2023
1 parent af237ce commit 5e46079
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { dirname, isInNodeModules, join, isInternal, toAbsolute } from './util/path.js';
import { _resolveSpecifier, _tryResolve } from './util/require.js';
import { _require } from './util/require.js';
import { loadTSConfig as loadCompilerOptions } from './util/tsconfig-loader.js';
import { loadTSConfig } from './util/tsconfig-loader.js';
import { WorkspaceWorker } from './WorkspaceWorker.js';
import type { Workspace } from './ConfigurationChief.js';
import type { CommandLineOptions } from './types/cli.js';
Expand Down Expand Up @@ -140,7 +140,7 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {

deputy.addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries });

const compilerOptions = await loadCompilerOptions(join(dir, tsConfigFile ?? 'tsconfig.json'));
const { compilerOptions, definitionPaths } = await loadTSConfig(join(dir, tsConfigFile ?? 'tsconfig.json'));

const principal = factory.getPrincipal({ cwd: dir, paths, compilerOptions, compilers, pkgName });

Expand All @@ -159,6 +159,9 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {

await worker.init();

principal.addEntryPaths(definitionPaths);
debugLogArray(`Found definition paths (${name})`, definitionPaths);

const sharedGlobOptions = { cwd, workingDir: dir, gitignore, ignore: worker.getIgnorePatterns() };

const entryPathsFromManifest = await getEntryPathFromManifest(cwd, dir, manifest);
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { hasDependency, load } from '../../util/plugin.js';
import { loadTSConfig } from '../../util/tsconfig-loader.js';
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
import type { TsConfigJson } from 'type-fest';
import type { CompilerOptions } from 'typescript';

// https://www.typescriptlang.org/tsconfig

Expand Down Expand Up @@ -34,7 +33,7 @@ const resolveExtensibleConfig = async (configFilePath: string) => {
};

export const findTypeScriptDependencies: GenericPluginCallback = async configFilePath => {
const compilerOptions: CompilerOptions = await loadTSConfig(configFilePath);
const { compilerOptions } = await loadTSConfig(configFilePath);
const config: TsConfigJson = await resolveExtensibleConfig(configFilePath); // Dual loader to get external `extends` dependencies

if (!compilerOptions || !config) return [];
Expand Down
6 changes: 4 additions & 2 deletions src/util/tsconfig-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const loadTSConfig = async (tsConfigFilePath: string) => {
if (isFile(tsConfigFilePath)) {
const config = ts.readConfigFile(tsConfigFilePath, ts.sys.readFile);
const parsedConfig = ts.parseJsonConfigFileContent(config.config, ts.sys, dirname(tsConfigFilePath));
return parsedConfig.options ?? {};
const compilerOptions = parsedConfig.options ?? {};
const definitionPaths = parsedConfig.fileNames.filter(filePath => filePath.endsWith('.d.ts'));
return { compilerOptions, definitionPaths };
}
return {};
return { compilerOptions: {}, definitionPaths: [] };
};
6 changes: 3 additions & 3 deletions tests/plugins/svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/svelte');

test('Use compilers', async () => {
test('Use compilers (svelte)', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
Expand All @@ -19,7 +19,7 @@ test('Use compilers', async () => {
assert.deepEqual(counters, {
...baseCounters,
devDependencies: 2,
processed: 10, // This includes .svelte and .css files
total: 10,
processed: 11, // This includes .svelte and .css files
total: 11,
});
});
18 changes: 9 additions & 9 deletions tests/subpath-imports-from-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import baseCounters from './helpers/baseCounters.js';

const cwd = resolve('fixtures/subpath-import-from-plugin');

test('Allows subpath-imports', async () => {
test('Allows subpath-imports from plugin', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
Expand All @@ -18,12 +18,12 @@ test('Allows subpath-imports', async () => {
assert.deepEqual(counters, {
...baseCounters,
dependencies: 1,
processed: 1,
total: 1,
processed: 2,
total: 2,
});
});

test('Allows subpath-imports (production)', async () => {
test('Allows subpath-imports from plugin (production)', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
Expand All @@ -35,12 +35,12 @@ test('Allows subpath-imports (production)', async () => {
assert.deepEqual(counters, {
...baseCounters,
dependencies: 1,
processed: 1,
total: 1,
processed: 2,
total: 2,
});
});

test('Allows subpath-imports (strict)', async () => {
test('Allows subpath-imports from plugin (strict)', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
Expand All @@ -53,7 +53,7 @@ test('Allows subpath-imports (strict)', async () => {
assert.deepEqual(counters, {
...baseCounters,
dependencies: 1,
processed: 1,
total: 1,
processed: 2,
total: 2,
});
});

0 comments on commit 5e46079

Please sign in to comment.