Skip to content

Commit

Permalink
Inject our global shims properly
Browse files Browse the repository at this point in the history
  • Loading branch information
twk3 committed Dec 14, 2023
1 parent e71dda9 commit 38dd354
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: { project: [path.join(__dirname, './tsconfig.json')] },
reportUnusedDisableDirectives: true,
globals: {
globalThis: false,
},
rules: {
'prettier/prettier': 'warn',

Expand Down
2 changes: 2 additions & 0 deletions packages/desktop-client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ test-results
# production
build
build-stats
stats.json

# misc
.DS_Store
.env
npm-debug.log
.swc

*kcab.*
public/kcab
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@react-aria/utils": "^3.19.0",
"@react-stately/collections": "^3.10.0",
"@react-stately/list": "^3.9.1",
"@rollup/plugin-inject": "^5.0.5",
"@svgr/cli": "^8.0.1",
"@swc/core": "^1.3.82",
"@swc/helpers": "^0.5.1",
Expand Down
14 changes: 14 additions & 0 deletions packages/desktop-client/src/build-shims.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const global = globalThis || this || self;

const process = {
env: {
...import.meta.env,
NODE_ENV: import.meta.env.MODE,
PUBLIC_URL: import.meta.env.BASE_URL.slice(0, -1),
},
};

// eslint-disable-next-line import/no-unused-modules
export { process };
// eslint-disable-next-line import/no-unused-modules
export { global };
2 changes: 0 additions & 2 deletions packages/desktop-client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './init';

// This file will initialize the app if we are in a real browser
// environment (not electron)
import './browser-preload';
Expand Down
8 changes: 0 additions & 8 deletions packages/desktop-client/src/init.js

This file was deleted.

11 changes: 11 additions & 0 deletions packages/desktop-client/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from 'path';

import inject from '@rollup/plugin-inject';
import react from '@vitejs/plugin-react-swc';
import { visualizer } from 'rollup-plugin-visualizer';
/// <reference types="vitest" />
Expand Down Expand Up @@ -116,10 +117,20 @@ export default defineConfig(({ mode }) => {
disableGlobbing: false,
},
},
optimizeDeps: {
include: ['process'],
},
resolve: {
extensions: resolveExtensions,
},
plugins: [
{
...inject({
global: [path.resolve('src/build-shims.js'), 'global'],
process: [path.resolve('src/build-shims.js'), 'process'],
}),
enforce: 'post',
},
addWatchers(),
visualizer({ template: 'raw-data' }),
react({
Expand Down
42 changes: 41 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ __metadata:
"@react-aria/utils": "npm:^3.19.0"
"@react-stately/collections": "npm:^3.10.0"
"@react-stately/list": "npm:^3.9.1"
"@rollup/plugin-inject": "npm:^5.0.5"
"@svgr/cli": "npm:^8.0.1"
"@swc/core": "npm:^1.3.82"
"@swc/helpers": "npm:^0.5.1"
Expand Down Expand Up @@ -3212,6 +3213,38 @@ __metadata:
languageName: node
linkType: hard

"@rollup/plugin-inject@npm:^5.0.5":
version: 5.0.5
resolution: "@rollup/plugin-inject@npm:5.0.5"
dependencies:
"@rollup/pluginutils": "npm:^5.0.1"
estree-walker: "npm:^2.0.2"
magic-string: "npm:^0.30.3"
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
checksum: 1d0e68dff0a8785398a1b6a7dac0dc0a7f2ded22319c0b4c411053f34cbe237ca897d1fc97e5150fddbc3486480f21cbeeb69f0ae7f44ab1ae7307c164c7e704
languageName: node
linkType: hard

"@rollup/pluginutils@npm:^5.0.1":
version: 5.1.0
resolution: "@rollup/pluginutils@npm:5.1.0"
dependencies:
"@types/estree": "npm:^1.0.0"
estree-walker: "npm:^2.0.2"
picomatch: "npm:^2.3.1"
peerDependencies:
rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
checksum: abb15eaec5b36f159ec351b48578401bedcefdfa371d24a914cfdbb1e27d0ebfbf895299ec18ccc343d247e71f2502cba21202bc1362d7ef27d5ded699e5c2b2
languageName: node
linkType: hard

"@rollup/rollup-android-arm-eabi@npm:4.8.0":
version: 4.8.0
resolution: "@rollup/rollup-android-arm-eabi@npm:4.8.0"
Expand Down Expand Up @@ -8227,6 +8260,13 @@ __metadata:
languageName: node
linkType: hard

"estree-walker@npm:^2.0.2":
version: 2.0.2
resolution: "estree-walker@npm:2.0.2"
checksum: b02109c5d46bc2ed47de4990eef770f7457b1159a229f0999a09224d2b85ffeed2d7679cffcff90aeb4448e94b0168feb5265b209cdec29aad50a3d6e93d21e2
languageName: node
linkType: hard

"esutils@npm:^2.0.2":
version: 2.0.3
resolution: "esutils@npm:2.0.3"
Expand Down Expand Up @@ -11565,7 +11605,7 @@ __metadata:
languageName: node
linkType: hard

"magic-string@npm:^0.30.5":
"magic-string@npm:^0.30.3, magic-string@npm:^0.30.5":
version: 0.30.5
resolution: "magic-string@npm:0.30.5"
dependencies:
Expand Down

0 comments on commit 38dd354

Please sign in to comment.