Skip to content

Commit 619dc21

Browse files
Handle globs using Windows separators (#547)
* Handle globs using Windows separators Glob patterns are being generated with Windows separators when running `gasket create` on Windows which causes `glob` to not find any files. Fix up pattern before passing to `glob`. * fix: lock file --------- Co-authored-by: Andrew Gerard <agerard@godaddy.com>
1 parent 4ba76c6 commit 619dc21

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

packages/gasket-cli/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `@gasket/cli`
22

3+
- Fix generation of files on Windows during gasket create when plugins use globs containing Windows separators
4+
35
### 6.34.6
46

57
- Retain destOverride from provided create context ([#480])

packages/gasket-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"test:integration:coverage": "nyc --reporter=text --reporter=json-summary --all run-s test:integration",
2929
"test:mocha": "mocha --require test/setup.js --recursive \"test/**/*.test.js\"",
3030
"test:unit": "mocha --require test/setup.js --recursive \"test/unit/**/*.test.js\"",
31+
"test:unit:watch": "npm run test:unit -- --watch",
3132
"test:unit:coverage": "nyc --reporter=text --reporter=lcov --all run-s test:unit"
3233
},
3334
"repository": {

packages/gasket-cli/src/scaffold/actions/generate-files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ async function getDescriptors(context) {
7979
await Promise.all(files.globSets.map(async set => {
8080
const { globs, source } = set;
8181
const matches = await Promise.all(globs.map(async pattern => {
82+
pattern = splitSep(pattern).join('/'); // Glob uses / for all OS's
8283
const srcPaths = await glob(pattern, { nodir: true });
8384
return assembleDescriptors(dest, source.name, pattern, srcPaths);
8485
}));

packages/gasket-cli/test/unit/scaffold/actions/generate-files.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ describe('generateFiles', () => {
276276
assume(results).lengthOf(5);
277277
});
278278

279+
it('works with Windows path separators', async function () {
280+
mockContext.files.globSets = [{
281+
globs: [fixtures + '\\generator\\**\\*'],
282+
source: {
283+
name: '@gasket/plugin-example'
284+
}
285+
}];
286+
const results = await generateFiles._getDescriptors(mockContext);
287+
assume(results).lengthOf(5);
288+
});
289+
279290
it('reduces duplicates with overrides prop', async function () {
280291
mockContext.files.globSets = [{
281292
globs: [fixtures + '/generator/*'],
@@ -333,15 +344,15 @@ describe('generateFiles', () => {
333344
// mixed slashes for testing
334345
'C:\\path\\to/my-app',
335346
from,
336-
'C:\\gasket-cli\\test\\fixtures/rel/../generator/*',
347+
'C:/gasket-cli/test/fixtures/rel/../generator/*',
337348
[
338349
'C:\\gasket-cli\\test\\fixtures\\generator\\file-a.md',
339350
// glob may return with forward-slash
340351
'C:/gasket-cli/test/fixtures/generator/file-b.md'
341352
]
342353
);
343354
assume(results[0]).objectContaining({
344-
pattern: 'C:\\gasket-cli\\test\\fixtures/rel/../generator/*',
355+
pattern: 'C:/gasket-cli/test/fixtures/rel/../generator/*',
345356
base: 'C:\\gasket-cli\\test\\fixtures\\generator',
346357
srcFile: sinon.match('C:\\gasket-cli\\test\\fixtures\\generator\\file-a.md'),
347358
targetFile: 'C:\\path\\to\\my-app\\file-a.md',

0 commit comments

Comments
 (0)