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

Switch tools #85

Merged
merged 16 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Libraries:

Not configured for serverless or SSG, I don't use Next.js for them.

### `vite-preact`, for frontend-only SPA
### `preact-spa`, for frontend-only SPA

based on [create-vite template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-preact-ts)

Expand All @@ -37,7 +37,7 @@ Libraries:
- [preact-router]()

If you need to host built assets with path rewriting,
I recommend `hono-serverless` variant,
I recommend `hono-worker` variant,
or [serve-handler](https://github.com/vercel/serve-handler) ([example](https://github.com/jokester/limb/blob/master/server/main.ts)).

### `hono-worker`, for edge-worker like environments
Expand Down
1 change: 1 addition & 0 deletions empty/.eslint.ts-mixin.mjs
1 change: 0 additions & 1 deletion empty/.eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion empty/.eslintrc.base.js

This file was deleted.

6 changes: 0 additions & 6 deletions empty/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion empty/.prettierrc.js

This file was deleted.

1 change: 1 addition & 0 deletions empty/dprint.json
17 changes: 17 additions & 0 deletions empty/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import mixin from './.eslint.ts-mixin.mjs';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
...mixin,
);
4 changes: 2 additions & 2 deletions empty/jest.config.js → empty/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
roots: ['src'],
transformIgnorePatterns: ['<rootDir>/node_modules/.*\\.js', '<rootDir>/build/.*\\.js'],
testMatch: ['**/*\\.(spec|test)\\.(ts|js|tsx|jsx)'],
Expand All @@ -11,7 +11,7 @@ module.exports = {
{
isolatedModules: true,
// to workaround https://github.com/kulshekhar/ts-jest/issues/4198
tsconfig: { moduleResolution: 'node', module: 'commonjs' },
tsconfig: {moduleResolution: 'node', module: 'commonjs'},
},
],
},
Expand Down
15 changes: 9 additions & 6 deletions empty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
],
"scripts": {
"build": "rm -rvf build && tsc",
"lint": "gts lint",
"lint:fix": "gts lint --fix",
"lint": "eslint src",
"lint:fix": "eslint --fix src",
"format": "dprint fmt",
"start": "node build/bin/example-bin",
"test": "jest",
"test:coverage": "jest --coverage",
Expand All @@ -24,17 +25,19 @@
"typecheck:watch": "tsc --watch --noEmit"
},
"devDependencies": {
"@eslint/js": "*",
"@tsconfig/strictest": "*",
"@types/jest": "*",
"@types/node": "*",
"@typescript-eslint/eslint-plugin": "*",
"@typescript-eslint/parser": "*",
"dprint": "*",
"eslint": "*",
"gts": "*",
"tslib": "^2",
"eslint-plugin-import-x": "*",
"jest": "*",
"ts-jest": "*",
"ts-node": "*",
"typescript": "*"
"typescript": "*",
"typescript-eslint": "*"
},
"engines": {
"node": ">=18"
Expand Down
5 changes: 4 additions & 1 deletion empty/src/bin/example-bin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { cliMain } from '../lib';

cliMain();
cliMain().catch(e => {
console.error(e);
process.exit(1);
});
3 changes: 2 additions & 1 deletion empty/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"__test__",
"bin",
"./*.json",
"./*.js"
"./*.js",
"./*.mjs"
]
}
1 change: 1 addition & 0 deletions hono-worker/.eslint.ts-mixin.mjs
1 change: 0 additions & 1 deletion hono-worker/.eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion hono-worker/.eslintrc.base.js

This file was deleted.

6 changes: 0 additions & 6 deletions hono-worker/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion hono-worker/.prettierrc.js

This file was deleted.

