Skip to content

Commit 024fea9

Browse files
Merge pull request #80 from davidmyersdev/77-missing-zlib-imports
Make sure all modules under `buffer` are exported
2 parents b981b7a + c87b6b4 commit 024fea9

File tree

9 files changed

+170
-4
lines changed

9 files changed

+170
-4
lines changed

pnpm-lock.yaml

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shims/buffer/index.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
1-
// eslint-disable-next-line unicorn/prefer-node-protocol, n/no-deprecated-api
2-
import { Buffer, SlowBuffer, kMaxLength } from 'buffer'
1+
import {
2+
Blob,
3+
BlobOptions,
4+
Buffer,
5+
File,
6+
FileOptions,
7+
INSPECT_MAX_BYTES,
8+
// eslint-disable-next-line n/no-deprecated-api
9+
SlowBuffer,
10+
TranscodeEncoding,
11+
atob,
12+
btoa,
13+
constants,
14+
isAscii,
15+
isUtf8,
16+
kMaxLength,
17+
kStringMaxLength,
18+
resolveObjectURL,
19+
transcode,
20+
// eslint-disable-next-line unicorn/prefer-node-protocol
21+
} from 'buffer'
22+
23+
export {
24+
Blob,
25+
BlobOptions,
26+
Buffer,
27+
File,
28+
FileOptions,
29+
INSPECT_MAX_BYTES,
30+
SlowBuffer,
31+
TranscodeEncoding,
32+
atob,
33+
btoa,
34+
constants,
35+
isAscii,
36+
isUtf8,
37+
kMaxLength,
38+
kStringMaxLength,
39+
resolveObjectURL,
40+
transcode,
41+
}
342

4-
export { Buffer, SlowBuffer, kMaxLength }
543
export default Buffer
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>missing-zlib-imports</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script type="module" src="/src/index.ts"></script>
11+
</body>
12+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "missing-zlib-imports",
3+
"type": "module",
4+
"version": "0.0.0",
5+
"private": true,
6+
"scripts": {
7+
"build": "vite build",
8+
"dev": "vite",
9+
"test:e2e": "CI=true run-p test:e2e:*",
10+
"test:e2e:build": "VITE_COMMAND=build WEB_SERVER_COMMAND='vite build && vite preview --port 15176' WEB_SERVER_URL='http://localhost:15176' playwright test",
11+
"test:e2e:dev": "VITE_COMMAND=dev WEB_SERVER_COMMAND='vite dev --port 15175' WEB_SERVER_URL='http://localhost:15175' playwright test"
12+
},
13+
"dependencies": {
14+
"fast-zlib": "^2.0.1",
15+
"vite-plugin-node-polyfills": "workspace:*"
16+
},
17+
"devDependencies": {
18+
"vite": "^5.1.1"
19+
}
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
const webServerCommand = process.env.WEB_SERVER_COMMAND || 'pnpm dev'
4+
const webServerUrl = process.env.WEB_SERVER_URL || 'http://localhost:5173'
5+
6+
// https://playwright.dev/docs/test-configuration
7+
export default defineConfig({
8+
forbidOnly: !!process.env.CI,
9+
fullyParallel: true,
10+
projects: [
11+
{
12+
name: 'chromium',
13+
use: { ...devices['Desktop Chrome'] },
14+
},
15+
],
16+
reporter: 'html',
17+
retries: process.env.CI ? 2 : 0,
18+
testDir: './test/e2e',
19+
use: {
20+
baseURL: webServerUrl,
21+
trace: 'on-first-retry',
22+
},
23+
webServer: {
24+
command: webServerCommand,
25+
stdout: 'ignore',
26+
url: webServerUrl,
27+
},
28+
workers: process.env.CI ? 1 : undefined,
29+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import zlib from 'fast-zlib'
2+
3+
// eslint-disable-next-line no-console
4+
console.log(Object.keys(zlib))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test('sets the page title', async ({ page }) => {
4+
await page.goto('/')
5+
6+
await expect(page).toHaveTitle('missing-zlib-imports')
7+
})
8+
9+
test('logs the correct values', async ({ page }) => {
10+
const errors = []
11+
const logs = []
12+
13+
page.on('console', (message) => {
14+
logs.push(message.text())
15+
})
16+
17+
page.on('pageerror', (error) => {
18+
errors.push(error.message)
19+
})
20+
21+
await page.goto('/')
22+
23+
expect(errors).toEqual([])
24+
expect(logs).toContainEqual(
25+
'[Inflate, Deflate, InflateRaw, DeflateRaw, Gzip, Gunzip, Unzip, BrotliCompress, BrotliDecompress, constants, default]',
26+
)
27+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'vite'
2+
import { nodePolyfills } from 'vite-plugin-node-polyfills'
3+
4+
// https://vitejs.dev/config/
5+
export default defineConfig({
6+
optimizeDeps: {
7+
force: true,
8+
},
9+
plugins: [
10+
nodePolyfills(),
11+
],
12+
})

vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
include: ['**/*.test.ts'],
6+
},
7+
})

0 commit comments

Comments
 (0)