Issue with `core-js` and `lodash` #354

Closed
pascalduez opened this Issue Feb 1, 2015 · 9 comments

Comments

Projects
None yet
3 participants
@pascalduez
Member

pascalduez commented Feb 1, 2015

Bumped in to a pretty edge/pain case while working on the theme generator.
The Gruntfile use BrowserSync and also sassoc to provide live reloading while working on css, js, and templates.

BrowserSync has a deep dependency which relies on lodash@1.0.1

Fatal error: boolean is not a function
TypeError: boolean is not a function
    at Function.isPlainObject ([...]/node_modules/grunt-browser-sync/node_modules/browser-sync/node_modules/glob-watcher/node_modules/gaze/node_modules/globule/node_modules/lodash/dist/lodash.js:1652:64)

Deps path:

grunt-browser-sync/browser-sync/glob-watcher/gaze/globule/lodash

Reproduce:

var sassdoc = require('sassdoc');
var _ = require('lodash'); // 1.0.1

_.isPlainObject({});  // Boom
var sassdoc = require('sassdoc');
var _ = require('lodash'); // >=3.0.0

_.isPlainObject({});  // \o/

This is coming from our require('core-js/shim') from polyfill.js
It must be overriding or extending a native prototype.

Not sure whether we could or should do something about it, just keeping a record of it here.

Ideally, it would be nice to not depend on core-js at some point, let see.

@valeriangalliat

This comment has been minimized.

Show comment
Hide comment
@valeriangalliat

valeriangalliat Feb 1, 2015

Member

After some investigation:

core-js is wrapping Object static methods to support (apparently) iterators. lodash 1.0.1 is failing (at least) when calling _.isPlainObject when Object.getPrototypeOf is not a native function.

This is fixed in further lodash versions.

Anyway, I'd like not to depend on core-js, but I think we use a lot of things from it, and it might be hard to avoid it with 6to5 (it's using core-js for Object.*, iterators and promises for what we're using, and I'm not sure we can tel 6to5 to use other implementations).

Member

valeriangalliat commented Feb 1, 2015

After some investigation:

core-js is wrapping Object static methods to support (apparently) iterators. lodash 1.0.1 is failing (at least) when calling _.isPlainObject when Object.getPrototypeOf is not a native function.

This is fixed in further lodash versions.

Anyway, I'd like not to depend on core-js, but I think we use a lot of things from it, and it might be hard to avoid it with 6to5 (it's using core-js for Object.*, iterators and promises for what we're using, and I'm not sure we can tel 6to5 to use other implementations).

@pascalduez

This comment has been minimized.

Show comment
Hide comment
@pascalduez

pascalduez Feb 1, 2015

Member

So it's breaking grunt-sassdoc used in conjunction with grunt-browser-sync.

Member

pascalduez commented Feb 1, 2015

So it's breaking grunt-sassdoc used in conjunction with grunt-browser-sync.

@FWeinb

This comment has been minimized.

Show comment
Hide comment
@FWeinb

FWeinb Feb 1, 2015

Member

Yeah core-js will break things. If we upgrade to 6to5 3.0.0 it will not be a problem because we will use selfContained than.

Member

FWeinb commented Feb 1, 2015

Yeah core-js will break things. If we upgrade to 6to5 3.0.0 it will not be a problem because we will use selfContained than.

@valeriangalliat

This comment has been minimized.

Show comment
Hide comment
@valeriangalliat

valeriangalliat Feb 1, 2015

Member

We need to merge this and this, then publish a patch.

Member

valeriangalliat commented Feb 1, 2015

We need to merge this and this, then publish a patch.

@valeriangalliat valeriangalliat added the Bug label Feb 1, 2015

@valeriangalliat

This comment has been minimized.

Show comment
Hide comment
@valeriangalliat

valeriangalliat Feb 2, 2015

Member

Ok we can test the 6to5 2to3 update with this script, forked from here.

sedi() {
    sed "$1" "$2" > "$2-tmp"
    mv "$2-tmp" "$2"
}

git clone --depth 1 --branch master git://github.com/SassDoc/sassdoc.git master
cd master
npm i
make dist
sedi 's/return sorter.*/return data;/' dist/sassdoc.js
sedi 's/postProcess(data) {/postProcess(data) { data = require(".\/sorter")(data);/' dist/parser.js
cd -

git clone --depth 1 --branch develop git://github.com/SassDoc/sassdoc.git develop
cd develop
npm i
make dist
cd -

git clone --depth 1 --branch develop git://github.com/SassDoc/sassdoc-theme-default.git std
cd std
npm i
make dist
cd -

cat << EOF > test
#!/bin/sh -e

mkdir -p in out

if [ -d "\$1" ]; then
    name=\$(basename "\$1")
    dir=\$1
else
    name=\$(basename "\$1" | sed 's/\.git$//')
    dir=in/\$name

    if [ ! -d "\$dir" ]; then
        git clone --depth 1 "\$1" "\$dir"
    fi
fi

t() {
    "./\$1/bin/sassdoc" -v -t "./std" --dest "out/\$name-\$1" "\$dir"
}

t master
t develop

git diff "out/\$name-master" "out/\$name-develop" || :
EOF

