Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline resolver options are ingored when loading modules #124

Closed
witq opened this Issue Mar 6, 2019 · 14 comments

Comments

Projects
None yet
2 participants
@witq
Copy link

witq commented Mar 6, 2019

Hi,

I've been trying to use inline resolver options when loading modules and noticed that setting the register property did nothing. I looked at load-modules.ts and it seemes that inline resolver options are ignored when constructing the final regOpts object:

const regOpts: BuildResolver<any> = {
  ...opts.resolverOptions,
  ...moduleDescriptorOpts
}

I changed it to treat inline options as the final component of the object, overwriting any previously set options and it worked flawlessly - my module's export has been registered asValue, as declared in the inline resolver options.
The changed regOpts look like this:

const regOpts: BuildResolver<any> = {
  ...opts.resolverOptions,
  ...moduleDescriptorOpts,
  ...inlineConfig
}

Since I'm not sure if this is by design and I'm having massive issues with setting up the environment for contributing, I'm opening an issue instead of a pull request.

Please let me know if this is something that you'd want a PR for. And thank you for this library - great use of proxies and a joy to work with 👍

@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

Thanks for the kind words!

I can't exactly remember if this was intended or not, but inline config should probably always win, so a PR is welcome! 👍

@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

I'm having massive issues with setting up the environment for contributing

Anything specific to this repo?

@witq

This comment has been minimized.

Copy link
Author

witq commented Mar 6, 2019

Anything specific to this repo?

I'm not sure. I'm also not sure if the isses I'm having are indeed massive 😉 When trying to run npm run build, I get the following output:

npm run build                                                                                                                                                                                      1 ↵

> awilix@4.2.0 build /Users/witek/Workspace/awilix
> rimraf lib && tsc -p tsconfig.build.json && rollup -c

src/container.ts:292:5 - error TS2322: Type '{ options: ContainerOptions; cradle: any; inspect: (depth: number, opts: any) => string; cache: Map<string | symbol, CacheEntry>; loadModules: (globPatterns: (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<...>])[], opts: LoadModulesOptions) => AwilixContainer & { ...; }; ... 8 m...' is not assignable to type 'AwilixContainer & { [ROLL_UP_REGISTRATIONS]: (bustCache?: boolean) => Record<string | number | symbol, Resolver<any>>; }'.
  Object literal may only specify known properties, and '[util.inspect.custom]' does not exist in type 'AwilixContainer & { [ROLL_UP_REGISTRATIONS]: (bustCache?: boolean) => Record<string | number | symbol, Resolver<any>>; }'.

292     [util.inspect.custom]: inspect,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

When trying to run npm run test, there are multiple type errors that I don't see an obvious fix for:

npm run test                                                                                                                                                                                       2 ↵

> awilix@4.2.0 test /Users/witek/Workspace/awilix
> npm run check && jest


> awilix@4.2.0 check /Users/witek/Workspace/awilix
> tsc -p tsconfig.json --noEmit --pretty

src/__tests__/load-modules.test.ts:32:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.
      Type '{ name: string; path: string; }[]' is not assignable to type 'ModuleDescriptor[]'.
        Property 'opts' is missing in type '{ name: string; path: string; }' but required in type 'ModuleDescriptor'.

32     const result = loadModules(deps, 'anything')
                                  ~~~~

  src/list-modules.ts:24:3
    24   opts: any
         ~~~~
    'opts' is declared here.

src/__tests__/load-modules.test.ts:57:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

57     const result = loadModules(deps, 'anything')
                                  ~~~~

src/__tests__/load-modules.test.ts:81:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

81     const result = loadModules(deps, 'anything')
                                  ~~~~

src/__tests__/load-modules.test.ts:113:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

113     const result = loadModules(deps, 'anything')
                                   ~~~~

src/__tests__/load-modules.test.ts:156:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

156     const result = loadModules(deps, 'anything')
                                   ~~~~

src/__tests__/load-modules.test.ts:181:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

181     const result = loadModules(deps, 'anything', opts)
                                   ~~~~

src/__tests__/load-modules.test.ts:204:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

204     const result = loadModules(deps, 'anything', opts)
                                   ~~~~

src/__tests__/load-modules.test.ts:224:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

224     const result = loadModules(deps, 'anything', opts)
                                   ~~~~

src/__tests__/load-modules.test.ts:244:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

244     const result = loadModules(deps, 'anything', opts)
                                   ~~~~

src/__tests__/load-modules.test.ts:270:32 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.

270     const result = loadModules(deps, 'anything', opts)
                                   ~~~~

src/__tests__/load-modules.test.ts:293:17 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<({ name: string; path: string; opts: LifetimeType; } | { name: string; path: string; opts?: undefined; })[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<({ name: string; path: string; opts: LifetimeType; } | { name: string; path: string; opts?: undefined; })[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.
      Type '({ name: string; path: string; opts: LifetimeType; } | { name: string; path: string; opts?: undefined; })[]' is not assignable to type 'ModuleDescriptor[]'.
        Type '{ name: string; path: string; opts: LifetimeType; } | { name: string; path: string; opts?: undefined; }' is not assignable to type 'ModuleDescriptor'.
          Type '{ name: string; path: string; opts?: undefined; }' is not assignable to type 'ModuleDescriptor'.
            Property 'opts' is optional in type '{ name: string; path: string; opts?: undefined; }' but required in type 'ModuleDescriptor'.

293     loadModules(deps, 'anything', {
                    ~~~~

src/__tests__/load-modules.test.ts:319:17 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<({ name: string; path: string; opts: { lifetime: LifetimeType; }; } | { name: string; path: string; opts?: undefined; })[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<({ name: string; path: string; opts: { lifetime: LifetimeType; }; } | { name: string; path: string; opts?: undefined; })[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.
      Type '({ name: string; path: string; opts: { lifetime: LifetimeType; }; } | { name: string; path: string; opts?: undefined; })[]' is not assignable to type 'ModuleDescriptor[]'.
        Type '{ name: string; path: string; opts: { lifetime: LifetimeType; }; } | { name: string; path: string; opts?: undefined; }' is not assignable to type 'ModuleDescriptor'.
          Type '{ name: string; path: string; opts?: undefined; }' is not assignable to type 'ModuleDescriptor'.
            Property 'opts' is optional in type '{ name: string; path: string; opts?: undefined; }' but required in type 'ModuleDescriptor'.

319     loadModules(deps, 'anything', {
                    ~~~~

src/__tests__/load-modules.test.ts:349:17 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<({ name: string; path: string; opts: { injectionMode: InjectionModeType; }; } | { name: string; path: string; opts?: undefined; })[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<({ name: string; path: string; opts: { injectionMode: InjectionModeType; }; } | { name: string; path: string; opts?: undefined; })[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.
      Type '({ name: string; path: string; opts: { injectionMode: InjectionModeType; }; } | { name: string; path: string; opts?: undefined; })[]' is not assignable to type 'ModuleDescriptor[]'.
        Type '{ name: string; path: string; opts: { injectionMode: InjectionModeType; }; } | { name: string; path: string; opts?: undefined; }' is not assignable to type 'ModuleDescriptor'.
          Type '{ name: string; path: string; opts?: undefined; }' is not assignable to type 'ModuleDescriptor'.
            Property 'opts' is optional in type '{ name: string; path: string; opts?: undefined; }' but required in type 'ModuleDescriptor'.

349     loadModules(deps, 'anything', {
                    ~~~~

src/__tests__/load-modules.test.ts:391:19 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.
      Type '{ name: string; path: string; }[]' is not assignable to type 'ModuleDescriptor[]'.
        Property 'opts' is missing in type '{ name: string; path: string; }' but required in type 'ModuleDescriptor'.

391       loadModules(deps, 'anything', {
                      ~~~~

  src/list-modules.ts:24:3
    24   opts: any
         ~~~~
    'opts' is declared here.

src/__tests__/load-modules.test.ts:430:19 - error TS2345: Argument of type '{ container: AwilixContainer; listModules: Mock<{ name: string; path: string; }[], []>; require: Mock<any, any[]>; }' is not assignable to parameter of type 'LoadModulesDeps'.
  Types of property 'listModules' are incompatible.
    Type 'Mock<{ name: string; path: string; }[], []>' is not assignable to type '(globPatterns: string | (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<any>])[], opts?: ListModulesOptions | undefined) => ModuleDescriptor[]'.
      Type '{ name: string; path: string; }[]' is not assignable to type 'ModuleDescriptor[]'.
        Property 'opts' is missing in type '{ name: string; path: string; }' but required in type 'ModuleDescriptor'.

430       loadModules(deps, 'anything', {
                      ~~~~

  src/list-modules.ts:24:3
    24   opts: any
         ~~~~
    'opts' is declared here.

src/__tests__/load-modules.test.ts:431:21 - error TS7006: Parameter 'desc' implicitly has an 'any' type.

431         formatName: desc => 'formatNameCalled',
                        ~~~~

src/container.ts:292:5 - error TS2322: Type '{ options: ContainerOptions; cradle: any; inspect: (depth: number, opts: any) => string; cache: Map<string | symbol, CacheEntry>; loadModules: (globPatterns: (string | [string] | [string, "SINGLETON" | "TRANSIENT" | "SCOPED" | ResolverOptions<...>])[], opts: LoadModulesOptions) => AwilixContainer & { ...; }; ... 8 m...' is not assignable to type 'AwilixContainer & { [ROLL_UP_REGISTRATIONS]: (bustCache?: boolean) => Record<string | number | symbol, Resolver<any>>; }'.
  Object literal may only specify known properties, and '[util.inspect.custom]' does not exist in type 'AwilixContainer & { [ROLL_UP_REGISTRATIONS]: (bustCache?: boolean) => Record<string | number | symbol, Resolver<any>>; }'.

292     [util.inspect.custom]: inspect,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 17 errors.```
@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

And you did yarn before running tests?

@witq

This comment has been minimized.

Copy link
Author

witq commented Mar 6, 2019

Yeah, actually nevermind, setting the opts property to be optional in ModuleDescriptor interface fixed all the errors except the one about util.inspect.custom. The modified ModuleDescriptor:

export interface ModuleDescriptor {
  name: string
  path: string
  opts?: any
}
@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

Don't worry about it, I'll push a fix for this. 😄

@witq

This comment has been minimized.

Copy link
Author

witq commented Mar 6, 2019

Great, then I'll do my thing with the inline resolver options 👍
Thank you for being so responsive 😄

@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

Oh, I am getting those errors as well after I updated all packages. I'll work them out.

jeffijoe added a commit that referenced this issue Mar 6, 2019

jeffijoe added a commit that referenced this issue Mar 6, 2019

@jeffijoe jeffijoe closed this in #125 Mar 6, 2019

@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

Shipped in 4.2.1, thanks for reporting!

@witq

This comment has been minimized.

Copy link
Author

witq commented Mar 6, 2019

Oh man I was hoping to score a contribution 😉
Thank you for the quick fix!

@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

Haha I considered that I was stealing it away from you but I didn't want to scare you away by making you fix build tools! 😂

@witq

This comment has been minimized.

Copy link
Author

witq commented Mar 6, 2019

I'll keep lurking around the codebase and finding bugs then... 😉

@jeffijoe

This comment has been minimized.

Copy link
Owner

jeffijoe commented Mar 6, 2019

Do it!

@witq

This comment has been minimized.

Copy link
Author

witq commented Mar 6, 2019

I loled. Love that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.