Skip to content
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

Default to the package.json source field #1991

Closed
jlarmstrongiv opened this issue Jul 8, 2022 · 4 comments
Closed

Default to the package.json source field #1991

jlarmstrongiv opened this issue Jul 8, 2022 · 4 comments
Labels
enhancement Improved functionality

Comments

@jlarmstrongiv
Copy link

jlarmstrongiv commented Jul 8, 2022

Search Terms

Legacy typedoc entry point config (using "typedocMain" field) found for "". Please update to use "typedoc": { "entryPoint": "..." } instead. In future upgrade, "typedocMain" field will be ignored.

package.json source field

Problem

Typedoc understandably needs to know where my source typescript files are.

Suggested Solution

Use the defacto standard of the package.json.source field by default. However, allow overriding the source field by using "typedoc": { "entryPoint": "..." }

The source field in the package.json points to the entry ts file and is used as a defacto standard.

Examples of the source field in the wild are:

@jlarmstrongiv jlarmstrongiv added the enhancement Improved functionality label Jul 8, 2022
@akphi
Copy link
Contributor

akphi commented Jul 8, 2022

I'm pretty sure if you don't specify either typedocMain or typedoc.entryPoint, we will resolve by main field

export function getTsEntryPointForPackage(
logger: Logger,
packageJsonPath: string,
packageJson: Record<string, unknown>
): string | undefined | typeof ignorePackage {
let packageMain = "index.js"; // The default, per the npm docs.
let packageTypes = null;
const typedocPackageConfig = extractTypedocConfigFromPackageManifest(
logger,
packageJsonPath
);
if (typedocPackageConfig?.entryPoint) {
packageMain = typedocPackageConfig.entryPoint;
} else if (
hasOwnProperty(packageJson, "typedocMain") &&
typeof packageJson.typedocMain == "string"
) {
logger.warn(
`Legacy typedoc entry point config (using "typedocMain" field) found for "${nicePath(
packageJsonPath
)}". Please update to use "typedoc": { "entryPoint": "..." } instead. In future upgrade, "typedocMain" field will be ignored.`
);
packageMain = packageJson.typedocMain;
} else if (
hasOwnProperty(packageJson, "main") &&
typeof packageJson.main == "string"
) {
packageMain = packageJson.main;
} else if (
hasOwnProperty(packageJson, "types") &&
typeof packageJson.types == "string"
) {
packageTypes = packageJson.types;
} else if (
hasOwnProperty(packageJson, "typings") &&
typeof packageJson.typings == "string"
) {
packageTypes = packageJson.typings;
}

@jlarmstrongiv
Copy link
Author

@akphi very interesting! For me, the main field always refers to the compiled dist/index.cjs, rather than the typescript in the source field src/index.ts

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 9, 2022

I'm somewhat wary of adding even more options for specifying source files without a very clear reason for making the already fairly complicated monorepo code even more so...

If your compiled source contains source maps, TypeDoc in packages mode will automatically resolve the compiled file back to the .ts file.

Another proposal for the use of the typescript:main key: microsoft/TypeScript#12561


This source key doesn't seem very commonly used... I have a folder with the 1000-packages dependency installed, which actually installs nearly 19,000 packages. Of these packages, a total of 23 use the source key.

@jlarmstrongiv
Copy link
Author

jlarmstrongiv commented Jul 9, 2022

@Gerrit0 alrighty, thank you for your consideration! I do not use source maps in production, so typedoc will not automatically resolve in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

No branches or pull requests

3 participants