2022-10-12 13:29:26 +00:00
|
|
|
import { fileURLToPath } from 'url';
|
2022-10-28 15:30:54 +00:00
|
|
|
import { crawlFrameworkPkgs } from 'vitefu';
|
|
|
|
|
|
|
|
export async function getSolidPkgsConfig(root: URL, isBuild: boolean) {
|
|
|
|
return await crawlFrameworkPkgs({
|
|
|
|
root: fileURLToPath(root),
|
|
|
|
isBuild,
|
|
|
|
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;
|
|
|
|
}
|