Skip to content

Commit

Permalink
feat: replace lerna-alias with nx APIs (microsoft#30149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell authored Jan 5, 2024
1 parent 6512201 commit a493617
Show file tree
Hide file tree
Showing 35 changed files with 187 additions and 116 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
"@types/jest-axe": "3.5.5",
"@types/jju": "1.4.1",
"@types/json-schema": "^7.0.8",
"@types/lerna-alias": "3.0.0",
"@types/loader-utils": "2.0.3",
"@types/lodash": "4.14.182",
"@types/markdown-table": "2.0.0",
Expand Down Expand Up @@ -272,7 +271,6 @@
"just-scripts": "1.8.2",
"lage": "1.8.8",
"lerna": "7.1.3",
"lerna-alias": "3.0.3-0",
"license-webpack-plugin": "2.3.10",
"lint-staged": "10.2.10",
"loader-utils": "2.0.4",
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/accessibility/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"lerna-alias": "^3.0.3-0"
"@fluentui/scripts-jest": "*"
},
"files": [
"dist"
Expand Down
1 change: 0 additions & 1 deletion packages/fluentui/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@fluentui/react-northstar": "*",
"@fluentui/react-northstar-prototypes": "*",
"@types/react-router-dom": "^5.1.5",
"lerna-alias": "^3.0.3-0",
"lodash": "^4.17.15",
"react-router-dom": "^5.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/fluentui/perf/gulp/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const webpackConfig: webpack.Configuration = {
},
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
...config.lernaAliases({ type: 'webpack' }),
...config.webpackAliases,

