Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/rushstack
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a91a919e7c03cc14d2e409f80d9afd17f6f6f5c3
Choose a base ref
...
head repository: microsoft/rushstack
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b878b90f1c2ebc057d474cd8f7cf7b25137ac0fa
Choose a head ref
  • 11 commits
  • 165 files changed
  • 2 contributors

Commits on May 25, 2024

  1. Update changelogs [skip ci]

    rushbot committed May 25, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    marsam Mario Rodas
    Copy the full SHA
    5283da3 View commit details
  2. Bump versions [skip ci]

    rushbot committed May 25, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    marsam Mario Rodas
    Copy the full SHA
    89c4b69 View commit details

Commits on May 26, 2024

  1. Include typings for the package.json 'exports' field support for reso…

    …lving the tsdoc-metadata.json field referenced by 'exports'.
    iclanton committed May 26, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    marsam Mario Rodas
    Copy the full SHA
    3a1d7ea View commit details
  2. Copy the full SHA
    7eba571 View commit details
  3. Update the algorithm that looks for 'tsdoc-metadata.json' to more cor…

    …rectly reflect the NodeJS resolution algorithm.
    iclanton committed May 26, 2024
    Copy the full SHA
    93bca77 View commit details
  4. Rush change.

    iclanton committed May 26, 2024
    Copy the full SHA
    d3a4a75 View commit details
  5. Copy the full SHA
    f50c3cc View commit details
  6. Add a test for tsdoc-metadata.json resolution order.

    iclanton committed May 26, 2024
    Copy the full SHA
    068ba0f View commit details

Commits on May 27, 2024

  1. Merge pull request #4730 from iclanton/add-support-for-exports-types

    [node-core-library] [api-extractor] Include typings for the package.json 'exports' and 'typesVersions' fields support for resolving the tsdoc-metadata.json field referenced by 'exports' and 'typesVersions'.
    iclanton authored May 27, 2024
    Copy the full SHA
    4123770 View commit details

Commits on May 28, 2024

  1. Update changelogs [skip ci]

    rushbot committed May 28, 2024
    Copy the full SHA
    b9448be View commit details
  2. Bump versions [skip ci]

    rushbot committed May 28, 2024
    Copy the full SHA
    b878b90 View commit details
