Skip to content

Commit

Permalink
Reorganize packages
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Feb 24, 2025
1 parent a805ed0 commit 0223b87
Show file tree
Hide file tree
Showing 35 changed files with 614 additions and 389 deletions.
45 changes: 28 additions & 17 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ jobs:
with:
check_name: "Test Results (Windows)"
files: .test-report.xml
- if: '!cancelled()'
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: .test-report.xml
- run: deno coverage --lcov .cov > .cov.lcov
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: dahlia/logtape
file: .cov.lcov
- run: deno task dnt
- run: bun run ./test_runner.js
working-directory: ${{ github.workspace }}/npm/
- run: deno task test-all:bun
- run: deno task check

publish:
Expand All @@ -64,33 +67,39 @@ jobs:
deno-version: v2.x
- if: github.ref_type == 'branch'
run: |
jq \
v="$(jq \
--raw-output \
--arg build "$GITHUB_RUN_NUMBER" \
--arg commit "${GITHUB_SHA::8}" \
'.version = .version + "-dev." + $build + "+" + $commit' \
deno.json > deno.json.tmp
mv deno.json.tmp deno.json
'.version + "-dev." + $build + "+" + $commit' \
logtape/deno.json)"
deno run --allow-read --allow-write scripts/update_versions.ts "$v"
deno task check:versions
- if: github.ref_type == 'tag'
run: |
set -ex
[[ "$(jq -r .version deno.json)" = "$GITHUB_REF_NAME" ]]
- run: 'deno task dnt "$(jq -r .version deno.json)"'
[[ "$(jq -r .version logtape/deno.json)" = "$GITHUB_REF_NAME" ]]
deno task check:versions
- run: deno task dnt-all
- if: github.event_name == 'push'
run: |
set -ex
npm config set //registry.npmjs.org/:_authToken "$NPM_AUTH_TOKEN"
if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
npm publish --provenance --access public
else
npm publish --provenance --access public --tag dev
fi
for npm in */npm/; do
pushd "$npm"
if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
npm publish --provenance --access public
else
npm publish --provenance --access public --tag dev
fi
popd
done
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
working-directory: ${{ github.workspace }}/npm/
- if: github.event_name == 'pull_request'
run: deno publish --dry-run --allow-dirty
run: deno task publish --dry-run --allow-dirty
- if: github.event_name == 'push'
run: deno publish --allow-dirty
run: deno task publish --allow-dirty

publish-docs:
if: github.event_name == 'push'
Expand All @@ -113,12 +122,14 @@ jobs:
bun install
if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
bun add -D "@logtape/logtape@$GITHUB_REF_NAME"
bun add -D "@logtape/file@$GITHUB_REF_NAME"
bun add -D @logtape/otel@latest
EXTRA_NAV_TEXT=Unstable \
EXTRA_NAV_LINK="$UNSTABLE_DOCS_URL" \
bun run build
else
bun add -D @logtape/logtape@dev
bun add -D @logtape/file@dev
bun add -D @logtape/otel@dev
EXTRA_NAV_TEXT=Stable \
EXTRA_NAV_LINK="$STABLE_DOCS_URL" \
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.dnt-import-map.json
coverage/
npm/
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
"source.sortImports": "always"
}
},
"[json]": {
Expand All @@ -28,13 +28,14 @@
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
"source.sortImports": "always"
}
},
"cSpell.words": [
"Codecov",
"consolemock",
"deno",
"filesink",
"hongminhee",
"logtape",
"runtimes",
Expand Down
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Version 0.9.0

To be released.

- Moved file sinks and rotating file sinks to separate packages.
[[#19], [#27], [#28]]

- Moved `getFileSink()` function to `@logtape/file` package.
- Moved `FileSinkOptions` interface to `@logtape/file` package.
- Moved `getRotatingFileSink()` function to `@logtape/file` package.
- Moved `RotatingFileSinkOptions` interface to `@logtape/file` package.

- Added synchronous versions of configuration functions.
[[#12], [#29] by Murph Murphy]

Expand All @@ -18,6 +26,9 @@ To be released.
- Added `ConsoleSinkOptions.levelMap` option.

[#12]: https://github.com/dahlia/logtape/issues/12
[#19]: https://github.com/dahlia/logtape/issues/19
[#27]: https://github.com/dahlia/logtape/issues/27
[#28]: https://github.com/dahlia/logtape/issues/28
[#29]: https://github.com/dahlia/logtape/pull/29


Expand Down
1 change: 1 addition & 0 deletions README.md
62 changes: 62 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"workspace": [
"./logtape",
"./file"
],
"imports": {
"@david/which-runtime": "jsr:@david/which-runtime@^0.2.1",
"@deno/dnt": "jsr:@deno/dnt@^0.41.1",
"@std/assert": "jsr:@std/assert@^0.222.1",
"@std/async": "jsr:@std/async@^0.222.1",
"@std/fs": "jsr:@std/fs@^0.223.0",
"@std/path": "jsr:@std/path@^1.0.2",
"@std/testing": "jsr:@std/testing@^0.222.1",
"consolemock": "npm:consolemock@^1.1.0"
},
"unstable": [
"fs"
],
"lock": false,
"exclude": [
".github/",
"docs/"
],
"tasks": {
"check": {
"command": "deno check **/*.ts && deno lint && deno fmt --check",
"dependencies": [
"check:versions"
]
},
"check:versions": "deno run --allow-read scripts/check_versions.ts",
"test": "deno test --allow-read --allow-write",
"coverage": "rm -rf coverage && deno task test --coverage && deno coverage --html coverage",
"dnt-all": "deno task --recursive dnt",
"test-all:bun": "deno task --recursive test:bun",
"test-all": {
"dependencies": [
"test",
"test-all:bun"
]
},
"publish": {
"command": "deno publish",
"dependencies": [
"check",
"test"
]
},
"hooks:install": "deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks",
"hooks:pre-commit": {
"dependencies": [
"check"
]
},
"hooks:pre-push": {
"dependencies": [
"check",
"test"
]
}
}
}
1 change: 1 addition & 0 deletions docs/.jsr-cache.file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"package":"@logtape/file","version":"0.9.0-dev.1","index":{"getFileSink()":{"kind":[{"char":"f","kind":"Function","title":"Function"}],"name":"getFileSink","file":".","doc":"Get a file sink.\n\nNote that this function is unavailable in the browser.\n","url":"https://jsr.io/@logtape/[email protected]/doc/~/getFileSink","deprecated":false,"label":"getFileSink()"},"getRotatingFileSink()":{"kind":[{"char":"f","kind":"Function","title":"Function"}],"name":"getRotatingFileSink","file":".","doc":"Get a rotating file sink.\n\nThis sink writes log records to a file, and rotates the file when it reaches\nthe `maxSize`. The rotated files are named with the original file name\nfollowed by a dot and a number, starting from 1. The number is incremented\nfor each rotation, and the maximum number of files to keep is `maxFiles`.\n\nNote that this function is unavailable in the browser.\n","url":"https://jsr.io/@logtape/[email protected]/doc/~/getRotatingFileSink","deprecated":false,"label":"getRotatingFileSink()"}}}
13 changes: 10 additions & 3 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
import { jsrRef } from "markdown-it-jsr-ref";
import { defineConfig } from "vitepress";
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";

const jsrRefVersion =
process.env.CI === "true" && process.env.GITHUB_REF_TYPE === "tag"
? "stable"
: "unstable";

const jsrRefPlugin = await jsrRef({
const jsrRef_logtape = await jsrRef({
package: "@logtape/logtape",
version: jsrRefVersion,
cachePath: ".jsr-cache.json",
});

const jsrRef_file = await jsrRef({
package: "@logtape/file",
version: jsrRefVersion,
cachePath: ".jsr-cache.file.json",
});

let extraNav: { text: string; link: string }[] = [];
if (process.env.EXTRA_NAV_TEXT && process.env.EXTRA_NAV_LINK) {
extraNav = [
Expand Down Expand Up @@ -116,7 +122,8 @@ export default defineConfig({
}),
],
config(md) {
md.use(jsrRefPlugin);
md.use(jsrRef_logtape);
md.use(jsrRef_file);
},
},

Expand Down
Binary file modified docs/bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion docs/manual/categories.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ hierarchy.
Here's an example of setting log levels for different categories:

~~~~ typescript{9-10} twoslash
import { configure, getConsoleSink, getFileSink } from "@logtape/logtape";
import { getFileSink } from "@logtape/file";
import { configure, getConsoleSink } from "@logtape/logtape";
await configure({
sinks: {
Expand Down
9 changes: 6 additions & 3 deletions docs/manual/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ sinks for different purposes:

~~~~ typescript twoslash
// @noErrors: 2345
import { configure, getConsoleSink, getFileSink } from "@logtape/logtape";
import { getFileSink } from "@logtape/file";
import { configure, getConsoleSink } from "@logtape/logtape";

await configure({
sinks: {
Expand Down Expand Up @@ -153,7 +154,8 @@ Here's how you might do that:
::: code-group

~~~~ typescript{1,6,11-12} twoslash [Deno]
import { configure, getConsoleSink, getFileSink } from "@logtape/logtape";
import { getFileSink } from "@logtape/file";
import { configure, getConsoleSink } from "@logtape/logtape";
// ---cut-before---
const isDevelopment = Deno.env.get("DENO_DEPLOYMENT_ID") == null;
Expand All @@ -175,7 +177,8 @@ await configure({
~~~~ typescript{1,6,11-12} twoslash [Node.js]
import "@types/node";
import process from "node:process";
import { configure, getConsoleSink, getFileSink } from "@logtape/logtape";
import { getFileSink } from "@logtape/file";
import { configure, getConsoleSink } from "@logtape/logtape";
// ---cut-before---
const isDevelopment = process.env.NODE_ENV === "development";
Expand Down
3 changes: 2 additions & 1 deletion docs/manual/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ above:

~~~~ typescript twoslash
// @noErrors: 2307
import { configure, getConsoleSink, getFileSink } from "@logtape/logtape";
import { getFileSink } from "@logtape/file";
import { configure, getConsoleSink } from "@logtape/logtape";
import { Database } from "my-awesome-lib";

await configure({
Expand Down
63 changes: 58 additions & 5 deletions docs/manual/sinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,38 @@ File sink
> [!NOTE]
> File sink is unavailable in the browser environment.
LogTape provides a file sink as well. Here's an example of a file sink that
writes log messages to a file:
LogTape provides a file sink through a separate package *@logtape/file*:

::: code-group

~~~~ sh [Deno]
deno add jsr:@logtape/file
~~~~

~~~~ sh [npm]
npm add @logtape/file
~~~~

~~~~ sh [pnpm]
pnpm add @logtape/file
~~~~

~~~~ sh [Yarn]
yarn add @logtape/file
~~~~

~~~~ sh [Bun]
bun add @logtape/file
~~~~

:::

Here's an example of a file sink that writes log messages to a file:

~~~~ typescript twoslash
// @noErrors: 2345
import { configure, getFileSink } from "@logtape/logtape";
import { getFileSink } from "@logtape/file";
import { configure } from "@logtape/logtape";

await configure({
sinks: {
Expand Down Expand Up @@ -181,12 +207,39 @@ the ability to *rotate* the log file when it reaches a certain size. This means:
This rotation process helps prevent any single log file from growing too large,
which can cause issues with file handling, log analysis, and storage management.

To use the rotating file sink, you can use the `getRotatingFileSink()` function.
To use the rotating file sink, you can use the `getRotatingFileSink()` function,
which is provided by the *@logtape/file* package:

::: code-group

~~~~ sh [Deno]
deno add jsr:@logtape/file
~~~~

~~~~ sh [npm]
npm add @logtape/file
~~~~

~~~~ sh [pnpm]
pnpm add @logtape/file
~~~~

~~~~ sh [Yarn]
yarn add @logtape/file
~~~~

~~~~ sh [Bun]
bun add @logtape/file
~~~~

:::

Here's an example of a rotating file sink that writes log messages to a file:

~~~~ typescript twoslash
// @noErrors: 2345
import { configure, getRotatingFileSink } from "@logtape/logtape";
import { getRotatingFileSink } from "@logtape/file";
import { configure } from "@logtape/logtape";

await configure({
sinks: {
Expand Down
3 changes: 2 additions & 1 deletion docs/manual/struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ providing a [text formatter](./formatters.md) to a file sink:

~~~~ typescript twoslash
// @noErrors: 2345
import { configure, getFileSink } from "@logtape/logtape";
import { getFileSink } from "@logtape/file";
import { configure } from "@logtape/logtape";

await configure({
sinks: {
Expand Down
Loading

0 comments on commit 0223b87

Please sign in to comment.