Skip to content

Commit

Permalink
fix: revert restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Jun 29, 2020
1 parent d5b5788 commit e758837
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function createWebpackLessPlugin(loaderContext) {
mainFields: ['less', 'style', 'main', '...'],
mainFiles: ['index', '...'],
extensions: ['.less', '.css'],
restrictions: [/\.(le|c)ss$/i],
});

class WebpackFileManager extends less.FileManager {
Expand Down
34 changes: 11 additions & 23 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,6 @@ exports[`loader should not alter the original options object: errors 1`] = `Arra
exports[`loader should not alter the original options object: warnings 1`] = `Array []`;
exports[`loader should not resolve when resolve.restrictions no passed: errors 1`] = `
Array [
"ModuleBuildError: Module build failed (from \`replaced original path\`):
",
]
`;
exports[`loader should not resolve when resolve.restrictions no passed: warnings 1`] = `Array []`;
exports[`loader should not to disable webpack's resolver by passing an empty paths array: css 1`] = `
".img {
background: url(some/img.jpg);
Expand Down Expand Up @@ -237,20 +228,6 @@ exports[`loader should not try to resolve CSS imports with URLs: errors 1`] = `A
exports[`loader should not try to resolve CSS imports with URLs: warnings 1`] = `Array []`;
exports[`loader should prefer a main file with "less" extension over main field with js file: css 1`] = `
".modules-dir-some-module {
color: hotpink;
}
.some-class {
background: hotpink;
}
"
`;
exports[`loader should prefer a main file with "less" extension over main field with js file: errors 1`] = `Array []`;
exports[`loader should prefer a main file with "less" extension over main field with js file: warnings 1`] = `Array []`;
exports[`loader should provide a useful error message if the import could not be found: errors 1`] = `
Array [
"ModuleBuildError: Module build failed (from \`replaced original path\`):
Expand Down Expand Up @@ -420,6 +397,17 @@ exports[`loader should resolve nested imports: errors 1`] = `Array []`;
exports[`loader should resolve nested imports: warnings 1`] = `Array []`;
exports[`loader should resolve non-less import with alias: css 1`] = `
".some-file {
background: hotpink;
}
"
`;
exports[`loader should resolve non-less import with alias: errors 1`] = `Array []`;
exports[`loader should resolve non-less import with alias: warnings 1`] = `Array []`;
exports[`loader should resolve unresolved url with alias: css 1`] = `
".box {
color: #fe33ac;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/import-non-less-2.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "../../some.file";
7 changes: 7 additions & 0 deletions test/helpers/getCodeFromLess.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const pathMap = {
'style.less'
),
'/styles/style.less': path.resolve(__dirname, '..', 'fixtures', 'basic.less'),
'../../some.file': path.resolve(
__dirname,
'..',
'fixtures',
'folder',
'some.file'
),
};

class ResolvePlugin extends less.FileManager {
Expand Down
32 changes: 20 additions & 12 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,21 +597,29 @@ describe('loader', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should not resolve when resolve.restrictions no passed', async () => {
const testId = './import-webpack-js-package.less';
const compiler = getCompiler(testId);
const stats = await compile(compiler);

expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it('should prefer a main file with "less" extension over main field with js file', async () => {
const testId = './import-webpack-js-package-2.less';
const compiler = getCompiler(testId);
it('should resolve non-less import with alias', async () => {
const testId = './import-non-less-2.less';
const compiler = getCompiler(
testId,
{},
{
resolve: {
alias: {
'../../some.file': path.resolve(
__dirname,
'fixtures',
'folder',
'some.file'
),
},
},
}
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromLess = await getCodeFromLess(testId);

expect(codeFromBundle.css).toBe(codeFromLess.css);
expect(codeFromBundle.css).toMatchSnapshot('css');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
expect(getErrors(stats)).toMatchSnapshot('errors');
Expand Down

0 comments on commit e758837

Please sign in to comment.