1 change: 1 addition & 0 deletions hono-worker/dprint.json
17 changes: 17 additions & 0 deletions hono-worker/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import mixin from './.eslint.ts-mixin.mjs';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
...mixin,
);
4 changes: 2 additions & 2 deletions hono-worker/jest.config.js → hono-worker/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
roots: ['src'],
transformIgnorePatterns: ['<rootDir>/node_modules/.*\\.js', '<rootDir>/build/.*\\.js'],
testMatch: ['**/*\\.(spec|test)\\.(ts|js|tsx|jsx)'],
Expand All @@ -11,7 +11,7 @@ module.exports = {
{
isolatedModules: true,
// to workaround https://github.com/kulshekhar/ts-jest/issues/4198
tsconfig: { moduleResolution: 'node', module: 'commonjs' },
tsconfig: {moduleResolution: 'node', module: 'commonjs'},
},
],
},
Expand Down
20 changes: 12 additions & 8 deletions hono-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,36 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "echo 'dummy: IDK how to build without logging into cloudflare'",
"build": "wrangler deploy --dry-run --outdir=build",
"deploy": "wrangler publish",
"dev": "wrangler dev --local --live-reload ./src/server.ts",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"lint": "eslint src",
"lint:fix": "eslint --fix src",
"format": "dprint fmt",
"test": "jest",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch",
"typecheck": "tsc --noEmit",
"typecheck:watch": "tsc --watch --noEmit"
},
"dependencies": {
"hono": "^4.0.1"
"hono": "^4.3.6"
},
"devDependencies": {
"@eslint-react/eslint-plugin": "*",
"@eslint/js": "*",
"@tsconfig/strictest": "*",
"@types/jest": "*",
"@typescript-eslint/eslint-plugin": "*",
"@typescript-eslint/parser": "*",
"dprint": "*",
"eslint": "*",
"gts": "*",
"tslib": "^2",
"eslint-plugin-import-x": "*",
"jest": "*",
"ts-jest": "*",
"ts-node": "*",
"typescript": "*",
"wrangler": "^3.28.1"
"typescript-eslint": "*",
"wrangler": "^3.56.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion hono-worker/src/routes/forward-route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hono } from 'hono';
import { MyBindings } from '../config';

export const forwardOpenaiRoute = new Hono<{ Bindings: MyBindings }>({});
export const forwardOpenaiRoute = new Hono<{Bindings: MyBindings}>({});

forwardOpenaiRoute.use('/*', async (c) => {
const incomingHeaders = new Headers(c.req.raw.headers);
Expand Down
2 changes: 1 addition & 1 deletion hono-worker/src/routes/json-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { Hono } from 'hono';
export const jsonRoute = new Hono();

jsonRoute.get('/', (c) => {
return c.json({ message: 'Hello!', path: c.req.path });
return c.json({message: 'Hello!', path: c.req.path});
});
2 changes: 1 addition & 1 deletion hono-worker/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { jsonRoute } from './routes/json-route';
import { MyBindings } from './config';
import { forwardOpenaiRoute } from './routes/forward-route';

const app = new Hono<{ Bindings: MyBindings }>();
const app = new Hono<{Bindings: MyBindings}>();

app.get(
'/*',
Expand Down
2 changes: 1 addition & 1 deletion hono-worker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"target": "ES2022",
"rootDir": "./src"
},
"exclude": ["node_modules", "coverage", "public", "./build", "/dist", "./*.json", "./*.js"]
"exclude": ["node_modules", "coverage", "public", "./build", "/dist", "./*.json", "./*.js", "./*.mjs"]
}
1 change: 1 addition & 0 deletions next/.eslint.react.mjs
1 change: 1 addition & 0 deletions next/.eslint.ts-mixin.mjs
1 change: 0 additions & 1 deletion next/.eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion next/.eslintrc.base.js

This file was deleted.

5 changes: 0 additions & 5 deletions next/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion next/.eslintrc.react.js

This file was deleted.

1 change: 0 additions & 1 deletion next/.prettierrc.js

This file was deleted.

1 change: 1 addition & 0 deletions next/dprint.json
23 changes: 23 additions & 0 deletions next/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import nextEslint from '@next/eslint-plugin-next';
import tsMixin from './.eslint.ts-mixin.mjs';
import reactMixin from './.eslint.react.mjs';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
plugins: {nextEslint},
},
...tsMixin,
...reactMixin,
);
2 changes: 1 addition & 1 deletion next/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const customJestConfig = {
const nextJest = require('next/jest');

// Providing the path to your Next.js app which will enable loading next.config.js and .env files
const createJestConfig = nextJest({ dir: './' });
const createJestConfig = nextJest({dir: './'});

// createJestConfig is exported in this way to ensure that next/jest can load the Next.js configuration, which is async
module.exports = createJestConfig(customJestConfig);
10 changes: 5 additions & 5 deletions next/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const nextConf = {
builtAt: new Date().toISOString(),
},
// see https://nextjs.org/docs/#customizing-webpack-config
webpack(config, { buildId, dev, isServer, webpack }) {
webpack(config, {buildId, dev, isServer, webpack}) {
config.plugins.push(
new webpack.DefinePlugin({
/**
Expand Down Expand Up @@ -65,15 +65,15 @@ const nextConf = {
reactStrictMode: true,
};

export default async (phase, { defaultConfig }) => {
export default async (phase, {defaultConfig}) => {
/**
* @type {import('next').NextConfig}
*/
let merged = { ...nextConf };
let merged = {...nextConf};

if (phase === PHASE_PRODUCTION_BUILD) {
const { default: analyzerPlugin } = await import('@next/bundle-analyzer');
merged = analyzerPlugin({ enabled: true, openAnalyzer: false })(merged);
const {default: analyzerPlugin} = await import('@next/bundle-analyzer');
merged = analyzerPlugin({enabled: true, openAnalyzer: false})(merged);
}

return merged;
Expand Down
Loading
Loading