// We are using React in production mode with tracing.
// https://gist.github.com/bvaughn/25e6233aeb1b4f0cdb8d8366e54a3977
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/react-bindings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"@types/classnames": "^2.2.9",
"lerna-alias": "^3.0.3-0"
"@types/classnames": "^2.2.9"
},
"files": [
"dist"
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/react-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"@types/react-frame-component": "^4.1.1",
"lerna-alias": "^3.0.3-0"
"@types/react-frame-component": "^4.1.1"
},
"peerDependencies": {
"@babel/standalone": "^7.8.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"@types/simulant": "^0.2.0",
"lerna-alias": "^3.0.3-0",
"simulant": "^0.2.2"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"lerna-alias": "^3.0.3-0"
"@fluentui/scripts-jest": "*"
},
"files": [
"dist"
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/react-component-ref/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"lerna-alias": "^3.0.3-0"
"@fluentui/scripts-jest": "*"
},
"files": [
"dist"
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/react-icons-northstar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"@types/classnames": "^2.2.9",
"lerna-alias": "^3.0.3-0"
"@types/classnames": "^2.2.9"
},
"files": [
"dist"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"@types/stylis": "4.0.0",
"lerna-alias": "^3.0.3-0"
"@types/stylis": "4.0.0"
},
"files": [
"dist"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"lerna-alias": "^3.0.3-0",
"react-fela": "^10.6.1"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"devDependencies": {
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"lerna-alias": "^3.0.3-0"
"@fluentui/scripts-gulp": "*"
},
"files": [
"dist"
Expand Down
1 change: 0 additions & 1 deletion packages/fluentui/react-northstar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"csstype": "^3.0.2",
"faker": "^4.1.0",
"fela-tools": "^10.6.1",
"lerna-alias": "^3.0.3-0",
"qs": "^6.8.0",
"simulant": "^0.2.2"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/react-proptypes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"lerna-alias": "^3.0.3-0"
"@fluentui/scripts-jest": "*"
},
"files": [
"dist"
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/react-telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@types/react-table": "^7.0.19",
"lerna-alias": "^3.0.3-0"
"@types/react-table": "^7.0.19"
},
"files": [
"dist"
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"devDependencies": {
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"lerna-alias": "^3.0.3-0"
"@fluentui/scripts-gulp": "*"
},
"files": [
"dist"
Expand Down
3 changes: 1 addition & 2 deletions packages/fluentui/styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-babel": "*",
"@fluentui/scripts-gulp": "*",
"@fluentui/scripts-jest": "*",
"lerna-alias": "^3.0.3-0"
"@fluentui/scripts-jest": "*"
},
"files": [
"dist"
Expand Down
33 changes: 25 additions & 8 deletions scripts/gulp/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
/* eslint-disable @typescript-eslint/naming-convention */
import * as path from 'path';
import * as _ from 'lodash';
import * as webpack from 'webpack';
import { URL } from 'url';

import { getLernaAliases } from '@fluentui/scripts-monorepo';
import { getWorkspaceProjects, getWorkspaceProjectsAliases } from '@fluentui/scripts-monorepo';
import * as _ from 'lodash';
import * as webpack from 'webpack';

// northstar packages should pull these from npm, not the repo
const excludedPackages = ['@fluentui/dom-utilities'];
const lernaAliases = (options: Omit<Parameters<typeof getLernaAliases>[number], 'excludedPackages'>) =>
getLernaAliases({ excludedPackages, ...options });
const excludedPackages = [
// northstar packages should pull these from npm, not the repo
'@fluentui/dom-utilities',
// we need to apply aliases only for v0 projects - otherwise webpack will explode. This will(can) be mitigated by implementing no-build needed for v0 e2e (https://github.com/microsoft/fluentui/pull/26928/commits/6dbc149b54c251ba74b3ebb70057846389ed3f88#diff-f1ffee4111d5db5b78ed08c5318068a3b5e313d6dbc72b60231cc65e4bd5eb2a)
...getProjectsExceptV0(),
];

const webpackAliases = getWorkspaceProjectsAliases({ excludeProjects: excludedPackages, type: 'webpack' });

function getProjectsExceptV0() {
const projectConfigs = getWorkspaceProjects().values();
const projects: string[] = [];
for (const projectConfig of projectConfigs) {
const tags = projectConfig.tags ?? [];
if (!tags.includes('react-northstar')) {
projects.push(projectConfig.name!);
}
}

return projects;
}

// ------------------------------------
// Environment vars
Expand Down Expand Up @@ -182,7 +199,7 @@ const config = {
isRoot,
/** Package name the task is running against: default to react if running at root, or cwd otherwise */
package: packageName,
lernaAliases,
webpackAliases,
};

export default config;
3 changes: 2 additions & 1 deletion scripts/gulp/src/tasks/test-dependencies/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';

import { LicenseWebpackPlugin } from 'license-webpack-plugin';
import webpack from 'webpack';

Expand Down Expand Up @@ -59,7 +60,7 @@ export const prepareWebpackConfig = (options: WebpackOptions) => {
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
...config.lernaAliases({ type: 'webpack' }),
...config.webpackAliases,
src: paths.packageSrc('react-northstar'),
},
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/gulp/src/webpack/webpack.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const webpackConfig: webpack.Configuration = {
path: require.resolve('path-browserify'),
},
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: config.lernaAliases({ type: 'webpack' }),
alias: config.webpackAliases,
},
performance: {
hints: false, // to (temporarily) disable "WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit")
Expand Down
9 changes: 4 additions & 5 deletions scripts/gulp/src/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { getDefaultEnvironmentVars } from '@fluentui/scripts-monorepo';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import _ from 'lodash';
import webpack from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import webpack from 'webpack';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';

import { getDefaultEnvironmentVars } from '@fluentui/scripts-monorepo';

import config from '../config';

const { paths } = config;
Expand Down Expand Up @@ -125,7 +124,7 @@ const webpackConfig: webpack.Configuration &
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
...config.lernaAliases({ type: 'webpack' }),
...config.webpackAliases,
src: paths.packageSrc('react-northstar'),
faker: 'faker/locale/en',
'react-hook-form': 'react-hook-form/dist/react-hook-form.ie11',
Expand Down
7 changes: 3 additions & 4 deletions scripts/jest/src/jest.preset.v0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getLernaAliases, workspaceRoot } = require('@fluentui/scripts-monorepo');
const { getWorkspaceProjectsAliases } = require('@fluentui/scripts-monorepo');

// northstar packages should pull these from npm, not the repo
const excludedPackages = ['@fluentui/dom-utilities'];
Expand All @@ -20,10 +20,9 @@ const createConfig = (/** @type {import('@jest/types').Config.InitialOptions} */
clearMocks: true,
...customConfig,
moduleNameMapper: {
...getLernaAliases({
...getWorkspaceProjectsAliases({
type: 'jest',
excludedPackages,
directory: workspaceRoot,
excludeProjects: excludedPackages,
}),
...customConfig.moduleNameMapper,
},
Expand Down
18 changes: 10 additions & 8 deletions scripts/lint-staged/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const fs = require('fs');
const os = require('os');
const path = require('path');
const { promisify } = require('util');
const { rollup: lernaAliases } = require('lerna-alias');

const { getWorkspaceProjects, workspaceRoot } = require('@fluentui/scripts-monorepo');
const { default: PQueue } = require('p-queue');
const exec = promisify(child_process.exec);

Expand All @@ -28,13 +29,14 @@ function groupFilesByPackage() {
/** @type {{ [packagePath: string]: string[] }} */
const filesByPackage = {};

const packagesWithEslint = Object.values(lernaAliases({ sourceDirectory: false })).filter(
packagePath =>
// exclude @fluentui/noop (northstar packages root)
path.basename(packagePath) !== 'fluentui' &&
// only include packages with an eslintrc (any extension)
fs.readdirSync(packagePath).some(f => f.startsWith('.eslintrc')),
);
const packagesWithEslint = [];
const projects = getWorkspaceProjects();
for (const [, projectConfig] of projects) {
const absoluteRootPath = path.join(workspaceRoot, projectConfig.root);
if (fs.readdirSync(absoluteRootPath).some(f => f.startsWith('.eslintrc'))) {
packagesWithEslint.push(absoluteRootPath);
}
}

for (const file of files) {
// eslint-disable-next-line no-shadow
Expand Down
16 changes: 0 additions & 16 deletions scripts/monorepo/src/get-lerna-aliases.js

This file was deleted.

22 changes: 10 additions & 12 deletions scripts/monorepo/src/getAllPackageInfo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const lernaAlias = require('lerna-alias');
const findGitRoot = require('./findGitRoot');

const { workspaceRoot } = require('@nx/devkit');

const { getWorkspaceProjects } = require('./workspace-utils');

/**
* @type {import('./types').AllPackageInfo}
Expand All @@ -20,19 +22,15 @@ function getAllPackageInfo() {
return packageInfo;
}

// Get mapping from package name to package path
// (rollup helper happens to be good for getting basic package name/path pairs)
const packagePaths = lernaAlias.rollup({ sourceDirectory: false });
delete packagePaths['@fluentui/noop']; // not a real package
const projects = getWorkspaceProjects();

packageInfo = {};
cwdForPackageInfo = process.cwd();
const gitRoot = findGitRoot();

for (const [packageName, packagePath] of Object.entries(packagePaths)) {
packageInfo[packageName] = {
packagePath: path.relative(gitRoot, packagePath),
packageJson: fs.readJSONSync(path.join(packagePath, 'package.json')),
for (const [projectName, projectConfig] of projects) {
packageInfo[projectName] = {
packagePath: projectConfig.root,
packageJson: JSON.parse(fs.readFileSync(path.join(workspaceRoot, projectConfig.root, 'package.json'), 'utf-8')),
};
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/monorepo/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export { default as findRepoDeps } from './findRepoDeps';
export { default as getAllPackageInfo } from './getAllPackageInfo';
export { isConvergedPackage, shipsAMD } from './isConvergedPackage';
export { getAffectedPackages } from './getAffectedPackages';
export { getLernaAliases } from './get-lerna-aliases';
export { getDefaultEnvironmentVars } from './getDefaultEnvironmentVars';
export { getProjectMetadata, workspaceRoot, getUncommittedFiles, getUntrackedFiles } from './utils';
export * as eslintConstants from './eslint-constants';
export { getNthCommit } from './getNthCommit';
export { tree, flushTreeChanges } from './tree';
export { getWorkspaceProjects, getWorkspaceProjectsAliases } from './workspace-utils';
Loading

0 comments on commit a493617

Please sign in to comment.