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

Support Single Types file #18

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"engines": {
"node": ">=18.0.0"
},
"version": "1.1.0",
"version": "1.2.0",
"dependencies": {
"@microsoft/tsdoc": "^0.15.0",
"@playcanvas/eslint-config": "^1.7.4",
Expand Down
24 changes: 18 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { createDefaultMapFromCDN, flatMapAnyNodes, getExportedNodes, getType, in
const toLowerCamelCase = str => str[0].toLowerCase() + str.substring(1);

const COMPILER_OPTIONS = {
noLib: true,
strict: false,
skipLibCheck: true, // Skip type checking of declaration files
target: ts.ScriptTarget.ES2022, // If this version changes, the types must be updated in the /rollup.config.mjs
target: ts.ScriptTarget.ES2023, // If this version changes, the types must be updated in the /rollup.config.mjs
module: ts.ModuleKind.CommonJS,
checkJs: true, // Enable JSDoc parsing
allowJs: true,
Expand All @@ -36,19 +37,30 @@ export class JSDocParser {
/**
* Initializes the JSDocParser with the standard library files
*
* @param {string} libPath - The path to standard library files
* @param {string} libPath - A path to a directory of library types, or a path to the '.d.ts' file itself
* @returns {Promise<JSDocParser>} - The initialized JSDocParser
*/
async init(libPath = '') {
async init(libPath) {
if (this._env) {
return this;
}

let fsMap;
if (libPath) {
fsMap = await createDefaultMapFromCDN({ target: ts.ScriptTarget.ES2022 }, libPath, ts);
} else {
if (!libPath) {

// This is a node only option. If no lib path is passed, attempt to resolve ES types from node_modules.
fsMap = await createDefaultMapFromNodeModules(COMPILER_OPTIONS, ts);

} else if (libPath.endsWith('.d.ts')) {

// If the libPath is a '.d.ts' file then load it and add it
const types = await fetch(libPath).then(r => r.text());
fsMap = new Map([['/lib.d.ts', types]]);

} else {

// A libPath was supplied, but not to a '.d.ts', so assume this is a path to types
fsMap = await createDefaultMapFromCDN(COMPILER_OPTIONS, libPath, ts);
}

// Set up the virtual file system and environment
Expand Down