Skip to content

Commit

Permalink
fix: ignore .d.ts files
Browse files Browse the repository at this point in the history
Closes #195
  • Loading branch information
eventualbuddha committed Jan 3, 2019
1 parent e226dc2 commit f108a17
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/cli/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import AstExplorerResolver from './resolvers/AstExplorerResolver';
import FileSystemResolver from './resolvers/FileSystemResolver';
import NetworkResolver from './resolvers/NetworkResolver';
import PackageResolver from './resolvers/PackageResolver';
import { EntryType } from './System';
import { disable, enable } from './transpile-requires';

export class Plugin {
Expand All @@ -33,8 +34,18 @@ export class Plugin {
}
}

function ignoreDotfiles(path: string, basename: string, root: string): boolean {
return basename.startsWith('.');
function defaultIgnorePredicate(
path: string,
basename: string,
root: string,
type: EntryType
): boolean {
return (
// ignore paths starting with a dot
basename.startsWith('.') ||
// ignore TypeScript declaration files
basename.endsWith('.d.ts')
);
}

export enum Printer {
Expand All @@ -55,7 +66,7 @@ export default class Config {
readonly requires: Array<string> = [],
readonly transpilePlugins: boolean = true,
readonly findBabelConfig: boolean = false,
readonly ignore: PathPredicate = ignoreDotfiles,
readonly ignore: PathPredicate = defaultIgnorePredicate,
readonly stdio: boolean = false,
readonly dry: boolean = false
) {}
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/test/cli/CLITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ describe('CLI', function() {
strictEqual(await readFile(processed, 'utf8'), '1;');
});

it('ignores .d.ts files', async function() {
let ignored = await createTemporaryFile(
'a-dir/ignored.d.ts',
'export = 42;'
);
let { status, stdout, stderr } = await runCodemodCLI([dirname(ignored)]);

deepEqual(
{ status, stdout, stderr },
{
status: 0,
stdout: `0 file(s), 0 modified, 0 errors\n`,
stderr: ''
}
);
strictEqual(await readFile(ignored, 'utf8'), 'export = 42;');
});

it('processes files but does not replace their contents when using --dry', async function() {
let afile = await createTemporaryFile('a-file.js', '3 + 4;');
let { status, stdout, stderr } = await runCodemodCLI([
Expand Down

0 comments on commit f108a17

Please sign in to comment.