Skip to content

Commit

Permalink
refactor(many): remove TransformImports just form theme packages
Browse files Browse the repository at this point in the history
  • Loading branch information
matyasf committed Oct 21, 2024
1 parent 9208396 commit e4167a8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/canvas-high-contrast-theme/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
coverage: Boolean(process.env.COVERAGE),
esModules: Boolean(process.env.ES_MODULES),
removeConsole: process.env.NODE_ENV === 'production',
transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
transformImports: false
}
]
]
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-theme/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
coverage: Boolean(process.env.COVERAGE),
esModules: Boolean(process.env.ES_MODULES),
removeConsole: process.env.NODE_ENV === 'production',
transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
transformImports: false
}
]
]
Expand Down
29 changes: 29 additions & 0 deletions packages/ui-babel-preset/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ module.exports = function (
]

let plugins = []
if (opts.transformImports) {
plugins.push([
require('@instructure/babel-plugin-transform-imports'),
{
'(@instructure/ui-[^(/|\\s)]+)$': {
// eslint-disable-line no-useless-escape
transform: (importName, matches) => {
const ignore = [
'@instructure/ui-test-queries',
'@instructure/ui-test-sandbox',
'@instructure/ui-test-utils'
]

if (!matches || !matches[1] || ignore.includes(matches[1])) return
return `${matches[1]}/lib/${importName}`
}
},
// Convert any es imports to lib imports
'(@instructure/ui-[^(/|\\s)]+/es/[^\\s]+)$': {
// eslint-disable-line no-useless-escape
transform: (importName, matches) => {
if (!matches || !matches[1]) return
return matches[1].replace(new RegExp('/es/'), '/lib/')
}
},
...(opts.importTransforms || {})
}
])
}
// Work around https://github.com/babel/babel/issues/10261, which causes
// Babel to not use the runtime helpers for things like _objectSpread.
// Remove this once that babel issue is fixed
Expand Down
1 change: 1 addition & 0 deletions packages/ui-babel-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.2",
"@babel/runtime": "^7.23.2",
"@instructure/babel-plugin-transform-imports": "8.56.4",
"@instructure/browserslist-config-instui": "8.56.4",
"babel-loader": "^9.1.3",
"babel-plugin-dynamic-import-node": "^2.3.3",
Expand Down
6 changes: 5 additions & 1 deletion packages/ui-babel-preset/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
"outDir": "./types"
},
"include": ["lib"],
"references": []
"references": [
{
"path": "../babel-plugin-transform-imports/tsconfig.build.json"
}
]
}
2 changes: 1 addition & 1 deletion packages/ui-themes/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
coverage: Boolean(process.env.COVERAGE),
esModules: Boolean(process.env.ES_MODULES),
removeConsole: process.env.NODE_ENV === 'production',
transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
transformImports: false
}
]
]
Expand Down

0 comments on commit e4167a8

Please sign in to comment.