Skip to content

Commit 9bd9b08

Browse files
authored
Merge pull request #122 from andersk/upgrade
Upgrade dependencies
2 parents 21807ca + ad2941d commit 9bd9b08

20 files changed

+212
-230
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ npm-debug.log
33
node_modules
44
fonts/dest*
55
/coverage
6-
.nyc_output
76
package-lock.json
87
test/ts/example.js

cli.js

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77

88
/* eslint-env node */
99

10-
'use strict';
11-
12-
var fs = require('fs');
13-
var meow = require('meow');
14-
var path = require('path');
15-
var stdin = require('get-stdin');
16-
var Fontmin = require('./');
17-
var _ = require('lodash');
10+
import * as fs from 'fs';
11+
import meow from 'meow';
12+
import * as path from 'path';
13+
import stdin from 'get-stdin';
14+
import Fontmin from './index.js';
15+
import _ from 'lodash';
1816

1917
var cli = meow({
18+
importMeta: import.meta,
2019
help: [
2120
'Usage',
2221
' $ fontmin <file> [<output>]',
@@ -37,35 +36,17 @@ var cli = meow({
3736
' --font-family font-family for @font-face CSS',
3837
' --css-glyph generate class for each glyf. default = false',
3938
' -T, --show-time show time fontmin cost'
40-
].join('\n')
41-
}, {
42-
'boolean': [
43-
'basic-text',
44-
'show-time',
45-
'deflate-woff',
46-
'css-glyph',
47-
'version'
48-
],
49-
'string': [
50-
'text',
51-
'font-family'
52-
],
53-
'alias': {
54-
t: 'text',
55-
b: 'basic-text',
56-
d: 'deflate-woff',
57-
T: 'show-time',
58-
h: 'help',
59-
v: 'version'
60-
}
39+
].join('\n'),
40+
flags: {
41+
basicText: { type: 'boolean', shortFlag: 'b' },
42+
showTime: { type: 'boolean', shortFlag: 'T' },
43+
deflateWoff: { type: 'boolean', shortFlag: 'd' },
44+
cssGlyph: { type: 'boolean' },
45+
text: { type: 'string', shortFlag: 't' },
46+
fontFamily: { type: 'string' },
47+
},
6148
});
6249

63-
// version
64-
if (cli.flags.version) {
65-
console.log(require('./package.json').version);
66-
process.exit(0);
67-
}
68-
6950
function isFile(path) {
7051
if (/^[^\s]+\.\w*$/.test(path)) {
7152
return true;

index.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@
55

66
/* eslint-env node */
77

8-
var combine = require('stream-combiner');
9-
var concat = require('concat-stream');
10-
var EventEmitter = require('events').EventEmitter;
11-
var inherits = require('util').inherits;
12-
var bufferToVinyl = require('buffer-to-vinyl');
13-
var vfs = require('vinyl-fs');
8+
import combine from 'stream-combiner';
9+
import concat from 'concat-stream';
10+
import { EventEmitter } from 'events';
11+
import { inherits } from 'util';
12+
import * as bufferToVinyl from 'buffer-to-vinyl';
13+
import vfs from 'vinyl-fs';
14+
15+
import * as util from './lib/util.js';
16+
import mime from './lib/mime-types.js';
17+
18+
import glyph from './plugins/glyph.js';
19+
import ttf2eot from './plugins/ttf2eot.js';
20+
import ttf2woff from './plugins/ttf2woff.js';
21+
import ttf2woff2 from './plugins/ttf2woff2.js';
22+
import ttf2svg from './plugins/ttf2svg.js';
23+
import css from './plugins/css.js';
24+
import svg2ttf from './plugins/svg2ttf.js';
25+
import svgs2ttf from './plugins/svgs2ttf.js';
26+
import otf2ttf from './plugins/otf2ttf.js';
1427

1528
/**
1629
* Initialize Fontmin
@@ -150,7 +163,8 @@ Fontmin.prototype.getFiles = function () {
150163
return bufferToVinyl.stream(this._src[0]);
151164
}
152165

153-
return vfs.src.apply(vfs, this.src());
166+
var [src, options] = this.src();
167+
return vfs.src(src, {encoding: false, ...options});
154168
};
155169

156170
/**
@@ -171,16 +185,21 @@ Fontmin.plugins = [
171185
];
172186

173187
// export pkged plugins
174-
Fontmin.plugins.forEach(function (plugin) {
175-
Fontmin[plugin] = require('./plugins/' + plugin);
176-
});
188+
Fontmin.glyph = glyph;
189+
Fontmin.ttf2eot = ttf2eot;
190+
Fontmin.ttf2woff = ttf2woff;
191+
Fontmin.ttf2woff2 = ttf2woff2;
192+
Fontmin.ttf2svg = ttf2svg;
193+
Fontmin.css = css;
194+
Fontmin.svg2ttf = svg2ttf;
195+
Fontmin.svgs2ttf = svgs2ttf;
196+
Fontmin.otf2ttf = otf2ttf;
177197

178198
/**
179199
* Module exports
180200
*/
181-
module.exports = Fontmin;
182201

183-
// exports util, mime
184-
module.exports.default = Fontmin;
185-
module.exports.util = exports.util = require('./lib/util');
186-
module.exports.mime = exports.mime = require('./lib/mime-types');
202+
export { util, mime };
203+
export default Fontmin;
204+
Fontmin.util = util;
205+
Fontmin.mime = mime;

lib/mime-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/* eslint-env node */
77

8-
module.exports = exports = {
8+
export default {
99
'.*': 'application/octet-stream',
1010
'ttf': 'application/font-sfnt',
1111
'otf': 'application/font-sfnt',

lib/util.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
/* eslint-env node */
77

8-
var fs = require('fs');
9-
var path = require('path');
10-
var _ = require('lodash');
11-
var codePoints = require('code-points');
8+
import * as fs from 'fs';
9+
import * as path from 'path';
10+
import _ from 'lodash';
11+
import codePoints from 'code-points';
1212

1313
/**
1414
* getFontFolder
1515
*
1616
* @return {string} fontFolder
1717
*/
18-
function getFontFolder() {
18+
export function getFontFolder() {
1919
return path.resolve({
2020
win32: '/Windows/fonts',
2121
darwin: '/Library/Fonts',
@@ -29,7 +29,7 @@ function getFontFolder() {
2929
* @param {string} path path
3030
* @return {Array} fonts
3131
*/
32-
function getFonts() {
32+
export function getFonts() {
3333
return fs.readdirSync(getFontFolder());
3434
}
3535

@@ -42,7 +42,7 @@ function getFonts() {
4242
* @param {string} str target text
4343
* @return {string} pure text
4444
*/
45-
function getPureText(str) {
45+
export function getPureText(str) {
4646

4747
// fix space
4848
var emptyTextMap = {};
@@ -77,7 +77,7 @@ function getPureText(str) {
7777
* @param {string} str target text
7878
* @return {string} uniq text
7979
*/
80-
function getUniqText(str) {
80+
export function getUniqText(str) {
8181
return _.uniq(
8282
str.split('')
8383
).join('');
@@ -99,7 +99,7 @@ var basicText = String.fromCharCode.apply(this, _.range(33, 126));
9999
* @param {Object} opts opts
100100
* @return {string} subset text
101101
*/
102-
function getSubsetText(opts) {
102+
export function getSubsetText(opts) {
103103

104104
var text = opts.text || '';
105105

@@ -118,13 +118,6 @@ function getSubsetText(opts) {
118118
* @param {string} str string
119119
* @return {Array} unicodes
120120
*/
121-
function string2unicodes(str) {
121+
export function string2unicodes(str) {
122122
return _.uniq(codePoints(str));
123123
}
124-
125-
exports.getFontFolder = getFontFolder;
126-
exports.getFonts = getFonts;
127-
exports.getPureText = getPureText;
128-
exports.getUniqText = getUniqText;
129-
exports.getSubsetText = getSubsetText;
130-
exports.string2unicodes = string2unicodes;

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "fontmin",
33
"version": "1.1.0",
44
"description": "Minify font seamlessly, font subsetter, webfont (eot, woff, svg) converter.",
5+
"type": "module",
56
"main": "index.js",
67
"types": "index.d.ts",
78
"keywords": [
@@ -31,47 +32,47 @@
3132
"license": "MIT",
3233
"repository": "ecomfe/fontmin",
3334
"engines": {
34-
"node": ">=12"
35+
"node": ">=18"
3536
},
3637
"bin": {
3738
"fontmin": "cli.js"
3839
},
3940
"scripts": {
4041
"test": "mocha test/*.spec.js",
41-
"coverage": "nyc mocha --reporter spec --check-leaks test/*.spec.js"
42+
"coverage": "c8 mocha --reporter spec --check-leaks test/*.spec.js"
4243
},
4344
"exports": {
4445
"require": "./index.js",
4546
"import": "./index.js"
4647
},
4748
"dependencies": {
48-
"@types/node": "^12.20.55",
49+
"@types/node": "*",
4950
"@types/through2": "^2.0.38",
5051
"b3b": "^0.0.1",
5152
"buffer-to-vinyl": "^1.0.0",
5253
"code-points": "^2.0.0-1",
5354
"concat-stream": "^2.0.0",
5455
"fonteditor-core": "^2.4.0",
55-
"get-stdin": "^8.0.0",
56+
"get-stdin": "^9.0.0",
5657
"is-otf": "^0.1.2",
57-
"is-svg": "^4.2.1",
58+
"is-svg": "^5.1.0",
5859
"is-ttf": "^0.2.2",
5960
"lodash": "^4.17.10",
60-
"meow": "^9.0.0",
61+
"meow": "^13.2.0",
6162
"pako": "^2.0.3",
6263
"replace-ext": "^2.0.0",
6364
"stream-combiner": "^0.2.1",
6465
"through2": "^4.0.2",
65-
"ttf2woff2": "^4.0.1",
66-
"vinyl-fs": "^3.0.3"
66+
"ttf2woff2": "^6.0.1",
67+
"vinyl-fs": "^4.0.0"
6768
},
6869
"devDependencies": {
69-
"chai": "^4.1.2",
70+
"c8": "^10.1.2",
71+
"chai": "^5.1.2",
7072
"gulp-clean": "^0.4.0",
7173
"is-eot": "^1.0.0",
7274
"is-woff": "^1.0.1",
7375
"is-woff2": "^1.0.0",
74-
"mocha": "^9.1.1",
75-
"nyc": "^15.1.0"
76+
"mocha": "^10.8.2"
7677
}
7778
}

plugins/css.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
*/
55

66
/* eslint-env node */
7-
var _ = require('lodash');
8-
var fs = require('fs');
9-
var path = require('path');
10-
var isTtf = require('is-ttf');
11-
var through = require('through2');
12-
var replaceExt = require('replace-ext');
13-
var b2a = require('b3b').b2a;
7+
import _ from 'lodash';
8+
import * as fs from 'fs';
9+
import * as path from 'path';
10+
import * as url from 'url';
11+
import isTtf from 'is-ttf';
12+
import through from 'through2';
13+
import replaceExt from 'replace-ext';
14+
import { b2a } from 'b3b';
1415

1516
/**
1617
* tpl
1718
*
1819
* @type {string}
1920
*/
2021
var tpl = fs.readFileSync(
21-
path.resolve(__dirname, '../lib/font-face.tpl')
22+
url.fileURLToPath(new URL('../lib/font-face.tpl', import.meta.url))
2223
).toString('utf-8');
2324

2425
/**
@@ -112,7 +113,7 @@ function getFontFamily(fontInfo, ttf, opts) {
112113
* @return {Object} stream.Transform instance
113114
* @api public
114115
*/
115-
module.exports = function (opts) {
116+
export default function (opts) {
116117
opts = opts || {};
117118

118119
return through.ctor({

plugins/glyph.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55

66
/* eslint-env node */
77

8-
var _ = require('lodash');
9-
var isTtf = require('is-ttf');
10-
var through = require('through2');
11-
var TTF = require('fonteditor-core').TTF;
12-
var TTFReader = require('fonteditor-core').TTFReader;
13-
var TTFWriter = require('fonteditor-core').TTFWriter;
14-
var b2ab = require('b3b').b2ab;
15-
var ab2b = require('b3b').ab2b;
16-
var util = require('../lib/util');
8+
import _ from 'lodash';
9+
import isTtf from 'is-ttf';
10+
import through from 'through2';
11+
import fonteditorCore from 'fonteditor-core';
12+
import { b2ab, ab2b } from 'b3b';
13+
import * as util from '../lib/util.js';
1714

1815
/**
1916
* getSubsetGlyfs
@@ -56,7 +53,7 @@ function minifyFontObject(ttfObject, subset, plugin) {
5653
}
5754

5855
// new TTF Object
59-
var ttf = new TTF(ttfObject);
56+
var ttf = new fonteditorCore.TTF(ttfObject);
6057

6158
// get target glyfs then set
6259
ttf.setGlyf(getSubsetGlyfs(ttf, subset));
@@ -84,7 +81,7 @@ function minifyTtf(contents, opts) {
8481
var ttfobj = contents;
8582

8683
if (Buffer.isBuffer(contents)) {
87-
ttfobj = new TTFReader(opts).read(b2ab(contents));
84+
ttfobj = new fonteditorCore.TTFReader(opts).read(b2ab(contents));
8885
}
8986

9087
var miniObj = minifyFontObject(
@@ -94,7 +91,7 @@ function minifyTtf(contents, opts) {
9491
);
9592

9693
var ttfBuffer = ab2b(
97-
new TTFWriter(Object.assign({writeZeroContoursGlyfData: true}, opts)).write(miniObj)
94+
new fonteditorCore.TTFWriter(Object.assign({writeZeroContoursGlyfData: true}, opts)).write(miniObj)
9895
);
9996

10097
return {
@@ -116,7 +113,7 @@ function minifyTtf(contents, opts) {
116113
* @return {Object} stream.Transform instance
117114
* @api public
118115
*/
119-
module.exports = function (opts) {
116+
export default function (opts) {
120117

121118
opts = _.extend({hinting: true, trim: true}, opts);
122119

0 commit comments

Comments
 (0)