Skip to content

Commit

Permalink
support relative imports
Browse files Browse the repository at this point in the history
  • Loading branch information
horvbalint committed Feb 15, 2025
1 parent c661248 commit deb5b6f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/rollup/plugins/handlers-meta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from "node:fs/promises";
import { transform } from "esbuild";
import type { Nitro } from "nitropack/types";
import { extname } from "pathe";
import { extname, resolve, dirname } from "pathe";
import type { Plugin } from "rollup";
import MagicString from "magic-string";

Expand Down Expand Up @@ -43,6 +43,8 @@ export function handlersMeta(nitro: Nitro) {
if (!id.startsWith(virtualPrefix)) return;

try {
const dirPath = dirname(id.slice(virtualPrefix.length));

const ext = extname(id) as keyof typeof esbuildLoaders;
const { code: jsCode } = await transform(code, {
loader: esbuildLoaders[ext],
Expand All @@ -57,7 +59,12 @@ export function handlersMeta(nitro: Nitro) {
typeof node.source.value === "string" &&
node.source.value?.startsWith(".")
) {
s.remove(node.start!, node.end!);
const absolutePath = resolve(dirPath, node.source.value);
s.overwrite(
node.source.start!,

Check failure on line 64 in src/rollup/plugins/handlers-meta.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Property 'start' does not exist on type 'Literal'.
node.source.end!,

Check failure on line 65 in src/rollup/plugins/handlers-meta.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Property 'end' does not exist on type 'Literal'.
`"${absolutePath}"`
);
}

// if its the macro call, we remove the code after it and replace it with the export
Expand Down

0 comments on commit deb5b6f

Please sign in to comment.