Skip to content

Commit 3e12d1e

Browse files
authored
Merge pull request #205 from semantic-release/fix/ignore-file
Fixed ignore and exclude file naming and priority CLoses #165
2 parents bb4c2e0 + 359040f commit 3e12d1e

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ You can also use the `include` option which works in the same manner.
9292
#### Notes
9393

9494
* Include and exclude options are not mutually exclusive so you can use both.
95-
* Plugin also looks for `.distinclude` and `.distexclude` files which take precedence over the options set in the plugin.
95+
* Plugin also looks for `.distinclude` and `.distexclude` / `.distignore` files which take precedence over the options set in the plugin.
9696
* By default we exclude a lot of build artifacts and files which are not needed in the package. You can see the full list in [constants.ts](lib/constants.ts).
9797

9898
### Examples

lib/utils/copy-files.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ function remapGlobs(workDir: string, includePath: string): string {
2424
* @returns Array of globs to include
2525
*/
2626
export function getInclude(workDir: string, files?: string[]): string[] {
27-
const include = [...new Set(files ?? getFileArray(workDir, '.distinclude'))];
27+
const include = [
28+
...new Set(getFileArray(workDir, '.distinclude') ?? files ?? []),
29+
];
2830

2931
return include.length !== 0 ? include : ['**/*'];
3032
}
@@ -40,7 +42,10 @@ export function getIgnore(workDir: string, files?: string[]): string[] {
4042
return [
4143
...new Set([
4244
...DEFAULT_EXCLUDES,
43-
...(files ?? getFileArray(workDir, '.distignore')),
45+
...(getFileArray(workDir, '.distexclude') ??
46+
getFileArray(workDir, '.distignore') ??
47+
files ??
48+
[]),
4449
]),
4550
]
4651
.filter(

lib/utils/get-file-array.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import fs from 'fs-extra';
22
import path from 'node:path';
33

4-
export function getFileArray(workDir: string, fileToRead: string): string[] {
4+
export function getFileArray(
5+
workDir: string,
6+
fileToRead: string,
7+
): null | string[] {
58
try {
69
const filesinFile = fs
7-
.readFileSync(path.resolve(path.join(workDir, fileToRead)), 'utf8')
8-
.split('\n')
9-
.filter((file) => file !== '')
10-
.map((file) => file.trim());
10+
.readFileSync(path.resolve(path.join(workDir, fileToRead)), 'utf8') // Read the file from the workDir
11+
.split('\n') // Split the file into an array of lines
12+
.map((file) => file.trim()) // Trim each line
13+
.filter((file) => file !== '' && !file.startsWith('#')); // Remove empty lines and comments
1114

1215
return [...new Set([...filesinFile])];
1316
} catch (err) {
14-
return [];
17+
return null;
1518
}
1619
}

test/0-corner-cases.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PluginConfig } from '../lib/classes/plugin-config.class.js';
99
describe('Corner cases affecting releases', () => {
1010
it('Should fail to read non-existant file', () => {
1111
try {
12-
const files = getFileArray('/test', 'non-existant-file.txt');
12+
const files = getFileArray('/test', 'non-existant-file.txt') ?? [];
1313
expect(files).toEqual([]);
1414
} catch (err) {}
1515
});
@@ -87,7 +87,7 @@ describe('Corner cases affecting releases', () => {
8787
'vendor',
8888
]);
8989
const ignore1 = DEFAULT_EXCLUDES;
90-
const include2 = getInclude(workDir);
90+
const include2 = getInclude(workDir, ['dist-test.php']);
9191
const ignore2 = getIgnore(workDir);
9292
const expected = ['dist-test.php', 'test1.php', 'vendor'].sort();
9393

test/fixtures/dist-test/.distinclude

-1
This file was deleted.

0 commit comments

Comments
 (0)