Skip to content

Commit

Permalink
Merge pull request #33 from frysztak/release/v0.4.0
Browse files Browse the repository at this point in the history
v0.4.0 into master
  • Loading branch information
frysztak authored Jun 12, 2022
2 parents 7c497ed + 6a8c968 commit f4371cd
Show file tree
Hide file tree
Showing 69 changed files with 3,562 additions and 2,545 deletions.
5 changes: 0 additions & 5 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ DB_PASS=""
DB_HOST=""
DB_PORT=""
DB_NAME=""
APP_DISABLE_LOGIN=""
COOKIE_SECRET=""
APP_USERNAME=""
APP_PASSWORD=""
APP_URL=""
API_URL=""
API_SSR_URL=""
NEXT_PUBLIC_GIT_COMMIT_HASH="dev"
NEXT_PUBLIC_VERSION="dev"
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.4.0] - 2022-06-12

### Added

- Feature: Reduced Docker image size from 478 MB to 126 MB (uncompressed)
- Feature: automatically detect RSS/Atom feed from URL
- Feature: automatically detect system color mode

### Changed

- Frontend: disable SSR
- Backend: migrate to Fastify 4
- Backend: improve compatibility with certain feeds

## [0.3.0] - 2022-06-04

### Added
Expand Down Expand Up @@ -58,7 +72,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- The entire app!

[Unreleased]: https://github.com/frysztak/orpington-news/compare/0.3.0...HEAD
[Unreleased]: https://github.com/frysztak/orpington-news/compare/0.4.0...HEAD

[0.4.0]: https://github.com/frysztak/orpington-news/compare/0.3.0...0.4.0

[0.3.0]: https://github.com/frysztak/orpington-news/compare/0.2.0...0.3.0

Expand Down
18 changes: 12 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ COPY --from=builder /app/package.json .
COPY --from=builder /app/yarn.lock .
COPY --from=builder /app/.yarnrc.yml .
COPY --from=builder /app/.yarn .yarn
COPY --from=builder /app/packages/shared /app/packages/shared
COPY --from=builder /app/packages/backend /app/packages/backend
COPY --from=builder /app/yarn.lock /app/packages/backend
COPY --from=builder /app/packages/frontend /app/packages/frontend
COPY --from=builder /app/yarn.lock /app/packages/frontend

RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn workspaces focus --all --production
COPY --from=builder /app/packages/backend/dist /app/packages/backend
COPY --from=builder /app/packages/backend/db/migrations /app/packages/backend/db/migrations
COPY --from=builder /app/packages/backend/package.json /app/packages/backend/package.json

COPY --from=builder /app/packages/frontend/public /app/packages/frontend/public
COPY --from=builder /app/packages/frontend/package.json /app/packages/frontend/package.json
COPY --from=builder /app/packages/frontend/.next/standalone /app/packages/frontend
COPY --from=builder /app/packages/frontend/.next/static /app/packages/frontend/.next/static

WORKDIR /app/packages/backend
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn workspaces focus --production
WORKDIR /app

