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
RHCLOUD-23014: Use API Extractor on distributable packages #184
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/coverage | ||
/docs/generated | ||
/screenshots | ||
**/node_modules | ||
**/dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
/coverage | ||
/docs/generated | ||
/screenshots | ||
**/node_modules | ||
**/dist | ||
|
||
# https://next.yarnpkg.com/getting-started/qa#which-files-should-be-gitignored | ||
.pnp.* | ||
.yarn/* | ||
|
@@ -6,9 +12,3 @@ | |
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
/coverage | ||
/screenshots | ||
**/node_modules | ||
**/dist | ||
**/.DS_Store | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vojtechszocs please add back There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel that OS specific files that aren't related to the project shouldn't have to be excluded in the first place, assuming that you configure the OS not to generate them within the repo. Having them OS generated and then git-ignored is not the best solution, in my opinion. After some quick research, it seems that Mac OS doesn't support per-directory That said, I'll add the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
// Matches the end_of_line setting in .editorconfig | ||
"newlineKind": "lf", | ||
|
||
"dtsRollup": { | ||
"enabled": true, | ||
"untrimmedFilePath": "<projectFolder>/dist/index.d.ts" | ||
}, | ||
|
||
"apiReport": { | ||
"enabled": true, | ||
"reportFolder": "reports", | ||
"reportTempFolder": "<projectFolder>/dist/api" | ||
}, | ||
|
||
"docModel": { | ||
"enabled": true | ||
}, | ||
|
||
// Avoid generating tsdoc-metadata.json | ||
// https://github.com/microsoft/rushstack/pull/1628#issuecomment-553665782 | ||
"tsdocMetadata": { | ||
"enabled": false | ||
}, | ||
|
||
"messages": { | ||
"extractorMessageReporting": { | ||
// Avoid having to explicitly mark every exported API member with @public tag | ||
"ae-missing-release-tag": { | ||
"logLevel": "none" | ||
}, | ||
// Avoid issues with TSDoc parser unable to process @link references | ||
"ae-unresolved-link": { | ||
"logLevel": "none" | ||
} | ||
}, | ||
|
||
"tsdocMessageReporting": { | ||
// https://github.com/Microsoft/tsdoc/issues/19 | ||
"tsdoc-param-tag-with-invalid-name": { | ||
"logLevel": "none" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
yarn install | ||
yarn build-libs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vojtechszocs if we are planning to run this in the pipeline, do we need to run the build? Or can we add docs generation to the end of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, this script is meant for manual execution. It's not called by scripts that get executed as part of the CI workflow ( The reason why we run
Generated API docs are currently git-ignored, with a planned follow-up RHCLOUD-23203 where we'd collect them (both hand-written ones as well as generated ones) and publish them somewhere. API doc generation, collection and publishing is closely related to publishing new version of lib package(s) to npmjs. For now, I'd suggest to keep this as a separate script, having the above follow-up in mind. |
||
|
||
mkdir -p docs/generated && rm -rf docs/generated/* | ||
|
||
shopt -s globstar | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vojtechszocs this command is not available on Mac OS :( Is there another option here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I'll look for an alternative. What we're basically doing here is copying matching files into a flat structure at the given directory. |
||
cp packages/lib-*/dist/api/lib-*.api.json docs/generated | ||
|
||
yarn api-documenter markdown -i docs/generated -o docs/generated/api |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,17 @@ | |
"test-e2e": "yarn workspace @monorepo/e2e-sample-app run test-e2e", | ||
"test-e2e-open": "yarn workspace @monorepo/e2e-sample-app run test-e2e-open", | ||
"test-e2e-ci": "start-server-and-test 'yarn run-samples' '9000|9001' 'yarn test-e2e'", | ||
"eslint": "eslint --max-warnings 0 --ext .js,.jsx,.ts,.tsx", | ||
"eslint-print-config": "eslint --print-config", | ||
"eslint": "eslint --max-warnings 0 --ext .js,.jsx,.ts,.tsx --rulesdir ./packages/eslint-plugin-internal/src/runtime-rules", | ||
"eslint-print-config": "yarn eslint --print-config", | ||
"jest": "TZ=UTC jest --passWithNoTests", | ||
"storybook": "start-storybook -p 6006", | ||
"build-storybook": "build-storybook" | ||
"api-extractor": "api-extractor run --typescript-compiler-folder ./node_modules/typescript/lib", | ||
"storybook": "start-storybook -p 6006" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.18.6", | ||
"@mdx-js/react": "^1.6.22", | ||
"@microsoft/api-documenter": "^7.19.24", | ||
"@microsoft/api-extractor": "^7.33.6", | ||
"@patternfly/react-core": "^4.202.16", | ||
"@patternfly/react-table": "^4.71.16", | ||
"@patternfly/react-virtualized-extension": "^4.53.2", | ||
|
@@ -60,7 +62,6 @@ | |
"@typescript-eslint/parser": "^5.3.1", | ||
"babel-loader": "^8.2.5", | ||
"cypress": "^9.7.0", | ||
"downlevel-dts": "^0.10.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for sanity/clarity - we will need to add this back in a later PR for the 4.13 OCP console dynamic plugins epic: https://issues.redhat.com/browse/CONSOLE-3304 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also @vojtechszocs we may want to consider splitting up unrelated changes in the future. It will reduce the diff (already very large) and make it faster for approval. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed and sorry, I have a bad habit of putting lots of changes together sometimes 🥲 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb": "^19.0.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
|
@@ -74,11 +75,13 @@ | |
"eslint-plugin-promise": "^5.1.1", | ||
"eslint-plugin-react": "^7.27.0", | ||
"eslint-plugin-react-hooks": "^4.3.0", | ||
"find-up": "^5.0.0", | ||
"identity-obj-proxy": "^3.0.0", | ||
"jest": "^27.5.1", | ||
"jest-axe": "^6.0.0", | ||
"lodash": "^4.17.21", | ||
"lodash-es": "^4.17.21", | ||
"minimatch": "^3.1.2", | ||
"prettier": "^2.4.1", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
|
@@ -91,7 +94,6 @@ | |
"redux-thunk": "^2.4.1", | ||
"rollup": "^2.61.1", | ||
"rollup-plugin-analyzer": "^4.0.0", | ||
"rollup-plugin-dts": "^4.0.1", | ||
"rollup-plugin-import-css": "^3.0.3", | ||
"start-server-and-test": "^1.14.0", | ||
"storybook-addon-react-router-v6": "^0.1.14", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,7 @@ import commonjs from '@rollup/plugin-commonjs'; | |
import nodeResolve from '@rollup/plugin-node-resolve'; | ||
import typescript from '@rollup/plugin-typescript'; | ||
import analyzer from 'rollup-plugin-analyzer'; | ||
import dts from 'rollup-plugin-dts'; | ||
import css from 'rollup-plugin-import-css'; | ||
import { replaceCode } from './rollup-plugins/replaceCode'; | ||
import { writeJSONFile } from './rollup-plugins/writeJSONFile'; | ||
|
||
// https://yarnpkg.com/advanced/lifecycle-scripts#environment-variables | ||
|
@@ -52,36 +50,8 @@ const getBanner = ({ repository }, buildMetadata) => { | |
/** | ||
* @param {import('type-fest').PackageJson} pkg | ||
*/ | ||
const getExternalModules = ({ dependencies, peerDependencies }) => { | ||
const modules = new Set([ | ||
...Object.keys(dependencies ?? {}), | ||
...Object.keys(peerDependencies ?? {}), | ||
]); | ||
|
||
modules.add('lodash-es'); | ||
modules.delete('lodash'); | ||
|
||
return Array.from(modules); | ||
}; | ||
|
||
/** | ||
* @param {import('type-fest').PackageJson} pkg | ||
*/ | ||
const getExternalModuleRegExps = (pkg) => { | ||
const externalModules = getExternalModules(pkg); | ||
return externalModules.map((module) => new RegExp(`^${module}(\\/.+)*$`)); | ||
}; | ||
|
||
/** | ||
* @param {string} fileName | ||
*/ | ||
const replaceLodashEsRequire = (fileName) => | ||
replaceCode({ | ||
fileName, | ||
replacements: { | ||
"require('lodash-es')": "require('lodash')", | ||
}, | ||
}); | ||
const getExternalModules = ({ dependencies, peerDependencies }) => | ||
Array.from(new Set([...Object.keys(dependencies ?? {}), ...Object.keys(peerDependencies ?? {})])); | ||
|
||
/** | ||
* Rollup configuration for generating the library `.js` bundle. | ||
|
@@ -93,6 +63,7 @@ const replaceLodashEsRequire = (fileName) => | |
*/ | ||
export const tsLibConfig = (pkg, inputFile, format = 'esm') => { | ||
const buildMetadata = getBuildMetadata(pkg); | ||
const externalModules = getExternalModules(pkg); | ||
|
||
return { | ||
input: inputFile, | ||
|
@@ -101,7 +72,7 @@ export const tsLibConfig = (pkg, inputFile, format = 'esm') => { | |
format, | ||
banner: getBanner(pkg, buildMetadata), | ||
}, | ||
external: getExternalModuleRegExps(pkg), | ||
external: externalModules.map((m) => new RegExp(`^${m}(\\/.+)*$`)), | ||
plugins: [ | ||
nodeResolve(), | ||
commonjs(), | ||
|
@@ -113,9 +84,8 @@ export const tsLibConfig = (pkg, inputFile, format = 'esm') => { | |
include: ['src/**/*', '../common/src/**/*'], | ||
noEmitOnError: true, | ||
}), | ||
...(format === 'cjs' ? [replaceLodashEsRequire('index.js')] : []), | ||
writeJSONFile({ | ||
fileName: 'build-meta.json', | ||
fileName: 'build-metadata.json', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vojtechszocs can we move the filename to the top of the file in a constant so it's easier to find and change in the future? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the string That said, I'll do the change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chatted with @florkbr and since we're not planning to change this string in future, we can keep it here. |
||
value: buildMetadata, | ||
}), | ||
analyzer({ | ||
|
@@ -125,27 +95,3 @@ export const tsLibConfig = (pkg, inputFile, format = 'esm') => { | |
], | ||
}; | ||
}; | ||
|
||
/** | ||
* Rollup configuration for generating the library `.d.ts` bundle. | ||
* | ||
* @param {import('type-fest').PackageJson} pkg | ||
* @param {string} inputFile | ||
* @returns {import('rollup').RollupOptions} | ||
*/ | ||
export const dtsLibConfig = (pkg, inputFile) => ({ | ||
input: inputFile, | ||
output: { | ||
file: 'dist/index.d.ts', | ||
}, | ||
external: [...getExternalModuleRegExps(pkg), /\.css$/], | ||
plugins: [ | ||
dts({ | ||
respectExternal: true, | ||
}), | ||
analyzer({ | ||
summaryOnly: true, | ||
root: rootDir, | ||
}), | ||
], | ||
}); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export * from './errors/CustomError'; | ||
export * from './errors/ErrorWithCause'; | ||
export * from './types/common'; | ||
export * from './types/fetch'; | ||
export * from './utils/logger'; | ||
export * from './utils/objects'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"module": "esnext", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"jsx": "react" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vojtechszocs I see we have
/reports
(checked in) and/docs/generated
(ignored). Just confirming that is the flow you expect?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is intended.
reports
directory contains API reports (one Markdown file per lib package) which list all APIs exposed by the given package. Whenever the API surface of some package changes, API extractor will detect the "what's currently generated vs. what's committed inreports
directory" discrepancy and force the change to be propagated toreports
directory, making it part of the code review.docs/generated
is meant to contain docs (including temporary artifacts such as JSON doc model files) that are generated from the project sources. Runninggenerate-api-docs.sh
script produces the following file structure:JSON files directly at
docs/generated
are JSON doc model files. From these files,docs/generated/api
content is generated via API Documenter tool.docs/generated/api/index.md
is the index page of generated API docs.See RHCLOUD-23203 which is a follow-up task related to the generated API docs.