Skip to content

Commit

Permalink
Merge branch 'master' into feature/TINY-10708
Browse files Browse the repository at this point in the history
  • Loading branch information
danoaky-tiny committed Mar 8, 2024
2 parents 194b6fa + 1fac4f6 commit 66b20f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Improved

- Reduced progress logs when on CI to 10% intervals #TINY-10708
- Now supports using `pnpm-workspace.yaml` to fetch workspaces #TINY-10688

## 14.1.2 - 2024-01-31

Expand Down
36 changes: 33 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,34 @@ 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 (stderr) console.error(stderr);
if (err) {
reject(err);
return;
}

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

0 comments on commit 66b20f2

Please sign in to comment.