-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: complete size padding * chore: test * chore: workflow
- Loading branch information
Showing
8 changed files
with
188 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: publish | ||
on: | ||
push: | ||
tags: ['v*'] | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: Install Dependices | ||
run: make | ||
- name: Pack and Publish | ||
run: | | ||
make build | ||
npm publish --provenance --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Writable } from 'stream' | ||
import { describe, expect, it } from 'vitest' | ||
import { createExtract, createPack } from '../src' | ||
|
||
describe('Stream', () => { | ||
describe('Uniform Standard Type Archive', () => { | ||
const assets: Record<string, string> = { | ||
'assets/a.mjs': 'const a = 1;', | ||
'assets/b.mjs': 'import "./c.css"; import { a } from "./a.mjs"; console.log(a);', | ||
'assets/c.css': 'body { background: red; }' | ||
} | ||
describe('Pack', () => { | ||
it('Normal', async () => { | ||
const pack = createPack() | ||
|
||
let expectByteLen = 0 | ||
let actualByteLen = 0 | ||
|
||
for (const [path, content] of Object.entries(assets)) { | ||
pack.add(new TextEncoder().encode(content), { | ||
filename: path | ||
}) | ||
expectByteLen += content.length | ||
expectByteLen += 512 - (content.length % 512) | ||
expectByteLen += 512 | ||
} | ||
expectByteLen += 1024 | ||
pack.done() | ||
const writer = new Writable({ | ||
write(chunk, _, callback) { | ||
actualByteLen += chunk.length | ||
callback() | ||
} | ||
}) | ||
pack.receiver.pipe(writer) | ||
await new Promise((resolve) => writer.on('finish', resolve)) | ||
expect(actualByteLen).toBe(expectByteLen) | ||
}) | ||
}) | ||
describe('Extract', () => { | ||
it('Normal', async () => { | ||
const pack = createPack() | ||
const extract = createExtract() | ||
const textDecode = new TextDecoder() | ||
for (const [path, content] of Object.entries(assets)) { | ||
pack.add(new TextEncoder().encode(content), { | ||
filename: path | ||
}) | ||
} | ||
|
||
extract.on('entry', (head, file) => { | ||
const content = assets[head.name] | ||
expect(content).toBe(textDecode.decode(file)) | ||
expect(head.size).toBe(content.length) | ||
}) | ||
pack.receiver.pipe(extract.receiver) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters