Skip to content

Commit e758837

Browse files
fix: revert restrictions
1 parent d5b5788 commit e758837

File tree

5 files changed

+39
-36
lines changed

5 files changed

+39
-36
lines changed

src/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function createWebpackLessPlugin(loaderContext) {
2727
mainFields: ['less', 'style', 'main', '...'],
2828
mainFiles: ['index', '...'],
2929
extensions: ['.less', '.css'],
30-
restrictions: [/\.(le|c)ss$/i],
3130
});
3231

3332
class WebpackFileManager extends less.FileManager {

test/__snapshots__/loader.test.js.snap

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,6 @@ exports[`loader should not alter the original options object: errors 1`] = `Arra
188188
189189
exports[`loader should not alter the original options object: warnings 1`] = `Array []`;
190190
191-
exports[`loader should not resolve when resolve.restrictions no passed: errors 1`] = `
192-
Array [
193-
"ModuleBuildError: Module build failed (from \`replaced original path\`):
194-
",
195-
]
196-
`;
197-
198-
exports[`loader should not resolve when resolve.restrictions no passed: warnings 1`] = `Array []`;
199-
200191
exports[`loader should not to disable webpack's resolver by passing an empty paths array: css 1`] = `
201192
".img {
202193
background: url(some/img.jpg);
@@ -237,20 +228,6 @@ exports[`loader should not try to resolve CSS imports with URLs: errors 1`] = `A
237228
238229
exports[`loader should not try to resolve CSS imports with URLs: warnings 1`] = `Array []`;
239230
240-
exports[`loader should prefer a main file with "less" extension over main field with js file: css 1`] = `
241-
".modules-dir-some-module {
242-
color: hotpink;
243-
}
244-
.some-class {
245-
background: hotpink;
246-
}
247-
"
248-
`;
249-
250-
exports[`loader should prefer a main file with "less" extension over main field with js file: errors 1`] = `Array []`;
251-
252-
exports[`loader should prefer a main file with "less" extension over main field with js file: warnings 1`] = `Array []`;
253-
254231
exports[`loader should provide a useful error message if the import could not be found: errors 1`] = `
255232
Array [
256233
"ModuleBuildError: Module build failed (from \`replaced original path\`):
@@ -420,6 +397,17 @@ exports[`loader should resolve nested imports: errors 1`] = `Array []`;
420397
421398
exports[`loader should resolve nested imports: warnings 1`] = `Array []`;
422399
400+
exports[`loader should resolve non-less import with alias: css 1`] = `
401+
".some-file {
402+
background: hotpink;
403+
}
404+
"
405+
`;
406+
407+
exports[`loader should resolve non-less import with alias: errors 1`] = `Array []`;
408+
409+
exports[`loader should resolve non-less import with alias: warnings 1`] = `Array []`;
410+
423411
exports[`loader should resolve unresolved url with alias: css 1`] = `
424412
".box {
425413
color: #fe33ac;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "../../some.file";

test/helpers/getCodeFromLess.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ const pathMap = {
7171
'style.less'
7272
),
7373
'/styles/style.less': path.resolve(__dirname, '..', 'fixtures', 'basic.less'),
74+
'../../some.file': path.resolve(
75+
__dirname,
76+
'..',
77+
'fixtures',
78+
'folder',
79+
'some.file'
80+
),
7481
};
7582

7683
class ResolvePlugin extends less.FileManager {

test/loader.test.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -597,21 +597,29 @@ describe('loader', () => {
597597
expect(getErrors(stats)).toMatchSnapshot('errors');
598598
});
599599

600-
it('should not resolve when resolve.restrictions no passed', async () => {
601-
const testId = './import-webpack-js-package.less';
602-
const compiler = getCompiler(testId);
603-
const stats = await compile(compiler);
604-
605-
expect(getWarnings(stats)).toMatchSnapshot('warnings');
606-
expect(getErrors(stats)).toMatchSnapshot('errors');
607-
});
608-
609-
it('should prefer a main file with "less" extension over main field with js file', async () => {
610-
const testId = './import-webpack-js-package-2.less';
611-
const compiler = getCompiler(testId);
600+
it('should resolve non-less import with alias', async () => {
601+
const testId = './import-non-less-2.less';
602+
const compiler = getCompiler(
603+
testId,
604+
{},
605+
{
606+
resolve: {
607+
alias: {
608+
'../../some.file': path.resolve(
609+
__dirname,
610+
'fixtures',
611+
'folder',
612+
'some.file'
613+
),
614+
},
615+
},
616+
}
617+
);
612618
const stats = await compile(compiler);
613619
const codeFromBundle = getCodeFromBundle(stats, compiler);
620+
const codeFromLess = await getCodeFromLess(testId);
614621

622+
expect(codeFromBundle.css).toBe(codeFromLess.css);
615623
expect(codeFromBundle.css).toMatchSnapshot('css');
616624
expect(getWarnings(stats)).toMatchSnapshot('warnings');
617625
expect(getErrors(stats)).toMatchSnapshot('errors');

0 commit comments

Comments
 (0)