Skip to content

Commit

Permalink
fix: throw better errors for users who are missing 'fetch' (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearofducks committed Jun 26, 2023
1 parent 5755b39 commit 77ba1e2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/plugin.js
Expand Up @@ -16,6 +16,7 @@ import { postprocess } from '#postprocess';
// TODO: improve generic type passed here
/** @type {import('@unocss/core').Preset<object>} */
export function presetWarp (options = {}) {
checkEnvironment();
const externalizeClasses = options.externalizeClasses;
const externalClasses = options.externalClasses ?? []; // will possibly be our own list in the future
const theme = useTheme(options);
Expand All @@ -30,4 +31,14 @@ export function presetWarp (options = {}) {
};
}

function checkEnvironment() {
if (typeof fetch === 'undefined') {
if (typeof process !== 'undefined') {
const NODE_MAJOR_VERSION = process.versions.node.split('.')[0];
if (NODE_MAJOR_VERSION < 18) throw new Error('Warp requires node 18 or higher');
}
throw new Error("'fetch' is undefined for some reason and presetWarp requires it");
}
}

export default presetWarp;

0 comments on commit 77ba1e2

Please sign in to comment.