Skip to content

Commit 38b0952

Browse files
authored
chore: remove tar-stream (#52)
* chore: init * feat: replace tar-stream * chore: bump version * rebse
1 parent f0c07af commit 38b0952

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2232
-1821
lines changed
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
---
2+
name: 'Bug report 🐞'
3+
about: "If something isn't working as expected 🤔."
14
---
2-
name: 'Bug report 🐞'
3-
about: "If something isn't working as expected 🤔."
4-
---
5-
6-
# Bug report 🐞
7-
8-
## Version & Environment
9-
10-
## Expection
11-
12-
## Actual results (or Errors)
5+
6+
# Bug report 🐞
7+
8+
## Version & Environment
9+
10+
## Expection
11+
12+
## Actual results (or Errors)
+18-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
---
2+
name: 'Feature request 🚀'
3+
about: 'I have a suggestion!'
14
---
2-
name: 'Feature request 🚀'
3-
about: 'I have a suggestion!'
4-
---
5-
6-
# Feature request 🚀
7-
8-
### Expected:
9-
10-
- No breaking changes
11-
12-
### Examples:
13-
14-
```js
15-
16-
```
17-
18-
### Programme:
19-
20-
### Others:
5+
6+
# Feature request 🚀
7+
8+
### Expected:
9+
10+
- No breaking changes
11+
12+
### Examples:
13+
14+
```js
15+
```
16+
17+
### Programme:
18+
19+
### Others:

.github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
run: corepack enable
1212
- uses: actions/setup-node@v3
1313
with:
14-
node-version: 18
14+
node-version: 22
1515
- name: Install Dependices
1616
run: yarn install
1717

.node-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20.5.1
1+
v22.3.0

.vscode/settings.json

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
{
2-
"eslint.experimental.useFlatConfig": true
3-
}
1+
{
2+
"eslint.useFlatConfig": true,
3+
"editor.defaultFormatter": "dprint.dprint",
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll": "explicit"
6+
},
7+
"editor.formatOnSave": true,
8+
"[json]": {
9+
"editor.defaultFormatter": "dprint.dprint"
10+
},
11+
"[markdown]": {
12+
"editor.defaultFormatter": "dprint.dprint"
13+
}
14+
}

CHANGELOG.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
@Ibadichan
1616

17-
1817
## 1.0.0
1918

2019
# Background
@@ -52,20 +51,18 @@ This is a stable version.
5251
- Perf types.
5352
- Reduce unnecessary installation packages.
5453

55-
5654
## 0.10.5
5755

5856
# Background
5957

60-
6158
### Improves
6259

6360
- Reduce bundle size.
61+
6462
### Patches
6563

6664
- Fix can't work at monorepo.
6765

68-
6966
## 0.10.4
7067

7168
# Background
@@ -91,6 +88,7 @@ This is a stable version.
9188
## 0.10.1
9289

9390
# Background
91+
9492
### Patches
9593

9694
- Fix chunk with side effect can't work with `threshold` #33
@@ -107,7 +105,6 @@ This is a stable version.
107105

108106
@vHeemstra @nonzzz
109107

110-
111108
## 0.9.3
112109

113110
# Background

README.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
## Install
88

99
```bash
10-
1110
$ yarn add vite-plugin-compression2 -D
1211

1312
# or
1413

1514
$ npm install vite-plugin-compression2 -D
16-
1715
```
1816

1917
## Usage
@@ -33,16 +31,16 @@ export default defineConfig({
3331

3432
## Options
3533

36-
| params | type | default | description |
37-
| ---------------------- | --------------------------------------------- | ----------------- | -------------------------------------------------------------- |
38-
| `include` | `string \| RegExp \| Array<string \| RegExp>` | `/\.(html\|xml\|css\|json\|js\|mjs\|svg)$/` | Include all assets matching any of these conditions. |
39-
| `exclude` | `string \| RegExp \| Array<string \| RegExp>` | `-` | Exclude all assets matching any of these conditions. |
40-
| `threshold` | `number` | `0` | Only assets bigger than this size are processed (in bytes) |
41-
| `algorithm` | `string\| function` | `gzip` | The compression algorithm |
42-
| `compressionOptions` | `Record<string,any>` | `{}` | Compression options for `algorithm`(details see `zlib module`) |
43-
| `deleteOriginalAssets` | `boolean` | `false` | Whether to delete the original assets or not |
44-
| `skipIfLargerOrEqual` | `boolean` | `true` | Whether to skip the compression if the result is larger than or equal to the original file |
45-
| `filename` | `string` | `[path][base].gz` | The target asset filename |
34+
| params | type | default | description |
35+
| ---------------------- | --------------------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------ |
36+
| `include` | `string \| RegExp \| Array<string \| RegExp>` | `/\.(html\|xml\|css\|json\|js\|mjs\|svg)$/` | Include all assets matching any of these conditions. |
37+
| `exclude` | `string \| RegExp \| Array<string \| RegExp>` | `-` | Exclude all assets matching any of these conditions. |
38+
| `threshold` | `number` | `0` | Only assets bigger than this size are processed (in bytes) |
39+
| `algorithm` | `string\| function` | `gzip` | The compression algorithm |
40+
| `compressionOptions` | `Record<string,any>` | `{}` | Compression options for `algorithm`(details see `zlib module`) |
41+
| `deleteOriginalAssets` | `boolean` | `false` | Whether to delete the original assets or not |
42+
| `skipIfLargerOrEqual` | `boolean` | `true` | Whether to skip the compression if the result is larger than or equal to the original file |
43+
| `filename` | `string` | `[path][base].gz` | The target asset filename |
4644

4745
## Q & A
4846

@@ -74,7 +72,9 @@ export default defineComponent({
7472
```
7573

7674
> Can i create a tarball for all of assets after compressed?
75+
7776
- Yes, you can import `tarball` plugin from this package(>=1.0.0)
77+
7878
```js
7979
import { defineComponent } from 'vite'
8080
import { compression, tarball } from 'vite-plugin-compression2'
@@ -86,15 +86,13 @@ export default defineComponent({
8686
tarball()
8787
]
8888
})
89-
9089
```
9190

9291
### Others
9392

9493
- If you want to analysis your bundle assets. Maybe you can try [vite-bundle-analyzer](https://github.com/nonzzz/vite-bundle-analyzer)
9594

96-
- `tarball` option `dest` means to generate a tarball somewhere
97-
95+
- `tarball` option `dest` means to generate a tarball somewhere
9896

9997
### LICENSE
10098

__tests__/compress.spec.ts

+23-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import type { InputType } from 'zlib'
2-
import test from 'ava'
3-
import { compress, ensureAlgorithm } from '../src/compress'
4-
import type { Algorithm } from '../src/interface'
5-
6-
const mockCompress = async (userAlgorithm: Algorithm, buf: InputType) => {
7-
const { algorithm } = ensureAlgorithm(userAlgorithm)
8-
return compress(buf, algorithm, {})
9-
}
10-
11-
test('transer', async (t) => {
12-
const fake = new TextEncoder().encode('test')
13-
await mockCompress('gzip', fake)
14-
t.pass()
15-
})
16-
17-
test('compress with error', async (t) => {
18-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19-
const msg = await t.throwsAsync(mockCompress('gzip', 123 as any))
20-
t.is(
21-
msg.message,
22-
'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received type number (123)'
23-
)
24-
})
1+
import type { InputType } from 'zlib'
2+
import test from 'ava'
3+
import { compress, ensureAlgorithm } from '../src/compress'
4+
import type { Algorithm } from '../src/interface'
5+
6+
const mockCompress = async (userAlgorithm: Algorithm, buf: InputType) => {
7+
const { algorithm } = ensureAlgorithm(userAlgorithm)
8+
return compress(buf, algorithm, {})
9+
}
10+
11+
test('transer', async (t) => {
12+
const fake = new TextEncoder().encode('test')
13+
await mockCompress('gzip', fake)
14+
t.pass()
15+
})
16+
17+
test('compress with error', async (t) => {
18+
const msg = await t.throwsAsync(mockCompress('gzip', 123 as any))
19+
t.is(
20+
msg.message,
21+
'The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (123)'
22+
)
23+
})
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import cat from './cat.gif'
2-
3-
const app = document.querySelector('#app')
4-
5-
const imgEl = document.createElement('img')
6-
7-
imgEl.src = cat
8-
app.appendChild(imgEl)
9-
10-
console.log('hello world')
1+
import cat from './cat.gif'
2+
3+
const app = document.querySelector('#app')
4+
5+
const imgEl = document.createElement('img')
6+
7+
imgEl.src = cat
8+
app.appendChild(imgEl)
9+
10+
console.log('hello world')
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import './font.css'
2-
3-
console.log('optimization')
1+
import './font.css'
2+
3+
console.log('optimization')
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('nesting assets')
1+
console.log('nesting assets')
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('nest 1')
1+
console.log('nest 1')
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('nest 2')
1+
console.log('nest 2')
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('first')
1+
console.log('first')
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('main process')
1+
console.log('main process')
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('test public resource')
1+
console.log('test public resource')

0 commit comments

Comments
 (0)