Skip to content

Commit

Permalink
Merge pull request #96 from groupon/dbushong/feature/main/ts
Browse files Browse the repository at this point in the history
Support .ts .mjs .tsx .jsx extensions for license headers
  • Loading branch information
dbushong authored Oct 29, 2021
2 parents 53eed49 + a7ee4ad commit 42ba254
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/license/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function collectFiles(cwd, whitelist, optionalExclude) {
);

function scanDirectory(directory) {
return globAsync(`${directory}/**/*.{js,coffee}`, {
return globAsync(`${directory}/**/*.{js,jsx,mjs,ts,tsx,coffee}`, {
ignore: exclude,
nodir: true,
cwd,
Expand Down Expand Up @@ -115,6 +115,10 @@ function addLicenseHeader(entry) {
function addMissingLicenseHeaders(licenseText, files) {
const licenseHeaders = {
'.js': COMMENT_TYPES['.js'].getLicenseHeader(licenseText),
'.jsx': COMMENT_TYPES['.js'].getLicenseHeader(licenseText),
'.mjs': COMMENT_TYPES['.js'].getLicenseHeader(licenseText),
'.ts': COMMENT_TYPES['.js'].getLicenseHeader(licenseText),
'.tsx': COMMENT_TYPES['.js'].getLicenseHeader(licenseText),
'.coffee': COMMENT_TYPES['.coffee'].getLicenseHeader(licenseText),
};
return files
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/merge-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
set -e
git init

echo "console.log('do stuff');" > merge.js
git add merge.js
echo "import { mittens } from 'kittens';" > merge.ts
git add merge.ts
git commit -m 'Merge pull request #119 from theowner/some/branch'
21 changes: 21 additions & 0 deletions test/license/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,25 @@ describe('addLicenseHeaders', () => {
);
});
});

describe('with a ts file w/o a license header', () => {
const dirname = withFixture('merge-commit');
const filename = `${dirname}/merge.ts`;

it('adds the header', async () => {
fs.writeFileSync(`${dirname}/LICENSE`, 'SIMPLE');

const changedFiles = await addLicenseHeaders(dirname);
assert.deepStrictEqual(changedFiles, [filename]);
assert.strictEqual(
fs.readFileSync(filename, 'utf8'),
`\
/*
* SIMPLE
*/
import { mittens } from 'kittens';
`
);
});
});
});

0 comments on commit 42ba254

Please sign in to comment.