You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ra...@apache.org on 2020/08/05 05:23:35 UTC
[incubator-annotator] 02/04: Add extensions to import and require
statements in build
This is an automated email from the ASF dual-hosted git repository.
randall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit acf90a5a77977128367e3330261b6129642b1e83
Author: Randall Leeds <ra...@apache.org>
AuthorDate: Tue Aug 4 22:09:43 2020 -0700
Add extensions to import and require statements in build
---
babel.config.js | 28 ++++++++++++++++++++++++----
package.json | 1 +
yarn.lock | 12 ++++++++++++
3 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/babel.config.js b/babel.config.js
index 44324e7..265fdcc 100644
--- a/babel.config.js
+++ b/babel.config.js
@@ -43,11 +43,29 @@ module.exports = (api) => {
onlyRemoveTypeImports: true,
};
+ const addImportExtensionOptions = {
+ extension: DEV || TEST ? 'ts' : 'js',
+ };
+
// Options for the module-resolver plugin.
// Used for resolving source files during development.
- let resolverOptions = {
+ const resolverOptions = {
alias: {
- '^@annotator/(.+)$': '@annotator/\\1/src/index.ts',
+ ...(DEV || TEST
+ ? {
+ '^@annotator/(.+)$': '@annotator/\\1/src/index.ts',
+ }
+ : null),
+ // TODO: Remove after babel/babel#8462 ships.
+ '^@babel/runtime-corejs3/core-js/(.+)$':
+ '@babel/runtime-corejs3/core-js/\\1.js',
+ '^@babel/runtime-corejs3/core-js-stable/(.+)$':
+ '@babel/runtime-corejs3/core-js-stable/\\1.js',
+ '^@babel/runtime-corejs3/helpers/(.+)$':
+ '@babel/runtime-corejs3/helpers/\\1.js',
+ '^@babel/runtime-corejs3/regenerator$':
+ '@babel/runtime-corejs3/regenerator/index.js',
+ extensions: ['.js', '.ts'],
},
};
@@ -56,14 +74,16 @@ module.exports = (api) => {
// Use corejs version 3.
corejs: { version: 3 },
// Use helpers formatted for the target environment.
- useESModules: !CJS && !TEST,
+ // TODO: Re-enable after babel/babel#8462 ships.
+ // useESModules: !CJS && !TEST,
};
return {
plugins: [
['@babel/transform-runtime', runtimeOptions],
...(TEST ? ['istanbul'] : []),
- ...(DEV ? [['module-resolver', resolverOptions]] : []),
+ ['add-import-extension', addImportExtensionOptions],
+ ['module-resolver', resolverOptions],
'preserve-comment-header',
],
presets: [
diff --git a/package.json b/package.json
index c5fb3e2..913aa56 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
"@typescript-eslint/parser": "^3.7.0",
"ajv": "^6.11.0",
"babel-loader": "^8.0.5",
+ "babel-plugin-add-import-extension": "^1.4.1",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-preserve-comment-header": "^1.0.1",
diff --git a/yarn.lock b/yarn.lock
index 07bcebc..259c26b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -192,6 +192,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.1.tgz#ec5a5cf0eec925b66c60580328b122c01230a127"
integrity sha512-fvoGeXt0bJc7VMWZGCAEBEMo/HAjW2mP8apF5eXK0wSqwLAVHAISCWRoLMBMUs2kqeaG77jltVqu4Hn8Egl3nA==
+"@babel/helper-plugin-utils@^7.10.4":
+ version "7.10.4"
+ resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.4.tgz#2f75a831269d4f677de49986dff59927533cf375"
+ integrity sha512-O4KCvQA6lLiMU9l2eawBPMf1xPP8xPfB3iEQw150hOVTqj/rfXz0ThTb4HEzqQfs2Bmo5Ay8BzxfzVtBrr9dVg==
+
"@babel/helper-regex@^7.10.1":
version "7.10.1"
resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.10.1.tgz#021cf1a7ba99822f993222a001cc3fec83255b96"
@@ -2424,6 +2429,13 @@ babel-loader@^8.0.5:
mkdirp "^0.5.1"
pify "^4.0.1"
+babel-plugin-add-import-extension@^1.4.1:
+ version "1.4.1"
+ resolved "https://registry.yarnpkg.com/babel-plugin-add-import-extension/-/babel-plugin-add-import-extension-1.4.1.tgz#d31b919ecbbd052aa3df210eca0b9f0153df770b"
+ integrity sha512-owxjRte+y2QB0YPCv3hWFNLF3Y1S7eEEZCCGo48TzRPM6zEzYsvxtOyx1h95Ghw1gEcl1UnOFIs5CY3Kd4OLYg==
+ dependencies:
+ "@babel/helper-plugin-utils" "^7.10.4"
+
babel-plugin-dynamic-import-node@^2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3"