lezer-parser / highlight

Syntax highlighting from Lezer trees
MIT License
31 stars 9 forks source link

Generate declarations as `index.d.ts` instead of `highlight.d.ts` #1

Closed fonsp closed 2 years ago

fonsp commented 2 years ago

I was having trouble building declarations for my project, with the following error:

➜  codemirror-pluto-setup git:(codemirror-0.20.0-but-better) ✗ npm run bundle

> @plutojl/codemirror-pluto-setup@0.28.0 bundle
> rollup -c

src/basic-setup.ts → dist/index.es.js...
created dist/index.es.js in 1.3s

src/basic-setup.ts → dist/index.d.ts...
[!] Error: 'Highlighter' is not exported by node_modules/@lezer/highlight/dist/index.js, imported by node_modules/@codemirror/language/dist/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/@codemirror/language/dist/index.js
Error: 'Highlighter' is not exported by node_modules/@lezer/highlight/dist/index.js, imported by node_modules/@codemirror/language/dist/index.js
    at error (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:198:30)
    at Module.error (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12477:16)
    at Module.traceVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12835:29)
    at ModuleScope.findVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:11465:39)
    at FunctionScope.findVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:6433:38)
    at Identifier.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:7724:40)
    at AssignmentPattern.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5298:23)
    at FunctionDeclaration.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5294:31)
    at Program.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5294:31)
    at Module.bindReferences (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12473:18)

(I am using @codemirror/language@0.20.1 and @lezer/highlight@0.16.0.)

I am getting this error because the declarations for @lezer/highlight/dist/index.js are in @lezer/highlight/dist/highlight.d.ts, not @lezer/highlight/dist/index.d.ts, and it looks like my bundler expects the declarations to have the same name as the JS file.

This PR fixes it by renaming src/highlight.ts to src/index.ts, which will rename the .d.ts file. (I could not find a way to change the name of the declarations file using config alone).

marijnh commented 2 years ago

and it looks like my bundler expects the declarations to have the same name as the JS file.

Seems it is ignoring the types field in package.json, which sounds like an issue in the bundler. I generally don't accept patches that work around bugs in other software, since those are really not my responsibility.

fonsp commented 2 years ago

Alright, sounds fair!