Skip to content
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

chore: enable TS intellisense in cross library projects for better/consistent DX #26605

Merged
merged 19 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8e3fd0f
generate change files
Hotell Feb 1, 2023
6d0df39
chore(public-docsite-v9): enable whole monorepo TS path aliases for i…
Hotell Feb 2, 2023
3acdb80
chore(public-docsite-v9): migrate to solution config and type-check .…
Hotell Feb 7, 2023
0b59fcf
chore(react-migration-v8-v9): enable cross project TS path aliases f…
Hotell Feb 7, 2023
c27facc
chore(react-migration-v0-v9): enable cross project TS path aliases f…
Hotell Feb 7, 2023
9bd7a30
feat(scripts-tasks): enable ts processing on projects with path alias…
Hotell Feb 7, 2023
48e8bb7
fix(typings): make transformSource optional in sb addons type extensions
Hotell Feb 7, 2023
142453b
chore: use tsconfig.base.all.json directly for TS path webpack plugin…
Hotell Apr 5, 2023
0cfba4d
feat(scripts-storybook): make createPathAliasesConfigconfigurable and…
Hotell Apr 5, 2023
900317a
feat(scripts-generators): update tsconfig.base.all.json after creatin…
Hotell Apr 5, 2023
d2f259f
feat(scripts-generators): incorporate base all generation to create-p…
Hotell Apr 6, 2023
10edcea
chore: update tsconfig.base.all after rebase
Hotell Apr 11, 2023
6c773b8
feat(scripts-tasks): implement type-check alias, update generate-api,…
Hotell Apr 11, 2023
136a5e7
chore: use new type-check task for cross project TS path aliases + en…
Hotell Apr 11, 2023
1674faa
fix(scripts-tasks): dont invoke api-extractor logic on every just-scr…
Hotell Apr 18, 2023
5b843e2
scaffold tsconfig-base-all generator
Hotell Apr 18, 2023
cae14c6
feat(tools): implement tsconfig-base-all generator
Hotell Apr 18, 2023
5735d61
refactor(ci): use nx workspace generator for tsconfib.base.all.json c…
Hotell Apr 18, 2023
272bb18
fixup! chore: update tsconfig.base.all after rebase
Hotell Apr 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/public-docsite-v9/.storybook/fix-title.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const fs = require('fs');
const path = require('path');

