Skip to content

Commit 3f678ba

Browse files
committed
feat(scripts-projects-test): use new scripts-monorepo getDependency within packPackages to migrate to lerna v7 apis
1 parent 6f118a6 commit 3f678ba

File tree

2 files changed

+5
-26
lines changed

2 files changed

+5
-26
lines changed

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@
162162
"@types/jju": "1.4.1",
163163
"@types/json-schema": "^7.0.8",
164164
"@types/lerna-alias": "3.0.0",
165-
"@types/lerna__package-graph": "5.1.0",
166-
"@types/lerna__project": "5.1.0",
167165
"@types/loader-utils": "2.0.3",
168166
"@types/lodash": "4.14.182",
169167
"@types/markdown-table": "2.0.0",
@@ -273,8 +271,6 @@
273271
"just-scripts": "1.8.2",
274272
"lage": "1.8.8",
275273
"lerna": "7.1.3",
276-
"@lerna/project": "6.4.1",
277-
"@lerna/package-graph": "6.4.1",
278274
"lerna-alias": "3.0.3-0",
279275
"license-webpack-plugin": "2.3.10",
280276
"lint-staged": "10.2.10",

scripts/projects-test/src/packPackages.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import path from 'path';
22

3+
import { getDependencies, workspaceRoot } from '@fluentui/scripts-monorepo';
34
import { sh } from '@fluentui/scripts-utils';
4-
import { PackageGraph } from '@lerna/package-graph';
5-
import { Project } from '@lerna/project';
65
import fs from 'fs-extra';
76

87
import { createTempDir, shEcho } from './utils';
@@ -12,17 +11,6 @@ type PackedPackages = Record<string, string>;
1211
/** Shared packed packages between tests since they're not modified by any test */
1312
let packedPackages: PackedPackages;
1413

15-
function flattenPackageGraph(rootPackages: string[], projectGraph: PackageGraph, packageList: string[] = []): string[] {
16-
rootPackages.forEach(packageName => {
17-
packageList.push(packageName);
18-
19-
// NOTE: we need to use Array.from instead of spread to new array because v0 packages have target `es5` thus this would trigger TS error
20-
flattenPackageGraph(Array.from(projectGraph.get(packageName).localDependencies.keys()), projectGraph, packageList);
21-
});
22-
23-
return packageList.sort().filter((v, i, a) => a.indexOf(v) === i);
24-
}
25-
2614
export async function addResolutionPathsForProjectPackages(testProjectDir: string, isTemplateJson?: boolean) {
2715
const jsonPath = path.resolve(testProjectDir, isTemplateJson ? 'template.json' : 'package.json');
2816
const json = fs.readJSONSync(jsonPath);
@@ -48,14 +36,9 @@ export async function packProjectPackages(
4836

4937
packedPackages = {};
5038

51-
const lernaProject = new Project(lernaRoot);
52-
// this is the list of package.json contents with some extra properties
53-
const projectPackages = await lernaProject.getPackages();
54-
55-
logger(`✔️ Used lerna config: ${lernaProject.rootConfigLocation}`);
39+
logger(`✔️ Used lerna config: ${workspaceRoot}`);
5640

57-
const projectPackagesGraph = new PackageGraph(projectPackages, 'dependencies');
58-
const requiredPackages = flattenPackageGraph(rootPackages, projectPackagesGraph);
41+
const { dependencies: requiredPackages, projectGraph } = await getDependencies(rootPackages);
5942

6043
logger(`✔️ Following packages will be packed:${requiredPackages.map(p => `\n${' '.repeat(30)}- ${p}`)}`);
6144

@@ -67,13 +50,13 @@ export async function packProjectPackages(
6750

6851
await Promise.all(
6952
requiredPackages.map(async packageName => {
70-
const packageInfo = projectPackages.find(pkg => pkg.name === packageName);
53+
const packageInfo = projectGraph.nodes[packageName].package;
7154
if (!packageInfo) {
7255
throw new Error(`Package ${packageName} doesn't exist`);
7356
}
7457

7558
const packagePath = packageInfo.location;
76-
const packageMain: string | undefined = packageInfo.get('main');
59+
const packageMain = packageInfo.get('main') as string | undefined;
7760
const entryPointPath = packageMain ? path.join(packagePath, packageMain) : '';
7861
if (!fs.existsSync(entryPointPath)) {
7962
throw new Error(

0 commit comments

Comments
 (0)