11import path from 'path' ;
22
3+ import { getDependencies , workspaceRoot } from '@fluentui/scripts-monorepo' ;
34import { sh } from '@fluentui/scripts-utils' ;
4- import { PackageGraph } from '@lerna/package-graph' ;
5- import { Project } from '@lerna/project' ;
65import fs from 'fs-extra' ;
76
87import { 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 */
1312let 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-
2614export 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