Use babel resolver instead of webpack
authorRandall Leeds <randall@apache.org>
Wed, 10 Jan 2018 08:34:17 +0000 (00:34 -0800)
committerRandall Leeds <randall@apache.org>
Wed, 10 Jan 2018 18:18:52 +0000 (10:18 -0800)
Resolve package sources during development so that tests and webpack can
work without running build first.

.babelrc.js
.eslintrc.yml
package.json
packages/selector/test/index.mjs
webpack.config.js
yarn.lock

index cf7b9ce..c8c73f6 100644 (file)
@@ -54,6 +54,14 @@ const envOptions = {
   useBuiltIns: 'entry',
 };
 
+// Options for the module-resolver plugin.
+// Used for resolving source files during development and testing.
+let resolverOptions = {
+  alias: {
+    '^(@annotator/.+?)(/|$)': '\\1/src',
+  },
+};
+
 // Options for the @babel/transform-runtime plugin.
 const runtimeOptions = {
   // Do not polyfill; leave that to applications.
@@ -68,6 +76,7 @@ const config = {
   plugins: [
     ['@babel/transform-runtime', runtimeOptions],
     ...(CJS ? ['@babel/transform-modules-commonjs']: []),
+    ...(DEV || TEST ? [['module-resolver', resolverOptions]]: []),
     ...(TEST ? [hacks, 'istanbul'] : []),
   ],
   presets: [
index caf7ce9..aa1813f 100644 (file)
@@ -41,7 +41,7 @@ rules:
 
 settings:
   import/extensions: ['.mjs', '.js']
-  import/resolver: node
+  import/resolver: babel-module
 
 overrides:
   - files:
index 3a165c7..518445d 100644 (file)
     "babel-eslint": "^8.2.1",
     "babel-loader": "^8.0.0-beta.0",
     "babel-plugin-istanbul": "^4.1.5",
+    "babel-plugin-module-resolver": "^3.0.0",
     "chai": "^4.1.2",
     "cross-env": "^5.1.3",
     "dom-highlight-range": "^1.0.1",
     "eslint": "^4.15.0",
     "eslint-config-prettier": "^2.9.0",
-    "eslint-import-resolver-node": "^0.3.2",
+    "eslint-import-resolver-babel-module": "^5.0.0-beta.0",
     "eslint-plugin-import": "^2.8.0",
     "eslint-plugin-node": "^5.2.1",
     "eslint-plugin-prettier": "^2.4.0",
index fb6d0dd..a5a4245 100644 (file)
@@ -1,4 +1,4 @@
-import * as selector from '../';
+import * as selector from '../src';
 
 describe('selector', () => {
   it('can be imported', () => {
index 4a6cb9d..f26e112 100644 (file)
@@ -46,11 +46,6 @@ module.exports = {
       },
     ],
   },
-  resolve: {
-    alias: {
-      '@annotator': path.resolve(__dirname, 'packages/'),
-    },
-  },
   plugins: [
     new webpack.HotModuleReplacementPlugin(),
     new webpack.NamedModulesPlugin(),
index 15a98da..390dd5b 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -1072,6 +1072,16 @@ babel-plugin-istanbul@^4.1.5:
     istanbul-lib-instrument "^1.7.5"
     test-exclude "^4.1.1"
 
+babel-plugin-module-resolver@^3.0.0:
+  version "3.0.0"
+  resolved "https://registry.yarnpkg.com/babel-plugin-module-resolver/-/babel-plugin-module-resolver-3.0.0.tgz#a2fe5b97f7b809a8bbac18beada0a94d45987c63"
+  dependencies:
+    find-babel-config "^1.1.0"
+    glob "^7.1.2"
+    pkg-up "^2.0.0"
+    reselect "^3.0.1"
+    resolve "^1.4.0"
+
 babel-plugin-syntax-async-functions@^6.8.0:
   version "6.13.0"
   resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
@@ -2544,7 +2554,7 @@ debug-log@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/debug-log/-/debug-log-1.0.1.tgz#2307632d4c04382b8df8a32f70b895046d52745f"
 
-debug@2, debug@2.6.9, debug@^2.0.0, debug@^2.1.0, debug@^2.2.0, debug@^2.6.8, debug@^2.6.9:
+debug@2, debug@2.6.9, debug@^2.0.0, debug@^2.1.0, debug@^2.2.0, debug@^2.6.8:
   version "2.6.9"
   resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
   dependencies:
@@ -2899,6 +2909,13 @@ eslint-config-prettier@^2.9.0:
   dependencies:
     get-stdin "^5.0.1"
 
+eslint-import-resolver-babel-module@^5.0.0-beta.0:
+  version "5.0.0-beta.0"
+  resolved "https://registry.yarnpkg.com/eslint-import-resolver-babel-module/-/eslint-import-resolver-babel-module-5.0.0-beta.0.tgz#ad371645cd9d22f8cbd82a286bcf1e50733ba00e"
+  dependencies:
+    pkg-up "^2.0.0"
+    resolve "^1.4.0"
+
 eslint-import-resolver-node@^0.3.1:
   version "0.3.1"
   resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.1.tgz#4422574cde66a9a7b099938ee4d508a199e0e3cc"
@@ -2906,13 +2923,6 @@ eslint-import-resolver-node@^0.3.1:
     debug "^2.6.8"
     resolve "^1.2.0"
 
-eslint-import-resolver-node@^0.3.2:
-  version "0.3.2"
-  resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz#58f15fb839b8d0576ca980413476aab2472db66a"
-  dependencies:
-    debug "^2.6.9"
-    resolve "^1.5.0"
-
 eslint-module-utils@^2.1.1:
   version "2.1.1"
   resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.1.1.tgz#abaec824177613b8a95b299639e1b6facf473449"
@@ -3252,6 +3262,13 @@ finalhandler@1.1.0:
     statuses "~1.3.1"
     unpipe "~1.0.0"
 
+find-babel-config@^1.1.0:
+  version "1.1.0"
+  resolved "https://registry.yarnpkg.com/find-babel-config/-/find-babel-config-1.1.0.tgz#acc01043a6749fec34429be6b64f542ebb5d6355"
+  dependencies:
+    json5 "^0.5.1"
+    path-exists "^3.0.0"
+
 find-cache-dir@^0.1.1:
   version "0.1.1"
   resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-0.1.1.tgz#c8defae57c8a52a8a784f9e31c57c742e993a0b9"
@@ -5691,6 +5708,12 @@ pkg-dir@^2.0.0:
   dependencies:
     find-up "^2.1.0"
 
+pkg-up@^2.0.0:
+  version "2.0.0"
+  resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-2.0.0.tgz#c819ac728059a461cab1c3889a2be3c49a004d7f"
+  dependencies:
+    find-up "^2.1.0"
+
 pluralize@^7.0.0:
   version "7.0.0"
   resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
@@ -6446,7 +6469,7 @@ resolve-from@^3.0.0:
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
 
-resolve@^1.1.6, resolve@^1.5.0:
+resolve@^1.1.6, resolve@^1.4.0:
   version "1.5.0"
   resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36"
   dependencies: