Skip to content

Commit

Permalink
fix(cli): fix alias module resolution on Windows OS
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Jan 25, 2025
1 parent 4969bbe commit 65ed90f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"@tsed/schema": ">=8.0.0",
"chalk": "^5.3.0",
"change-case": "^5.4.4",
"esm-module-alias": "^2.2.1",
"globby": "^14.0.2",
"read-pkg-up": "^11.0.0",
"semver": "^7.6.3",
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/bin/tsed.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env node
import {register} from "node:module";
import {join} from "node:path";
import {fileURLToPath, pathToFileURL} from "node:url";

const EXT = process.env.CLI_MODE === "ts" ? "ts" : "js";

register(pathToFileURL(`${import.meta.dirname}/../loaders/alias.hook.${EXT}`), {
register(pathToFileURL(join(import.meta.dirname, `../loaders/alias.hook.${EXT}`)), {
parentURL: import.meta.dirname,
data: {
"@tsed/core": fileURLToPath(import.meta.resolve("@tsed/core")),
"@tsed/di": fileURLToPath(import.meta.resolve("@tsed/di")),
"@tsed/schema": fileURLToPath(import.meta.resolve("@tsed/schema")),
"@tsed/cli-core": fileURLToPath(import.meta.resolve("@tsed/cli-core")),
"@tsed/cli": fileURLToPath(import.meta.resolve("@tsed/cli"))
"@tsed/core": import.meta.resolve("@tsed/core"),
"@tsed/di": import.meta.resolve("@tsed/di"),
"@tsed/schema": import.meta.resolve("@tsed/schema"),
"@tsed/cli-core": import.meta.resolve("@tsed/cli-core"),
"@tsed/cli": import.meta.resolve("@tsed/cli")
},
transferList: []
});
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/src/loaders/alias.hook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import generateAliasesResolver from "esm-module-alias";
function generateAliasesResolver(aliases: Record<string, string>, options?: any) {
return (specifier: any, parentModuleURL: any, defaultResolve: any) => {
if (aliases[specifier]) {
return defaultResolve(aliases[specifier], parentModuleURL);
}

return defaultResolve(specifier, parentModuleURL);
};
}

let resolver: any = null;

export async function initialize(aliases: Record<string, string>) {
// Receives data from `register`.
resolver = generateAliasesResolver(aliases);
}

Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,6 @@ __metadata:
chalk: "npm:^5.3.0"
change-case: "npm:^5.4.4"
cross-env: "npm:7.0.3"
esm-module-alias: "npm:^2.2.1"
globby: "npm:^14.0.2"
read-pkg-up: "npm:^11.0.0"
semver: "npm:^7.6.3"
Expand Down Expand Up @@ -6703,13 +6702,6 @@ __metadata:
languageName: node
linkType: hard

"esm-module-alias@npm:^2.2.1":
version: 2.2.1
resolution: "esm-module-alias@npm:2.2.1"
checksum: 10/2dda8bdde12b7b6fdfe7dd0efc4abe15c09af26f62cf5540d3df464dfe1be6a9a627105d5b6ea940f0be4d87c78c15db192fff821be7869b16cc9a1e678b8b31
languageName: node
linkType: hard

"espree@npm:^10.0.1, espree@npm:^10.1.0":
version: 10.1.0
resolution: "espree@npm:10.1.0"
Expand Down

0 comments on commit 65ed90f

Please sign in to comment.