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
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish

on:
push:
branches: [main]
paths:
- package.json

jobs:
check-version:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check.outputs.changed }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Check if version changed
id: check
run: |
PREV=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version" 2>/dev/null || echo "none")
CURR=$(node -p "require('./package.json').version")
echo "Previous: $PREV, Current: $CURR"
if [ "$PREV" != "$CURR" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

publish:
environment: npm
needs: check-version
if: needs.check-version.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Update npm to latest version for OIDC support
run: npm install -g npm@latest
- run: npm ci
- run: npm publish --provenance --access public
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION=$(node -p "require('./package.json').version")
gh release create "v$VERSION" --generate-notes --title "v$VERSION"
2 changes: 1 addition & 1 deletion dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ export declare class BufferFormat<EncoderType extends EncoderDefinition, HeaderT
* performance, and to minimize memory allocation and fragmentation.
*/
encodeInto<TDecodedType extends DecodedType<EncoderType>>(data: TDecodedType, bytes: Uint8Array): Uint8Array;
/**
* Encode an object into an existing byte array, without allocating a view.
*
* @returns the number of bytes written to the start of `bytes`
* @throws if fails to encode value to schema, or `bytes` is too small
*/
encodeIntoLength<TDecodedType extends DecodedType<EncoderType>>(data: TDecodedType, bytes: Uint8Array): number;
/**
* Encode an object to bytes.
*
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tinybuf",
"version": "1.8.8",
"version": "1.9.0",
"author": "Reece Como <reece.como@gmail.com>",
"authors": [
"Reece Como <reece.como@gmail.com>",
Expand All @@ -11,7 +11,9 @@
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "./dist/index.d.ts",
"files": ["./dist"],
"files": [
"./dist"
],
"sideEffects": false,
"scripts": {
"build": "rimraf dist && rollup -c --bundleConfigAsCjs && rimraf dist/core && ./node_modules/.bin/dts-bundle-generator -o dist/index.d.ts src/index.ts --no-banner --export-referenced-types",
Expand Down Expand Up @@ -63,4 +65,4 @@
"directories": {
"test": "src/__tests__"
}
}
}
4 changes: 2 additions & 2 deletions src/__tests__/BufferFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe("BufferFormat", () => {
});

const objB2 = obj.b;
expect(objB1).not.toBe(objB2); // shorter arrays trigger new array instance
expect(objB1).toBe(objB2); // shorter arrays are re-used
expect(objC1D1).toBe(obj.c![0]); // but underlying object instances ARE recycled

MyBufferFormat.decode(input4WithLongerArrs, obj);
Expand All @@ -124,7 +124,7 @@ describe("BufferFormat", () => {
],
});

expect(objB2).not.toBe(obj.b); // longer arrays trigger new array instance also
expect(objB2).toBe(obj.b); // longer arrays are re-used
expect(objC1D1).toBe(obj.c![0]); // underlying object instances ARE recycled
expect(objC1D2).not.toBe(obj.c![1]); // ...but only when they existed in the previous instance
});
Expand Down
Loading
Loading