@storybook/angular 7.0.0-beta.50 → 7.0.0-beta.52

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.
@@ -88,11 +88,17 @@ class AbstractRenderer {
88
88
  }
89
89
  this.storyProps$ = newStoryProps$;
90
90
  this.initAngularRootElement(targetDOMNode, targetSelector);
91
+ const analyzedMetadata = new PropertyExtractor_1.PropertyExtractor(storyFnAngular.moduleMetadata, component);
91
92
  const providers = [
92
93
  // Providers for BrowserAnimations & NoopAnimationsModule
93
- (0, PropertyExtractor_1.extractSingletons)(storyFnAngular.moduleMetadata),
94
+ analyzedMetadata.singletons,
95
+ (0, core_1.importProvidersFrom)(...analyzedMetadata.imports.filter((imported) => {
96
+ const { isStandalone } = PropertyExtractor_1.PropertyExtractor.analyzeDecorators(component);
97
+ return !isStandalone;
98
+ })),
99
+ analyzedMetadata.providers,
94
100
  (0, StorybookProvider_1.storyPropsProvider)(newStoryProps$),
95
- ];
101
+ ].filter(Boolean);
96
102
  const application = (0, StorybookModule_1.getApplication)({ storyFnAngular, component, targetSelector });
97
103
  const applicationRef = await (0, platform_browser_1.bootstrapApplication)(application, { providers });
98
104
  applicationRefs.add(applicationRef);
@@ -40,9 +40,8 @@ const createStorybookWrapperComponent = (selector, template, storyComponent, sty
40
40
  // In ivy, a '' selector is not allowed, therefore we need to just set it to anything if
41
41
  // storyComponent was not provided.
42
42
  const viewChildSelector = storyComponent ?? '__storybook-noop';
43
- const imports = (0, PropertyExtractor_1.extractImports)(moduleMetadata, storyComponent);
44
- const declarations = (0, PropertyExtractor_1.extractDeclarations)(moduleMetadata, storyComponent);
45
- const providers = (0, PropertyExtractor_1.extractProviders)(moduleMetadata);
43
+ const analyzedMetadata = new PropertyExtractor_1.PropertyExtractor(moduleMetadata, storyComponent);
44
+ const { imports, declarations, providers } = analyzedMetadata;
46
45
  // Only create a new module if it doesn't already exist
47
46
  // This is to prevent the module from being recreated on every story change
48
47
  // Declarations & Imports are only added once
@@ -1,4 +1,2 @@
1
- export declare class WithAnimationsModule {
2
- }
3
1
  export declare class WithOfficialModule {
4
2
  }
@@ -6,24 +6,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.WithOfficialModule = exports.WithAnimationsModule = void 0;
9
+ exports.WithOfficialModule = void 0;
10
10
  const common_1 = require("@angular/common");
11
11
  const http_1 = require("@angular/common/http");
12
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
13
  let WithOfficialModule = class WithOfficialModule {
28
14
  };
29
15
  WithOfficialModule = __decorate([
@@ -1,50 +1,32 @@
1
- import { InjectionToken, Provider } from '@angular/core';
1
+ import { InjectionToken, NgModule, Provider, ɵReflectionCapabilities as ReflectionCapabilities } from '@angular/core';
2
2
  import { NgModuleMetadata } from '../../types';
3
+ export declare const reflectionCapabilities: ReflectionCapabilities;
3
4
  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, storyComponent?: any) => 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[];
5
+ export declare const uniqueArray: (arr: any[]) => any[];
6
+ export declare class PropertyExtractor implements NgModuleMetadata {
7
+ private metadata;
8
+ private component?;
9
+ declarations?: any[];
10
+ imports?: any[];
11
+ providers?: Provider[];
12
+ singletons?: Provider[];
13
+ constructor(metadata: NgModuleMetadata, component?: any);
14
+ private init;
15
+ /**
16
+ * Analyze NgModule Metadata
17
+ *
18
+ * - Removes Restricted Imports
19
+ * - Extracts providers from ModuleWithProviders
20
+ * - Flattens imports
21
+ * - Returns a new NgModuleMetadata object
22
+ *
23
+ *
24
+ */
25
+ private analyzeMetadata;
26
+ static analyzeRestricted: (ngModule: NgModule) => (boolean | Provider[])[];
27
+ static analyzeDecorators: (component: any) => {
28
+ isDeclarable: boolean;
29
+ isStandalone: boolean;
30
+ };
31
+ static isDecoratorInstanceOf: (decorator: any, name: string) => boolean;
32
+ }
@@ -1,17 +1,78 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractDeclarations = exports.extractSingletons = exports.extractProviders = exports.extractImports = exports.analyzeMetadata = exports.REMOVED_MODULES = void 0;
4
+ exports.PropertyExtractor = exports.uniqueArray = exports.REMOVED_MODULES = exports.reflectionCapabilities = void 0;
4
5
  const common_1 = require("@angular/common");
5
- const http_1 = require("@angular/common/http");
6
6
  const core_1 = require("@angular/core");
7
7
  const platform_browser_1 = require("@angular/platform-browser");
8
8
  const animations_1 = require("@angular/platform-browser/animations");
9
- const NgComponentAnalyzer_1 = require("./NgComponentAnalyzer");
10
9
  const NgModulesAnalyzer_1 = require("./NgModulesAnalyzer");
10
+ exports.reflectionCapabilities = new core_1.ɵReflectionCapabilities();
11
+ exports.REMOVED_MODULES = new core_1.InjectionToken('REMOVED_MODULES');
11
12
  const uniqueArray = (arr) => {
12
- return arr.flat(Number.MAX_VALUE).filter((value, index, self) => self.indexOf(value) === index);
13
+ return arr
14
+ .flat(Number.MAX_VALUE)
15
+ .filter(Boolean)
16
+ .filter((value, index, self) => self.indexOf(value) === index);
13
17
  };
14
- const analyzeRestricted = (ngModule) => {
18
+ exports.uniqueArray = uniqueArray;
19
+ class PropertyExtractor {
20
+ /* eslint-enable @typescript-eslint/lines-between-class-members */
21
+ constructor(metadata, component) {
22
+ this.metadata = metadata;
23
+ this.component = component;
24
+ /* eslint-disable @typescript-eslint/lines-between-class-members */
25
+ this.declarations = [];
26
+ /**
27
+ * Analyze NgModule Metadata
28
+ *
29
+ * - Removes Restricted Imports
30
+ * - Extracts providers from ModuleWithProviders
31
+ * - Flattens imports
32
+ * - Returns a new NgModuleMetadata object
33
+ *
34
+ *
35
+ */
36
+ this.analyzeMetadata = (metadata) => {
37
+ const declarations = [...(metadata?.declarations || [])];
38
+ const providers = [...(metadata?.providers || [])];
39
+ const singletons = [...(metadata?.singletons || [])];
40
+ const imports = [...(metadata?.imports || [])].reduce((acc, imported) => {
41
+ // remove ngModule and use only its providers if it is restricted
42
+ // (e.g. BrowserModule, BrowserAnimationsModule, NoopAnimationsModule, ...etc)
43
+ const [isRestricted, restrictedProviders] = PropertyExtractor.analyzeRestricted(imported);
44
+ if (isRestricted) {
45
+ singletons.unshift(restrictedProviders || []);
46
+ return acc;
47
+ }
48
+ acc.push(imported);
49
+ return acc;
50
+ }, []);
51
+ return { ...metadata, imports, providers, singletons, declarations };
52
+ };
53
+ this.init();
54
+ }
55
+ init() {
56
+ const analyzed = this.analyzeMetadata(this.metadata);
57
+ this.imports = (0, exports.uniqueArray)([common_1.CommonModule, analyzed.imports]);
58
+ this.providers = (0, exports.uniqueArray)(analyzed.providers);
59
+ this.singletons = (0, exports.uniqueArray)(analyzed.singletons);
60
+ this.declarations = (0, exports.uniqueArray)(analyzed.declarations);
61
+ if (this.component) {
62
+ const { isDeclarable, isStandalone } = PropertyExtractor.analyzeDecorators(this.component);
63
+ const isDeclared = (0, NgModulesAnalyzer_1.isComponentAlreadyDeclared)(this.component, analyzed.declarations, this.imports);
64
+ if (isStandalone) {
65
+ this.imports.push(this.component);
66
+ }
67
+ else if (isDeclarable && !isDeclared) {
68
+ this.declarations.push(this.component);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ exports.PropertyExtractor = PropertyExtractor;
74
+ _a = PropertyExtractor;
75
+ PropertyExtractor.analyzeRestricted = (ngModule) => {
15
76
  /**
16
77
  * BrowserModule is restricted,
17
78
  * because bootstrapApplication API, which mounts the component to the DOM,
@@ -36,124 +97,40 @@ const analyzeRestricted = (ngModule) => {
36
97
  if (ngModule === animations_1.NoopAnimationsModule) {
37
98
  return [true, (0, animations_1.provideNoopAnimations)()];
38
99
  }
39
- /**
40
- * HttpClient has to be provided manually as a singleton
41
- */
42
- if (ngModule === http_1.HttpClientModule) {
43
- return [true, (0, http_1.provideHttpClient)()];
44
- }
45
100
  return [false];
46
101
  };
47
- exports.REMOVED_MODULES = new core_1.InjectionToken('REMOVED_MODULES');
48
- /**
49
- * Analyze NgModule Metadata
50
- *
51
- * - Removes Restricted Imports
52
- * - Extracts providers from ModuleWithProviders
53
- * - Flattens imports
54
- * - Returns a new NgModuleMetadata object
55
- *
56
- *
57
- */
58
- const analyzeMetadata = (metadata) => {
59
- const declarations = [...(metadata?.declarations || [])];
60
- const providers = [...(metadata?.providers || [])];
61
- const singletons = [];
62
- const imports = [...(metadata?.imports || [])]
63
- .reduce((acc, ngModule) => {
64
- // remove ngModule and use only its providers if it is restricted
65
- // (e.g. BrowserModule, BrowserAnimationsModule, NoopAnimationsModule, ...etc)
66
- const [isRestricted, restrictedProviders] = analyzeRestricted(ngModule);
67
- if (isRestricted) {
68
- singletons.unshift(restrictedProviders || []);
69
- return acc;
70
- }
71
- // destructure into ngModule & providers if it is a ModuleWithProviders
72
- if (ngModule?.providers) {
73
- providers.unshift(ngModule.providers || []);
74
- // eslint-disable-next-line no-param-reassign
75
- ngModule = ngModule.ngModule;
76
- }
77
- // extract providers, declarations, singletons from ngModule
78
- // eslint-disable-next-line no-underscore-dangle
79
- const ngMetadata = ngModule?.__annotations__?.[0];
80
- if (ngMetadata) {
81
- const newMetadata = (0, exports.analyzeMetadata)(ngMetadata);
82
- acc.unshift(...newMetadata.imports);
83
- providers.unshift(...newMetadata.providers);
84
- singletons.unshift(...newMetadata.singletons);
85
- declarations.unshift(...newMetadata.declarations);
86
- if (ngMetadata.standalone === true) {
87
- acc.push(ngModule);
88
- }
89
- // keeping a copy of the removed module
90
- providers.push({ provide: exports.REMOVED_MODULES, useValue: ngModule, multi: true });
91
- return acc;
92
- }
93
- // include Angular official modules as-is
94
- if (ngModule.ɵmod) {
95
- acc.push(ngModule);
96
- return acc;
97
- }
98
- return acc;
99
- }, [])
100
- .flat(Number.MAX_VALUE);
101
- return { ...metadata, imports, providers, singletons, declarations };
102
- };
103
- exports.analyzeMetadata = analyzeMetadata;
104
- /**
105
- * Extract Imports from NgModule
106
- *
107
- * CommonModule is always imported
108
- * Only standalone components are imported
109
- *
110
- */
111
- const extractImports = (metadata, storyComponent) => {
112
- const { imports } = (0, exports.analyzeMetadata)(metadata);
113
- if ((0, NgComponentAnalyzer_1.isStandaloneComponent)(storyComponent)) {
114
- imports.push(storyComponent);
115
- }
116
- return uniqueArray([common_1.CommonModule, imports]);
117
- };
118
- exports.extractImports = extractImports;
119
- /**
120
- * Extract providers from NgModule
121
- *
122
- * - A new array is returned with:
123
- * - metadata.providers
124
- * - providers from each **ModuleWithProviders** (e.g. forRoot() & forChild() )
125
- *
126
- *
127
- */
128
- const extractProviders = (metadata) => {
129
- const { providers } = (0, exports.analyzeMetadata)(metadata);
130
- return uniqueArray(providers);
102
+ PropertyExtractor.analyzeDecorators = (component) => {
103
+ const decorators = exports.reflectionCapabilities.annotations(component);
104
+ const isComponent = decorators.some((d) => _a.isDecoratorInstanceOf(d, 'Component'));
105
+ const isDirective = decorators.some((d) => _a.isDecoratorInstanceOf(d, 'Directive'));
106
+ const isPipe = decorators.some((d) => _a.isDecoratorInstanceOf(d, 'Pipe'));
107
+ const isDeclarable = isComponent || isDirective || isPipe;
108
+ const isStandalone = isComponent && decorators.some((d) => d.standalone);
109
+ return { isDeclarable, isStandalone };
131
110
  };
132
- exports.extractProviders = extractProviders;
133
- const extractSingletons = (metadata) => {
134
- const { singletons } = (0, exports.analyzeMetadata)(metadata);
135
- return uniqueArray(singletons);
136
- };
137
- exports.extractSingletons = extractSingletons;
138
- /**
139
- * Extract declarations from NgModule
140
- *
141
- * - If a story component is provided, it will be added to the declarations array if:
142
- * - It is a component or directive or pipe
143
- * - It is not already declared
144
- * - It is not a standalone component
145
- *
146
- */
147
- const extractDeclarations = (metadata, storyComponent) => {
148
- const { declarations } = (0, exports.analyzeMetadata)(metadata);
149
- if (storyComponent) {
150
- const isStandalone = (0, NgComponentAnalyzer_1.isStandaloneComponent)(storyComponent);
151
- const isDeclared = (0, NgModulesAnalyzer_1.isComponentAlreadyDeclared)(storyComponent, declarations, metadata.imports);
152
- const requiresDeclaration = (0, NgComponentAnalyzer_1.isDeclarable)(storyComponent) && !isDeclared && !isStandalone;
153
- if (requiresDeclaration) {
154
- declarations.push(storyComponent);
155
- }
111
+ PropertyExtractor.isDecoratorInstanceOf = (decorator, name) => {
112
+ let factory;
113
+ switch (name) {
114
+ case 'Component':
115
+ factory = core_1.Component;
116
+ break;
117
+ case 'Directive':
118
+ factory = core_1.Directive;
119
+ break;
120
+ case 'Pipe':
121
+ factory = core_1.Pipe;
122
+ break;
123
+ case 'Injectable':
124
+ factory = core_1.Injectable;
125
+ break;
126
+ case 'Input':
127
+ factory = core_1.Input;
128
+ break;
129
+ case 'Output':
130
+ factory = core_1.Output;
131
+ break;
132
+ default:
133
+ throw new Error(`Unknown decorator type: ${name}`);
156
134
  }
157
- return uniqueArray(declarations);
135
+ return decorator instanceof factory || decorator.ngMetadataName === name;
158
136
  };
159
- exports.extractDeclarations = extractDeclarations;
@@ -4,7 +4,6 @@ const common_1 = require("@angular/common");
4
4
  const core_1 = require("@angular/core");
5
5
  const platform_browser_1 = require("@angular/platform-browser");
6
6
  const animations_1 = require("@angular/platform-browser/animations");
7
- const http_1 = require("@angular/common/http");
8
7
  const PropertyExtractor_1 = require("./PropertyExtractor");
9
8
  const test_module_1 = require("../__testfixtures__/test.module");
10
9
  const TEST_TOKEN = new core_1.InjectionToken('testToken');
@@ -26,14 +25,33 @@ const TestModuleWithImportsAndProviders = (0, core_1.NgModule)({
26
25
  providers: [TestTokenProvider],
27
26
  })(class {
28
27
  });
28
+ const analyzeMetadata = (metadata, component) => {
29
+ return new PropertyExtractor_1.PropertyExtractor(metadata, component);
30
+ };
31
+ const extractImports = (metadata, component) => {
32
+ const { imports } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
33
+ return imports;
34
+ };
35
+ const extractDeclarations = (metadata, component) => {
36
+ const { declarations } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
37
+ return declarations;
38
+ };
39
+ const extractProviders = (metadata, component) => {
40
+ const { providers } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
41
+ return providers;
42
+ };
43
+ const extractSingletons = (metadata, component) => {
44
+ const { singletons } = new PropertyExtractor_1.PropertyExtractor(metadata, component);
45
+ return singletons;
46
+ };
29
47
  describe('PropertyExtractor', () => {
30
48
  describe('analyzeMetadata', () => {
31
49
  it('should remove BrowserModule', () => {
32
50
  const metadata = {
33
51
  imports: [platform_browser_1.BrowserModule],
34
52
  };
35
- const { imports, providers, singletons } = (0, PropertyExtractor_1.analyzeMetadata)(metadata);
36
- expect(imports.flat(Number.MAX_VALUE)).toEqual([]);
53
+ const { imports, providers, singletons } = analyzeMetadata(metadata);
54
+ expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
37
55
  expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
38
56
  expect(singletons.flat(Number.MAX_VALUE)).toEqual([]);
39
57
  });
@@ -41,8 +59,8 @@ describe('PropertyExtractor', () => {
41
59
  const metadata = {
42
60
  imports: [animations_1.BrowserAnimationsModule],
43
61
  };
44
- const { imports, providers, singletons } = (0, PropertyExtractor_1.analyzeMetadata)(metadata);
45
- expect(imports.flat(Number.MAX_VALUE)).toEqual([]);
62
+ const { imports, providers, singletons } = analyzeMetadata(metadata);
63
+ expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
46
64
  expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
47
65
  expect(singletons.flat(Number.MAX_VALUE)).toEqual((0, animations_1.provideAnimations)());
48
66
  });
@@ -50,127 +68,71 @@ describe('PropertyExtractor', () => {
50
68
  const metadata = {
51
69
  imports: [animations_1.NoopAnimationsModule],
52
70
  };
53
- const { imports, providers, singletons } = (0, PropertyExtractor_1.analyzeMetadata)(metadata);
54
- expect(imports.flat(Number.MAX_VALUE)).toEqual([]);
71
+ const { imports, providers, singletons } = analyzeMetadata(metadata);
72
+ expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
55
73
  expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
56
74
  expect(singletons.flat(Number.MAX_VALUE)).toEqual((0, animations_1.provideNoopAnimations)());
57
75
  });
58
76
  it('should remove Browser/Animations modules recursively', () => {
59
77
  const metadata = {
60
- imports: [test_module_1.WithAnimationsModule],
78
+ imports: [animations_1.BrowserAnimationsModule, platform_browser_1.BrowserModule],
61
79
  };
62
- const { imports, providers, singletons } = (0, PropertyExtractor_1.analyzeMetadata)(metadata);
63
- expect(imports.flat(Number.MAX_VALUE)).toEqual([]);
64
- expect(providers.flat(Number.MAX_VALUE)).toEqual([
65
- { provide: PropertyExtractor_1.REMOVED_MODULES, useValue: test_module_1.WithAnimationsModule, multi: true },
66
- ]);
80
+ const { imports, providers, singletons } = analyzeMetadata(metadata);
81
+ expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule]);
82
+ expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
67
83
  expect(singletons.flat(Number.MAX_VALUE)).toEqual((0, animations_1.provideAnimations)());
68
84
  });
69
85
  it('should not destructure Angular official module', () => {
70
86
  const metadata = {
71
87
  imports: [test_module_1.WithOfficialModule],
72
88
  };
73
- const { imports, providers, singletons } = (0, PropertyExtractor_1.analyzeMetadata)(metadata);
74
- expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule, http_1.HttpClientModule]);
75
- expect(providers.flat(Number.MAX_VALUE)).toEqual([
76
- { provide: PropertyExtractor_1.REMOVED_MODULES, useValue: test_module_1.WithOfficialModule, multi: true },
77
- ]);
89
+ const { imports, providers, singletons } = analyzeMetadata(metadata);
90
+ expect(imports.flat(Number.MAX_VALUE)).toEqual([common_1.CommonModule, test_module_1.WithOfficialModule]);
91
+ expect(providers.flat(Number.MAX_VALUE)).toEqual([]);
78
92
  expect(singletons.flat(Number.MAX_VALUE)).toEqual([]);
79
93
  });
80
94
  });
81
95
  describe('extractImports', () => {
82
96
  it('should return Angular official modules', () => {
83
- const imports = (0, PropertyExtractor_1.extractImports)({ imports: [TestModuleWithImportsAndProviders] });
84
- expect(imports).toEqual([common_1.CommonModule]);
97
+ const imports = extractImports({ imports: [TestModuleWithImportsAndProviders] });
98
+ expect(imports).toEqual([common_1.CommonModule, TestModuleWithImportsAndProviders]);
85
99
  });
86
100
  it('should return standalone components', () => {
87
- const imports = (0, PropertyExtractor_1.extractImports)({
101
+ const imports = extractImports({
88
102
  imports: [TestModuleWithImportsAndProviders],
89
103
  }, StandaloneTestComponent);
90
- expect(imports).toEqual([common_1.CommonModule, StandaloneTestComponent]);
91
- });
92
- it('should not return any regular modules (they get destructured)', () => {
93
- const imports = (0, PropertyExtractor_1.extractImports)({
94
- imports: [
95
- TestModuleWithDeclarations,
96
- { ngModule: TestModuleWithImportsAndProviders, providers: [] },
97
- ],
98
- });
99
- expect(imports).toEqual([common_1.CommonModule]);
104
+ expect(imports).toEqual([
105
+ common_1.CommonModule,
106
+ TestModuleWithImportsAndProviders,
107
+ StandaloneTestComponent,
108
+ ]);
100
109
  });
101
110
  });
102
111
  describe('extractDeclarations', () => {
103
112
  it('should return an array of declarations that contains `storyComponent`', () => {
104
- const declarations = (0, PropertyExtractor_1.extractDeclarations)({ declarations: [TestComponent1] }, TestComponent2);
113
+ const declarations = extractDeclarations({ declarations: [TestComponent1] }, TestComponent2);
105
114
  expect(declarations).toEqual([TestComponent1, TestComponent2]);
106
115
  });
107
- it('should ignore `storyComponent` if it is already declared', () => {
108
- const declarations = (0, PropertyExtractor_1.extractDeclarations)({
109
- imports: [TestModuleWithImportsAndProviders],
110
- declarations: [TestComponent2, StandaloneTestComponent, TestDirective],
111
- }, TestComponent1);
112
- expect(declarations).toEqual([
113
- TestComponent1,
114
- TestComponent2,
115
- StandaloneTestComponent,
116
- TestDirective,
117
- ]);
118
- });
119
- it('should ignore `storyComponent` if it is standalone', () => {
120
- const declarations = (0, PropertyExtractor_1.extractDeclarations)({
121
- imports: [TestModuleWithImportsAndProviders],
122
- declarations: [TestComponent1, TestComponent2, TestDirective],
123
- }, StandaloneTestComponent);
124
- expect(declarations).toEqual([TestComponent1, TestComponent2, TestDirective]);
116
+ });
117
+ describe('analyzeDecorators', () => {
118
+ it('isStandalone should be false', () => {
119
+ const { isStandalone } = PropertyExtractor_1.PropertyExtractor.analyzeDecorators(TestComponent1);
120
+ expect(isStandalone).toBe(false);
125
121
  });
126
- it('should ignore `storyComponent` if it is not a component/directive/pipe', () => {
127
- const declarations = (0, PropertyExtractor_1.extractDeclarations)({
128
- imports: [TestModuleWithImportsAndProviders],
129
- declarations: [TestComponent1, TestComponent2, StandaloneTestComponent],
130
- }, TestService);
131
- expect(declarations).toEqual([TestComponent1, TestComponent2, StandaloneTestComponent]);
122
+ it('isStandalone should be true', () => {
123
+ const { isStandalone } = PropertyExtractor_1.PropertyExtractor.analyzeDecorators(StandaloneTestComponent);
124
+ expect(isStandalone).toBe(true);
132
125
  });
133
126
  });
134
127
  describe('extractProviders', () => {
135
128
  it('should return an array of providers', () => {
136
- const providers = (0, PropertyExtractor_1.extractProviders)({
129
+ const providers = extractProviders({
137
130
  providers: [TestService],
138
131
  });
139
132
  expect(providers).toEqual([TestService]);
140
133
  });
141
- it('should return an array of providers extracted from ModuleWithProviders', () => {
142
- const providers = (0, PropertyExtractor_1.extractProviders)({
143
- imports: [{ ngModule: TestModuleWithImportsAndProviders, providers: [TestService] }],
144
- });
145
- expect(providers).toEqual([
146
- { provide: TEST_TOKEN, useValue: 123 },
147
- { provide: PropertyExtractor_1.REMOVED_MODULES, useValue: TestModuleWithDeclarations, multi: true },
148
- TestService,
149
- { provide: PropertyExtractor_1.REMOVED_MODULES, useValue: TestModuleWithImportsAndProviders, multi: true },
150
- ]);
151
- });
152
- it('should return an array of unique providers', () => {
153
- const providers = (0, PropertyExtractor_1.extractProviders)({
154
- imports: [{ ngModule: TestModuleWithImportsAndProviders, providers: [TestService] }],
155
- providers: [TestService, { provide: TEST_TOKEN, useValue: 123 }],
156
- });
157
- expect(providers).toEqual([
158
- { provide: TEST_TOKEN, useValue: 123 },
159
- { provide: PropertyExtractor_1.REMOVED_MODULES, useValue: TestModuleWithDeclarations, multi: true },
160
- TestService,
161
- {
162
- provide: new core_1.InjectionToken('testToken'),
163
- useValue: 123,
164
- },
165
- {
166
- provide: PropertyExtractor_1.REMOVED_MODULES,
167
- useValue: TestModuleWithImportsAndProviders,
168
- multi: true,
169
- },
170
- ]);
171
- });
172
134
  it('should return an array of singletons extracted', () => {
173
- const singeltons = (0, PropertyExtractor_1.extractSingletons)({
135
+ const singeltons = extractSingletons({
174
136
  imports: [animations_1.BrowserAnimationsModule],
175
137
  });
176
138
  expect(singeltons).toEqual((0, animations_1.provideAnimations)());
@@ -2,5 +2,5 @@ import './globals';
2
2
  export { render, renderToCanvas } from './render';
3
3
  export { decorateStory as applyDecorators } from './decorateStory';
4
4
  export declare const parameters: {
5
- framework: "angular";
5
+ renderer: "angular";
6
6
  };
@@ -7,4 +7,4 @@ Object.defineProperty(exports, "render", { enumerable: true, get: function () {
7
7
  Object.defineProperty(exports, "renderToCanvas", { enumerable: true, get: function () { return render_1.renderToCanvas; } });
8
8
  var decorateStory_1 = require("./decorateStory");
9
9
  Object.defineProperty(exports, "applyDecorators", { enumerable: true, get: function () { return decorateStory_1.decorateStory; } });
10
- exports.parameters = { framework: 'angular' };
10
+ exports.parameters = { renderer: 'angular' };
@@ -22,15 +22,15 @@ const core_client_1 = require("@storybook/core-client");
22
22
  const render_1 = require("./render");
23
23
  const decorateStory_1 = __importDefault(require("./decorateStory"));
24
24
  __exportStar(require("./public-types"), exports);
25
- const FRAMEWORK = 'angular';
25
+ const RENDERER = 'angular';
26
26
  const api = (0, core_client_1.start)(render_1.renderToCanvas, { decorateStory: decorateStory_1.default, render: render_1.render });
27
27
  const storiesOf = (kind, m) => {
28
28
  return api.clientApi.storiesOf(kind, m).addParameters({
29
- framework: FRAMEWORK,
29
+ renderer: RENDERER,
30
30
  });
31
31
  };
32
32
  exports.storiesOf = storiesOf;
33
- const configure = (...args) => api.configure(FRAMEWORK, ...args);
33
+ const configure = (...args) => api.configure(RENDERER, ...args);
34
34
  exports.configure = configure;
35
35
  exports.forceReRender = api.forceReRender;
36
36
  exports.raw = api.clientApi.raw;
@@ -5,6 +5,7 @@ export interface NgModuleMetadata {
5
5
  imports?: any[];
6
6
  schemas?: any[];
7
7
  providers?: any[];
8
+ singletons?: any[];
8
9
  }
9
10
  export interface ICollection {
10
11
  [p: string]: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/angular",
3
- "version": "7.0.0-beta.50",
3
+ "version": "7.0.0-beta.52",
4
4
  "description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -36,20 +36,20 @@
36
36
  "prep": "../../../scripts/prepare/tsc.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@storybook/builder-webpack5": "7.0.0-beta.50",
40
- "@storybook/cli": "7.0.0-beta.50",
41
- "@storybook/client-logger": "7.0.0-beta.50",
42
- "@storybook/core-client": "7.0.0-beta.50",
43
- "@storybook/core-common": "7.0.0-beta.50",
44
- "@storybook/core-events": "7.0.0-beta.50",
45
- "@storybook/core-server": "7.0.0-beta.50",
46
- "@storybook/core-webpack": "7.0.0-beta.50",
47
- "@storybook/docs-tools": "7.0.0-beta.50",
39
+ "@storybook/builder-webpack5": "7.0.0-beta.52",
40
+ "@storybook/cli": "7.0.0-beta.52",
41
+ "@storybook/client-logger": "7.0.0-beta.52",
42
+ "@storybook/core-client": "7.0.0-beta.52",
43
+ "@storybook/core-common": "7.0.0-beta.52",
44
+ "@storybook/core-events": "7.0.0-beta.52",
45
+ "@storybook/core-server": "7.0.0-beta.52",
46
+ "@storybook/core-webpack": "7.0.0-beta.52",
47
+ "@storybook/docs-tools": "7.0.0-beta.52",
48
48
  "@storybook/global": "^5.0.0",
49
- "@storybook/manager-api": "7.0.0-beta.50",
50
- "@storybook/node-logger": "7.0.0-beta.50",
51
- "@storybook/preview-api": "7.0.0-beta.50",
52
- "@storybook/types": "7.0.0-beta.50",
49
+ "@storybook/manager-api": "7.0.0-beta.52",
50
+ "@storybook/node-logger": "7.0.0-beta.52",
51
+ "@storybook/preview-api": "7.0.0-beta.52",
52
+ "@storybook/types": "7.0.0-beta.52",
53
53
  "@types/node": "^16.0.0",
54
54
  "@types/react": "^16.14.34",
55
55
  "@types/react-dom": "^16.9.14",
@@ -123,5 +123,5 @@
123
123
  "bundler": {
124
124
  "tsConfig": "tsconfig.build.json"
125
125
  },
126
- "gitHead": "ecbe308bda919d3cc60188dbb17dc4511f6b7a0e"
126
+ "gitHead": "1f559ed69a4fdd8eeb88e4190b16a8932104908e"
127
127
  }
@@ -0,0 +1,34 @@
1
+ import { moduleMetadata, Meta } from '@storybook/angular';
2
+ import { APP_INITIALIZER } from '@angular/core';
3
+ import { action } from '@storybook/addon-actions';
4
+ import Button from '../../button.component';
5
+
6
+ const meta: Meta<Button> = {
7
+ component: Button,
8
+ render: (args) => ({
9
+ props: {
10
+ ...args,
11
+ },
12
+ }),
13
+ decorators: [
14
+ moduleMetadata({
15
+ providers: [
16
+ {
17
+ provide: APP_INITIALIZER,
18
+ useFactory: () => {
19
+ return action('APP_INITIALIZER useFactory called successfully');
20
+ },
21
+ multi: true,
22
+ },
23
+ ],
24
+ }),
25
+ ],
26
+ };
27
+
28
+ export default meta;
29
+
30
+ export const Default = {
31
+ args: {
32
+ text: 'Button',
33
+ },
34
+ };