Skip to content

Commit

Permalink
test: code
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Sep 28, 2020
1 parent 678eac8 commit 58b6298
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
31 changes: 13 additions & 18 deletions src/utils.js
Expand Up @@ -238,11 +238,11 @@ async function getDependencies(

const isArray = Array.isArray(resolved);

// `stylus` can return files with glob characters, we should escape them to avid re globbing
// `stylus` returns forward slashes on windows
// eslint-disable-next-line no-param-reassign
result.resolved = isArray
? resolved.map((item) => fastGlob.escapePath(path.normalize(item)))
: fastGlob.escapePath(path.normalize(resolved));
? resolved.map((item) => path.normalize(item))
: path.normalize(resolved);

const dependenciesOfDependencies = [];

Expand Down Expand Up @@ -373,37 +373,32 @@ async function createEvaluator(loaderContext, code, options) {
const { resolved } = dependency;

if (!Array.isArray(resolved)) {
node.string = resolved;
// Avoid re globbing when resolved import contains glob characters
node.string = fastGlob.escapePath(resolved);
} else if (resolved.length > 0) {
let hasError = false;

const blocks = resolved.map((item) => {
const clonedImported = imported.clone();
const clonedNode = this.visit(clonedImported.path).first;

clonedNode.string = item;
// Avoid re globbing when resolved import contains glob characters
clonedNode.string = fastGlob.escapePath(item);

let result;

try {
result = super.visitImport(clonedImported);
} catch (error) {
loaderContext.emitError(
new Error(
`Stylus resolver error: ${error.message}${
webpackResolveError
? `\n\nWebpack resolver error details:\n${webpackResolveError.details}\n\n` +
`Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`
: ''
}`
)
);

return imported;
hasError = true;
}

return result;
});

return mergeBlocks(blocks);
if (!hasError) {
return mergeBlocks(blocks);
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -348,6 +348,20 @@ exports[`loader imports files listed in option as glob: errors 1`] = `Array []`;

exports[`loader imports files listed in option as glob: warnings 1`] = `Array []`;

exports[`loader imports files with special characters listed in glob: css 1`] = `
".directoryfile {
color: #f00;
}
.nestedfile {
color: #f00;
}
"
`;

exports[`loader imports files with special characters listed in glob: errors 1`] = `Array []`;

exports[`loader imports files with special characters listed in glob: warnings 1`] = `Array []`;

exports[`loader imports the right file based on context: css 1`] = `
".a-color {
color: #aaa;
Expand Down
2 changes: 1 addition & 1 deletion test/loader.test.js
Expand Up @@ -844,7 +844,7 @@ describe('loader', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it.skip('imports files with special characters listed in glob', async () => {
it('imports files with special characters listed in glob', async () => {
const testId = './import-glob-special.styl';
const compiler = getCompiler(testId);
const stats = await compile(compiler);
Expand Down

0 comments on commit 58b6298

Please sign in to comment.