Merge pull request #418 from TheArcaneBrony/compiler-change

Switch compiler to swc
This commit is contained in:
Flam3rboy 2021-10-08 10:50:32 +02:00 committed by GitHub
commit e261380304
27 changed files with 219 additions and 37 deletions

17
api/.swcrc Normal file
View File

@ -0,0 +1,17 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2021",
"baseUrl": "./",
"paths": {
"@fosscord/api": ["src/index.ts"],
"@fosscord/api/*": ["src/*"]
}
}
}

View File

@ -1,11 +0,0 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@util/*": ["./src/util/*"],
"@middlewares/*": ["./src/middlewares/*"],
"@schema/*": ["./src/schema/*"]
}
},
"include": ["src"]
}

BIN
api/package-lock.json generated

Binary file not shown.

View File

@ -2,8 +2,8 @@
"name": "@fosscord/api",
"version": "1.0.0",
"description": "This repository contains the HTTP API Server",
"main": "dist/Server.js",
"types": "dist/Server.d.ts",
"main": "dist/index.js",
"types": "src/index.ts",
"scripts": {
"test:only": "jest --coverage --verbose --forceExit ./tests",
"test:routes": "jest --coverage --verbose --forceExit ./routes.test.ts",
@ -40,6 +40,8 @@
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.6",
"@babel/preset-typescript": "^7.15.0",
"@swc/cli": "^0.1.51",
"@swc/core": "^1.2.93",
"@types/amqplib": "^0.8.1",
"@types/bcrypt": "^5.0.0",
"@types/express": "^4.17.9",
@ -67,6 +69,7 @@
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",
"ts-patch": "^1.4.4",
"tsup": "^5.4.0",
"typescript": "^4.4.2",
"typescript-json-schema": "0.50.1"
},
@ -84,6 +87,7 @@
"dot-prop": "^6.0.1",
"dotenv": "^8.2.0",
"env-paths": "^2.2.1",
"esbuild": "^0.13.4",
"express": "^4.17.1",
"express-validator": "^6.9.2",
"form-data": "^3.0.0",
@ -102,7 +106,8 @@
"patch-package": "^6.4.7",
"supertest": "^6.1.6",
"tsconfig-paths": "^3.11.0",
"typeorm": "^0.2.37"
"typeorm": "^0.2.37",
"wsc": "^0.3.0"
},
"jest": {
"setupFiles": [

View File

@ -7,7 +7,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2020"] /* Specify library files to be included in the compilation. */,
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */

View File

@ -7,7 +7,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2020"] /* Specify library files to be included in the compilation. */,
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */

12
bundle/.swcrc Normal file
View File

@ -0,0 +1,12 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2021"
}
}

BIN
bundle/package-lock.json generated

Binary file not shown.

View File

@ -5,15 +5,10 @@
"main": "src/start.js",
"scripts": {
"setup": "cd ../util && npm --production=false i && cd ../api && npm --production=false i && cd ../cdn && npm --production=false i && cd ../gateway && npm --production=false i && cd ../bundle/ && npm --production=false i && npm run build",
"build": "npm run build:util && npm run build:api && npm run build:cdn && npm run build:gateway && npm run build:bundle",
"postinstall": "ts-patch install -s",
"build": "node scripts/build.js",
"build:bundle": "npx tsc -b .",
"build:util": "cd ../util/ && npm run build",
"build:api": "cd ../api/ && npm run build",
"build:cdn": "cd ../cdn/ && npm run build",
"build:gateway": "cd ../gateway/ && npm run build",
"start": "npm run build && npm run start:bundle",
"start:bundle": "node dist/start.js",
"start": "node scripts/build.js && node -r tsconfig-paths/register dist/start.js",
"start:bundle": "node -r tsconfig-paths/register dist/start.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@ -28,6 +23,8 @@
},
"homepage": "https://fosscord.com",
"devDependencies": {
"@swc/cli": "^0.1.51",
"@swc/core": "^1.2.93",
"@types/amqplib": "^0.8.1",
"@types/async-exit-hook": "^2.0.0",
"@types/bcrypt": "^5.0.0",
@ -44,9 +41,12 @@
"@types/uuid": "^8.3.0",
"@types/ws": "^7.4.0",
"@zerollup/ts-transform-paths": "^1.7.18",
"esbuild": "^0.13.4",
"esbuild-plugin-tsc": "^0.3.0",
"ts-node": "^10.2.1",
"ts-patch": "^1.4.4",
"typescript": "^4.3.5"
"tsconfig-paths": "^3.11.0",
"typescript": "^4.4.3"
},
"dependencies": {
"@fosscord/api": "file:../api",
@ -59,6 +59,6 @@
"missing-native-js-functions": "^1.2.17",
"nanocolors": "^0.2.12",
"node-os-utils": "^1.3.5",
"tsconfig-paths": "^3.11.0"
"reflect-metadata": "^0.1.13"
}
}

70
bundle/scripts/build.js Normal file
View File

