Skip to content

Commit

Permalink
Remove support for subsetPerPage:true (semver-major)
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Aug 8, 2020
1 parent 7609a24 commit 90f109c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 509 deletions.
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -91,8 +91,6 @@ Options:
[boolean] [default: false]
--font-display Injects a font-display value into the @font-face CSS.
[string] [choices: "auto", "block", "swap", "fallback", "optional"] [default: "swap"]
--subset-per-page Create a unique subset for each page.
[boolean] [default: false]
--recursive, -r Crawl all HTML-pages linked with relative and root relative
links. This stays inside your domain
[boolean] [default: false]
Expand Down
13 changes: 7 additions & 6 deletions lib/parseCommandLineOptions.js
Expand Up @@ -72,11 +72,6 @@ module.exports = function parseCommandLineOptions(argv) {
default: 'swap',
choices: ['auto', 'block', 'swap', 'fallback', 'optional'],
})
.options('subset-per-page', {
describe: 'Create a unique subset for each page.',
type: 'boolean',
default: false,
})
.options('recursive', {
alias: 'r',
describe:
Expand Down Expand Up @@ -108,7 +103,13 @@ module.exports = function parseCommandLineOptions(argv) {
type: 'boolean',
default: false,
})
.check(({ harfbuzz }) => {
.check(({ harfbuzz, subsetPerPage }) => {
// Fail instead of silently ignoring legacy switches.
// This prevents --subset-per-page etc. from implicitly being interpreted as 'string',
// which means that it would consume a following non-option cli param
if (subsetPerPage !== undefined) {
return '--[no-]subset-per-page is no longer supported as of subfont 6.0.0';
}
if (harfbuzz && parseInt(process.versions.node) < 10) {
return 'The --harfbuzz option requires node.js 10 or above';
} else {
Expand Down
3 changes: 0 additions & 3 deletions lib/subfont.js
Expand Up @@ -18,7 +18,6 @@ module.exports = async function subfont(
inlineCss = false,
fontDisplay = 'swap',
formats,
subsetPerPage = false,
inPlace = false,
inputFiles = [],
recursive = false,
Expand Down Expand Up @@ -219,7 +218,6 @@ module.exports = async function subfont(
inlineFonts,
inlineCss,
fontDisplay,
subsetPerPage,
formats,
jsPreload,
omitFallbacks: !fallbacks,
Expand Down Expand Up @@ -364,7 +362,6 @@ module.exports = async function subfont(
fontUsage.codepoints.original.length
).padStart(String(maxOriginalCodePoints).length)} codepoints used`;
if (
!subsetPerPage &&
fontUsage.codepoints.page.length !== fontUsage.codepoints.used.length
) {
status += ` (${fontUsage.codepoints.page.length} on this page)`;
Expand Down
17 changes: 8 additions & 9 deletions lib/subsetFonts.js
Expand Up @@ -104,12 +104,12 @@ function getFontFaceDeclarationText(node, relations) {
// Takes the output of fontTracer
function groupTextsByFontFamilyProps(
htmlAsset,
textByPropsArray,
availableFontFaceDeclarations,
isOnPageFn
globalTextByPropsArray,
pageTextByPropsArray,
availableFontFaceDeclarations
) {
const snappedTexts = _.flatMapDeep(textByPropsArray, (textAndProps) => {
const isOnPage = isOnPageFn(textAndProps);
const snappedTexts = _.flatMapDeep(globalTextByPropsArray, (textAndProps) => {
const isOnPage = pageTextByPropsArray.includes(textAndProps);
const family = textAndProps.props['font-family'];
if (family === undefined) {
return [];
Expand Down Expand Up @@ -649,7 +649,6 @@ async function subsetFonts(
subsetPath = 'subfont/',
jsPreload = true,
omitFallbacks = false,
subsetPerPage,
inlineFonts,
inlineCss,
fontDisplay,
Expand Down Expand Up @@ -811,9 +810,9 @@ async function subsetFonts(
} = htmlAssetTextsWithPropsEntry;
htmlAssetTextsWithPropsEntry.fontUsages = groupTextsByFontFamilyProps(
htmlAsset,
subsetPerPage ? textByProps : globalTextByProps,
accumulatedFontFaceDeclarations,
(t) => (subsetPerPage ? true : textByProps.includes(t))
globalTextByProps,
textByProps,
accumulatedFontFaceDeclarations
);
}

Expand Down
128 changes: 43 additions & 85 deletions test/subfont.js
Expand Up @@ -432,98 +432,56 @@ describe('subfont', function () {
);
});

describe('when subsetPerPage is false', function () {
it('should report how many codepoints are used on the page as well as globally', async function () {
const root = encodeURI(
`file://${pathModule.resolve(
__dirname,
'..',
'testdata',
'differentCodepointsOnDifferentPages'
)}`
);

await subfont(
{
subsetPerPage: false,
silent: true,
dryRun: true,
root,
inputFiles: [`${root}/first.html`, `${root}/second.html`],
},
mockConsole
);
expect(mockConsole.log, 'to have a call satisfying', () => {
mockConsole.log(
expect.it(
'to contain',
'400 : 6/214 codepoints used (3 on this page),'
)
);
}).and('to have a call satisfying', () => {
mockConsole.log(
expect.it(
'to contain',
'400 : 6/214 codepoints used (4 on this page),'
)
);
});
});
it('should report how many codepoints are used on the page as well as globally', async function () {
const root = encodeURI(
`file://${pathModule.resolve(
__dirname,
'..',
'testdata',
'differentCodepointsOnDifferentPages'
)}`
);

// Regression test for https://gitter.im/assetgraph/assetgraph?at=5f1ddc1afe6ecd2888764496
it('should not crash in the reporting code when a font has no text on a given page', async function () {
const root = encodeURI(
`file://${pathModule.resolve(
__dirname,
'..',
'testdata',
'noFontUsageOnOnePage'
)}`
await subfont(
{
silent: true,
dryRun: true,
root,
inputFiles: [`${root}/first.html`, `${root}/second.html`],
},
mockConsole
);
expect(mockConsole.log, 'to have a call satisfying', () => {
mockConsole.log(
expect.it('to contain', '400 : 6/214 codepoints used (3 on this page),')
);

await subfont(
{
silent: true,
dryRun: true,
root,
inputFiles: [`${root}/first.html`, `${root}/second.html`],
},
mockConsole
}).and('to have a call satisfying', () => {
mockConsole.log(
expect.it('to contain', '400 : 6/214 codepoints used (4 on this page),')
);
});
});

describe('when subsetPerPage is true', function () {
it('should report how many codepoints are used on the page as well as globally', async function () {
const root = encodeURI(
`file://${pathModule.resolve(
__dirname,
'..',
'testdata',
'differentCodepointsOnDifferentPages'
)}`
);
// Regression test for https://gitter.im/assetgraph/assetgraph?at=5f1ddc1afe6ecd2888764496
it('should not crash in the reporting code when a font has no text on a given page', async function () {
const root = encodeURI(
`file://${pathModule.resolve(
__dirname,
'..',
'testdata',
'noFontUsageOnOnePage'
)}`
);

await subfont(
{
subsetPerPage: true,
silent: true,
dryRun: true,
root,
inputFiles: [`${root}/first.html`, `${root}/second.html`],
},
mockConsole
);
expect(mockConsole.log, 'to have a call satisfying', () => {
mockConsole.log(
expect.it('to contain', '400 : 3/214 codepoints used,')
);
}).and('to have a call satisfying', () => {
mockConsole.log(
expect.it('to contain', '400 : 4/214 codepoints used,')
);
});
});
await subfont(
{
silent: true,
dryRun: true,
root,
inputFiles: [`${root}/first.html`, `${root}/second.html`],
},
mockConsole
);
});

describe('with --dynamic', function () {
Expand Down

0 comments on commit 90f109c

Please sign in to comment.