Skip to content

Commit

Permalink
Merge pull request #18 from playcanvas/fix-esm-next
Browse files Browse the repository at this point in the history
Support Single Types file
  • Loading branch information
marklundin authored Oct 4, 2024
2 parents e1876a2 + 1c2a5d5 commit e26fcf3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
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

0 comments on commit e26fcf3

Please sign in to comment.