2022-11-11 06:22:43 +00:00
|
|
|
import type { AstroConfig } from 'astro';
|
2022-10-12 13:29:26 +00:00
|
|
|
import { fileURLToPath } from 'url';
|
2022-10-28 15:30:54 +00:00
|
|
|
import { crawlFrameworkPkgs } from 'vitefu';
|
|
|
|
|
2022-11-11 06:22:43 +00:00
|
|
|
export async function getSolidPkgsConfig(isBuild: boolean, astroConfig: AstroConfig) {
|
2022-10-28 15:30:54 +00:00
|
|
|
return await crawlFrameworkPkgs({
|
2022-11-11 06:22:43 +00:00
|
|
|
root: fileURLToPath(astroConfig.root),
|
2022-10-28 15:30:54 +00:00
|
|
|
isBuild,
|
2022-11-11 06:22:43 +00:00
|
|
|
viteUserConfig: astroConfig.vite,
|
2022-10-28 15:30:54 +00:00
|
|
|
isFrameworkPkgByJson(pkgJson) {
|
|
|
|
return containsSolidField(pkgJson.exports || {});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2022-10-12 13:29:26 +00:00
|
|
|
|
2022-10-28 15:30:54 +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;
|
2022-10-28 15:30:54 +00:00
|
|
|
if (typeof fields[key] === 'object' && fields[key] != null && containsSolidField(fields[key]))
|
|
|
|
return true;
|
2022-10-12 13:29:26 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|