Skip to content

Commit 9cd5134

Browse files
committed
❌ Removing the tsup package, adding the bundle size to the README
1 parent 0276fac commit 9cd5134

5 files changed

Lines changed: 71 additions & 207 deletions

File tree

.github/workflows/ci.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
test:
1212
name: Test and Build
1313
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
1416

1517
steps:
1618
- name: Checkout repository
@@ -39,7 +41,10 @@ jobs:
3941
run: bun run test:coverage
4042

4143
- name: Build Project
42-
run: bun run build
44+
id: bundle_size
45+
run: |
46+
STATS=$(bun run build | tail -n 1)
47+
echo "stats=$STATS" >> $GITHUB_OUTPUT
4348
4449
- name: Upload Coverage Results
4550
if: always()
@@ -48,3 +53,32 @@ jobs:
4853
name: coverage-report
4954
path: coverage/
5055
retention-days: 7
56+
57+
- name: Update README with Bundle Size
58+
run: |
59+
STATS='${{ steps.bundle_size.outputs.stats }}'
60+
UNCOMPRESSED=$(echo $STATS | jq -r '.uncompressedSize')
61+
COMPRESSED=$(echo $STATS | jq -r '.compressedSize')
62+
63+
# Construindo o novo conteúdo sem quebra de linha
64+
printf -- "<!-- BUNDLE_SIZE_START -->\`%s\` (Minified) / \`%s\` (Gzipped)<!-- BUNDLE_SIZE_END -->" "$UNCOMPRESSED" "$COMPRESSED" > bundle_info.txt
65+
66+
# Usando perl para substituição multiline
67+
perl -0777 -i -pe 'BEGIN{undef $/; open(F, "<bundle_info.txt"); $n=<F>; close(F)} s/<!-- BUNDLE_SIZE_START -->.*?<!-- BUNDLE_SIZE_END -->/$n/gs' README.md
68+
rm bundle_info.txt
69+
70+
- name: Commit and Push changes
71+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
72+
run: |
73+
git config --global user.name "github-actions[bot]"
74+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
75+
git add README.md
76+
if ! git diff --staged --quiet; then
77+
git log -1 --pretty=%B > .git/commit_message
78+
if ! grep -q "\[skip ci\]" .git/commit_message; then
79+
echo "" >> .git/commit_message
80+
echo "[skip ci]" >> .git/commit_message
81+
fi
82+
git commit --amend -F .git/commit_message
83+
git push --force
84+
fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
> High-performance typed URL parser with automatic type casting and AST-based analysis.
2121
22-
url-ast is a specialized module for analyzing and manipulating URLs using an Abstract Syntax Tree (AST) approach. It provides deep and structured URL analysis, transforming URLs into interconnected nodes that represent each component (protocol, hostname, parameters, etc.), facilitating manipulation and validation with full TypeScript support and automatic type casting.
22+
url-ast is a specialized module for analyzing and manipulating URLs using an Abstract Syntax Tree (AST) approach. It provides deep and structured URL analysis, transforming URLs into interconnected nodes that represent each component (protocol, hostname, parameters, etc.), facilitating manipulation and validation with full TypeScript support and automatic type casting, with a footprint of <!-- BUNDLE_SIZE_START --> <!-- BUNDLE_SIZE_END -->.
2323

2424
📖 **[Full Documentation](https://asterflow.github.io/url-ast)**
2525

build.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { build, gzipSync } from 'bun'
12
import { generateDtsBundle } from 'dts-bundle-generator'
2-
import { existsSync } from 'node:fs'
3-
import { mkdir, rm, writeFile } from 'node:fs/promises'
3+
import { existsSync, } from 'node:fs'
4+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
45
import { dirname, join } from 'node:path'
5-
import { build } from 'tsup'
66

77
async function cleanDistDirectory(directoryPath: string): Promise<void> {
88
if (existsSync(directoryPath)) {
@@ -38,28 +38,38 @@ async function generateTypes(sourceFilePath: string, outputDirectory: string): P
3838
await cleanDistDirectory('dist')
3939

4040
await build({
41-
entry: ['src/index.ts'],
42-
bundle: true,
41+
entrypoints: ['src/index.ts'],
42+
outdir: 'dist/cjs',
43+
format: 'cjs',
44+
target: 'node',
4345
minify: true,
44-
format: ['cjs'],
45-
outDir: 'dist/cjs',
46-
target: 'es6',
47-
sourcemap: true,
48-
silent: true,
46+
sourcemap: 'linked',
4947
})
5048

5149
await build({
52-
entry: ['src/index.ts'],
53-
bundle: true,
50+
entrypoints: ['src/index.ts'],
51+
outdir: 'dist/mjs',
52+
format: 'esm',
53+
target: 'node',
5454
minify: true,
55-
format: ['esm'],
56-
outDir: 'dist/mjs',
57-
target: 'es2024',
58-
sourcemap: true,
59-
silent: true,
55+
sourcemap: 'linked',
6056
})
6157

6258
await writePackageJson('dist/cjs', 'commonjs')
6359
await writePackageJson('dist/mjs', 'module')
60+
6461
await generateTypes(join(currentWorkingDirectory, 'src/index.ts'), join(currentWorkingDirectory, 'dist/types'))
65-
})()
62+
63+
const esmFilePath = join(currentWorkingDirectory, 'dist/mjs/index.js')
64+
if (existsSync(esmFilePath)) {
65+
const fileBuffer = await readFile(esmFilePath)
66+
const gzippedBytes = gzipSync(fileBuffer)
67+
68+
const toKB = (bytesSize: number) => (bytesSize / 1024).toFixed(2) + ' KB'
69+
70+
console.log(JSON.stringify({
71+
uncompressedSize: toKB(fileBuffer.length),
72+
compressedSize: toKB(gzippedBytes.length)
73+
}))
74+
}
75+
})()

0 commit comments

Comments
 (0)