@storybook/angular 7.0.0-beta.4 → 7.0.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +66 -0
  2. package/dist/builders/build-storybook/index.d.ts +5 -3
  3. package/dist/builders/build-storybook/index.js +7 -3
  4. package/dist/builders/build-storybook/schema.json +14 -6
  5. package/dist/builders/start-storybook/index.d.ts +5 -3
  6. package/dist/builders/start-storybook/index.js +9 -5
  7. package/dist/builders/start-storybook/schema.json +10 -5
  8. package/dist/builders/utils/run-compodoc.js +11 -27
  9. package/dist/builders/utils/run-compodoc.spec.js +42 -0
  10. package/dist/builders/utils/standalone-options.d.ts +2 -2
  11. package/dist/client/angular-beta/AbstractRenderer.d.ts +3 -3
  12. package/dist/client/angular-beta/AbstractRenderer.js +25 -32
  13. package/dist/client/angular-beta/CanvasRenderer.js +1 -1
  14. package/dist/client/angular-beta/DocsRenderer.js +5 -3
  15. package/dist/client/angular-beta/RendererFactory.js +5 -4
  16. package/dist/client/angular-beta/StorybookModule.d.ts +3 -6
  17. package/dist/client/angular-beta/StorybookModule.js +4 -45
  18. package/dist/client/angular-beta/StorybookModule.test.js +51 -36
  19. package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +3 -2
  20. package/dist/client/angular-beta/StorybookWrapperComponent.js +30 -2
  21. package/dist/client/angular-beta/__testfixtures__/test.module.d.ts +4 -0
  22. package/dist/client/angular-beta/__testfixtures__/test.module.js +34 -0
  23. package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +1 -1
  24. package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +43 -5
  25. package/dist/client/angular-beta/utils/NgModulesAnalyzer.d.ts +1 -1
  26. package/dist/client/angular-beta/utils/NgModulesAnalyzer.js +4 -4
  27. package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +3 -3
  28. package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +50 -0
  29. package/dist/client/angular-beta/utils/PropertyExtractor.js +149 -0
  30. package/dist/client/angular-beta/utils/PropertyExtractor.test.d.ts +1 -0
  31. package/dist/client/angular-beta/utils/PropertyExtractor.test.js +179 -0
  32. package/dist/client/decorateStory.js +1 -1
  33. package/dist/client/docs/compodoc.js +5 -7
  34. package/dist/client/docs/config.js +1 -2
  35. package/dist/client/globals.d.ts +0 -8
  36. package/dist/client/globals.js +2 -29
  37. package/dist/client/render.d.ts +1 -0
  38. package/dist/client/render.js +1 -5
  39. package/dist/client/types.d.ts +0 -2
  40. package/dist/index.mjs +13 -0
  41. package/dist/preset.mjs +26 -0
  42. package/dist/renderer.d.ts +2 -1
  43. package/dist/renderer.js +4 -2
  44. package/dist/renderer.mjs +5 -0
  45. package/dist/server/framework-preset-angular-cli.d.ts +2 -1
  46. package/dist/server/framework-preset-angular-cli.js +21 -92
  47. package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +15 -13
  48. package/dist/server/preset-options.d.ts +3 -2
  49. package/dist/types.mjs +1 -0
  50. package/jest.config.js +19 -0
  51. package/package.json +46 -45
  52. package/template/cli/Button.stories.ts +1 -1
  53. package/template/cli/Header.stories.ts +2 -2
  54. package/template/cli/button.component.ts +2 -0
  55. package/template/components/index.js +2 -2
  56. package/template/stories/angular-mdx.stories.mdx +1 -1
  57. package/template/stories/basics/component-without-selector/without-selector-ng-component-outlet.stories.ts +1 -1
  58. package/template/stories/basics/component-without-selector/without-selector-ng-factory-resolver.stories.ts +1 -1
  59. package/template/stories/basics/component-without-selector/without-selector.stories.ts +1 -1
  60. package/template/stories/basics/ng-module/import-module-chip.stories.ts +23 -0
  61. package/template/stories/basics/ng-module/import-module.stories.ts +2 -13
  62. package/template/stories/core/decorators/componentWrapperDecorator/decorators.stories.ts +0 -18
  63. package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.css +13 -0
  64. package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.html +7 -0
  65. package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.ts +39 -0
  66. package/template/stories/core/moduleMetadata/with-browser-animations.stories.ts +30 -0
  67. package/template/stories/core/moduleMetadata/with-noop-browser-animations.stories.ts +27 -0
  68. package/template/stories/core/parameters/bootstrap-options.stories.ts +1 -5
  69. package/dist/client/angular/helpers.d.ts +0 -8
  70. package/dist/client/angular/helpers.js +0 -150
  71. package/dist/server/angular-read-workspace.d.ts +0 -13
  72. package/dist/server/angular-read-workspace.js +0 -78
  73. package/dist/server/utils/normalize-asset-patterns.d.ts +0 -7
  74. package/dist/server/utils/normalize-asset-patterns.js +0 -64
  75. package/dist/server/utils/normalize-optimization.d.ts +0 -3
  76. package/dist/server/utils/normalize-optimization.js +0 -21
