Skip to content

Commit

Permalink
Merge pull request #3860 from iclanton/rush-lib-dts-test-project
Browse files Browse the repository at this point in the history
[rush-lib] Add a test that ensures that all `lib/**/*.d.ts` files have valid imports.
  • Loading branch information
iclanton authored Dec 21, 2022
2 parents c4c9466 + f81c052 commit 576816f
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ These GitHub repositories provide supplementary resources for Rush Stack:
| [/build-tests/localization-plugin-test-02](./build-tests/localization-plugin-test-02/) | Building this project exercises @microsoft/localization-plugin. This tests that the loader works correctly with the exportAsDefault option unset. |
| [/build-tests/localization-plugin-test-03](./build-tests/localization-plugin-test-03/) | Building this project exercises @microsoft/localization-plugin. This tests that the plugin works correctly with the exportAsDefault option set to true. |
| [/build-tests/rush-amazon-s3-build-cache-plugin-integration-test](./build-tests/rush-amazon-s3-build-cache-plugin-integration-test/) | Tests connecting to an amazon S3 endpoint |
| [/build-tests/rush-lib-declaration-paths-test](./build-tests/rush-lib-declaration-paths-test/) | This project ensures all of the paths in rush-lib/lib/... have imports that resolve correctly. If this project builds, all `lib/**/*.d.ts` files in the `@microsoft/rush-lib` package are valid. |
| [/build-tests/rush-project-change-analyzer-test](./build-tests/rush-project-change-analyzer-test/) | This is an example project that uses rush-lib's ProjectChangeAnalyzer to |
| [/build-tests/set-webpack-public-path-plugin-webpack4-test](./build-tests/set-webpack-public-path-plugin-webpack4-test/) | Building this project tests the set-webpack-public-path-plugin using Webpack 4 |
| [/build-tests/ts-command-line-test](./build-tests/ts-command-line-test/) | Building this project is a regression test for ts-command-line |
Expand Down
10 changes: 10 additions & 0 deletions build-tests/rush-lib-declaration-paths-test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution');

module.exports = {
extends: [
'@rushstack/eslint-config/profile/node-trusted-tool',
'@rushstack/eslint-config/mixins/friendly-locals'
],
parserOptions: { tsconfigRootDir: __dirname }
};
2 changes: 2 additions & 0 deletions build-tests/rush-lib-declaration-paths-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is generated by the build
src/
32 changes: 32 additions & 0 deletions build-tests/rush-lib-declaration-paths-test/config/heft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json",

"extends": "@rushstack/heft-node-rig/profiles/default/config/heft.json",

"eventActions": [
{
"actionKind": "deleteGlobs",
"actionId": "deleteSrc",
"heftEvent": "clean",
"globsToDelete": ["src/**/*"]
},
{
"actionKind": "copyFiles",
"heftEvent": "pre-compile",
"actionId": "createSrc",
"copyOperations": [
{
"sourceFolder": "node_modules/@microsoft/rush-lib/src",
"destinationFolders": ["src"],
"includeGlobs": ["npm-check-typings.d.ts"]
}
]
},
{
"actionKind": "runScript",
"heftEvent": "pre-compile",
"actionId": "createSrc",
"scriptPath": "./scripts/createSrc.js"
}
]
}
7 changes: 7 additions & 0 deletions build-tests/rush-lib-declaration-paths-test/config/rig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// The "rig.json" file directs tools to look for their config files in an external package.
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",

"rigPackageName": "@rushstack/heft-node-rig"
}
20 changes: 20 additions & 0 deletions build-tests/rush-lib-declaration-paths-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "rush-lib-declaration-paths-test",
"description": "This project ensures all of the paths in rush-lib/lib/... have imports that resolve correctly. If this project builds, all `lib/**/*.d.ts` files in the `@microsoft/rush-lib` package are valid.",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "heft build --clean",
"_phase:build": "heft build --clean"
},
"dependencies": {
"@microsoft/rush-lib": "workspace:*"
},
"devDependencies": {
"@rushstack/eslint-config": "workspace:*",
"@rushstack/heft-node-rig": "workspace:*",
"@rushstack/heft": "workspace:*",
"@rushstack/node-core-library": "workspace:*",
"@types/node": "12.20.24"
}
}
39 changes: 39 additions & 0 deletions build-tests/rush-lib-declaration-paths-test/scripts/createSrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'ues strict';

