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';
|
||||
const ansiStyles = require('ansi-styles');
|
||||
const {stdout: stdoutColor, stderr: stderrColor} = require('supports-color');
|
||||
const template = require('./templates');
|
||||
const {
|
||||
stringReplaceAll,
|
||||
stringEncaseCRLFWithFirstIndex
|
||||
|
|
@ -15,9 +14,6 @@ const levelMapping = [
|
|||
'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 applyOptions = (object, options = {}) => {
|
||||
|
|
@ -76,11 +72,9 @@ styles.visible = {
|
|||
}
|
||||
};
|
||||
|
||||
for (const model of Object.keys(ansiStyles.color.ansi)) {
|
||||
if (skipModels.has(model)) {
|
||||
continue;
|
||||
}
|
||||
const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
|
||||
|
||||
for (const model of usedModels) {
|
||||
styles[model] = {
|
||||
get() {
|
||||
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)) {
|
||||
if (skipModels.has(model)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const model of usedModels) {
|
||||
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
||||
styles[bgModel] = {
|
||||
get() {
|
||||
|
|
@ -194,6 +184,7 @@ const applyStyle = (self, string) => {
|
|||
return openAll + string + closeAll;
|
||||
};
|
||||
|
||||
let template;
|
||||
const chalkTag = (chalk, ...strings) => {
|
||||
const [firstString] = strings;
|
||||
|
||||
|
|
@ -213,6 +204,10 @@ const chalkTag = (chalk, ...strings) => {
|
|||
);
|
||||
}
|
||||
|
||||
if (template === undefined) {
|
||||
template = require('./templates');
|
||||
}
|
||||
|
||||
return template(chalk, parts.join(''));
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue