diff --git a/apps/perf-test-react-components/just.config.ts b/apps/perf-test-react-components/just.config.ts index aff98a21110cdc..bf2e8d44cddd07 100644 --- a/apps/perf-test-react-components/just.config.ts +++ b/apps/perf-test-react-components/just.config.ts @@ -5,4 +5,4 @@ import { config } from './config/perf-test'; preset(); task('run-perf-test', () => getPerfRegressions(config)); -task('perf-test', series('build', 'bundle', 'run-perf-test')); +task('perf-test', series('clean', 'copy', 'bundle', 'run-perf-test')); diff --git a/apps/perf-test-react-components/package.json b/apps/perf-test-react-components/package.json index 118e28bd6b5740..d88456c7a6e3f3 100644 --- a/apps/perf-test-react-components/package.json +++ b/apps/perf-test-react-components/package.json @@ -4,17 +4,18 @@ "version": "9.0.0-rc.0", "private": true, "scripts": { - "build": "just-scripts build", "bundle": "just-scripts bundle", "lint": "just-scripts lint", "just": "just-scripts", "clean": "just-scripts clean", - "code-style": "just-scripts code-style" + "code-style": "just-scripts code-style", + "type-check": "tsc -p . --noEmit", + "test:perf": "just-scripts perf-test" }, "devDependencies": { "@fluentui/eslint-plugin": "*", "@fluentui/scripts-tasks": "*", - "@fluentui/scripts-webpack": "*" + "@fluentui/scripts-storybook": "*" }, "dependencies": { "@fluentui/scripts-perf-test-flamegrill": "*", diff --git a/apps/perf-test-react-components/tsconfig.json b/apps/perf-test-react-components/tsconfig.json index 399abe363dcada..33ae901fce3cda 100644 --- a/apps/perf-test-react-components/tsconfig.json +++ b/apps/perf-test-react-components/tsconfig.json @@ -5,7 +5,6 @@ "outDir": "lib", "module": "commonjs", "jsx": "react", - "declaration": true, "experimentalDecorators": true, "preserveConstEnums": true, "lib": ["ES2015", "DOM"], diff --git a/apps/perf-test-react-components/webpack.config.js b/apps/perf-test-react-components/webpack.config.js index e0bbbaa8322cae..6d7158e78b518a 100644 --- a/apps/perf-test-react-components/webpack.config.js +++ b/apps/perf-test-react-components/webpack.config.js @@ -1,4 +1,8 @@ -const { resources } = require('@fluentui/scripts-webpack'); +// @ts-check +const path = require('path'); +const { rules, registerTsPaths } = require('@fluentui/scripts-storybook'); + +const tsConfigPath = path.resolve(__dirname, '../../tsconfig.base.json'); // The issue here is making readable Flamegraphs that don't have complicated paths like: // ~Fabric.../../packages/react/lib/components/DetailsList/DetailsRow.base.js.DetailsRowBase.render @@ -6,13 +10,22 @@ const { resources } = require('@fluentui/scripts-webpack'); // ~DetailsRowBase.render (22.16%, 168 samples) // The only way found to do this so far has been to use a webpack serve config for bundling. // TODO: Should root cause why this only works as a serve config. -module.exports = resources.createServeConfig( - { - entry: './src/app.tsx', - mode: 'production', - output: { - filename: 'perf-test.js', - }, +const config = /** @type {import('webpack').Configuration}*/ ({ + mode: 'production', + target: ['web', 'es5'], + entry: './src/app.tsx', + output: { + filename: 'perf-test.js', + libraryTarget: 'umd', + path: path.join(__dirname, 'dist'), + }, + resolve: { + extensions: ['.ts', '.tsx', '.js'], }, - 'dist', -); + devtool: 'eval', + module: { + rules: [rules.cssRule, rules.scssRule, rules.tsRule], + }, +}); + +module.exports = registerTsPaths({ config, configFile: tsConfigPath }); diff --git a/apps/perf-test/just.config.ts b/apps/perf-test/just.config.ts index aff98a21110cdc..bf2e8d44cddd07 100644 --- a/apps/perf-test/just.config.ts +++ b/apps/perf-test/just.config.ts @@ -5,4 +5,4 @@ import { config } from './config/perf-test'; preset(); task('run-perf-test', () => getPerfRegressions(config)); -task('perf-test', series('build', 'bundle', 'run-perf-test')); +task('perf-test', series('clean', 'copy', 'bundle', 'run-perf-test')); diff --git a/apps/perf-test/package.json b/apps/perf-test/package.json index 48b0ce0a0679ca..ee66074e234e54 100644 --- a/apps/perf-test/package.json +++ b/apps/perf-test/package.json @@ -4,17 +4,18 @@ "version": "1.0.0", "private": true, "scripts": { - "build": "just-scripts build", "bundle": "just-scripts bundle", "lint": "just-scripts lint", "just": "just-scripts", "clean": "just-scripts clean", - "code-style": "just-scripts code-style" + "code-style": "just-scripts code-style", + "type-check": "tsc -p . --noEmit", + "test:perf": "just-scripts perf-test" }, "devDependencies": { "@fluentui/eslint-plugin": "*", "@fluentui/scripts-tasks": "*", - "@fluentui/scripts-webpack": "*" + "@fluentui/scripts-storybook": "*" }, "dependencies": { "@fluentui/scripts-perf-test-flamegrill": "*", diff --git a/apps/perf-test/tsconfig.json b/apps/perf-test/tsconfig.json index 1ad60241b65c29..047c5cbd92fbeb 100644 --- a/apps/perf-test/tsconfig.json +++ b/apps/perf-test/tsconfig.json @@ -5,7 +5,6 @@ "outDir": "lib", "module": "commonjs", "jsx": "react", - "declaration": true, "experimentalDecorators": true, "preserveConstEnums": true, "lib": ["ES2015", "DOM"], diff --git a/apps/perf-test/webpack.config.js b/apps/perf-test/webpack.config.js index e0bbbaa8322cae..2c7a51a03dc3c4 100644 --- a/apps/perf-test/webpack.config.js +++ b/apps/perf-test/webpack.config.js @@ -1,4 +1,9 @@ -const { resources } = require('@fluentui/scripts-webpack'); +// @ts-check +const path = require('path'); + +const { rules, registerTsPaths } = require('@fluentui/scripts-storybook'); + +const tsConfigPath = path.resolve(__dirname, '../../tsconfig.base.v8.json'); // The issue here is making readable Flamegraphs that don't have complicated paths like: // ~Fabric.../../packages/react/lib/components/DetailsList/DetailsRow.base.js.DetailsRowBase.render @@ -6,13 +11,22 @@ const { resources } = require('@fluentui/scripts-webpack'); // ~DetailsRowBase.render (22.16%, 168 samples) // The only way found to do this so far has been to use a webpack serve config for bundling. // TODO: Should root cause why this only works as a serve config. -module.exports = resources.createServeConfig( - { - entry: './src/app.tsx', - mode: 'production', - output: { - filename: 'perf-test.js', - }, +const config = /** @type {import('webpack').Configuration}*/ ({ + mode: 'production', + target: ['web', 'es5'], + entry: './src/app.tsx', + output: { + filename: 'perf-test.js', + libraryTarget: 'umd', + path: path.join(__dirname, 'dist'), + }, + resolve: { + extensions: ['.ts', '.tsx', '.js'], }, - 'dist', -); + devtool: 'eval', + module: { + rules: [rules.cssRule, rules.scssRule, rules.tsRule], + }, +}); + +module.exports = registerTsPaths({ config, configFile: tsConfigPath }); diff --git a/azure-pipelines.perf-test.yml b/azure-pipelines.perf-test.yml index c0662c3d9b1f18..53e0f5cf972170 100644 --- a/azure-pipelines.perf-test.yml +++ b/azure-pipelines.perf-test.yml @@ -36,7 +36,7 @@ jobs: name: PackagesAffected displayName: Check if v8, v9 and/or northstar packages were affected - - job: PerfTestNorthstar + - job: PerfTestReactNorthstar displayName: Perf test for @fluentui/react-northstar dependsOn: CheckIfPackagesAffected condition: eq(dependencies.CheckIfPackagesAffected.outputs['PackagesAffected.NorthstarPackageAffected'], true) @@ -51,20 +51,13 @@ jobs: displayName: yarn - script: | - yarn lage build --to @fluentui/perf-test-northstar --to @fluentui/react-conformance --verbose - condition: eq(variables.isPR, true) - displayName: Build to Perf Test (Northstar) - - - script: | - yarn perf:test --base + yarn workspace @fluentui/perf-test-northstar perf:test --base condition: eq(variables.isPR, false) - workingDirectory: packages/fluentui/perf-test-northstar displayName: Run Perf Test Base (Northstar) - script: | - yarn perf:test + yarn workspace @fluentui/perf-test-northstar perf:test condition: eq(variables.isPR, true) - workingDirectory: packages/fluentui/perf-test-northstar displayName: Run Perf Test (Northstar) - task: AzureUpload@2 @@ -107,7 +100,7 @@ jobs: - template: .devops/templates/cleanup.yml - - job: PerfTestV8 + - job: PerfTestReact displayName: Perf test for @fluentui/react dependsOn: CheckIfPackagesAffected condition: eq(dependencies.CheckIfPackagesAffected.outputs['PackagesAffected.V8PackageAffected'], true) @@ -121,14 +114,8 @@ jobs: displayName: yarn - script: | - yarn lage build --to perf-test --verbose + yarn workspace @fluentui/perf-test test:perf condition: eq(variables.isPR, true) - displayName: Build to Perf Test - - - script: | - yarn just perf-test - condition: eq(variables.isPR, true) - workingDirectory: apps/perf-test displayName: Run Perf Test - task: AzureUpload@2 @@ -167,14 +154,8 @@ jobs: displayName: yarn - script: | - yarn lage build --to perf-test-react-components --verbose - condition: eq(variables.isPR, true) - displayName: Build to Perf Test - - - script: | - yarn just perf-test + yarn workspace @fluentui/perf-test-react-components test:perf condition: eq(variables.isPR, true) - workingDirectory: apps/perf-test-react-components displayName: Run Perf Test - task: AzureUpload@2 diff --git a/packages/fluentui/digest/package.json b/packages/fluentui/digest/package.json index f64083bcfe65b8..7c572df4bb9ac0 100644 --- a/packages/fluentui/digest/package.json +++ b/packages/fluentui/digest/package.json @@ -5,9 +5,6 @@ "main": "lib/digest.js", "module": "lib/digest.js", "license": "MIT", - "bin": { - "digest": "./bin/digest.js" - }, "repository": { "type": "git", "url": "https://github.com/microsoft/digest" diff --git a/packages/fluentui/digest/src/digest.tsx b/packages/fluentui/digest/src/digest.tsx index 7c96cc48324c7f..ef699d6e80c8fd 100644 --- a/packages/fluentui/digest/src/digest.tsx +++ b/packages/fluentui/digest/src/digest.tsx @@ -12,6 +12,7 @@ export async function digestStories(digestConfig: DigestConfig) { console.log('Bundling digest..'); const defaultConfigs = defaultConfig(digestConfig); + const webpackConfigs = []; // TODO: use a real merge. or move this merge into webpack.config.ts and use webpackMerge there. diff --git a/packages/fluentui/digest/src/webpack.config.ts b/packages/fluentui/digest/src/webpack.config.ts index fc6b7904f62047..9d37228fcf52b6 100644 --- a/packages/fluentui/digest/src/webpack.config.ts +++ b/packages/fluentui/digest/src/webpack.config.ts @@ -1,7 +1,31 @@ +import { registerTsPaths, rules } from '@fluentui/scripts-storybook'; import * as path from 'path'; // TODO: remove just as a dependency. should only be a dev dependency when used. -import { webpackConfig, webpackMerge, htmlOverlay } from 'just-scripts'; +import { webpackMerge, htmlOverlay, stylesOverlay, fileOverlay, basicWebpackConfig } from 'just-scripts'; +import type { Configuration } from 'webpack'; + +const tsConfigPath = path.resolve(__dirname, '../../../../tsconfig.base.v0.json'); + +const webpackConfig = (config: Partial): Configuration => { + const mergedConfig = webpackMerge.merge( + basicWebpackConfig, + stylesOverlay(), + { + resolve: { + extensions: ['.js', '.ts', '.tsx'], + }, + module: { rules: [rules.tsRule] }, + }, + fileOverlay(), + config, + ); + + return registerTsPaths({ + config: mergedConfig, + configFile: tsConfigPath, + }); +}; const IgnoreNotFoundExportWebpackPlugin = require('ignore-not-found-export-webpack-plugin'); diff --git a/packages/fluentui/perf-test-northstar/just.config.ts b/packages/fluentui/perf-test-northstar/just.config.ts index c9885ea8db84c2..dcc2d7f7037290 100644 --- a/packages/fluentui/perf-test-northstar/just.config.ts +++ b/packages/fluentui/perf-test-northstar/just.config.ts @@ -1,4 +1,5 @@ import path from 'path'; +import { execSync } from 'child_process'; import { series, task, argv, taskPresets } from 'just-scripts'; import { config } from './tasks/perf-test.config'; @@ -11,6 +12,7 @@ taskPresets.lib(); // - Existing perf story format diverges from CSF format, requiring special loader. function bundleStories() { return async function () { + buildDependencies(); // delay require in case digest isn't built yet const { digestStories } = require('@fluentui/digest'); await digestStories({ @@ -20,6 +22,12 @@ function bundleStories() { }; } +function buildDependencies() { + const cmd = 'yarn workspace @fluentui/digest build'; + console.log(`exec: ${cmd}`); + execSync(cmd, { stdio: 'inherit' }); +} + // TODO: how should this be integrated with the default 'build' task? // TODO: add config and output dir settings like buildStorybookTask // TODO: perf-text prefix naming required? @@ -32,9 +40,8 @@ task('perf-test:run', () => { return getPerfRegressions(config, (argv() as { base?: boolean }).base); }); -// TOOD: is build doing anything meaningful? only if there's source that's not a just script? // TODO: if stories/scenarios are added in this package, make sure build catches type errors -task('perf-test', series('build', 'perf-test:bundle', 'perf-test:run')); +task('perf-test', series('perf-test:bundle', 'perf-test:run')); // TODO: Uncomment once stories can be referred to in a dependency. // This command will not be reliable until perf stories are in a package that can be set as a dep. diff --git a/packages/fluentui/perf-test-northstar/package.json b/packages/fluentui/perf-test-northstar/package.json index 1e82b92462e492..3cba3658afd9eb 100644 --- a/packages/fluentui/perf-test-northstar/package.json +++ b/packages/fluentui/perf-test-northstar/package.json @@ -4,7 +4,7 @@ "version": "0.66.4", "private": true, "scripts": { - "build": "just-scripts build", + "type-check": "tsc -p . --noEmit", "bundle": "just-scripts perf-test:bundle", "clean": "just-scripts clean", "test": "just-scripts test", diff --git a/packages/fluentui/perf-test-northstar/tasks/fluentPerfRegressions.ts b/packages/fluentui/perf-test-northstar/tasks/fluentPerfRegressions.ts index 461a962712a0b6..e86a7a6d30cd80 100644 --- a/packages/fluentui/perf-test-northstar/tasks/fluentPerfRegressions.ts +++ b/packages/fluentui/perf-test-northstar/tasks/fluentPerfRegressions.ts @@ -1,6 +1,6 @@ import * as _ from 'lodash'; import * as path from 'path'; -import { workspaceRoot } from 'nx/src/utils/app-root'; +import { workspaceRoot } from '@nrwl/devkit'; import { perfTestEnv } from '@fluentui/scripts-tasks'; import { config } from './perf-test.config'; diff --git a/scripts/storybook/src/rules.js b/scripts/storybook/src/rules.js index 8e2116b5e79604..ab0f4f37c73b2d 100644 --- a/scripts/storybook/src/rules.js +++ b/scripts/storybook/src/rules.js @@ -1,5 +1,41 @@ const { _createCodesandboxRule } = require('./utils'); +/** + * @type {import("webpack").RuleSetRule} + */ +const tsRule = { + test: [/\.tsx?$/], + use: { + loader: 'swc-loader', + options: { + jsc: { + target: 'es2015', + parser: { + syntax: 'typescript', + tsx: true, + decorators: true, + dynamicImport: true, + }, + transform: { + decoratorMetadata: true, + legacyDecorator: true, + }, + keepClassNames: true, + externalHelpers: true, + loose: true, + }, + }, + }, +}; + +/** + * @type {import("webpack").RuleSetRule} + */ +const cssRule = { + test: /\.css$/, + use: ['style-loader', 'css-loader'], +}; + /** * v8 uses SCSS/CSS modules * @type {import("webpack").RuleSetRule} @@ -61,6 +97,8 @@ const griffelRule = { */ const codesandboxRule = _createCodesandboxRule(); +exports.tsRule = tsRule; exports.scssRule = scssRule; +exports.cssRule = cssRule; exports.griffelRule = griffelRule; exports.codesandboxRule = codesandboxRule;