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

Broken reference to grunt.task.current.data #73

Open
iabw opened this issue Mar 24, 2015 · 0 comments
Open

Broken reference to grunt.task.current.data #73

iabw opened this issue Mar 24, 2015 · 0 comments

Comments

@iabw
Copy link

iabw commented Mar 24, 2015

Hey, this seems like an issue that someone else would have reported by now if it were "real", but searching got me nothing.

I have a concat task, that adds a banner with a list of all concatted files. This works when used independantly via grunt concat:concatModule. When fired from a newer:concat via watch when saving one of the files in concat:concatModule's src list, it does not properly print the list of files. The files are concatted correctly and the banner and footer are added - it's only the file list being printed via grunt.task.current.data which doesn't work.

Digging into it, it seems like the src and dest are in grunt.task.current.data.files[0]. I thought, "okay, that makes sense, the newer task has its own data, so the originals are nested in here - I can if around that". But when attempting to write the file list from that location, it seems like the newer task either doesn't properly write to the output, or maybe the banner is processed a second time and the task no longer has references to either grunt.task.current.data or grunt.task.current.data[0].files.

I'm pretty sure the process option on the concat task and the module wrapper strings added to the task are NOT the reason for this error, but I've included them for completeness.

Expected banner output:

/*! 
  packagename - v0.0.0
  filepath/dest.js
  Included Files:
    file1.js,
    file2.js,
    file3.js,
    file4.js,
    file5.js
 */

Generated banner output:

/*! 
  packagename - v0.0.0

 */

Here is the simplified Gruntfile

var concatBanner = '/*! \n  <%= pkg.name %> - v<%= pkg.version %>\n' +
    '<% if (grunt.task.current.data && grunt.task.current.data.src){ %>' +
    '  <%= grunt.task.current.data.dest %>\n' +
    '  Included Files:\n    ' +
    '<%= grunt.task.current.data.src.join("\\n    ") %>' +
    '<% } %>\n */',

    moduleStart = "\n(function(){\n",

    moduleEnd = "\n}());\n";

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
        js: {
            files: [
                '/**/*.js'
            ],
            tasks: [
                'newer:concat'
            ]
        }
    },
    concat: {
        options: {
            separator: ';',
            success: true,
            banner: concatBanner,
            process: function(src, filepath) {
                // Add the filename above each concatenated section
                return '\n\n// FILE: ' + filepath + '\n\n' + src;
            }
        },
        concatModule: {
            nonull: true,
            src: [
                'file1.js',
                'file2.js',
                'file3.js',
                'file4.js',
                'file5.js'
            ],
            options: {
                banner: concatBanner + moduleStart,
                footer: moduleEnd
            }
        },
        otherConcatWithoutModuleWrapper1: {},
        otherConcatWithoutModuleWrapper2: {}
    }
});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-newer');
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

1 participant