Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v13.0.3

- Fix CJS environments (e.g. Jest + esbuild) failing to `require()` the `.mjs` native loader by providing separate CJS and ESM versions of `load-module-native` ([#418](https://github.com/jeffijoe/awilix/issues/418), [#419](https://github.com/jeffijoe/awilix/pull/419))

# v13.0.2

- Fix ESM interop by renaming `load-module-native.js` to `load-module-native.mjs` so Node.js treats it as ESM regardless of the package `type` field ([#416](https://github.com/jeffijoe/awilix/issues/416), [#417](https://github.com/jeffijoe/awilix/pull/417))
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "awilix",
"version": "13.0.2",
"version": "13.0.3-alpha.0",
"description": "Extremely powerful dependency injection container.",
"main": "lib/awilix.js",
"module": "lib/awilix.module.mjs",
Expand Down Expand Up @@ -48,7 +48,7 @@
"cover": "npm run test -- --coverage",
"publish:pre": "npm run lint && npm run build && npm run cover",
"publish:post": "npm publish && git push --follow-tags",
"release:prerelease": "npm run publish:pre && npm version prerelease --preid alpha && npm run publish:post",
"release:prerelease": "npm run publish:pre && npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
"release:patch": "npm run publish:pre && npm version patch && npm run publish:post",
"release:minor": "npm run publish:pre && npm version minor && npm run publish:post",
"release:major": "npm run publish:pre && npm version major && npm run publish:post"
Expand Down Expand Up @@ -148,6 +148,7 @@
"__tests__",
"lib",
"src/load-module-native.mjs",
"src/load-module-native.js",
"src/awilix.ts"
],
"moduleFileExtensions": [
Expand Down
26 changes: 17 additions & 9 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ export default [
// Build 1: ES modules for Node.
{
input: 'src/awilix.ts',
external: [
'fast-glob',
'path',
'url',
'util',
'./load-module-native.mjs',
],
external: ['fast-glob', 'path', 'url', 'util'],
treeshake: { moduleSideEffects: 'no-external' },
onwarn,
output: [
Expand All @@ -41,9 +35,23 @@ export default [
},
],
plugins: [
// Copy the native module loader
// The source imports ./load-module-native.js (the CJS version) so that
// tsc emits require("./load-module-native.js") in the CJS build.
// For this ESM bundle we remap it to the .mjs version.
// Returning a relative id with external: true tells rollup to preserve
// the path as-is in the output (see https://rollupjs.org/plugin-development/#resolveid).
{
name: 'rewrite-native-loader',
resolveId(source) {
if (source === './load-module-native.js') {
return { id: './load-module-native.mjs', external: true }
}
return null
},
},
// Copy the native module loaders and their type declarations to lib/
copy({
targets: [{ src: 'src/load-module-native.mjs', dest: 'lib' }],
targets: [{ src: 'src/load-module-native.*', dest: 'lib' }],
}),
typescript(tsOpts),
],
Expand Down
2 changes: 1 addition & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { type InjectionModeType, InjectionMode } from './injection-mode'
import { type LifetimeType, Lifetime, isLifetimeLonger } from './lifetime'
import { type GlobWithOptions, listModules } from './list-modules'
import { importModule } from './load-module-native.mjs'
import { importModule } from './load-module-native.js'
import {
type LoadModulesOptions,
type LoadModulesResult,
Expand Down
1 change: 1 addition & 0 deletions src/load-module-native.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function importModule(path: string): Promise<any>
5 changes: 5 additions & 0 deletions src/load-module-native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This is kept in a separate .js file to prevent TypeScript re-writing the import() statement to a require() statement
// This is the CJS version; the .mjs version is used by the ESM build.
module.exports.importModule = function importModule(path) {
return import(path)
}