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

RequireJS and angular #18

Open
araymer opened this issue Dec 30, 2015 · 10 comments
Open

RequireJS and angular #18

araymer opened this issue Dec 30, 2015 · 10 comments

Comments

@araymer
Copy link

araymer commented Dec 30, 2015

So this bit of code:

var _fs, jszip;
if(typeof JSZip !== 'undefined') jszip = JSZip;
if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
        if(has_buf && typeof jszip === 'undefined') jszip = require('js'+'zip');
        if(typeof jszip === 'undefined') jszip = require('./js'+'zip').JSZip;
        _fs = require('f'+'s');
    }
}

Does not take into account if you are using requireJS without node. So you have modularity, the first if statement will not assign JSZip, but you're not using node, so the second if statement will not require properly, either. I suggest adding a default jszip = require('jszip') or changing the if/else logic a bit to allow for this.

So, maybe:

var _fs, jszip;
if(typeof JSZip !== 'undefined') jszip = JSZip;
else if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
        if(has_buf && typeof jszip === 'undefined') jszip = require('js'+'zip');
        if(typeof jszip === 'undefined') jszip = require('./js'+'zip').JSZip;
        _fs = require('f'+'s');
    }
}
else
    jszip = require('js'+'zip');
@pietersv
Copy link
Collaborator

Thanks! This seems related to #17 also reported this morning.

@pietersv
Copy link
Collaborator

Referred to main branch SheetJS#339

@protobi protobi reopened this Jan 8, 2016
@pietersv
Copy link
Collaborator

pietersv commented Jan 8, 2016

@araymer Might you have a test case I can use to verify? Even a snippet is helpful, need not be a complete mocha test.

Any suggestion why strings were broken, e.g. './js'+'zip' vs simply jszip? It looks like it was added to /bits/21_ziputils.js on 7/28/14 with this commit message.

version bump 0.7.8: docs, defaults, details

@araymer
Copy link
Author

araymer commented Jan 8, 2016

Honestly, I have no idea why the strings weren't written contiguously for the require methods. I kept it as such out of caution. In my mind, it seems like it shouldn't make a difference.

As for a test case: I don't, sorry. I made the change on the project I was working on and just kinda went with it because it seemed to work fine (we were using bower, requireJS and angularJS with a .net backend. So, no node support beyond the build, but still needed modularity.)

@ralekna
Copy link

ralekna commented Mar 3, 2016

I guess that this was an optimization to avoid loading of jszip if it is included into document already. The problem is that module loaders like System.js parses such files statically to find dependencies but they don't do event primitive code evaluation inside require statements.

Fixing this would be very helpful.

@mattbasta
Copy link

I'd be happy to make a pull request that concatenates these strings, if it would be accepted.

@pietersv
Copy link
Collaborator

Are you able to run the test suite?

@mattbasta
Copy link

@pietersv Yes, this is the final output when I run make test:

screen shot 2016-03-10 at 11 28 32 am

This is for a clean clone of the repo.

@pietersv
Copy link
Collaborator

@mattbasta That's awesome. May I ask how you were able to run these, what Node version? On a clean clone of the root project on Node 4.1.1 I get 937 failed tests.

@mattbasta
Copy link

We are using 0.10. I used the instructions in the readme.

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

4 participants