Skip to content

Commit

Permalink
fix(globs): don't remove tsconfig.json files by default
Browse files Browse the repository at this point in the history
  • Loading branch information
duniul committed Jul 9, 2023
1 parent b104241 commit 17603eb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-eagles-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'clean-modules': patch
---

Don't remove `tsconfig.json` files by default, as they can be shared.
1 change: 0 additions & 1 deletion .cleanmodules-default
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ licen@(s|c)e.txt
licen@(s|c)e-mit.txt

# typescript
tsconfig.json
.tsbuildinfo

# npm
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/getMockedFileStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function getMockedFileStructure(): Promise<Record<string, any>> {
'.npmrc': '.',
},
dep2: {
'tsconfig.json': '.',
'CHANGELOG.md': '.',
'file.js': '.',
},
dep3: {
Expand Down
20 changes: 10 additions & 10 deletions src/analyze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,34 @@ describe('analyzeIncluded', () => {
it('says if a file was excluded or not', async () => {
const results = await analyzeIncluded(nodeModulesPath, {
...EMPTY_GLOB_LISTS,
included: ['**/tsconfig.json', '**/file.js'],
originalIncluded: ['tsconfig.json', 'file.js'],
included: ['**/CHANGELOG.md', '**/file.js'],
originalIncluded: ['CHANGELOG.md', 'file.js'],
});

const fileResult = results.find((r) => r.filePath.endsWith('file.js'));
const tsconfigResult = results.find((r) => r.filePath.endsWith('tsconfig.json'));
const changelogResult = results.find((r) => r.filePath.endsWith('CHANGELOG.md'));

expect(fileResult).toHaveProperty('includedByDefault', false);
expect(tsconfigResult).toHaveProperty('includedByDefault', true);
expect(changelogResult).toHaveProperty('includedByDefault', true);
});

it('lists what globs (original and derived version) included the file', async () => {
const results = await analyzeIncluded(nodeModulesPath, {
...EMPTY_GLOB_LISTS,
included: ['**/*.json', '**/tsconfig.json', '**/file.js'],
originalIncluded: ['*.json', 'tsconfig.json', 'file.js'],
included: ['**/*.md', '**/CHANGELOG.md', '**/file.js'],
originalIncluded: ['*.md', 'CHANGELOG.md', 'file.js'],
});

const fileResult = results.find((r) => r.filePath.endsWith('file.js'));
const tsconfigResult = results.find((r) => r.filePath.endsWith('tsconfig.json'));
const changelogResult = results.find((r) => r.filePath.endsWith('CHANGELOG.md'));

expect(fileResult).toHaveProperty('includedByGlobs', [
{ derived: 'node_modules/**/file.js', original: 'file.js' },
]);

expect(tsconfigResult).toHaveProperty('includedByGlobs', [
{ derived: 'node_modules/**/*.json', original: '*.json' },
{ derived: 'node_modules/**/tsconfig.json', original: 'tsconfig.json' },
expect(changelogResult).toHaveProperty('includedByGlobs', [
{ derived: 'node_modules/**/*.md', original: '*.md' },
{ derived: 'node_modules/**/CHANGELOG.md', original: 'CHANGELOG.md' },
]);
});
});
2 changes: 1 addition & 1 deletion src/clean.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('removeEmptyDirs', () => {
const filePaths = [
'node_modules/dep1/__tests__/test1.js',
'node_modules/dep1/a-dir/doc.md',
'node_modules/dep2/tsconfig.json',
'node_modules/dep2/CHANGELOG.md',
'node_modules/dep2/file.js',
];

Expand Down

0 comments on commit 17603eb

Please sign in to comment.