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

Use JSDOM alternative for deploying to Vercel #95

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5360fc9
Update next
Josehower Jun 19, 2023
896f69e
Remove Fly deploy
Josehower Jun 19, 2023
99f045e
Configure for railway
Josehower Jun 19, 2023
21cfc53
Update webpack config
Josehower Jun 20, 2023
5513174
Use canvas externals in webpack
Josehower Jun 20, 2023
73f34ad
Use ENV variable from vercel
Josehower Jun 20, 2023
9e70757
Use ligth JSDOM lib
Josehower Jun 20, 2023
4074dd3
Update lock
Josehower Jun 20, 2023
fe22997
Remove extra webpack config
Josehower Jun 20, 2023
d90acd5
Add vercel fix suggestion
Josehower Jun 20, 2023
af6f979
Update to use different canvas
Josehower Jun 20, 2023
dd55c34
Use different dom lib
Josehower Jun 20, 2023
281ba8f
Remove canvas
Josehower Jun 20, 2023
d9ebf98
Use new JSDOM lib
Josehower Jun 20, 2023
aa1c96e
Update to trigger deploy
Josehower Jun 20, 2023
61d93f6
Use ESM
Josehower Jun 22, 2023
27a6367
Use ESM
Josehower Jun 26, 2023
f900e10
Update object
Josehower Jun 26, 2023
8b14159
Update ssl
Josehower Jun 26, 2023
53e81a3
Use default export
Josehower Jun 26, 2023
25bb8b5
Update next
Josehower Jun 27, 2023
fd69555
Remove Fly deploy
Josehower Jun 19, 2023
a8482d9
Configure for railway
Josehower Jun 19, 2023
f8e9a7f
Update sass
Josehower Jun 27, 2023
afc6f2f
Update dependencies
Josehower Jun 27, 2023
b2957c1
Update lock
Josehower Jun 27, 2023
3fc307f
Merge branch 'main' into vercel-deploy
Josehower Jun 27, 2023
7f9e56a
Delete ley.config.js
karlhorky Jun 27, 2023
33c31b6
Update types
Josehower Jun 27, 2023
2331a16
Add generic
Josehower Jun 27, 2023
d829dae
Add types
Josehower Jun 27, 2023
7bd396a
Discard changes to ...rkflows/lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
9828dd4
Update lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
392d455
Discard changes to ...rkflows/lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
21cafe0
Create lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
7c01333
Discard changes to scripts/fly-io-start.sh
karlhorky Jun 30, 2023
e30ad76
Update next.config.js
karlhorky Jun 30, 2023
c5ffe0f
Add back deleted file
karlhorky Jun 30, 2023
51ea59d
Update config file to work
Josehower Jun 30, 2023
76e8678
Update dependency upgrades - non-major (#97)
Josehower Jun 30, 2023
2071c6f
Update dependency eslint-config-upleveled to v5 (#98)
renovate[bot] Jun 30, 2023
2e35968
Enable deployment to both Fly and Vercel (#96)
Josehower Jun 30, 2023
d0a3fff
Remove Fly deploy
Josehower Jun 30, 2023
c75a75f
Configure for railway
Josehower Jun 19, 2023
5933f1e
Use ligth JSDOM lib
Josehower Jun 20, 2023
0894cc2
Update object
Josehower Jun 26, 2023
19c51b6
Update ssl
Josehower Jun 26, 2023
d3d60bc
Add back removed deploy step
karlhorky Jun 30, 2023
32f0518
Rename lint-check-types-build.yml to lint-check-types-build-deploy.yml
karlhorky Jun 30, 2023
5c96612
Create fly-io-start.sh
karlhorky Jun 30, 2023
fe782aa
Create fly.toml
karlhorky Jun 30, 2023
e661e69
Fix dockerfile
Josehower Jun 30, 2023
afc7e2b
Delete ley.config.js
karlhorky Jun 30, 2023
b5b186c
Update connect
Josehower Jun 30, 2023
bc86540
Merge branch 'main' into vercel-deploy
Josehower Jun 30, 2023
181b96b
Update lock
Josehower Jun 30, 2023
c39d258
Use Boolean constructor instead of !!
Josehower Jun 30, 2023
a4be47b
Use sinfle file for jsdom types
Josehower Jun 30, 2023
baa4d62
Remove unnecesary configuration
Josehower Jun 30, 2023
7bc5af8
Merge branch 'main' into vercel-deploy
karlhorky Jun 30, 2023
be48c35
Update tsconfig.json
karlhorky Jun 30, 2023
31abf21
Merge branch 'main' into vercel-deploy
karlhorky Jun 30, 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
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('@typescript-eslint/utils').TSESLint.Linter.Config} */
const config = {
extends: ['upleveled'],
globals: {
NodeJS: true,
},
};

module.exports = config;
14 changes: 12 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
// Enable Stylelint in javascript and typescriptreact (for CSS-in-JS) and scss
"css.lint.unknownAtRules": "ignore",
// Ignore unknown CSS at rules for Tailwind CSS
"stylelint.validate": [
"css",
"scss",
"postcss",
"javascript",
"typescriptreact"
],
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.tsdk": "./node_modules/typescript/lib"
}
2 changes: 2 additions & 0 deletions app/LinkIfNotCurrent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import Link, { LinkProps } from 'next/link';
import { usePathname } from 'next/navigation';
import { ReactNode } from 'react';

export default function LinkIfNotCurrent<RouteType>({
matchParentSegment,
...props
}: LinkProps<RouteType> & {
matchParentSegment?: boolean;
children: ReactNode;
}) {
const pathname = usePathname();

Expand Down
2 changes: 1 addition & 1 deletion app/example-6-cross-site-scripting/solution-2/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DOMPurify from 'dompurify';
import { JSDOM } from 'jsdom';
import { JSDOM } from 'jsdom-napi-rs-canvas';
import { notFound } from 'next/navigation';
import { getBlogPostById } from '../../../database/blogPosts';
import Common from '../common';
Expand Down
6 changes: 3 additions & 3 deletions database/connect.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { config } from 'dotenv-safe';
import postgres from 'postgres';
import { setEnvironmentVariables } from '../ley.config.mjs';

// This loads all environment variables from a .env file
// for all code after this line
if (!process.env.FLY_IO) config();
setEnvironmentVariables();

// Type needed for the connection function below
declare module globalThis {
Expand All @@ -15,6 +14,7 @@ declare module globalThis {
function connectOneTimeToDatabase() {
if (!globalThis.postgresSqlClient) {
globalThis.postgresSqlClient = postgres({
ssl: !!process.env.POSTGRES_URL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use Boolean() here for expressiveness?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform: {
...postgres.camel,
undefined: null,
Expand Down
42 changes: 42 additions & 0 deletions ley.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from 'node:fs';
import dotenv from 'dotenv';

export function setEnvironmentVariables() {
if (process.env.NODE_ENV === 'production' || process.env.CI) {
// Set standard environment variables for Postgres.js from Vercel environment variables
if (process.env.POSTGRES_URL) {
process.env.PGHOST = process.env.POSTGRES_HOST;
process.env.PGDATABASE = process.env.POSTGRES_DATABASE;
process.env.PGUSERNAME = process.env.POSTGRES_USER;
process.env.PGPASSWORD = process.env.POSTGRES_PASSWORD;
}
return;
}

// Replacement for unmaintained dotenv-safe package
// https://github.com/rolodato/dotenv-safe/issues/128#issuecomment-1383176751
//
// TODO: Remove this and switch to dotenv/safe if this proposal gets implemented:
// https://github.com/motdotla/dotenv/issues/709
dotenv.config();

const unconfiguredEnvVars = Object.keys(
dotenv.parse(fs.readFileSync('./.env.example')),
).filter((exampleKey) => !process.env[exampleKey]);

if (unconfiguredEnvVars.length > 0) {
throw new Error(
`.env.example environment ${
unconfiguredEnvVars.length > 1 ? 'variables' : 'variable'
} ${unconfiguredEnvVars.join(', ')} not configured in .env file`,
);
}
}

setEnvironmentVariables();

const options = {
ssl: !!process.env.POSTGRES_URL,
};

export default options;
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const nextConfig = {
reactStrictMode: true,
experimental: {
appDir: true,
serverComponentsExternalPackages: ['canvas', 'jsdom'],
serverComponentsExternalPackages: ['jsdom-napi-rs-canvas'],
typedRoutes: true,
},
eslint: {
Expand Down
23 changes: 0 additions & 23 deletions next.d.ts

This file was deleted.

17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@
"build": "next build",
"dev": "next dev",
"lint": "next lint",
"migrate": "dotenv -- ley --require tsm",
"migrate": "ley --require tsm",
"start": "next start"
},
"dependencies": {
"@types/cookie": "0.5.1",
"@types/dotenv-safe": "8.1.2",
"bcrypt": "5.1.0",
"canvas": "2.11.2",
"cookie": "0.5.0",
"dompurify": "3.0.3",
"dotenv-cli": "7.2.1",
"dotenv-safe": "8.2.0",
"jsdom": "22.1.0",
"dompurify": "3.0.4",
"dotenv": "^16.3.1",
"jsdom-napi-rs-canvas": "^19.0.0",
"ley": "0.8.1",
"next": "13.4.7",
"postgres": "3.3.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-markdown": "8.0.7",
"sass": "1.63.6",
"server-only": "^0.0.1",
"sharp": "0.32.1",
"tsm": "2.3.0",
"zod": "3.21.4"
Expand All @@ -34,15 +32,14 @@
"@ts-safeql/eslint-plugin": "1.1.4",
"@types/bcrypt": "5.0.0",
"@types/dompurify": "3.0.2",
"@types/jsdom": "21.1.1",
"@types/node": "18.16.3",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"eslint": "8.43.0",
"eslint-config-upleveled": "4.7.2",
"eslint-config-upleveled": "5.0.0",
"libpg-query": "15.0.2",
"stylelint": "15.9.0",
"stylelint-config-upleveled": "^1.0.2",
"typescript": "5.1.3"
"typescript": "5.1.6"
}
}
Loading