Skip to content

Commit 43cd20c

Browse files
feat: allow to extend conditionNames (#488)
1 parent c1aa4f5 commit 43cd20c

File tree

11 files changed

+131
-5
lines changed

11 files changed

+131
-5
lines changed

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const MODULE_REQUEST_REGEX = /^[^?]*~/;
3434
function createWebpackLessPlugin(loaderContext, implementation) {
3535
const resolve = loaderContext.getResolve({
3636
dependencyType: "less",
37-
conditionNames: ["less", "style"],
37+
conditionNames: ["less", "style", "..."],
3838
mainFields: ["less", "style", "main", "..."],
3939
mainFiles: ["index", "..."],
4040
extensions: [".less", ".css"],

test/__snapshots__/loader.test.js.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,28 @@ exports[`loader should work third-party plugins as fileLoader: errors 1`] = `[]`
583583
584584
exports[`loader should work third-party plugins as fileLoader: warnings 1`] = `[]`;
585585
586+
exports[`loader should work with a package with "sass" and "exports" fields and a custom condition (theme1): css 1`] = `
587+
".load-me {
588+
color: red;
589+
}
590+
"
591+
`;
592+
593+
exports[`loader should work with a package with "sass" and "exports" fields and a custom condition (theme1): errors 1`] = `[]`;
594+
595+
exports[`loader should work with a package with "sass" and "exports" fields and a custom condition (theme1): warnings 1`] = `[]`;
596+
597+
exports[`loader should work with a package with "sass" and "exports" fields and a custom condition (theme2): css 1`] = `
598+
".load-me {
599+
color: blue;
600+
}
601+
"
602+
`;
603+
604+
exports[`loader should work with a package with "sass" and "exports" fields and a custom condition (theme2): errors 1`] = `[]`;
605+
606+
exports[`loader should work with a package with "sass" and "exports" fields and a custom condition (theme2): warnings 1`] = `[]`;
607+
586608
exports[`loader should work: css 1`] = `
587609
".box {
588610
color: #fe33ac;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'package-with-exports-and-custom-condition';

test/fixtures/node_modules/package-with-exports-and-custom-condition/index.cjs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/package-with-exports-and-custom-condition/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/package-with-exports-and-custom-condition/package.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/package-with-exports-and-custom-condition/style-1.less

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/package-with-exports-and-custom-condition/style-2.less

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/package-with-exports/package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/helpers/getCodeFromLess.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,27 @@ class CustomImportPlugin {
150150
}
151151
}
152152

153-
async function getCodeFromLess(testId, options = {}) {
154-
const pathToFile = path.resolve(__dirname, "..", "fixtures", testId);
153+
async function getCodeFromLess(testId, options = {}, context = {}) {
154+
let pathToFile;
155+
156+
if (context.packageExportsCustomConditionTestVariant === 1) {
157+
pathToFile = path.resolve(
158+
__dirname,
159+
"..",
160+
"fixtures",
161+
"node_modules/package-with-exports-and-custom-condition/style-1.less"
162+
);
163+
} else if (context.packageExportsCustomConditionTestVariant === 2) {
164+
pathToFile = path.resolve(
165+
__dirname,
166+
"..",
167+
"fixtures",
168+
"node_modules/package-with-exports-and-custom-condition/style-2.less"
169+
);
170+
} else {
171+
pathToFile = path.resolve(__dirname, "..", "fixtures", testId);
172+
}
173+
155174
const defaultOptions = {
156175
plugins: [],
157176
relativeUrls: true,

0 commit comments

Comments
 (0)