Skip to content

Commit b02e6c9

Browse files
Merge pull request #63 from davidmyersdev/47-unexpected-string
Improve global shims
2 parents f0aecbe + d01862f commit b02e6c9

File tree

14 files changed

+147
-58
lines changed

14 files changed

+147
-58
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- uses: ./.github/actions/install-dependencies
2929
- run: pnpm build:core
3030
- run: pnpm build:shims
31-
- run: pnpm build:shims:banner
31+
- run: pnpm build:banner
3232
- run: pnpm test
3333
typecheck:
3434
needs:
@@ -39,5 +39,5 @@ jobs:
3939
- uses: ./.github/actions/install-dependencies
4040
- run: pnpm build:core
4141
- run: pnpm build:shims
42-
- run: pnpm build:shims:banner
42+
- run: pnpm build:banner
4343
- run: pnpm typecheck

package.json

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,19 @@
3333
},
3434
"./shims/banner": {
3535
"require": "./shims/banner/dist/index.cjs",
36-
"import": "./shims/banner/dist/index.cjs"
36+
"import": "./shims/banner/dist/index.js"
37+
},
38+
"./shims/buffer": {
39+
"require": "./shims/buffer/dist/index.cjs",
40+
"import": "./shims/buffer/dist/index.js"
41+
},
42+
"./shims/global": {
43+
"require": "./shims/global/dist/index.cjs",
44+
"import": "./shims/global/dist/index.js"
45+
},
46+
"./shims/process": {
47+
"require": "./shims/process/dist/index.cjs",
48+
"import": "./shims/process/dist/index.js"
3749
}
3850
},
3951
"main": "./dist/index.cjs",
@@ -44,10 +56,13 @@
4456
"shims"
4557
],
4658
"scripts": {
47-
"build": "run-s build:core build:shims build:shims:banner build:types",
59+
"build": "run-s build:core build:shims build:banner build:types",
60+
"build:banner": "vite-node ./shims/banner/build.ts",
4861
"build:core": "vite build",
49-
"build:shims": "vite build ./shims",
50-
"build:shims:banner": "vite-node ./shims/banner/build.ts",
62+
"build:shims": "run-p build:shims:*",
63+
"build:shims:buffer": "vite build -c ./shims/vite.config.ts ./shims/buffer",
64+
"build:shims:global": "vite build -c ./shims/vite.config.ts ./shims/global",
65+
"build:shims:process": "vite build -c ./shims/vite.config.ts ./shims/process",
5166
"build:types": "run-s typecheck",
5267
"lint": "eslint .",
5368
"lint:fix": "eslint --fix .",
@@ -70,16 +85,16 @@
7085
},
7186
"dependencies": {
7287
"@rollup/plugin-inject": "^5.0.5",
73-
"buffer-polyfill": "npm:buffer@^6.0.3",
74-
"node-stdlib-browser": "^1.2.0",
75-
"process": "^0.11.10"
88+
"node-stdlib-browser": "^1.2.0"
7689
},
7790
"devDependencies": {
7891
"@types/node": "^18.18.8",
92+
"buffer": "6.0.3",
7993
"esbuild": "^0.19.8",
8094
"eslint": "^8.54.0",
8195
"eslint-config-artisan": "^0.2.1",
8296
"npm-run-all": "^4.1.5",
97+
"process": "^0.11.10",
8398
"rollup": "^4.6.0",
8499
"typescript": "4.8.3",
85100
"vite": "^5.0.2",
@@ -92,6 +107,9 @@
92107
"access": "public"
93108
},
94109
"pnpm": {
110+
"overrides": {
111+
"buffer": "6.0.3"
112+
},
95113
"patchedDependencies": {
96114
97115
}

pnpm-lock.yaml

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

shims/banner/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ await build({
88
bundle: true,
99
entryPoints: [join(thisDir, './index.cjs')],
1010
format: 'iife',
11-
inject: [join(thisDir, '..')],
11+
inject: [
12+
join(thisDir, '../buffer'),
13+
join(thisDir, '../global'),
14+
join(thisDir, '../process'),
15+
],
1216
outdir: join(thisDir, './dist'),
1317
outExtension: { '.js': '.cjs' },
1418
})

shims/banner/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "module",
3+
"sideEffects": false,
4+
"main": "./dist/index.cjs"
5+
}

shims/buffer/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line unicorn/prefer-node-protocol
2+
import { Buffer } from 'buffer'
3+
4+
export { Buffer }
5+
export default Buffer

shims/buffer/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "module",
3+
"sideEffects": false,
4+
"exports": {
5+
".": {
6+
"require": "./dist/index.cjs",
7+
"import": "./dist/index.js"
8+
}
9+
},
10+
"main": "./dist/index.cjs",
11+
"module": "./dist/index.js"
12+
}

shims/global/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line @typescript-eslint/no-invalid-this
2+
const global = globalThis || this || self
3+
4+
export { global }
5+
export default global

shims/global/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "module",
3+
"sideEffects": false,
4+
"exports": {
5+
".": {
6+
"require": "./dist/index.cjs",
7+
"import": "./dist/index.js"
8+
}
9+
},
10+
"main": "./dist/index.cjs",
11+
"module": "./dist/index.js"
12+
}

shims/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
".": {
66
"require": "./dist/index.cjs",
77
"import": "./dist/index.js"
8+
},
9+
"./buffer": {
10+
"require": "./buffer/dist/index.cjs",
11+
"import": "./buffer/dist/index.js"
12+
},
13+
"./global": {
14+
"require": "./global/dist/index.cjs",
15+
"import": "./global/dist/index.js"
16+
},
17+
"./process": {
18+
"require": "./process/dist/index.cjs",
19+
"import": "./process/dist/index.js"
820
}
921
},
1022
"main": "./dist/index.cjs",

0 commit comments

Comments
 (0)