@@ -1,20 +1,9 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createStorybookModule = exports.getStorybookModuleMetadata = void 0;
10
- const core_1 = require("@angular/core");
11
- const platform_browser_1 = require("@angular/platform-browser");
12
- const StorybookProvider_1 = require("./StorybookProvider");
13
- const NgModulesAnalyzer_1 = require("./utils/NgModulesAnalyzer");
14
- const NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
3
+ exports.getApplication = void 0;
15
4
  const StorybookWrapperComponent_1 = require("./StorybookWrapperComponent");
16
5
  const ComputesTemplateFromComponent_1 = require("./ComputesTemplateFromComponent");
17
- const getStorybookModuleMetadata = ({ storyFnAngular, component, targetSelector, }, storyProps$) => {
6
+ const getApplication = ({ storyFnAngular, component, targetSelector, }) => {
18
7
  const { props, styles, moduleMetadata = {} } = storyFnAngular;
19
8
  let { template } = storyFnAngular;
20
9
  const hasTemplate = !hasNoTemplate(template);
@@ -24,39 +13,9 @@ const getStorybookModuleMetadata = ({ storyFnAngular, component, targetSelector,
24
13
  /**
25
14
  * Create a component that wraps generated template and gives it props
26
15
  */
27
- const ComponentToInject = (0, StorybookWrapperComponent_1.createStorybookWrapperComponent)(targetSelector, template, component, styles, props);
28
- const isStandalone = (0, NgComponentAnalyzer_1.isStandaloneComponent)(component);
29
- // Look recursively (deep) if the component is not already declared by an import module
30
- const requiresComponentDeclaration = (0, NgComponentAnalyzer_1.isDeclarable)(component) &&
31
- !(0, NgModulesAnalyzer_1.isComponentAlreadyDeclaredInModules)(component, moduleMetadata.declarations, moduleMetadata.imports) &&
32
- !isStandalone;
33
- return {
34
- declarations: [
35
- ...(requiresComponentDeclaration ? [component] : []),
36
- ComponentToInject,
37
- ...(moduleMetadata.declarations ?? []),
38
- ],
39
- imports: [
40
- platform_browser_1.BrowserModule,
41
- ...(isStandalone ? [component] : []),
42
- ...(moduleMetadata.imports ?? []),
43
- ],
44
- providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$), ...(moduleMetadata.providers ?? [])],
45
- entryComponents: [...(moduleMetadata.entryComponents ?? [])],
46
- schemas: [...(moduleMetadata.schemas ?? [])],
47
- bootstrap: [ComponentToInject],
48
- };
49
- };
50
- exports.getStorybookModuleMetadata = getStorybookModuleMetadata;
51
- const createStorybookModule = (ngModule) => {
52
- let StorybookModule = class StorybookModule {
53
- };
54
- StorybookModule = __decorate([
55
- (0, core_1.NgModule)(ngModule)
56
- ], StorybookModule);
57
- return StorybookModule;
16
+ return (0, StorybookWrapperComponent_1.createStorybookWrapperComponent)(targetSelector, template, component, styles, moduleMetadata, props);
58
17
  };
59
- exports.createStorybookModule = createStorybookModule;
18
+ exports.getApplication = getApplication;
60
19
  function hasNoTemplate(template) {
61
20
  return template === null || template === undefined;
62
21
  }
@@ -11,9 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const core_1 = require("@angular/core");
13
13
  const testing_1 = require("@angular/core/testing");
14
- const platform_browser_1 = require("@angular/platform-browser");
15
14
  const rxjs_1 = require("rxjs");
16
15
  const StorybookModule_1 = require("./StorybookModule");
16
+ const StorybookProvider_1 = require("./StorybookProvider");
17
17
  describe('StorybookModule', () => {
18
18
  describe('getStorybookModuleMetadata', () => {
19
19
  describe('with simple component', () => {
@@ -70,12 +70,15 @@ describe('StorybookModule', () => {
70
70
  localProperty: 'localProperty',
71
71
  localFunction: () => 'localFunction',
72
72
  };
73
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
73
+ const application = (0, StorybookModule_1.getApplication)({
74
74
  storyFnAngular: { props },
75
75
  component: FooComponent,
76
76
  targetSelector: 'my-selector',
77
- }, new rxjs_1.BehaviorSubject(props));
78
- const { fixture } = await configureTestingModule(ngModule);
77
+ });
78
+ const { fixture } = await configureTestingModule({
79
+ imports: [application],
80
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(new rxjs_1.BehaviorSubject(props))],
81
+ });
79
82
  fixture.detectChanges();
80
83
  expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(props.input);
81
84
  expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual(props.inputBindingPropertyName);
@@ -93,12 +96,15 @@ describe('StorybookModule', () => {
93
96
  expectedOutputBindingValue = value;
94
97
  },
95
98
  };
96
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
99
+ const application = (0, StorybookModule_1.getApplication)({
97
100
  storyFnAngular: { props },
98
101
  component: FooComponent,
99
102
  targetSelector: 'my-selector',
100
- }, new rxjs_1.BehaviorSubject(props));
101
- const { fixture } = await configureTestingModule(ngModule);
103
+ });
104
+ const { fixture } = await configureTestingModule({
105
+ imports: [application],
106
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(new rxjs_1.BehaviorSubject(props))],
107
+ });
102
108
  fixture.detectChanges();
103
109
  fixture.nativeElement.querySelector('p#output').click();
104
110
  fixture.nativeElement.querySelector('p#outputBindingPropertyName').click();
@@ -111,12 +117,15 @@ describe('StorybookModule', () => {
111
117
  inputBindingPropertyName: '',
112
118
  };
113
119
  const storyProps$ = new rxjs_1.BehaviorSubject(initialProps);
114
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
120
+ const application = (0, StorybookModule_1.getApplication)({
115
121
  storyFnAngular: { props: initialProps },
116
122
  component: FooComponent,
117
123
  targetSelector: 'my-selector',
118
- }, storyProps$);
119
- const { fixture } = await configureTestingModule(ngModule);
124
+ });
125
+ const { fixture } = await configureTestingModule({
126
+ imports: [application],
127
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$)],
128
+ });
120
129
  fixture.detectChanges();
121
130
  expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
122
131
  expect(fixture.nativeElement.querySelector('p#inputBindingPropertyName').innerHTML).toEqual('');
@@ -146,12 +155,15 @@ describe('StorybookModule', () => {
146
155
  },
147
156
  };
148
157
  const storyProps$ = new rxjs_1.BehaviorSubject(initialProps);
149
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
158
+ const application = (0, StorybookModule_1.getApplication)({
150
159
  storyFnAngular: { props: initialProps },
151
160
  component: FooComponent,
152
161
  targetSelector: 'my-selector',
153
- }, storyProps$);
154
- const { fixture } = await configureTestingModule(ngModule);
162
+ });
163
+ const { fixture } = await configureTestingModule({
164
+ imports: [application],
165
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$)],
166
+ });
155
167
  fixture.detectChanges();
156
168
  const newProps = {
157
169
  input: 'new input',
@@ -176,15 +188,18 @@ describe('StorybookModule', () => {
176
188
  input: 'input',
177
189
  };
178
190
  const storyProps$ = new rxjs_1.BehaviorSubject(initialProps);
179
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
191
+ const application = (0, StorybookModule_1.getApplication)({
180
192
  storyFnAngular: {
181
193
  props: initialProps,
182
194
  template: '<p [style.color]="color"><foo [input]="input"></foo></p>',
183
195
  },
184
196
  component: FooComponent,
185
197
  targetSelector: 'my-selector',
186
- }, storyProps$);
187
- const { fixture } = await configureTestingModule(ngModule);
198
+ });
199
+ const { fixture } = await configureTestingModule({
200
+ imports: [application],
201
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$)],
202
+ });
188
203
  fixture.detectChanges();
