Skip to content

Commit

Permalink
#570: Extract and deduplicate webpack resolution config (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jul 12, 2021
1 parent f55af8e commit e355c90
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
19 changes: 14 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
"settings": {
"import/resolver": {
"webpack": {
"config": "./browsers/webpack.config.js"
"config": "./browsers/resolve.config.js"
}
},
"import/ignore": [
"react-select" // For some reason it points to a flow JS file
],
"react": {
"version": "detect"
}
Expand All @@ -26,13 +29,10 @@

"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:security/recommended",
"plugin:unicorn/recommended"

// TODO: Restore these after https://github.com/benmosher/eslint-plugin-import/issues/1931
// "plugin:import/errors",
// "plugin:import/warnings",
],
"rules": {
"@typescript-eslint/no-unused-vars": [
Expand All @@ -54,6 +54,14 @@
}
],

"import/no-unresolved": [
"error",
{
"ignore": [
"json-schema" // @types-only package
]
}
],
"unicorn/prevent-abbreviations": [
"error",
{
Expand Down Expand Up @@ -88,6 +96,7 @@

// Disable recommended rules
"@typescript-eslint/no-empty-function": "off",
"import/named": "off", // TypeScript does this natively
"react/prop-types": "off",
"unicorn/no-null": "off", // Maybe later
"unicorn/filename-case": "off", // Contrasts with React
Expand Down
24 changes: 24 additions & 0 deletions browsers/resolve.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Resolve-only webpack configuration for ESlint

const path = require("path");
const rootDir = path.resolve(__dirname, "../");

module.exports = {
resolve: {
alias: {
"@": path.resolve(rootDir, "src"),
"@img": path.resolve(rootDir, "img"),
"@contrib": path.resolve(rootDir, "contrib"),
"@schemas": path.resolve(rootDir, "schemas"),
vendors: path.resolve(rootDir, "src/vendors"),
"@microsoft/applicationinsights-web": path.resolve(
rootDir,
"src/contrib/uipath/quietLogger"
),

// An existence check triggers webpack’s warnings https://github.com/handlebars-lang/handlebars.js/issues/953
handlebars: "handlebars/dist/handlebars.js",
},
extensions: [".ts", ".tsx", ".jsx", ".js"],
},
};
17 changes: 2 additions & 15 deletions browsers/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CopyPlugin = require("copy-webpack-plugin");
const { uniq, isEmpty } = require("lodash");
const Policy = require("csp-parse");

const { resolve } = require("./resolve.config.js");
const rootDir = path.resolve(__dirname, "../");

// Include defaults required for webpack here. Add defaults for the extension bundle to EnvironmentPlugin
Expand Down Expand Up @@ -211,32 +212,18 @@ module.exports = (env, options) => ({
action: path.resolve(rootDir, "src/action"),
},
resolve: {
...resolve,
// Need to set these fields manually as their default values rely on `web` target.
// See https://v4.webpack.js.org/configuration/resolve/#resolvemainfields
mainFields: ["browser", "module", "main"],
aliasFields: ["browser"],
alias: {
"@": path.resolve(rootDir, "src"),
"@img": path.resolve(rootDir, "img"),
"@contrib": path.resolve(rootDir, "contrib"),
"@schemas": path.resolve(rootDir, "schemas"),
vendors: path.resolve(rootDir, "src/vendors"),
"@microsoft/applicationinsights-web": path.resolve(
rootDir,
"src/contrib/uipath/quietLogger"
),

// An existence check triggers webpack’s warnings https://github.com/handlebars-lang/handlebars.js/issues/953
handlebars: "handlebars/dist/handlebars.js",
},
fallback: {
fs: false,
crypto: false,
console: false,
vm: false,
path: false,
},
extensions: [".ts", ".tsx", ".jsx", ".js"],
},

// https://github.com/webpack/webpack/issues/3017#issuecomment-285954512
Expand Down
15 changes: 5 additions & 10 deletions scripts/webpack.scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const { merge } = require("lodash");
const path = require("path");
const rootDir = path.resolve(__dirname, "../");
const webpack = require("webpack");

const { resolve } = require("../browsers/resolve.config.js");

module.exports = {
mode: "development",
target: "node",
Expand All @@ -37,22 +40,14 @@ module.exports = {
// https://github.com/yan-foto/electron-reload/issues/71#issuecomment-588988382
fsevents: "require('fsevents')",
},
resolve: {
resolve: merge(resolve, {
alias: {
"@": path.resolve(rootDir, "src"),
"@img": path.resolve(rootDir, "img"),
"@contrib": path.resolve(rootDir, "contrib"),
"@schemas": path.resolve(rootDir, "schemas"),
vendors: path.resolve(rootDir, "src/vendors"),
"@uipath/robot": path.resolve(rootDir, "src/__mocks__/robotMock"),
// An existence check triggers webpack’s warnings https://github.com/handlebars-lang/handlebars.js/issues/953
handlebars: "handlebars/dist/handlebars.js",
},
extensions: [".ts", ".tsx", ".jsx", ".js"],
fallback: {
chokidar: false,
},
},
}),
plugins: [
new webpack.ProvidePlugin({
window: "global/window.js",
Expand Down
16 changes: 8 additions & 8 deletions src/blocks/readers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export * from "./meta";
export * from "./PageMetadataReader";
export * from "./PageSemanticReader";
export * from "./BlankReader";
export * from "./ImageReader";
export * from "./ImageEXIFReader";
export * from "./ElementReader";
import "./meta";
import "./PageMetadataReader";
import "./PageSemanticReader";
import "./BlankReader";
import "./ImageReader";
import "./ImageEXIFReader";
import "./ElementReader";

// generic readers
export * from "./frameworkReader";
import "./frameworkReader";
export * from "./jquery";
export * from "./window";

0 comments on commit e355c90

Please sign in to comment.