const { FileSystem, Import } = require('@rushstack/node-core-library');

const DTS_EXTENSION = '.d.ts';

module.exports = {
runAsync: async ({ heftConfiguration: { buildFolder } }) => {
const rushLibPath = Import.resolvePackage({
packageName: '@microsoft/rush-lib',
baseFolderPath: __dirname
});

async function* collectDtsPaths(absoluteFolderPath, relativeFolderPath) {
const folderItems = FileSystem.readFolderItems(absoluteFolderPath);
for (const folderItem of folderItems) {
const folderItemName = folderItem.name;
if (folderItem.isDirectory()) {
yield* collectDtsPaths(
`${absoluteFolderPath}/${folderItemName}`,
`${relativeFolderPath}/${folderItemName}`
);
} else if (folderItemName.endsWith(DTS_EXTENSION)) {
yield `${relativeFolderPath}/${folderItemName.slice(0, -DTS_EXTENSION.length)}`;
}
}
}

const indexFileLines = ['/// <reference path="./npm-check-typings.d.ts" />', ''];
for await (const dtsPath of collectDtsPaths(`${rushLibPath}/lib`, '@microsoft/rush-lib/lib')) {
indexFileLines.push(`import '${dtsPath}';`);
}

const srcFolderPath = `${buildFolder}/src`;
await FileSystem.writeFileAsync(`${srcFolderPath}/index.ts`, indexFileLines.join('\n'), {
ensureFolderExists: true
});
}
};
6 changes: 6 additions & 0 deletions build-tests/rush-lib-declaration-paths-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json",
"compilerOptions": {
"types": ["node"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "",
"type": "none",
"packageName": "@microsoft/rush"
}
],
"packageName": "@microsoft/rush",
"email": "[email protected]"
}
17 changes: 17 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions libraries/rush-lib/config/heft.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
"hardlink": true
}
]
},
{
"actionKind": "deleteGlobs",
"heftEvent": "bundle",
"actionId": "deleteBadTypings",
"globsToDelete": [
"lib/utilities/prompts/SearchListPrompt.d.ts" // This module has an import with typings issues
]
}
],

Expand Down
1 change: 1 addition & 0 deletions libraries/rush-lib/src/logic/InteractiveUpgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE in the project root for license information.

import npmCheck from 'npm-check';
import type * as NpmCheck from 'npm-check';
import colors from 'colors/safe';

import { RushConfiguration } from '../api/RushConfiguration';
Expand Down
1 change: 1 addition & 0 deletions libraries/rush-lib/src/logic/PackageJsonUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import colors from 'colors/safe';
import * as semver from 'semver';
import type * as NpmCheck from 'npm-check';
import { ConsoleTerminalProvider, Terminal, ITerminalProvider, Colors } from '@rushstack/node-core-library';

import { RushConfiguration } from '../api/RushConfiguration';
Expand Down
6 changes: 1 addition & 5 deletions libraries/rush-lib/src/npm-check-typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare namespace NpmCheck {
declare module 'npm-check' {
interface INpmCheckOptions {
global?: boolean;
update?: boolean;
Expand Down Expand Up @@ -44,7 +44,3 @@ declare namespace NpmCheck {
then(stateFn: (state: INpmCheckCurrentState) => void): void;
};
}

declare module 'npm-check' {
export = NpmCheck.default;
}
1 change: 1 addition & 0 deletions libraries/rush-lib/src/utilities/InteractiveUpgradeUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import colors from 'colors/safe';
import CliTable from 'cli-table';
import Separator from 'inquirer/lib/objects/separator';
import { Import } from '@rushstack/node-core-library';
import type * as NpmCheck from 'npm-check';

const _: typeof import('lodash') = Import.lazy('lodash', require);

Expand Down
6 changes: 6 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,12 @@
"reviewCategory": "tests",
"shouldPublish": false
},
{
"packageName": "rush-lib-declaration-paths-test",
"projectFolder": "build-tests/rush-lib-declaration-paths-test",
"reviewCategory": "tests",
"shouldPublish": false
},
{
"packageName": "rush-project-change-analyzer-test",
"projectFolder": "build-tests/rush-project-change-analyzer-test",
Expand Down

0 comments on commit 576816f

Please sign in to comment.