2021-07-05 21:44:15 +00:00
|
|
|
const basicIncludes = (bundleCode, code, display = code[0].toUpperCase() + code.substring(1)) => {
|
2021-03-07 13:41:37 +00:00
|
|
|
if (bundleCode.includes(code)) return display;
|
2021-02-14 18:30:46 +00:00
|
|
|
};
|
|
|
|
|
2021-07-05 21:44:15 +00:00
|
|
|
export default (bundleCode, currentTags) => {
|
|
|
|
// Scans final bundle JS to try and auto-detect things, then adding tags
|
2021-02-14 18:30:46 +00:00
|
|
|
const tags = [
|
|
|
|
basicIncludes(bundleCode, 'react'),
|
|
|
|
basicIncludes(bundleCode, 'document', 'DOM'),
|
2021-03-07 13:41:06 +00:00
|
|
|
|
2021-07-05 21:44:15 +00:00
|
|
|
/document\.createElement\(['"`]style['"`]\)/.test(bundleCode) ? 'CSS' : undefined,
|
2021-03-07 13:41:06 +00:00
|
|
|
|
2021-07-05 21:44:15 +00:00
|
|
|
currentTags.includes('themes') ? 'theme' : undefined,
|
|
|
|
]
|
|
|
|
.filter((x) => x !== undefined)
|
|
|
|
.concat(currentTags.filter((x) => x !== 'themes'));
|
2021-02-14 18:30:46 +00:00
|
|
|
|
|
|
|
return tags;
|
2021-07-05 21:44:15 +00:00
|
|
|
};
|