Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 14, 2024
1 parent 3bc15f7 commit 6213817
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type RollupOptions, rollup } from "rollup";
import { JspmError, exists } from "../utils";
import type { Flags } from "../types";
import { RollupImportmapPlugin } from "./rollup-importmap-plugin";
import { pathToFileURL } from "node:url";

Check failure on line 8 in src/build/index.ts

View workflow job for this annotation

GitHub Actions / Node.js Tests (16.x)

`node:url` import should occur before import of `rollup`

Check failure on line 8 in src/build/index.ts

View workflow job for this annotation

GitHub Actions / Node.js Tests (18.x)

`node:url` import should occur before import of `rollup`

export default async function build(entry: string, options: Flags) {
if (!entry && !options.config) {
Expand Down Expand Up @@ -40,7 +41,7 @@ export default async function build(entry: string, options: Flags) {
`Build config file does not exist: ${buildConfigPath}`
);
}
const rollupConfig = await import(buildConfigPath)
const rollupConfig = await import(pathToFileURL(buildConfigPath).href)
.then((mod) => mod.default)
.catch((err) => {
throw new JspmError(`Failed to load build config: ${err}`);
Expand Down
25 changes: 11 additions & 14 deletions src/build/rollup-importmap-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,22 @@ export const RollupImportmapPlugin = async (flags: Flags): Promise<Plugin> => {
}
},
load: async (id: string) => {
let url: URL;
try {
const url = new URL(id);
if (url.protocol === "file:") {
const filePath =
path.extname(url.pathname) === ""
? `${url.pathname}.js`
: url.pathname;

return await fs.readFile(pathToFileURL(filePath), "utf-8");
}
url = new URL(id);
} catch (e) {
throw new JspmError(`Unsupported URL ${id} \n ${e.message}`);
}

if (url.protocol === "https:") {
switch (url.protocol) {
case 'file:':
return await fs.readFile(new URL(id), "utf-8");
case 'https:': {
const response = await fetch(id);
return await response.text();
}
} catch (err) {
throw new JspmError(
`\n Unsupported protocol ${id} \n ${err.message} \n`
);
default:
throw new JspmError(`Unsupported protocol ${url.protocol}`);
}
},
};
Expand Down

0 comments on commit 6213817

Please sign in to comment.