-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(scripts-monorepo): migrate to lerna 7 apis #29281
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
Merged
Hotell
merged 13 commits into
microsoft:master
from
Hotell:hotell/nx/lerna-7-migration-v2
Oct 11, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bb3e139
feat(scripts-monorepo): re-implement getDependencies helper to use le…
Hotell 87cac22
feat(scripts-projects-test): use new scripts-monorepo getDependency w…
Hotell a3205c9
chore: remove lerna v6 packages as they are not needed anymore
Hotell 86b7ea0
fix(apps/ts-minbar-*): disable type checking when invoking test scrip…
Hotell 1cb5ac0
refactor(lerna): move typings to /typings folder and provide manual d…
Hotell b35cf87
feat(nx): turn off analyzeSourceFiles in order to create dep graph as…
Hotell 1b6ef39
feat(scripts/monorepo): refactor getDependencies with collectDependen…
Hotell d9a85d6
feat(scripts/projects-test): remove unused lernaRoot parameter from p…
Hotell 3a8e920
refactor(cra-template): get rid of fs-extra usage
Hotell 00d1421
feat(scripts/monorepo): remove package provided in getDependencies fr…
Hotell 65275e4
feat(scripts/projects-test): restrict packProjectPackages func to be …
Hotell 2d26928
chore(apps/ts-minbar-test-react): remove unused workspaceRoot import
Hotell 48f7e6f
generate changefile
Hotell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
change/@fluentui-cra-template-be360b59-bfe0-4e5e-9fcf-8b5ec9154ac5.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "none", | ||
| "comment": "chore: refactor test to use latest APIs", | ||
| "packageName": "@fluentui/cra-template", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "none" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Why is this manual type declaration needed? | ||
| // - modules(projects) written in TS not having enabled `checkJS:true` wont infer types from .js files, thus the API will have `any` type. | ||
| // This errors in strict ts check mode. | ||
|
|
||
| /// <reference path="../../../typings/lerna/index.d.ts" /> | ||
| export declare function getDependencies(packageName: string): Promise<{ | ||
| dependencies: Dependency[]; | ||
| devDependencies: Dependency[]; | ||
| all: Dependency[]; | ||
| projectGraph: import('lerna/utils').ProjectGraphWithPackages; | ||
| }>; | ||
|
|
||
| type Dependency = { | ||
| name: string; | ||
| isTopLevel: boolean; | ||
| dependencyType: import('lerna/utils').ProjectGraphWorkspacePackageDependency['dependencyCollection']; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,82 @@ | ||
| const path = require('path'); | ||
| const lernaUtils = require('lerna/utils'); | ||
|
|
||
| const { Project } = require('@lerna/project'); | ||
|
|
||
| const { PackageGraph } = require('@lerna/package-graph'); | ||
|
|
||
| const findGitRoot = require('./findGitRoot'); | ||
| /** | ||
| * @typedef {{ | ||
| name: string, | ||
| isTopLevel: boolean, | ||
| dependencyType: lernaUtils.ProjectGraphWorkspacePackageDependency['dependencyCollection'], | ||
| }} Dependency | ||
| */ | ||
|
|
||
| /** | ||
| * | ||
| * @param {string[]} rootPackages | ||
| * @param {Map<any,any>} projectGraph | ||
| * @param {string[]} packageList | ||
| * @returns | ||
| * @param {string} project | ||
| * @param {lernaUtils.ProjectGraphWithPackages} projectGraph | ||
| * @param {*} options | ||
| * @param {Dependency[]} _acc | ||
| * @param {boolean} _areTopLevelDeps | ||
| * @returns {Dependency[]} | ||
| */ | ||
| function flattenPackageGraph(rootPackages, projectGraph, packageList = []) { | ||
| rootPackages.forEach(packageName => { | ||
| packageList.push(packageName); | ||
| function collectDependencies( | ||
| project, | ||
| projectGraph, | ||
| options = { | ||
| shallow: true, | ||
| dependenciesOnly: false, | ||
| }, | ||
| _acc = [], | ||
| _areTopLevelDeps = true, | ||
| ) { | ||
| if (!projectGraph.localPackageDependencies[project]) { | ||
| return _acc; | ||
| } | ||
|
|
||
| flattenPackageGraph([...projectGraph.get(packageName).localDependencies.keys()], projectGraph, packageList); | ||
| }); | ||
| projectGraph.localPackageDependencies[project].forEach(dependency => { | ||
| const isDependencyAlreadyCollected = _acc.some(dep => dep.name === dependency.target); | ||
|
|
||
| return packageList.sort().filter((v, i, a) => a.indexOf(v) === i); | ||
| } | ||
| if (isDependencyAlreadyCollected) { | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * Returns all the dependencies of a given package name | ||
| * @param {string} packageName including `@fluentui/` prefix | ||
| * @param {Object} options | ||
| * @param {boolean} [options.dev] include dev dependencies | ||
| * @param {boolean} [options.production] include production dependencies | ||
| */ | ||
| async function getDependencies(packageName, options = { production: true }) { | ||
| const lernaProject = new Project(path.resolve(findGitRoot(), 'packages')); | ||
| const projectPackages = await lernaProject.getPackages(); | ||
| if ( | ||
| options.dependenciesOnly && | ||
| dependency.dependencyCollection && | ||
| dependency.dependencyCollection !== 'dependencies' | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const allDepsGraph = flattenPackageGraph([packageName], new PackageGraph(projectPackages)); | ||
| const productionDepsGraph = flattenPackageGraph([packageName], new PackageGraph(projectPackages, 'dependencies')); | ||
| _acc.push({ | ||
| name: dependency.target, | ||
| dependencyType: dependency.dependencyCollection, | ||
| isTopLevel: _areTopLevelDeps, | ||
| }); | ||
|
|
||
| const devDependencies = allDepsGraph.filter(dep => !productionDepsGraph.includes(dep)); | ||
| if (!options.shallow) { | ||
| collectDependencies(dependency.target, projectGraph, options, _acc, false); | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * @type {string[]} | ||
| */ | ||
| let res = []; | ||
| return _acc; | ||
| } | ||
|
|
||
| if (options.dev) { | ||
| res = res.concat(devDependencies); | ||
| } | ||
| /** | ||
| * Returns dependencies metadata build from dependency graph for provided package | ||
| * @param {string} packageName - including `@fluentui/` prefix | ||
| */ | ||
| async function getDependencies(packageName) { | ||
| const { projectGraph } = await lernaUtils.detectProjects(); | ||
|
|
||
| if (options.production) { | ||
| res = res.concat(productionDepsGraph); | ||
| } | ||
| const allDepsGraph = collectDependencies(packageName, projectGraph, { shallow: false, dependenciesOnly: false }); | ||
| const depsGraph = collectDependencies(packageName, projectGraph, { shallow: false, dependenciesOnly: true }); | ||
| const devDepsGraph = allDepsGraph.filter(anyDep => !depsGraph.find(prodDep => prodDep.name === anyDep.name)); | ||
|
|
||
| return res; | ||
| return { | ||
| dependencies: depsGraph, | ||
| devDependencies: devDepsGraph, | ||
| all: allDepsGraph, | ||
| projectGraph, | ||
| }; | ||
| } | ||
|
|
||
| module.exports = getDependencies; | ||
| exports.getDependencies = getDependencies; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.