Skip to content

Commit

Permalink
fix: errors caused by non-normalized windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
recursive-beast committed Apr 24, 2021
1 parent 76249e4 commit cf9f716
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs/promises";
import path from "path";
import { Plugin } from "rollup";
import { createFilter, FilterPattern } from "@rollup/pluginutils";
import { createFilter, FilterPattern, normalizePath } from "@rollup/pluginutils";
import { parse, print, types, visit } from "recast";
import { getOutputId, getRelativeImportPath, normalizeFilterPattern } from "./helpers";

Expand Down Expand Up @@ -62,26 +62,31 @@ export default function externalAssets(

if (!resolution || !idFilter(resolution.id)) return null;

assets.set(resolution.id, await fs.readFile(resolution.id));
const id = resolution.id;
const normalizedId = normalizePath(id);

this.addWatchFile(resolution.id);
assets.set(normalizedId, await fs.readFile(id));

this.addWatchFile(id);

return {
id: PREFIX + resolution.id,
id: PREFIX + normalizedId,
external: true,
};
},

async load(id) {
if (!idFilter(id)) return null;

assets.set(id, await fs.readFile(id));
const normalizedId = normalizePath(id);

assets.set(normalizedId, await fs.readFile(id));

// Load a proxy module that rollup will discard in favor of inligning the imports.
// The benefit of doing it this way, instead of resolving asset imports to external ids,
// is that we get watch mode support out of the box.
return `export * from "${PREFIX + id}";\n`
+ `export { default } from "${PREFIX + id}";\n`;
return `export * from "${PREFIX + normalizedId}";\n`
+ `export { default } from "${PREFIX + normalizedId}";\n`;
},

async renderChunk(code, chunk, outputOptions) {
Expand Down

0 comments on commit cf9f716

Please sign in to comment.