yslow npm CLI dead?
jean opened this issue · 1 comments
It does pull in a bunch of packages, but doesn't result in any yslow
executable:
10:54 john@john:~$ npm install yslow
npm WARN saveError ENOENT: no such file or directory, open '/home/john/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/john/package.json'
npm WARN john No description
npm WARN john No repository field.
npm WARN john No README data
npm WARN john No license field.
The executable is hiding in the .tgz
file, which isn't unpacked:
$ ls .npm/yslow/3.1.0/ .npm/yslow/3.1.0/package
.npm/yslow/3.1.0/:
package package.tgz
.npm/yslow/3.1.0/package:
package.json
$ tar tf .npm/yslow/3.1.0/package.tgz
package/package.json
package/bin/yslow
package/lib/yslow.js
Unpacking it manually doesn't help much:
$ ./package/bin/yslow
/home/john/.npm/yslow/3.1.0/package/bin/yslow:16
doc = require('jsdom').jsdom(),
^
TypeError: require(...).jsdom is not a function
at Object.<anonymous> (/home/john/.npm/yslow/3.1.0/package/bin/yslow:16:28)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I'm guessing it's too old.
I have just fixed the above issue. PFB the code changes that would actually fix yslow. (I picked up the fix from stackoverflow and updated the yslow code with the fix).
require('fs').readFile('XXX.har', function (err, data) {
var har = JSON.parse(data);
var YSLOW = require('yslow').YSLOW;
var jsdom = require('jsdom');
const { JSDOM } = jsdom;
const { document } = (new JSDOM('')).window;
global.document = document;
var res = YSLOW.harImporter.run(document, har, 'ydefault');
var content = YSLOW.util.getResults(res.context, 'basic');
console.log(content);
});