fix(providence-analytics): pass globs via cli

This commit is contained in:
Thijs Louisse 2021-01-22 11:06:27 +01:00
parent 70bfeba9d1
commit b4ec2fe884
4 changed files with 49 additions and 17 deletions

View file

@ -0,0 +1,5 @@
---
'providence-analytics': patch
---
- allowlist does not preprocess globs in cli before handing them over to the program

View file

@ -175,13 +175,13 @@ async function cli({ cwd } = {}) {
v => cliHelpers.pathsArrayFromCs(v, cwd), v => cliHelpers.pathsArrayFromCs(v, cwd),
InputDataService.referenceProjectPaths, InputDataService.referenceProjectPaths,
) )
.option('-a, --allowlist [allowlist]', `allowlisted paths, like './src, ./packages/*'`, v => .option('-a, --allowlist [allowlist]', `allowlisted paths, like 'src/**/*, packages/**/*'`, v =>
cliHelpers.pathsArrayFromCs(v, cwd), cliHelpers.csToArray(v, cwd),
) )
.option( .option(
'--allowlist-reference [allowlist-reference]', '--allowlist-reference [allowlist-reference]',
`allowed paths for reference, like './src, ./packages/*'`, `allowed paths for reference, like 'src/**/*, packages/**/*'`,
v => cliHelpers.pathsArrayFromCs(v, cwd), v => cliHelpers.csToArray(v, cwd),
) )
.option( .option(
'--search-target-collection [collection-name]', '--search-target-collection [collection-name]',

View file

@ -52,7 +52,10 @@ const externalCfgMock = {
}; };
async function runCli(args, cwd) { async function runCli(args, cwd) {
process.argv = [...process.argv.slice(0, 2), ...args.split(' ')]; process.argv = [
...process.argv.slice(0, 2),
...args.split(' ').map(a => a.replace(/^("|')?(.*)("|')?$/, '$2')),
];
await cli({ cwd }); await cli({ cwd });
} }
@ -231,27 +234,26 @@ describe('Providence CLI', () => {
}); });
it('"-a --allowlist"', async () => { it('"-a --allowlist"', async () => {
await runCli(`${analyzeCmd} -a /mocked/path/example-project`, rootDir); await runCli(`${analyzeCmd} -a mocked/**/*,rocked/*`, rootDir);
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([ expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
'/mocked/path/example-project', 'mocked/**/*',
'rocked/*',
]); ]);
pathsArrayFromCsStub.resetHistory();
providenceStub.resetHistory(); providenceStub.resetHistory();
await runCli(`${analyzeCmd} --allowlist /mocked/path/example-project`, rootDir); await runCli(`${analyzeCmd} --allowlist mocked/**/*,rocked/*`, rootDir);
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([ expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
'/mocked/path/example-project', 'mocked/**/*',
'rocked/*',
]); ]);
}); });
it('"--allowlist-reference"', async () => { it('"--allowlist-reference"', async () => {
await runCli(`${analyzeCmd} --allowlist-reference /mocked/path/example-project`, rootDir); await runCli(`${analyzeCmd} --allowlist-reference mocked/**/*,rocked/*`, rootDir);
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
expect(providenceStub.args[0][1].gatherFilesConfigReference.allowlist).to.eql([ expect(providenceStub.args[0][1].gatherFilesConfigReference.allowlist).to.eql([
'/mocked/path/example-project', 'mocked/**/*',
'rocked/*',
]); ]);
}); });
@ -383,8 +385,8 @@ describe('Providence CLI', () => {
}, },
outputFolder: '/outp', outputFolder: '/outp',
extensions: ['.bla'], extensions: ['.bla'],
allowlist: [`${rootDir}/al`], allowlist: ['al'],
allowlistReference: [`${rootDir}/alr`], allowlistReference: ['alr'],
cwd: undefined, cwd: undefined,
}); });
}); });

View file

@ -197,6 +197,14 @@ describe('InputDataService', () => {
]); ]);
}); });
it('does not support non globs in "allowlist"', async () => {
const globOutput = InputDataService.gatherFilesFromDir('/fictional/project', {
extensions: ['.html', '.js'],
allowlist: ['nested'],
});
expect(globOutput).to.eql([]);
});
it('omits node_modules and bower_components at root level by default', async () => { it('omits node_modules and bower_components at root level by default', async () => {
mockProject({ mockProject({
'./index.js': '', './index.js': '',
@ -229,6 +237,23 @@ describe('InputDataService', () => {
]); ]);
}); });
it('allows deeper globs', async () => {
mockProject({
'./root-lvl.js': '',
'./deeper/glob/structure/file.js': '',
'./deeper/glob/file.js': '',
'./deeper/file.js': '',
});
const globOutput = InputDataService.gatherFilesFromDir('/fictional/project', {
allowlist: ['deeper/**/*'],
});
expect(globOutput).to.eql([
'/fictional/project/deeper/file.js',
'/fictional/project/deeper/glob/file.js',
'/fictional/project/deeper/glob/structure/file.js',
]);
});
describe('Default config', () => { describe('Default config', () => {
it('omits config files by default', async () => { it('omits config files by default', async () => {
mockProject({ mockProject({