-
-
Save brigand/f5327551eefcb81d8f77756cb5069ae0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const {dirname} = require('path'); | |
const resolve = require('require-relative'); | |
require.extensions['.js'] = (module, filename) => { | |
const str = fs.readFileSync(module.filename, 'utf-8'); | |
const str2 = str.replace(/require\(([^)]+)\)/, (m, path) => { | |
const resolved = resolve.resolve(path.replace(/['"]/g, '').trim(), dirname(filename)); | |
return `timeRequire('${resolved}', () => ${m})`; | |
}); | |
module._compile(str2, filename); | |
}; | |
const times = []; | |
global.timeRequire = (path, f) => { | |
const now = Date.now(); | |
const res = f(); | |
times.push({time: Date.now() - now, path}); | |
return res; | |
}; | |
require('stylelint'); | |
const output = times | |
.filter(x => x.time > 50) | |
.sort((a, b) => b.time - a.time); | |
console.log(output); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"require-relative": "^0.8.7", | |
"stylelint": "^7.9.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ { time: 309, | |
path: '/private/tmp/temp-9870/node_modules/stylelint/lib/utils/isAutoprefixable.js' }, | |
{ time: 100, | |
path: '/private/tmp/temp-9870/node_modules/stylelint/lib/rules/at-rule-blacklist/index.js' }, | |
{ time: 67, | |
path: '/private/tmp/temp-9870/node_modules/postcss/lib/declaration.js' }, | |
{ time: 65, | |
path: '/private/tmp/temp-9870/node_modules/doiuse/lib/doiuse.js' }, | |
{ time: 56, | |
path: '/private/tmp/temp-9870/node_modules/postcss/lib/css-syntax-error.js' }, | |
{ time: 53, | |
path: '/private/tmp/temp-9870/node_modules/micromatch/lib/expand.js' }, | |
{ time: 51, | |
path: '/private/tmp/temp-9870/node_modules/stylelint/lib/utils/report.js' } ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment