From a774f999d9fd6348f678012e79b3985052f0f654 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 15 Feb 2023 13:47:55 +0100 Subject: [PATCH 1/5] chore: make lint task run without need of build --- apps/public-docsite-resources/package.json | 2 +- apps/react-18-tests-v8/package.json | 2 +- lage.config.js | 2 +- .../react-portal-compat-context/package.json | 2 +- .../react-portal-compat/package.json | 2 +- scripts/tasks/src/lint-imports.ts | 14 ++++--- scripts/tasks/src/presets.ts | 41 ++++++++++--------- workspace.json | 3 +- 8 files changed, 38 insertions(+), 30 deletions(-) diff --git a/apps/public-docsite-resources/package.json b/apps/public-docsite-resources/package.json index 0e0117cba9512..46f7bba0072b4 100644 --- a/apps/public-docsite-resources/package.json +++ b/apps/public-docsite-resources/package.json @@ -19,7 +19,7 @@ "scripts": { "build": "just-scripts build", "bundle": "just-scripts bundle", - "lint": "just-scripts lint", + "lint": "eslint --ext .js,.ts,.tsx ./src", "just": "just-scripts", "clean": "just-scripts clean", "code-style": "just-scripts code-style", diff --git a/apps/react-18-tests-v8/package.json b/apps/react-18-tests-v8/package.json index 056fd6394b305..563caf5c4d426 100644 --- a/apps/react-18-tests-v8/package.json +++ b/apps/react-18-tests-v8/package.json @@ -9,7 +9,7 @@ "format:check": "yarn format -c", "e2e": "cypress run --component", "e2e:local": "cypress open --component", - "lint": "eslint --ext .js,.ts.,.tsx ./src", + "lint": "eslint --ext .js,.ts,.tsx ./src", "test": "jest --passWithNoTests", "start": "webpack-dev-server --mode=development" }, diff --git a/lage.config.js b/lage.config.js index 543af751ae9b8..a2474bb61c3cf 100644 --- a/lage.config.js +++ b/lage.config.js @@ -5,7 +5,7 @@ module.exports = { 'build:info': [], bundle: ['build'], 'bundle-size': ['build'], - lint: ['build'], + lint: [], clean: [], test: ['build'], 'type-check': ['build'], diff --git a/packages/react-components/react-portal-compat-context/package.json b/packages/react-components/react-portal-compat-context/package.json index c42745a5de63f..84d7e68b75d28 100644 --- a/packages/react-components/react-portal-compat-context/package.json +++ b/packages/react-components/react-portal-compat-context/package.json @@ -16,7 +16,7 @@ "clean": "just-scripts clean", "code-style": "just-scripts code-style", "just": "just-scripts", - "lint": "just-scripts lint && just-scripts lint-imports", + "lint": "just-scripts lint", "test": "jest --passWithNoTests", "type-check": "tsc -b tsconfig.json", "generate-api": "tsc -p ./tsconfig.lib.json --emitDeclarationOnly && just-scripts api-extractor" diff --git a/packages/react-components/react-portal-compat/package.json b/packages/react-components/react-portal-compat/package.json index 8b9c7c84acd55..c4e27a796df05 100644 --- a/packages/react-components/react-portal-compat/package.json +++ b/packages/react-components/react-portal-compat/package.json @@ -19,7 +19,7 @@ "e2e": "cypress run --component", "e2e:local": "cypress open --component", "just": "just-scripts", - "lint": "just-scripts lint && just-scripts lint-imports", + "lint": "just-scripts lint", "test": "jest --passWithNoTests", "type-check": "tsc -b tsconfig.json", "generate-api": "tsc -p ./tsconfig.lib.json --emitDeclarationOnly && just-scripts api-extractor" diff --git a/scripts/tasks/src/lint-imports.ts b/scripts/tasks/src/lint-imports.ts index 34a430733370a..c97521dba7389 100644 --- a/scripts/tasks/src/lint-imports.ts +++ b/scripts/tasks/src/lint-imports.ts @@ -1,9 +1,10 @@ -import { getAllPackageInfo, findGitRoot } from '@fluentui/scripts-monorepo'; -import { readConfig } from '@fluentui/scripts-utils'; -import * as glob from 'glob'; -import * as path from 'path'; import * as fs from 'fs'; +import * as path from 'path'; + +import { findGitRoot, getAllPackageInfo } from '@fluentui/scripts-monorepo'; +import { readConfig } from '@fluentui/scripts-utils'; import chalk from 'chalk'; +import * as glob from 'glob'; interface ImportErrorGroup { count: number; @@ -60,7 +61,10 @@ export function lintImports() { const currentPackageJson = readConfig('package.json'); const currentMonorepoPackage = currentPackageJson.name; - return lintSource(); + return lintSource().catch(err => { + console.error(err); + process.exit(1); + }); function lintSource() { const files = glob.sync(path.join(sourcePath, '**/*.{ts,tsx}')); diff --git a/scripts/tasks/src/presets.ts b/scripts/tasks/src/presets.ts index 2a58b06e43a04..13b8b283007bd 100644 --- a/scripts/tasks/src/presets.ts +++ b/scripts/tasks/src/presets.ts @@ -1,25 +1,24 @@ -import { task, series, parallel, condition, option, addResolvePath } from 'just-scripts'; - -import path from 'path'; import fs from 'fs'; +import path from 'path'; import { isConvergedPackage } from '@fluentui/scripts-monorepo'; +import { addResolvePath, condition, option, parallel, series, task } from 'just-scripts'; +import { apiExtractor } from './api-extractor'; +import { getJustArgv } from './argv'; import { babel } from './babel'; import { clean } from './clean'; import { copy, copyCompiled } from './copy'; -import { jest as jestTask, jestWatch } from './jest'; -import { sass } from './sass'; -import { ts } from './ts'; import { eslint } from './eslint'; -import { webpack, webpackDevServer } from './webpack'; -import { apiExtractor } from './api-extractor'; +import { jest as jestTask, jestWatch } from './jest'; import { lintImports } from './lint-imports'; -import { prettier } from './prettier'; import { postprocessTask } from './postprocess'; import { postprocessAmdTask } from './postprocess-amd'; -import { startStorybookTask, buildStorybookTask } from './storybook'; -import { getJustArgv } from './argv'; +import { prettier } from './prettier'; +import { sass } from './sass'; +import { buildStorybookTask, startStorybookTask } from './storybook'; +import { ts } from './ts'; +import { webpack, webpackDevServer } from './webpack'; /** Do only the bare minimum setup of options and resolve paths */ export function basicPreset() { @@ -102,13 +101,7 @@ export function preset() { condition('jest', () => fs.existsSync(path.join(process.cwd(), 'jest.config.js'))), ); - task( - 'lint', - parallel( - condition('lint-imports', () => !isConvergedPackage()), - 'eslint', - ), - ); + task('lint', 'eslint'); task('code-style', series('prettier', 'lint')); @@ -117,7 +110,17 @@ export function preset() { task('build:node-lib', series('clean', 'copy', 'ts:commonjs')).cached!(); - task('build', series('clean', 'copy', 'sass', 'ts', 'api-extractor')).cached!(); + task( + 'build', + series( + 'clean', + 'copy', + 'sass', + 'ts', + 'api-extractor', + condition('lint-imports', () => !isConvergedPackage()), + ), + ).cached!(); task( 'bundle', diff --git a/workspace.json b/workspace.json index 6103cce5741dd..d24024326a2c0 100644 --- a/workspace.json +++ b/workspace.json @@ -272,7 +272,8 @@ "@fluentui/public-docsite-v9": { "root": "apps/public-docsite-v9", "projectType": "application", - "implicitDependencies": [] + "implicitDependencies": [], + "tags": ["platform:web"] }, "@fluentui/react": { "root": "packages/react", From ad8f92183f8d4858f54d42c8883c8d9c3de53e51 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 16 Feb 2023 16:15:03 +0100 Subject: [PATCH 2/5] chore: re-enable AMD import checks for only mixed and v8 packages --- apps/public-docsite-resources/just.config.ts | 2 +- packages/monaco-editor/just.config.ts | 2 +- packages/react-monaco-editor/just.config.ts | 2 +- scripts/monorepo/src/index.d.ts | 2 +- scripts/monorepo/src/index.js | 2 +- scripts/monorepo/src/isConvergedPackage.js | 47 ++++++- scripts/tasks/src/lint-imports.ts | 127 +++++++++++++++---- scripts/tasks/src/presets.ts | 10 +- workspace.json | 8 +- 9 files changed, 164 insertions(+), 38 deletions(-) diff --git a/apps/public-docsite-resources/just.config.ts b/apps/public-docsite-resources/just.config.ts index 4e67a31a4ac52..63303cc466ba3 100644 --- a/apps/public-docsite-resources/just.config.ts +++ b/apps/public-docsite-resources/just.config.ts @@ -6,5 +6,5 @@ preset(); task('generate-json', () => generatePageJsonFiles(require('./config/api-docs'))); // copied from scripts/just.config.js with addition of generate-json -task('build', series('clean', 'copy', 'sass', 'generate-json', 'ts')).cached!(); +task('build', series('clean', 'copy', 'sass', 'generate-json', 'ts', 'lint-imports:all')).cached!(); task('dev', series('copy', 'sass', 'generate-json', 'webpack-dev-server')); diff --git a/packages/monaco-editor/just.config.ts b/packages/monaco-editor/just.config.ts index a42b6f92a7ca9..c45111615c5fe 100644 --- a/packages/monaco-editor/just.config.ts +++ b/packages/monaco-editor/just.config.ts @@ -34,6 +34,6 @@ task('ts:postprocess', postprocess.postprocessTask([...postprocess.defaultLibPat task('ts', series(parallel('ts:esm', 'ts:commonjs'), 'ts:postprocess')); task('eslint', eslint); -task('build', series('clean', 'copy', 'transform-css', 'ts')).cached!(); +task('build', series('clean', 'copy', 'transform-css', 'ts', 'lint-imports:all')).cached!(); task('lint', 'eslint'); diff --git a/packages/react-monaco-editor/just.config.ts b/packages/react-monaco-editor/just.config.ts index a6237c53abc50..acecacfdca022 100644 --- a/packages/react-monaco-editor/just.config.ts +++ b/packages/react-monaco-editor/just.config.ts @@ -8,4 +8,4 @@ task('copy-types', copyTypes); // These have to be manually re-defined because we need to chain copy-types after copy, and // chain() doesn't work if the task chained against is in the middle of the series... task('dev', series('clean', 'copy', 'copy-types', 'sass', 'webpack-dev-server')); -task('build', series('clean', 'copy', 'copy-types', 'ts')).cached!(); +task('build', series('clean', 'copy', 'copy-types', 'ts', 'lint-imports:all')).cached!(); diff --git a/scripts/monorepo/src/index.d.ts b/scripts/monorepo/src/index.d.ts index b87ceae56b7da..2a4c56adac346 100644 --- a/scripts/monorepo/src/index.d.ts +++ b/scripts/monorepo/src/index.d.ts @@ -3,7 +3,7 @@ export { default as getDependencies } from './getDependencies'; export { default as findGitRoot } from './findGitRoot'; export { default as findRepoDeps } from './findRepoDeps'; export { default as getAllPackageInfo } from './getAllPackageInfo'; -export { default as isConvergedPackage } from './isConvergedPackage'; +export { isConvergedPackage, shipsAMD } from './isConvergedPackage'; export { getAffectedPackages } from './getAffectedPackages'; export { getLernaAliases } from './get-lerna-aliases'; export { getDefaultEnvironmentVars } from './getDefaultEnvironmentVars'; diff --git a/scripts/monorepo/src/index.js b/scripts/monorepo/src/index.js index 43387536b4e3e..f4721822fbbda 100644 --- a/scripts/monorepo/src/index.js +++ b/scripts/monorepo/src/index.js @@ -3,8 +3,8 @@ module.exports = { findGitRoot: require('./findGitRoot'), findRepoDeps: require('./findRepoDeps'), getAllPackageInfo: require('./getAllPackageInfo'), - isConvergedPackage: require('./isConvergedPackage'), eslintConstants: require('./eslint-constants'), + ...require('./isConvergedPackage'), ...require('./getAffectedPackages'), ...require('./getNthCommit'), ...require('./getDefaultEnvironmentVars'), diff --git a/scripts/monorepo/src/isConvergedPackage.js b/scripts/monorepo/src/isConvergedPackage.js index d50115ed1fa57..34c345ee4071d 100644 --- a/scripts/monorepo/src/isConvergedPackage.js +++ b/scripts/monorepo/src/isConvergedPackage.js @@ -1,5 +1,6 @@ -const semver = require('semver'); const { readConfig } = require('@fluentui/scripts-utils'); +const semver = require('semver'); + const { getProjectMetadata } = require('./utils'); /** @@ -38,6 +39,47 @@ function isConvergedPackage(options = {}) { return semver.major(packageJson.version) >= 9 || isNightlyVersion(packageJson.version) || hasVNextTag; } +/** + * @param {Object} [options] + * @param {PathOrPackageJson} [options.packagePathOrJson] - optional different package path to run in OR previously-read package.json + * (defaults to reading package.json from `process.cwd()`) + * @returns + */ +function shipsAMD(options = {}) { + const { packagePathOrJson } = options; + const packageJson = + !packagePathOrJson || typeof packagePathOrJson === 'string' + ? readConfig('package.json', /** @type {string|undefined} */ (packagePathOrJson)) + : packagePathOrJson; + + if (!packageJson) { + throw new Error(`package.json doesn't exist`); + } + + const metadata = getProjectMetadata({ name: packageJson.name }); + + if (metadata.projectType !== 'library') { + return false; + } + + const tags = new Set(metadata.tags ?? []); + const isV8 = tags.has('v8'); + const isV9 = tags.has('vNext'); + const needsAMD = tags.has('ships-amd'); + const isMixedProject = isV9 && isV8; + + if (needsAMD) { + return true; + } + if (isMixedProject) { + return true; + } + if (isV9) { + return false; + } + return true; +} + /** * Determines if a version is the 0.0.0 nightly version used by converged packages * @param {string} version @@ -46,4 +88,5 @@ function isNightlyVersion(version) { return semver.major(version) === 0 && semver.minor(version) === 0 && semver.patch(version) === 0; } -module.exports = isConvergedPackage; +exports.isConvergedPackage = isConvergedPackage; +exports.shipsAMD = shipsAMD; diff --git a/scripts/tasks/src/lint-imports.ts b/scripts/tasks/src/lint-imports.ts index c97521dba7389..a454e975cc895 100644 --- a/scripts/tasks/src/lint-imports.ts +++ b/scripts/tasks/src/lint-imports.ts @@ -6,32 +6,91 @@ import { readConfig } from '@fluentui/scripts-utils'; import chalk from 'chalk'; import * as glob from 'glob'; +function processArgs() { + const argv = process.argv.slice(2); + return { + /** + * This will throw errors only if amd import violations are present + */ + checkAmd: argv.includes('--check-amd'), + }; +} + interface ImportErrorGroup { count: number; matches: { [filePath: string]: { importPath: string; alternative?: string }[] }; } interface ImportErrors { - pathAbsolute: ImportErrorGroup; + /** + * AMD = checkAmd + * This checks is only "helpful" when import is from a folder without specifying explicitly `index` + * + * @example + * `from './folder'` - invalid (this resolves to 'index' only within NodeJS resolution. ESM spec nor AMD does not support loading folders - TODO: migrate this to eslint rule and enable everywhere + * `from './folder/index'` - valid + */ pathNotFile: ImportErrorGroup; + pathAbsolute: ImportErrorGroup; + /** + * Examples related + */ pathRelative: ImportErrorGroup; + /** + * Examples related + */ pathDeep: ImportErrorGroup; + /** + * Examples related + */ pathReExported: ImportErrorGroup; + /** + * Examples related + */ importStar: ImportErrorGroup; + /** + * Examples related + */ exportMulti: ImportErrorGroup; + /** + * Examples related + */ exportDefault: ImportErrorGroup; } -export function lintImports() { +export function lintImportTaskAll() { + return lintImports(); +} +export function lintImportTaskAmdOnly() { + return lintImports({ checkAmd: true }); +} + +function lintImports( + options: { + /** + * This will throw errors only if amd import violations are present + */ + checkAmd?: boolean; + } = {}, +) { + const { checkAmd } = options; + const gitRoot = findGitRoot(); const sourcePath = path.join(process.cwd(), 'src'); const cwdNodeModulesPath = path.join(process.cwd(), 'node_modules'); const nodeModulesPath = path.join(gitRoot, 'node_modules'); if (!fs.existsSync(sourcePath)) { + console.log('no /src directory found. exiting...'); return; } + if (checkAmd) { + console.log( + 'checkAmd enabled: validating if import path(s) reference physical files. violations can break AMD imports.', + ); + } + const allowedDeepImports = [ // This is a temporary measure until we figure out what root file these should be exported from. // TODO: Ideally these would eventually be removed. @@ -61,6 +120,10 @@ export function lintImports() { const currentPackageJson = readConfig('package.json'); const currentMonorepoPackage = currentPackageJson.name; + // !! be careful !! changing the regex can affect matched parts below. + const importStatementRegex = /^(import|export) [^'"]*(?:from )?['"]([^'"]+)['"];.*$/; + const importStatementRegexGlobalMultiline = new RegExp(importStatementRegex, 'gm'); + return lintSource().catch(err => { console.error(err); process.exit(1); @@ -96,12 +159,9 @@ export function lintImports() { } function _evaluateFile(filePath: string, importErrors: ImportErrors, isExample: boolean) { - // !! be careful !! changing the regex can affect matched parts below. - const importStatementRegex = /^(import|export) [^'"]*(?:from )?['"]([^'"]+)['"];.*$/; - const fileContent = fs.readFileSync(filePath, 'utf8'); - const importStatements = fileContent.match(new RegExp(importStatementRegex, 'gm')); + const importStatements = fileContent.match(importStatementRegexGlobalMultiline); if (importStatements) { importStatements.forEach(statement => { @@ -113,6 +173,10 @@ export function lintImports() { }); } + if (checkAmd) { + return; + } + if (isExample) { // borrowing this script to also check for some problematic export patterns in examples const relativePath = path.relative(sourcePath, filePath); @@ -205,6 +269,10 @@ export function lintImports() { _addError(importErrors.pathNotFile, relativePath, importPath); } + if (checkAmd) { + return; + } + if (isExample) { const isScss = importPath.endsWith('.scss'); @@ -256,12 +324,14 @@ export function lintImports() { } function reportFilePathErrors(importErrors: ImportErrors) { + let hasError = false; + const errorMessages: { [k in keyof ImportErrors]: string } = { - pathAbsolute: - 'files are using absolute imports. Please update the following imports to use relative paths instead:', pathNotFile: 'import path(s) do not reference physical files. This can break AMD imports. ' + 'Please ensure the following imports reference physical files:', + pathAbsolute: + 'files are using absolute imports. Please update the following imports to use relative paths instead:', pathRelative: 'example files are using relative imports. For example portability, please ensure that the following imports are absolute:', pathDeep: @@ -277,29 +347,40 @@ export function lintImports() { exportDefault: 'example files are using a default export. Please use only named exports.', }; - let hasError = false; - for (const groupName of Object.keys(importErrors) as Array) { + const groupNames: Array = checkAmd + ? ['pathNotFile'] + : (Object.keys(importErrors) as Array); + + for (const groupName of groupNames) { + reportViolations(groupName); + } + + function reportViolations(groupName: keyof ImportErrors) { const errorGroup: ImportErrorGroup = importErrors[groupName]; - if (errorGroup.count) { - hasError = true; - console.error(`${chalk.red('ERROR')}: ${errorGroup.count} ${errorMessages[groupName]}`); - console.error('-------------------------------------'); - // eslint-disable-next-line guard-for-in - for (const filePath in errorGroup.matches) { - console.error(` ${filePath}:`); - for (const { importPath, alternative } of errorGroup.matches[filePath]) { - console.error(` ${chalk.inverse(importPath)}`); - if (alternative) { - console.error(` (use instead: '${alternative}')`); - } + if (errorGroup.count === 0) { + return; + } + + hasError = true; + console.error(`${chalk.red('ERROR')}: ${errorGroup.count} ${errorMessages[groupName]}`); + console.error('-------------------------------------'); + // eslint-disable-next-line guard-for-in + for (const filePath in errorGroup.matches) { + console.error(` ${filePath}:`); + for (const { importPath, alternative } of errorGroup.matches[filePath]) { + console.error(` ${chalk.inverse(importPath)}`); + if (alternative) { + console.error(` (use instead: '${alternative}')`); } } } } + return hasError; } } if (require.main === module) { - lintImports(); + const args = processArgs(); + lintImports(args); } diff --git a/scripts/tasks/src/presets.ts b/scripts/tasks/src/presets.ts index 13b8b283007bd..18c51fccb85e9 100644 --- a/scripts/tasks/src/presets.ts +++ b/scripts/tasks/src/presets.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; -import { isConvergedPackage } from '@fluentui/scripts-monorepo'; +import { isConvergedPackage, shipsAMD } from '@fluentui/scripts-monorepo'; import { addResolvePath, condition, option, parallel, series, task } from 'just-scripts'; import { apiExtractor } from './api-extractor'; @@ -11,7 +11,7 @@ import { clean } from './clean'; import { copy, copyCompiled } from './copy'; import { eslint } from './eslint'; import { jest as jestTask, jestWatch } from './jest'; -import { lintImports } from './lint-imports'; +import { lintImportTaskAll, lintImportTaskAmdOnly } from './lint-imports'; import { postprocessTask } from './postprocess'; import { postprocessAmdTask } from './postprocess-amd'; import { prettier } from './prettier'; @@ -63,7 +63,8 @@ export function preset() { task('webpack', webpack); task('webpack-dev-server', webpackDevServer(args)); task('api-extractor', apiExtractor()); - task('lint-imports', lintImports); + task('lint-imports:all', lintImportTaskAll); + task('lint-imports:amd', lintImportTaskAmdOnly); task('prettier', prettier); task('storybook:start', startStorybookTask()); task('storybook:build', buildStorybookTask()); @@ -118,7 +119,8 @@ export function preset() { 'sass', 'ts', 'api-extractor', - condition('lint-imports', () => !isConvergedPackage()), + condition('lint-imports:all', () => !isConvergedPackage() && shipsAMD()), + condition('lint-imports:amd', () => isConvergedPackage() && shipsAMD()), ), ).cached!(); diff --git a/workspace.json b/workspace.json index d24024326a2c0..e76700ab5c642 100644 --- a/workspace.json +++ b/workspace.json @@ -579,14 +579,14 @@ "projectType": "library", "implicitDependencies": [], "sourceRoot": "packages/react-components/react-migration-v0-v9/src", - "tags": ["vNext", "platform:web"] + "tags": ["vNext", "react-northstar", "platform:web"] }, "@fluentui/react-migration-v8-v9": { "root": "packages/react-components/react-migration-v8-v9", "projectType": "library", "implicitDependencies": [], "sourceRoot": "packages/react-components/react-migration-v8-v9/src", - "tags": ["vNext", "platform:web"] + "tags": ["vNext", "v8", "platform:web"] }, "@fluentui/react-monaco-editor": { "root": "packages/react-monaco-editor", @@ -656,14 +656,14 @@ "projectType": "library", "implicitDependencies": [], "sourceRoot": "packages/react-components/react-portal-compat/src", - "tags": ["vNext", "platform:web"] + "tags": ["vNext", "ships-amd", "platform:web"] }, "@fluentui/react-portal-compat-context": { "root": "packages/react-components/react-portal-compat-context", "projectType": "library", "implicitDependencies": [], "sourceRoot": "packages/react-components/react-portal-compat-context/src", - "tags": ["vNext", "platform:web"] + "tags": ["vNext", "ships-amd", "platform:web"] }, "@fluentui/react-positioning": { "root": "packages/react-components/react-positioning", From 78e382916b2ea7cb44ccb0d4dc0154dfc90173d6 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 16 Feb 2023 16:40:20 +0100 Subject: [PATCH 3/5] generate change files --- ...monaco-editor-3cc9c097-aa92-421f-a9b7-bfc355c1104f.json | 7 +++++++ ...monaco-editor-9287da0f-bb0a-458e-b0d0-5800450447e6.json | 7 +++++++ ...ompat-context-63109ecf-905f-4a46-9e10-34953ede7cfb.json | 7 +++++++ ...portal-compat-d7b8a2ab-27b5-4f62-9abb-bab99b74e95b.json | 7 +++++++ 4 files changed, 28 insertions(+) create mode 100644 change/@fluentui-monaco-editor-3cc9c097-aa92-421f-a9b7-bfc355c1104f.json create mode 100644 change/@fluentui-react-monaco-editor-9287da0f-bb0a-458e-b0d0-5800450447e6.json create mode 100644 change/@fluentui-react-portal-compat-context-63109ecf-905f-4a46-9e10-34953ede7cfb.json create mode 100644 change/@fluentui-react-portal-compat-d7b8a2ab-27b5-4f62-9abb-bab99b74e95b.json diff --git a/change/@fluentui-monaco-editor-3cc9c097-aa92-421f-a9b7-bfc355c1104f.json b/change/@fluentui-monaco-editor-3cc9c097-aa92-421f-a9b7-bfc355c1104f.json new file mode 100644 index 0000000000000..e39191414e592 --- /dev/null +++ b/change/@fluentui-monaco-editor-3cc9c097-aa92-421f-a9b7-bfc355c1104f.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: re-enable AMD import checks for only mixed and v8 packages", + "packageName": "@fluentui/monaco-editor", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-monaco-editor-9287da0f-bb0a-458e-b0d0-5800450447e6.json b/change/@fluentui-react-monaco-editor-9287da0f-bb0a-458e-b0d0-5800450447e6.json new file mode 100644 index 0000000000000..9dc9ee76f0b29 --- /dev/null +++ b/change/@fluentui-react-monaco-editor-9287da0f-bb0a-458e-b0d0-5800450447e6.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: re-enable AMD import checks for only mixed and v8 packages", + "packageName": "@fluentui/react-monaco-editor", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-portal-compat-context-63109ecf-905f-4a46-9e10-34953ede7cfb.json b/change/@fluentui-react-portal-compat-context-63109ecf-905f-4a46-9e10-34953ede7cfb.json new file mode 100644 index 0000000000000..cff11794ea2dd --- /dev/null +++ b/change/@fluentui-react-portal-compat-context-63109ecf-905f-4a46-9e10-34953ede7cfb.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: re-enable AMD import checks for only mixed and v8 packages", + "packageName": "@fluentui/react-portal-compat-context", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-portal-compat-d7b8a2ab-27b5-4f62-9abb-bab99b74e95b.json b/change/@fluentui-react-portal-compat-d7b8a2ab-27b5-4f62-9abb-bab99b74e95b.json new file mode 100644 index 0000000000000..b5ed1f644e231 --- /dev/null +++ b/change/@fluentui-react-portal-compat-d7b8a2ab-27b5-4f62-9abb-bab99b74e95b.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: re-enable AMD import checks for only mixed and v8 packages", + "packageName": "@fluentui/react-portal-compat", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +} From a73b6224d4e0577409a2d159e6498bff12c77f68 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 17 Feb 2023 11:57:03 +0100 Subject: [PATCH 4/5] feat(scripts-tasks): unify monaco-editor task setup and reduce public api surface --- packages/monaco-editor/config/pre-copy.json | 5 ++ packages/monaco-editor/just.config.ts | 30 +------ scripts/tasks/src/index.ts | 93 +++++++++++++++++++-- scripts/tasks/src/postprocess.ts | 4 +- scripts/tasks/src/presets.ts | 2 +- 5 files changed, 100 insertions(+), 34 deletions(-) create mode 100644 packages/monaco-editor/config/pre-copy.json diff --git a/packages/monaco-editor/config/pre-copy.json b/packages/monaco-editor/config/pre-copy.json new file mode 100644 index 0000000000000..e3fb81b154d09 --- /dev/null +++ b/packages/monaco-editor/config/pre-copy.json @@ -0,0 +1,5 @@ +{ + "copyTo": { + "esm": ["monaco-editor/esm/"] + } +} diff --git a/packages/monaco-editor/just.config.ts b/packages/monaco-editor/just.config.ts index c45111615c5fe..ec4614eb7abec 100644 --- a/packages/monaco-editor/just.config.ts +++ b/packages/monaco-editor/just.config.ts @@ -1,38 +1,14 @@ -import { - basicPreset, - task, - series, - parallel, - copyInstructions, - copyInstructionsTask, - cleanTask, - ts, - postprocess, - eslint, -} from '@fluentui/scripts-tasks'; +import { preset, task, series, parallel, cleanTask, postprocessTask } from '@fluentui/scripts-tasks'; import * as path from 'path'; import { transformCssTask } from './tasks/transformCssTask'; -const monacoEditorPath = path.dirname(require.resolve('monaco-editor/package.json')); -const monacoSrcPath = path.join(monacoEditorPath, 'esm'); -const monacoDestPath = path.join(__dirname, 'esm'); - -basicPreset(); +preset(); task('clean', cleanTask({ paths: ['esm', 'lib', 'lib-commonjs'].map(p => path.join(process.cwd(), p)) })); -task( - 'copy', - copyInstructionsTask({ - copyInstructions: copyInstructions.copyFilesInDirectory(monacoSrcPath, monacoDestPath), - }), -); task('transform-css', transformCssTask); -task('ts:esm', ts.esm); -task('ts:commonjs', ts.commonjs); -task('ts:postprocess', postprocess.postprocessTask([...postprocess.defaultLibPaths, 'esm/**/*.d.ts'])); +task('ts:postprocess', postprocessTask([...postprocessTask.defaultLibPaths, 'esm/**/*.d.ts'])); task('ts', series(parallel('ts:esm', 'ts:commonjs'), 'ts:postprocess')); -task('eslint', eslint); task('build', series('clean', 'copy', 'transform-css', 'ts', 'lint-imports:all')).cached!(); diff --git a/scripts/tasks/src/index.ts b/scripts/tasks/src/index.ts index 9b7e8561d090c..a06699dde7e7d 100644 --- a/scripts/tasks/src/index.ts +++ b/scripts/tasks/src/index.ts @@ -1,6 +1,89 @@ -export * from 'just-scripts'; -export { preset, basicPreset } from './presets'; -export { ts } from './ts'; -export { eslint } from './eslint'; +export { + CopyConfig, + CopyInstruction, + Logger, + TsCheckerOptions, + TsLoaderOptions, + addResolvePath, + argv, + basicWebpackConfig, + basicWebpackServeConfig, + chain, + // eslint-disable-next-line deprecation/deprecation + cleanTask, + clearCache, + condition, + copyInstructions, + copyInstructionsTask, + // eslint-disable-next-line deprecation/deprecation + copyTask, + createStylesOverlay, + createTarTask, + defaultCleanPaths, + displayBailoutOverlay, + esbuildTask, + eslintTask, + extractTarTask, + fileOverlay, + fixApiFileNewlines, + htmlOverlay, + jestTask, + logger, + mark, + nodeExecTask, + option, + parallel, + prettierCheckTask, + prettierTask, + resetResolvePaths, + // eslint-disable-next-line deprecation/deprecation + resolve, + // eslint-disable-next-line deprecation/deprecation + resolveCwd, + // eslint-disable-next-line deprecation/deprecation + sassTask, + series, + spawn, + stylesOverlay, + task, + taskPresets, + tsOverlay, + tscTask, + tscWatchTask, + tslintTask, + undertaker, + watch, + webpackCliInitTask, + webpackCliTask, + webpackConfig, + webpackDevServerTask, + webpackMerge, + webpackOverlays, + webpackServeConfig, + webpackTask, +} from 'just-scripts'; +export type { + ApiExtractorOptions, + CleanTaskOptions, + CopyTaskOptions, + CreateOptions, + EntryHeader, + EsLintTaskOptions, + EsbuildBuildOptions, + EsbuildTransformOptions, + ExtractOptions, + JestTaskOptions, + NodeExecTaskOptions, + SassTaskOptions, + Task, + TaskContext, + TaskFunction, + TsLintTaskOptions, + TscTaskOptions, + WebpackCliTaskOptions, + WebpackDevServerTaskOptions, + WebpackTaskOptions, +} from 'just-scripts'; +export { preset } from './presets'; export { expandSourcePath } from './copy'; -export * as postprocess from './postprocess'; +export { postprocessTask } from './postprocess'; diff --git a/scripts/tasks/src/postprocess.ts b/scripts/tasks/src/postprocess.ts index 1bffa2458c5dd..b4ee568b9a63a 100644 --- a/scripts/tasks/src/postprocess.ts +++ b/scripts/tasks/src/postprocess.ts @@ -1,4 +1,4 @@ -export const defaultLibPaths = ['lib/**/*.d.ts', 'lib-commonjs/**/*.d.ts', 'lib-amd/**/*.d.ts']; +const defaultLibPaths = ['lib/**/*.d.ts', 'lib-commonjs/**/*.d.ts', 'lib-amd/**/*.d.ts']; /** * @param libPaths - Globs to .d.ts files which need postprocessing @@ -9,3 +9,5 @@ export function postprocessTask(libPaths: string[] = defaultLibPaths) { // but not for now, while our TS minbar and local version match. }; } + +postprocessTask.defaultLibPaths = defaultLibPaths; diff --git a/scripts/tasks/src/presets.ts b/scripts/tasks/src/presets.ts index 18c51fccb85e9..3afca6a11d9c3 100644 --- a/scripts/tasks/src/presets.ts +++ b/scripts/tasks/src/presets.ts @@ -21,7 +21,7 @@ import { ts } from './ts'; import { webpack, webpackDevServer } from './webpack'; /** Do only the bare minimum setup of options and resolve paths */ -export function basicPreset() { +function basicPreset() { // this adds a resolve path for the build tooling deps like TS from the scripts folder addResolvePath(__dirname); From 177dcdd3b138f5d4bece57d498b83700db209d78 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 24 Feb 2023 11:38:35 +0100 Subject: [PATCH 5/5] Update scripts/tasks/src/lint-imports.ts Co-authored-by: Makoto Morimoto --- scripts/tasks/src/lint-imports.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tasks/src/lint-imports.ts b/scripts/tasks/src/lint-imports.ts index a454e975cc895..d97a7651f9d44 100644 --- a/scripts/tasks/src/lint-imports.ts +++ b/scripts/tasks/src/lint-imports.ts @@ -24,7 +24,7 @@ interface ImportErrorGroup { interface ImportErrors { /** * AMD = checkAmd - * This checks is only "helpful" when import is from a folder without specifying explicitly `index` + * This check is only "helpful" when import is from a folder without specifying explicitly `index` * * @example * `from './folder'` - invalid (this resolves to 'index' only within NodeJS resolution. ESM spec nor AMD does not support loading folders - TODO: migrate this to eslint rule and enable everywhere