189
204
  expect(fixture.nativeElement.querySelector('p').style.color).toEqual('red');
190
205
  expect(fixture.nativeElement.querySelector('p#input').innerHTML).toEqual(initialProps.input);
@@ -202,12 +217,15 @@ describe('StorybookModule', () => {
202
217
  setter: 'init',
203
218
  };
204
219
  const storyProps$ = new rxjs_1.BehaviorSubject(initialProps);
205
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
220
+ const application = (0, StorybookModule_1.getApplication)({
206
221
  storyFnAngular: { props: initialProps },
207
222
  component: FooComponent,
208
223
  targetSelector: 'my-selector',
209
- }, storyProps$);
210
- const { fixture } = await configureTestingModule(ngModule);
224
+ });
225
+ const { fixture } = await configureTestingModule({
226
+ imports: [application],
227
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(storyProps$)],
228
+ });
211
229
  fixture.detectChanges();
212
230
  expect(fixture.nativeElement.querySelector('p#setterCallNb').innerHTML).toEqual('1');
213
231
  const newProps = {
@@ -228,15 +246,18 @@ describe('StorybookModule', () => {
228
246
  ], WithoutSelectorComponent);
229
247
  it('should display the component', async () => {
230
248
  const props = {};
231
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
249
+ const application = (0, StorybookModule_1.getApplication)({
232
250
  storyFnAngular: {
233
251
  props,
234
252
  moduleMetadata: { entryComponents: [WithoutSelectorComponent] },
235
253
  },
236
254
  component: WithoutSelectorComponent,
237
255
  targetSelector: 'my-selector',
238
- }, new rxjs_1.BehaviorSubject(props));
239
- const { fixture } = await configureTestingModule(ngModule);
256
+ });
257
+ const { fixture } = await configureTestingModule({
258
+ imports: [application],
259
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(new rxjs_1.BehaviorSubject(props))],
260
+ });
240
261
  fixture.detectChanges();
241
262
  expect(fixture.nativeElement.innerHTML).toContain('The content');
242
263
  });
@@ -250,28 +271,22 @@ describe('StorybookModule', () => {
250
271
  template: `Should not be displayed`,
251
272
  })
252
273
  ], FooComponent);
253
- const ngModule = (0, StorybookModule_1.getStorybookModuleMetadata)({
274
+ const application = (0, StorybookModule_1.getApplication)({
254
275
  storyFnAngular: { template: '' },
255
276
  component: FooComponent,
256
277
  targetSelector: 'my-selector',
257
- }, new rxjs_1.BehaviorSubject({}));
258
- const { fixture } = await configureTestingModule(ngModule);
278
+ });
279
+ const { fixture } = await configureTestingModule({
280
+ imports: [application],
281
+ providers: [(0, StorybookProvider_1.storyPropsProvider)(new rxjs_1.BehaviorSubject({}))],
282
+ });
259
283
  fixture.detectChanges();
260
284
  expect(fixture.nativeElement.innerHTML).toEqual('');
261
285
  });
262
286
  });
