fix: errors with npm run build && npm run start #168

Merged
Sainan merged 2 commits from pathman into main 2024-05-09 06:10:13 -07:00
2 changed files with 13 additions and 1 deletions
Showing only changes of commit 2816db6b92 - Show all commits

View File

@ -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 ",
OrdisPrime commented 2024-05-06 06:12:00 -07:00 (Migrated from github.com)
Review

the file is called pathman.ts but used as pathman.js here? is that intended?

the file is called pathman.ts but used as pathman.js here? is that intended?
Review

Yes, that's what happens to TS files when they're built.

Yes, that's what happens to TS files when they're built.
"build": "tsc",
"lint": "eslint --ext .ts .",

12
src/pathman.ts Normal file
View File

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