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

refactor(common,core): support read-only arrays on module metadata #13655

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ModuleMetadata {
* Optional list of imported modules that export the providers which are
* required in this module.
*/
imports?: Array<
imports?: ReadonlyArray<
Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
>;
/**
Expand All @@ -33,7 +33,7 @@ export interface ModuleMetadata {
* Optional list of the subset of providers that are provided by this module
* and should be available in other modules which import this module.
*/
exports?: Array<
exports?: ReadonlyArray<
| DynamicModule
| Promise<DynamicModule>
| string
Expand Down
5 changes: 4 additions & 1 deletion packages/core/injector/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export class NestContainer {
await this.addDynamicModules(imports, scope);
}

public async addDynamicModules(modules: any[], scope: Type<any>[]) {
public async addDynamicModules(
modules: ReadonlyArray<any>,
scope: Type<any>[],
) {
if (!modules) {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/core/test/injector/container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ describe('NestContainer', () => {
expect(addModuleSpy.called).to.be.true;
});
});
describe('when array is readonly', () => {
it('should call "addModule"', () => {
const addModuleSpy = sinon.spy(container, 'addModule');

const readonlyModules: ReadonlyArray<any> = Object.freeze([Test]);
container.addDynamicModules(readonlyModules, []);

expect(addModuleSpy.called).to.be.true;
});
});
});

describe('get applicationConfig', () => {
Expand Down