Skip to content

Commit 66e82a3

Browse files
authored
[FIX] Workspace: Ignore empty npm workspace modules (#614)
If a dynamic npm workspaces[1] configuration resolves to a directory lacking a package.json file, ignore that module silently. This can happen when using a pattern like "packages/*" in the workspaces configuration, and then deleting a package. In case files on .gitignore remain in the directory for some users, the physical directory is not removed by git. This lead to issues for UI5 Tooling, trying to use the empty directory and throwing because of the lacking package.json. With this change, an error is only thrown if the module path is explicitly configured (no pattern). [1] https://docs.npmjs.com/cli/v9/using-npm/workspaces?v=true
1 parent b3bb3a0 commit 66e82a3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/graph/Workspace.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Workspace {
174174
};
175175
}
176176

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

229235
const resolvedModules = new Map();
230236
await Promise.all(searchPaths.map(async (pkgPath) => {
231-
const modules = await this._getModulesFromPath(nodePath, pkgPath);
237+
const modules = await this._getModulesFromPath(nodePath, pkgPath, staticPatterns.includes(pkgPath));
232238
modules.forEach((module) => {
233239
const id = module.getId();
234240
if (!resolvedModules.get(id)) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This file is a stand-in for an empty project directory.
2+
This directory, even though matching the npm workspace configuration pattern, should be ignored by UI5 Tooling.

0 commit comments

Comments
 (0)