Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: [push, pull_request]

env:
DENO_VERSION: 2.x
DENO_TLS_CA_STORE: system

jobs:
test:
Expand Down
28 changes: 26 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: publish

env:
DENO_VERSION: 2.x
NODE_VERSION: 20.x
DENO_TLS_CA_STORE: system

on:
push:
Expand All @@ -14,12 +16,34 @@ permissions:
id-token: write

jobs:
publish:
publish-jsr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Publish on tag
- name: Publish to JSR
run: deno run --allow-env --allow-run=deno --allow-read --allow-write=deno.jsonc jsr:@david/publish-on-tag@0.1.4

publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}
cache: true
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"
- name: Build npm package
run: deno task npm:build
env:
VERSION: ${{ github.ref_name }}
- name: Publish to npm
run: npm publish --provenance --access=public
working-directory: ./npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
docs/
coverage/
coverage/
npm/
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
## @cosense/types

[![JSR](https://jsr.io/badges/@cosense/types)](https://jsr.io/@cosense/types)
[![npm](https://img.shields.io/npm/v/@cosense/types)](https://www.npmjs.com/package/@cosense/types)
[![test](https://github.com/scrapbox-jp/types/workflows/ci/badge.svg)](https://github.com/scrapbox-jp/types/actions?query=workflow%3Aci)

> **Node.js & npm Notice (since 0.11.1)**
>
> Now also published on **[npm](https://www.npmjs.com/package/@cosense/types)**.
>
> Node.js support is **experimental**: I mainly target Deno and browsers, so I
> don't actively maintain Node.js compatibility. Some tests run, but there may
> still be runtime or type gaps remaining. Please use it with that
> understanding.
>
> That said, **issues / PRs to improve Node support are very welcome!**
>
> If you don't need a public npm package, you can consume the JSR version
> directly—`npm` via a custom registry in `.npmrc`; `yarn` or `pnpm` need no
> extra config. See the
> [JSR docs](https://jsr.io/docs/using-packages#adding-a-package).

Type definitions for [cosense](https://cosen.se)

## Getting Started

This library provides TypeScript type definitions for Scrapbox/Cosense and
supports both JSR (JavaScript Registry) and npm installation methods.

### Installation

#### Option 1: JSR (Recommended for Deno projects)

If you want to use type definitions for REST API, run

```bash
Expand All @@ -18,3 +42,51 @@ If you want to use type definitions for UserScript, run
```bash
deno add jsr:@cosense/types/userscript
```

#### Option 2: npm (For Node.js projects)

Install via npm:

```bash
npm install @cosense/types
```

Import the library:

```typescript ignore
// ESM syntax
import type { PageList } from "@cosense/types/rest";
import type { Scrapbox } from "@cosense/types/userscript";
```

### Usage Examples

```typescript ignore
// Example for JSR (Deno)
import type { PageList } from "jsr:@cosense/types/rest";

const pages: PageList = {
projectName: "example-project",
skip: 0,
limit: 100,
count: 42,
pages: [],
};
```

For npm users:

```typescript ignore
// Example for npm (Node.js)
import type { PageList } from "@cosense/types/rest";
import type { Scrapbox } from "@cosense/types/userscript";

// Use the types in your Node.js application
const pageData: PageList = {
projectName: "my-project",
skip: 0,
limit: 50,
count: 10,
pages: [],
};
```
10 changes: 7 additions & 3 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"fix": "deno fmt && deno lint --fix && deno test --allow-read --doc --parallel --shuffle && deno publish --dry-run --allow-dirty",
"check": "deno fmt --check && deno lint && deno test --allow-read --doc --parallel --shuffle && deno publish --dry-run",
"coverage": "deno test --allow-read=./ --parallel --shuffle --coverage && deno coverage --html",
"doc": "deno doc --html rest.ts userscript.ts websocket.ts"
"doc": "deno doc --html rest.ts userscript.ts websocket.ts",
"npm:build": "deno run -A scripts/build_npm.ts",
"npm:check": "cd npm && npm publish --provenance --access=public --dry-run"
},
"imports": {
"@std/testing/types": "jsr:@std/testing@0/types"
"@std/testing/types": "jsr:@std/testing@0/types",
"@deno/dnt": "jsr:@deno/dnt@^0.42.3"
},
"exports": {
"./rest": "./rest.ts",
Expand All @@ -24,6 +27,7 @@
},
"exclude": [
"coverage/",
"docs/"
"docs/",
"npm/"
]
}
59 changes: 57 additions & 2 deletions deno.lock

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

60 changes: 60 additions & 0 deletions scripts/build_npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { build, emptyDir } from "@deno/dnt";

await emptyDir("./npm");

await build({
entryPoints: [
{
name: "./rest",
path: "./rest.ts",
},
{
name: "./userscript",
path: "./userscript.ts",
},
{
name: "./websocket",
path: "./websocket.ts",
},
],
outDir: "./npm",
shims: { deno: "dev" },
package: {
// package.json properties
name: "@cosense/types",
version: Deno.env.get("VERSION") ?? "0.0.0",
description: "Type definitions for cosense",
author: "scrapbox-jp",
license: "MIT",
repository: {
type: "git",
url: "git+https://github.com/scrapbox-jp/types.git",
},
homepage: "https://github.com/scrapbox-jp/types#readme",
bugs: {
url: "https://github.com/scrapbox-jp/types/issues",
},
keywords: [
"scrapbox",
"cosense",
"types",
"typescript",
"deno",
],
engines: {
node: ">=16.0.0",
},
},
// Don't run type checking during build to avoid Node.js compatibility issues
typeCheck: false,
declaration: "separate",
scriptModule: false,
compilerOptions: {
lib: ["ESNext", "DOM", "DOM.Iterable"],
target: "ES2023",
},
postBuild: async () => {
await Deno.copyFile("LICENSE", "npm/LICENSE");
await Deno.copyFile("README.md", "npm/README.md");
},
});