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

Merged
merged 2 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .types/tsql.d.ts
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
Contributor 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LanguageFn } from "highlight.js";

declare module 'highlight.js-tsql' {
const tsql: LanguageFn;
export default tsql;
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ Simply load this module after loading Highlight.js. You'll use the minified vers

For more details of the usage see [Highlight.js main page](https://github.com/highlightjs/highlight.js#highlightjs).

### Usage with TypeScript import from npm package

```typescript
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
Contributor 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?

```

## Authors

[David Simner](https://github.com/DavidSimner), [Greg Smulko](https://github.com/Greg-Smulko)
Expand Down
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "highlight.js-tsql",
"description": "Syntax highlighting for T-SQL.",
"main": "dist/tsql.js",
"main": "src/languages/tsql.js",
"types": ".types/tsql.d.ts",
"keywords": [
"highlight",
"syntax",
"T-SQL",
"sql"
],
"homepage": "https://github.com/highlightjs/highlightjs-tsql",
"version": "1.2.0",
"version": "1.3.0",
"author": "Greg Smulko",
"bugs": {
"url": "https://github.com/highlightjs/highlightjs-tsql/issues"
Expand All @@ -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
Contributor Author

Choose a reason for hiding this comment

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

Fixed

]
],
"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
Contributor 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?

}