Skip to content

Commit 653815f

Browse files
committed
build: add npm publishing
1 parent acb0fc4 commit 653815f

6 files changed

Lines changed: 215 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
with:
2323
deno-version: v2.x
2424

25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 22
29+
2530
- name: Verify formatting
2631
run: deno fmt --check
2732

@@ -34,6 +39,9 @@ jobs:
3439
- name: Run tests
3540
run: deno test
3641

42+
- name: Build npm package
43+
run: deno task build:npm
44+
3745
docs:
3846
runs-on: ubuntu-latest
3947
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
coverage/
22
docs/vendor/
3+
npm/

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<p align="center">
1717
<a href="https://github.com/ClaudiuCeia/ts-duckling/actions/workflows/ci.yml"><img src="https://github.com/ClaudiuCeia/ts-duckling/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
1818
<a href="https://jsr.io/@claudiu-ceia/ts-duckling"><img src="https://jsr.io/badges/@claudiu-ceia/ts-duckling" alt="JSR"></a>
19+
<a href="https://www.npmjs.com/package/@claudiu-ceia/ts-duckling"><img src="https://img.shields.io/npm/v/@claudiu-ceia/ts-duckling" alt="npm"></a>
1920
<a href="./LICENSE"><img src="https://img.shields.io/github/license/ClaudiuCeia/ts-duckling" alt="MIT license"></a>
2021
<a href="https://claudiuceia.github.io/ts-duckling/"><img src="https://img.shields.io/badge/playground-live%20demo-3b82f6" alt="Playground"></a>
2122
</p>
@@ -103,7 +104,7 @@ deno add jsr:@claudiu-ceia/ts-duckling
103104
### npm
104105

105106
```sh
106-
npx jsr add @claudiu-ceia/ts-duckling
107+
npm install @claudiu-ceia/ts-duckling
107108
```
108109

109110
## Getting started

deno.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"imports": {
1818
"@claudiu-ceia/combine": "jsr:@claudiu-ceia/combine@0.3.0",
19+
"@deno/dnt": "jsr:@deno/dnt@^0.41.3",
1920
"@std/assert": "jsr:@std/assert@1.0.18",
2021
"@std/testing/time": "jsr:@std/testing@1.0.17/time",
2122

@@ -27,6 +28,8 @@
2728
"fmt": "deno fmt",
2829
"lint": "deno lint",
2930
"check": "deno fmt --check && deno lint && deno check mod.ts && deno test",
31+
"build:npm": "deno run -A scripts/build_npm.ts",
32+
"publish:npm": "deno task build:npm && npm publish ./npm --access public",
3033
"update:data": "deno run -A scripts/update_data.ts",
3134
"test": "deno test",
3235
"hooks:install": "ln -sf ../../scripts/pre-commit .git/hooks/pre-commit && chmod +x scripts/pre-commit",

deno.lock

Lines changed: 121 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build_npm.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { build, emptyDir } from "@deno/dnt";
2+
3+
const denoJson = JSON.parse(await Deno.readTextFile("./deno.json")) as {
4+
version: string;
5+
};
6+
7+
await emptyDir("./npm");
8+
9+
await build({
10+
entryPoints: ["./mod.ts"],
11+
outDir: "./npm",
12+
importMap: "deno.json",
13+
test: false,
14+
esModule: true,
15+
scriptModule: false,
16+
typeCheck: "single",
17+
compilerOptions: {
18+
target: "ES2022",
19+
lib: ["ES2022", "DOM"],
20+
sourceMap: false,
21+
inlineSources: false,
22+
},
23+
shims: {
24+
deno: false,
25+
weakRef: false,
26+
webSocket: false,
27+
blob: false,
28+
crypto: false,
29+
domException: false,
30+
fetch: false,
31+
file: false,
32+
fileReader: false,
33+
formData: false,
34+
headers: false,
35+
httpClient: false,
36+
readFile: false,
37+
timers: false,
38+
url: false,
39+
urlSearchParams: false,
40+
},
41+
package: {
42+
name: "@claudiu-ceia/ts-duckling",
43+
version: denoJson.version,
44+
description: "A tiny, deterministic entity extractor for TypeScript.",
45+
license: "MIT",
46+
keywords: [
47+
"entity-extraction",
48+
"parser",
49+
"pii",
50+
"redaction",
51+
"typescript",
52+
],
53+
repository: {
54+
type: "git",
55+
url: "git+https://github.com/ClaudiuCeia/ts-duckling.git",
56+
},
57+
bugs: {
58+
url: "https://github.com/ClaudiuCeia/ts-duckling/issues",
59+
},
60+
homepage: "https://github.com/ClaudiuCeia/ts-duckling#readme",
61+
engines: {
62+
node: ">=18",
63+
},
64+
},
65+
postBuild() {
66+
Deno.copyFileSync("README.md", "npm/README.md");
67+
Deno.copyFileSync("LICENSE", "npm/LICENSE");
68+
Deno.writeTextFileSync(
69+
"npm/.npmignore",
70+
[
71+
"/src/",
72+
"**/*.d.ts.map",
73+
"**/*.js.map",
74+
"package-lock.json",
75+
"yarn.lock",
76+
"pnpm-lock.yaml",
77+
].join("\n") + "\n",
78+
);
79+
},
80+
});

0 commit comments

Comments
 (0)