diff --git a/src/downloader.ts b/src/downloader.ts index c18f0ab..7fe42ee 100644 --- a/src/downloader.ts +++ b/src/downloader.ts @@ -68,7 +68,11 @@ export class Downloader extends Hookable { const currentCssContent = readFileSync(cssPath, 'utf-8') const currentUrl = (currentCssContent.split(/\r?\n/, 1).shift() || '').replace('/*', '').replace('*/', '').trim() - overwriting = currentUrl !== this.url + if (currentUrl === this.url) { + return + } + + overwriting = true } if (overwriting) { diff --git a/test/download.test.ts b/test/download.test.ts index dfc610e..a9203ac 100644 --- a/test/download.test.ts +++ b/test/download.test.ts @@ -22,7 +22,7 @@ describe('download', () => { rmSync(outputDir, { recursive: true, force: true }) }, 60000) - test('overwriting', async () => { + test('force overwriting when a different url', async () => { const outputDir = temporaryDirectory() const stylePath = 'font.css' const fontsDir = 'fonts' @@ -51,6 +51,33 @@ describe('download', () => { rmSync(outputDir, { recursive: true, force: true }) }, 60000) + test('download only once', async () => { + const outputDir = temporaryDirectory() + const stylePath = 'font.css' + const fontsDir = 'fonts' + const config = { + families: { + Roboto: true + } + } + + const url = constructURL(config) || '' + + await download(url, { outputDir, stylePath, fontsDir }).execute() + + expect(existsSync(join(outputDir, stylePath))).toBe(true) + expect(existsSync(join(outputDir, fontsDir))).toBe(true) + expect(readFileSync(join(outputDir, stylePath), 'utf-8')).toContain(url) + rmSync(join(outputDir, fontsDir), { recursive: true, force: true }) + + await download(url, { outputDir, stylePath, fontsDir }).execute() + + expect(existsSync(join(outputDir, stylePath))).toBe(true) + expect(existsSync(join(outputDir, fontsDir))).toBe(false) + + rmSync(outputDir, { recursive: true, force: true }) + }, 60000) + test('base64', async () => { const outputDir = temporaryDirectory() const stylePath = 'font.css'