Skip to content

Commit

Permalink
refactor(ci): use nx workspace generator for tsconfib.base.all.json c…
Browse files Browse the repository at this point in the history
…heck
  • Loading branch information
Hotell committed Apr 18, 2023
1 parent 8213eb3 commit 3297686
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 93 deletions.
7 changes: 2 additions & 5 deletions 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 All @@ -41,10 +42,6 @@ jobs:
yarn tsc -p ./tsconfig.json
displayName: Type-check just.config.ts files
- script: |
yarn ts-node --swc scripts/generators/generate-ts-base-all-json.ts --verify
displayName: Check tsconfig.base.all.json integrity
- script: |
yarn check:installed-dependencies-versions
displayName: 'check packages: installed dependencies versions'
Expand Down
13 changes: 10 additions & 3 deletions scripts/generators/create-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import _ from 'lodash';
import { Actions } from 'node-plop';
import { AddManyActionConfig, NodePlopAPI } from 'plop';

import { main as generateTsBaseAllJson } from '../generate-ts-base-all-json';

const root = findGitRoot();

const v8ReferencePackages = {
Expand Down Expand Up @@ -162,8 +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.',
);
}

generateTsBaseAllJson();
return 'Successfully migrated package';
},
() => {
Expand Down
33 changes: 0 additions & 33 deletions scripts/generators/generate-ts-base-all-json.ts

This file was deleted.

1 change: 0 additions & 1 deletion scripts/generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
"dependencies": {
"@fluentui/scripts-monorepo": "*",
"@fluentui/scripts-storybook": "*",
"@fluentui/scripts-projects-test": "*"
}
}
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
51 changes: 1 addition & 50 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,58 +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}
*
* @param {{relativeFolderPathFromRoot?:string,writeFileToDisk?:boolean}} options
*/
function createPathAliasesConfig(options = {}) {
const { relativeFolderPathFromRoot = './dist', writeFileToDisk = true } = options;
const rootPath = workspaceRoot;
const mergedTsConfigRoot = path.join(rootPath, relativeFolderPathFromRoot);
const tsConfigAllFileName = 'tsconfig.base.all.json';
const tsConfigAllPath = path.join(mergedTsConfigRoot, tsConfigAllFileName);
const existingTsConfig = readJsonFile(tsConfigAllPath);

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 tsConfigBase = rootPath === mergedTsConfigRoot ? '.' : rootPath;
const mergedTsConfig = {
compilerOptions: {
moduleResolution: 'node',
forceConsistentCasingInFileNames: true,
skipLibCheck: true,
typeRoots: ['node_modules/@types', './typings'],
isolatedModules: true,
preserveConstEnums: true,
sourceMap: true,
pretty: true,
rootDir: tsConfigBase,
baseUrl: tsConfigBase,
paths: {
...baseConfigs.v0.compilerOptions.paths,
...baseConfigs.v8.compilerOptions.paths,
...baseConfigs.v9.compilerOptions.paths,
},
},
};

if (writeFileToDisk) {
writeJsonFile(tsConfigAllPath, mergedTsConfig);
}

return { tsConfigAllPath, tsConfigAllFileName, mergedTsConfig, existingTsConfig };
}

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

0 comments on commit 3297686

Please sign in to comment.