Skip to content

Commit c1db1ec

Browse files
committedJul 9, 2024
Minor refactors
1 parent 699fd28 commit c1db1ec

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed
 

‎packages/knip/src/ProjectPrincipal.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { dirname, extname, isInNodeModules, join } from './util/path.js';
1818
import type { ToSourceFilePath } from './util/to-source-path.js';
1919

2020
// These compiler options override local options
21-
const baseCompilerOptions = {
21+
const baseCompilerOptions: ts.CompilerOptions = {
2222
allowJs: true,
2323
allowSyntheticDefaultImports: true,
2424
declaration: false,
@@ -29,11 +29,11 @@ const baseCompilerOptions = {
2929
jsx: ts.JsxEmit.Preserve,
3030
jsxImportSource: undefined,
3131
lib: [],
32-
types: ['node'],
3332
noEmit: true,
3433
skipDefaultLibCheck: true,
3534
skipLibCheck: true,
3635
sourceMap: false,
36+
types: ['node'],
3737
};
3838

3939
const tsCreateProgram = timerify(ts.createProgram);
@@ -87,7 +87,7 @@ export class ProjectPrincipal {
8787
this.compilerOptions = {
8888
...compilerOptions,
8989
...baseCompilerOptions,
90-
types: compact([...(compilerOptions.types ?? []), ...baseCompilerOptions.types]),
90+
types: compact([...(compilerOptions.types ?? []), ...(baseCompilerOptions.types ?? [])]),
9191
allowNonTsExtensions: true,
9292
};
9393

‎packages/knip/src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
355355
const files = resolvedFiles.filter(filePath => !analyzedFiles.has(filePath));
356356

357357
debugLogArray('*', `Analyzing used resolved files [P${principals.indexOf(principal) + 1}/${++round}]`, files);
358-
for (const filePath of files) {
359-
analyzeSourceFile(filePath, principal);
360-
}
358+
for (const filePath of files) analyzeSourceFile(filePath, principal);
361359
} while (size !== principal.entryPaths.size);
362360

363361
for (const filePath of principal.getUnreferencedFiles()) unreferencedFiles.add(filePath);

‎packages/knip/src/util/modules.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ export const getEntryPathFromManifest = (
7070
};
7171

7272
// Strip `?search` and other proprietary directives from the specifier (e.g. https://webpack.js.org/concepts/loaders/)
73+
const matchDirectives = /^([?!|-]+)?([^!?:]+).*/;
7374
export const sanitizeSpecifier = (specifier: string) => {
7475
if (isBuiltin(specifier)) return specifier;
7576
if (isAbsolute(specifier)) return specifier;
7677
if (specifier.startsWith('virtual:')) return specifier;
77-
return specifier.replace(/^([?!|-]+)?([^!?:]+).*/, '$2');
78+
return specifier.replace(matchDirectives, '$2');
7879
};

0 commit comments

Comments
 (0)
Please sign in to comment.