Skip to content

Commit

Permalink
Merge pull request #2551 from koddsson/update-glob
Browse files Browse the repository at this point in the history
update glob to latest version
  • Loading branch information
koddsson authored Nov 13, 2023
2 parents 6eceb7e + ff1ba1b commit 3a9d007
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 87 deletions.
6 changes: 6 additions & 0 deletions .changeset/twenty-eels-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@web/rollup-plugin-copy': patch
'@web/rollup-plugin-html': patch
---

Update the `glob` dependency
151 changes: 115 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/rollup-plugin-copy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
"copy"
],
"dependencies": {
"glob": "^7.1.6"
"glob": "^10.0.0"
},
"devDependencies": {
"@types/glob": "^7.1.3"
"@types/glob": "^8.1.0"
},
"types": "dist/copy.d.ts"
}
24 changes: 10 additions & 14 deletions packages/rollup-plugin-copy/src/listFiles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const glob = require('glob');
const { glob } = require('glob');
const fs = require('fs');
const path = require('path');

Expand All @@ -11,19 +11,15 @@ const path = require('path');
* @param {string} rootDir
* @param {string|string[]} [ignore]
*/
function listFiles(fromGlob, rootDir, ignore) {
return new Promise(resolve => {
glob(fromGlob, { cwd: rootDir, dot: true, ignore }, (er, files) => {
// remember, each filepath returned is relative to rootDir
resolve(
files
// fully resolve the filename relative to rootDir
.map(filePath => path.resolve(rootDir, filePath))
// filter out directories
.filter(filePath => !fs.lstatSync(filePath).isDirectory()),
);
});
});
async function listFiles(fromGlob, rootDir, ignore) {
// remember, each filepath returned is relative to rootDir
return (
(await glob(fromGlob, { cwd: rootDir, dot: true, ignore }))
// fully resolve the filename relative to rootDir
.map(filePath => path.resolve(rootDir, filePath))
// filter out directories
.filter(filePath => !fs.lstatSync(filePath).isDirectory())
);
}

module.exports = { listFiles };
10 changes: 6 additions & 4 deletions packages/rollup-plugin-copy/test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ describe('rollup-plugin-copy', () => {
const { output } = await bundle.generate({ format: 'es' });

expect(output.length).to.equal(5);
expect(output[1].fileName).to.equal('a.svg');
expect(output[2].fileName).to.equal('b.svg');
expect(output[3].fileName).to.equal(`sub${path.sep}sub-a.svg`);
expect(output[4].fileName).to.equal(`sub${path.sep}sub-b.mark.svg`);
expect(output.map(x => x.fileName).filter(x => x.endsWith('.svg'))).to.have.members([
'a.svg',
'b.svg',
'sub/sub-a.svg',
'sub/sub-b.mark.svg',
]);
});
});
16 changes: 10 additions & 6 deletions packages/rollup-plugin-copy/test/listFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ describe('listFiles', () => {
it('gives a list of files', async () => {
const files = await listFiles('*.svg', path.resolve(__dirname, './fixture/'));
expect(files.length).to.equal(2);
expect(files[0]).to.match(/fixture(\/|\\)a\.svg$/);
expect(files[1]).to.match(/fixture(\/|\\)b\.svg$/);
expect(files).to.have.members([
path.join(__dirname, './fixture/a.svg'),
path.join(__dirname, './fixture/b.svg'),
]);
});

it('only gives files and no folders', async () => {
const files = await listFiles('**/*.svg', path.resolve(__dirname, './fixture/'));
expect(files.length).to.equal(4);
expect(files[0]).to.match(/fixture(\/|\\)a\.svg$/);
expect(files[1]).to.match(/fixture(\/|\\)b\.svg$/);
expect(files[2]).to.match(/fixture(\/|\\)sub(\/|\\)sub-a\.svg$/);
expect(files[3]).to.match(/fixture(\/|\\)sub(\/|\\)sub-b\.mark\.svg$/);
expect(files).to.have.members([
path.join(__dirname, './fixture/a.svg'),
path.join(__dirname, './fixture/b.svg'),
path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
path.join(__dirname, './fixture/sub/sub-a.svg'),
]);
});

it('will copy files inside dot folders', async () => {
Expand Down
14 changes: 9 additions & 5 deletions packages/rollup-plugin-copy/test/patternsToFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ describe('patternsToFiles', () => {
it('works with a string', async () => {
const files = await patternsToFiles('*.svg', path.resolve(__dirname, './fixture/'));
expect(files.length).to.equal(2);
expect(files[0]).to.match(/fixture(\/|\\)a\.svg$/);
expect(files[1]).to.match(/fixture(\/|\\)b\.svg$/);
expect(files).to.have.members([
path.join(__dirname, './fixture/a.svg'),
path.join(__dirname, './fixture/b.svg'),
]);
});

it('works with an array of strings ', async () => {
Expand All @@ -17,8 +19,10 @@ describe('patternsToFiles', () => {
path.resolve(__dirname, './fixture/'),
);
expect(files.length).to.equal(3);
expect(files[0]).to.match(/fixture(\/|\\)a\.svg$/);
expect(files[1]).to.match(/fixture(\/|\\)b\.svg$/);
expect(files[2]).to.match(/fixture(\/|\\)sub(\/|\\)sub-b\.mark\.svg$/);
expect(files).to.have.members([
path.join(__dirname, './fixture/a.svg'),
path.join(__dirname, './fixture/b.svg'),
path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
]);
});
});
2 changes: 1 addition & 1 deletion packages/rollup-plugin-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
],
"dependencies": {
"@web/parse5-utils": "^2.1.0",
"glob": "^7.1.6",
"glob": "^10.0.0",
"html-minifier-terser": "^7.1.0",
"parse5": "^6.0.1"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/rollup-plugin-html/src/input/getInputData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import glob from 'glob';
import { globSync, GlobOptionsWithFileTypesFalse } from 'glob';

import { createError } from '../utils.js';
import { RollupPluginHTMLOptions } from '../RollupPluginHTMLOptions.js';
Expand All @@ -9,8 +9,8 @@ import { normalizeInputOptions } from './normalizeInputOptions.js';
import { extractModulesAndAssets } from './extract/extractModulesAndAssets.js';
import { InputOption } from 'rollup';

function resolveGlob(fromGlob: string, opts: glob.IOptions) {
const files = glob.sync(fromGlob, { ...opts, absolute: true });
function resolveGlob(fromGlob: string, opts: GlobOptionsWithFileTypesFalse) {
const files = globSync(fromGlob, { ...opts, absolute: true });
return (
files
// filter out directories
Expand Down
Loading

0 comments on commit 3a9d007

Please sign in to comment.