fix(providence-analytics): better allowlist-mode detection
This commit is contained in:
parent
64bdddf6b7
commit
17dadabfbf
3 changed files with 47 additions and 6 deletions
5
.changeset/thirty-scissors-hug.md
Normal file
5
.changeset/thirty-scissors-hug.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'providence-analytics': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
providence-analytics: enhanced allowlistMode detection
|
||||||
|
|
@ -423,6 +423,16 @@ class InputDataService {
|
||||||
return { globPattern };
|
return { globPattern };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets allowlist mode that determines which files to analyze
|
||||||
|
* @param {PathFromSystemRoot} startPath - local filesystem path
|
||||||
|
* @returns {'git'|'npm'}
|
||||||
|
*/
|
||||||
|
static _determineAllowListMode(startPath) {
|
||||||
|
const isNodeModule = /^.*\/(node_modules\/@.*|node_modules)\/.*$/.test(startPath);
|
||||||
|
return isNodeModule ? 'npm' : 'git';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an array of files for given extension
|
* Gets an array of files for given extension
|
||||||
* @param {PathFromSystemRoot} startPath - local filesystem path
|
* @param {PathFromSystemRoot} startPath - local filesystem path
|
||||||
|
|
@ -453,9 +463,7 @@ class InputDataService {
|
||||||
let gitIgnorePaths = [];
|
let gitIgnorePaths = [];
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
let npmPackagePaths = [];
|
let npmPackagePaths = [];
|
||||||
|
const allowlistMode = cfg.allowlistMode || this._determineAllowListMode(startPath);
|
||||||
const hasGitIgnore = getGitignoreFile(startPath);
|
|
||||||
const allowlistMode = cfg.allowlistMode || (hasGitIgnore ? 'git' : 'npm');
|
|
||||||
|
|
||||||
if (allowlistMode === 'git') {
|
if (allowlistMode === 'git') {
|
||||||
gitIgnorePaths = getGitIgnorePaths(startPath);
|
gitIgnorePaths = getGitIgnorePaths(startPath);
|
||||||
|
|
|
||||||
|
|
@ -349,9 +349,7 @@ build/
|
||||||
'./package.json': JSON.stringify({
|
'./package.json': JSON.stringify({
|
||||||
files: ['dist'],
|
files: ['dist'],
|
||||||
}),
|
}),
|
||||||
'.gitignore': `
|
'.gitignore': '/dist',
|
||||||
/dist
|
|
||||||
`,
|
|
||||||
});
|
});
|
||||||
const globOutput = InputDataService.gatherFilesFromDir('/fictional/project');
|
const globOutput = InputDataService.gatherFilesFromDir('/fictional/project');
|
||||||
expect(globOutput).to.eql([
|
expect(globOutput).to.eql([
|
||||||
|
|
@ -372,6 +370,36 @@ build/
|
||||||
// This means allowlistMode is 'npm'
|
// This means allowlistMode is 'npm'
|
||||||
'/fictional/project/dist/bundle.js',
|
'/fictional/project/dist/bundle.js',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
mockProject(
|
||||||
|
{ './dist/bundle.js': '', '.gitignore': '/dist' },
|
||||||
|
{
|
||||||
|
projectName: 'detect-as-npm',
|
||||||
|
projectPath: '/inside/proj/with/node_modules/detect-as-npm',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const globOutput3 = InputDataService.gatherFilesFromDir(
|
||||||
|
'/inside/proj/with/node_modules/detect-as-npm',
|
||||||
|
);
|
||||||
|
expect(globOutput3).to.eql([
|
||||||
|
// This means allowlistMode is 'npm' (even though we found .gitignore)
|
||||||
|
'/inside/proj/with/node_modules/detect-as-npm/dist/bundle.js',
|
||||||
|
]);
|
||||||
|
|
||||||
|
mockProject(
|
||||||
|
{ './dist/bundle.js': '', '.gitignore': '/dist' },
|
||||||
|
{
|
||||||
|
projectName: '@scoped/detect-as-npm',
|
||||||
|
projectPath: '/inside/proj/with/node_modules/@scoped/detect-as-npm',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const globOutput4 = InputDataService.gatherFilesFromDir(
|
||||||
|
'/inside/proj/with/node_modules/@scoped/detect-as-npm',
|
||||||
|
);
|
||||||
|
expect(globOutput4).to.eql([
|
||||||
|
// This means allowlistMode is 'npm' (even though we found .gitignore)
|
||||||
|
'/inside/proj/with/node_modules/@scoped/detect-as-npm/dist/bundle.js',
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('custom "allowlist" will take precedence over "allowlistMode"', async () => {
|
it('custom "allowlist" will take precedence over "allowlistMode"', async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue