Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ module.exports = {
'ember-cli-babel': {
// prevents the helpers from being double transpiled, and including themselves
disablePresetEnv: true
},
babel: {
// the helpers import each other with explicit `.js` extensions, which
// the loader cannot resolve against the extensionless module names
// defined for this tree
plugins: [require.resolve('./lib/strip-relative-import-extensions')]
}
});

Expand Down
33 changes: 33 additions & 0 deletions lib/strip-relative-import-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

/*
* `@babel/runtime` >= 7.13 publishes its ESM helpers with explicit `.js`
* extensions on their relative imports (e.g. `import x from "./x.js"`).
* The AMD modules we define for these helpers use extensionless names, so
* the extension must be stripped for the imports to resolve at runtime.
* See: https://github.com/emberjs/ember-cli-babel/issues/384
*/
module.exports = function stripRelativeImportExtensions() {
const rewrite = (path) => {
const source = path.node.source;
if (source && source.value.startsWith('.') && source.value.endsWith('.js')) {
source.value = source.value.slice(0, -3);
}
};

return {
name: 'strip-relative-import-extensions',
visitor: {
// the rewrite must happen in `Program.enter` because
// babel-plugin-module-resolver resolves import paths in its own
// `Program` visitor, before individual declaration visitors run
Program: {
enter(programPath) {
programPath.traverse({
'ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration': rewrite,
});
},
},
},
};
};
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
"test:node:debug": "mocha debug node-tests"
},
"dependencies": {
"@babel/helper-compilation-targets": "^7.20.7",
"@babel/plugin-proposal-decorators": "^7.20.13",
"@babel/plugin-transform-class-properties": "^7.16.5",
"@babel/plugin-transform-class-static-block": "^7.22.11",
"@babel/plugin-transform-modules-amd": "^7.20.11",
"@babel/plugin-transform-private-methods": "^7.16.5",
"@babel/plugin-transform-private-property-in-object": "^7.20.5",
"@babel/plugin-transform-runtime": "^7.13.9",
"@babel/plugin-transform-typescript": "^7.20.13",
"@babel/preset-env": "^7.20.2",
"@babel/runtime": "7.12.18",
"@babel/helper-compilation-targets": "^7.29.7",
"@babel/plugin-proposal-decorators": "^7.29.7",
"@babel/plugin-transform-class-properties": "^7.29.7",
"@babel/plugin-transform-class-static-block": "^7.29.7",
"@babel/plugin-transform-modules-amd": "^7.29.7",
"@babel/plugin-transform-private-methods": "^7.29.7",
"@babel/plugin-transform-private-property-in-object": "^7.29.7",
"@babel/plugin-transform-runtime": "^7.29.7",
"@babel/plugin-transform-typescript": "^7.29.7",
"@babel/preset-env": "^7.29.7",
"@babel/runtime": "^7.29.7",
"amd-name-resolver": "^1.3.1",
"babel-plugin-debug-macros": "^0.3.4",
"babel-plugin-ember-data-packages-polyfill": "^0.1.2",
Expand All @@ -69,7 +69,7 @@
"semver": "^7.3.8"
},
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/core": "^7.29.7",
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^3.2.0",
Expand Down
Loading
Loading