Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions __tests__/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Generate', () => {
readFile.mockImplementation((file, callback): void => {
const fullPath = path.join(
__dirname,
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile]
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile],
);
const content = readFileSync(fullPath);
callback(null, content);
Expand All @@ -73,7 +73,7 @@ describe('Generate', () => {
check: true,
preserveBlockPosition: true,
},
{ parent: {} }
{ parent: {} },
);
});
it('should generate a CODEOWNERS file (re-using codeowners content) and fail when using --check option', async () => {
Expand All @@ -91,15 +91,15 @@ describe('Generate', () => {
readFile.mockImplementation((file, callback): void => {
const fullPath = path.join(
__dirname,
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile]
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile],
);
const content = readFileSync(fullPath);
callback(null, content);
});

await generateCommand(
{ output: 'CODEOWNERS', customRegenerationCommand: 'yarn codeowners-generator generate', check: true },
{ parent: {} }
{ parent: {} },
);

expect(mockExit).toBeCalledWith(1);
Expand All @@ -118,15 +118,15 @@ describe('Generate', () => {
readFile.mockImplementation((file, callback): void => {
const fullPath = path.join(
__dirname,
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile]
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile],
);
const content = readFileSync(fullPath);
callback(null, content);
});

await generateCommand(
{ output: 'CODEOWNERS', customRegenerationCommand: 'yarn codeowners-generator generate' },
{ parent: {} }
{ parent: {} },
);
expect(writeFile.mock.calls[0]).toMatchInlineSnapshot(`
[
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('Generate', () => {
readFile.mockImplementation((file, callback): void => {
const fullPath = path.join(
__dirname,
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile]
withPopulatedCodeownersFile[file as keyof typeof withPopulatedCodeownersFile],
);
const content = readFileSync(fullPath);
callback(null, content);
Expand All @@ -195,7 +195,7 @@ describe('Generate', () => {
customRegenerationCommand: 'yarn codeowners-generator generate',
preserveBlockPosition: true,
},
{ parent: {} }
{ parent: {} },
);
expect(writeFile.mock.calls[0]).toMatchInlineSnapshot(`
[
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('Generate', () => {
groupSourceComments: true,
customRegenerationCommand: 'npm run codeowners-generator generate',
},
{ parent: {} }
{ parent: {} },
);
expect(writeFile.mock.calls).toMatchInlineSnapshot(`
[
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('Generate', () => {
output: 'CODEOWNERS',
useMaintainers: true,
},
})
}),
);

const packageFiles = {
Expand All @@ -355,7 +355,7 @@ describe('Generate', () => {
const withAddedPackageFiles = { ...packageFiles, ...withGitIgnore };
readFile.mockImplementation((file, callback) => {
const content = readFileSync(
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles])
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles]),
);
callback(null, content);
});
Expand Down Expand Up @@ -413,7 +413,7 @@ describe('Generate', () => {
output: 'CODEOWNERS',
useMaintainers: true,
},
})
}),
);

const packageFiles = {
Expand All @@ -431,7 +431,7 @@ describe('Generate', () => {
const withAddedPackageFiles = { ...packageFiles, ...withGitIgnore };
readFile.mockImplementation((file, callback) => {
const content = readFileSync(
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles])
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles]),
);
callback(null, content);
});
Expand Down Expand Up @@ -484,7 +484,7 @@ describe('Generate', () => {
groupSourceComments: true,
includes: ['dir1/*', 'dir2/*', 'dir5/*', 'dir6/*', 'dir7/*'],
},
})
}),
);

const packageFiles = {
Expand All @@ -501,7 +501,7 @@ describe('Generate', () => {
const withAddedPackageFiles = { ...packageFiles, ...withGitIgnore };
readFile.mockImplementation((file, callback) => {
const content = readFileSync(
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles])
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles]),
);
callback(null, content);
});
Expand Down Expand Up @@ -545,7 +545,7 @@ describe('Generate', () => {
groupSourceComments: true,
includes: ['dir1/*', 'dir2/*', 'dir5/*', 'dir6/*', 'dir7/*'],
},
})
}),
);

const packageFiles = {
Expand All @@ -562,7 +562,7 @@ describe('Generate', () => {
const withAddedPackageFiles = { ...packageFiles, ...withGitIgnore };
readFile.mockImplementation((file, callback) => {
const content = readFileSync(
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles])
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles]),
);
callback(null, content);
});
Expand Down Expand Up @@ -616,7 +616,7 @@ describe('Generate', () => {
const withAddedPackageFiles = { ...packageFiles, ...withGitIgnore };
readFile.mockImplementation((file, callback) => {
const content = readFileSync(
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles])
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles]),
);
callback(null, content);
});
Expand Down Expand Up @@ -671,7 +671,7 @@ describe('Generate', () => {
const withAddedPackageFiles = { ...packageFiles, ...withGitIgnore };
readFile.mockImplementation((file, callback) => {
const content = readFileSync(
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles])
path.join(__dirname, withAddedPackageFiles[file as keyof typeof withAddedPackageFiles]),
);
callback(null, content);
});
Expand Down Expand Up @@ -788,7 +788,7 @@ describe('Generate', () => {
parent: {
includes: ['**/NOT_STANDARD_CODEOWNERS'],
},
}
},
);
expect(stopAndPersist.mock.calls).toMatchInlineSnapshot(`
[
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"jest": "^29.0.0",
"jest-mock-process": "^2.0.0",
"lint-staged": "13.0.3",
"prettier": "2.7.1",
"prettier": "3.1.0",
"tslib": "2.4.0",
"tsx": "^3.12.5",
"typescript": "4.7.4"
Expand Down
12 changes: 6 additions & 6 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ program
.option(
'--use-maintainers',
'For every package.json found, generate a CODEOWNERS entry using the maintainers field',
false
false,
)
.option(
'--use-root-maintainers',
'It will use `maintainers` field from the package.json in the root to generate default codeowners. Works only in conjunction with `useMaintainers`',
false
false,
)
.option(
'--group-source-comments',
'Instead of generating one comment per rule, enabling this flag will group them, reducing comments to one per source file. Useful if your codeowners file gets too noisy',
false
false,
)
.option(
'--preserve-block-position',
'It will keep the generated block in the same position it was found in the CODEOWNERS file (if present). Useful for when you make manual additions',
false
false,
)
.option(
'--custom-regeneration-command',
'Specify a custom regeneration command to be printed in the generated CODEOWNERS file, it should be mapped to run codeowners-generator'
'Specify a custom regeneration command to be printed in the generated CODEOWNERS file, it should be mapped to run codeowners-generator',
)
.option('--output [output file]', 'The output path and name of the file, (default: CODEOWNERS)')
.option(
'--check',
'It will fail if the CODEOWNERS generated does not match the current (or missing) CODEOWNERS. Useful for validating that the CODEOWNERS file is up to date date during CI'
'It will fail if the CODEOWNERS generated does not match the current (or missing) CODEOWNERS. Useful for validating that the CODEOWNERS file is up to date date during CI',
)
.action(generateCommand);

Expand Down
6 changes: 3 additions & 3 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const generate: Generate = async ({ rootDir, includes, useMaintainers = f
const filteredJSONs: string[] = groups.json.filter((packageJsonFile: string) => {
if (codeownersDirNames.has(dirname(packageJsonFile))) {
console.warn(
`We will ignore the package.json ${packageJsonFile}, given that we have encountered a CODEOWNERS file at the same dir level`
`We will ignore the package.json ${packageJsonFile}, given that we have encountered a CODEOWNERS file at the same dir level`,
);
return false;
}
Expand Down Expand Up @@ -147,13 +147,13 @@ export const command = async (options: Options, command: Command): Promise<void>
ownerRules,
groupSourceComments,
preserveBlockPosition,
customRegenerationCommand
customRegenerationCommand,
);

if (check) {
if (originalContent.trimEnd() !== newContent) {
throw new Error(
'We found differences between the existing codeowners file and the generated. Remove --check option to avoid this error'
'We found differences between the existing codeowners file and the generated. Remove --check option to avoid this error',
);
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/codeowners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const generateOwnersFile = async (
ownerRules: ownerRule[],
groupSourceComments = false,
preserveBlockPosition = false,
customRegenerationCommand?: string
customRegenerationCommand?: string,
): Promise<createOwnersFileResponse> => {
let originalContent = '';

Expand Down Expand Up @@ -168,7 +168,7 @@ export const loadCodeOwnerFiles = async (dirname: string, files: string[]): Prom
const content = await readContent(filePath);

return parseCodeOwner(filePath.replace(`${dirname}/`, ''), content);
})
}),
);
return codeOwners.reduce((memo, rules) => [...memo, ...rules], []);
};
Expand Down Expand Up @@ -206,7 +206,7 @@ const getOwnersFromMaintainerField = (filePath: string, content: string): ownerR

if (!owners.length) {
throw new Error(
`malformed maintainer entry ${maintainers} this file will be skipped. For more info https://classic.yarnpkg.com/en/docs/package-json/#toc-maintainers`
`malformed maintainer entry ${maintainers} this file will be skipped. For more info https://classic.yarnpkg.com/en/docs/package-json/#toc-maintainers`,
);
}

Expand Down Expand Up @@ -239,7 +239,7 @@ export const loadOwnersFromPackage = async (dirname: string, files: string[]): P
} catch (e) {
return undefined;
}
})
}),
);

// https://github.com/microsoft/TypeScript/issues/30621
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getPatternsFromIgnoreFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getPatternsFromIgnoreFiles = async (): Promise<string[]> => {
debug(`We failed when reading ${filePath}, skipping file. reason: `, e);
return [];
}
})
}),
);

const patterns = filesContent.reduce((memo, patterns) => [...memo, ...patterns], [] as string[]);
Expand Down
Loading