Skip to content

Filenames containing dots get cut off #54

Closed
tomcode opened this Issue May 3, 2013 · 6 comments

5 participants

@tomcode
tomcode commented May 3, 2013

I have set up a task to minify, add the suffix .min and write to file to the same folder:

expected result
dragin/without_dots.js.js -> dragin/without_dots.js.min.js
dragin/dragin.jquery.js -> dragin/dragin.jquery.min.js

obtained result
dragin/without_dots.js.js -> dragin/without_dots.js.min.js
dragin/dragin.jquery.js -> dragin/dragin.min.js

the .jquery part of dragin.jquery.js gets cut off

Output of

grunt uglify:dragin --verbose --debug --stack
Running "uglify:dragin" (uglify) task
Verifying property uglify.dragin exists in config...OK
Files: htdocs/assets/dragin/dragin.jquery.js -> htdocs/assets/dragin/dragin.min.js
Files: htdocs/assets/dragin/without_dots.js -> htdocs/assets/dragin/without_dots.min.js
Minifying with UglifyJS...Reading htdocs/assets/dragin/dragin.jquery.js...OK
OK
Writing htdocs/assets/dragin/dragin.min.js...OK
File "htdocs/assets/dragin/dragin.min.js" created.
Minifying with UglifyJS...Reading htdocs/assets/dragin/without_dots.js...OK
OK
Writing htdocs/assets/dragin/without_dots.min.js...OK
File "htdocs/assets/dragin/without_dots.min.js" created.

Done, without errors.

My task configuration

      // Does not work with filenames containing dots
      dragin: {
        // Grunt will search for "**/*.js" under "lib/" when the "minify" task
        // runs and build the appropriate src-dest file mappings then, so you
        // don't need to update the Gruntfile when files are added or removed.
        files: [
          {
            expand: true,     // Enable dynamic expansion.
            cwd: 'htdocs/assets/dragin/',      // Src matches are relative to this path.
            src: ['**/*.js', '!*.min.js'], // Actual pattern(s) to match.
            dest: 'htdocs/assets/dragin/',   // Destination path prefix.
            ext: '.min.js'    // Dest filepaths will have this extension.
          }
        ]
      }
@davidcl64

+1

Is there a known workaround for this?

@existentialism

The ext option doesn't necessarily work as you'd expect, it replaces everything from the first '.' it finds.

Check out: gruntjs/grunt#625

To get it working how you're wanting, pass a rename function to implement whatever renaming logic you need.

@davidcl64

Thank you for the workaround and, while I understand the discussion held in gruntjs/grunt#625 it does seem to be redefining convention.

http://en.wikipedia.org/wiki/Filename_extension

Other than behaving in an unexpected fashion (by convention anyway), what is the most common use case for uglify? If it is to minify js code, the current behavior flies in the face of DRY as anyone using grunt to minify JS could using expansion now has to implement the code to use the last dot convention. It's not that it isn't trivial, just that it shouldn't be necessary.

If it would be considered too much of a breaking change to use the more standard convention by default, perhaps an additional configuration parameter: useLastDot: true to change the behavior could be considered?

Or if someone was feeling really energetic useDot: n where n is a negative or positive number (1 == first dot, -1 == last dot, -2 == second to last dot [.min.js])

The explaination given in gruntjs/grunt#625 also seems a bit flawed in that a quick glance around at jquery plugins should a number with multiple dots in the names (i.e.: myplugin.jquery.js ==> myplugin.jquery.min.js) First dot convention is broken here as well. Or perhaps I am missing something more fundamental?

@existentialism

@davidcl64 I don't disagree with you one bit :)

Both @tkellen and @cowboy mention revisiting this in gruntjs/grunt#750, so I would definitely continue the conversation over there as this affects more than just the uglify plugin.

@davidcl64

sounds like a plan! :)

@davidcl64 davidcl64 referenced this issue in gruntjs/grunt May 5, 2013
Closed

extension is after _last_ period only #750

@renatoargh

this thread has helped me! :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.