Showing with 1,957 additions and 314 deletions.
  1. +24 −0 apps/api-documenter/CHANGELOG.json
  2. +6 −1 apps/api-documenter/CHANGELOG.md
  3. +1 −1 apps/api-documenter/package.json
  4. +26 −0 apps/api-extractor/CHANGELOG.json
  5. +8 −1 apps/api-extractor/CHANGELOG.md
  6. +1 −1 apps/api-extractor/package.json
  7. +152 −28 apps/api-extractor/src/analyzer/PackageMetadataManager.ts
  8. +398 −86 apps/api-extractor/src/analyzer/test/PackageMetadataManager.test.ts
  9. +0 −4 ...-extractor/src/analyzer/test/test-data/tsdoc-metadata-path-inference/package-default/package.json
  10. +0 −5 ...src/analyzer/test/test-data/tsdoc-metadata-path-inference/package-inferred-from-main/package.json
  11. +0 −7 ...er/test/test-data/tsdoc-metadata-path-inference/package-inferred-from-tsdoc-metadata/package.json
  12. +0 −6 .../analyzer/test/test-data/tsdoc-metadata-path-inference/package-inferred-from-typings/package.json
  13. +27 −0 apps/heft/CHANGELOG.json
  14. +6 −1 apps/heft/CHANGELOG.md
  15. +1 −1 apps/heft/package.json
  16. +18 −0 apps/lockfile-explorer/CHANGELOG.json
  17. +6 −1 apps/lockfile-explorer/CHANGELOG.md
  18. +1 −1 apps/lockfile-explorer/package.json
  19. +18 −0 apps/rundown/CHANGELOG.json
  20. +6 −1 apps/rundown/CHANGELOG.md
  21. +1 −1 apps/rundown/package.json
  22. +24 −0 apps/rush/CHANGELOG.json
  23. +12 −1 apps/rush/CHANGELOG.md
  24. +1 −1 apps/rush/package.json
  25. +21 −0 apps/trace-import/CHANGELOG.json
  26. +6 −1 apps/trace-import/CHANGELOG.md
  27. +1 −1 apps/trace-import/package.json
  28. +0 −10 common/changes/@microsoft/rush/fix-caching-behavior-undefined_2024-04-17-14-52.json
  29. +0 −10 common/changes/@microsoft/rush/jest-sharding_2024-04-26-17-58.json
  30. +0 −10 common/changes/@microsoft/rush/octogonz-upgrade-prettier_2024-05-23-17-38.json
  31. +0 −10 common/changes/@microsoft/rush/sennyeya-log-replays_2024-04-29-20-05.json
  32. +0 −10 common/changes/@microsoft/rush/will-subspace-patch-25_2024-05-14-21-13.json
  33. +0 −10 common/changes/@microsoft/rush/will-subspaces-patch-26_2024-05-20-22-22.json
  34. +1 −1 common/config/rush/version-policies.json
  35. +15 −0 common/reviews/api/node-core-library.api.md
  36. +12 −0 eslint/eslint-bulk/CHANGELOG.json
  37. +6 −1 eslint/eslint-bulk/CHANGELOG.md
  38. +1 −1 eslint/eslint-bulk/package.json
  39. +27 −0 heft-plugins/heft-api-extractor-plugin/CHANGELOG.json
  40. +6 −1 heft-plugins/heft-api-extractor-plugin/CHANGELOG.md
  41. +2 −2 heft-plugins/heft-api-extractor-plugin/package.json
  42. +21 −0 heft-plugins/heft-dev-cert-plugin/CHANGELOG.json
  43. +6 −1 heft-plugins/heft-dev-cert-plugin/CHANGELOG.md
  44. +2 −2 heft-plugins/heft-dev-cert-plugin/package.json
  45. +24 −0 heft-plugins/heft-jest-plugin/CHANGELOG.json
  46. +6 −1 heft-plugins/heft-jest-plugin/CHANGELOG.md
  47. +2 −2 heft-plugins/heft-jest-plugin/package.json
  48. +24 −0 heft-plugins/heft-lint-plugin/CHANGELOG.json
  49. +6 −1 heft-plugins/heft-lint-plugin/CHANGELOG.md
  50. +2 −2 heft-plugins/heft-lint-plugin/package.json
  51. +27 −0 heft-plugins/heft-sass-plugin/CHANGELOG.json
  52. +6 −1 heft-plugins/heft-sass-plugin/CHANGELOG.md
  53. +2 −2 heft-plugins/heft-sass-plugin/package.json
  54. +24 −0 heft-plugins/heft-serverless-stack-plugin/CHANGELOG.json
  55. +6 −1 heft-plugins/heft-serverless-stack-plugin/CHANGELOG.md
  56. +2 −2 heft-plugins/heft-serverless-stack-plugin/package.json
  57. +27 −0 heft-plugins/heft-storybook-plugin/CHANGELOG.json
  58. +6 −1 heft-plugins/heft-storybook-plugin/CHANGELOG.md
  59. +2 −2 heft-plugins/heft-storybook-plugin/package.json
  60. +24 −0 heft-plugins/heft-typescript-plugin/CHANGELOG.json
  61. +6 −1 heft-plugins/heft-typescript-plugin/CHANGELOG.md
  62. +2 −2 heft-plugins/heft-typescript-plugin/package.json
  63. +24 −0 heft-plugins/heft-webpack4-plugin/CHANGELOG.json
  64. +6 −1 heft-plugins/heft-webpack4-plugin/CHANGELOG.md
  65. +2 −2 heft-plugins/heft-webpack4-plugin/package.json
  66. +24 −0 heft-plugins/heft-webpack5-plugin/CHANGELOG.json
  67. +6 −1 heft-plugins/heft-webpack5-plugin/CHANGELOG.md
  68. +2 −2 heft-plugins/heft-webpack5-plugin/package.json
  69. +12 −0 libraries/api-extractor-model/CHANGELOG.json
  70. +6 −1 libraries/api-extractor-model/CHANGELOG.md
  71. +1 −1 libraries/api-extractor-model/package.json
  72. +18 −0 libraries/debug-certificate-manager/CHANGELOG.json
  73. +6 −1 libraries/debug-certificate-manager/CHANGELOG.md
  74. +1 −1 libraries/debug-certificate-manager/package.json
  75. +15 −0 libraries/heft-config-file/CHANGELOG.json
  76. +6 −1 libraries/heft-config-file/CHANGELOG.md
  77. +1 −1 libraries/heft-config-file/package.json
  78. +12 −0 libraries/load-themed-styles/CHANGELOG.json
  79. +6 −1 libraries/load-themed-styles/CHANGELOG.md
  80. +1 −1 libraries/load-themed-styles/package.json
  81. +21 −0 libraries/localization-utilities/CHANGELOG.json
  82. +6 −1 libraries/localization-utilities/CHANGELOG.md
  83. +1 −1 libraries/localization-utilities/package.json
  84. +15 −0 libraries/module-minifier/CHANGELOG.json
  85. +6 −1 libraries/module-minifier/CHANGELOG.md
  86. +1 −1 libraries/module-minifier/package.json
  87. +12 −0 libraries/node-core-library/CHANGELOG.json
  88. +8 −1 libraries/node-core-library/CHANGELOG.md
  89. +1 −1 libraries/node-core-library/package.json
  90. +107 −0 libraries/node-core-library/src/IPackageJson.ts
  91. +2 −1 libraries/node-core-library/src/PackageJsonLookup.ts
  92. +2 −1 libraries/node-core-library/src/index.ts
  93. +15 −0 libraries/operation-graph/CHANGELOG.json
  94. +6 −1 libraries/operation-graph/CHANGELOG.md
  95. +1 −1 libraries/operation-graph/package.json
  96. +15 −0 libraries/package-deps-hash/CHANGELOG.json
  97. +6 −1 libraries/package-deps-hash/CHANGELOG.md
  98. +1 −1 libraries/package-deps-hash/package.json
  99. +24 −0 libraries/package-extractor/CHANGELOG.json
  100. +6 −1 libraries/package-extractor/CHANGELOG.md
  101. +1 −1 libraries/package-extractor/package.json
  102. +1 −1 libraries/rush-lib/package.json
  103. +1 −1 libraries/rush-sdk/package.json
  104. +18 −0 libraries/stream-collator/CHANGELOG.json
  105. +6 −1 libraries/stream-collator/CHANGELOG.md
  106. +1 −1 libraries/stream-collator/package.json
  107. +12 −0 libraries/terminal/CHANGELOG.json
  108. +6 −1 libraries/terminal/CHANGELOG.md
  109. +1 −1 libraries/terminal/package.json
  110. +12 −0 libraries/ts-command-line/CHANGELOG.json
  111. +6 −1 libraries/ts-command-line/CHANGELOG.md
  112. +1 −1 libraries/ts-command-line/package.json
  113. +18 −0 libraries/typings-generator/CHANGELOG.json
  114. +6 −1 libraries/typings-generator/CHANGELOG.md
  115. +1 −1 libraries/typings-generator/package.json
  116. +12 −0 libraries/worker-pool/CHANGELOG.json
  117. +6 −1 libraries/worker-pool/CHANGELOG.md
  118. +1 −1 libraries/worker-pool/package.json
  119. +30 −0 rigs/heft-node-rig/CHANGELOG.json
  120. +6 −1 rigs/heft-node-rig/CHANGELOG.md
  121. +2 −2 rigs/heft-node-rig/package.json
  122. +36 −0 rigs/heft-web-rig/CHANGELOG.json
  123. +6 −1 rigs/heft-web-rig/CHANGELOG.md
  124. +2 −2 rigs/heft-web-rig/package.json
  125. +1 −1 rush-plugins/rush-amazon-s3-build-cache-plugin/package.json
  126. +1 −1 rush-plugins/rush-azure-storage-build-cache-plugin/package.json
  127. +1 −1 rush-plugins/rush-http-build-cache-plugin/package.json
  128. +1 −1 rush-plugins/rush-redis-cobuild-plugin/package.json
  129. +1 −1 rush-plugins/rush-serve-plugin/package.json
  130. +15 −0 webpack/hashed-folder-copy-plugin/CHANGELOG.json
  131. +6 −1 webpack/hashed-folder-copy-plugin/CHANGELOG.md
  132. +1 −1 webpack/hashed-folder-copy-plugin/package.json
  133. +18 −0 webpack/loader-load-themed-styles/CHANGELOG.json
  134. +6 −1 webpack/loader-load-themed-styles/CHANGELOG.md
  135. +2 −2 webpack/loader-load-themed-styles/package.json
  136. +12 −0 webpack/loader-raw-script/CHANGELOG.json
  137. +6 −1 webpack/loader-raw-script/CHANGELOG.md
  138. +1 −1 webpack/loader-raw-script/package.json
  139. +12 −0 webpack/preserve-dynamic-require-plugin/CHANGELOG.json
  140. +6 −1 webpack/preserve-dynamic-require-plugin/CHANGELOG.md
  141. +1 −1 webpack/preserve-dynamic-require-plugin/package.json
  142. +18 −0 webpack/set-webpack-public-path-plugin/CHANGELOG.json
  143. +6 −1 webpack/set-webpack-public-path-plugin/CHANGELOG.md
  144. +1 −1 webpack/set-webpack-public-path-plugin/package.json
  145. +18 −0 webpack/webpack-embedded-dependencies-plugin/CHANGELOG.json
  146. +6 −1 webpack/webpack-embedded-dependencies-plugin/CHANGELOG.md
  147. +1 −1 webpack/webpack-embedded-dependencies-plugin/package.json
  148. +12 −0 webpack/webpack-plugin-utilities/CHANGELOG.json
  149. +6 −1 webpack/webpack-plugin-utilities/CHANGELOG.md
  150. +1 −1 webpack/webpack-plugin-utilities/package.json
  151. +21 −0 webpack/webpack4-localization-plugin/CHANGELOG.json
  152. +6 −1 webpack/webpack4-localization-plugin/CHANGELOG.md
  153. +1 −1 webpack/webpack4-localization-plugin/package.json
  154. +18 −0 webpack/webpack4-module-minifier-plugin/CHANGELOG.json
  155. +6 −1 webpack/webpack4-module-minifier-plugin/CHANGELOG.md
  156. +1 −1 webpack/webpack4-module-minifier-plugin/package.json
  157. +21 −0 webpack/webpack5-load-themed-styles-loader/CHANGELOG.json
  158. +6 −1 webpack/webpack5-load-themed-styles-loader/CHANGELOG.md
  159. +2 −2 webpack/webpack5-load-themed-styles-loader/package.json
  160. +21 −0 webpack/webpack5-localization-plugin/CHANGELOG.json
  161. +6 −1 webpack/webpack5-localization-plugin/CHANGELOG.md
  162. +1 −1 webpack/webpack5-localization-plugin/package.json
  163. +21 −0 webpack/webpack5-module-minifier-plugin/CHANGELOG.json
  164. +6 −1 webpack/webpack5-module-minifier-plugin/CHANGELOG.md
  165. +1 −1 webpack/webpack5-module-minifier-plugin/package.json
