antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.11k stars 3.28k forks source link

Antlr 4.13.0 typescript target introduced invalid module configuration #4285

Closed trmjoa closed 1 year ago

trmjoa commented 1 year ago

Hi,

This PR introduces a bug in the npm package definition.

In the exports section of the package.json file the file referenced in the node/browser sections does not exist.

  "exports": {
    ".": {
      "node": {
        "types": "src/index.node.d.ts",
        "import": "./dist/antlr4.node.mjs",
        "require": "./dist/antlr4.node.cjs",
        "default": "./dist/antlr4.node.mjs"
      },
      "browser": {
        "types": "src/index.web.d.ts",
        "import": "./dist/antlr4.web.mjs",
        "require": "./dist/antlr4.web.cjs",
        "default": "./dist/antlr4.web.mjs"
      }
    }

src/index.node.d.ts and src/index.web.d.ts does not exist in the shipped package. All files in the src directory in the released module is located in src/antlr4, and even here there is no combined definition files.

Unless you create a combined file the intention is maybe to point this path at src/antlr4/index.d.ts?

ericvergnaud commented 1 year ago

mmm.... not sure what happened @Tarjei400 Any chance you can look into this and submit a PR ?

Tarjei400 commented 1 year ago

@ericvergnaud I will take a look :+1:

Tarjei400 commented 1 year ago

@trmjoa @ericvergnaud Seems it came in review and my missunderstanding of types file. I think you are right and we should stick to reference src/antlr4/index.d.ts in type, and remove node/browser override. Could you take a look at pr?

ericvergnaud commented 1 year ago

@trmjoa Can you confirm if this change does not introduce other related issues ?

Tarjei400 commented 1 year ago

For reference, proper solution will be comming with this PR #4297

trmjoa commented 1 year ago

Hi. Sorry for the late reply. I have been off-grid for a while. I have tried locally changing the types pointer as in #4297, which seems to be an improvement. vscode/typescript compiler manages to resolve the file (as we would expect), but vscode is unable to resolved the named imports.

Example, when you click a named export in your generated parser, vscode will not manage to look the types for that export, something it usually does. Anyhow, #4297 fixes that its at least is a valid path.