Skip to content

Commit

Permalink
finalize picomatch support (#2912)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Mar 19, 2021
1 parent d33076a commit a800bf3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions esinstall/src/entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import validatePackageName from 'validate-npm-package-name';
import {ExportField, ExportMapEntry, PackageManifestWithExports, PackageManifest} from './types';
import {parsePackageImportSpecifier, resolveDependencyManifest} from './util';
import resolve from 'resolve';
import pm from 'picomatch';
import picomatch from 'picomatch';

export const MAIN_FIELDS = [
'browser:module',
Expand Down Expand Up @@ -277,7 +277,7 @@ function* forEachWildcardEntry(
cwd: string,
): Generator<[string, string], any, undefined> {
// Creates a regex from a pattern like ./src/extras/*
let expr = pm.makeRe(value, picoMatchGlobalOptions);
let expr = picomatch.makeRe(value, picoMatchGlobalOptions);

// The directory, ie ./src/extras
let valueDirectoryName = path.dirname(value);
Expand Down
2 changes: 1 addition & 1 deletion snowpack/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function build(commandOptions: CommandOptions): Promise<SnowpackBui
const excludeGlobs = [...config.exclude, ...config.testOptions.files];
const foundExcludeMatch = picomatch(excludeGlobs);
for (const f of files) {
if (foundExcludeMatch(f) || excludePrivate.test(f)) {
if (excludePrivate.test(f) || foundExcludeMatch(f)) {
continue;
}
const fileUrls = getUrlsForFile(f, config)!;
Expand Down
11 changes: 5 additions & 6 deletions snowpack/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,26 +290,25 @@ export async function startServer(
const symlinkDirectories = new Set();
const inMemoryBuildCache = new Map<string, FileBuilder>();
let fileToUrlMapping = new OneToManyMap();

const excludeGlobs = [
...config.exclude,
...(process.env.NODE_ENV === 'test' ? [] : config.testOptions.files),
];
const excludePrivate = new RegExp(`\\${path.sep}\\.`);
const foundExcludeMatch = picomatch(excludeGlobs);

for (const [mountKey, mountEntry] of Object.entries(config.mount)) {
logger.debug(`Mounting directory: '${mountKey}' as URL '${mountEntry.url}'`);
const files = (await new fdir()
.withFullPaths()
.filter((path) => !foundExcludeMatch(path))
// Note: exclude() only matches directories, and not files. However, the cost
// of false positives here is minor, so do this as a quick check to possibly
// skip scanning into entire folder trees.
.exclude((_, dirPath) => excludePrivate.test(dirPath) || foundExcludeMatch(dirPath))
.crawl(mountKey)
.withPromise()) as string[];

const excludePrivate = new RegExp(`\\${path.sep}\\.`);
for (const f of files) {
if (excludePrivate.test(f)) {
continue;
}
fileToUrlMapping.add(f, getUrlsForFile(f, config)!);
}
}
Expand Down
4 changes: 2 additions & 2 deletions snowpack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import type {Awaited} from './util';

const CONFIG_NAME = 'snowpack';
const ALWAYS_EXCLUDE = ['**/node_modules/**/*', '**/_*.{sass,scss}', '**/*.d.ts'];
const ALWAYS_EXCLUDE = ['**/node_modules/**', '**/_*.{sass,scss}', '**.d.ts'];

// default settings
const DEFAULT_ROOT = process.cwd();
Expand Down Expand Up @@ -408,7 +408,7 @@ function normalizeConfig(_config: SnowpackUserConfig): SnowpackConfig {
config.packageOptions.rollup.plugins = config.packageOptions.rollup.plugins || [];
}
config.exclude = Array.from(
new Set([...ALWAYS_EXCLUDE, `${config.buildOptions.out}/**/*`, ...config.exclude]),
new Set([...ALWAYS_EXCLUDE, `${config.buildOptions.out}/**`, ...config.exclude]),
);
// normalize config URL/path values
config.buildOptions.out = removeTrailingSlash(config.buildOptions.out);
Expand Down
2 changes: 1 addition & 1 deletion snowpack/src/scan-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export async function scanImports(
const loadedFiles: (SnowpackSourceFile | null)[] = await Promise.all(
includeFiles.map(
async (filePath: string): Promise<SnowpackSourceFile | null> => {
if (foundExcludeMatch(filePath) || excludePrivate.test(filePath)) {
if (excludePrivate.test(filePath) || foundExcludeMatch(filePath)) {
return null;
}
return {
Expand Down

1 comment on commit a800bf3

@vercel
Copy link

@vercel vercel bot commented on a800bf3 Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.