Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit e605718

Browse files
committed
lint fixes
1 parent 02aeb11 commit e605718

File tree

10 files changed

+63
-54
lines changed

10 files changed

+63
-54
lines changed

.eslintrc.cjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
extends: [require.resolve("@itsmapleleaf/configs/eslint")],
3+
plugins: ["prettier"],
4+
ignorePatterns: [
5+
"**/node_modules/**",
6+
"**/dist/**",
7+
"**/build/**",
8+
"**/.cache/**",
9+
"**/.vscode/**",
10+
"**/integration/fixtures/**",
11+
],
12+
rules: {
13+
"prettier/prettier": "error",
14+
"import/no-unused-modules": "off",
15+
"unicorn/prefer-module": "off",
16+
"unicorn/prevent-abbreviations": "off",
17+
"unicorn/no-process-exit": "off",
18+
"prefer-const": "error",
19+
"@typescript-eslint/no-var-requires": "off",
20+
"@typescript-eslint/ban-ts-comment": "off",
21+
},
22+
settings: {
23+
react: {
24+
version: "detect",
25+
},
26+
},
27+
}

package.json

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
],
1414
"scripts": {
1515
"build": "tsup-node src/main.ts --target node16 --format cjs --dts --sourcemap",
16-
"build-watch": "pnpm build -- --watch",
16+
"build-watch": "pnpm build --watch",
1717
"lint": "eslint --ext js,ts,tsx .",
18-
"lint-fix": "pnpm lint -- --fix",
18+
"lint-fix": "pnpm lint --fix",
1919
"format": "prettier --write .",
2020
"typecheck": "tsc --noEmit",
2121
"test": "pnpm build && vitest --no-watch",
@@ -72,35 +72,6 @@
7272
"vite": "^4.3.9",
7373
"vitest": "^0.31.2"
7474
},
75-
"eslintConfig": {
76-
"extends": [
77-
"./node_modules/@itsmapleleaf/configs/eslint"
78-
],
79-
"plugins": [
80-
"prettier"
81-
],
82-
"ignorePatterns": [
83-
"**/node_modules/**",
84-
"**/dist/**",
85-
"**/build/**",
86-
"**/.cache/**",
87-
"**/.vscode/**",
88-
"**/integration/fixtures/**"
89-
],
90-
"rules": {
91-
"prettier/prettier": "error",
92-
"import/no-unused-modules": "off",
93-
"unicorn/prefer-module": "off",
94-
"unicorn/prevent-abbreviations": "off",
95-
"unicorn/no-process-exit": "off",
96-
"prefer-const": "error"
97-
},
98-
"settings": {
99-
"react": {
100-
"version": "detect"
101-
}
102-
}
103-
},
10475
"prettier": "@itsmapleleaf/configs/prettier",
10576
"release-it": {
10677
"git": {

src/asset-files.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import mime from "mime"
33
import { createReadStream } from "node:fs"
44
import { readFile } from "node:fs/promises"
55
import { relative } from "node:path"
6-
import { Readable } from "node:stream"
6+
import { type Readable } from "node:stream"
77

88
export type AssetFile = {
99
path: string
@@ -19,16 +19,16 @@ export async function collectAssetFiles(folder: string): Promise<AssetFile[]> {
1919
})
2020

2121
return files.map((file) => ({
22-
path: "/" + relative(folder, file).replace(/\\/g, "/"),
22+
path: "/" + relative(folder, file).replaceAll("\\", "/"),
2323
content: () => readFile(file),
2424
stream: () => createReadStream(file),
2525
}))
2626
}
2727

28-
export async function serveAsset(
28+
export function serveAsset(
2929
request: Electron.ProtocolRequest,
3030
files: AssetFile[],
31-
): Promise<Electron.ProtocolResponse | undefined> {
31+
): Electron.ProtocolResponse | undefined {
3232
const url = new URL(request.url)
3333

3434
const file = files.find((file) => file.path === url.pathname)

src/browser-globals.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Object.assign(globalThis, {
1616
AbortController,
1717
})
1818

19-
if (typeof globalThis.ReadableStream === "undefined") {
20-
const { ReadableStream } = require("@remix-run/web-stream")
19+
if (globalThis.ReadableStream === undefined) {
20+
const { ReadableStream } =
21+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
22+
require("@remix-run/web-stream") as typeof import("@remix-run/web-stream")
2123
globalThis.ReadableStream = ReadableStream
2224
}

src/main.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ export async function initRemix({
4747
const appRoot = app.getAppPath()
4848
const publicFolder = asAbsolutePath(publicFolderOption, appRoot)
4949

50-
let serverBuild: ServerBuild =
50+
let serverBuild =
5151
typeof serverBuildOption === "string"
52-
? require(serverBuildOption)
52+
? // eslint-disable-next-line @typescript-eslint/no-var-requires
53+
(require(serverBuildOption) as ServerBuild)
5354
: serverBuildOption
5455

5556
let [assetFiles] = await Promise.all([
@@ -63,6 +64,7 @@ export async function initRemix({
6364
? require.resolve(serverBuildOption)
6465
: undefined
6566

67+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
6668
protocol.interceptStreamProtocol("http", async (request, callback) => {
6769
try {
6870
if (mode === "development") {
@@ -81,7 +83,8 @@ export async function initRemix({
8183
lastBuildTime !== buildTime
8284
) {
8385
purgeRequireCache(buildPath)
84-
serverBuild = require(buildPath)
86+
// eslint-disable-next-line @typescript-eslint/no-var-requires
87+
serverBuild = require(buildPath) as ServerBuild
8588
lastBuildTime = buildTime
8689
}
8790

@@ -93,10 +96,10 @@ export async function initRemix({
9396
)
9497
} catch (error) {
9598
console.warn("[remix-electron]", error)
99+
const { stack, message } = toError(error)
96100
callback({
97101
statusCode: 500,
98-
// @ts-expect-error
99-
data: `<pre>${error?.stack || error?.message || String(error)}</pre>`,
102+
data: `<pre>${stack || message}</pre>`,
100103
})
101104
}
102105
})
@@ -113,7 +116,7 @@ async function handleRequest(
113116
context: unknown,
114117
): Promise<Electron.ProtocolResponse> {
115118
return (
116-
(await serveAsset(request, assetFiles)) ??
119+
serveAsset(request, assetFiles) ??
117120
(await serveRemixResponse(request, requestHandler, context))
118121
)
119122
}
@@ -125,3 +128,7 @@ function purgeRequireCache(prefix: string) {
125128
}
126129
}
127130
}
131+
132+
function toError(value: unknown) {
133+
return value instanceof Error ? value : new Error(String(value))
134+
}

src/serve-remix-response.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type { RequestHandler } from "@remix-run/server-runtime"
2-
import { Readable, PassThrough } from "node:stream"
1+
import type { AppLoadContext, RequestHandler } from "@remix-run/server-runtime"
2+
import { ReadableStream } from "@remix-run/web-stream"
3+
import { PassThrough, Readable } from "node:stream"
34
import "./browser-globals"
45

5-
function createPassThroughStream(text: any) {
6+
function createPassThroughStream(text: string | Buffer) {
67
const readable = new PassThrough()
78
readable.push(text)
89
readable.push(null) // eslint-disable-line unicorn/no-null, unicorn/no-array-push-push
@@ -12,7 +13,7 @@ function createPassThroughStream(text: any) {
1213
export async function serveRemixResponse(
1314
request: Electron.ProtocolRequest,
1415
handleRequest: RequestHandler,
15-
context: unknown,
16+
context: AppLoadContext | undefined,
1617
): Promise<Electron.ProtocolResponse> {
1718
const body = request.uploadData
1819
? Buffer.concat(request.uploadData.map((data) => data.bytes))
@@ -37,8 +38,9 @@ export async function serveRemixResponse(
3738

3839
if (response.body instanceof ReadableStream) {
3940
return {
40-
// @ts-expect-error
41-
data: Readable.from(response.body),
41+
data: Readable.from(
42+
response.body as unknown as AsyncIterable<Uint8Array>,
43+
),
4244
headers,
4345
statusCode: response.status,
4446
}

template/app/routes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function loader() {
88
}
99

1010
export default function Index() {
11-
const data = useLoaderData()
11+
const data = useLoaderData<typeof loader>()
1212
return (
1313
<main>
1414
<h1>Welcome to Remix</h1>

tests/fixtures/test-app/app/routes/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useState } from "react"
21
import { useLoaderData } from "@remix-run/react"
2+
import { useState } from "react"
33
import { app } from "~/electron.server"
44

55
export function loader() {
@@ -9,7 +9,7 @@ export function loader() {
99
}
1010

1111
export default function Index() {
12-
const data = useLoaderData()
12+
const data = useLoaderData<typeof loader>()
1313
const [count, setCount] = useState(0)
1414
return (
1515
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}>

tests/fixtures/test-app/app/routes/referrer-redirect.action.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { redirect } from "@remix-run/node"
33

44
export const action: ActionFunction = async ({ request }) => {
55
const { redirects } = Object.fromEntries(await request.formData())
6-
const url = new URL(request.headers.get("referer")!)
6+
const url = new URL(request.headers.get("referer") as string)
77
url.searchParams.set("redirects", String(Number(redirects) + 1))
88
return redirect(url.toString())
99
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "@itsmapleleaf/configs/tsconfig.base",
33
"compilerOptions": {
4-
"module": "commonjs",
4+
"module": "esnext",
55
"noUnusedLocals": true,
66
"jsx": "react-jsx",
77
"paths": {

0 commit comments

Comments
 (0)