Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixed minifier for Windows users #21311

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading