Skip to content

Commit

Permalink
feat: --all-projects skips failed workspaces
Browse files Browse the repository at this point in the history
By default --yarn-workspaces fails if any scans fail,
however --all-projects skips any failed projects
and logs an  error to stderr. Adapting scanning workspaces
to adhere to the same behaviour as part of --all-projects
while keeping original behaviour with --yarn-worksapces
  • Loading branch information
lili2311 committed Nov 23, 2021
1 parent 2ada19f commit 2e5effe
Show file tree
Hide file tree
Showing 6 changed files with 4,745 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/lib/plugins/get-multi-plugin-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async function processYarnWorkspacesProjects(
);
return { scannedProjects, unprocessedFiles };
} catch (e) {
debug('ERROR: ', e)
debug('Error during detecting or processing Yarn Workspaces: ', e);
return { scannedProjects: [], unprocessedFiles: targetFiles };
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/lib/plugins/nodejs-plugin/yarn-workspaces-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function processYarnWorkspaces(
let rootWorkspaceManifestContent = {};
// the folders must be ordered highest first
for (const directory of Object.keys(yarnTargetFiles)) {
debug(`Processing ${directory} as a potential Yarn workspace`)
debug(`Processing ${directory} as a potential Yarn workspace`);
let isYarnWorkspacePackage = false;
let isRootPackageJson = false;
const packageJsonFileName = pathUtil.join(directory, 'package.json');
Expand Down Expand Up @@ -82,7 +82,13 @@ export async function processYarnWorkspaces(
}
}

if (isYarnWorkspacePackage || isRootPackageJson) {
if (!(isYarnWorkspacePackage || isRootPackageJson)) {
debug(
`${packageJsonFileName} is not part of any detected workspace, skipping`,
);
continue;
}
try {
const rootDir = isYarnWorkspacePackage
? pathUtil.dirname(yarnWorkspacesFilesMap[packageJsonFileName].root)
: pathUtil.dirname(packageJsonFileName);
Expand Down Expand Up @@ -118,10 +124,11 @@ export async function processYarnWorkspaces(
},
};
result.scannedProjects.push(project);
} else {
debug(
`${packageJsonFileName} is not part of any detected workspace, skipping`,
);
} catch (e) {
if (settings.yarnWorkspaces) {
throw e;
}
debug(`Error process workspace: ${packageJsonFileName}. ERROR: ${e}`);
}
}
if (!result.scannedProjects.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ async function assembleLocalPayloads(
);
if (options['fail-fast']) {
throw new FailedToRunTestError(
'Your test request could not be completed. Please email support@snyk.io',
errorMessageWithRetry('Your test request could not be completed.'),
);
}
}
Expand Down

0 comments on commit 2e5effe

Please sign in to comment.