-
-
Notifications
You must be signed in to change notification settings - Fork 224
Add TypeScript definitions #797
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
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,30 @@ | |||
{ | |||
"name": "goatcounter", | |||
"version": "4.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This intends to match these versions and could be bumped accordingly in the future.
| (GoatCounter.Settings & | ||
GoatCounter.DataParameters & | ||
GoatCounter.Methods) | ||
| undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
accounts for scenarios in which the async script might still be loading.
package.json
Outdated
"prepack": "cp README.md git.README.md && mv README.npm.md README.md", | ||
"postpack": "mv README.md README.npm.md && mv git.README.md README.md" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This temporarily swaps the repository's README.md
with README.npm.md
during the npm packing process such that the npm package can use a different, slimmed down README.
tpl/help/countjs-host.md
Outdated
@@ -7,6 +7,8 @@ inside `<script>` tags. You won’t get any new features or other updates, but t | |||
To host `count.js` somewhere else just copy it from https://gc.zgo.at/count.js | |||
and adjust the URL in `src`. | |||
|
|||
For convenience, the script is also published as an [npm package](https://www.npmjs.com/package/goatcounter) which can be copied into a public directory during your application's build process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand what "can be copied into a public directory" means here?
Or to phrase it different: how would one use the npm package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The count.js
source code is included in the package in addition to the type definitions, so instead of manually copying the file (per the existing sentence above), an application's build process could copy it from ./node_modules/goatcounter/public/count.js
into its public / webroot directory to serve locally.
Feel free to expand the suggested documentation update, or I could take another pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you use the types? That also needs to be copied manually then I assume?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the package just has to be referenced in TSConfig types
.
9b86465 expands documentation, but let me know if I can clarify anything else!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I have it working locally by putting the count.d.ts in the public/ directory and adding /// <reference path="./count.d.ts" />
to count.js
I haven't looked at the whole npm story yet, but that seems the best way to get it working in a simple npm-less setups? At the very least it's useful for me testing/changing the count.d.ts file going forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, such triple-slash directives can be used for testing – they're just less common these days (as compared to TSConfig and package managers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for the confirmation; appreciate it. There's tons of documentation on everything regarding JS/TS, with different ways of doing things, and not always so easy to see what the "right" or "wrong" way is.
I think all my questions are answered, but it will probably be a few weeks until I look at it in more detail because it's relatively time-consuming and I have some other things I want to do first.
* `null`. | ||
* | ||
* @see https://www.goatcounter.com/help/modify | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using /* .. */
style comments required? Or will //
comments also work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, //
is fine for single line comments, but this is conventional JSDoc (which is supported well in most IDEs).
* 'main' of github.com:namoscato/goatcounter: Update GeoDB Change default location of SQLite DB and ACME certs to goatcounter-data/ Clarify "append not found" error in count.js Strip trailing slash from visitor counter Don't error out if email activation token is used more than once Update pt-BR translation Update dependencies and refspam
Resolves #789
Summary
count.d.ts
TypeScript definitions for public JavaScript APIREADME.npm.md
, used as npm package's README during packTesting
In an application codebase, run
npm install
with the full path to this repository, i.e.Additionally, you can check to see what will by published by running
npm pack
:Publishing
See Creating and publishing unscoped public packages for more information on how to publish this package to npm, i.e.
npm publish