mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-27 02:27:18 +00:00
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
// Resolves the virtual modules of SvelteKit to stubs, so that the code that imports them can be
|
|
// tested outside of the framework.
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
|
const stubs = {
|
|
'$app/environment': 'app-environment.ts',
|
|
'$app/paths': 'app-paths.ts',
|
|
'$app/state': 'app-state.ts',
|
|
'$env/static/public': 'env-static-public.ts',
|
|
};
|
|
|
|
export async function resolve(specifier, context, nextResolve) {
|
|
const stub = stubs[specifier];
|
|
if (stub) {
|
|
const url = pathToFileURL(fileURLToPath(new URL(`./stubs/${stub}`, import.meta.url)));
|
|
return nextResolve(url.href, context);
|
|
}
|
|
return nextResolve(specifier, context);
|
|
}
|
|
|
|
// Stylesheets are for the browser: importing one gives nothing.
|
|
export async function load(url, context, nextLoad) {
|
|
if (url.endsWith('.css')) {
|
|
return { format: 'module', source: '', shortCircuit: true };
|
|
}
|
|
// The URL of a file given by Vite (`?url`, `?worker&url`), which the tests do not load.
|
|
if (new URL(url).searchParams.has('url')) {
|
|
return { format: 'module', source: "export default '';", shortCircuit: true };
|
|
}
|
|
return nextLoad(url, context);
|
|
}
|