Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

vendor files concatenated to output file last #1527

Open
3000 opened this issue Oct 17, 2016 · 4 comments
Open

vendor files concatenated to output file last #1527

3000 opened this issue Oct 17, 2016 · 4 comments

Comments

@3000
Copy link

3000 commented Oct 17, 2016

Description

The documentation for 'files' here - http://brunch.io/docs/config#files states that files from vendor folder will be compiled first by default. The docs there also state the 'order' property can be used to configure the compilation order.

In previous/old versions of brunch (< v1.8) the app.js would have the js-yaml.js file at the top, followed by the compiled modules in app/. This is what the docs suggest should happen by default.

Since upgrading my project to 2.8 the app/ modules are always at the top of the app.js. This would appear contrary to the docs.

I have traced the code in brunch and i feel like when the files array is split in to 'moduleFiles' and 'nonModulesFiles' in lib/fs_utils/generate.js#concat for processing that the order of the files is lost.

I see this split is done likely so that deppack can be run on the moduleFiles only, but feel like it breaks the ordering?

Test case: https://github.com/3000/brunch-order

Expected behavior

The vendor/js-yaml.js should be the first js processed and written to the top of app.js file.

The app.js file should have the app/.*coffee files appended to the end of app.js below the vendor file(s).

Actual behavior

vendor/js-yaml.js is always written last to the file, regardless of the stated defaults and order in the config.

I believe this is because generateModuleFiles writes the files always before nonModuleFiles in #basicGenerate

const basicGenerate = (generateModuleFiles, nonModuleFiles, processor, deppack, definition, path, root) => {
      root.add(definition);
      generateModuleFiles();
      nonModuleFiles.forEach(processor);
    };

Environment

  1. Brunch: ~2.8
  2. Node: v6.30
  3. NPM: 3.10.3
  4. Operating system: Mac OSX 10.11.6

package.json contents

{
    "author": "3000",
    "name": "app",
    "description": "",
    "version": "1.12.25",
    "private": true,
    "engines": {
        "node": ">=0.8.0"
    },
    "scripts": {
        "test": "run/tests",
        "test-debug": "run/tests-debug",
        "start": "run/server"
    },
    "dependencies": {
        "brunch": "~2.8",
        "javascript-brunch": "~2.0",
        "coffee-script": "~1.6",
        "coffee-script-brunch": "~2.1",
        "uglify-js-brunch": "~2.0"
    },
    "devDependencies": {
        "auto-reload-brunch": "*",
        "karma": "0.13.22",
        "karma-mocha-reporter": "^1.1.0",
        "karma-coffee-preprocessor": "1.0.0",
        "karma-mocha": "1.2.0",
        "karma-chai": "*",
        "karma-chrome-launcher": "~0.1",
        "karma-safari-launcher": "~0.1",
        "karma-phantomjs2-launcher": "0.5.0",
        "chai": "*",
        "mocha": "*"
    }
}

brunch config contents

exports.config =

  npm:
    enabled: false

  modules:
    definition: false
    wrapper: false

  files:
    javascripts:
      joinTo: 
        'app.js' : [ 'vendor/js-yaml.js', /^app\/.*coffee/ ]
      order:
        before: ['vendor/js-yaml.js']

  overrides:
    production:
      minify: false
      optimize: false
      sourceMaps: false
      plugins: autoReload: enabled: false

  server:
    noPushState: yes

Other useful files, when present (log, bower.json etc.)

Used to order as expected in brunch 1.8. Since upgrading to 2.8 this order is not as expected.

Debug output from brunch indicates that the files will be concatenated in the correct order:

17 Oct 12:14:53 - warn: vendor/jquery-1.11.2.js compiled, but not written. Check your javascripts.joinTo config
  brunch:write Writing 1/1 files +75ms
  brunch:generate Concatenating [vendor/js-yaml.js, app/evaluator.coffee, app/runner.coffee] => public/app.js +6ms
  brunch:generate Writing public/app.js +42ms
  brunch:generate Writing public/app.js.map +19ms
@3000 3000 changed the title vendor files concatenated to output file last despite documented defaults and order config vendor files concatenated to output file last Oct 17, 2016
@cxw42
Copy link

cxw42 commented Sep 26, 2018

I believe this is true. The lines here seem to be flipped - if I understand the docs correctly, nonModuleFiles should be output before moduleFiles. I tried flipping them in my local copy of brunch and got the output I expected. The patched code is:

const basicGenerate = (generateModuleFiles, nonModuleFiles, processor, deppack, definition, path, root) => {
  root.add(definition);
  nonModuleFiles.forEach(processor);     // ### Now this one is first
  generateModuleFiles();                 // ### and this one is second
};

cxw42 pushed a commit to cxw42/brunch that referenced this issue Sep 26, 2018
Implements the change described in my comment on brunch#1527 at
brunch#1527 (comment)
@cxw42
Copy link

cxw42 commented May 2, 2020

This seems to still be the case as of d6b6577 (master as of writing):

function basicGenerate(generateModuleFiles, nonModuleFiles, processor, deppack, definition, path, root) {
root.add(definition);
generateModuleFiles();
nonModuleFiles.forEach(processor);
}

Any thoughts from the maintainers? Thanks again for this tool, which has been serving me well for several years now!

@paulmillr
Copy link
Contributor

I'll debug this ASAP and see what can be fixed!

@cxw42
Copy link

cxw42 commented May 3, 2020

Thank you! If it helps, I just brought my branch at https://github.com/cxw42/brunch/tree/1527 up to date with master. That branch actually permits putting vendor files both before and after wrapped files.

I believe the fix is easy, but figuring out whether it will break existing clients may be harder :) .

@paulmillr paulmillr reopened this Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants