Skip to content

Commit b9184cc

Browse files
amirehmatyasf
authored andcommitted
fix(esm): improve esm support
refs FOO-1331 - all imports must specify the extension (and can't import directories), which is handled by the newly added babel plugin - console ported to ESM so that it can be imported by ESM dependents == test plan == using node 14, you can now import some of the packages (ones that don't rely on babel / react) nvm use v14 node --input-type=module -e 'import "@instructure/debounce"' Change-Id: I1b677307c38fe12c2e25a2a3f72775e537eb0306
1 parent 6007684 commit b9184cc

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

packages/console/src/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
const React = require('react')
24+
import React from 'react'
2525

2626
let loggedInitialDeprecationWarning = false
2727

@@ -65,12 +65,12 @@ function logDeprecated(condition, message, ...args) {
6565
}
6666
}
6767

68-
exports.error = (...args) => logMessage('error', true, ...args)
69-
exports.warn = (...args) => logMessage('warn', true, ...args)
70-
exports.warnDeprecated = (...args) => logDeprecated(...args)
71-
exports.info = (...args) => console.info(...args)
72-
exports.assert = (...args) => console.assert(...args)
73-
exports.debug = (...args) => console.debug(...args)
74-
exports.log = (...args) => console.log(...args)
68+
export const error = (...args) => logMessage('error', true, ...args)
69+
export const warn = (...args) => logMessage('warn', true, ...args)
70+
export const warnDeprecated = (...args) => logDeprecated(...args)
71+
export const info = (...args) => console.info(...args)
72+
export const assert = (...args) => console.assert(...args)
73+
export const debug = (...args) => console.debug(...args)
74+
export const log = (...args) => console.log(...args)
7575

7676
/* eslint-enable no-console */

packages/ui-babel-preset/lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ module.exports = function (
112112
}
113113
],
114114
require('@babel/plugin-syntax-dynamic-import').default,
115-
require('babel-plugin-transform-undefined-to-void')
115+
require('babel-plugin-transform-undefined-to-void'),
116+
require('babel-plugin-add-import-extension'),
116117
])
117118

118119
if (process.env.NODE_ENV === 'production') {

packages/ui-babel-preset/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@instructure/config-loader": "^7.3.2",
3838
"@instructure/ui-postcss-config": "^7.3.2",
3939
"babel-loader": "^8.1.0",
40+
"babel-plugin-add-import-extension": "^1.4.3",
4041
"babel-plugin-dynamic-import-node": "^2.3.0",
4142
"babel-plugin-istanbul": "^6.0.0",
4243
"babel-plugin-macros": "^2.8.0",

packages/ui-i18n/src/Decimal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
import { Locale } from './Locale'
26-
import BaseDecimal from 'decimal.js/decimal'
26+
import BaseDecimal from 'decimal.js/decimal.mjs'
2727

2828
/**
2929
* ---

packages/ui-stylesheet/src/StyleSheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import { StyleSheet as GlamorStyleSheet } from 'glamor/lib/sheet'
25+
import { StyleSheet as GlamorStyleSheet } from 'glamor/lib/sheet.js'
2626

2727
const ENV = process.env.NODE_ENV || 'production'
2828
const DEBUG = process.env.DEBUG || ENV === 'development'

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@
216216
resolved "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670"
217217
integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ==
218218

219+
"@babel/helper-plugin-utils@^7.10.4":
220+
version "7.10.4"
221+
resolved "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.4.tgz#2f75a831269d4f677de49986dff59927533cf375"
222+
integrity sha512-O4KCvQA6lLiMU9l2eawBPMf1xPP8xPfB3iEQw150hOVTqj/rfXz0ThTb4HEzqQfs2Bmo5Ay8BzxfzVtBrr9dVg==
223+
219224
"@babel/helper-regex@^7.8.3":
220225
version "7.8.3"
221226
resolved "https://registry.npmjs.org/@babel/helper-regex/-/helper-regex-7.8.3.tgz#139772607d51b93f23effe72105b319d2a4c6965"
@@ -4409,6 +4414,13 @@ babel-messages@^6.23.0:
44094414
dependencies:
44104415
babel-runtime "^6.22.0"
44114416

4417+
babel-plugin-add-import-extension@^1.4.3:
4418+
version "1.4.3"
4419+
resolved "https://registry.npmjs.org/babel-plugin-add-import-extension/-/babel-plugin-add-import-extension-1.4.3.tgz#9a153095f3c8bb820abbf168bbc71aba837e4e4a"
4420+
integrity sha512-NiKs80ucIlktWtQ6VGovyVprpgaDxqlo3fT2e2vIyF6k3+02YMmQt+QrBDOq/YImkK/pIXb/SKaO+FxKsfvNlA==
4421+
dependencies:
4422+
"@babel/helper-plugin-utils" "^7.10.4"
4423+
44124424
babel-plugin-add-react-displayname@^0.0.5:
44134425
version "0.0.5"
44144426
resolved "https://registry.npmjs.org/babel-plugin-add-react-displayname/-/babel-plugin-add-react-displayname-0.0.5.tgz#339d4cddb7b65fd62d1df9db9fe04de134122bd5"

0 commit comments

Comments
 (0)