@mlut/core 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jit/JitEngine.d.ts +1 -1
- package/dist/jit/JitEngine.js +24 -19
- package/package.json +1 -1
package/dist/jit/JitEngine.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class JitEngine {
|
|
|
13
13
|
updateSassConfig(content: string): Promise<void>;
|
|
14
14
|
generateCss(): Promise<string>;
|
|
15
15
|
private extractUtils;
|
|
16
|
-
private
|
|
16
|
+
private filterAndProcessClassStr;
|
|
17
17
|
private extractUserSassConfig;
|
|
18
18
|
private loadUtils;
|
|
19
19
|
}
|
package/dist/jit/JitEngine.js
CHANGED
|
@@ -14,16 +14,22 @@ export class JitEngine {
|
|
|
14
14
|
defaultSassConfig = '@use "sass:map";\n @use "../sass/tools/settings" as ml;';
|
|
15
15
|
utilsByFile = new Map();
|
|
16
16
|
utilsRegexps = {
|
|
17
|
-
quotedContent: /"\n?[^"]
|
|
18
|
-
singleQuotedContent: /'\n?[^']
|
|
17
|
+
quotedContent: /"\n?[^"]*[^"\n]*\n?"/g,
|
|
18
|
+
singleQuotedContent: /'\n?[^']*[^'\n]*\n?'/g,
|
|
19
|
+
backtickQuotedContent: /`\n?[^`]*[^`\n]*\n?`/g,
|
|
19
20
|
tooMoreSpaces: /\s{2,}|\n/g,
|
|
21
|
+
escapedQuotes: /\\['"`]/g,
|
|
20
22
|
utilName: /^-?[A-Z]{1}[a-zA-Z]*/,
|
|
23
|
+
uppercaseLetter: /[A-Z]/,
|
|
21
24
|
};
|
|
22
25
|
configRegexps = {
|
|
23
26
|
userSettings: /@use ['"][^'"]*(tools|mlut|core)['"](\s*as\s+[\w]+)?\s+with\s*\(([^;]+)\);/s,
|
|
24
27
|
sassModuleName: /@use ['"][^'"]*(tools|mlut|core)['"]\s*;/s,
|
|
25
28
|
};
|
|
26
29
|
async init([inputPath, inputContent] = ['', '']) {
|
|
30
|
+
if (this.utils.size) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
27
33
|
let sassConfig = this.defaultSassConfig;
|
|
28
34
|
if (inputPath && inputContent) {
|
|
29
35
|
this.inputFileDir = path.dirname(path.resolve(process.cwd(), inputPath));
|
|
@@ -59,25 +65,21 @@ export class JitEngine {
|
|
|
59
65
|
}
|
|
60
66
|
const allUniqueUtils = [...new Set([...this.utilsByFile.values()].flat())];
|
|
61
67
|
const applyStr = `\n@include ${this.sassModuleName}.apply(${JSON.stringify(allUniqueUtils)},(),true);`;
|
|
62
|
-
// `compileStringAsync` is almost always faster than `compile` in sass-embedded
|
|
63
68
|
return sass.compileStringAsync(this.inputFileCache + applyStr, { loadPaths: [this.inputFileDir, 'node_modules'] }).then(({ css }) => css, (e) => (logger.error('Sass compilation error.', e), ''));
|
|
64
69
|
}
|
|
65
70
|
extractUtils(content) {
|
|
66
|
-
|
|
67
|
-
const
|
|
71
|
+
let fixedContent = content.replace(this.utilsRegexps.escapedQuotes, '');
|
|
72
|
+
const allClassNames = fixedContent
|
|
68
73
|
.match(this.utilsRegexps.quotedContent)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
.replace(this.utilsRegexps.quotedContent, '')
|
|
74
|
+
?.reduce(this.filterAndProcessClassStr, []) ?? [];
|
|
75
|
+
fixedContent = fixedContent.replace(this.utilsRegexps.quotedContent, '');
|
|
76
|
+
fixedContent
|
|
73
77
|
.match(this.utilsRegexps.singleQuotedContent)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
}
|
|
78
|
+
?.reduce(this.filterAndProcessClassStr, allClassNames);
|
|
79
|
+
fixedContent
|
|
80
|
+
.replace(this.utilsRegexps.singleQuotedContent, '')
|
|
81
|
+
.match(this.utilsRegexps.backtickQuotedContent)
|
|
82
|
+
?.reduce(this.filterAndProcessClassStr, allClassNames);
|
|
81
83
|
return [...allClassNames.join(' ').split(' ').reduce((acc, cssClass) => {
|
|
82
84
|
const utility = cssClass.split('_').find((str) => (this.utilsRegexps.utilName.test(str)));
|
|
83
85
|
if (utility) {
|
|
@@ -89,9 +91,12 @@ export class JitEngine {
|
|
|
89
91
|
return acc;
|
|
90
92
|
}, new Set())];
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
filterAndProcessClassStr = (acc, str) => {
|
|
95
|
+
if (this.utilsRegexps.uppercaseLetter.test(str)) {
|
|
96
|
+
acc.push(str.replace(this.utilsRegexps.tooMoreSpaces, ' ').slice(1, -1));
|
|
97
|
+
}
|
|
98
|
+
return acc;
|
|
99
|
+
};
|
|
95
100
|
extractUserSassConfig(content) {
|
|
96
101
|
let matchResult = content.match(this.configRegexps.userSettings);
|
|
97
102
|
if (matchResult != null) {
|