elliotstokes / gpx-parse

GPX parser
MIT License
44 stars 40 forks source link

Missing `lib-cov` #3

Closed akoenig closed 9 years ago

akoenig commented 10 years ago

Hey Elliot,

thanks for writing and sharing gpx-parse. Works great in Node.js!

I tried to browserify your module so that I can use it in the browser as well without any API modifications. Unfortunately that did not work. There are missing source files in the repository. The culprit is the ternary operator within index.js.

Browserify fails here because it seeks for all require statements in order to embed the dependencies. The first require statement imports a module which does not exist in the source tree. Is this intended? This statement will also fail in a Node.js environment if the respective environment variable is set.

process.env.GPXPARSE_COV ? require('./lib-cov/gpx-parse') : require('./lib/gpx-parse');

Maybe we could commit a skeleton directory which emulates that what will be injected by jscoverage/JSCover.

/André

elliotstokes commented 10 years ago

Ah ok. these should never be called by the application when its running its purely there to compute code coverage. What would be required. Just the empty folder or the files as well? I currently specifically add that folder to the .gitignore atm.

elliotstokes commented 10 years ago

Is there someway to ignore this require statement in browserfy or copy a blank index.js into the folder before running?

Wilkins commented 9 years ago

I created a fork to browserify this module : https://github.com/Wilkins/gpx-parse I had to hack the browserify configuration so simulate a fake lib-cov module. It's working pretty nicely up to now. If you guys can test it to confirm everything is ok. The resulting JS code is pretty huge though : 400kB.

elliotstokes commented 9 years ago

Is this something you could wrap up in a pull request or explain so I can add to the project as this has come up a few times before.

Regarding the large file size - I'm guessing there is a reasonable amount of unexecuted js wrapped up in that file too that could be removed and the file could also be minified or is that post minification size?

Wilkins commented 9 years ago

Done in this PR : https://github.com/elliotstokes/gpx-parse/pull/8 The result file of 400kB is before minification. The minified version is about 150kB.

elliotstokes commented 9 years ago

Fixed by #8

boldtrn commented 8 years ago

@elliotstokes I just installed gpx-parse and had the same error using npm install gpx-parse.

When I run browserify I get the following error:

Error: Cannot find module './lib-cov/gpx-parse' from 'somewhere\node_modules\gpx-parse'

I add it to my .js like this:

var gpxParse = require('gpx-parse');
elliotstokes commented 8 years ago

Really? Did you run

  npm run browserify

I just tried and it was successful here. The dist folder should contain the latest browserified version if you are having issues.

elliotstokes commented 8 years ago

Essentially what I' doing is adding an alias within the grunt task.

dist: {
  src: 'index.js',
  dest: 'dist/gpx-parse-browser.js',
  options: {
    alias: [
      // Mockup to avoid loading lib-cov/gpx-parse in the browserify build process
      './browserify-mock.js:./lib-cov/gpx-parse'
    ]
  }
}

Open to other suggestions though if you have any.

boldtrn commented 8 years ago

@elliotstokes Running it for your repository works for me. But when I install it and add it with the above require statement to my js and run browserify on my js I get that exception.

boldtrn commented 8 years ago

@elliotstokes I want to add gpx-parse to my existing js. To build my js I use browserify.

I add gpx-parse to my js using: var gpxParse = require('gpx-parse'); I build the js using: browserify js/main-template.js -o js/main.js

This produces the following exception:

Error: Cannot find module './lib-cov/gpx-parse' from 'C:\workspace\project\node_modules\gpx-parse'
    at C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:55:21
    at load (C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:69:43)
    at onex (C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:92:31)
    at C:\workspace\project\node_modules\browserify\node_modules\resolve\lib\async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)

When I run npm run browserify from C:\workspace\project\node_modules\gpx-parse this works and generates the js in the dist folder.

elliotstokes commented 8 years ago

You need to set up an alias for the missing file and use the browserify-mock.js file instead. I'm doing it with gulp in my build. I'm not sure of the correct parameters on the browserify cli.

boldtrn commented 8 years ago

@elliotstokes Thanks. I tried with aliasify, but wasn't able to do it. For now I just changed the require statement in your index.js. I might try again in the future.

Thanks for your work and your help!