263
287
  async function configureTestingModule(ngModule) {
264
- await testing_1.TestBed.configureTestingModule({
265
- declarations: ngModule.declarations,
266
- providers: ngModule.providers,
267
- })
268
- .overrideModule(platform_browser_1.BrowserModule, {
269
- set: {
270
- entryComponents: [...ngModule.entryComponents],
271
- },
272
- })
273
- .compileComponents();
274
- const fixture = testing_1.TestBed.createComponent(ngModule.bootstrap[0]);
288
+ await testing_1.TestBed.configureTestingModule(ngModule).compileComponents();
289
+ const fixture = testing_1.TestBed.createComponent(ngModule.imports[0]);
275
290
  return {
276
291
  fixture,
277
292
  };
@@ -1,9 +1,10 @@
1
1
  import { Type } from '@angular/core';
2
- import { ICollection } from '../types';
2
+ import { ICollection, NgModuleMetadata } from '../types';
3
+ export declare const componentNgModules: Map<any, Type<any>>;
3
4
  /**
4
5
  * Wraps the story template into a component
5
6
  *
6
7
  * @param storyComponent
7
8
  * @param initialProps
8
9
  */
9
- export declare const createStorybookWrapperComponent: (selector: string, template: string, storyComponent: Type<unknown> | undefined, styles: string[], initialProps?: ICollection) => Type<any>;
10
+ export declare const createStorybookWrapperComponent: (selector: string, template: string, storyComponent: Type<unknown> | undefined, styles: string[], moduleMetadata: NgModuleMetadata, initialProps?: ICollection) => Type<any>;
@@ -12,12 +12,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.createStorybookWrapperComponent = void 0;
15
+ exports.createStorybookWrapperComponent = exports.componentNgModules = void 0;
16
16
  const core_1 = require("@angular/core");
17
17
  const rxjs_1 = require("rxjs");
18
18
  const operators_1 = require("rxjs/operators");
19
19
  const StorybookProvider_1 = require("./StorybookProvider");
20
20
  const NgComponentAnalyzer_1 = require("./utils/NgComponentAnalyzer");
21
+ const PropertyExtractor_1 = require("./utils/PropertyExtractor");
21
22
  const getNonInputsOutputsProps = (ngComponentInputsOutputs, props = {}) => {
22
23
  const inputs = ngComponentInputsOutputs.inputs
23
24
  .filter((i) => i.templateName in props)
@@ -27,16 +28,39 @@ const getNonInputsOutputsProps = (ngComponentInputsOutputs, props = {}) => {
27
28
  .map((o) => o.templateName);
28
29
  return Object.keys(props).filter((k) => ![...inputs, ...outputs].includes(k));
29
30
  };
31
+ // component modules cache
32
+ exports.componentNgModules = new Map();
30
33
  /**
31
34
  * Wraps the story template into a component
32
35
  *
33
36
  * @param storyComponent
34
37
  * @param initialProps
35
38
  */
36
- const createStorybookWrapperComponent = (selector, template, storyComponent, styles, initialProps) => {
39
+ const createStorybookWrapperComponent = (selector, template, storyComponent, styles, moduleMetadata, initialProps) => {
37
40
  // In ivy, a '' selector is not allowed, therefore we need to just set it to anything if
38
41
  // storyComponent was not provided.
39
42
  const viewChildSelector = storyComponent ?? '__storybook-noop';
43
+ const imports = (0, PropertyExtractor_1.extractImports)(moduleMetadata);
44
+ const declarations = (0, PropertyExtractor_1.extractDeclarations)(moduleMetadata, storyComponent);
45
+ const providers = (0, PropertyExtractor_1.extractProviders)(moduleMetadata);
46
+ // Only create a new module if it doesn't already exist
47
+ // This is to prevent the module from being recreated on every story change
48
+ // Declarations & Imports are only added once
49
+ // Providers are added on every story change to allow for story-specific providers
50
+ let ngModule = exports.componentNgModules.get(storyComponent);
51
+ if (!ngModule) {
52
+ let StorybookComponentModule = class StorybookComponentModule {
53
+ };
54
+ StorybookComponentModule = __decorate([
55
+ (0, core_1.NgModule)({
56
+ declarations,
57
+ imports,
58
+ exports: [...declarations, ...imports],
59
+ })
60
+ ], StorybookComponentModule);
61
+ exports.componentNgModules.set(storyComponent, StorybookComponentModule);
62
+ ngModule = exports.componentNgModules.get(storyComponent);
63
+ }
40
64
  let StorybookWrapperComponent = class StorybookWrapperComponent {
41
65
  constructor(storyProps$, changeDetectorRef) {
42
66
  this.storyProps$ = storyProps$;
@@ -104,7 +128,11 @@ const createStorybookWrapperComponent = (selector, template, storyComponent, sty
104
128
  (0, core_1.Component)({
105
129
  selector,
106
130
  template,
131
+ standalone: true,
132
+ imports: [ngModule],
133
+ providers,
107
134
  styles,
135
+ schemas: moduleMetadata.schemas,
108
136
  }),
109
137
  __param(0, (0, core_1.Inject)(StorybookProvider_1.STORY_PROPS)),
110
138
  __metadata("design:paramtypes", [rxjs_1.Subject,
@@ -0,0 +1,4 @@
1
+ export declare class WithAnimationsModule {
2
+ }
3
+ export declare class WithOfficialModule {
4
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.WithOfficialModule = exports.WithAnimationsModule = void 0;
10
+ const common_1 = require("@angular/common");
11
+ const http_1 = require("@angular/common/http");
12
+ const core_1 = require("@angular/core");
13
+ const platform_browser_1 = require("@angular/platform-browser");
14
+ const animations_1 = require("@angular/platform-browser/animations");
15
+ let WithAnimationsModule = class WithAnimationsModule {
16
+ };
17
+ WithAnimationsModule = __decorate([
18
+ (0, core_1.NgModule)({
19
+ imports: [
20
+ //
21
+ platform_browser_1.BrowserModule,
22
+ animations_1.BrowserAnimationsModule,
23
+ ],
24
+ })
25
+ ], WithAnimationsModule);
26
+ exports.WithAnimationsModule = WithAnimationsModule;
27
+ let WithOfficialModule = class WithOfficialModule {
28
+ };
29
+ WithOfficialModule = __decorate([
30
+ (0, core_1.NgModule)({
31
+ imports: [common_1.CommonModule, http_1.HttpClientModule],
32
+ })
33
+ ], WithOfficialModule);
34
+ exports.WithOfficialModule = WithOfficialModule;
@@ -76,7 +76,7 @@ const isStandaloneComponent = (component) => {
76
76
  const decorators = reflectionCapabilities.annotations(component);
77
77
  // TODO: `standalone` is only available in Angular v14. Remove cast to `any` once
78
78
  // Angular deps are updated to v14.x.x.
79
- return (decorators || []).some((d) => d instanceof core_1.Component && d.standalone);
79
+ return (decorators || []).some((d) => (d instanceof core_1.Component || d instanceof core_1.Directive || d instanceof core_1.Pipe) && d.standalone);
80
80
  };
81
81
  exports.isStandaloneComponent = isStandaloneComponent;
82
82
  /**
@@ -252,8 +252,6 @@ describe('isComponent', () => {
252
252
  });
253
253
  describe('isStandaloneComponent', () => {
254
254
  it('should return true with a Component with "standalone: true"', () => {
255
- // TODO: `standalone` is only available in Angular v14. Remove cast to `any` once
256
- // Angular deps are updated to v14.x.x.
257
255
  let FooComponent = class FooComponent {
258
256
  };
259
257
  FooComponent = __decorate([
@@ -262,8 +260,6 @@ describe('isStandaloneComponent', () => {
262
260
  expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooComponent)).toEqual(true);
263
261
  });
264
262
  it('should return false with a Component with "standalone: false"', () => {
265
- // TODO: `standalone` is only available in Angular v14. Remove cast to `any` once
266
- // Angular deps are updated to v14.x.x.
267
263
  let FooComponent = class FooComponent {
268
264
  };
269
265
  FooComponent = __decorate([
@@ -284,7 +280,23 @@ describe('isStandaloneComponent', () => {
284
280
  }
285
281
  expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooPipe)).toEqual(false);
286
282
  });
287
- it('should return false with Directive', () => {
283
+ it('should return true with a Directive with "standalone: true"', () => {
284
+ let FooDirective = class FooDirective {
285
+ };
286
+ FooDirective = __decorate([
287
+ (0, core_1.Directive)({ standalone: true })
288
+ ], FooDirective);
289
+ expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooDirective)).toEqual(true);
290
+ });
291
+ it('should return false with a Directive with "standalone: false"', () => {
292
+ let FooDirective = class FooDirective {
293
+ };
294
+ FooDirective = __decorate([
295
+ (0, core_1.Directive)({ standalone: false })
296
+ ], FooDirective);
297
+ expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooDirective)).toEqual(false);
298
+ });
299
+ it('should return false with Directive without the "standalone" property', () => {
288
300
  let FooDirective = class FooDirective {
289
301
  };
290
302
  FooDirective = __decorate([
@@ -292,6 +304,32 @@ describe('isStandaloneComponent', () => {
292
304
  ], FooDirective);
293
305
  expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooDirective)).toEqual(false);
294
306
  });
307
+ it('should return true with a Pipe with "standalone: true"', () => {
308
+ let FooPipe = class FooPipe {
309
+ };
310
+ FooPipe = __decorate([
311
+ (0, core_1.Pipe)({ name: 'FooPipe', standalone: true })
312
+ ], FooPipe);
313
+ expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooPipe)).toEqual(true);
314
+ });
315
+ it('should return false with a Pipe with "standalone: false"', () => {
316
+ let FooPipe = class FooPipe {
317
+ };
318
+ FooPipe = __decorate([
319
+ (0, core_1.Pipe)({ name: 'FooPipe', standalone: false })
320
+ ], FooPipe);
321
+ expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooPipe)).toEqual(false);
322
+ });
323
+ it('should return false with Pipe without the "standalone" property', () => {
324
+ let FooPipe = class FooPipe {
325
+ };
326
+ FooPipe = __decorate([
327
+ (0, core_1.Pipe)({
328
+ name: 'fooPipe',
329
+ })
330
+ ], FooPipe);
331
+ expect((0, NgComponentAnalyzer_1.isStandaloneComponent)(FooPipe)).toEqual(false);
332
+ });
295
333
  });
296
334
  describe('getComponentDecoratorMetadata', () => {
297
335
  it('should return Component with a Component', () => {
@@ -3,4 +3,4 @@
3
3
  *
4
4
  * Checks recursively if the component has already been declared in all import Module
5
5
  */
6
- export declare const isComponentAlreadyDeclaredInModules: (componentToFind: any, moduleDeclarations: any[], moduleImports: any[]) => boolean;
6
+ export declare const isComponentAlreadyDeclared: (componentToFind: any, moduleDeclarations: any[], moduleImports: any[]) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isComponentAlreadyDeclaredInModules = void 0;
3
+ exports.isComponentAlreadyDeclared = void 0;
4
4
  const core_1 = require("@angular/core");
5
5
  const reflectionCapabilities = new core_1.ɵReflectionCapabilities();
6
6
  /**
@@ -8,7 +8,7 @@ const reflectionCapabilities = new core_1.ɵReflectionCapabilities();
8
8
  *
9
9
  * Checks recursively if the component has already been declared in all import Module
10
10
  */
11
- const isComponentAlreadyDeclaredInModules = (componentToFind, moduleDeclarations, moduleImports) => {
11
+ const isComponentAlreadyDeclared = (componentToFind, moduleDeclarations, moduleImports) => {
12
12
  if (moduleDeclarations &&
13
13
  moduleDeclarations.some((declaration) => declaration === componentToFind)) {
14
14
  // Found component in declarations array
@@ -23,10 +23,10 @@ const isComponentAlreadyDeclaredInModules = (componentToFind, moduleDeclarations
23
23
  // Not an NgModule
24
24
  return false;
25
25
  }
26
- return (0, exports.isComponentAlreadyDeclaredInModules)(componentToFind, extractedNgModuleMetadata.declarations, extractedNgModuleMetadata.imports);
26
+ return (0, exports.isComponentAlreadyDeclared)(componentToFind, extractedNgModuleMetadata.declarations, extractedNgModuleMetadata.imports);
27
27
  });
28
28
  };
29
- exports.isComponentAlreadyDeclaredInModules = isComponentAlreadyDeclaredInModules;
29
+ exports.isComponentAlreadyDeclared = isComponentAlreadyDeclared;
30
30
  const extractNgModuleMetadata = (importItem) => {
31
31
  const target = importItem && importItem.ngModule ? importItem.ngModule : importItem;
32
32
  const decorators = reflectionCapabilities.annotations(target);
@@ -12,12 +12,12 @@ const AlphaModule = (0, core_1.NgModule)({ imports: [BetaModule] })(class {
12
12
  });
13
13
  describe('isComponentAlreadyDeclaredInModules', () => {
14
14
  it('should return true when the component is already declared in one of modules', () => {
15
- expect((0, NgModulesAnalyzer_1.isComponentAlreadyDeclaredInModules)(FooComponent, [], [AlphaModule])).toEqual(true);
15
+ expect((0, NgModulesAnalyzer_1.isComponentAlreadyDeclared)(FooComponent, [], [AlphaModule])).toEqual(true);
16
16
  });
17
17
  it('should return true if the component is in moduleDeclarations', () => {
18
- expect((0, NgModulesAnalyzer_1.isComponentAlreadyDeclaredInModules)(BarComponent, [BarComponent], [AlphaModule])).toEqual(true);
18
+ expect((0, NgModulesAnalyzer_1.isComponentAlreadyDeclared)(BarComponent, [BarComponent], [AlphaModule])).toEqual(true);
19
19
  });
20
20
  it('should return false if the component is not declared', () => {
21
- expect((0, NgModulesAnalyzer_1.isComponentAlreadyDeclaredInModules)(BarComponent, [], [AlphaModule])).toEqual(false);
21
+ expect((0, NgModulesAnalyzer_1.isComponentAlreadyDeclared)(BarComponent, [], [AlphaModule])).toEqual(false);
22
22
  });
23
23
  });
@@ -0,0 +1,50 @@
1
+ import { InjectionToken, Provider } from '@angular/core';
2
+ import { NgModuleMetadata } from '../../types';
3
+ export declare const REMOVED_MODULES: InjectionToken<unknown>;
4
+ /**
5
+ * Analyze NgModule Metadata
6
+ *
7
+ * - Removes Restricted Imports
8
+ * - Extracts providers from ModuleWithProviders
9
+ * - Flattens imports
10
+ * - Returns a new NgModuleMetadata object
11
+ *
12
+ *
13
+ */
14
+ export declare const analyzeMetadata: (metadata: NgModuleMetadata) => {
15
+ imports: any;
16
+ providers: any[];
17
+ singletons: any[];
18
+ declarations: any[];
19
+ entryComponents?: any[];
20
+ schemas?: any[];
21
+ };
22
+ /**
23
+ * Extract Imports from NgModule
24
+ *
25
+ * CommonModule is always imported
26
+ * Only standalone components are imported
27
+ *
28
+ */
29
+ export declare const extractImports: (metadata: NgModuleMetadata) => any[];
30
+ /**
31
+ * Extract providers from NgModule
32
+ *
33
+ * - A new array is returned with:
34
+ * - metadata.providers
35
+ * - providers from each **ModuleWithProviders** (e.g. forRoot() & forChild() )
36
+ *
37
+ *
38
+ */
39
+ export declare const extractProviders: (metadata: NgModuleMetadata) => Provider[];
40
+ export declare const extractSingletons: (metadata: NgModuleMetadata) => Provider[];
41
+ /**
42
+ * Extract declarations from NgModule
43
+ *
44
+ * - If a story component is provided, it will be added to the declarations array if:
45
+ * - It is a component or directive or pipe
46
+ * - It is not already declared
47
+ * - It is not a standalone component
48
+ *
49
+ */
50
+ export declare const extractDeclarations: (metadata: NgModuleMetadata, storyComponent?: any) => any[];