Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Workspace: Ignore empty npm workspace modules #614

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/graph/Workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Workspace {
};
}

async _getModulesFromPath(cwd, relPath) {
async _getModulesFromPath(cwd, relPath, failOnMissingFiles = true) {
const nodePath = path.join(cwd, relPath);
if (this.#visitedNodePaths.has(nodePath)) {
log.verbose(`Module located at ${nodePath} has already been visited`);
Expand All @@ -189,6 +189,12 @@ class Workspace {
`package.json must contain fields 'name' and 'version'`);
}
} catch (err) {
if (!failOnMissingFiles && err.code === "ENOENT") {
// When resolving a dynamic workspace pattern (not a static path), ignore modules that
// are missing a package.json (this might simply indicate an empty directory)
log.verbose(`Ignoring module at path ${nodePath}: Directory does not contain a package.json`);
return [];
}
throw new Error(
`Failed to resolve workspace dependency resolution path ${relPath} to ${nodePath}: ${err.message}`);
}
Expand Down Expand Up @@ -228,7 +234,7 @@ class Workspace {

const resolvedModules = new Map();
await Promise.all(searchPaths.map(async (pkgPath) => {
const modules = await this._getModulesFromPath(nodePath, pkgPath);
const modules = await this._getModulesFromPath(nodePath, pkgPath, staticPatterns.includes(pkgPath));
modules.forEach((module) => {
const id = module.getId();
if (!resolvedModules.get(id)) {
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/collection.b/sub-empty/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This file is a stand-in for an empty project directory.
This directory, even though matching the npm workspace configuration pattern, should be ignored by UI5 Tooling.