diff --git a/package.json b/package.json index 1c987971..23b401a6 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "WF Emulator", "main": "index.ts", "scripts": { - "start": "node build/index.js", + "start": "node --import ./build/src/pathman.js build/src/index.js", "dev": "ts-node-dev --openssl-legacy-provider -r tsconfig-paths/register src/index.ts ", "build": "tsc", "lint": "eslint --ext .ts .", diff --git a/src/pathman.ts b/src/pathman.ts new file mode 100644 index 00000000..1e1d5127 --- /dev/null +++ b/src/pathman.ts @@ -0,0 +1,12 @@ +// Hooks node to support require from "@/" paths for `npm run build && npm run start`. +// Based on https://github.com/dividab/tsconfig-paths + +const Module = require("module"); +const originalResolveFilename = Module._resolveFilename; +Module._resolveFilename = function (request: string, _parent: any): string { + if (request.substring(0, 2) == "@/") { + const modifiedArguments = [process.cwd() + "/build/" + request.substr(2), ...[].slice.call(arguments, 1)]; // Passes all arguments. Even those that is not specified above. + return originalResolveFilename.apply(this, modifiedArguments); + } + return originalResolveFilename.apply(this, arguments); +};