@playcanvas/attribute-parser 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +18 -6
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
7
7
  },
8
- "version": "1.2.0",
8
+ "version": "1.3.0",
9
9
  "dependencies": {
10
10
  "@microsoft/tsdoc": "^0.15.0",
11
11
  "@playcanvas/eslint-config": "^1.7.4",
package/src/index.js CHANGED
@@ -8,9 +8,10 @@ import { createDefaultMapFromCDN, flatMapAnyNodes, getExportedNodes, getType, in
8
8
  const toLowerCamelCase = str => str[0].toLowerCase() + str.substring(1);
9
9
 
10
10
  const COMPILER_OPTIONS = {
11
+ noLib: true,
11
12
  strict: false,
12
13
  skipLibCheck: true, // Skip type checking of declaration files
13
- target: ts.ScriptTarget.ES2022, // If this version changes, the types must be updated in the /rollup.config.mjs
14
+ target: ts.ScriptTarget.ES2023, // If this version changes, the types must be updated in the /rollup.config.mjs
14
15
  module: ts.ModuleKind.CommonJS,
15
16
  checkJs: true, // Enable JSDoc parsing
16
17
  allowJs: true,
@@ -36,19 +37,30 @@ export class JSDocParser {
36
37
  /**
37
38
  * Initializes the JSDocParser with the standard library files
38
39
  *
39
- * @param {string} libPath - The path to standard library files
40
+ * @param {string} libPath - A path to a directory of library types, or a path to the '.d.ts' file itself
40
41
  * @returns {Promise<JSDocParser>} - The initialized JSDocParser
41
42
  */
42
- async init(libPath = '') {
43
+ async init(libPath) {
43
44
  if (this._env) {
44
45
  return this;
45
46
  }
46
47
 
47
48
  let fsMap;
48
- if (libPath) {
49
- fsMap = await createDefaultMapFromCDN({ target: ts.ScriptTarget.ES2022 }, libPath, ts);
50
- } else {
49
+ if (!libPath) {
50
+
51
+ // This is a node only option. If no lib path is passed, attempt to resolve ES types from node_modules.
51
52
  fsMap = await createDefaultMapFromNodeModules(COMPILER_OPTIONS, ts);
53
+
54
+ } else if (libPath.endsWith('.d.ts')) {
55
+
56
+ // If the libPath is a '.d.ts' file then load it and add it
57
+ const types = await fetch(libPath).then(r => r.text());
58
+ fsMap = new Map([['/lib.d.ts', types]]);
59
+
60
+ } else {
61
+
62
+ // A libPath was supplied, but not to a '.d.ts', so assume this is a path to types
63
+ fsMap = await createDefaultMapFromCDN(COMPILER_OPTIONS, libPath, ts);
52
64
  }
53
65
 
54
66
  // Set up the virtual file system and environment