Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yslow npm CLI dead? #189

Open
jean opened this issue Nov 21, 2017 · 1 comment
Open

yslow npm CLI dead? #189

jean opened this issue Nov 21, 2017 · 1 comment

Comments

@jean
Copy link

jean commented Nov 21, 2017

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.

@paramesh
Copy link

paramesh commented Jul 9, 2018

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants