Skip to content
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
40 changes: 31 additions & 9 deletions ts-parser/src/utils/monorepo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import * as fs from 'fs';
import * as path from 'path';

/**
* Interface for Eden monorepo pnpmWorkspace configuration
* Available when emo version >= 3.6.0
*/
export interface PnpmWorkspaceConfig {
// Workspace packages configuration (same as workspaces)
packages?: string[];
}

/**
* Interface for Eden monorepo configuration
* Supports both legacy packages format and new workspaces format
Expand Down Expand Up @@ -40,6 +49,8 @@ export interface EdenMonorepoConfig {
}>;
// New workspaces format (supports glob patterns)
workspaces?: string[];
// This has higher priority than packages and workspaces
pnpmWorkspace?: PnpmWorkspaceConfig;
}

/**
Expand Down Expand Up @@ -117,11 +128,28 @@ export class MonorepoUtils {

/**
* Get packages from Eden monorepo configuration
* Supports both packages array and workspaces array formats
* Supports packages array, workspaces array, and pnpmWorkspace formats
* pnpmWorkspace has the highest priority (emo >= 3.6.0)
*/
static getEdenPackages(rootPath: string, config: EdenMonorepoConfig): MonorepoPackage[] {
const packages: MonorepoPackage[] = [];

if (config.pnpmWorkspace && config.pnpmWorkspace.packages && config.pnpmWorkspace.packages.length > 0) {
for (const workspace of config.pnpmWorkspace.packages) {
const workspacePackages = this.expandWorkspacePattern(rootPath, workspace);
packages.push(...workspacePackages);
}
return packages; // Return early if pnpmWorkspace is configured
}

// Handle new workspaces array format
if (config.workspaces && config.workspaces.length > 0) {
for (const workspace of config.workspaces) {
const workspacePackages = this.expandWorkspacePattern(rootPath, workspace);
packages.push(...workspacePackages);
}
}

// Handle legacy packages array format
if (config.packages && config.packages.length > 0) {
for (const pkg of config.packages) {
Expand Down Expand Up @@ -154,14 +182,6 @@ export class MonorepoUtils {
}
}

// Handle new workspaces array format
if (config.workspaces && config.workspaces.length > 0) {
for (const workspace of config.workspaces) {
const workspacePackages = this.expandWorkspacePattern(rootPath, workspace);
packages.push(...workspacePackages);
}
}

return packages;
}

Expand Down Expand Up @@ -327,4 +347,6 @@ export class MonorepoUtils {

return null;
}


}
107 changes: 107 additions & 0 deletions ts-parser/src/utils/test/monorepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,113 @@ describe('MonorepoUtils', () => {
});
});

describe('pnpmWorkspace support', () => {
describe('getEdenPackages with pnpmWorkspace', () => {
it('should parse pnpmWorkspace configuration and extract packages', () => {
const testProject = createPnpmWorkspaceProject([
{
path: 'packages/core',
packageJson: {
name: '@test/core',
version: '1.0.0',
dependencies: {
'react': '^18.0.0',
'lodash': '^4.17.21'
}
}
},
{
path: 'packages/utils',
packageJson: {
name: '@test/utils',
version: '1.0.0',
dependencies: {
'typescript': '^5.0.0'
}
}
}
], ['packages/*']);

const config: EdenMonorepoConfig = {
pnpmWorkspace: {
packages: ['packages/*']
}
};

const result = MonorepoUtils.getEdenPackages(testProject.rootDir, config);

expect(result).toHaveLength(2);

const corePackage = result.find(pkg => pkg.name === '@test/core');
expect(corePackage).toBeDefined();
expect(corePackage?.path).toBe('packages/core');

const utilsPackage = result.find(pkg => pkg.name === '@test/utils');
expect(utilsPackage).toBeDefined();
expect(utilsPackage?.path).toBe('packages/utils');

testProject.cleanup();
});

it('should prioritize pnpmWorkspace over workspaces and packages', () => {
const testProject = createPnpmWorkspaceProject([
{
path: 'packages/core',
packageJson: {
name: '@test/core',
version: '1.0.0'
}
}
], ['packages/*']);

const config: EdenMonorepoConfig = {
pnpmWorkspace: {
packages: ['packages/*']
},
workspaces: ['apps/*'],
packages: [
{ path: 'legacy/*', shouldPublish: true }
]
};

const result = MonorepoUtils.getEdenPackages(testProject.rootDir, config);

expect(result).toHaveLength(1);
expect(result[0].name).toBe('@test/core');
expect(result[0].path).toBe('packages/core');

testProject.cleanup();
});

it('should handle pnpmWorkspace without catalog configuration', () => {
const testProject = createPnpmWorkspaceProject([
{
path: 'apps/web',
packageJson: {
name: '@test/web',
version: '1.0.0'
}
}
], ['apps/*']);

const config: EdenMonorepoConfig = {
pnpmWorkspace: {
packages: ['apps/*']
}
};

const result = MonorepoUtils.getEdenPackages(testProject.rootDir, config);

expect(result).toHaveLength(1);
expect(result[0].name).toBe('@test/web');

testProject.cleanup();
});
});


});

describe('findPackageForPath', () => {
const packages: MonorepoPackage[] = [
{
Expand Down
Loading