Skip to content

Commit

Permalink
Remove filename-unsafe but package-safe characters from bundle name (#…
Browse files Browse the repository at this point in the history
…285)

* prettify the plugins test

* replace package-safe but non-filesafe characters in package name

* use the `sanitize-filename` module for entry name

* remove sanitizeFilename indirection
  • Loading branch information
chee authored and devongovett committed Dec 20, 2017
1 parent 1947a15 commit df02196
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"postcss-value-parser": "^3.3.0",
"posthtml": "^0.10.1",
"resolve": "^1.4.0",
"sanitize-filename": "^1.6.1",
"serve-static": "^1.12.4",
"uglify-es": "^3.2.1",
"v8-compile-cache": "^1.1.0",
Expand Down
8 changes: 6 additions & 2 deletions src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require('./utils/fs');
const objectHash = require('./utils/objectHash');
const md5 = require('./utils/md5');
const isURL = require('./utils/is-url');
const sanitizeFilename = require('sanitize-filename');

let ASSET_ID = 1;

Expand Down Expand Up @@ -151,9 +152,12 @@ class Asset {
: null;
let ext = '.' + this.type;

// If this asset is main file of the package, use the package name
// If this asset is main file of the package, use the sanitized package name
if (this.name === main) {
return this.package.name + ext;
const packageName = sanitizeFilename(this.package.name, {
replacement: '-'
});
return packageName + ext;
}

// If this is the entry point of the root bundle, use the original filename
Expand Down
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4204,6 +4204,12 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@~5.1.0,
version "5.1.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"

sanitize-filename@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/sanitize-filename/-/sanitize-filename-1.6.1.tgz#612da1c96473fa02dccda92dcd5b4ab164a6772a"
dependencies:
truncate-utf8-bytes "^1.0.0"

sass-graph@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/sass-graph/-/sass-graph-2.2.4.tgz#13fbd63cd1caf0908b9fd93476ad43a51d1e0b49"
Expand Down Expand Up @@ -4724,6 +4730,12 @@ trim-right@^1.0.1:
dependencies:
glob "^6.0.4"

truncate-utf8-bytes@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz#405923909592d56f78a5818434b0b78489ca5f2b"
dependencies:
utf8-byte-length "^1.0.1"

[email protected]:
version "0.0.0"
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"
Expand Down Expand Up @@ -4827,6 +4839,10 @@ user-home@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190"

utf8-byte-length@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz#f45f150c4c66eee968186505ab93fcbb8ad6bf61"

util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down

0 comments on commit df02196

Please sign in to comment.