sighjs / sigh

multi-process expressive build system for the web and node.js, built using baconjs observables
209 stars 12 forks source link

Request for help with sigh configuration: processing the same files with two configurations and seeing output for one configuration twice. #12

Closed Flaise closed 8 years ago

Flaise commented 9 years ago

I wrote a plugin for doing Javascript preprocessing. I pass parameters to the plugin constructor that tell it (among other things) which parts of a source file to exclude. I need to run the plugin more than once with different parameters on the same source file, i.e. the client side output files are different than the server side output files even though they come from the same input files. Sigh's caching makes it so if I don't run the two different configurations in entirely different processes, I get the same output for both configurations, the output of whichever configuration ran first. Is there a way for my plugin to change this caching behavior? If not, there should be.

insidewhy commented 9 years ago

Sigh doesn't use a cache, it's based on reactive updates. Could you paste the sigh file you are seeing this issue with? It might be a timing issue that could be solved with debounce, I'll know more once I see your sigh file.

insidewhy commented 9 years ago

Maybe it's also something you could solve with a combination of pipeline and merge.

Flaise commented 9 years ago

I'm already using debounce, though perhaps incorrectly (and if you could comment on whether my usage appears sensible, that would be appreciated). I don't think that's an important factor, however, because the issue I opened here still happens even when not building in --watch mode.

Here is my sigh.js file. If this doesn't give you specific enough information then, time permitting, I will eventually make a simpler reproduction of the issue.

'use strict'

var glob, write, env, merge, debounce, concat
var babel, preprocess, riot, uglify

function context(/* flag list */) {
    var constants = require('./settings')
    var merge = require('ramda').merge

    return {constants: merge({SERVER_ADDRESS: 'undefined'}, constants),
            flagList: Array.prototype.slice.call(arguments)}
}

function buildSource(folderName, flags, assetTypes) {
    if(!flags)
        flags = []
    else if(!(flags instanceof Array))
        flags = [flags]

    if(!assetTypes)
        assetTypes = []
    else if(!(assetTypes instanceof Array))
        assetTypes = [assetTypes]
    assetTypes = ['json'].concat(assetTypes)
    assetTypes = assetTypes.join('|')

    var productionFlags = flags.concat(['PRODUCTION'])

    // Note that each of these plugins is constructed twice with the same parameters,
    // except preprocess, which takes different parameters.
    return [
        merge(
            [
                merge(
                    [
                        glob({basePath: 'src'}, '**/*.tag'),
                        riot()
                    ],
                    glob({basePath: 'src'}, '**/*.es6')
                ),
                env(preprocess(context.apply(null, productionFlags)), 'production'),
                env(preprocess(context.apply(null, flags)), 'development'),
                babel({modules: 'common', optional: ['runtime']})
            ],
            [
                glob({basePath: 'src'}, '**/*.@(js|html)'),
                env(preprocess(context.apply(null, productionFlags)), 'production'),
                env(preprocess(context.apply(null, flags)), 'development'),
            ]
        ),
        env(uglify(), 'production'),
        glob({basePath: 'src'}, '**/*.@(' + assetTypes + ')'),
        debounce(500),
        write({clobber: true}, 'build/' + folderName)
    ]
}

module.exports = function(pipelines) {
    pipelines['build-server'] = buildSource('server', 'SERVER')

    pipelines['build-client'] = buildSource('client', ['NW', 'CLIENT'], ['ogg', 'png', 'gif', 'css'])

    pipelines['build-vendor'] = [
        glob({basePath: 'vendor'}, '**/*.js'),
        debounce(500),
        concat('vendor.js'),
        env(uglify(), 'production'),
        write('build/client/shared')
    ]
}
insidewhy commented 9 years ago

Did this end up being https://github.com/sighjs/sigh-babel/pull/1 or is it a different issue?

Flaise commented 9 years ago

No, it's my custom Preprocess plugin that's generating the wrong output for one of the pipelines, not Babel.

insidewhy commented 8 years ago

You found the issue? If not could you try to limit the problem down to a smaller source file and reopen this issue. Thanks!