-
Notifications
You must be signed in to change notification settings - Fork 607
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
[api-extractor] Replace the old "tsdocFlavor" field with a dist/tsdoc-metadata.json output #960
Conversation
…iles belonging to the current project (which may not have been built yet)
apps/api-documenter/src/start.ts
Outdated
__dirname, '..', FileConstants.PackageJson) | ||
); | ||
const myPackageJson: { version: string } = require(myPackageJsonFilename); | ||
const myPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname, '..').version; |
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.
Do you actually need the ..
? #Resolved
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, package.json is above the src folder.
We could walk upwards to probe for package.json, but that's inefficient and error-prone for a scenario that is supposed to be basically hardcoded.
In reply to: 236574942 [](ancestors = 236574942)
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.
* The NPM package version for the currently executing instance of the "\@microsoft/api-extractor" library. | ||
*/ | ||
public static get version(): string { | ||
return PackageJsonLookup.loadOwnPackageJson(__dirname, '../..').version; |
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.
Same here. #ByDesign
} else { | ||
throw new Error(`The specified entry point does not appear to have an associated package.json file:\n` | ||
+ sourceFile.fileName); | ||
if (this._program.isSourceFileFromExternalLibrary(sourceFile)) { |
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.
Is this right, or is this condition backwards? #Resolved
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.
It's right. If the source file is NOT from an external library, then it's part of the project we're analyzing, which obviously supports API Extractor.
In reply to: 236575683 [](ancestors = 236575683)
* 2. The current project is not guaranteed to have a package.json file at all. For example, API Extractor can | ||
* be invoked on a bare .d.ts file. | ||
* | ||
* Use ts.program.isSourceFileFromExternalLibrary() to test source files before passing the to PackageMetadataManager. |
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.
What would the perf impact be if we tested for this in PackageMetadataManager
? #WontFix
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.
Generally if you're inside PackageMetadataManager
for a local file, it's already too late.
I could add an assertion here to catch that mistake however.
PackageMetadataManager
is a fairly half-baked file right now, though. I want to make tsdoc-metadata.json a feature of the TSDoc library, and then we'll redesign PackageMetadataManager
when we update it to use that.
In reply to: 236576224 [](ancestors = 236576224)
// This feature is still being standardized: https://github.com/Microsoft/tsdoc/issues/7 | ||
// In the future we will use the @microsoft/tsdoc library to read this file. | ||
const tsdocMetadataPath: string = path.join(packageJsonFolder, | ||
'dist', PackageMetadataManager.tsdocMetadataFilename); |
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.
dist
is an arbitrary assumption to make. This should probably be placed in the same directory as the rollup file. #Resolved
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.
The rollup file may not exist. But we could put it in the same directory as the default entry point for the NPM package.
In reply to: 236576554 [](ancestors = 236576554)
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.
apps/api-extractor/src/start.ts
Outdated
__dirname, '..', FileConstants.PackageJson) | ||
); | ||
const myPackageJson: { version: string } = require(myPackageJsonFilename); | ||
const myPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname, '..').version; |
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.
This should just use Extractor.version
#Resolved
apps/rush-lib/src/api/Rush.ts
Outdated
} | ||
|
||
return Rush._version; | ||
return PackageJsonLookup.loadOwnPackageJson(__dirname, '../..').version; |
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.
Same here with the ../..
#Resolved
apps/rush/src/start.ts
Outdated
@@ -51,7 +48,8 @@ import { MinimalRushConfiguration } from './MinimalRushConfiguration'; | |||
|
|||
// Load the configuration | |||
const configuration: MinimalRushConfiguration | undefined = MinimalRushConfiguration.loadFromDefaultLocation(); | |||
const currentPackageJson: IPackageJson = JsonFile.load(path.join(__dirname, '..', FileConstants.PackageJson)); | |||
|
|||
const currentPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname, '..').version; |
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.
And here #Resolved
* loading, an exception will be thrown instead. | ||
*/ | ||
public static loadOwnPackageJson(dirnameOfCaller: string, pathToPackageJsonFolder: string): IPackageJson { | ||
const packageJsonPath: string = path.join(dirnameOfCaller, pathToPackageJsonFolder, FileConstants.PackageJson); |
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.
Seems like this would be simpler if it just used the normal package discovery algorithm. We could include an optimization where we check if the specified path is under a cached path, but without a node_modules
folder between the provided path and the cached path. #Resolved
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.
This needs to be a static member. That means we assume the files we look at will never change on disk, and the cache can accumulate entries without bound. We need to be careful about what we store in this cache.
In reply to: 236578450 [](ancestors = 236578450)
.tryGetPackageJsonFilePathFor(sourceFile.fileName); | ||
|
||
if (packageJsonPath) { | ||
throw new Error(`Please add a field such as "tsdoc": { "tsdocFlavor": "AEDoc" } to this file:\n` |
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.
Didn't we say we wanted to just use the metadata file if we're generating a rollup? #Resolved
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.
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.
Fixes #959 |
This is based on the discussion in microsoft/tsdoc#7 .
Instead of the
tsdocFlavor
field in package.json:...we now recognize that an external package is TSDoc-compatible by looking for a file dist/tsdoc-metadata.json with contents like this:
This is a prototype until an official implementation is provided by the @microsoft/tsdoc library.