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

This commit is contained in:
Elian Doran 2025-04-23 13:10:13 +03:00
parent 492e953517
commit 15fbe41312
No known key found for this signature in database
13 changed files with 170 additions and 39 deletions

View File

@ -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": []
}

View File

@ -0,0 +1,5 @@
import baseConfig from "../../eslint.config.mjs";
export default [
...baseConfig
];

View File

@ -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',
};

View File

@ -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"
]
}
}
}
}

View File

@ -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' });
});
})

View File

@ -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';
};

View File

@ -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__);
};

View File

@ -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}`;
};

View File

@ -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": []
}

View File

@ -4,43 +4,6 @@
"private": true, "private": true,
"nx": { "nx": {
"targets": { "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": { "serve": {
"executor": "@nx/js:node", "executor": "@nx/js:node",
"defaultConfiguration": "development", "defaultConfiguration": "development",

View File

@ -1 +1,21 @@
console.log('Hello World'); /**
* 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);

View File

@ -3,7 +3,8 @@
"compilerOptions": { "compilerOptions": {
"outDir": "dist", "outDir": "dist",
"types": [ "types": [
"node" "node",
"express"
], ],
"rootDir": "src", "rootDir": "src",
"tsBuildInfoFile": "dist/tsconfig.app.tsbuildinfo" "tsBuildInfoFile": "dist/tsconfig.app.tsbuildinfo"

View File

@ -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,
})
],
};