24 changes: 24 additions & 0 deletions apps/api-documenter/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
{
"name": "@microsoft/api-documenter",
"entries": [
{
"version": "7.24.12",
"tag": "@microsoft/api-documenter_v7.24.12",
"date": "Tue, 28 May 2024 00:09:47 GMT",
"comments": {
"dependency": [
{
"comment": "Updating dependency \"@microsoft/api-extractor-model\" to `7.28.20`"
},
{
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.2.0`"
},
{
"comment": "Updating dependency \"@rushstack/terminal\" to `0.12.1`"
},
{
"comment": "Updating dependency \"@rushstack/ts-command-line\" to `4.21.3`"
},
{
"comment": "Updating dependency \"@rushstack/heft\" to `0.66.13`"
}
]
}
},
{
"version": "7.24.11",
"tag": "@microsoft/api-documenter_v7.24.11",
7 changes: 6 additions & 1 deletion apps/api-documenter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log - @microsoft/api-documenter

This log was last generated on Sat, 25 May 2024 04:54:07 GMT and should not be manually modified.
This log was last generated on Tue, 28 May 2024 00:09:47 GMT and should not be manually modified.

## 7.24.12
Tue, 28 May 2024 00:09:47 GMT

_Version update only_

## 7.24.11
Sat, 25 May 2024 04:54:07 GMT
2 changes: 1 addition & 1 deletion apps/api-documenter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/api-documenter",
"version": "7.24.11",
"version": "7.24.12",
"description": "Read JSON files from api-extractor, generate documentation pages",
"repository": {
"type": "git",
26 changes: 26 additions & 0 deletions apps/api-extractor/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
{
"name": "@microsoft/api-extractor",
"entries": [
{
"version": "7.45.0",
"tag": "@microsoft/api-extractor_v7.45.0",
"date": "Tue, 28 May 2024 00:09:47 GMT",
"comments": {
"minor": [
{
"comment": "Improve support for resolving the `tsdoc-metadata.json` to include the folder referenced by a `types` field in an `\"exports\"` field and an `\"typesVersions\"` field in addition to `\"types\"`, `\"typings\"`, and `\"tsdocMetadata\"` fields."
}
],
"dependency": [
{
"comment": "Updating dependency \"@microsoft/api-extractor-model\" to `7.28.20`"
},
{
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.2.0`"
},
{
"comment": "Updating dependency \"@rushstack/terminal\" to `0.12.1`"
},
{
"comment": "Updating dependency \"@rushstack/ts-command-line\" to `4.21.3`"
}
]
}
},
{
"version": "7.44.1",
"tag": "@microsoft/api-extractor_v7.44.1",
9 changes: 8 additions & 1 deletion apps/api-extractor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log - @microsoft/api-extractor

This log was last generated on Sat, 25 May 2024 04:54:07 GMT and should not be manually modified.
This log was last generated on Tue, 28 May 2024 00:09:47 GMT and should not be manually modified.

## 7.45.0
Tue, 28 May 2024 00:09:47 GMT

### Minor changes

- Improve support for resolving the `tsdoc-metadata.json` to include the folder referenced by a `types` field in an `"exports"` field and an `"typesVersions"` field in addition to `"types"`, `"typings"`, and `"tsdocMetadata"` fields.

## 7.44.1
Sat, 25 May 2024 04:54:07 GMT
2 changes: 1 addition & 1 deletion apps/api-extractor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/api-extractor",
"version": "7.44.1",
"version": "7.45.0",
"description": "Analyze the exported API for a TypeScript library and generate reviews, documentation, and .d.ts rollups",
"keywords": [
"typescript",
180 changes: 152 additions & 28 deletions apps/api-extractor/src/analyzer/PackageMetadataManager.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import * as path from 'path';
import path from 'path';
import semver from 'semver';

import {
type PackageJsonLookup,
FileSystem,
JsonFile,
type NewlineKind,
type INodePackageJson,
type JsonObject
type JsonObject,
type IPackageJsonExports
} from '@rushstack/node-core-library';
import { Extractor } from '../api/Extractor';
import type { MessageRouter } from '../collector/MessageRouter';
@@ -42,6 +44,134 @@ export class PackageMetadata {
}
}

const TSDOC_METADATA_FILENAME: 'tsdoc-metadata.json' = 'tsdoc-metadata.json';

/**
* 1. If package.json a `"tsdocMetadata": "./path1/path2/tsdoc-metadata.json"` field
* then that takes precedence. This convention will be rarely needed, since the other rules below generally
* produce a good result.
*/
function _tryResolveTsdocMetadataFromTsdocMetadataField({
tsdocMetadata
}: INodePackageJson): string | undefined {
return tsdocMetadata;
}

/**
* 2. If package.json contains a `"exports": { ".": { "types": "./path1/path2/index.d.ts" } }` field,
* then we look for the file under "./path1/path2/tsdoc-metadata.json"
*
* This always looks for a "." and then a "*" entry in the exports field, and then evaluates for
* a "types" field in that entry.
*/

function _tryResolveTsdocMetadataFromExportsField({ exports }: INodePackageJson): string | undefined {
switch (typeof exports) {
case 'string': {
return `${path.dirname(exports)}/${TSDOC_METADATA_FILENAME}`;
}

case 'object': {
if (Array.isArray(exports)) {
const [firstExport] = exports;
// Take the first entry in the array
if (firstExport) {
return `${path.dirname(exports[0])}/${TSDOC_METADATA_FILENAME}`;
}
} else {
const rootExport: IPackageJsonExports | string | null | undefined = exports['.'] ?? exports['*'];
switch (typeof rootExport) {
case 'string': {
return `${path.dirname(rootExport)}/${TSDOC_METADATA_FILENAME}`;
}

case 'object': {
let typesExport: IPackageJsonExports | string | undefined = rootExport?.types;
while (typesExport) {
switch (typeof typesExport) {
case 'string': {
return `${path.dirname(typesExport)}/${TSDOC_METADATA_FILENAME}`;
}

case 'object': {
typesExport = typesExport?.types;
break;
}
}
}
}
}
}
break;
}
}
}

/**
* 3. If package.json contains a `typesVersions` field, look for the version
* matching the highest minimum version that either includes a "." or "*" entry.
*/
function _tryResolveTsdocMetadataFromTypesVersionsField({
typesVersions
}: INodePackageJson): string | undefined {
if (typesVersions) {
let highestMinimumMatchingSemver: semver.SemVer | undefined;
let latestMatchingPath: string | undefined;
for (const [version, paths] of Object.entries(typesVersions)) {
let range: semver.Range;
try {
range = new semver.Range(version);
} catch {
continue;
}

const minimumMatchingSemver: semver.SemVer | null = semver.minVersion(range);
if (
minimumMatchingSemver &&
(!highestMinimumMatchingSemver || semver.gt(minimumMatchingSemver, highestMinimumMatchingSemver))
) {
const pathEntry: string[] | undefined = paths['.'] ?? paths['*'];
const firstPath: string | undefined = pathEntry?.[0];
if (firstPath) {
highestMinimumMatchingSemver = minimumMatchingSemver;
latestMatchingPath = firstPath;
}
}
}

if (latestMatchingPath) {
return `${path.dirname(latestMatchingPath)}/${TSDOC_METADATA_FILENAME}`;
}
}
}

/**
* 4. If package.json contains a `"types": "./path1/path2/index.d.ts"` or a `"typings": "./path1/path2/index.d.ts"`
* field, then we look for the file under "./path1/path2/tsdoc-metadata.json".
*
* @remarks
* `types` takes precedence over `typings`.
*/
function _tryResolveTsdocMetadataFromTypesOrTypingsFields({
typings,
types
}: INodePackageJson): string | undefined {
const typesField: string | undefined = types ?? typings;
if (typesField) {
return `${path.dirname(typesField)}/${TSDOC_METADATA_FILENAME}`;
}
}

/**
* 5. If package.json contains a `"main": "./path1/path2/index.js"` field, then we look for the file under
* "./path1/path2/tsdoc-metadata.json".
*/
function _tryResolveTsdocMetadataFromMainField({ main }: INodePackageJson): string | undefined {
if (main) {
return `${path.dirname(main)}/${TSDOC_METADATA_FILENAME}`;
}
}

/**
* This class maintains a cache of analyzed information obtained from package.json
* files. It is built on top of the PackageJsonLookup class.
@@ -56,7 +186,7 @@ export class PackageMetadata {
* Use ts.program.isSourceFileFromExternalLibrary() to test source files before passing the to PackageMetadataManager.
*/
export class PackageMetadataManager {
public static tsdocMetadataFilename: string = 'tsdoc-metadata.json';
public static tsdocMetadataFilename: string = TSDOC_METADATA_FILENAME;

private readonly _packageJsonLookup: PackageJsonLookup;
private readonly _messageRouter: MessageRouter;
@@ -70,37 +200,30 @@ export class PackageMetadataManager {
this._messageRouter = messageRouter;
}

// 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.
/**
* 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.
*/
private static _resolveTsdocMetadataPathFromPackageJson(
packageFolder: string,
packageJson: INodePackageJson
): string {
const tsdocMetadataFilename: string = PackageMetadataManager.tsdocMetadataFilename;

let tsdocMetadataRelativePath: string;

if (packageJson.tsdocMetadata) {
// 1. If package.json contains a field such as "tsdocMetadata": "./path1/path2/tsdoc-metadata.json",
// then that takes precedence. This convention will be rarely needed, since the other rules below generally
// produce a good result.
tsdocMetadataRelativePath = packageJson.tsdocMetadata;
} else if (packageJson.typings) {
// 2. If package.json contains a field such as "typings": "./path1/path2/index.d.ts", then we look
// for the file under "./path1/path2/tsdoc-metadata.json"
tsdocMetadataRelativePath = path.join(path.dirname(packageJson.typings), tsdocMetadataFilename);
} else if (packageJson.main) {
// 3. If package.json contains a field such as "main": "./path1/path2/index.js", then we look for
// the file under "./path1/path2/tsdoc-metadata.json"
tsdocMetadataRelativePath = path.join(path.dirname(packageJson.main), tsdocMetadataFilename);
} else {
// 4. If none of the above rules apply, then by default we look for the file under "./tsdoc-metadata.json"
// since the default entry point is "./index.js"
tsdocMetadataRelativePath = tsdocMetadataFilename;
}
const tsdocMetadataRelativePath: string =
_tryResolveTsdocMetadataFromTsdocMetadataField(packageJson) ??
_tryResolveTsdocMetadataFromExportsField(packageJson) ??
_tryResolveTsdocMetadataFromTypesVersionsField(packageJson) ??
_tryResolveTsdocMetadataFromTypesOrTypingsFields(packageJson) ??
_tryResolveTsdocMetadataFromMainField(packageJson) ??
// As a final fallback, place the file in the root of the package.
TSDOC_METADATA_FILENAME;

// Always resolve relative to the package folder.
const tsdocMetadataPath: string = path.resolve(packageFolder, tsdocMetadataRelativePath);
const tsdocMetadataPath: string = path.resolve(
packageFolder,
// This non-null assertion is safe because the last entry in TSDOC_METADATA_RESOLUTION_FUNCTIONS
// returns a non-undefined value.
tsdocMetadataRelativePath!
);
return tsdocMetadataPath;
}

@@ -117,6 +240,7 @@ export class PackageMetadataManager {
if (tsdocMetadataPath) {
return path.resolve(packageFolder, tsdocMetadataPath);
}

return PackageMetadataManager._resolveTsdocMetadataPathFromPackageJson(packageFolder, packageJson);
}

Loading