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

TINY-10688: Support using pnpm-workspace.yaml #141

Merged
merged 6 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Improved
- Now supports using `pnpm-workspace.yaml` to fetch workspaces.

## 14.1.2 - 2024-01-31

### Fixed
Expand Down
34 changes: 31 additions & 3 deletions modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import * as childProcess from 'child_process';
import * as glob from 'glob';
import * as Routes from './Routes';
import * as Compiler from '../compiler/Compiler';
Expand All @@ -11,6 +12,11 @@ interface PackageJson {
readonly workspaces: string[];
}

interface WorkspaceRoot {
name: string;
folder: string;
}

export const generate = async (mode: string, projectdir: string, basedir: string, configFile: string, bundler: 'webpack' | 'rollup', testfiles: string[], chunk: number,
retries: number, singleTimeout: number, stopOnFailure: boolean, basePage: string, coverage: string[], polyfills: string[]): Promise<Routes.Runner> => {
const files = testfiles.map((filePath) => {
Expand All @@ -31,7 +37,7 @@ export const generate = async (mode: string, projectdir: string, basedir: string
const pkjson: PackageJson = FileUtils.readFileAsJson(`${projectdir}/package.json`);

// Search for yarn workspace projects to use as resource folders
const findWorkspaceResources = (moduleFolder: string): Array<{name: string; folder: string}> => {
const findWorkspaceResources = (moduleFolder: string): Array<WorkspaceRoot> => {
const moduleJson = `${moduleFolder}/package.json`;
if (fs.statSync(moduleJson)) {
const workspaceJson = FileUtils.readFileAsJson(moduleJson);
Expand All @@ -41,10 +47,32 @@ export const generate = async (mode: string, projectdir: string, basedir: string
}
};

const workspaceRoots = (
const findPnpmWorkspaces = async (): Promise<WorkspaceRoot[]> => {
if (!fs.existsSync(path.join(projectdir, 'pnpm-workspace.yaml'))) {
return [];
}

return new Promise<WorkspaceRoot[]>((resolve, reject) =>
childProcess.exec('pnpm list -r --only-projects --json', (err, stdout, stderr) => {
if (err) reject(err);
else if (stderr) reject(stderr);
danoaky-tiny marked this conversation as resolved.
Show resolved Hide resolved
else {
const result: WorkspaceRoot[] = [];
for (const p of JSON.parse(stdout) as { name: string; path: string }[]) {
const folder = path.relative(projectdir, p.path);
if (!folder.length) continue;
result.push({ name: p.name, folder });
}
resolve(result);
}
})
);
};

const workspaceRoots: WorkspaceRoot[] = (
pkjson.workspaces
? Arr.bind2(pkjson.workspaces, (w) => glob.sync(w), findWorkspaceResources)
: []
: await findPnpmWorkspaces()
);

const resourceRoots = [{name: pkjson.name, folder: '.'}].concat(workspaceRoots);
Expand Down
Loading