Requested changes

This commit is contained in:
Daniel Hougaard
2024-07-06 01:32:18 +02:00
parent eb90f503a9
commit b4770116a8
5 changed files with 2117 additions and 65 deletions
+4 -6
View File
@@ -2,7 +2,7 @@
"name": "backend", "name": "backend",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "./dist/main.mjs", "main": "./dist/main.js",
"bin": "dist/main.js", "bin": "dist/main.js",
"pkg": { "pkg": {
"scripts": [ "scripts": [
@@ -25,19 +25,17 @@
"outputPath": "binary" "outputPath": "binary"
}, },
"scripts": { "scripts": {
"binary:build": "npm run binary:clean && npm run build:frontend && npm run build && npm run binary:babel-frontend && npm run binary:babel-backend && npm run binary:rename-imports", "binary:build": "npm run binary:clean && npm run build:frontend && npm run build && npm run binary:babel-frontend",
"binary:package": "pkg --no-bytecode --public-packages \"*\" --public --target host .", "binary:package": "pkg --no-bytecode --public-packages \"*\" --public --target host .",
"binary:babel-backend": " babel ./dist -d ./dist",
"binary:babel-frontend": "babel --copy-files ../frontend/.next/server -d ../frontend/.next/server", "binary:babel-frontend": "babel --copy-files ../frontend/.next/server -d ../frontend/.next/server",
"binary:clean": "rm -rf ./dist && rm -rf ./binary", "binary:clean": "rm -rf ./dist && rm -rf ./binary",
"binary:rename-imports": "ts-node ./scripts/rename-mjs.ts",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"dev": "tsx watch --clear-screen=false ./src/main.ts | pino-pretty --colorize --colorizeObjects --singleLine", "dev": "tsx watch --clear-screen=false ./src/main.ts | pino-pretty --colorize --colorizeObjects --singleLine",
"dev:docker": "nodemon", "dev:docker": "nodemon",
"build": "tsup", "build": "tsup",
"build:frontend": "npm run build --prefix ../frontend", "build:frontend": "npm run build --prefix ../frontend",
"start": "node dist/main.mjs", "start": "node dist/main.js",
"type:check": "tsc --noEmit", "type:check": "tsc --noEmit",
"lint:fix": "eslint --fix --ext js,ts ./src", "lint:fix": "eslint --fix --ext js,ts ./src",
"lint": "eslint 'src/**/*.ts'", "lint": "eslint 'src/**/*.ts'",
-27
View File
@@ -1,27 +0,0 @@
/* eslint-disable @typescript-eslint/no-shadow */
import fs from "node:fs";
import path from "node:path";
function replaceMjsOccurrences(directory: string) {
fs.readdir(directory, (err, files) => {
if (err) throw err;
files.forEach((file) => {
const filePath = path.join(directory, file);
if (fs.statSync(filePath).isDirectory()) {
replaceMjsOccurrences(filePath);
} else {
fs.readFile(filePath, "utf8", (err, data) => {
if (err) throw err;
const result = data.replace(/\.mjs/g, ".js");
fs.writeFile(filePath, result, "utf8", (err) => {
if (err) throw err;
// eslint-disable-next-line no-console
console.log(`Updated: ${filePath}`);
});
});
}
});
});
}
replaceMjsOccurrences("dist");
+1 -32
View File
@@ -17,8 +17,7 @@ export default defineConfig({
clean: true, clean: true,
minify: false, minify: false,
keepNames: true, keepNames: true,
splitting: false, splitting: true,
format: "esm",
// copy the files to output // copy the files to output
loader: { loader: {
".handlebars": "copy", ".handlebars": "copy",
@@ -32,37 +31,7 @@ export default defineConfig({
entry: ["./src"], entry: ["./src"],
sourceMap: true, sourceMap: true,
skipNodeModulesBundle: true, skipNodeModulesBundle: true,
esbuildPlugins: [
{
// esm directory import are not allowed
// /folder1 should be explicitly imported as /folder1/index.ts
// this plugin will append it automatically on build time to all imports
name: "commonjs-esm-directory-import",
setup(build) {
build.onResolve({ filter: /.*/ }, async (args) => {
if (args.importer) {
if (args.kind === "import-statement") {
const isRelativePath = args.path.startsWith(".");
const absPath = isRelativePath
? path.join(args.resolveDir, args.path)
: path.join(args.path.replace("@app", "./src"));
const isFile = await fs
.stat(`${absPath}.ts`)
.then((el) => el.isFile)
.catch((err) => err.code === "ENOTDIR");
return {
path: isFile ? `${args.path}.mjs` : `${args.path}/index.mjs`,
external: true
};
}
}
return undefined;
});
}
}
],
async onSuccess() { async onSuccess() {
// this will replace all tsconfig paths // this will replace all tsconfig paths
await replaceTscAliasPaths({ await replaceTscAliasPaths({
+2111
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -20,6 +20,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/uuid": "^9.0.7", "@types/uuid": "^9.0.7",
"@yao-pkg/pkg": "^5.12.0",
"eslint": "^8.29.0", "eslint": "^8.29.0",
"husky": "^8.0.3" "husky": "^8.0.3"
}, },