Skip to content

Commit

Permalink
feat: add publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Jul 18, 2024
1 parent 4739928 commit 5fc77dc
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 16 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/publish.yaml
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 }}
2 changes: 1 addition & 1 deletion __tests__/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterAll, expect, test } from 'vitest'

import type { Pretty, ViteCompressionPluginConfigAlgorithm } from '../src/interface'
import { compression } from '../src'
import { readAll } from '../src/utils'
import { readAll } from '../src/shared'
import type { Algorithm } from '../src'

const getId = () => Math.random().toString(32).slice(2, 10)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fsp from 'fs/promises'
import util from 'util'
import type { ZlibOptions } from 'zlib'
import { afterAll, expect, test } from 'vitest'
import { len, readAll } from '../src/utils'
import { len, readAll } from '../src/shared'
import { type Algorithm, type ViteCompressionPluginConfig, compression } from '../src'

const getId = () => Math.random().toString(32).slice(2, 10)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/tarball.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fsp from 'fs/promises'
import { build } from 'vite'
import { afterAll, expect, test } from 'vitest'
import tar from 'tar-stream'
import { readAll } from '../src/utils'
import { readAll } from '../src/shared'
import type { ViteCompressionPluginConfig, ViteTarballPluginOptions } from '../src'
import { compression, tarball } from '../src'

Expand Down
2 changes: 1 addition & 1 deletion src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path'
import type { BrotliOptions, InputType, ZlibOptions } from 'zlib'
import { Pack } from './tar'
import type { Algorithm, AlgorithmFunction, UserCompressionOptions } from './interface'
import { slash, stringToBytes } from './utils'
import { slash, stringToBytes } from './shared'

export function ensureAlgorithm(userAlgorithm: Algorithm) {
const algorithm = userAlgorithm in zlib ? userAlgorithm : 'gzip'
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os from 'os'
import path from 'path'
import { createFilter } from '@rollup/pluginutils'
import type { Plugin, ResolvedConfig } from 'vite'
import { len, readAll, replaceFileName, slash, stringToBytes } from './utils'
import { len, readAll, replaceFileName, slash, stringToBytes } from './shared'
import { compress, createTarBall, defaultCompressionOptions, ensureAlgorithm } from './compress'
import { createConcurrentQueue } from './task'
import type {
Expand Down
11 changes: 2 additions & 9 deletions src/utils.ts → src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fsp from 'fs/promises'
import path from 'path'
import { u8 } from './tar'

export function len<T extends ArrayLike<unknown>>(source: T) {
return source.length
Expand Down Expand Up @@ -40,14 +41,6 @@ export async function readAll(entry: string) {
return result
}

let _encoder: TextEncoder

export function stringToBytes(b: string | Uint8Array) {
if (typeof b === 'string') {
if (!_encoder) {
_encoder = new TextEncoder()
}
return _encoder.encode(b)
}
return b
return typeof b === 'string' ? u8.encode(b) : b
}
2 changes: 1 addition & 1 deletion src/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// No gnu or old gnu or v7 and oters etc.
// POSIX.1-1988
// https://www.gnu.org/software/tar/manual/tar.html#Blocking-Factor
import { len } from './utils'
import { len } from './shared'

export interface Header {
name: Uint8Array[100]
Expand Down
2 changes: 1 addition & 1 deletion src/task.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { len } from './utils'
import { len } from './shared'

class Queue {
maxConcurrent: number
Expand Down

0 comments on commit 5fc77dc

Please sign in to comment.