Skip to content

Commit

Permalink
fix eslint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Jul 21, 2020
1 parent 8fa8913 commit b9959a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
4 changes: 3 additions & 1 deletion packages/gatsby/src/utils/gatsby-webpack-virtual-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface IGatsbyWebpackVirtualModulesContext {
const fileContentLookup: Record<string, string> = {}
const instances: IGatsbyWebpackVirtualModulesContext[] = []

export const VIRTUAL_MODULES_BASE_PATH = `_this_is_virtual_fs_path_`

export class GatsbyWebpackVirtualModules {
apply(compiler): void {
const virtualModules = new VirtualModulesPlugin(fileContentLookup)
Expand All @@ -33,7 +35,7 @@ export class GatsbyWebpackVirtualModules {
}

export function getAbsolutePathForVirtualModule(filePath: string): string {
return path.join(process.cwd(), `_this_is_virtual_fs_path_`, filePath)
return path.join(process.cwd(), VIRTUAL_MODULES_BASE_PATH, filePath)
}

export function writeModule(filePath: string, fileContents: string): void {
Expand Down
35 changes: 20 additions & 15 deletions packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { getBrowsersList } from "./browserslist"

import { GatsbyWebpackStatsExtractor } from "./gatsby-webpack-stats-extractor"
import { GatsbyWebpackEslintGraphqlSchemaReload } from "./gatsby-webpack-eslint-graphql-schema-reload-plugin"
import { GatsbyWebpackVirtualModules } from "./gatsby-webpack-virtual-modules"
import {
GatsbyWebpackVirtualModules,
VIRTUAL_MODULES_BASE_PATH,
} from "./gatsby-webpack-virtual-modules"

import { builtinPlugins } from "./webpack-plugins"
import { IProgram, Stage } from "../commands/types"
Expand Down Expand Up @@ -431,21 +434,21 @@ export const createWebpackUtils = (
return {
test: /\.(js|mjs)$/,
exclude: (modulePath: string): boolean => {
if (vendorRegex.test(modulePath)) {
// If dep uses Gatsby, exclude
if (
modulesThatUseGatsby.some(module =>
modulePath.includes(module.path)
)
) {
return true
}

return doNotPolyfillRegex.test(modulePath)
// If dep is user land code, exclude
if (!vendorRegex.test(modulePath)) {
return true
}

// If dep is user land code, exclude
return true
// If dep uses Gatsby, exclude
if (
modulesThatUseGatsby.some(module =>
modulePath.includes(module.path)
)
) {
return true
}

return doNotPolyfillRegex.test(modulePath)
},
type: `javascript/auto`,
use: [loaders.dependencies(jsOptions)],
Expand All @@ -458,7 +461,9 @@ export const createWebpackUtils = (
return {
enforce: `pre`,
test: /\.jsx?$/,
exclude: vendorRegex,
exclude: (modulePath: string): boolean =>
modulePath.includes(VIRTUAL_MODULES_BASE_PATH) ||
vendorRegex.test(modulePath),
use: [loaders.eslint(schema)],
}
}
Expand Down

0 comments on commit b9959a9

Please sign in to comment.