Skip to content

Commit

Permalink
Throw error if no files were found
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Oct 16, 2023
1 parent 42b17cc commit 321a9a3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/dynamic-import-vars/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createFilter } from '@rollup/pluginutils';

import { dynamicImportToGlob, VariableDynamicImportError } from './dynamic-import-to-glob';

function dynamicImportVariables({ include, exclude, warnOnError } = {}) {
function dynamicImportVariables({ include, exclude, warnOnError, errorWhenNoFilesFound } = {}) {
const filter = createFilter(include, exclude);

return {
Expand Down Expand Up @@ -55,6 +55,12 @@ function dynamicImportVariables({ include, exclude, warnOnError } = {}) {
r.startsWith('./') || r.startsWith('../') ? r : `./${r}`
);

if (errorWhenNoFilesFound && paths.length === 0) {
this.error(
new Error('No files found when trying to dynamically load concatted string')
);
}

// create magic string if it wasn't created already
ms = ms || new MagicString(code);
// unpack variable dynamic import into a function with import statements per file, rollup
Expand Down

0 comments on commit 321a9a3

Please sign in to comment.