Skip to content

Make usable from typescript file using npm imports #13

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Banner-Keith
Copy link

Hello, hopefully this Pull Request is welcome.

I was running into issues trying to use this in a project where I set up highlight.js from a typescript module. I was able to resolve this simply by adding a typing file and surfacing the src/languages/tsql.js file as the main import.

I don't think this will negatively affect CDN users, but I wasn't quite sure how to test that scenario, so help in that area would be appreciated.

I also incremented the minor version number, which seems appropriate, but I will the new version number up to you.

Please let me know if there is anything you'd like me to change.

Added types file. Included dependency on highlight.js to allow type specification to specify return type to avoid TypeScript linter errors. Added usage example.

Added types file. Included dependency on highlight.js to allow type specification to specify return type to avoid TypeScript linter errors. Added usage example.
@Greg-Smulko
Copy link
Collaborator

Hey Keith, of course, always welcome! :)

As you can see, there's not much activity in here, but I'll try to remind myself how to package and publish a new version to npm. ;)

Copy link
Collaborator

@Greg-Smulko Greg-Smulko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm totally happy to have it merged as is, but I have some concerns about whether it would work the way you'd like it to. ;)

Regarding testing, probably https://github.com/highlightjs/highlight.js/blob/main/extra/3RD_PARTY_QUICK_START.md is the best source.

My main concern is that the files don't end up in tar.gz to be published to npm.

package.json Outdated
Comment on lines 28 to 30
"devDependencies": {
"highlight.js": "^11.6.0"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a production dependency, not a dev one, isn't it?
Why this version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest a looser > 11.x pin where x is maybe a more recent release... We're usually very serious about breaking changes. If it works with 11.0 it should work with 11.9, 11.24, etc...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to a dependency instead of dev dependency and set to ^11.x

@joshgoebel would you prefer I specifically make it > 11.x so that it will work with greater major versions too?

.types/tsql.d.ts Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth following the convention from https://github.com/highlightjs/highlight.js/tree/main/types , so types rather than .types?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Fixed that.

package.json Outdated
@@ -23,5 +24,8 @@
"dist/tsql.min.js",
"dist/tsql.es.min.js",
"dist/ssms.min.css"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsql.d.ts doesn't end up in the package when I run npm pack - should we list it files as per https://docs.npmjs.com/cli/v9/commands/npm-publish#files-included-in-package ?

Probably the same about src/languages/tsql.js now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think so.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

README.md Outdated
import hljs from 'highlight.js';

import tsql from 'highlight.js-tsql';
hljs.registerLanguage('tsql', tsql);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work as it is in terms of importing the ssms.css, does it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the example to include the css import. Did a local pack and installed the package locally and the styles resolved successfully.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks a lot!

LGTM - @joshgoebel, anything from you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants