astro/packages/integrations/solid/src/dependencies.ts

29 lines
1 KiB
TypeScript
Raw Normal View History

import type { AstroConfig } from 'astro';
2022-10-12 13:29:26 +00:00
import { fileURLToPath } from 'url';
import { crawlFrameworkPkgs } from 'vitefu';
export async function getSolidPkgsConfig(isBuild: boolean, astroConfig: AstroConfig) {
return await crawlFrameworkPkgs({
root: fileURLToPath(astroConfig.root),
isBuild,
viteUserConfig: astroConfig.vite,
isFrameworkPkgByJson(pkgJson) {
return containsSolidField(pkgJson.exports || {});
},
});
}
2022-10-12 13:29:26 +00:00
// Reference vite-plugin-solid heuristic
// https://github.com/solidjs/vite-plugin-solid/blob/5558486b0c63788e1275244256918f80294a8338/src/index.ts#L251-L259
// License: MIT (https://github.com/solidjs/vite-plugin-solid/blob/5558486b0c63788e1275244256918f80294a8338/package.json#L38)
2022-10-12 13:29:26 +00:00
function containsSolidField(fields: Record<string, any>) {
const keys = Object.keys(fields);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (key === 'solid') return true;
if (typeof fields[key] === 'object' && fields[key] != null && containsSolidField(fields[key]))
return true;
2022-10-12 13:29:26 +00:00
}
return false;
}