fontmin-webpack
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -13,5 +13,11 @@ const fs = require('fs') | ||
const GLYPH_REGEX = /content\s*:[^};]*?('|")(.*?)\s*('|"|;)/g | ||
const UNICODE_REGEX = /\\(\w{4})/ | ||
const UNICODE_REGEX = /\\([0-9a-f]{4,6})/i | ||
const FONTMIN_EXTENSIONS = ['eot', 'woff', 'svg'] | ||
function getSurrogatePair(astralCodePoint) { | ||
const highSurrogate = Math.floor((astralCodePoint - 0x10000) / 0x400) + 0xD800 | ||
const lowSurrogate = ((astralCodePoint - 0x10000) % 0x400) + 0xDC00 | ||
return [highSurrogate, lowSurrogate] | ||
} | ||
class FontminPlugin { | ||
@@ -109,3 +115,15 @@ constructor(options) { | ||
const unicodeMatch = match.match(UNICODE_REGEX) | ||
return unicodeMatch ? String.fromCharCode(parseInt(unicodeMatch[1], 16)) : false | ||
if (!unicodeMatch) { | ||
return false | ||
} | ||
const unicodeHex = unicodeMatch[1] | ||
const numericValue = parseInt(unicodeHex, 16) | ||
const character = String.fromCharCode(numericValue) | ||
if (unicodeHex.length === 4) { | ||
return character | ||
} | ||
const multiCharacter = getSurrogatePair(numericValue) | ||
.map(v => String.fromCharCode(v)) | ||
.join('') | ||
return multiCharacter | ||
}) | ||
@@ -178,9 +196,11 @@ .filter(Boolean) | ||
return minifiableFonts.reduce((prev, group) => { | ||
return prev.then(() => this.minifyFontGroup(group, glyphs)).then(files => { | ||
files.forEach(file => { | ||
if (file.buffer.length > file.minified.length) { | ||
compilation.assets[file.asset] = new RawSource(file.minified) | ||
} | ||
return prev | ||
.then(() => this.minifyFontGroup(group, glyphs)) | ||
.then(files => { | ||
files.forEach(file => { | ||
if (file.buffer.length > file.minified.length) { | ||
compilation.assets[file.asset] = new RawSource(file.minified) | ||
} | ||
}) | ||
}) | ||
}) | ||
}, Promise.resolve()) | ||
@@ -192,2 +212,8 @@ } | ||
compilation.hooks.additionalAssets.tapPromise('FontminPlugin', () => { | ||
if (!compilation.modules || !compilation.assets) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`[fontmin-webpack] Failed to detect modules. Check your webpack version!`) | ||
return Promise.resolve() | ||
} | ||
return this.onAdditionalAssets(compilation) | ||
@@ -194,0 +220,0 @@ }) |
{ | ||
"name": "fontmin-webpack", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Minifies icon fonts to just what is used.", | ||
@@ -31,6 +31,6 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"debug": "^3.0.1", | ||
"fontmin": "^0.9.6", | ||
"lodash": "^4.17.4", | ||
"ttf2woff2": "^3.0.0", | ||
"debug": "^4.3.1", | ||
"fontmin": "^0.9.8", | ||
"lodash": "^4.17.21", | ||
"ttf2woff2": "^4.0.1", | ||
"webpack-sources": "^2.2.0" | ||
@@ -42,16 +42,17 @@ }, | ||
"devDependencies": { | ||
"@mdi/font": "^5.9.55", | ||
"@patrickhulce/lint": "^2.1.3", | ||
"chai": "^4.1.1", | ||
"css-loader": "^5.0.0", | ||
"cz-conventional-changelog": "^2.0.0", | ||
"chai": "^4.3.0", | ||
"css-loader": "^5.0.2", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"file-loader": "^6.2.0", | ||
"font-awesome": "^4.7.0", | ||
"html-webpack-plugin": "^4.5.0", | ||
"mini-css-extract-plugin": "^1.2.1", | ||
"mocha": "^3.2.0", | ||
"rimraf": "^2.5.4", | ||
"html-webpack-plugin": "^5.2.0", | ||
"mini-css-extract-plugin": "^1.3.8", | ||
"mocha": "^8.3.0", | ||
"rimraf": "^3.0.2", | ||
"style-loader": "^2.0.0", | ||
"webpack": "^5.3.2", | ||
"webpack-cli": "^4.1.0" | ||
"webpack": "^5.24.1", | ||
"webpack-cli": "^4.5.0" | ||
} | ||
} |
@@ -17,4 +17,3 @@ const FontminPlugin = require('../../lib') | ||
new MiniCssExtractPlugin({ | ||
filename: 'out.css', | ||
allChunks: true, | ||
filename: 'out.css' | ||
}), | ||
@@ -21,0 +20,0 @@ new HtmlWebpackPlugin(), |
@@ -17,2 +17,3 @@ const fs = require('fs') | ||
const baseExtractConfig = require('./fixtures/webpack.extract-text.config.js') | ||
const baseUnicodeConfig = require('./fixtures/webpack.unicode.config.js') | ||
const originalStats = collectFontStats(FONT_AWESOME_FOLDER + '/fonts', { | ||
@@ -199,2 +200,11 @@ 'fontawesome-webfont.eot': true, | ||
}) | ||
describe('FontAwesome with multi-byte unicode characters', () => { | ||
it('should run successfully', function (done) { | ||
this.timeout(60000) | ||
testWithConfig(baseUnicodeConfig, done) | ||
}) | ||
after(done => rimraf(DIST_FOLDER, done)) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
464
22735
14
14
- Removedansi-regex@2.1.1(transitive)
- Removedaproba@1.2.0(transitive)
- Removedare-we-there-yet@1.1.7(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbufferstreams@2.0.1(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedchownr@1.1.4(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddebug@3.2.7(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedfs-minipass@1.2.7(transitive)
- Removedgauge@2.7.4(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedminipass@2.9.0(transitive)
- Removedminizlib@1.3.3(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednode-gyp@4.0.0(transitive)
- Removednopt@3.0.6(transitive)
- Removednpmlog@4.1.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsemver@5.3.0(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedtar@4.4.19(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedttf2woff2@3.0.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedyallist@3.1.1(transitive)
Updateddebug@^4.3.1
Updatedfontmin@^0.9.8
Updatedlodash@^4.17.21
Updatedttf2woff2@^4.0.1