/**
*
* @param {string} filePath
* @param {string} title
*/
function fixTitle(filePath, title) {
const htmlDocumentPath = path.resolve(__dirname, filePath);
const htmlDocument = fs.readFileSync(htmlDocumentPath, 'utf-8');
Expand Down
13 changes: 3 additions & 10 deletions apps/public-docsite-v9/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
// @ts-check

const {
getPackageStoriesGlob,
createPathAliasesConfig,
registerTsPaths,
rules,
registerRules,
} = require('@fluentui/scripts-storybook');
const path = require('path');
const { getPackageStoriesGlob, registerTsPaths, rules, registerRules } = require('@fluentui/scripts-storybook');

const rootMain = require('../../../.storybook/main');

const { tsConfigAllPath } = createPathAliasesConfig();
const tsConfigAllPath = path.join(__dirname, '../../../tsconfig.base.all.json');

module.exports = /** @type {Omit<import('../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
Expand Down
4 changes: 3 additions & 1 deletion apps/public-docsite-v9/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as rootPreview from '../../../.storybook/preview';

import { FluentDocsContainer } from '../src/DocsComponents/FluentDocsContainer.stories';
import { FluentDocsPage } from '../src/DocsComponents/FluentDocsPage.stories';
import * as rootPreview from '../../../.storybook/preview';

import './docs-root-v9.css';

/** @type {NonNullable<import('@storybook/react').Story['decorators']>} */
Expand Down
1 change: 1 addition & 0 deletions apps/public-docsite-v9/.storybook/theme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { create } from '@storybook/theming';

import logo from '../public/fluentui-logo.svg';

/**
Expand Down
9 changes: 9 additions & 0 deletions apps/public-docsite-v9/.storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"types": ["node", "static-assets", "storybook__addons"]
},
"include": ["*.js"]
}
1 change: 1 addition & 0 deletions apps/public-docsite-v9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"code-style": "just-scripts code-style",
"just": "just-scripts",
"lint": "just-scripts lint",
"type-check": "just-scripts type-check",
"start": "yarn storybook:docs",
"storybook": "start-storybook --port 3000 --no-manager-cache",
"storybook:docs": "yarn storybook --docs"
Expand Down
13 changes: 13 additions & 0 deletions apps/public-docsite-v9/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"target": "ES2019",
"noEmit": false,
"outDir": "lib",
"jsx": "react",
"sourceMap": true,
"types": ["webpack-env"]
},
"include": ["src"]
}
26 changes: 14 additions & 12 deletions apps/public-docsite-v9/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"extends": "../../tsconfig.base.all.json",
"compilerOptions": {
"target": "es5",
"outDir": "lib",
"module": "commonjs",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"module": "ESNext",
"target": "ES2019",
"noEmit": true,
"experimentalDecorators": true,
"noUnusedLocals": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"noImplicitAny": true,
"moduleResolution": "node",
"preserveConstEnums": true,
"skipLibCheck": true,
"types": ["webpack-env", "@storybook/react"]
"types": ["webpack-env"]
},
"include": ["src"]
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./.storybook/tsconfig.json"
}
]
}
4 changes: 2 additions & 2 deletions apps/stress-test/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path';
import { fileURLToPath } from 'url';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
// eslint-disable-next-line import/no-extraneous-dependencies
import { registerTsPaths, createPathAliasesConfig, rules } from '@fluentui/scripts-storybook';
import { registerTsPaths, rules } from '@fluentui/scripts-storybook';
import { configurePages } from './pageConfig.js';
import { configureGriffel } from './griffelConfig.js';
import * as WebpackDevServer from 'webpack-dev-server';
Expand All @@ -12,7 +12,7 @@ const enabledReactProfiling = true;

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const { tsConfigAllPath } = createPathAliasesConfig();
const tsConfigAllPath = path.join(__dirname, '../../../tsconfig.base.all.json');

type WebpackArgs = {
mode: 'production' | 'development' | 'none';
Expand Down
3 changes: 2 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
- script: |
yarn nx workspace-lint
yarn nx run @fluentui/nx-workspace-tools:check-graph
displayName: NX workspace lint
yarn nx workspace-generator tsconfig-base-all --verify
displayName: Workspace lint
- script: |
# @fluentui/api-docs is used within apps/public-docsite-resources/just.config.ts, thus it needs to be build in advance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: enable build-less DX for storybook",
"packageName": "@fluentui/react-migration-v8-v9",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { registerTsPaths, createPathAliasesConfig } = require('@fluentui/scripts-storybook');
const path = require('path');
const { registerTsPaths } = require('@fluentui/scripts-storybook');

const rootMain = require('../../../../.storybook/main');

const { tsConfigAllPath } = createPathAliasesConfig();
const tsConfigAllPath = path.join(__dirname, '../../../../tsconfig.base.all.json');

module.exports = /** @type {Omit<import('../../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import { ComponentProps } from '@fluentui/react-components';
import { GriffelStyle } from '@fluentui/react-components';
import { ObjectOf } from '@fluentui/react-northstar';
import { ObjectShorthandValue } from '@fluentui/react-northstar';
import type { ObjectShorthandValue } from '@fluentui/react-northstar';
import * as React_2 from 'react';
import { Slot } from '@fluentui/react-components';
import { Slot as Slot_2 } from '@fluentui/react-utilities';
import { SlotRenderFunction } from '@fluentui/react-components';
import { SlotRenderFunction } from '@fluentui/react-utilities';

// @public (undocumented)
export const Flex: React_2.ForwardRefExoticComponent<React_2.HTMLAttributes<HTMLElement> & FlexProps & React_2.RefAttributes<HTMLDivElement>>;
Expand Down Expand Up @@ -133,7 +133,7 @@ export type StyledTextSlots = {
};

// @public (undocumented)
export const useFlexStyles: () => Record<"fill" | "wrap" | "inline" | "flex" | "column" | "alignItemsFlexStart" | "alignItemsCenter" | "alignItemsFlexEnd" | "alignItemsStretch" | "justifyContentFlexStart" | "justifyContentCenter" | "justifyContentFlexEnd" | "justifyContentStretch" | "justifyContentSpaceAround" | "justifyContentSpaceBetween" | "justifyContentSpaceEvenly" | "gapForColumnFlexSmall" | "gapForColumnFlexSmaller" | "gapForColumnFlexMedium" | "gapForColumnFlexLarge" | "gapForRowFlexSmall" | "gapForRowFlexSmaller" | "gapForRowFlexMedium" | "gapForRowFlexLarge" | "paddingMedium", string>;
export const useFlexStyles: () => Record<"flex" | "fill" | "column" | "wrap" | "inline" | "alignItemsFlexStart" | "alignItemsCenter" | "alignItemsFlexEnd" | "alignItemsStretch" | "justifyContentFlexStart" | "justifyContentCenter" | "justifyContentFlexEnd" | "justifyContentStretch" | "justifyContentSpaceAround" | "justifyContentSpaceBetween" | "justifyContentSpaceEvenly" | "gapForColumnFlexSmall" | "gapForColumnFlexSmaller" | "gapForColumnFlexMedium" | "gapForColumnFlexLarge" | "gapForRowFlexSmall" | "gapForRowFlexSmaller" | "gapForRowFlexMedium" | "gapForRowFlexLarge" | "paddingMedium", string>;

// @public (undocumented)
export const useGridStyles: () => Record<"grid" | "onlyRows" | "rows1" | "rows2" | "rows3" | "columns1" | "columns2" | "columns3" | "columnsDefault", string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"just": "just-scripts",
"lint": "just-scripts lint",
"test": "jest --passWithNoTests",
"type-check": "tsc -b tsconfig.json",
"type-check": "just-scripts type-check",
"generate-api": "just-scripts generate-api",
"storybook": "start-storybook",
"start": "yarn storybook"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
useFieldStyles_unstable,
useField_unstable,
} from '@fluentui/react-components';
import { ObjectShorthandValue } from '@fluentui/react-northstar';
import type { ObjectShorthandValue } from '@fluentui/react-northstar';

import * as React from 'react';

type WithContent = ObjectShorthandValue<React.HTMLAttributes<HTMLDivElement>> | string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.base.all.json",
"compilerOptions": {
"strict": true,
"target": "ES2019",
"noEmit": true,
"isolatedModules": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { registerTsPaths, createPathAliasesConfig, registerRules, rules } = require('@fluentui/scripts-storybook');
const path = require('path');
const { registerTsPaths, registerRules, rules } = require('@fluentui/scripts-storybook');

const rootMain = require('../../../../.storybook/main');

const { tsConfigAllPath } = createPathAliasesConfig();
const tsConfigAllPath = path.join(__dirname, '../../../../tsconfig.base.all.json');

module.exports = /** @type {Omit<import('../../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"just": "just-scripts",
"lint": "just-scripts lint",
"test": "jest --passWithNoTests",
"type-check": "tsc -b tsconfig.json",
"type-check": "just-scripts type-check",
"generate-api": "just-scripts generate-api",
"storybook": "start-storybook",
"start": "yarn storybook"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"extends": "../../../tsconfig.base.json",
"extends": "../../../tsconfig.base.all.json",
"compilerOptions": {
"strict": true,
"target": "ES2019",
"noEmit": true,
"isolatedModules": true,
"importHelpers": true,
"jsx": "react",
"noUnusedLocals": true,
"preserveConstEnums": true
"preserveConstEnums": true,
"paths": {}
},
"include": [],
"files": [],
Expand Down
25 changes: 18 additions & 7 deletions scripts/generators/create-package/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { NodePlopAPI, AddManyActionConfig } from 'plop';
import { Actions } from 'node-plop';
import { spawnSync } from 'child_process';
import * as path from 'path';

import { PackageJson, findGitRoot } from '@fluentui/scripts-monorepo';
import { WorkspaceJsonConfiguration } from '@nrwl/devkit';
import chalk from 'chalk';
import * as fs from 'fs-extra';
import * as jju from 'jju';
import _ from 'lodash';
import chalk from 'chalk';
import { spawnSync } from 'child_process';
import { WorkspaceJsonConfiguration } from '@nrwl/devkit';

import { findGitRoot, PackageJson } from '@fluentui/scripts-monorepo';
import { Actions } from 'node-plop';
import { AddManyActionConfig, NodePlopAPI } from 'plop';

const root = findGitRoot();

Expand Down Expand Up @@ -160,6 +160,17 @@ module.exports = (plop: NodePlopAPI) => {
if (migrateResult.status !== 0) {
throw new Error('Something went wrong running the migration. Please check previous logs for details.');
}
const tsConfigAllUpdate = spawnSync('yarn', ['nx', 'workspace-generator', 'tsconfig-base-all'], {
cwd: root,
stdio: 'inherit',
shell: true,
});
if (tsConfigAllUpdate.status !== 0) {
throw new Error(
'Something went wrong while updating tsconfig.base.all.json. Please check previous logs for details.',
);
}

return 'Successfully migrated package';
},
() => {
Expand Down
1 change: 0 additions & 1 deletion scripts/storybook/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export {
loadWorkspaceAddon,
registerTsPaths,
registerRules,
createPathAliasesConfig,
overrideDefaultBabelLoader,
} from './utils';

Expand Down
9 changes: 1 addition & 8 deletions scripts/storybook/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
const rules = require('./rules');
const {
createPathAliasesConfig,
getPackageStoriesGlob,
loadWorkspaceAddon,
registerRules,
registerTsPaths,
} = require('./utils');
const { getPackageStoriesGlob, loadWorkspaceAddon, registerRules, registerTsPaths } = require('./utils');

module.exports = {
createPathAliasesConfig,
getPackageStoriesGlob,
loadWorkspaceAddon,
registerRules,
Expand Down
41 changes: 1 addition & 40 deletions scripts/storybook/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');

const { fullSourcePlugin: babelPlugin } = require('@fluentui/babel-preset-storybook-full-source');
const { isConvergedPackage, getAllPackageInfo, getProjectMetadata } = require('@fluentui/scripts-monorepo');
const { stripIndents, offsetFromRoot, workspaceRoot, readJsonFile, writeJsonFile } = require('@nrwl/devkit');
const { stripIndents, offsetFromRoot, workspaceRoot } = require('@nrwl/devkit');
const semver = require('semver');
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');

Expand Down Expand Up @@ -354,48 +354,9 @@ function overrideDefaultBabelLoader(options) {
}
}

/**
* Create tsconfig.json with merged "compilerOptions.paths" from v0,v8,v9 tsconfigs.
*
* Main purpose of this is to be used for build-less DX in webpack in tandem with {@link registerTsPaths}
* @returns
*/
function createPathAliasesConfig() {
const { tsConfigAllPath } = createMergedTsConfig();
return { tsConfigAllPath };
}

function createMergedTsConfig() {
const rootPath = workspaceRoot;
const tsConfigAllPath = path.join(rootPath, 'dist/tsconfig.base.all.json');
const baseConfigs = {
v0: readJsonFile(path.join(rootPath, 'tsconfig.base.v0.json')),
v8: readJsonFile(path.join(rootPath, 'tsconfig.base.v8.json')),
v9: readJsonFile(path.join(rootPath, 'tsconfig.base.json')),
};
const mergedTsConfig = {
compilerOptions: {
moduleResolution: 'node',
forceConsistentCasingInFileNames: true,
skipLibCheck: true,
baseUrl: workspaceRoot,
paths: {
...baseConfigs.v0.compilerOptions.paths,
...baseConfigs.v8.compilerOptions.paths,
...baseConfigs.v9.compilerOptions.paths,
},
},
};

writeJsonFile(tsConfigAllPath, mergedTsConfig);

return { tsConfigAllPath, mergedTsConfig };
}

exports.getPackageStoriesGlob = getPackageStoriesGlob;
exports.loadWorkspaceAddon = loadWorkspaceAddon;
exports.registerTsPaths = registerTsPaths;
exports.registerRules = registerRules;
exports.createPathAliasesConfig = createPathAliasesConfig;
exports.overrideDefaultBabelLoader = overrideDefaultBabelLoader;
exports._createCodesandboxRule = _createCodesandboxRule;
Loading