fix(providence-analytics): pass globs via cli
This commit is contained in:
parent
70bfeba9d1
commit
b4ec2fe884
4 changed files with 49 additions and 17 deletions
5
.changeset/proud-waves-kick.md
Normal file
5
.changeset/proud-waves-kick.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'providence-analytics': patch
|
||||
---
|
||||
|
||||
- allowlist does not preprocess globs in cli before handing them over to the program
|
||||
|
|
@ -175,13 +175,13 @@ async function cli({ cwd } = {}) {
|
|||
v => cliHelpers.pathsArrayFromCs(v, cwd),
|
||||
InputDataService.referenceProjectPaths,
|
||||
)
|
||||
.option('-a, --allowlist [allowlist]', `allowlisted paths, like './src, ./packages/*'`, v =>
|
||||
cliHelpers.pathsArrayFromCs(v, cwd),
|
||||
.option('-a, --allowlist [allowlist]', `allowlisted paths, like 'src/**/*, packages/**/*'`, v =>
|
||||
cliHelpers.csToArray(v, cwd),
|
||||
)
|
||||
.option(
|
||||
'--allowlist-reference [allowlist-reference]',
|
||||
`allowed paths for reference, like './src, ./packages/*'`,
|
||||
v => cliHelpers.pathsArrayFromCs(v, cwd),
|
||||
`allowed paths for reference, like 'src/**/*, packages/**/*'`,
|
||||
v => cliHelpers.csToArray(v, cwd),
|
||||
)
|
||||
.option(
|
||||
'--search-target-collection [collection-name]',
|
||||
|
|
|
|||
|
|
@ -52,7 +52,10 @@ const externalCfgMock = {
|
|||
};
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
|
|
@ -231,27 +234,26 @@ describe('Providence CLI', () => {
|
|||
});
|
||||
|
||||
it('"-a --allowlist"', async () => {
|
||||
await runCli(`${analyzeCmd} -a /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
await runCli(`${analyzeCmd} -a mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
|
||||
pathsArrayFromCsStub.resetHistory();
|
||||
providenceStub.resetHistory();
|
||||
|
||||
await runCli(`${analyzeCmd} --allowlist /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
await runCli(`${analyzeCmd} --allowlist mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfig.allowlist).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
});
|
||||
|
||||
it('"--allowlist-reference"', async () => {
|
||||
await runCli(`${analyzeCmd} --allowlist-reference /mocked/path/example-project`, rootDir);
|
||||
expect(pathsArrayFromCsStub.args[0][0]).to.equal('/mocked/path/example-project');
|
||||
await runCli(`${analyzeCmd} --allowlist-reference mocked/**/*,rocked/*`, rootDir);
|
||||
expect(providenceStub.args[0][1].gatherFilesConfigReference.allowlist).to.eql([
|
||||
'/mocked/path/example-project',
|
||||
'mocked/**/*',
|
||||
'rocked/*',
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
@ -383,8 +385,8 @@ describe('Providence CLI', () => {
|
|||
},
|
||||
outputFolder: '/outp',
|
||||
extensions: ['.bla'],
|
||||
allowlist: [`${rootDir}/al`],
|
||||
allowlistReference: [`${rootDir}/alr`],
|
||||
allowlist: ['al'],
|
||||
allowlistReference: ['alr'],
|
||||
cwd: undefined,
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
mockProject({
|
||||
'./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', () => {
|
||||
it('omits config files by default', async () => {
|
||||
mockProject({
|
||||
|
|
|
|||
Loading…
Reference in a new issue