Determine which config files each sheet uses
This commit is contained in:
parent
f1418794ac
commit
719e6d9f8a
2 changed files with 33 additions and 0 deletions
|
|
@ -125,6 +125,24 @@ export async function analyze(stylesheets: Stylesheet[]) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Determine which config files are used by each stylesheet (if any)
|
||||
for (let sheet of stylesheets) {
|
||||
for (let node of sheet.configRules) {
|
||||
let configPath = node.params.match(/['"](.*)['"]/)?.[1]
|
||||
if (!configPath) continue
|
||||
|
||||
sheet.configFiles.add(configPath)
|
||||
}
|
||||
}
|
||||
|
||||
for (let sheet of stylesheets) {
|
||||
for (let parent of sheet.ancestors) {
|
||||
for (let file of parent.configFiles) {
|
||||
sheet.configFiles.add(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function split(stylesheets: Stylesheet[]) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ export class Stylesheet {
|
|||
*/
|
||||
layers = new Set<string>()
|
||||
|
||||
/**
|
||||
* The list of config files that this stylesheet uses
|
||||
*/
|
||||
configFiles = new Set<string>()
|
||||
|
||||
static async load(filepath: string) {
|
||||
filepath = path.resolve(process.cwd(), filepath)
|
||||
|
||||
|
|
@ -75,6 +80,16 @@ export class Stylesheet {
|
|||
return imports
|
||||
}
|
||||
|
||||
get configRules() {
|
||||
let rules = new Set<postcss.AtRule>()
|
||||
|
||||
this.root.walkAtRules('config', (rule) => {
|
||||
rules.add(rule)
|
||||
})
|
||||
|
||||
return rules
|
||||
}
|
||||
|
||||
get isEmpty() {
|
||||
return this.root.toString().trim() === ''
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue