Improve require speed (#358)
This commit is contained in:
parent
4e65299e7b
commit
61aca7cb76
1 changed files with 8 additions and 13 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
const ansiStyles = require('ansi-styles');
|
const ansiStyles = require('ansi-styles');
|
||||||
const {stdout: stdoutColor, stderr: stderrColor} = require('supports-color');
|
const {stdout: stdoutColor, stderr: stderrColor} = require('supports-color');
|
||||||
const template = require('./templates');
|
|
||||||
const {
|
const {
|
||||||
stringReplaceAll,
|
stringReplaceAll,
|
||||||
stringEncaseCRLFWithFirstIndex
|
stringEncaseCRLFWithFirstIndex
|
||||||
|
|
@ -15,9 +14,6 @@ const levelMapping = [
|
||||||
'ansi16m'
|
'ansi16m'
|
||||||
];
|
];
|
||||||
|
|
||||||
// `color-convert` models to exclude from the Chalk API due to conflicts and such
|
|
||||||
const skipModels = new Set(['gray']);
|
|
||||||
|
|
||||||
const styles = Object.create(null);
|
const styles = Object.create(null);
|
||||||
|
|
||||||
const applyOptions = (object, options = {}) => {
|
const applyOptions = (object, options = {}) => {
|
||||||
|
|
@ -76,11 +72,9 @@ styles.visible = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const model of Object.keys(ansiStyles.color.ansi)) {
|
const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
|
||||||
if (skipModels.has(model)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (const model of usedModels) {
|
||||||
styles[model] = {
|
styles[model] = {
|
||||||
get() {
|
get() {
|
||||||
const {level} = this;
|
const {level} = this;
|
||||||
|
|
@ -92,11 +86,7 @@ for (const model of Object.keys(ansiStyles.color.ansi)) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
|
for (const model of usedModels) {
|
||||||
if (skipModels.has(model)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
||||||
styles[bgModel] = {
|
styles[bgModel] = {
|
||||||
get() {
|
get() {
|
||||||
|
|
@ -194,6 +184,7 @@ const applyStyle = (self, string) => {
|
||||||
return openAll + string + closeAll;
|
return openAll + string + closeAll;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let template;
|
||||||
const chalkTag = (chalk, ...strings) => {
|
const chalkTag = (chalk, ...strings) => {
|
||||||
const [firstString] = strings;
|
const [firstString] = strings;
|
||||||
|
|
||||||
|
|
@ -213,6 +204,10 @@ const chalkTag = (chalk, ...strings) => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (template === undefined) {
|
||||||
|
template = require('./templates');
|
||||||
|
}
|
||||||
|
|
||||||
return template(chalk, parts.join(''));
|
return template(chalk, parts.join(''));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue