Skip to content

Build your personal knowledge base with Trilium Notes

chore(nx/desktop): switch to webpack-based build

Elian Doran15fbe4131243
diff --git a/apps/desktop-e2e/.spec.swcrc b/apps/desktop-e2e/.spec.swcrc
new file mode 100644
index 0000000000..3b52a5376b
--- /dev/null
+++ b/apps/desktop-e2e/.spec.swcrc
@@ -0,0 +1,22 @@
+{
+ "jsc": {
+ "target": "es2017",
+ "parser": {
+ "syntax": "typescript",
+ "decorators": true,
+ "dynamicImport": true
+ },
+ "transform": {
+ "decoratorMetadata": true,
+ "legacyDecorator": true
+ },
+ "keepClassNames": true,
+ "externalHelpers": true,
+ "loose": true
+ },
+ "module": {
+ "type": "es6"
+ },
+ "sourceMaps": true,
+ "exclude": []
+}
diff --git a/apps/desktop-e2e/eslint.config.mjs b/apps/desktop-e2e/eslint.config.mjs
new file mode 100644
index 0000000000..724052a2e2
--- /dev/null
+++ b/apps/desktop-e2e/eslint.config.mjs
@@ -0,0 +1,5 @@
+import baseConfig from "../../eslint.config.mjs";
+
+export default [
+ ...baseConfig
+];
diff --git a/apps/desktop-e2e/jest.config.ts b/apps/desktop-e2e/jest.config.ts
new file mode 100644
index 0000000000..25564ee814
--- /dev/null
+++ b/apps/desktop-e2e/jest.config.ts
@@ -0,0 +1,24 @@
+/* eslint-disable */
+import { readFileSync } from 'fs';
+
+// Reading the SWC compilation config for the spec files
+const swcJestConfig = JSON.parse(
+ readFileSync(`${__dirname}/.spec.swcrc`, 'utf-8')
+);
+
+// Disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves
+swcJestConfig.swcrc = false;
+
+export default {
+ displayName: '@triliumnext/desktop-e2e',
+ preset: '../../jest.preset.js',
+ globalSetup: '<rootDir>/src/support/global-setup.ts',
+ globalTeardown: '<rootDir>/src/support/global-teardown.ts',
+ setupFiles: ['<rootDir>/src/support/test-setup.ts'],
+ testEnvironment: 'node',
+ transform: {
+ '^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
+ },
+ moduleFileExtensions: ['ts', 'js', 'html'],
+ coverageDirectory: 'test-output/jest/coverage',
+};
diff --git a/apps/desktop-e2e/package.json b/apps/desktop-e2e/package.json
new file mode 100644
index 0000000000..37556fa95c
--- /dev/null
+++ b/apps/desktop-e2e/package.json
@@ -0,0 +1,25 @@
+{
+ "name": "@triliumnext/desktop-e2e",
+ "version": "0.0.1",
+ "private": true,
+ "nx": {
+ "implicitDependencies": [
+ "@triliumnext/desktop"
+ ],
+ "targets": {
+ "e2e": {
+ "executor": "@nx/jest:jest",
+ "outputs": [
+ "{projectRoot}/test-output/jest/coverage"
+ ],
+ "options": {
+ "jestConfig": "apps/desktop-e2e/jest.config.ts",
+ "passWithNoTests": true
+ },
+ "dependsOn": [
+ "@triliumnext/desktop:build"
+ ]
+ }
+ }
+ }
+}
diff --git a/apps/desktop-e2e/src/desktop/desktop.spec.ts b/apps/desktop-e2e/src/desktop/desktop.spec.ts
new file mode 100644
index 0000000000..52572d00fd
--- /dev/null
+++ b/apps/desktop-e2e/src/desktop/desktop.spec.ts
@@ -0,0 +1,10 @@
+import axios from 'axios';
+
+describe('GET /', () => {
+ it('should return a message', async () => {
+ const res = await axios.get(`/`);
+
+ expect(res.status).toBe(200);
+ expect(res.data).toEqual({ message: 'Hello API' });
+ });
+})
diff --git a/apps/desktop-e2e/src/support/global-setup.ts b/apps/desktop-e2e/src/support/global-setup.ts
new file mode 100644
index 0000000000..d18e0f2947
--- /dev/null
+++ b/apps/desktop-e2e/src/support/global-setup.ts
@@ -0,0 +1,11 @@
+/* eslint-disable */
+var __TEARDOWN_MESSAGE__: string;
+
+module.exports = async function() {
+ // Start services that that the app needs to run (e.g. database, docker-compose, etc.).
+ console.log('\nSetting up...\n');
+
+ // Hint: Use `globalThis` to pass variables to global teardown.
+ globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
+};
+
diff --git a/apps/desktop-e2e/src/support/global-teardown.ts b/apps/desktop-e2e/src/support/global-teardown.ts
new file mode 100644
index 0000000000..67746cebd3
--- /dev/null
+++ b/apps/desktop-e2e/src/support/global-teardown.ts
@@ -0,0 +1,7 @@
+/* eslint-disable */
+
+module.exports = async function() {
+ // Put clean up logic here (e.g. stopping services, docker-compose, etc.).
+ // Hint: `globalThis` is shared between setup and teardown.
+ console.log(globalThis.__TEARDOWN_MESSAGE__);
+};
diff --git a/apps/desktop-e2e/src/support/test-setup.ts b/apps/desktop-e2e/src/support/test-setup.ts
new file mode 100644
index 0000000000..c803356a28
--- /dev/null
+++ b/apps/desktop-e2e/src/support/test-setup.ts
@@ -0,0 +1,9 @@
+/* eslint-disable */
+import axios from 'axios';
+
+module.exports = async function() {
+ // Configure axios for tests to use.
+ const host = process.env.HOST ?? 'localhost';
+ const port = process.env.PORT ?? '3000';
+ axios.defaults.baseURL = `http://${host}:${port}`;
+};
diff --git a/apps/desktop-e2e/tsconfig.json b/apps/desktop-e2e/tsconfig.json
new file mode 100644
index 0000000000..2e98c0f609
--- /dev/null
+++ b/apps/desktop-e2e/tsconfig.json
@@ -0,0 +1,14 @@
+{
+ "extends": "../../tsconfig.base.json",
+ "compilerOptions": {
+ "outDir": "out-tsc/@triliumnext/desktop-e2e",
+ "esModuleInterop": true,
+ "noUnusedLocals": false,
+ "noImplicitAny": false
+ },
+ "include": [
+ "jest.config.ts",
+ "src/**/*.ts"
+ ],
+ "references": []
+}
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index b0691054ab..66428c0729 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -4,43 +4,6 @@
"private": true,
"nx": {
"targets": {
- "build": {
- "executor": "@nx/esbuild:esbuild",
- "outputs": [
- "{options.outputPath}"
- ],
- "defaultConfiguration": "production",
- "options": {
- "platform": "node",
- "outputPath": "apps/desktop/dist",
- "format": [
- "cjs"
- ],
- "bundle": false,
- "main": "apps/desktop/src/main.ts",
- "tsConfig": "apps/desktop/tsconfig.app.json",
- "assets": [
- "apps/desktop/src/assets"
- ],
- "esbuildOptions": {
- "sourcemap": true,
- "outExtension": {
- ".js": ".js"
- }
- }
- },
- "configurations": {
- "development": {},
- "production": {
- "esbuildOptions": {
- "sourcemap": false,
- "outExtension": {
- ".js": ".js"
- }
- }
- }
- }
- },
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index 73c02658c4..a8a385463e 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -1 +1,21 @@
-console.log('Hello World');
\ No newline at end of file
+/**
+ * This is not a production server yet!
+ * This is only a minimal backend to get started.
+ */
+
+import express from 'express';
+import * as path from 'path';
+
+const app = express();
+
+app.use('/assets', express.static(path.join(__dirname, 'assets')));
+
+app.get('/api', (req, res) => {
+ res.send({ message: 'Welcome to desktop!' });
+});
+
+const port = process.env.PORT || 3333;
+const server = app.listen(port, () => {
+ console.log(`Listening at http://localhost:${port}/api`);
+});
+server.on('error', console.error);
diff --git a/apps/desktop/tsconfig.app.json b/apps/desktop/tsconfig.app.json
index bdf9ba8617..b293e155dc 100644
--- a/apps/desktop/tsconfig.app.json
+++ b/apps/desktop/tsconfig.app.json
@@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "dist",
"types": [
- "node"
+ "node",
+ "express"
],
"rootDir": "src",
"tsBuildInfoFile": "dist/tsconfig.app.tsbuildinfo"
diff --git a/apps/desktop/webpack.config.js b/apps/desktop/webpack.config.js
new file mode 100644
index 0000000000..4f8180c8e3
--- /dev/null
+++ b/apps/desktop/webpack.config.js
@@ -0,0 +1,20 @@
+const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
+const { join } = require('path');
+
+module.exports = {
+ output: {
+ path: join(__dirname, 'dist'),
+ },
+ plugins: [
+ new NxAppWebpackPlugin({
+ target: 'node',
+ compiler: 'tsc',
+ main: './src/main.ts',
+ tsConfig: './tsconfig.app.json',
+ assets: ["./src/assets"],
+ optimization: false,
+ outputHashing: 'none',
+ generatePackageJson: true,
+ })
+ ],
+};