Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.d.ts needs updating for version 11 #3722

Closed
PeterWone opened this issue Feb 26, 2023 · 8 comments
Closed

.d.ts needs updating for version 11 #3722

PeterWone opened this issue Feb 26, 2023 · 8 comments
Labels
bug help welcome Could use help from community parser

Comments

@PeterWone
Copy link

Updating to 11.* causes code like this to break. Revert to 10.7.3 and the weirdness stops.

renderedCode = hljs.highlight(raw, { language: languageId }).value;

Adding .default helps

renderedCode = hljs.default.highlight(raw, { language: languageId }).value;

but then there is a new problem reported

Module not found: Error: Package path ./styles is not exported from package C:\pathto\node_modules\highlight.js (see exports field in C:\pathto\node_modules\highlight.js\package.json)

Revert to 10.7.3 and the weirdness stops.

I had a look at .d.ts definition at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/highlightjs/index.d.ts but the problem wasn't evident.

@joshgoebel
Copy link
Member

Updating to 11.* causes code like this to break.

Break how? How are you using the library? CJS? ES? Browser/Node?

Adding .default helps

This is definitely not intended, this only exists to make some bundlers happy with how we export things.

I had a look at .d.ts definition at

That is for version 9, so it's very incorrect and outdated now.

@PeterWone
Copy link
Author

My code is a VS Code extension which makes the answer to your second question "node".

It breaks in the sense that VS Code says the hljs.highlight and hljs.highlightAuto methods do not exist until I rewrite as described (hljs.default.highlight) and also webpack cannot find ./styles/ even though I can see the files are present in node_modules.

As soon as I revert to 10.7.3 everything is good - although it hasn't been updated since 9.x those typings work fine for both vscode and webpack.

@joshgoebel
Copy link
Member

which makes the answer to your second question "node".

And how exactly are you importing the library?

and also webpack cannot find ./styles/

We export ./styles/* in exports, so this may be a bug with webpack. Webpack has had it's share of issues trying to keep up with this stuff. If there is something we need to change, I'm all ears if anyone knows.

Our types file exports hljs as default, which means this "just works":

import hljs from 'highlight.js';
hljs.getLanguages() // etc

This certainly works (in practice) with just pulling in the library directly with Node. As far as why VS Code or TypeScript might dislike that I dunno - we really could use a Typescript expert to help us with such matters...

@PeterWone
Copy link
Author

Yep did as I said and while you were writing my autoimporter (code tool) figured out import hljs from 'highlight.js'; and it works so that part is 100% good.

This is what webpack reports:

Module not found: Error: Package path ./styles is not exported from package C:\projects\vsc-print\node_modules\highlight.js (see exports field in C:\projects\vsc-print\node_modules\highlight.js\package.json)
 @ ./src/extension.ts 15:24-50

@joshgoebel
Copy link
Member

What style are you trying to import exactly?

@PeterWone
Copy link
Author

PeterWone commented Mar 6, 2023

All the light ones. I let users pick at runtime and my embedded webserver serves by name out of the bundle. I don't let them pick dark themes because users don't seem to understand that it doesn't matter what they do on-screen, paper continues to be white.

			switch (urlParts[3]) {
				case "colour-scheme.css":
					let colourScheme = vscode.workspace.getConfiguration("print").colourScheme;
					let colourSchemeName: string = filenameByCaption[colourScheme];
					logger.debug(`Loading colour scheme from ${colourSchemeName}`);
					let colourSchemeCss: string = require(`highlight.js/styles/${colourSchemeName}.css`).default.toString();
					response.writeHead(200, {
						"Content-Type": "text/css; charset=utf-8",
						"Content-Length": colourSchemeCss.length,
						'Cache-Control': 'no-cache'
					});
					response.end(colourSchemeCss);
					break;

@joshgoebel
Copy link
Member

So the import works now? Great!

The styles issues is a dup of #3634... which I've closed - you'll need to take the issue up with Webpack.

@PeterWone
Copy link
Author

blergh... guess I'll stick with 10.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community parser
Projects
None yet
Development

No branches or pull requests

2 participants