Skip to content

Commit

Permalink
Merge branch 'feature/glob-empty-dir'
Browse files Browse the repository at this point in the history
  • Loading branch information
maoberlehner committed Jan 13, 2018
2 parents 4bfa6a2 + 53bf377 commit fe3c0b8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/node-sass-glob-importer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export = function globImporter() {

const filePaths = resolveGlobUrl(url, includePaths);

if (filePaths.length) {
if (filePaths) {
const contents = filePaths
.map((x: string) => `@import '${x}';`)
.join(`\n`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe(`resolveGlobUrl()`, () => {
const result = resolveGlobUrl(`test/url`);

expect(globMock.hasMagic).toBeCalled();
expect(result).toEqual([]);
expect(result).toEqual(null);
});

test(`It should return found glob file paths.`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export function resolveGlobUrlFactory(
.split(`\\`).join(`/`));
});
});

return [...filePaths];
}

return [...filePaths];
return null;
};
}
2 changes: 1 addition & 1 deletion packages/node-sass-magic-importer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export = function magicImporter(userOptions?: IMagicImporterOptions) {
filterPrefix = `${url.split(` from `)[0]} from `;
}

if (globFilePaths.length) {
if (globFilePaths) {
const contents = globFilePaths
.filter((x) => !store.has(getStoreId(x, selectorFilters, nodeFilters)))
.map((x) => `@import '${filterPrefix}${x}';`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type IResolveGlobUrl = (
url: string,
includePaths?: string[],
) => string[];
) => string[]|null;
Empty file added test/files/empty-dir/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions test/files/glob-import-empty-dir.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'empty-dir/*.scss';
11 changes: 11 additions & 0 deletions test/glob-importer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ describe(`globImporter()`, () => {
expect(result).toBe(expectedResult);
});

test(`Should not fail when dir is empty.`, () => {
const expectedResult = ``;

const result = sass.renderSync({
file: `test/files/glob-import-empty-dir.scss`,
importer: globImporter(),
}).css.toString();

expect(result).toBe(expectedResult);
});

test(`It should import glob files via CLI.`, async () => {
// tslint:disable-next-line max-line-length
const cmd = `node node_modules/.bin/node-sass --importer packages/node-sass-glob-importer/dist/cli.js test/files/glob-import.scss`;
Expand Down

0 comments on commit fe3c0b8

Please sign in to comment.