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

Fresh install utilizing broken dependencies? #27

Open
rafaelnco opened this issue Jan 18, 2016 · 2 comments
Open

Fresh install utilizing broken dependencies? #27

rafaelnco opened this issue Jan 18, 2016 · 2 comments

Comments

@rafaelnco
Copy link

TL;DR: patch jsdom 0.2.14 used by jquery 1.8.3 used by munchjs; patch munch.js solving ENOENT .usage file and then remove script tags from your views to get MunchJS fully working.

Although MunchJS is many years old, it seems pretty useful as companies like Google and Facebook develop and utilize their own tools that do pretty much the same thing. So, as this may interest some people, I'm creating this Issue thread to help us install & use MunchJS as it was intended for.

In the initial scenario, we need a fresh install:

Git clone repo

$ cd ~
$ git clone https://github.com/jmrocela/munchjs.git

Install MunchJS globally:

$ npm install -g .

note the . at the end of the line

Test the tool with some simple example

index.html:
<html>
    <head>
        <title>This is a simple title</title>
    </head>
    <body>
    </body>
    <script src="js.js"></script>
</html>

Our first error: missing setters parameters

$ munch --view index.html

/usr/lib/node_modules/munch/node_modules/jquery/node_modules/jsdom/lib/jsdom/level1/core.js:418
  set nodeName() { throw new core.DOMException();},
              ^^

SyntaxError: Setter must have exactly one formal parameter.
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/node_modules/munch/node_modules/jquery/node_modules/jsdom/lib/jsdom/level2/core.js:1:94)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)

Hooray! Our first error (please, refer to this)!

You can solve it by entering the needed parameters in the setter functions. I'm using Sublime Text 2, so this is simple:

find what: set (\w+)\(\)
replace with: set \1(a)

We then execute munchjs again...

$ munch --view index.html

/usr/lib/node_modules/munch/node_modules/jquery/node_modules/jsdom/lib/jsdom/level2/html.js:446
  set head() { /* noop */ },
          ^^

SyntaxError: Setter must have exactly one formal parameter.
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/lib/node_modules/munch/node_modules/jquery/node_modules/jsdom/lib/jsdom/level3/html.js:2:12)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)

Hooray! Almost done! We can fix it by the same way we have fixed level1/core.js and then continue testin

Our second error: ENOENT '.usage'

Now that we solved this, we get to this

$ munch --view index.html

fs.js:584
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open './usage'
    at Error (native)
    at Object.fs.openSync (fs.js:584:18)
    at Object.fs.readFileSync (fs.js:431:33)
    at Object.exports.run (/usr/lib/node_modules/munch/munch.js:859:31)
    at Object.<anonymous> (/usr/lib/node_modules/munch/bin/munch:7:27)
    at Module._compile (module.js:397:26)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:429:10)

This is easily solved with this magic replacement:

find what: './usage'
replace with: __dirname+'/usage'

Our third error: script tags

$ munch --view index.html

   __  ___              __     _
  /  |/  /_ _____  ____/ /    (_)__
 / /|_/ / // / _ \/ __/ _ \  / (_-<
/_/  /_/\_,_/_//_/\__/_//_/_/ /___/
                         |___/

Copyright (c) 2013 John Rocela <me@iamjamoy.com>


Processing view
index.html
Finished!

-------------------------------
Mapped 0 IDs and Classes
-------------------------------

Rewriting view
/usr/lib/node_modules/munch/node_modules/jsdom/lib/jsdom/level1/core.js:554
      Array.prototype.splice.call(this._childNodes, refChildIndex, 0, newCh
ild);
                             ^

TypeError: Cannot set property length of [object Object] which has only a getter
    at Object.core.Node.insertBefore (/usr/lib/node_modules/munch/node_modules/jsdom/lib/jsdom/level1/core.js:554:30)
    at Object.<anonymous> (/usr/lib/node_modules/munch/node_modules/jsdom/lib/jsdom/level2/events.js:314:20)
    at Object.proto.(anonymous function) [as insertBefore] (/usr/lib/node_modules/munch/node_modules/jsdom/lib/jsdom/utils.js:21:26)
    at Object.core.Node.appendChild (/usr/lib/node_modules/munch/node_modules/jsdom/lib/jsdom/level1/core.js:672:17)
    at Function.jQuery.extend.clean (/usr/lib/node_modules/munch/node_modules/jquery/lib/node-jquery.js:6431:15)
    at Function.jQuery.buildFragment (/usr/lib/node_modules/munch/node_modules/jquery/lib/node-jquery.js:6189:10)
    at jQuery.fn.extend.domManip (/usr/lib/node_modules/munch/node_modules/jquery/lib/node-jquery.js:5999:21)
    at jQuery.fn.extend.append (/usr/lib/node_modules/munch/node_modules/jquery/lib/node-jquery.js:5802:15)
    at null.<anonymous> (/usr/lib/node_modules/munch/node_modules/jquery/lib/node-jquery.js:5732:18)
    at Function.jQuery.extend.access (/usr/lib/node_modules/munch/node_modules/jquery/lib/node-jquery.js:839:9)

This error is very strange, at least for me, as I've found a simple solution that makes MunchJS run flawlessly: modify index.html, removing < script > tags.

The modified index.html now looks like:

<html>
      <head>
            <title>This is a simple title</title>
      </head>
      <body>
      </body>
</html>

Well, at this moment I'm investigating the causes for this error, but for now this solution works and I'm on my way to expanding rewriteJS regexes. After Munching, re-inserting script tags is simple, so I won't be dealing with this problem further.

@jagged3dge
Copy link

Thank you so much for this walkthrough 👍
Please do share if you've achieved the rewriteJS regexes

@dstuecken
Copy link

Could you please create a pull request for your changes?

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

3 participants