Merge pull request #1191 from ing-bank/fix/passGlobsViaCli
fix(providence-analytics): pass globs via cli
This commit is contained in:
commit
d4af29ab76
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),
|
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]',
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue