@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.
- package/README.md +66 -0
- package/dist/builders/build-storybook/index.d.ts +5 -3
- package/dist/builders/build-storybook/index.js +7 -3
- package/dist/builders/build-storybook/schema.json +14 -6
- package/dist/builders/start-storybook/index.d.ts +5 -3
- package/dist/builders/start-storybook/index.js +9 -5
- package/dist/builders/start-storybook/schema.json +10 -5
- package/dist/builders/utils/run-compodoc.js +11 -27
- package/dist/builders/utils/run-compodoc.spec.js +42 -0
- package/dist/builders/utils/standalone-options.d.ts +2 -2
- package/dist/client/angular-beta/AbstractRenderer.d.ts +3 -3
- package/dist/client/angular-beta/AbstractRenderer.js +25 -32
- package/dist/client/angular-beta/CanvasRenderer.js +1 -1
- package/dist/client/angular-beta/DocsRenderer.js +5 -3
- package/dist/client/angular-beta/RendererFactory.js +5 -4
- package/dist/client/angular-beta/StorybookModule.d.ts +3 -6
- package/dist/client/angular-beta/StorybookModule.js +4 -45
- package/dist/client/angular-beta/StorybookModule.test.js +51 -36
- package/dist/client/angular-beta/StorybookWrapperComponent.d.ts +3 -2
- package/dist/client/angular-beta/StorybookWrapperComponent.js +30 -2
- package/dist/client/angular-beta/__testfixtures__/test.module.d.ts +4 -0
- package/dist/client/angular-beta/__testfixtures__/test.module.js +34 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.js +1 -1
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.js +43 -5
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.d.ts +1 -1
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.js +4 -4
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.js +3 -3
- package/dist/client/angular-beta/utils/PropertyExtractor.d.ts +50 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.js +149 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.d.ts +1 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.js +179 -0
- package/dist/client/decorateStory.js +1 -1
- package/dist/client/docs/compodoc.js +5 -7
- package/dist/client/docs/config.js +1 -2
- package/dist/client/globals.d.ts +0 -8
- package/dist/client/globals.js +2 -29
- package/dist/client/render.d.ts +1 -0
- package/dist/client/render.js +1 -5
- package/dist/client/types.d.ts +0 -2
- package/dist/index.mjs +13 -0
- package/dist/preset.mjs +26 -0
- package/dist/renderer.d.ts +2 -1
- package/dist/renderer.js +4 -2
- package/dist/renderer.mjs +5 -0
- package/dist/server/framework-preset-angular-cli.d.ts +2 -1
- package/dist/server/framework-preset-angular-cli.js +21 -92
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.js +15 -13
- package/dist/server/preset-options.d.ts +3 -2
- package/dist/types.mjs +1 -0
- package/jest.config.js +19 -0
- package/package.json +46 -45
- package/template/cli/Button.stories.ts +1 -1
- package/template/cli/Header.stories.ts +2 -2
- package/template/cli/button.component.ts +2 -0
- package/template/components/index.js +2 -2
- package/template/stories/angular-mdx.stories.mdx +1 -1
- package/template/stories/basics/component-without-selector/without-selector-ng-component-outlet.stories.ts +1 -1
- package/template/stories/basics/component-without-selector/without-selector-ng-factory-resolver.stories.ts +1 -1
- package/template/stories/basics/component-without-selector/without-selector.stories.ts +1 -1
- package/template/stories/basics/ng-module/import-module-chip.stories.ts +23 -0
- package/template/stories/basics/ng-module/import-module.stories.ts +2 -13
- package/template/stories/core/decorators/componentWrapperDecorator/decorators.stories.ts +0 -18
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.css +13 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.html +7 -0
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.ts +39 -0
- package/template/stories/core/moduleMetadata/with-browser-animations.stories.ts +30 -0
- package/template/stories/core/moduleMetadata/with-noop-browser-animations.stories.ts +27 -0
- package/template/stories/core/parameters/bootstrap-options.stories.ts +1 -5
- package/dist/client/angular/helpers.d.ts +0 -8
- package/dist/client/angular/helpers.js +0 -150
- package/dist/server/angular-read-workspace.d.ts +0 -13
- package/dist/server/angular-read-workspace.js +0 -78
- package/dist/server/utils/normalize-asset-patterns.d.ts +0 -7
- package/dist/server/utils/normalize-asset-patterns.js +0 -64
- package/dist/server/utils/normalize-optimization.d.ts +0 -3
- package/dist/server/utils/normalize-optimization.js +0 -21
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Meta, StoryFn } from '@storybook/angular';
|
|
2
|
+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|
3
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
4
|
+
import { expect } from '@storybook/jest';
|
|
5
|
+
import { OpenCloseComponent } from './angular-src/open-close-component/open-close.component';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
component: OpenCloseComponent,
|
|
9
|
+
} as Meta;
|
|
10
|
+
|
|
11
|
+
export const WithNoopBrowserAnimations: StoryFn = () => ({
|
|
12
|
+
template: `<app-open-close></app-open-close>`,
|
|
13
|
+
moduleMetadata: {
|
|
14
|
+
declarations: [OpenCloseComponent],
|
|
15
|
+
imports: [NoopAnimationsModule],
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
WithNoopBrowserAnimations.play = async ({ canvasElement }) => {
|
|
20
|
+
const canvas = within(canvasElement);
|
|
21
|
+
const opened = canvas.getByText('The box is now Open!');
|
|
22
|
+
expect(opened).toBeDefined();
|
|
23
|
+
const submitButton = canvas.getByRole('button');
|
|
24
|
+
await userEvent.click(submitButton);
|
|
25
|
+
const closed = canvas.getByText('The box is now Closed!');
|
|
26
|
+
expect(closed).toBeDefined();
|
|
27
|
+
};
|
|
@@ -3,6 +3,7 @@ import { Component } from '@angular/core';
|
|
|
3
3
|
|
|
4
4
|
@Component({
|
|
5
5
|
selector: 'component-with-whitespace',
|
|
6
|
+
preserveWhitespaces: true,
|
|
6
7
|
template: ` <div>
|
|
7
8
|
<p>Some content</p>
|
|
8
9
|
</div>`,
|
|
@@ -12,11 +13,6 @@ class ComponentWithWhitespace {}
|
|
|
12
13
|
export default {
|
|
13
14
|
// title: 'Core / Parameters / With Bootstrap Options',
|
|
14
15
|
component: ComponentWithWhitespace,
|
|
15
|
-
parameters: {
|
|
16
|
-
bootstrapOptions: {
|
|
17
|
-
preserveWhitespaces: true,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
16
|
} as Meta;
|
|
21
17
|
|
|
22
18
|
export const WithPreserveWhitespaces: StoryFn = (_args) => ({});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PartialStoryFn } from '@storybook/types';
|
|
2
|
-
import { AngularRenderer } from '../types';
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
NODE_ENV: 'string' | 'development' | undefined;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export declare const renderNgApp: (storyFn: PartialStoryFn<AngularRenderer>, forced: boolean) => void;
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renderNgApp = void 0;
|
|
7
|
-
const global_1 = __importDefault(require("global"));
|
|
8
|
-
const core_1 = require("@angular/core");
|
|
9
|
-
const forms_1 = require("@angular/forms");
|
|
10
|
-
const platform_browser_dynamic_1 = require("@angular/platform-browser-dynamic");
|
|
11
|
-
const platform_browser_1 = require("@angular/platform-browser");
|
|
12
|
-
const rxjs_1 = require("rxjs");
|
|
13
|
-
const app_component_1 = require("./app.component");
|
|
14
|
-
const app_token_1 = require("./app.token");
|
|
15
|
-
const { document } = global_1.default;
|
|
16
|
-
let platform = null;
|
|
17
|
-
let promises = [];
|
|
18
|
-
let storyData = new rxjs_1.ReplaySubject(1);
|
|
19
|
-
const moduleClass = class DynamicModule {
|
|
20
|
-
};
|
|
21
|
-
const componentClass = class DynamicComponent {
|
|
22
|
-
};
|
|
23
|
-
function storyDataFactory(data) {
|
|
24
|
-
return (ngZone) => new rxjs_1.Observable((subscriber) => {
|
|
25
|
-
const sub = data.subscribe((v) => {
|
|
26
|
-
ngZone.run(() => subscriber.next(v));
|
|
27
|
-
}, (err) => {
|
|
28
|
-
ngZone.run(() => subscriber.error(err));
|
|
29
|
-
}, () => {
|
|
30
|
-
ngZone.run(() => subscriber.complete());
|
|
31
|
-
});
|
|
32
|
-
return () => {
|
|
33
|
-
sub.unsubscribe();
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const getModule = (declarations, entryComponents, bootstrap, data, moduleMetadata) => {
|
|
38
|
-
// Complete last ReplaySubject and create a new one for the current module
|
|
39
|
-
storyData.complete();
|
|
40
|
-
storyData = new rxjs_1.ReplaySubject(1);
|
|
41
|
-
storyData.next(data);
|
|
42
|
-
const moduleMeta = {
|
|
43
|
-
declarations: [...declarations, ...(moduleMetadata.declarations || [])],
|
|
44
|
-
imports: [platform_browser_1.BrowserModule, forms_1.FormsModule, ...(moduleMetadata.imports || [])],
|
|
45
|
-
providers: [
|
|
46
|
-
{ provide: app_token_1.STORY, useFactory: storyDataFactory(storyData.asObservable()), deps: [core_1.NgZone] },
|
|
47
|
-
...(moduleMetadata.providers || []),
|
|
48
|
-
],
|
|
49
|
-
entryComponents: [...entryComponents, ...(moduleMetadata.entryComponents || [])],
|
|
50
|
-
schemas: [...(moduleMetadata.schemas || [])],
|
|
51
|
-
bootstrap: [...bootstrap],
|
|
52
|
-
};
|
|
53
|
-
return (0, core_1.NgModule)(moduleMeta)(moduleClass);
|
|
54
|
-
};
|
|
55
|
-
const createComponentFromTemplate = (template, styles) => {
|
|
56
|
-
return (0, core_1.Component)({
|
|
57
|
-
template,
|
|
58
|
-
styles,
|
|
59
|
-
})(componentClass);
|
|
60
|
-
};
|
|
61
|
-
const extractNgModuleMetadata = (importItem) => {
|
|
62
|
-
const target = importItem && importItem.ngModule ? importItem.ngModule : importItem;
|
|
63
|
-
const decoratorKey = '__annotations__';
|
|
64
|
-
const decorators = Reflect &&
|
|
65
|
-
Reflect.getOwnPropertyDescriptor &&
|
|
66
|
-
Reflect.getOwnPropertyDescriptor(target, decoratorKey)
|
|
67
|
-
? Reflect.getOwnPropertyDescriptor(target, decoratorKey).value
|
|
68
|
-
: target[decoratorKey];
|
|
69
|
-
if (!decorators || decorators.length === 0) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const ngModuleDecorator = decorators.find((decorator) => decorator instanceof core_1.NgModule);
|
|
73
|
-
if (!ngModuleDecorator) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
return ngModuleDecorator;
|
|
77
|
-
};
|
|
78
|
-
const getExistenceOfComponentInModules = (component, declarations, imports) => {
|
|
79
|
-
if (declarations && declarations.some((declaration) => declaration === component)) {
|
|
80
|
-
// Found component in declarations array
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
if (!imports) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
return imports.some((importItem) => {
|
|
87
|
-
const extractedNgModuleMetadata = extractNgModuleMetadata(importItem);
|
|
88
|
-
if (!extractedNgModuleMetadata) {
|
|
89
|
-
// Not an NgModule
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
return getExistenceOfComponentInModules(component, extractedNgModuleMetadata.declarations, extractedNgModuleMetadata.imports);
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
const initModule = (storyFn) => {
|
|
96
|
-
const storyObj = storyFn();
|
|
97
|
-
const { component, template, props, styles, moduleMetadata = {} } = storyObj;
|
|
98
|
-
const isCreatingComponentFromTemplate = Boolean(template);
|
|
99
|
-
const AnnotatedComponent = isCreatingComponentFromTemplate
|
|
100
|
-
? createComponentFromTemplate(template, styles)
|
|
101
|
-
: component;
|
|
102
|
-
const componentRequiresDeclaration = isCreatingComponentFromTemplate ||
|
|
103
|
-
!getExistenceOfComponentInModules(component, moduleMetadata.declarations, moduleMetadata.imports);
|
|
104
|
-
const componentDeclarations = componentRequiresDeclaration
|
|
105
|
-
? [app_component_1.AppComponent, AnnotatedComponent]
|
|
106
|
-
: [app_component_1.AppComponent];
|
|
107
|
-
const story = {
|
|
108
|
-
component: AnnotatedComponent,
|
|
109
|
-
props,
|
|
110
|
-
};
|
|
111
|
-
return getModule(componentDeclarations, [AnnotatedComponent], [app_component_1.AppComponent], story, moduleMetadata);
|
|
112
|
-
};
|
|
113
|
-
const staticRoot = document.getElementById('storybook-root');
|
|
114
|
-
const insertDynamicRoot = () => {
|
|
115
|
-
const app = document.createElement('storybook-dynamic-app-root');
|
|
116
|
-
staticRoot.innerHTML = '';
|
|
117
|
-
staticRoot.appendChild(app);
|
|
118
|
-
};
|
|
119
|
-
const draw = (newModule) => {
|
|
120
|
-
if (!platform) {
|
|
121
|
-
insertDynamicRoot();
|
|
122
|
-
if (typeof NODE_ENV === 'string' && NODE_ENV !== 'development') {
|
|
123
|
-
try {
|
|
124
|
-
(0, core_1.enableProdMode)();
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
//
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
platform = (0, platform_browser_dynamic_1.platformBrowserDynamic)();
|
|
131
|
-
promises.push(platform.bootstrapModule(newModule));
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
Promise.all(promises).then((modules) => {
|
|
135
|
-
modules.forEach((mod) => mod.destroy());
|
|
136
|
-
insertDynamicRoot();
|
|
137
|
-
promises = [];
|
|
138
|
-
promises.push(platform.bootstrapModule(newModule));
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
const renderNgApp = (storyFn, forced) => {
|
|
143
|
-
if (!forced) {
|
|
144
|
-
draw(initModule(storyFn));
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
storyData.next(storyFn());
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
exports.renderNgApp = renderNgApp;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { workspaces } from '@angular-devkit/core';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the workspace definition
|
|
4
|
-
*
|
|
5
|
-
* - Either from NX if it is present
|
|
6
|
-
* - Either from `@angular-devkit/core` -> https://github.com/angular/angular-cli/tree/master/packages/angular_devkit/core
|
|
7
|
-
*/
|
|
8
|
-
export declare const readAngularWorkspaceConfig: (dirToSearch: string) => Promise<workspaces.WorkspaceDefinition>;
|
|
9
|
-
export declare const getDefaultProjectName: (workspace: workspaces.WorkspaceDefinition) => string;
|
|
10
|
-
export declare const findAngularProjectTarget: (workspace: workspaces.WorkspaceDefinition, projectName: string, targetName: string) => {
|
|
11
|
-
project: workspaces.ProjectDefinition;
|
|
12
|
-
target: workspaces.TargetDefinition;
|
|
13
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findAngularProjectTarget = exports.getDefaultProjectName = exports.readAngularWorkspaceConfig = void 0;
|
|
4
|
-
/* eslint-disable global-require */
|
|
5
|
-
const node_1 = require("@angular-devkit/core/node");
|
|
6
|
-
const core_1 = require("@angular-devkit/core");
|
|
7
|
-
/**
|
|
8
|
-
* Returns the workspace definition
|
|
9
|
-
*
|
|
10
|
-
* - Either from NX if it is present
|
|
11
|
-
* - Either from `@angular-devkit/core` -> https://github.com/angular/angular-cli/tree/master/packages/angular_devkit/core
|
|
12
|
-
*/
|
|
13
|
-
const readAngularWorkspaceConfig = async (dirToSearch) => {
|
|
14
|
-
const host = core_1.workspaces.createWorkspaceHost(new node_1.NodeJsSyncHost());
|
|
15
|
-
try {
|
|
16
|
-
/**
|
|
17
|
-
* Apologies for the following line
|
|
18
|
-
* If there's a better way to do it, let's do it
|
|
19
|
-
*/
|
|
20
|
-
// catch if nx.json does not exist
|
|
21
|
-
require('@nrwl/workspace').readNxJson();
|
|
22
|
-
const nxWorkspace = require('@nrwl/workspace').readWorkspaceConfig({
|
|
23
|
-
format: 'angularCli',
|
|
24
|
-
path: dirToSearch,
|
|
25
|
-
});
|
|
26
|
-
// Use the workspace version of nx when angular looks for the angular.json file
|
|
27
|
-
host.readFile = (path) => {
|
|
28
|
-
if (typeof path === 'string' && path.endsWith('angular.json')) {
|
|
29
|
-
return Promise.resolve(JSON.stringify(nxWorkspace));
|
|
30
|
-
}
|
|
31
|
-
return host.readFile(path);
|
|
32
|
-
};
|
|
33
|
-
host.isFile = (path) => {
|
|
34
|
-
if (typeof path === 'string' && path.endsWith('angular.json')) {
|
|
35
|
-
return Promise.resolve(true);
|
|
36
|
-
}
|
|
37
|
-
return host.isFile(path);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
// Ignore if the client does not use NX
|
|
42
|
-
}
|
|
43
|
-
return (await core_1.workspaces.readWorkspace(dirToSearch, host)).workspace;
|
|
44
|
-
};
|
|
45
|
-
exports.readAngularWorkspaceConfig = readAngularWorkspaceConfig;
|
|
46
|
-
const getDefaultProjectName = (workspace) => {
|
|
47
|
-
const environmentProjectName = process.env.STORYBOOK_ANGULAR_PROJECT;
|
|
48
|
-
if (environmentProjectName) {
|
|
49
|
-
return environmentProjectName;
|
|
50
|
-
}
|
|
51
|
-
if (workspace.projects.has('storybook')) {
|
|
52
|
-
return 'storybook';
|
|
53
|
-
}
|
|
54
|
-
if (workspace.extensions.defaultProject) {
|
|
55
|
-
return workspace.extensions.defaultProject;
|
|
56
|
-
}
|
|
57
|
-
const firstProjectName = workspace.projects.keys().next().value;
|
|
58
|
-
if (firstProjectName) {
|
|
59
|
-
return firstProjectName;
|
|
60
|
-
}
|
|
61
|
-
throw new Error('No angular projects found');
|
|
62
|
-
};
|
|
63
|
-
exports.getDefaultProjectName = getDefaultProjectName;
|
|
64
|
-
const findAngularProjectTarget = (workspace, projectName, targetName) => {
|
|
65
|
-
if (!workspace.projects || !Object.keys(workspace.projects).length) {
|
|
66
|
-
throw new Error('No angular projects found');
|
|
67
|
-
}
|
|
68
|
-
const project = workspace.projects.get(projectName);
|
|
69
|
-
if (!project) {
|
|
70
|
-
throw new Error(`"${projectName}" project is not found in angular.json`);
|
|
71
|
-
}
|
|
72
|
-
if (!project.targets.has(targetName)) {
|
|
73
|
-
throw new Error(`"${targetName}" target is not found in "${projectName}" project`);
|
|
74
|
-
}
|
|
75
|
-
const target = project.targets.get(targetName);
|
|
76
|
-
return { project, target };
|
|
77
|
-
};
|
|
78
|
-
exports.findAngularProjectTarget = findAngularProjectTarget;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Path, BaseException } from '@angular-devkit/core';
|
|
2
|
-
import { AssetPattern } from '@angular-devkit/build-angular';
|
|
3
|
-
import { AssetPatternClass } from '@angular-devkit/build-angular/src/builders/browser/schema';
|
|
4
|
-
export declare class MissingAssetSourceRootException extends BaseException {
|
|
5
|
-
constructor(path: string);
|
|
6
|
-
}
|
|
7
|
-
export declare function normalizeAssetPatterns(assetPatterns: AssetPattern[], root: Path, projectRoot: Path, maybeSourceRoot: Path | undefined): AssetPatternClass[];
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeAssetPatterns = exports.MissingAssetSourceRootException = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Clone of `normalizeAssetPatterns` function from angular-cli v11.2.*
|
|
6
|
-
* > https://github.com/angular/angular-cli/blob/de63f41d669e42ada84f94ca1795d2791b9b45cc/packages/angular_devkit/build_angular/src/utils/normalize-asset-patterns.ts
|
|
7
|
-
*
|
|
8
|
-
* It is not possible to use the original because arguments have changed between version 6.1.* and 11.*.* of angular-cli
|
|
9
|
-
*/
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const core_1 = require("@angular-devkit/core");
|
|
12
|
-
class MissingAssetSourceRootException extends core_1.BaseException {
|
|
13
|
-
constructor(path) {
|
|
14
|
-
super(`The ${path} asset path must start with the project source root.`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.MissingAssetSourceRootException = MissingAssetSourceRootException;
|
|
18
|
-
function normalizeAssetPatterns(assetPatterns, root, projectRoot, maybeSourceRoot) {
|
|
19
|
-
// When sourceRoot is not available, we default to ${projectRoot}/src.
|
|
20
|
-
const sourceRoot = maybeSourceRoot || (0, core_1.join)(projectRoot, 'src');
|
|
21
|
-
const resolvedSourceRoot = (0, core_1.resolve)(root, sourceRoot);
|
|
22
|
-
if (assetPatterns.length === 0) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
return assetPatterns.map((assetPattern) => {
|
|
26
|
-
// Normalize string asset patterns to objects.
|
|
27
|
-
if (typeof assetPattern === 'string') {
|
|
28
|
-
const assetPath = (0, core_1.normalize)(assetPattern);
|
|
29
|
-
const resolvedAssetPath = (0, core_1.resolve)(root, assetPath);
|
|
30
|
-
// Check if the string asset is within sourceRoot.
|
|
31
|
-
if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
|
|
32
|
-
throw new MissingAssetSourceRootException(assetPattern);
|
|
33
|
-
}
|
|
34
|
-
let glob;
|
|
35
|
-
let input;
|
|
36
|
-
let isDirectory = false;
|
|
37
|
-
try {
|
|
38
|
-
isDirectory = (0, fs_1.statSync)((0, core_1.getSystemPath)(resolvedAssetPath)).isDirectory();
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
isDirectory = true;
|
|
42
|
-
}
|
|
43
|
-
if (isDirectory) {
|
|
44
|
-
// Folders get a recursive star glob.
|
|
45
|
-
glob = '**/*';
|
|
46
|
-
// Input directory is their original path.
|
|
47
|
-
input = assetPath;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Files are their own glob.
|
|
51
|
-
glob = (0, core_1.basename)(assetPath);
|
|
52
|
-
// Input directory is their original dirname.
|
|
53
|
-
input = (0, core_1.dirname)(assetPath);
|
|
54
|
-
}
|
|
55
|
-
// Output directory for both is the relative path from source root to input.
|
|
56
|
-
const output = (0, core_1.relative)(resolvedSourceRoot, (0, core_1.resolve)(root, input));
|
|
57
|
-
// Return the asset pattern in object format.
|
|
58
|
-
return { glob, input, output };
|
|
59
|
-
}
|
|
60
|
-
// It's already an AssetPatternObject, no need to convert.
|
|
61
|
-
return assetPattern;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
exports.normalizeAssetPatterns = normalizeAssetPatterns;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { OptimizationUnion } from '@angular-devkit/build-angular';
|
|
2
|
-
import { NormalizedOptimizationOptions } from '@angular-devkit/build-angular/src/utils/normalize-optimization';
|
|
3
|
-
export declare const normalizeOptimization: (options: OptimizationUnion) => NormalizedOptimizationOptions;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeOptimization = void 0;
|
|
4
|
-
const module_is_available_1 = require("./module-is-available");
|
|
5
|
-
const importAngularCliNormalizeOptimization = () => {
|
|
6
|
-
// First we look for webpack config according to directory structure of Angular
|
|
7
|
-
// present since the version 7.2.0
|
|
8
|
-
if ((0, module_is_available_1.moduleIsAvailable)('@angular-devkit/build-angular/src/utils/normalize-optimization')) {
|
|
9
|
-
// eslint-disable-next-line global-require
|
|
10
|
-
return require('@angular-devkit/build-angular/src/utils/normalize-optimization');
|
|
11
|
-
}
|
|
12
|
-
return undefined;
|
|
13
|
-
};
|
|
14
|
-
const normalizeOptimization = (options) => {
|
|
15
|
-
if (importAngularCliNormalizeOptimization()) {
|
|
16
|
-
return importAngularCliNormalizeOptimization().normalizeOptimization(options);
|
|
17
|
-
}
|
|
18
|
-
// Best effort to stay compatible with 6.1.*
|
|
19
|
-
return options;
|
|
20
|
-
};
|
|
21
|
-
exports.normalizeOptimization = normalizeOptimization;
|