EXPOSE 8000
CMD /bin/sh /app/run.sh
6 changes: 2 additions & 4 deletions docker/apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
{
"name": "web",
"cwd": "/app/packages/frontend/",
"script": "node_modules/.bin/next",
"args": "start",
"script": "server.js",
"env": {
"NODE_ENV": "production",
"API_SSR_URL": "http://127.0.0.1:5000",
"PORT": "3000"
},
"error_file": "/var/log/web/error.log",
Expand All @@ -16,7 +14,7 @@
{
"name": "api",
"cwd": "/app/packages/backend/",
"script": "dist/server.js",
"script": "server.cjs",
"env": {
"NODE_ENV": "production",
"PORT": "5000"
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"devDependencies": {
"cross-env": "^7.0.3",
"husky": "^8.0.1",
"lerna": "^5.0.0",
"lint-staged": "^12.5.0",
"lerna": "^5.1.1",
"lint-staged": "^13.0.1",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typescript": "^4.7.2",
"typescript": "^4.7.3",
"yarn-audit-fix": "^9.3.1"
},
"workspaces": {
Expand All @@ -33,5 +33,5 @@
"*.{js,cjs,css,md,ts,tsx,json,yml,yaml}": "prettier --write"
},
"packageManager": "[email protected]",
"version": "0.3.0"
"version": "0.4.0"
}
15 changes: 15 additions & 0 deletions packages/backend/esbuild/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { build } from 'esbuild';
import { jsdomPlugin } from './jsdom.js';
import { nativeNodeModulesPlugin } from './native-node-module.js';

build({
entryPoints: ['server.ts'],
bundle: true,
minify: true,
outdir: 'dist',
outExtension: { '.js': '.cjs' },
platform: 'node',
target: ['node16'],
external: ['pg-native', 'canvas', 'pino'],
plugins: [jsdomPlugin(), nativeNodeModulesPlugin()],
}).catch((err) => process.exit(1));
27 changes: 27 additions & 0 deletions packages/backend/esbuild/jsdom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from 'fs';
import { createRequire } from 'module';

export const jsdomPlugin = () => {
const require = createRequire(import.meta.url);

return {
name: 'jsdom-patch',
setup(build) {
build.onLoad(
{ filter: /jsdom\/living\/xhr\/XMLHttpRequest-impl\.js$/ },
async (args) => {
let contents = await fs.promises.readFile(args.path, 'utf8');

contents = contents.replace(
'const syncWorkerFile = require.resolve ? require.resolve("./xhr-sync-worker.js") : null;',
`const syncWorkerFile = "${require.resolve(
'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
)}";`
);

return { contents, loader: 'js' };
}
);
},
};
};
60 changes: 60 additions & 0 deletions packages/backend/esbuild/native-node-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// https://raw.githubusercontent.com/egoist/tsup/dev/src/esbuild/native-node-module.ts
import path from 'path';
import { createRequire } from 'module';

// Copied from https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
export const nativeNodeModulesPlugin = () => {
const require = createRequire(import.meta.url);

return {
name: 'native-node-modules',
setup(build) {
// If a ".node" file is imported within a module in the "file" namespace, resolve
// it to an absolute path and put it into the "node-file" virtual namespace.
build.onResolve({ filter: /\.node$/, namespace: 'file' }, (args) => {
const resolvedId = require.resolve(args.path, {
paths: [args.resolveDir],
});
if (resolvedId.endsWith('.node')) {
return {
path: resolvedId,
namespace: 'node-file',
};
}
return {
path: resolvedId,
};
});

// Files in the "node-file" virtual namespace call "require()" on the
// path from esbuild of the ".node" file in the output directory.
build.onLoad({ filter: /.*/, namespace: 'node-file' }, (args) => {
return {
contents: `
import path from ${JSON.stringify(args.path)}
try { module.exports = require(path) }
catch {}
`,
resolveDir: path.dirname(args.path),
};
});

// If a ".node" file is imported within a module in the "node-file" namespace, put
// it in the "file" namespace where esbuild's default loading behavior will handle
// it. It is already an absolute path since we resolved it to one above.
build.onResolve(
{ filter: /\.node$/, namespace: 'node-file' },
(args) => ({
path: args.path,
namespace: 'file',
})
);

// Tell esbuild's default loading behavior to use the "file" loader for
// these ".node" files.
const opts = build.initialOptions;
opts.loader = opts.loader || {};
opts.loader['.node'] = 'file';
},
};
};
4 changes: 3 additions & 1 deletion packages/backend/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = {
},
},
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
transformIgnorePatterns: ['node_modules/(?!(normalize-url)/)'],
transformIgnorePatterns: [
'node_modules/(?!(normalize-url|is-relative-url|is-absolute-url|node-fetch|data-uri-to-buffer|fetch-blob|formdata-polyfill)/)',
],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.jsx?$': 'babel-jest',
Expand Down
85 changes: 48 additions & 37 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,79 @@
"license": "ISC",
"scripts": {
"dev": "cp ../../.env.local .env && NODE_ENV=development rollup -c -w",
"build": "rimraf dist && rollup -c",
"start": "node dist/server.js",
"migrate": "node dist/migrate.js",
"build": "rimraf dist && tsc --noEmit && node esbuild/build.js",
"start": "node dist/server.cjs",
"migrate": "node dist/db/migrate.cjs",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@fastify/auth": "^2.0.0",
"@fastify/cookie": "^6.0.0",
"@fastify/cors": "^7.0.0",
"@fastify/etag": "3.0.0",
"@fastify/schedule": "^2.0.0",
"@fastify/session": "^8.2.0",
"@fastify/swagger": "^6.1.0",
"pino": "^8.0.0",
"pino-pretty": "^8.0.0"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/plugin-transform-modules-commonjs": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@fastify/auth": "^3.0.1",
"@fastify/cookie": "^7.0.0",
"@fastify/cors": "^8.0.0",
"@fastify/etag": "4.0.0",
"@fastify/schedule": "^3.0.0",
"@fastify/session": "^9.0.0",
"@fastify/swagger": "^7.3.0",
"@fastify/type-provider-typebox": "^1.0.0",
"@orpington-news/shared": "^0.0.0",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-run": "^2.1.0",
"@rollup/plugin-typescript": "^8.3.3",
"@sinclair/typebox": "^0.23.5",
"@slonik/migrator": "^0.11.2",
"@types/connect-pg-simple": "^7.0.0",
"@types/jest": "^28.1.1",
"@types/node": "^17.0.42",
"@types/proper-url-join": "^2.1.1",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"argon2": "^0.28.5",
"babel-jest": "^28.1.1",
"cheerio": "1.0.0-rc.11",
"close-with-grace": "^1.1.0",
"connect-pg-simple": "^7.0.0",
"data-uri-to-buffer": "^4.0.0",
"date-fns": "^2.28.0",
"dotenv": "^16.0.1",
"esbuild": "^0.14.43",
"eslint-plugin-sql": "^2.1.0",
"event-iterator": "^2.0.0",
"fastify": "^3.29.0",
"fastify-sse-v2": "^2.0.6",
"fastify": "^4.0.1",
"fastify-sse-v2": "^2.2.1",
"file-type": "^17.1.2",
"html-entities": "^2.3.3",
"is-relative-url": "^3.0.0",
"is-relative-url": "^4.0.0",
"isomorphic-dompurify": "^0.19.0",
"jest": "^28.1.1",
"nock": "^13.2.6",
"node-fetch": "^3.2.6",
"node-html-parser": "^5.3.3",
"normalize-url": "7.0.3",
"pino": "^7.11.0",
"pino-pretty": "^7.6.1",
"pg": "^8.7.3",
"proper-url-join": "^2.1.1",
"reading-time": "^1.5.0",
"rimraf": "^3.0.2",
"rollup": "^2.75.6",
"rss-parser": "^3.12.0",
"slonik": "^28.1.0",
"slonik": "^28.1.1",
"striptags": "^3.2.0",
"toad-scheduler": "^1.6.1",
"truncate-html": "^1.0.4"
"truncate-html": "^1.0.4",
"ts-jest": "^28.0.4",
"typescript": "^4.7.3"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/plugin-transform-modules-commonjs": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-run": "^2.1.0",
"@rollup/plugin-typescript": "^8.3.2",
"@sinclair/typebox": "^0.23.5",
"@types/connect-pg-simple": "^7.0.0",
"@types/jest": "^27.5.2",
"@types/node": "^17.0.38",
"@types/proper-url-join": "^2.1.1",
"babel-jest": "^28.1.0",
"eslint-plugin-sql": "^2.1.0",
"jest": "^28.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.75.5",
"ts-jest": "^28.0.3"
"installConfig": {
"hoistingLimits": "workspaces"
}
}
2 changes: 1 addition & 1 deletion packages/backend/plugins/verifySession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const plugin = async (fastify: FastifyInstance) => {
};

export const fastifyVerifySession = fastifyPlugin(plugin, {
fastify: '3.x',
fastify: '4.x',
name: 'fastify-verify-session',
});

Expand Down
3 changes: 3 additions & 0 deletions packages/backend/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import run from '@rollup/plugin-run';
import json from '@rollup/plugin-json';
import pkg from './package.json';

const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];

Expand All @@ -17,6 +19,7 @@ const plugins = [
exclude: ['**/*.spec.ts', '**/jest.config.ts'],
}),
commonjs(),
json(),
];

const output = {
Expand Down
1 change: 0 additions & 1 deletion packages/backend/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ export const auth: FastifyPluginAsync = async (fastify): Promise<void> => {
schema: {
tags: ['Auth'],
},
preHandler: fastify.auth([fastify.verifySession]),
},
async (request, reply) => {
await request.session.destroy();
Expand Down
Loading

0 comments on commit f4371cd

Please sign in to comment.