diff --git a/src/utilities/validateTargetDirectory.js b/src/utilities/validateTargetDirectory.js index 4f917fa..48a4c6e 100644 --- a/src/utilities/validateTargetDirectory.js +++ b/src/utilities/validateTargetDirectory.js @@ -1,6 +1,5 @@ import fs from 'fs'; import path from 'path'; -import _ from 'lodash'; export default (targetDirectory) => { let stats; @@ -25,7 +24,7 @@ export default (targetDirectory) => { const indexFile = fs.readFileSync(indexFilePath, 'utf8'); - if (!_.startsWith(indexFile, '// @create-index\n')) { + if (!indexFile.match(/(?:^|[\n\r]+)\/\/ @create-index[\n\r]+/)) { throw new Error('"' + indexFilePath + '" unsafe index.'); } diff --git a/test/fixtures/validate-target-directory/safe-index-with-banner/index.js b/test/fixtures/validate-target-directory/safe-index-with-banner/index.js new file mode 100644 index 0000000..69a1f5b --- /dev/null +++ b/test/fixtures/validate-target-directory/safe-index-with-banner/index.js @@ -0,0 +1,3 @@ +/* eslint-disable */ + +// @create-index diff --git a/test/validateTargetDirectory.js b/test/validateTargetDirectory.js index 9a27c8e..63429da 100644 --- a/test/validateTargetDirectory.js +++ b/test/validateTargetDirectory.js @@ -36,6 +36,11 @@ describe('validateTargetDirectory()', () => { expect(validateTargetDirectory(path.resolve(fixturesPath, 'safe-index'))).to.equal(true); }); }); + context('safe with banner', () => { + it('returns true', () => { + expect(validateTargetDirectory(path.resolve(fixturesPath, 'safe-index-with-banner'))).to.equal(true); + }); + }); context('unsafe', () => { it('throws an error', () => { expect(() => {