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

plugins order of excecution #996

Closed
yairEO opened this issue Sep 28, 2016 · 4 comments
Closed

plugins order of excecution #996

yairEO opened this issue Sep 28, 2016 · 4 comments

Comments

@yairEO
Copy link

yairEO commented Sep 28, 2016

Hi, is the order of plugins execution nontenured?
I have a transform plugin which must run before the babel plugin, and it seems to not be running at the order the Array of plugins was set to be.

I have lines of code with things like [SERVERPATH] which make no sense for Babel and throws an error for them, unless those are replaced with a real meaningful string via basic rollup transform:

// .. rollup plugins Array creation
rollupPlugins = [];

var rollupPlugins__transform = {
        transform( code, id ){
            return code
                .replace(/\[SERVERPATH]/g, config.serverPath)
                .replace(/\[prodUrl]/g, config.prodUrl)
                .replace(/mocks\//g, config.serverPath + '/BUILD/mocks/');
        }
    },
    rollupPlugins__babel = {
        presets        : [['es2015', {"modules": false}]], //['es2015-rollup'],
        runtimeHelpers : true,
        exclude        : 'node_modules/**',
        plugins        : ["external-helpers"]
    },
    rollupPlugins__uglify = uglifyRollup(uglify_settings);



rollupPlugins.push(rollupPlugins__transform);
rollupPlugins.push(eslintRollup(eslint_settings));
rollupPlugins.push(babelRollup(rollupPlugins__babel));


// .. later
rollup({
        entry   : 'app.js',
        plugins : rollupPlugins
    })
    .then(function (bundle) {
        // ... irrelevant code
    });
@Victorystick
Copy link
Contributor

Plugins are executed in order. What behaviour are you having, and what do you want?

@yairEO
Copy link
Author

yairEO commented Sep 28, 2016

Create an entry file with some ES2015 (for babel) and some "variable" (FOO) which will be transformed:

(()=>{
    'test me string'.replace([FOO]/, 1);
})()

End result should be

(function(){
    'test me string'.replace(/test/, 1);
})()

setup Rollup with plugins:

// Define rollup plugins
var rollupPlugins = [],
    rollupPlugins__transform = {
        transform( code, id ){
            return code.replace(/\[FOO]/g, '/test')
        }
    },
    rollupPlugins__babel = {
        presets        : [['es2015', {"modules": false}]], 
        runtimeHelpers : true,
        exclude        : 'node_modules/**',
        plugins        : ["external-helpers"]
    };

rollupPlugins.push(rollupPlugins__transform);
rollupPlugins.push(rollupPlugins__babel);

// create the bundle
rollup({
    entry   : 'xxx.js',
    plugins : rollupPlugins
})
.then(function (bundle) {
    var result = bundle.generate();

    // bundle file
    fs.writeFile( 'xxx.js', result.code);
})
.catch(function(err){
    gutil.log( gutil.colors.white.bgRed('Rollup [catch]: ', err.stack) );
})

When I run this (as GULP task) I get this stack trace:


[17:03:25] Rollup [catch]:  SyntaxError: Unexpected token (2:35) in C:\www\UI\BUILD\xxx.js
    at Parser.pp$4.raise (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:4072:13)
    at Parser.pp.unexpected (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:2270:8)
    at Parser.pp$3.parseExprAtom (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3624:10)
    at Parser.pp$3.parseExprSubscripts (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3494:19)
    at Parser.pp$3.parseMaybeUnary (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3471:17)
    at Parser.pp$3.parseExprOp (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3432:41)
    at Parser.pp$3.parseExprOps (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3415:15)
    at Parser.pp$3.parseMaybeConditional (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3396:19)
    at Parser.pp$3.parseMaybeAssign (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3373:19)
    at Parser.pp$3.parseExprList (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:4005:20)
    at Parser.pp$3.parseSubscripts (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3520:29)
    at Parser.pp$3.parseExprSubscripts (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3497:15)
    at Parser.pp$3.parseMaybeUnary (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3471:17)
    at Parser.pp$3.parseExprOps (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3413:19)
    at Parser.pp$3.parseMaybeConditional (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3396:19)
    at Parser.pp$3.parseMaybeAssign (C:\www\UI\BUILD\node_modules\rollup\dist\rollup.js:3373:19)

What I think

Seems like the transform doesn't happen in time, and the regex in the entry file replace([FOO]/, 1); is invalid because it must have the / at the beginning

@yairEO
Copy link
Author

yairEO commented Sep 28, 2016

Wait I am investigating more, seems like it works in another setup

@yairEO yairEO closed this as completed Sep 28, 2016
@yairEO
Copy link
Author

yairEO commented Sep 28, 2016

Sorry for have wasted your time, it was a mistake of my part which had led me to the wrong conclusion. I'm very deeply sorry! please continue your nice day and have no memory of this ticket.

tl;dr

The error message which I saw was from my tests, which use different rollup plugins array, and that array order wasn't so the trasnform was first, so when my app's default gulp task ran, the app bundle was fine but the tests rollup bundle broke.

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

No branches or pull requests

2 participants