From 68f6fe58d5266af4a38e86ed2f817df3638f2323 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 6 Mar 2022 17:18:35 +1100 Subject: [PATCH] Tsnode support (#580) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ts-node support. debugging is slightly wonky as vscode will not allow breakpoints in modules that aren't bundle, yet. * apparently ts-node compilerOptions.path wasn't needed? on windows I could've sworn it was. * Cleaned up tsconfig.json a bit ( moved tsnode config to own file ). Fixed breakpoints for all modules under tsnode * Removed Microsoft Corp advert * Remove one more Microsoft Corp. ad Signed-off-by: Erkin Alp Güney * Added `tsnode` npm script * Added `typescript-cached-transpile` package to help improve performance Co-authored-by: Erkin Alp Güney --- bundle/.vscode/launch.json | 53 ++++++--- bundle/package-lock.json | Bin 588826 -> 595145 bytes bundle/package.json | 5 +- bundle/tsconfig.json | 171 ++++++++++++++--------------- bundle/tsnode.tsconfig.json | 15 +++ util/src/util/TraverseDirectory.ts | 5 +- 6 files changed, 143 insertions(+), 106 deletions(-) create mode 100644 bundle/tsnode.tsconfig.json diff --git a/bundle/.vscode/launch.json b/bundle/.vscode/launch.json index aa4e743a..d7129ed8 100644 --- a/bundle/.vscode/launch.json +++ b/bundle/.vscode/launch.json @@ -1,18 +1,35 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "sourceMaps": true, - "type": "node", - "request": "launch", - "name": "Launch Server", - "program": "${workspaceFolder}/dist/bundle/src/start.js", - "preLaunchTask": "tsc: build - tsconfig.json", - "outFiles": ["${workspaceFolder}/dist/**/*.js"], - "envFile": "${workspaceFolder}/.env" - } - ] -} +{ + "version": "0.2.0", + "configurations": [ + { + "sourceMaps": true, + "name": "ts-node", + "type": "node", + "request": "launch", + "args": [ + "${workspaceFolder}/src/start.ts" + ], + "runtimeArgs": [ + "-r", + "ts-node/register" + ], + "protocol": "inspector", + "internalConsoleOptions": "openOnSessionStart", + "env": { + "TS_NODE_PROJECT": "${workspaceFolder}/tsnode.tsconfig.json", + "TS_NODE_COMPILER": "typescript-cached-transpile" + }, + "resolveSourceMapLocations": null, /* allow breakpoints in modules other than bundle */ + }, + { + "sourceMaps": true, + "type": "node", + "request": "launch", + "name": "Launch Server", + "program": "${workspaceFolder}/dist/bundle/src/start.js", + "preLaunchTask": "tsc: build - tsconfig.json", + "outFiles": ["${workspaceFolder}/dist/**/*.js"], + "envFile": "${workspaceFolder}/.env", + } + ] +} diff --git a/bundle/package-lock.json b/bundle/package-lock.json index a9129c243d83e5d96552c5274371f8c8f6de1996..7fe4317aff5a6f9ad7f8fdd3f04f75358613908e 100644 GIT binary patch delta 2212 zcmdUve{2(F7{_zF>-FWwI)>YDB?v3q8dt8pYrA$eCeW33Tf4T`tv_f@kp8%?zjpoI zbyd^^6aEp@H1Z@Oh7h7dh0PdJlWBm6i9;nr6Es8&{Nq0um46J0$>Oz(ER*q%kwh=| z=DoY;x#xYJ=l#B)H}CCSIMY3Mo|J}z;TRX83b`Pk&%{%l?5Q2H{j`!+>Z;1kvX3s4 zck#}AIL$}n6I3Qxh~*m&8YQDv(lWSx6}43lv=g9sg4}RuaeZxZJ+^cnY8Jd5=nfDv?j~{VHmCrs}H*c2_&GbsIzJiNR$MZC+y^#>z4 z-syMiDp@b@%La=2xN6X)8RTP?(oiU2PH+j!KBt;a*+y)cDR;1#Nt)ORbF`!#3fP#D z!EoH_F~|IQja8G;_gf-Cx5Zoi@CE~OpJJrEQQ`d_stvMT>(>dFY~?#6RLwy46wwJ! z_Yf`c{5+Dt`$@3`PQE9+o;*vC;^j`O;2jIz3v3x}gsorT^48Vu69Pfz2-f8Z+Qzj$ zSAymEv2xs%HyJc`M>J7Z@F9zqHAeiE$%u-vjwA+#{grGqR23VDGh8gq3yuV66r=gHQ|RADfC??nj!u*QGx@P2m)po2(e_f`~dSebu@$n zOBWD=?@wUz-3{r4g>?$lYVQ_pn{-&Y8jeLB{W9PSSq^eUs%u1K&P zj&+i1rJ7c1!T1J7cP^h8J{_r7S)V9jfrdGI1l!?>>dMY+F&x?(&kgBEofR&UDOD1z z#^atGE)>SnMU6e3FKbGphN+yvIN}ZS}Cxs!d&GG28 zom{5ie~UcOIwPXsR+jvy=&63NxB)T-vP0CM3mC7WZg|B?u0@;RUUH}Rk@j=JiI>4tl|QCDs36V$v(CcyS!ow%}xV&VUWm@boO zTYY~eYcM8gAbViX3?>#BB!=H|qzG=9kwp9#C@vXEM!M(WAPF8sGVdb+iK|9PP#J@k zUbL&Rjqu`TbR2p~Q6Ic&A?HD^KzjH?j2Z`80WUm;wt(s!^23)3)K)8hg-)sd1W;h> AUjP6A delta 127 zcmV-_0D%9=sU({CBe1mwlaCS)v+)M;1DDIRu?0g2Gmr$|+ zNr&IU0f*nh0=M7714r$*O|%3L8kbwP0T7q3+yM=jY0dE diff --git a/bundle/package.json b/bundle/package.json index 0b3fc817..c33605e4 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -9,7 +9,8 @@ "start": "node scripts/build.js && node dist/bundle/src/start.js", "start:bundle": "node dist/bundle/src/start.js", "test": "echo \"Error: no test specified\" && exit 1", - "migrate": "cd ../util/ && npm i && node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run" + "migrate": "cd ../util/ && npm i && node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run", + "tsnode": "npx ts-node --transpile-only -P tsnode.tsconfig.json src/start.ts" }, "repository": { "type": "git", @@ -51,6 +52,7 @@ "ts-node": "^10.2.1", "ts-node-dev": "^1.1.6", "ts-patch": "^1.4.4", + "tsconfig-paths": "^3.12.0", "typescript": "^4.2.3", "typescript-json-schema": "0.50.1" }, @@ -104,6 +106,7 @@ "tslib": "^2.3.1", "typeorm": "^0.2.37", "typescript": "^4.1.2", + "typescript-cached-transpile": "^0.0.6", "typescript-json-schema": "^0.50.1", "ws": "^7.4.2", "nan": "^2.15.0" diff --git a/bundle/tsconfig.json b/bundle/tsconfig.json index 2257b4ab..563ff444 100644 --- a/bundle/tsconfig.json +++ b/bundle/tsconfig.json @@ -1,86 +1,85 @@ -{ - "include": ["dist/**/*.ts"], - "exclude": [], - "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Basic Options */ - "incremental": false /* 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": [ - "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'. */ - "declaration": false /* Generates corresponding '.d.ts' file. */, - "declarationMap": false /* Generates a sourcemap for each corresponding '.d.ts' file. */, - "sourceMap": false /* Generates corresponding '.map' file. */, - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist/" /* Redirect output structure to the directory. */, - "rootDir": "./dist/" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, - // "composite": true, /* Enable project compilation */ - // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */, - "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, - "strictNullChecks": true /* Enable strict null checks. */, - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - "strictPropertyInitialization": false /* Enable strict checking of property initialization in classes. */, - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - - /* Module Resolution Options */ - "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - "types": [ - "node" - ] /* Type declaration files to be included in compilation. */, - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - - /* Advanced Options */ - "skipLibCheck": true /* Skip type checking of declaration files. */, - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "resolveJsonModule": true, - "baseUrl": "./dist/", - "paths": { - "@fosscord/api": ["api/src/index"], - "@fosscord/gateway": ["gateway/src/index"], - "@fosscord/cdn": ["cdn/src/index"], - "@fosscord/util": ["util/src/index"] - }, - "plugins": [{ "transform": "@zerollup/ts-transform-paths" }], - "noEmitHelpers": true, - "importHelpers": true - } -} +{ + "include": ["dist/**/*.ts"], + "exclude": [], + "compilerOptions": { + + /* Basic Options */ + "incremental": false /* 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": [ + "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'. */ + "declaration": false /* Generates corresponding '.d.ts' file. */, + "declarationMap": false /* Generates a sourcemap for each corresponding '.d.ts' file. */, + "sourceMap": true /* Generates corresponding '.map' file. */, + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./dist/" /* Redirect output structure to the directory. */, + "rootDir": "./dist/" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */, + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true /* Enable all strict type-checking options. */, + "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + "strictNullChecks": true /* Enable strict null checks. */, + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + "strictPropertyInitialization": false /* Enable strict checking of property initialization in classes. */, + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + "types": [ + "node" + ] /* Type declaration files to be included in compilation. */, + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true /* Skip type checking of declaration files. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "resolveJsonModule": true, + "baseUrl": "./dist/", + "paths": { + "@fosscord/api": ["api/src/index"], + "@fosscord/gateway": ["gateway/src/index"], + "@fosscord/cdn": ["cdn/src/index"], + "@fosscord/util": ["util/src/index"] + }, + "plugins": [{ "transform": "@zerollup/ts-transform-paths" }], + "noEmitHelpers": true, + "importHelpers": true + } +} diff --git a/bundle/tsnode.tsconfig.json b/bundle/tsnode.tsconfig.json new file mode 100644 index 00000000..422d336c --- /dev/null +++ b/bundle/tsnode.tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "ts-node": { + "transpileOnly": true, + "preferTsExts": true, + "require": ["tsconfig-paths/register"], + "compiler": "typescript-cached-transpile", + }, + "compilerOptions": { + "rootDir": "../", + "baseUrl": "../", + "sourceRoot": "../", + "sourceMap": true, + } +} \ No newline at end of file diff --git a/util/src/util/TraverseDirectory.ts b/util/src/util/TraverseDirectory.ts index 275b7dcc..3d0d6279 100644 --- a/util/src/util/TraverseDirectory.ts +++ b/util/src/util/TraverseDirectory.ts @@ -1,6 +1,9 @@ import { Server, traverseDirectory } from "lambert-server"; -const DEFAULT_FILTER = /^([^\.].*)(?