retorquere / generator-zotero-plugin

Generate zotero plugin build scaffolding
MIT License
30 stars 7 forks source link

Excluding node_modules excludes zotero-types #37

Open ProfDoof opened 11 months ago

ProfDoof commented 11 months ago

https://github.com/retorquere/generator-zotero-plugin/blob/2ea55de163dcce039db9c7950ea8323f332ab67b/app/tsconfig.json#L19-L24

This may be because I'm not as familiar with the tsconfig.json or my LSP not working correctly, but when the tsconfig.json excludes the node_modules folder, it excludes the zotero-types folder as well. I believe that's because according to https://www.typescriptlang.org/tsconfig#exclude, the exclude only excludes things that are matched by include and that match the pattern. It almost seems like a filter function on top of include rather than excluding everything except for what's included like what I would expect.

This causes my LSP to not be able to find the zotero-types type declarations and the need to declare const Zotero: any at the top which isn't needed when I get rid of the line excluding the node_modules folder. When I use the following tsconfig.json, I no longer get Cannot find name 'Zotero'. (2304) in my lib.ts file.

tsconfig.json

{
  "compilerOptions": {
    "importHelpers": true,
    "target": "es2017",
    "disableSizeLimit": true,
    "module": "commonjs",
    "strict": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "esModuleInterop": true,
    "removeComments": false,
    "preserveConstEnums": false,
    "sourceMap": false,
    "downlevelIteration": true,
    "lib": [ "es2017", "dom" ]
  },
  "include": [ "*.ts", "chrome/content", "typing", "node_modules/zotero-types" ],
  "exclude": [
    "**/*.spec.ts",
    "typings"
  ]
}

even with my lib.ts looking like this without declaring the const at the top.

lib.ts

const {
  // classes: Cc,
  // interfaces: Ci,
  utils: Cu,
} = Components

if (Zotero.platformMajorVersion < 102) {
  Cu.importGlobalProperties(['URL'])
}

Zotero.DuplicateMergingFlow = new class {
  debug(msg: string) {
    Zotero.debug(`Duplicate Merging Flow [DEBUG]: ${  msg}`)
  }

  info(msg: string) {
    Zotero.log(`Duplicate Merging Flow [INFO]: ${  msg}`)
  }
}
retorquere commented 11 months ago

I must admit I don't fully grok the tsconfig file, I've been experimenting my wag through it. If you have a recommended change I'd be happy to include it.

ProfDoof commented 11 months ago

I'm pretty much in the same boat. Let me get another friend of mine in here who works with TS and JS more often than I do. XD