chmod +x test

./test git://github.com/pascalduez/SassyIcons.git
./test git://github.com/pascalduez/SassyFilters.git
./test git://github.com/pascalduez/SassySVG.git
./test git://github.com/HugoGiraudel/SassyIteratorsGenerators
./test git://github.com/HugoGiraudel/SassyJSON
./test git://github.com/HugoGiraudel/SassyMatrix
./test git://github.com/HugoGiraudel/SassyStrings
./test git://github.com/HugoGiraudel/SassyCast
./test git://github.com/HugoGiraudel/SassySort
./test git://github.com/HugoGiraudel/SassyBitwise
./test git://github.com/HugoGiraudel/SassyLogger
./test git://github.com/HugoGiraudel/SassyGradients

Currently I can't test anything with this with the master branch don't renders the documentation, it just exits without failure and without doing anything. --debug don't help, the debug data is exactly the same with develop except sassdoc-data.json is never dumped.

Member

valeriangalliat commented Feb 2, 2015

Ok we can test the 6to5 2to3 update with this script, forked from here.

sedi() {
    sed "$1" "$2" > "$2-tmp"
    mv "$2-tmp" "$2"
}

git clone --depth 1 --branch master git://github.com/SassDoc/sassdoc.git master
cd master
npm i
make dist
sedi 's/return sorter.*/return data;/' dist/sassdoc.js
sedi 's/postProcess(data) {/postProcess(data) { data = require(".\/sorter")(data);/' dist/parser.js
cd -

git clone --depth 1 --branch develop git://github.com/SassDoc/sassdoc.git develop
cd develop
npm i
make dist
cd -

git clone --depth 1 --branch develop git://github.com/SassDoc/sassdoc-theme-default.git std
cd std
npm i
make dist
cd -

cat << EOF > test
#!/bin/sh -e

mkdir -p in out

if [ -d "\$1" ]; then
    name=\$(basename "\$1")
    dir=\$1
else
    name=\$(basename "\$1" | sed 's/\.git$//')
    dir=in/\$name

    if [ ! -d "\$dir" ]; then
        git clone --depth 1 "\$1" "\$dir"
    fi
fi

t() {
    "./\$1/bin/sassdoc" -v -t "./std" --dest "out/\$name-\$1" "\$dir"
}

t master
t develop

git diff "out/\$name-master" "out/\$name-develop" || :
EOF

chmod +x test

./test git://github.com/pascalduez/SassyIcons.git
./test git://github.com/pascalduez/SassyFilters.git
./test git://github.com/pascalduez/SassySVG.git
./test git://github.com/HugoGiraudel/SassyIteratorsGenerators
./test git://github.com/HugoGiraudel/SassyJSON
./test git://github.com/HugoGiraudel/SassyMatrix
./test git://github.com/HugoGiraudel/SassyStrings
./test git://github.com/HugoGiraudel/SassyCast
./test git://github.com/HugoGiraudel/SassySort
./test git://github.com/HugoGiraudel/SassyBitwise
./test git://github.com/HugoGiraudel/SassyLogger
./test git://github.com/HugoGiraudel/SassyGradients

Currently I can't test anything with this with the master branch don't renders the documentation, it just exits without failure and without doing anything. --debug don't help, the debug data is exactly the same with develop except sassdoc-data.json is never dumped.

@pascalduez

This comment has been minimized.

Show comment
Hide comment
@pascalduez

pascalduez Feb 2, 2015

Member

Wow, that's exactly what I wanted to ask you, an automated scipt for testing on several "real" projects.

Might be handy to add such thing to SassDoc/team ?

Member

pascalduez commented Feb 2, 2015

Wow, that's exactly what I wanted to ask you, an automated scipt for testing on several "real" projects.

Might be handy to add such thing to SassDoc/team ?

@valeriangalliat

This comment has been minimized.

Show comment
Hide comment
@valeriangalliat

valeriangalliat Feb 2, 2015

Member

That's not exactly the purpose of my script. The above script will test several "real" projects with both master and develop branches and spawn a diff with the outputs (and let you manually compare the eventual differences).

It's quite specific to the fact develop contains a rewritten master but should yield the exact same results.

Member

valeriangalliat commented Feb 2, 2015

That's not exactly the purpose of my script. The above script will test several "real" projects with both master and develop branches and spawn a diff with the outputs (and let you manually compare the eventual differences).

It's quite specific to the fact develop contains a rewritten master but should yield the exact same results.

@valeriangalliat

This comment has been minimized.

Show comment
Hide comment
@valeriangalliat

valeriangalliat Feb 2, 2015

Member

Ok my problem with master not working was a bug with the sed replacement to fix order output. Now the script can test properly, and I can assure you there's no difference between the master and develop branch for all the projects above!

Member

valeriangalliat commented Feb 2, 2015

Ok my problem with master not working was a bug with the sed replacement to fix order output. Now the script can test properly, and I can assure you there's no difference between the master and develop branch for all the projects above!

@pascalduez

This comment has been minimized.

Show comment
Hide comment
@pascalduez

pascalduez Feb 2, 2015

Member

Tremendous

Member

pascalduez commented Feb 2, 2015

Tremendous

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment