Download scripts/alias-hooks.mjs from helo-ayush/NewIntentExtractor: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/helo-ayush/NewIntentExtractor/resolve/main/scripts/alias-hooks.mjs
- Command line
-
hf download hf://spaces/helo-ayush/NewIntentExtractor/scripts/alias-hooks.mjs
-
curl -L -o alias-hooks.mjs https://huggingface.co/spaces/helo-ayush/NewIntentExtractor/resolve/main/scripts/alias-hooks.mjs
1.4 kB
| /** | |
| * Resolves the `@/*` -> `src/*` TypeScript path alias for plain `node` runs. | |
| * | |
| * Node reads neither tsconfig.json nor its `paths`, so maintenance scripts that | |
| * import app modules (`@/models/teams`) fail to resolve without this. Node 24 | |
| * strips the TypeScript itself; only the alias and the missing file extension | |
| * need handling. | |
| * | |
| * Registered via `--import ./scripts/register-alias.mjs` in the npm scripts. | |
| */ | |
| import { existsSync } from "node:fs"; | |
| import path from "node:path"; | |
| import { fileURLToPath, pathToFileURL } from "node:url"; | |
| const __dirname = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url)); | |
| const SRC = path.resolve(__dirname, "..", "src"); | |
| // Extensionless imports need a suffix; try the same order tsc would. | |
| const CANDIDATES = ["", ".ts", ".tsx", ".js", ".mjs", "/index.ts", "/index.tsx"]; | |
| export async function resolve(specifier, context, next) { | |
| if (specifier === "server-only") { | |
| return next("next/dist/compiled/server-only/empty", context); | |
| } | |
| if (!specifier.startsWith("@/")) return next(specifier, context); | |
| const base = path.join(SRC, specifier.slice(2)); | |
| for (const ext of CANDIDATES) { | |
| const candidate = base + ext; | |
| if (existsSync(candidate)) { | |
| return next(pathToFileURL(candidate).href, context); | |
| } | |
| } | |
| throw new Error( | |
| `[register-alias] could not resolve "${specifier}" under ${SRC}` | |
| ); | |
| } | |