Skip to content

Commit

Permalink
fix: add mounted node_modules to ignore list (FredKSchott#3227)
Browse files Browse the repository at this point in the history
* fix: add mounted node_modules to ignore list

* refactor: use original method for including mounted node_modules

* fix: lint issue

Co-authored-by: natemoo-re <[email protected]>
  • Loading branch information
ivoreis and natemoo-re authored Apr 29, 2021
1 parent f53e183 commit 0707fd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
HMR_CLIENT_CODE,
HMR_OVERLAY_CODE,
isFsEventsEnabled,
openInBrowser,
openInBrowser
} from '../util';
import {getPort, startDashboard, paintEvent} from './paint';
import {cssModuleJSON} from '../build/import-css';
Expand Down Expand Up @@ -300,7 +300,7 @@ export async function startServer(
...(config.mode === 'test' ? [] : config.testOptions.files),
];

const foundExcludeMatch = picomatch(excludeGlobs);
const foundExcludeMatch = picomatch(excludeGlobs, { ignore: '**/node_modules/**' });

for (const [mountKey, mountEntry] of Object.entries(config.mount)) {
logger.debug(`Mounting directory: '${mountKey}' as URL '${mountEntry.url}'`);
Expand Down
10 changes: 9 additions & 1 deletion snowpack/src/scan-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,21 @@ export async function scanImports(
const excludeGlobs = includeTests
? config.exclude
: [...config.exclude, ...config.testOptions.files];

const mountedNodeModules = Object.keys(config.mount).filter((v) => v.includes('node_modules'));
const foundExcludeMatch = picomatch(excludeGlobs);
const loadedFiles: (SnowpackSourceFile | null)[] = await Promise.all(
includeFiles.map(
async (filePath: string): Promise<SnowpackSourceFile | null> => {
if (excludePrivate.test(filePath) || foundExcludeMatch(filePath)) {
if (excludePrivate.test(filePath)) {
return null;
}
if (foundExcludeMatch(filePath)) {
const isMounted = mountedNodeModules.find((mountKey) => filePath.startsWith(mountKey));
if (!isMounted || (isMounted && foundExcludeMatch(filePath.slice(isMounted.length)))) {
return null;
}
}
return {
baseExt: getExtension(filePath),
root: config.root,
Expand Down

0 comments on commit 0707fd6

Please sign in to comment.