Skip to content

Making container ESM ready

Choose a tag to compare

@thetutlage thetutlage released this 10 Feb 10:13

Changes

The IoC container now ships with alternative async APIs to work with ES modules in the future. Converting from sync to async always going to be a breaking change and hence we are doing it now.

Infact, there are no hard breaking changes. Just recommendations around using the async API and the old sync API will still continue to work.

useAsync

Async alternative to use. Right now, there is no difference. However, in the future, we will use ES modules to import dependencies.

await ioc.useAsync('App/Models/User')

makeAsync

Async alternative to make.

const user = await ioc.makeAsync('App/Models/User')

callAsync

Async alternative to call method.

class User {
  public foo () {}
}

await ioc.callAsync(User, 'foo')

Hard breaking changes

The following methods and properties have been removed or renamed.

directoryAliases -> importAliases

Renamed the public property. If you were using it, then you will have to use the new property name. The underlying data structure is still same

ioc.importAliases

getPathAlias

Removed the method altogether. I don't any use case for using this method. Happy to add it back, if others are using it

clearAliasesCache

Removed this method altogether. This method used to clear the IoC container require cache and the require cache of Node.js too. Moving forward with ES modules, the cache is not exposed and cannot be purged.

Hence, it is better to not rely on deleting cache at all. Otherwise, one module system will allow removing cache and other will not and this inconsistency will lead to confusion and buggy code base.

Async only register method

The register method on the Registrar class is not async and there is no sync version of it. Again, the change is done, so that in the future we can shift to ES modules without causing any breaking changes

Commits

  • refactor: fix file casing in git history c3fa546
  • refactor: restructure code and add async apis 2c16929
  • style: reformat source files 77a24b5
  • chore: remove npm-audit in favor of synk bb81224
  • chore: update dependencies 1e2e1ee
  • chore: update dependencies d4873f7
  • chore(deps): bump highlight.js from 10.4.0 to 10.4.1 (#55) 9c781eb
  • chore(deps): bump ini from 1.3.5 to 1.3.7 (#56) a4c4f67

v7.0.9...v8.0.0