From 981f357cb5e176b1238c1d9687a70435d2d27a07 Mon Sep 17 00:00:00 2001 From: Daniel Oakman <141111365+danoaky-tiny@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:22:08 +1100 Subject: [PATCH 1/6] TINY-10688: Call `pnpm list` if `pnpm-workspace.yaml` exists to fetch workspace roots --- .../main/ts/bedrock/server/RunnerRoutes.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts index 447c5d10..a19c81ee 100644 --- a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts +++ b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts @@ -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'; @@ -41,10 +42,30 @@ export const generate = async (mode: string, projectdir: string, basedir: string } }; + const findPnpmWorkspaces = async () => { + if (!fs.existsSync(path.join(projectdir, 'pnpm-workspace.yaml'))) { + return []; + } + + return new Promise<{ name: string; folder: string }[]>((resolve, reject) => + childProcess.exec('pnpm list -r --only-projects --json', (err, stdout, stderr) => { + if (err) reject(err); + else if (stderr) reject(stderr); + else { + resolve( + (JSON.parse(stdout) as { name: string; path: string }[]) + .map((p) => ({ name: p.name, folder: path.relative(projectdir, p.path) })) + .filter((p) => p.folder) + ); + } + }) + ); + }; + const workspaceRoots = ( pkjson.workspaces ? Arr.bind2(pkjson.workspaces, (w) => glob.sync(w), findWorkspaceResources) - : [] + : await findPnpmWorkspaces() ); const resourceRoots = [{name: pkjson.name, folder: '.'}].concat(workspaceRoots); From 16d36d8b83bf62184e84f744639bbe09188d5e22 Mon Sep 17 00:00:00 2001 From: Daniel Oakman <141111365+danoaky-tiny@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:06:44 +1100 Subject: [PATCH 2/6] TINY-10688: Added `WorkspaceRoot` interface --- .../src/main/ts/bedrock/server/RunnerRoutes.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts index a19c81ee..b2193b1b 100644 --- a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts +++ b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts @@ -12,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 => { const files = testfiles.map((filePath) => { @@ -32,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 => { const moduleJson = `${moduleFolder}/package.json`; if (fs.statSync(moduleJson)) { const workspaceJson = FileUtils.readFileAsJson(moduleJson); @@ -42,12 +47,12 @@ export const generate = async (mode: string, projectdir: string, basedir: string } }; - const findPnpmWorkspaces = async () => { + const findPnpmWorkspaces = async (): Promise => { if (!fs.existsSync(path.join(projectdir, 'pnpm-workspace.yaml'))) { return []; } - return new Promise<{ name: string; folder: string }[]>((resolve, reject) => + return new Promise((resolve, reject) => childProcess.exec('pnpm list -r --only-projects --json', (err, stdout, stderr) => { if (err) reject(err); else if (stderr) reject(stderr); @@ -62,7 +67,7 @@ export const generate = async (mode: string, projectdir: string, basedir: string ); }; - const workspaceRoots = ( + const workspaceRoots: WorkspaceRoot[] = ( pkjson.workspaces ? Arr.bind2(pkjson.workspaces, (w) => glob.sync(w), findWorkspaceResources) : await findPnpmWorkspaces() From 49929cc061ddccd3ad84dd422d5b2c68d9084286 Mon Sep 17 00:00:00 2001 From: Daniel Oakman <141111365+danoaky-tiny@users.noreply.github.com> Date: Fri, 1 Mar 2024 07:27:25 +1100 Subject: [PATCH 3/6] TINY-10688: Added changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 765351ab..6faf8a30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 72fe456a65157d90bd4f34c0589eef6f3e2f064a Mon Sep 17 00:00:00 2001 From: Daniel Oakman <141111365+danoaky-tiny@users.noreply.github.com> Date: Fri, 1 Mar 2024 07:48:45 +1100 Subject: [PATCH 4/6] TINY-10688: Use a `for of` instead of iterating twice in a `map().filter()` --- .../src/main/ts/bedrock/server/RunnerRoutes.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts index b2193b1b..9b4126ec 100644 --- a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts +++ b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts @@ -57,11 +57,13 @@ export const generate = async (mode: string, projectdir: string, basedir: string if (err) reject(err); else if (stderr) reject(stderr); else { - resolve( - (JSON.parse(stdout) as { name: string; path: string }[]) - .map((p) => ({ name: p.name, folder: path.relative(projectdir, p.path) })) - .filter((p) => p.folder) - ); + 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); } }) ); From aba54dec9c605b770261fa8e10d1f0662622ecaf Mon Sep 17 00:00:00 2001 From: Daniel Oakman <141111365+danoaky-tiny@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:47:10 +1100 Subject: [PATCH 5/6] TINY-10688: Just print `stderr` --- .../main/ts/bedrock/server/RunnerRoutes.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts index 9b4126ec..0d8c47d2 100644 --- a/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts +++ b/modules/server/src/main/ts/bedrock/server/RunnerRoutes.ts @@ -54,17 +54,19 @@ export const generate = async (mode: string, projectdir: string, basedir: string return new Promise((resolve, reject) => childProcess.exec('pnpm list -r --only-projects --json', (err, stdout, stderr) => { - if (err) reject(err); - else if (stderr) reject(stderr); - 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); + 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); }) ); }; From d2c5b9d30612722f6a2ec0564985d2b777f2ef6b Mon Sep 17 00:00:00 2001 From: Daniel Oakman <141111365+danoaky-tiny@users.noreply.github.com> Date: Wed, 6 Mar 2024 09:51:09 +1100 Subject: [PATCH 6/6] TINY-10688: Added missing ticket number to changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6faf8a30..60c524d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ 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. +- Now supports using `pnpm-workspace.yaml` to fetch workspaces #TINY-10688 ## 14.1.2 - 2024-01-31