Skip to content

Commit

Permalink
Fix Windows compatibility
Browse files Browse the repository at this point in the history
Fixes #98
  • Loading branch information
sindresorhus committed Nov 15, 2023
1 parent 3216691 commit 1513d7a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
yarn.lock
dest
Empty file added fixtures/foo.css
Empty file.
Empty file added fixtures/foo.js
Empty file.
Empty file added fixtures/foo.txt
Empty file.
8 changes: 8 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import gulp from 'gulp';
import filter from './index.js';

export default function main() {
return gulp.src('fixtures/**/*')
.pipe(filter('**/*.css'))
.pipe(gulp.dest('dest'));
}
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import process from 'node:process';
import path from 'node:path';
import PluginError from 'plugin-error';
import multimatch from 'multimatch';
import streamfilter from 'streamfilter';
import toAbsoluteGlob from 'to-absolute-glob';
import slash from 'slash';

export default function plugin(pattern, options = {}) {
pattern = typeof pattern === 'string' ? [pattern] : pattern;
Expand All @@ -19,7 +21,8 @@ export default function plugin(pattern, options = {}) {
match = pattern(file);
} else {
const base = path.dirname(file.path);
const patterns = pattern.map(pattern => {

let patterns = pattern.map(pattern => {
// Filename only matching glob, prepend full path.
if (!pattern.includes('/')) {
if (pattern[0] === '!') {
Expand All @@ -40,6 +43,10 @@ export default function plugin(pattern, options = {}) {
return path.resolve(pattern);
});

if (process.platform === 'win32') {
patterns = patterns.map(pattern => slash(pattern));
}

match = multimatch(path.resolve(file.cwd, file.path), patterns, options).length > 0;
}

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"type": "module",
"exports": "./index.js",
"sideEffects": false,
"engines": {
"node": ">=18"
},
Expand All @@ -36,11 +37,13 @@
"dependencies": {
"multimatch": "^7.0.0",
"plugin-error": "^2.0.1",
"slash": "^5.1.0",
"streamfilter": "^3.0.0",
"to-absolute-glob": "^3.0.0"
},
"devDependencies": {
"ava": "^5.3.1",
"gulp": "^4.0.2",
"p-event": "^6.0.0",
"vinyl": "^3.0.0",
"xo": "^0.56.0"
Expand Down

0 comments on commit 1513d7a

Please sign in to comment.