Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remix v2 updates and other fixes #19

Merged
merged 44 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9e73856
upgrades
itsMapleLeaf Oct 14, 2023
e408a29
remove future flags
itsMapleLeaf Oct 14, 2023
83fcfed
add stdio
itsMapleLeaf Oct 14, 2023
27d7149
document initRemix
itsMapleLeaf Oct 14, 2023
19f81da
fix v2 type
itsMapleLeaf Oct 14, 2023
745bb1b
more updates for remix v2
itsMapleLeaf Oct 14, 2023
d963e59
fix asset files race condition
itsMapleLeaf Oct 14, 2023
63e1202
include build
itsMapleLeaf Oct 15, 2023
448268d
fix tests
itsMapleLeaf Oct 15, 2023
61724ae
update lint configs + fixes
itsMapleLeaf Oct 15, 2023
4da0e94
improve workflows
itsMapleLeaf Oct 15, 2023
e75e4be
oops
itsMapleLeaf Oct 15, 2023
76b1e74
i'm so good at this
itsMapleLeaf Oct 15, 2023
17fffd9
ok github
itsMapleLeaf Oct 15, 2023
4a6f5cf
ok github??
itsMapleLeaf Oct 15, 2023
ee7a926
okay we use an action not a workflow call, got it
itsMapleLeaf Oct 15, 2023
5f8149f
remove clean script, don't need it
itsMapleLeaf Oct 15, 2023
9a08824
i like this up here
itsMapleLeaf Oct 15, 2023
83153e6
more lint fix
itsMapleLeaf Oct 15, 2023
aef7f6e
index is fine
itsMapleLeaf Oct 15, 2023
2fdd4a2
new electron.server.ts setup
itsMapleLeaf Oct 15, 2023
4e73bd8
trim deps with knip
itsMapleLeaf Oct 15, 2023
0a18671
ci format test
itsMapleLeaf Oct 15, 2023
9a5bc38
remove unneeded usage of @remix-run/node
itsMapleLeaf Oct 15, 2023
7087171
put nodemon back
itsMapleLeaf Oct 15, 2023
98ac8ff
update remix.env.d.ts
itsMapleLeaf Oct 15, 2023
db6cb9f
trim peer deps
itsMapleLeaf Oct 15, 2023
53841e9
update readme
itsMapleLeaf Oct 15, 2023
00d30a1
ci: lint fix
itsMapleLeaf Oct 15, 2023
d89c87f
always run commit action
itsMapleLeaf Oct 15, 2023
331c86b
Merge branch 'upgrades-remix-v2' of https://github.com/itsMapleLeaf/r…
itsMapleLeaf Oct 15, 2023
3416c22
pass if commit fails
itsMapleLeaf Oct 15, 2023
bf48ef1
no longer need this (did we ever?)
itsMapleLeaf Oct 15, 2023
2cf4586
ignore dist in template
itsMapleLeaf Oct 15, 2023
5ea1ee8
copy template to a temp dir for testing
itsMapleLeaf Oct 15, 2023
874b050
fix executable path
itsMapleLeaf Oct 15, 2023
d08bcf1
more explicit command runs
itsMapleLeaf Oct 15, 2023
9465569
don't use file:
itsMapleLeaf Oct 15, 2023
5721616
use default reporter again
itsMapleLeaf Oct 15, 2023
056ba86
wait for electron app to close
itsMapleLeaf Oct 15, 2023
a090b37
add retry to folder removal
itsMapleLeaf Oct 15, 2023
89c5c03
remove logs, they're finally annoying
itsMapleLeaf Oct 15, 2023
a5b9805
only inherit stderr
itsMapleLeaf Oct 15, 2023
bc57d3b
add back test config for knip (?? lol)
itsMapleLeaf Oct 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .eslintrc.cjs

This file was deleted.

23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": ["./node_modules/@itsmapleleaf/configs/eslint.config.cjs"],
"plugins": ["prettier"],
"ignorePatterns": ["**/node_modules/**", "**/dist/**", "**/build/**"],
"parserOptions": {
"EXPERIMENTAL_useProjectService": true
},
"rules": {
"prettier/prettier": "error",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false
}
]
},
"settings": {
"react": {
"version": "detect"
}
}
}
18 changes: 18 additions & 0 deletions .github/actions/pnpm-install-cached/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: PNPM Install with Cache
description: Setup pnpm and install dependencies, caches node_modules
runs:
using: composite
steps:
- uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: "lts/*"
cache: "pnpm"
- shell: bash
run: pnpm install --frozen-lockfile
46 changes: 12 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: tests

on:
push:
Expand All @@ -13,49 +13,27 @@ concurrency:

jobs:
test:
name: Test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
name: test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v3
with:
# https://github.com/actions/setup-node#supported-version-syntax
node-version: "lts/*"
cache: "pnpm"
- name: Install
run: pnpm install
- name: Test
uses: coactions/setup-xvfb@v1
- uses: actions/checkout@v3
- uses: ./.github/actions/pnpm-install-cached
- uses: coactions/setup-xvfb@v1
with:
run: pnpm test

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v3
- uses: actions/checkout@v3
- uses: ./.github/actions/pnpm-install-cached
- run: pnpm run lint
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ always() }}
continue-on-error: true
with:
# https://github.com/actions/setup-node#supported-version-syntax
node-version: "lts/*"
cache: "pnpm"
- name: Install
run: pnpm install
- name: Lint
run: pnpm run lint
commit_message: "ci: lint fix"
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
shamefully-hoist = true
ignore-workspace-root-check = true
98 changes: 48 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,77 +14,75 @@ npx degit itsMapleLeaf/remix-electron/template my-desktop-app

### Adding to an existing Remix project

Install remix-electron and peer dependencies:
Install remix-electron and electron:

```bash
npm i remix-electron electron @remix-run/node @remix-run/server-runtime react react-dom
npm i remix-electron electron
```

Add a file at `desktop/main.js` to run the electron app. The `initRemix` function returns a url to load in the browser window.
Add a file at `desktop/index.js` to run the electron app. The `initRemix` function returns a url to load in the browser window.

```ts
// desktop/main.js
// desktop/index.js
const { initRemix } = require("remix-electron")
const { app, BrowserWindow } = require("electron")
const { join } = require("node:path")

/** @type {BrowserWindow | undefined} */
let win

app.on("ready", async () => {
try {
const url = await initRemix({
serverBuild: join(__dirname, "build"),
})

win = new BrowserWindow({ show: false })
await win.loadURL(url)
win.show()
} catch (error) {
console.error(error)
}
try {
const url = await initRemix({
serverBuild: join(__dirname, "../build/index.js"),
})

win = new BrowserWindow({ show: false })
await win.loadURL(url)
win.show()
} catch (error) {
console.error(error)
}
})
```

Update `serverBuildPath` in your Remix config:

```js
// remix.config.js
/**
* @type {import('@remix-run/dev/config').AppConfig}
*/
module.exports = {
serverBuildPath: "desktop/build/index.js",
// ...
}
```

Build the app with `npm run build`, then run `npx electron desktop/main.js` to start the app! 🚀
Build the app with `npm run build`, then run `npx electron desktop/index.js` to start the app! 🚀

## Using Electron APIs

Importing `"electron"` directly in route files results in Electron trying to get bundled and called in the browser / renderer process.

To circumvent this, create a `electron.server.ts` file, which re-exports from electron. The `.server` suffix tells Remix to only load it in the main process. You should use `.server` for any code that runs in the main process and uses node/electron APIs.

```js
```ts
// app/electron.server.ts
// @ts-nocheck
import electron from "electron"
export = electron
export default electron
```

```ts
// app/routes/_index.tsx
import electron from "~/electron.server"

export function loader() {
return {
userDataPath: electron.app.getPath("userData"),
}
}
```

Likewise, for any code running in the renderer process, e.g. using the [clipboard](https://www.electronjs.org/docs/latest/api/clipboard) module, you can use the `.client` suffix. Renderer process modules require `nodeIntegration`.

```js
// desktop/main.ts
```ts
// desktop/index.js
function createWindow() {
// ...
win = new BrowserWindow({
// ...
webPreferences: {
nodeIntegration: true,
},
})
// ...
win = new BrowserWindow({
// ...
webPreferences: {
nodeIntegration: true,
},
})
}
```

Expand All @@ -110,29 +108,29 @@ Options:
**app/context.ts**

```ts
import type * as remix from "@remix-run/server-runtime"
import type * as remix from "@remix-run/node"

// your context type
export type LoadContext = {
secret: string
secret: string
}

// a custom data function args type to use for loaders/actions
export type DataFunctionArgs = Omit<remix.DataFunctionArgs, "context"> & {
context: LoadContext
context: LoadContext
}
```

**desktop/main.js**

```ts
const url = await initRemix({
// ...
// ...

/** @type {import("~/context").LoadContext} */
getLoadContext: () => ({
secret: "123",
}),
/** @type {import("~/context").LoadContext} */
getLoadContext: () => ({
secret: "123",
}),
})
```

Expand All @@ -142,7 +140,7 @@ In a route file:
import type { DataFunctionArgs, LoadContext } from "~/context"

export async function loader({ context }: DataFunctionArgs) {
// do something with context
// do something with context
}
```

Expand Down
15 changes: 15 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "./node_modules/knip/schema.json",
"workspaces": {
".": {
"vitest": {
"config": ["vitest.config.mts"],
"entry": ["**/*.test.?(c|m)[jt]s?(x)"]
},
"ignoreDependencies": ["basic"]
},
"template": {
"ignoreDependencies": ["isbot", "nodemon"]
}
}
}
Loading