Skip to content

Commit

Permalink
🐛 Fixed minifier for Windows users (#21311)
Browse files Browse the repository at this point in the history
ref #15893

This got closed as stale long ago. Resurrecting this as it's a simple
change and will help our Windows-based theme devs in particular.
  • Loading branch information
9larsons authored Nov 21, 2024
1 parent 600b3c6 commit c806cf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion ghost/minifier/lib/Minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const tpl = require('@tryghost/tpl');
const glob = require('tiny-glob');
const path = require('path');
const fs = require('fs').promises;
const isWin = process.platform === 'win32';

const messages = {
badDestination: {
Expand Down Expand Up @@ -69,7 +70,11 @@ class Minifier {
}

async getMatchingFiles(src) {
return await glob(this.getFullSrc(src));
let fullSrc = this.getFullSrc(src);
if (isWin) {
fullSrc = fullSrc.replace(/\\/g,'/');
}
return await glob(fullSrc);
}

async readFiles(files) {
Expand Down
16 changes: 8 additions & 8 deletions ghost/minifier/test/minifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ describe('Minifier', function () {
let result = await minifier.getMatchingFiles('css/*.css');

result.should.be.an.Array().with.lengthOf(3);
result[0].should.eql('test/fixtures/basic-cards/css/bookmark.css');
result[1].should.eql('test/fixtures/basic-cards/css/empty.css');
result[2].should.eql('test/fixtures/basic-cards/css/gallery.css');
result[0].should.eql(path.join('test','fixtures','basic-cards','css','bookmark.css'));
result[1].should.eql(path.join('test','fixtures','basic-cards','css','empty.css'));
result[2].should.eql(path.join('test','fixtures','basic-cards','css','gallery.css'));
});

it('match glob range e.g. css/bookmark.css and css/empty.css (css/@(bookmark|empty).css)', async function () {
let result = await minifier.getMatchingFiles('css/@(bookmark|empty).css');

result.should.be.an.Array().with.lengthOf(2);
result[0].should.eql('test/fixtures/basic-cards/css/bookmark.css');
result[1].should.eql('test/fixtures/basic-cards/css/empty.css');
result[0].should.eql(path.join('test','fixtures','basic-cards','css','bookmark.css'));
result[1].should.eql(path.join('test','fixtures','basic-cards','css','empty.css'));
});

it('reverse match glob e.g. css/!(bookmark).css', async function () {
let result = await minifier.getMatchingFiles('css/!(bookmark).css');

result.should.be.an.Array().with.lengthOf(2);
result[0].should.eql('test/fixtures/basic-cards/css/empty.css');
result[1].should.eql('test/fixtures/basic-cards/css/gallery.css');
result[0].should.eql(path.join('test','fixtures','basic-cards','css','empty.css'));
result[1].should.eql(path.join('test','fixtures','basic-cards','css','gallery.css'));
});
it('reverse match glob e.g. css/!(bookmark|gallery).css', async function () {
let result = await minifier.getMatchingFiles('css/!(bookmark|gallery).css');

result.should.be.an.Array().with.lengthOf(1);
result[0].should.eql('test/fixtures/basic-cards/css/empty.css');
result[0].should.eql(path.join('test','fixtures','basic-cards','css','empty.css'));
});
});

Expand Down

0 comments on commit c806cf6

Please sign in to comment.