Skip to content
Open
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
22 changes: 19 additions & 3 deletions packages/core/src/config-loader/find-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ export async function findDmnoServices(includeUnitialized = false): Promise<Scan
const filePath = path.join(cwd, settingsLocation.file);
if (!await pathExists(filePath)) continue;

debug(`found workspace settings file: ${filePath}`);

// assume first package.json file found is root until we find evidence otherwise
if (settingsLocation.file === 'package.json' && !dmnoWorkspaceRootPath) {
dmnoWorkspaceRootPath = cwd;
debug(`set dmnoWorkspaceRootPath to ${cwd} (from package.json)`);
}

debug(`looking for workspace globs in ${filePath} > ${settingsLocation.globsPath}`);
Expand All @@ -97,13 +100,26 @@ export async function findDmnoServices(includeUnitialized = false): Promise<Scan
}
const possiblePackagePatterns = _.get(fileContents, settingsLocation.globsPath);
if (possiblePackagePatterns) {
packagePatterns = possiblePackagePatterns;
dmnoWorkspaceRootPath = cwd;
isMonorepo = true;
// Handle both legacy format (workspaces as array) and modern format (workspaces as object with packages property)
let actualPackagePatterns: string[] | undefined;
if (Array.isArray(possiblePackagePatterns)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Array.isArray(possiblePackagePatterns)) {
if (_.isArray(possiblePackagePatterns)) {

actualPackagePatterns = possiblePackagePatterns;
} else if (possiblePackagePatterns && typeof possiblePackagePatterns === 'object' && possiblePackagePatterns.packages) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (possiblePackagePatterns && typeof possiblePackagePatterns === 'object' && possiblePackagePatterns.packages) {
} else if (_.isObject(possiblePackagePatterns) && _.isArray(possiblePackagePatterns.packages)) {

actualPackagePatterns = possiblePackagePatterns.packages;
}

if (actualPackagePatterns) {
debug(`found workspace patterns in ${filePath}:`, actualPackagePatterns);
packagePatterns = actualPackagePatterns;
dmnoWorkspaceRootPath = cwd;
debug(`updated dmnoWorkspaceRootPath to ${cwd} (from workspace patterns)`);
isMonorepo = true;
}
}

// if this is our dmno-specific file, we'll consider this "final" and stop scanning upwards
if (settingsLocation.file === '.dmno/workspace.yaml') {
debug(`found dmno workspace config at ${filePath} - stopping upward scan`);
dmnoWorkspaceFinal = true;
// everything else in the yaml file is additional settings
otherSettings = _.omit(fileContents, settingsLocation.globsPath);
Expand Down
Loading