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

refactor: migrate to ESM #524

Merged
merged 80 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
2f98d69
chore: integrate remix vite (wip)
hi-ogawa Nov 12, 2023
6005202
fix: workaround uno.css infinite update
hi-ogawa Nov 12, 2023
048925e
fix: workaround "handle" skip HMR
hi-ogawa Nov 12, 2023
8883f0e
chore: tweak script
hi-ogawa Nov 12, 2023
2d23d28
fix: fix FOUC
hi-ogawa Nov 12, 2023
49bc14a
chore: comment
hi-ogawa Nov 12, 2023
5ee678f
chore: disable remix plugin on vitest
hi-ogawa Nov 12, 2023
5b7802d
chore: workaround knexfile dirname
hi-ogawa Nov 12, 2023
c865b95
chore: update build script
hi-ogawa Nov 12, 2023
ceaf48a
fix: more build workaround
hi-ogawa Nov 12, 2023
c356369
chore: workaround cjs
hi-ogawa Nov 12, 2023
2371adf
chore: struggle assets dir (wip)
hi-ogawa Nov 12, 2023
a16bfb2
chore: lint
hi-ogawa Nov 12, 2023
1fab0df
chore: disable coverage for e2e temporary
hi-ogawa Nov 12, 2023
7cfcd10
fix: inject css manually for prod
hi-ogawa Nov 12, 2023
20cff61
refactor: simplify knexfile
hi-ogawa Nov 12, 2023
ed834d4
chore: lint
hi-ogawa Nov 12, 2023
e317128
chore: one more knexfile workaround
hi-ogawa Nov 12, 2023
ed50bce
fix: patch `skipEnvCheck`
hi-ogawa Nov 12, 2023
6a36933
test: waitForHydration for e2e
hi-ogawa Nov 12, 2023
96a210f
refactor: use copyPublicDir = false
hi-ogawa Nov 17, 2023
833bc14
chore(deps): remix 2.3.0 and vite 5.0.0
hi-ogawa Nov 19, 2023
ea752c2
chore: remove unused
hi-ogawa Nov 19, 2023
fc7664a
chore: remove obsolete workaround
hi-ogawa Nov 19, 2023
0a940b2
ci: add waitForHydration to e2e
hi-ogawa Nov 19, 2023
8c42339
test: more waitForHydration
hi-ogawa Nov 19, 2023
08581eb
test: more ci struggle
hi-ogawa Nov 19, 2023
0ac381f
ci: disable coverage
hi-ogawa Nov 19, 2023
0217c8a
chore: esm
hi-ogawa Nov 19, 2023
f5f61d4
Revert "chore: esm"
hi-ogawa Nov 19, 2023
f376d43
chore(deps): update react-query (TODO: this should be done in a separ…
hi-ogawa Nov 19, 2023
7219dfe
Revert "chore(deps): update react-query (TODO: this should be done in…
hi-ogawa Nov 19, 2023
198a2b3
chore(deps): update unocss
hi-ogawa Nov 20, 2023
302e253
chore: silence react-query "use client" warning
hi-ogawa Nov 20, 2023
8e0e87d
chore: minify vercel serverless
hi-ogawa Nov 20, 2023
5e6efb9
chore: add vite.config.ui.ts
hi-ogawa Nov 20, 2023
21dc151
chore: HMR for "handle" export
hi-ogawa Nov 20, 2023
0ac8ab7
refactor: remove __dirname
hi-ogawa Nov 20, 2023
d40b421
fix: struggle with cwd
hi-ogawa Nov 20, 2023
0046d4a
chore: more struggle with knex cwd
hi-ogawa Nov 20, 2023
b21bf55
refactor: simplify db config and knexfile management
hi-ogawa Nov 20, 2023
7b235fe
refactor: "require" => "import"
hi-ogawa Nov 20, 2023
9dff9d2
chore: type "module" (wip)
hi-ogawa Nov 20, 2023
0c7d3d2
chore: update remix nightly (no more patch!)
hi-ogawa Nov 29, 2023
11e2f54
refactor: simplify config
hi-ogawa Nov 29, 2023
54752f9
chore: minor
hi-ogawa Nov 29, 2023
093171a
refactor: minor
hi-ogawa Nov 29, 2023
bad35dd
chore: tree-shake react-query-devtools
hi-ogawa Nov 30, 2023
acc6aaf
fix: fix knex
hi-ogawa Dec 1, 2023
ae9d35a
chore: knex js to esm
hi-ogawa Dec 1, 2023
962b709
chore: fix cjs scripts
hi-ogawa Dec 1, 2023
3e628d0
chore: obsolete comment
hi-ogawa Dec 1, 2023
8c70605
chore: comment
hi-ogawa Dec 1, 2023
bdd19e0
chore: replace @vavite/connect with vite-plugin-ssr-middleware
hi-ogawa Dec 2, 2023
366dbd1
Merge branch 'refactor-remix-vite' into refactor-esm
hi-ogawa Dec 3, 2023
0175409
chore: tweak script
hi-ogawa Dec 3, 2023
3b0c52b
fix: replace "require"
hi-ogawa Dec 3, 2023
67aeeaa
chore: replace __filename
hi-ogawa Dec 3, 2023
d4ba2a3
chore: test esm deployment
hi-ogawa Dec 3, 2023
e385991
fix: esm require banner trick
hi-ogawa Dec 3, 2023
0951c7b
chore: remove unused deps
hi-ogawa Dec 3, 2023
e580f93
chore: use `@hattip/adapter-node/native-fetch`
hi-ogawa Dec 4, 2023
79ced34
chore: unused deps
hi-ogawa Dec 4, 2023
b59fe29
chore: update @vitejs/plugin-react
hi-ogawa Dec 4, 2023
20c7570
chore: update opentelemetry
hi-ogawa Dec 4, 2023
63790d8
Merge branch 'refactor-remix-vite' into refactor-esm
hi-ogawa Dec 4, 2023
d5bae80
chore: update icheck-ts
hi-ogawa Dec 4, 2023
39c1cc0
chore: update icheck-ts and node
hi-ogawa Dec 5, 2023
73a438a
chore: move vitest.config to vite.config
hi-ogawa Dec 7, 2023
7a53a10
chore: install @vitest/ui
hi-ogawa Dec 11, 2023
098bd68
chore: more ignoredFilePatterns
hi-ogawa Dec 25, 2023
a8d8bea
chore: simplify FOUC hack
hi-ogawa Dec 25, 2023
1e8c36f
fix: fix vercel cache header
hi-ogawa Dec 26, 2023
3384aa5
Merge branch 'master' into refactor-remix-vite
hi-ogawa Dec 26, 2023
f9e8563
Merge branch 'refactor-remix-vite' into refactor-esm
hi-ogawa Dec 26, 2023
40ebbe1
Merge branch 'master' into refactor-esm
hi-ogawa Dec 26, 2023
1f1389b
Merge branch 'master' into refactor-esm
hi-ogawa Dec 26, 2023
80aa460
chore: tweak "createRequire" banner
hi-ogawa Dec 26, 2023
837349d
Merge branch 'master' into refactor-esm
hi-ogawa Dec 27, 2023
cb3fed8
Merge branch 'master' into refactor-esm
hi-ogawa Dec 27, 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
15 changes: 15 additions & 0 deletions app/db/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { type ConnectionOptions } from "mysql2";
import { serverConfig } from "../utils/config";

export function dbConfig() {
return {
host: serverConfig.APP_MYSQL_HOST,
port: serverConfig.APP_MYSQL_PORT,
user: serverConfig.APP_MYSQL_USER,
password: serverConfig.APP_MYSQL_PASSWORD,
database: serverConfig.APP_MYSQL_DATABASE,
ssl: serverConfig.APP_MYSQL_SSL ? {} : undefined,
multipleStatements: true,
timezone: "+00:00", // planetscale and development mysql image have UTC localtime
} satisfies ConnectionOptions;
}
5 changes: 2 additions & 3 deletions app/db/drizzle-client.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { Connection } from "mysql2";
import { createConnection } from "mysql2/promise";
import { uninitialized } from "../utils/misc";
import type { PaginationMetadata, PaginationParams } from "../utils/pagination";
import knexfile from "./knexfile.server";
import { dbConfig } from "./config";
import type { DeckCache, PracticeActionType, PracticeQueueType } from "./types";

//
Expand Down Expand Up @@ -353,8 +353,7 @@ export async function initializeDrizzleClient() {
db = globalThis.__drizzleClient ??= await inner();

async function inner() {
const config = knexfile();
const connection = await createConnection(config.connection);
const connection = await createConnection(dbConfig());
return drizzle(connection, {
logger: process.env["DEBUG"]?.includes("drizzle"), // enable query logging by DEBUG=drizzle
});
Expand Down
16 changes: 16 additions & 0 deletions app/db/knexfile.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Knex } from "knex";
import { initializeConfigServer } from "../utils/config";
import { dbConfig } from "./config";

export default function knexfile() {
initializeConfigServer();

return {
client: "mysql2",
connection: dbConfig(),
migrations: {
directory: "migrations",
stub: "__migration-stub.ts",
},
} satisfies Knex.Config;
}
24 changes: 0 additions & 24 deletions app/db/knexfile.server.ts

This file was deleted.

4 changes: 2 additions & 2 deletions app/db/migrations/20220226100116_create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
CREATE TABLE users (
id BIGINT AUTO_INCREMENT,
Expand All @@ -20,7 +20,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
DROP TABLE users;
`);
Expand Down
4 changes: 2 additions & 2 deletions app/db/migrations/20220402105114_add-user-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE users ADD settings JSON DEFAULT NULL;
`);
Expand All @@ -12,7 +12,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE users DROP COLUMN settings;
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE users MODIFY createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
`);
Expand All @@ -15,7 +15,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE users MODIFY updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
UPDATE users SET settings = JSON_OBJECT() WHERE settings IS NULL
`);
Expand All @@ -15,7 +15,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE users MODIFY settings JSON DEFAULT NULL
`);
Expand Down
10 changes: 6 additions & 4 deletions app/db/migrations/20220408030906_change-users-settings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as assert from "assert/strict";

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
if (process.env.MIGRATION_UNIT_TEST) await testUp.before(knex);

await knex.raw(`
Expand All @@ -21,7 +23,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
if (process.env.MIGRATION_UNIT_TEST) await testDown.before(knex);

await knex.raw(`
Expand All @@ -48,7 +50,7 @@ const testUp = {
const [rows] = await knex.raw(
`SELECT language1, language2 FROM users ORDER BY username`
);
require("assert").deepStrictEqual(rows, [
assert.deepEqual(rows, [
{ language1: null, language2: null },
{ language1: "fr", language2: null },
{ language1: "fr", language2: "en" },
Expand All @@ -70,7 +72,7 @@ const testDown = {
const [rows] = await knex.raw(
`SELECT settings FROM users ORDER BY username`
);
require("assert").deepStrictEqual(rows, [
assert.deepEqual(rows, [
{ settings: { language1: null, language2: null } },
{ settings: { language1: "fr", language2: null } },
{ settings: { language1: "fr", language2: "en" } },
Expand Down
4 changes: 2 additions & 2 deletions app/db/migrations/20220410120806_create-videos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
CREATE TABLE videos (
id BIGINT AUTO_INCREMENT,
Expand Down Expand Up @@ -43,7 +43,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
DROP TABLE captionEntries;
`);
Expand Down
4 changes: 2 additions & 2 deletions app/db/migrations/20220411031243_create-bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
CREATE TABLE bookmarkEntries (
id BIGINT AUTO_INCREMENT,
Expand All @@ -26,7 +26,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
DROP TABLE bookmarkEntries;
`);
Expand Down
4 changes: 2 additions & 2 deletions app/db/migrations/20220417071104_create-practice-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
CREATE TABLE decks (
id BIGINT AUTO_INCREMENT,
Expand Down Expand Up @@ -51,7 +51,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`DROP TABLE practiceActions`);
await knex.raw(`DROP TABLE practiceEntries`);
await knex.raw(`DROP TABLE decks`);
Expand Down
4 changes: 2 additions & 2 deletions app/db/migrations/20220504095705_add-deck-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE decks
ADD newEntriesPerDay INTEGER NOT NULL DEFAULT 50,
Expand All @@ -16,7 +16,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE decks
DROP newEntriesPerDay,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
for (const table of TABLES) {
await knex.raw(`
ALTER TABLE ${table} MODIFY createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
Expand All @@ -15,7 +15,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
for (const table of TABLES) {
await knex.raw(`
ALTER TABLE ${table} MODIFY updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
Expand Down
4 changes: 2 additions & 2 deletions app/db/migrations/20220508102506_add-deck-randomize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE decks ADD randomMode BOOL NOT NULL DEFAULT FALSE
`);
Expand All @@ -12,7 +12,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE decks DROP randomMode
`);
Expand Down
4 changes: 2 additions & 2 deletions app/db/migrations/20220528054447_add-user-timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE users ADD timezone VARCHAR(32) NOT NULL DEFAULT '+00:00'
`);
Expand All @@ -12,7 +12,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE users DROP timezone
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE videos ADD bookmarkEntriesCount INT NOT NULL DEFAULT 0
`);
Expand All @@ -12,7 +12,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE videos DROP bookmarkEntriesCount
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE practiceEntries ADD practiceActionsCount INT NOT NULL DEFAULT 0
`);
Expand All @@ -12,7 +12,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE practiceEntries DROP practiceActionsCount
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE decks ADD practiceEntriesCountByQueueType JSON NOT NULL DEFAULT (JSON_OBJECT('NEW', 0, 'LEARN', 0, 'REVIEW', 0))
`);
Expand All @@ -12,7 +12,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE decks DROP practiceEntriesCountByQueueType
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
export const up = async function (knex) {
await knex.raw(`
ALTER TABLE practiceActions ADD KEY practiceActions_createdAt_key (createdAt)
`);
Expand All @@ -12,7 +12,7 @@ exports.up = async function (knex) {
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
export const down = async function (knex) {
await knex.raw(`
ALTER TABLE practiceActions DROP KEY practiceActions_createdAt_key
`);
Expand Down
Loading
Loading