@ -0,0 +1,70 @@
const { spawn } = require("child_process");
const path = require("path");
const { performance } = require("perf_hooks");
const fs = require("fs");
const esbuildPluginTsc = require("esbuild-plugin-tsc");
let parts = "api,cdn,gateway,bundle".split(",");
const tscBin = path.join(__dirname, "..", "..", "util", "node_modules", "typescript", "bin", "tsc");
const swcBin = path.join(__dirname, "..", "..", "util", "node_modules", "@swc", "cli", "bin", "swc");
// because npm run is slow we directly get the build script of the package.json script
function buildPackage(dir) {
const element = path.basename(dir);
require("esbuild").build({
entryPoints: walk(path.join(dir, "src")),
bundle: false,
outdir: path.join(dir, "dist"),
target: "es2021",
format: "cjs",
plugins: [esbuildPluginTsc({})],
keepNames: true,
});
}
function util() {
// const child = spawn("node", `${swcBin} src --out-dir dist --sync`.split(" "), {
const child = spawn("node", `${tscBin} -b .`.split(" "), {
cwd: path.join(__dirname, "..", "..", "util"),
env: process.env,
shell: true,
});
function log(data) {
console.log(`[util] ` + data.toString().slice(0, -1));
}
child.stdout.on("data", log);
child.stderr.on("data", log);
child.on("error", (err) => console.error("util", err));
return child;
}
const start = performance.now();
console.log("[Build] starting ...");
util();
for (const part of parts) {
buildPackage(path.join(__dirname, "..", "..", part));
}
process.on("exit", () => {
console.log("[Build] took " + Math.round(performance.now() - start) + "ms");
});
function walk(dir) {
var results = [];
var list = fs.readdirSync(dir);
list.forEach(function (file) {
file = dir + "/" + file;
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
/* Recurse into a subdirectory */
results = results.concat(walk(file));
} else if (file.endsWith(".ts")) {
/* Is a file */
results.push(file);
}
});
return results;
}

View File

@ -1,4 +1,20 @@
// process.env.MONGOMS_DEBUG = "true";
const tsConfigPaths = require("tsconfig-paths");
const path = require("path");
const baseUrl = path.join(__dirname, ".."); // Either absolute or relative path. If relative it's resolved to current working directory.
const cleanup = tsConfigPaths.register({
baseUrl,
paths: {
"@fosscord/api": ["../api/dist/index.js"],
"@fosscord/api/*": ["../api/dist/*"],
"@fosscord/gateway": ["../gateway/dist/index.js"],
"@fosscord/gateway/*": ["../gateway/dist/*"],
"@fosscord/cdn": ["../cdn/dist/index.js"],
"@fosscord/cdn/*": ["../cdn/dist/*"],
},
});
import "reflect-metadata";
import cluster from "cluster";
import os from "os";
import { red, bold, yellow, cyan } from "nanocolors";

View File

@ -4,10 +4,10 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"incremental": true /* Enable incremental compilation */,
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2020"] /* Specify library files to be included in the compilation. */,
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
@ -63,6 +63,8 @@
/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}

17
cdn/.swcrc Normal file
View File

@ -0,0 +1,17 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2021",
"baseUrl": ".",
"paths": {
"@fosscord/cdn/": ["src/index"],
"@fosscord/cdn/*": ["src/*"]
}
}
}

BIN
cdn/package-lock.json generated

Binary file not shown.

View File

@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "cdn for fosscord",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "src/index.ts",
"scripts": {
"postinstall": "ts-patch install -s",
"test": "npm run build && jest --coverage ./tests",
@ -22,6 +22,8 @@
},
"homepage": "https://github.com/fosscord/fosscord-server#readme",
"devDependencies": {
"@swc/cli": "^0.1.51",
"@swc/core": "^1.2.93",
"@types/amqplib": "^0.8.1",
"@types/body-parser": "^1.19.0",
"@types/btoa": "^1.2.3",

View File

@ -4,7 +4,7 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"incremental": true, /* Enable incremental compilation */
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2015", "dom"] /* Specify library files to be included in the compilation. */,

17
gateway/.swcrc Normal file
View File

@ -0,0 +1,17 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2021",
"baseUrl": ".",
"paths": {
"@fosscord/gateway": ["src/index"],
"@fosscord/gateway/*": ["src/*"]
}
}
}

Binary file not shown.

View File

@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"types": "src/index.ts",
"scripts": {
"postinstall": "npx ts-patch install -s",
"test": "echo \"Error: no test specified\" && exit 1",
@ -14,6 +15,8 @@
"author": "Fosscord",
"license": "ISC",
"devDependencies": {
"@swc/cli": "^0.1.51",
"@swc/core": "^1.2.93",
"@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongodb": "^3.6.9",

View File

@ -5,7 +5,7 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"incremental": true, /* Enable incremental compilation */
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2015", "ES2020.BigInt", "DOM"] /* Specify library files to be included in the compilation. */,

18
util/.swcrc Normal file
View File

@ -0,0 +1,18 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2021",
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"keepClassNames": true,
"loose": true
}
}

BIN
util/package-lock.json generated

Binary file not shown.

View File

@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "Utility functions for the all server repositories",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "src/index.ts",
"scripts": {
"start": "npm run build && node dist/",
"test": "npm run build && jest",
@ -28,6 +28,8 @@
},
"homepage": "https://docs.fosscord.com/",
"devDependencies": {
"@swc/cli": "^0.1.51",
"@swc/core": "^1.2.93",
"@types/amqplib": "^0.8.1",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongoose-autopopulate": "^0.10.1",

View File

@ -1,5 +1,5 @@
// @ts-nocheck
import cluster from "cluster";
import * as cluster from "cluster";
// https://github.com/discordjs/discord.js/blob/master/src/util/Snowflake.js
// Apache License Version 2.0 Copyright 2015 - 2021 Amish Shah

View File

@ -4,10 +4,10 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"incremental": true, /* Enable incremental compilation */
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2020"] /* Specify library files to be included in the compilation. */,
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */

12
webrtc/.swcrc Normal file
View File

@ -0,0 +1,12 @@
{
"module": {
"type": "commonjs"
},
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2021"
}
}

View File

@ -7,7 +7,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2020"] /* Specify library files to be included in the compilation. */,
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */