diff --git a/__tests__/__snapshots__/index.test.ts.snap b/__tests__/__snapshots__/index.test.ts.snap index 15e67f2..1888d06 100644 --- a/__tests__/__snapshots__/index.test.ts.snap +++ b/__tests__/__snapshots__/index.test.ts.snap @@ -6,17 +6,17 @@ exports[`less-loader > builds imported ._less_ files 1`] = ` `; exports[`less-loader > builds imported .css files 1`] = ` -"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} +"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}.index-style{transition:.2s all cubic-bezier(.075,.82,.165,1)}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} " `; exports[`less-loader > builds imported .less files 1`] = ` -"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} +"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}.index-style{transition:.2s all cubic-bezier(.075,.82,.165,1)}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} " `; exports[`less-loader > builds successful 1`] = ` -"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} +"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}.index-style{transition:.2s all cubic-bezier(.075,.82,.165,1)}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} " `; @@ -26,7 +26,7 @@ exports[`less-loader > builds successful custom filter 1`] = ` `; exports[`less-loader > builds successful with less as entrypoint 1`] = ` -"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} +"#style-5-css{position:-webkit-sticky;position:sticky;background:url(data:image/png;base64,iVBORw0KGgoAAAAASURBVA==) no-repeat}#style-4-css{display:none}.style-3-less{color:red}.style-2-less{color:red;background:url(data:image/jpeg;base64,/9j/) no-repeat}.index-style{transition:.2s all cubic-bezier(.075,.82,.165,1)}body{background:#ff0000}body article{width:100px}body article:first-child{width:200px} " `; diff --git a/__tests__/less-utils.test.ts b/__tests__/less-utils.test.ts index 1458fc8..7ab7ffe 100644 --- a/__tests__/less-utils.test.ts +++ b/__tests__/less-utils.test.ts @@ -13,6 +13,7 @@ describe('less-utils', () => { expect.stringContaining('styles/inner/style-3.less'), expect.stringContaining('styles/inner/style-4.css'), expect.stringContaining('styles/inner/style-5.css'), + expect.stringContaining('styles/without-ext.less'), ]), ); }); @@ -27,6 +28,7 @@ describe('less-utils', () => { expect.stringContaining('styles/inner/style-3.less'), expect.stringContaining('styles/inner/style-4.css'), expect.stringContaining('styles/inner/style-5.css'), + expect.stringContaining('styles/without-ext.less'), ]), ); }); diff --git a/example/styles/style.less b/example/styles/style.less index c480158..8c9c927 100644 --- a/example/styles/style.less +++ b/example/styles/style.less @@ -1,5 +1,6 @@ @import './style-2.less'; @import './inner/style-4.css'; +@import './without-ext'; body { background: @primaryColor; // This var is defined in build.ts diff --git a/example/styles/without-ext.less b/example/styles/without-ext.less new file mode 100644 index 0000000..5adcd7e --- /dev/null +++ b/example/styles/without-ext.less @@ -0,0 +1,3 @@ +.index-style { + transition: 0.2s all cubic-bezier(0.075, 0.82, 0.165, 1); +} diff --git a/src/less-utils.ts b/src/less-utils.ts index 8a7638a..3cb0007 100644 --- a/src/less-utils.ts +++ b/src/less-utils.ts @@ -30,6 +30,8 @@ export const getLessImports = (filePath: string, paths: string[] = []): string[] // Assume the file exists at the default import. If it does not, check relative to provided // import paths too, and take the first path that resolves to a real file. let filepath = path.resolve(dir, path.extname(el) ? el : `${el}.less`); + // NOTE: it's actually covered + /* c8 ignore next 9 */ if (!fs.existsSync(filepath)) { for (let i = 0; i < paths.length; i++) { const f = path.resolve(paths[i], path.extname(el) ? el : `${el}.less`);