@dugararchit/cdk 0.0.0-dugararchit
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/_index.scss +8 -0
- package/a11y/_index.import.scss +2 -0
- package/a11y/_index.scss +102 -0
- package/a11y/a11y-prebuilt.scss +3 -0
- package/fesm2022/stagefright5-cdk-a11y.mjs +2381 -0
- package/fesm2022/stagefright5-cdk-a11y.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-accordion.mjs +267 -0
- package/fesm2022/stagefright5-cdk-accordion.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-bidi.mjs +185 -0
- package/fesm2022/stagefright5-cdk-bidi.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-clipboard.mjs +250 -0
- package/fesm2022/stagefright5-cdk-clipboard.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-coercion.mjs +128 -0
- package/fesm2022/stagefright5-cdk-coercion.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-collections.mjs +472 -0
- package/fesm2022/stagefright5-cdk-collections.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-drag-drop.mjs +3690 -0
- package/fesm2022/stagefright5-cdk-drag-drop.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-keycodes.mjs +159 -0
- package/fesm2022/stagefright5-cdk-keycodes.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-layout.mjs +246 -0
- package/fesm2022/stagefright5-cdk-layout.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-observers.mjs +203 -0
- package/fesm2022/stagefright5-cdk-observers.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-overlay.mjs +3033 -0
- package/fesm2022/stagefright5-cdk-overlay.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-platform.mjs +375 -0
- package/fesm2022/stagefright5-cdk-platform.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-portal.mjs +672 -0
- package/fesm2022/stagefright5-cdk-portal.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-scrolling.mjs +1399 -0
- package/fesm2022/stagefright5-cdk-scrolling.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-stepper.mjs +624 -0
- package/fesm2022/stagefright5-cdk-stepper.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-table.mjs +2346 -0
- package/fesm2022/stagefright5-cdk-table.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing-protractor.mjs +324 -0
- package/fesm2022/stagefright5-cdk-testing-protractor.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs +364 -0
- package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing-testbed.mjs +806 -0
- package/fesm2022/stagefright5-cdk-testing-testbed.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing.mjs +740 -0
- package/fesm2022/stagefright5-cdk-testing.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-text-field.mjs +453 -0
- package/fesm2022/stagefright5-cdk-text-field.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-tree.mjs +945 -0
- package/fesm2022/stagefright5-cdk-tree.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk.mjs +26 -0
- package/fesm2022/stagefright5-cdk.mjs.map +1 -0
- package/overlay/_index-deprecated.scss +13 -0
- package/overlay/_index.import.scss +13 -0
- package/overlay/_index.scss +148 -0
- package/overlay/overlay-prebuilt.scss +3 -0
- package/package.json +159 -0
- package/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
- package/schematics/schematics/BUILD.bazel +104 -0
- package/schematics/schematics/README.md +4 -0
- package/schematics/schematics/collection.json +18 -0
- package/schematics/schematics/index.ts +22 -0
- package/schematics/schematics/migration.json +50 -0
- package/schematics/schematics/ng-add/index.spec.ts +50 -0
- package/schematics/schematics/ng-add/index.ts +39 -0
- package/schematics/schematics/ng-add/package-config.ts +62 -0
- package/schematics/schematics/ng-add/schema.json +16 -0
- package/schematics/schematics/ng-add/schema.ts +12 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__style__.template +53 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template +17 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template +29 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template +43 -0
- package/schematics/schematics/ng-generate/drag-drop/index.spec.ts +205 -0
- package/schematics/schematics/ng-generate/drag-drop/index.ts +35 -0
- package/schematics/schematics/ng-generate/drag-drop/schema.json +93 -0
- package/schematics/schematics/ng-generate/drag-drop/schema.ts +11 -0
- package/schematics/schematics/ng-update/data/attribute-selectors.ts +29 -0
- package/schematics/schematics/ng-update/data/class-names.ts +50 -0
- package/schematics/schematics/ng-update/data/constructor-checks.ts +75 -0
- package/schematics/schematics/ng-update/data/css-selectors.ts +33 -0
- package/schematics/schematics/ng-update/data/element-selectors.ts +21 -0
- package/schematics/schematics/ng-update/data/index.ts +18 -0
- package/schematics/schematics/ng-update/data/input-names.ts +118 -0
- package/schematics/schematics/ng-update/data/method-call-checks.ts +63 -0
- package/schematics/schematics/ng-update/data/output-names.ts +42 -0
- package/schematics/schematics/ng-update/data/property-names.ts +151 -0
- package/schematics/schematics/ng-update/data/symbol-removal.ts +22 -0
- package/schematics/schematics/ng-update/devkit-file-system.ts +87 -0
- package/schematics/schematics/ng-update/devkit-migration-rule.ts +185 -0
- package/schematics/schematics/ng-update/devkit-migration.ts +47 -0
- package/schematics/schematics/ng-update/find-stylesheets.ts +43 -0
- package/schematics/schematics/ng-update/html-parsing/angular.ts +49 -0
- package/schematics/schematics/ng-update/html-parsing/elements.ts +66 -0
- package/schematics/schematics/ng-update/index.ts +113 -0
- package/schematics/schematics/ng-update/migrations/attribute-selectors.ts +83 -0
- package/schematics/schematics/ng-update/migrations/class-inheritance.ts +63 -0
- package/schematics/schematics/ng-update/migrations/class-names.ts +107 -0
- package/schematics/schematics/ng-update/migrations/constructor-signature.ts +170 -0
- package/schematics/schematics/ng-update/migrations/css-selectors.ts +83 -0
- package/schematics/schematics/ng-update/migrations/element-selectors.ts +75 -0
- package/schematics/schematics/ng-update/migrations/input-names.ts +83 -0
- package/schematics/schematics/ng-update/migrations/method-call-arguments.ts +70 -0
- package/schematics/schematics/ng-update/migrations/misc-template.ts +36 -0
- package/schematics/schematics/ng-update/migrations/output-names.ts +61 -0
- package/schematics/schematics/ng-update/migrations/property-names.ts +61 -0
- package/schematics/schematics/ng-update/migrations/symbol-removal.ts +51 -0
- package/schematics/schematics/ng-update/migrations/tilde-import-v13/tilde-import-migration.ts +40 -0
- package/schematics/schematics/ng-update/public-api.ts +18 -0
- package/schematics/schematics/ng-update/test-cases/index.spec.ts +18 -0
- package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts +32 -0
- package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution_input.ts +22 -0
- package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
- package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets.spec.ts +50 -0
- package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets_input.ts +8 -0
- package/schematics/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts +20 -0
- package/schematics/schematics/ng-update/test-cases/misc/method-call-checks_input.ts +18 -0
- package/schematics/schematics/ng-update/test-cases/misc/module-resolution.spec.ts +27 -0
- package/schematics/schematics/ng-update/test-cases/v13/misc/tilde-import-v13.spec.ts +149 -0
- package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_expected_output.ts +36 -0
- package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_input.ts +36 -0
- package/schematics/schematics/ng-update/test-cases/v6/class-names_expected_output.ts +8 -0
- package/schematics/schematics/ng-update/test-cases/v6/class-names_input.ts +8 -0
- package/schematics/schematics/ng-update/test-cases/v6/input-names_expected_output.ts +22 -0
- package/schematics/schematics/ng-update/test-cases/v6/input-names_input.ts +22 -0
- package/schematics/schematics/ng-update/test-cases/v6/property-names_expected_output.ts +64 -0
- package/schematics/schematics/ng-update/test-cases/v6/property-names_input.ts +64 -0
- package/schematics/schematics/ng-update/test-cases/v7/property-names_expected_output.ts +28 -0
- package/schematics/schematics/ng-update/test-cases/v7/property-names_input.ts +28 -0
- package/schematics/schematics/ng-update/typescript/base-types.ts +22 -0
- package/schematics/schematics/ng-update/typescript/imports.ts +54 -0
- package/schematics/schematics/ng-update/typescript/literal.ts +32 -0
- package/schematics/schematics/ng-update/typescript/module-specifiers.ts +39 -0
- package/schematics/schematics/ng-update/update-schematic.md +209 -0
- package/schematics/schematics/ng-update/upgrade-data.ts +79 -0
- package/schematics/schematics/paths.ts +15 -0
- package/schematics/schematics/testing/BUILD.bazel +27 -0
- package/schematics/schematics/testing/file-content.ts +20 -0
- package/schematics/schematics/testing/index.ts +14 -0
- package/schematics/schematics/testing/post-scheduled-tasks.ts +45 -0
- package/schematics/schematics/testing/resolve-bazel-path.ts +46 -0
- package/schematics/schematics/testing/test-app.ts +21 -0
- package/schematics/schematics/testing/test-case-setup.ts +236 -0
- package/schematics/schematics/testing/test-library.ts +21 -0
- package/schematics/schematics/testing/test-project.ts +40 -0
- package/schematics/schematics/testing/tsconfig.json +7 -0
- package/schematics/schematics/tsconfig.json +28 -0
- package/schematics/schematics/update-tool/BUILD.bazel +19 -0
- package/schematics/schematics/update-tool/component-resource-collector.ts +195 -0
- package/schematics/schematics/update-tool/file-system.ts +78 -0
- package/schematics/schematics/update-tool/index.ts +191 -0
- package/schematics/schematics/update-tool/logger.ts +23 -0
- package/schematics/schematics/update-tool/migration.ts +88 -0
- package/schematics/schematics/update-tool/public-api.ts +16 -0
- package/schematics/schematics/update-tool/target-version.ts +31 -0
- package/schematics/schematics/update-tool/tsconfig.json +7 -0
- package/schematics/schematics/update-tool/update-recorder.ts +14 -0
- package/schematics/schematics/update-tool/utils/decorators.ts +54 -0
- package/schematics/schematics/update-tool/utils/functions.ts +18 -0
- package/schematics/schematics/update-tool/utils/imports.ts +128 -0
- package/schematics/schematics/update-tool/utils/line-mappings.ts +84 -0
- package/schematics/schematics/update-tool/utils/parse-tsconfig.ts +25 -0
- package/schematics/schematics/update-tool/utils/property-name.ts +28 -0
- package/schematics/schematics/update-tool/utils/virtual-host.ts +116 -0
- package/schematics/schematics/update-tool/version-changes.ts +49 -0
- package/schematics/schematics/utils/ast/ng-module-imports.spec.ts +43 -0
- package/schematics/schematics/utils/ast/ng-module-imports.ts +102 -0
- package/schematics/schematics/utils/ast.ts +88 -0
- package/schematics/schematics/utils/build-component.ts +252 -0
- package/schematics/schematics/utils/get-project.ts +27 -0
- package/schematics/schematics/utils/html-manipulation.ts +105 -0
- package/schematics/schematics/utils/index.ts +19 -0
- package/schematics/schematics/utils/parse5-element.ts +34 -0
- package/schematics/schematics/utils/project-index-file.ts +21 -0
- package/schematics/schematics/utils/project-main-file.ts +26 -0
- package/schematics/schematics/utils/project-style-file.ts +53 -0
- package/schematics/schematics/utils/project-targets.ts +43 -0
- package/schematics/schematics/utils/project-tsconfig-paths.spec.ts +91 -0
- package/schematics/schematics/utils/project-tsconfig-paths.ts +49 -0
- package/schematics/schematics/utils/schematic-options.ts +65 -0
- package/schematics/schematics/utils/vendored-ast-utils/index.ts +599 -0
- package/scrolling/virtual-scroll-viewport.scss +87 -0
- package/table/table.scss +3 -0
- package/text-field/_index.import.scss +2 -0
- package/text-field/_index.scss +89 -0
- package/text-field/text-field-prebuilt.scss +4 -0
- package/types/stagefright5-cdk-a11y.d.ts +1160 -0
- package/types/stagefright5-cdk-accordion.d.ts +95 -0
- package/types/stagefright5-cdk-bidi.d.ts +95 -0
- package/types/stagefright5-cdk-clipboard.d.ts +116 -0
- package/types/stagefright5-cdk-coercion.d.ts +101 -0
- package/types/stagefright5-cdk-collections.d.ts +405 -0
- package/types/stagefright5-cdk-drag-drop.d.ts +1471 -0
- package/types/stagefright5-cdk-keycodes.d.ts +142 -0
- package/types/stagefright5-cdk-layout.d.ts +96 -0
- package/types/stagefright5-cdk-observers.d.ts +91 -0
- package/types/stagefright5-cdk-overlay.d.ts +1258 -0
- package/types/stagefright5-cdk-platform.d.ts +130 -0
- package/types/stagefright5-cdk-portal.d.ts +327 -0
- package/types/stagefright5-cdk-scrolling.d.ts +631 -0
- package/types/stagefright5-cdk-stepper.d.ts +302 -0
- package/types/stagefright5-cdk-table.d.ts +1128 -0
- package/types/stagefright5-cdk-testing-protractor.d.ts +146 -0
- package/types/stagefright5-cdk-testing-selenium-webdriver.d.ts +161 -0
- package/types/stagefright5-cdk-testing-testbed.d.ts +168 -0
- package/types/stagefright5-cdk-testing.d.ts +735 -0
- package/types/stagefright5-cdk-text-field.d.ts +171 -0
- package/types/stagefright5-cdk-tree.d.ts +522 -0
- package/types/stagefright5-cdk.d.ts +14 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {FileSystem, WorkspacePath} from '../file-system';
|
|
11
|
+
import {FileSystemHost} from './virtual-host';
|
|
12
|
+
import {dirname} from 'path';
|
|
13
|
+
|
|
14
|
+
export function parseTsconfigFile(
|
|
15
|
+
tsconfigPath: WorkspacePath,
|
|
16
|
+
fileSystem: FileSystem,
|
|
17
|
+
): ts.ParsedCommandLine {
|
|
18
|
+
const {config} = ts.readConfigFile(tsconfigPath, p => fileSystem.read(fileSystem.resolve(p))!);
|
|
19
|
+
return ts.parseJsonConfigFileContent(
|
|
20
|
+
config,
|
|
21
|
+
new FileSystemHost(fileSystem),
|
|
22
|
+
dirname(tsconfigPath),
|
|
23
|
+
{},
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
|
|
11
|
+
/** Type that describes a property name with an obtainable text. */
|
|
12
|
+
type PropertyNameWithText = Exclude<ts.PropertyName, ts.ComputedPropertyName>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Gets the text of the given property name. Returns null if the property
|
|
16
|
+
* name couldn't be determined statically.
|
|
17
|
+
*/
|
|
18
|
+
export function getPropertyNameText(node: ts.PropertyName): string | null {
|
|
19
|
+
if (ts.isIdentifier(node) || ts.isStringLiteralLike(node)) {
|
|
20
|
+
return node.text;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Checks whether the given property name has a text. */
|
|
26
|
+
export function hasPropertyNameText(node: ts.PropertyName): node is PropertyNameWithText {
|
|
27
|
+
return ts.isStringLiteral(node) || ts.isNumericLiteral(node) || ts.isIdentifier(node);
|
|
28
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {FileSystem} from '../file-system';
|
|
11
|
+
|
|
12
|
+
// We use TypeScript's native `ts.matchFiles` utility for the virtual file system
|
|
13
|
+
// hosts, as that function implements complex logic for matching files with respect
|
|
14
|
+
// to root directory, extensions, excludes, includes etc. The function is currently
|
|
15
|
+
// internal but we can use it as the API most likely will not change any time soon,
|
|
16
|
+
// nor does it seem like this is being made public any time soon.
|
|
17
|
+
// Related issue for tracking: https://github.com/microsoft/TypeScript/issues/13793.
|
|
18
|
+
// https://github.com/microsoft/TypeScript/blob/b397d1fd4abd0edef85adf0afd91c030bb0b4955/src/compiler/utilities.ts#L6192
|
|
19
|
+
declare module 'typescript' {
|
|
20
|
+
export interface FileSystemEntries {
|
|
21
|
+
readonly files: readonly string[];
|
|
22
|
+
readonly directories: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const matchFiles:
|
|
26
|
+
| undefined
|
|
27
|
+
| ((
|
|
28
|
+
path: string,
|
|
29
|
+
extensions: readonly string[] | undefined,
|
|
30
|
+
excludes: readonly string[] | undefined,
|
|
31
|
+
includes: readonly string[] | undefined,
|
|
32
|
+
useCaseSensitiveFileNames: boolean,
|
|
33
|
+
currentDirectory: string,
|
|
34
|
+
depth: number | undefined,
|
|
35
|
+
getFileSystemEntries: (path: string) => FileSystemEntries,
|
|
36
|
+
realpath: (path: string) => string,
|
|
37
|
+
directoryExists: (path: string) => boolean,
|
|
38
|
+
) => string[]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Implementation of a TypeScript parse config host that relies fully on
|
|
43
|
+
* a given virtual file system.
|
|
44
|
+
*/
|
|
45
|
+
export class FileSystemHost implements ts.ParseConfigHost {
|
|
46
|
+
useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
|
|
47
|
+
|
|
48
|
+
constructor(private _fileSystem: FileSystem) {}
|
|
49
|
+
|
|
50
|
+
fileExists(path: string): boolean {
|
|
51
|
+
return this._fileSystem.fileExists(this._fileSystem.resolve(path));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
readFile(path: string): string | undefined {
|
|
55
|
+
const content = this._fileSystem.read(this._fileSystem.resolve(path));
|
|
56
|
+
if (content === null) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
// Strip BOM as otherwise TSC methods (e.g. "getWidth") will return an offset which
|
|
60
|
+
// which breaks the CLI UpdateRecorder. https://github.com/angular/angular/pull/30719
|
|
61
|
+
return content.replace(/^\uFEFF/, '');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
readDirectory(
|
|
65
|
+
rootDir: string,
|
|
66
|
+
extensions: string[],
|
|
67
|
+
excludes: string[] | undefined,
|
|
68
|
+
includes: string[],
|
|
69
|
+
depth?: number,
|
|
70
|
+
): string[] {
|
|
71
|
+
if (ts.matchFiles === undefined) {
|
|
72
|
+
throw Error(
|
|
73
|
+
'Unable to read directory in virtual file system host. This means that ' +
|
|
74
|
+
'TypeScript changed its file matching internals.\n\nPlease consider downgrading your ' +
|
|
75
|
+
'TypeScript version, and report an issue in the Angular Components repository.',
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return ts.matchFiles(
|
|
79
|
+
rootDir,
|
|
80
|
+
extensions,
|
|
81
|
+
extensions,
|
|
82
|
+
includes,
|
|
83
|
+
this.useCaseSensitiveFileNames,
|
|
84
|
+
'/',
|
|
85
|
+
depth,
|
|
86
|
+
p => this._getFileSystemEntries(p),
|
|
87
|
+
p => this._fileSystem.resolve(p),
|
|
88
|
+
p => this._fileSystem.directoryExists(this._fileSystem.resolve(p)),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private _getFileSystemEntries(path: string): ts.FileSystemEntries {
|
|
93
|
+
return this._fileSystem.readDirectory(this._fileSystem.resolve(path));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Creates a TypeScript compiler host that fully relies fully on the given
|
|
99
|
+
* virtual file system. i.e. no interactions with the working directory.
|
|
100
|
+
*/
|
|
101
|
+
export function createFileSystemCompilerHost(
|
|
102
|
+
options: ts.CompilerOptions,
|
|
103
|
+
fileSystem: FileSystem,
|
|
104
|
+
): ts.CompilerHost {
|
|
105
|
+
const host = ts.createCompilerHost(options, true);
|
|
106
|
+
const virtualHost = new FileSystemHost(fileSystem);
|
|
107
|
+
|
|
108
|
+
host.readFile = virtualHost.readFile.bind(virtualHost);
|
|
109
|
+
host.readDirectory = virtualHost.readDirectory.bind(virtualHost);
|
|
110
|
+
host.fileExists = virtualHost.fileExists.bind(virtualHost);
|
|
111
|
+
host.directoryExists = dirPath => fileSystem.directoryExists(fileSystem.resolve(dirPath));
|
|
112
|
+
host.getCurrentDirectory = () => '/';
|
|
113
|
+
host.getCanonicalFileName = p => fileSystem.resolve(p);
|
|
114
|
+
|
|
115
|
+
return host;
|
|
116
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {TargetVersion} from './target-version';
|
|
10
|
+
|
|
11
|
+
export type VersionChanges<T> = {
|
|
12
|
+
[target in TargetVersion]?: ReadableChange<T>[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ReadableChange<T> = {
|
|
16
|
+
pr: string;
|
|
17
|
+
changes: T[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Conditional type that unwraps the value of a version changes type. */
|
|
21
|
+
export type ValueOfChanges<T> = T extends VersionChanges<infer X> ? X : null;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Gets the changes for a given target version from the specified version changes object.
|
|
25
|
+
*
|
|
26
|
+
* For readability and a good overview of breaking changes, the version change data always
|
|
27
|
+
* includes the related Pull Request link. Since this data is not needed when performing the
|
|
28
|
+
* upgrade, this unused data can be removed and the changes data can be flattened into an
|
|
29
|
+
* easy iterable array.
|
|
30
|
+
*/
|
|
31
|
+
export function getChangesForTarget<T>(target: TargetVersion, data: VersionChanges<T>): T[] {
|
|
32
|
+
if (!data) {
|
|
33
|
+
const version = (TargetVersion as Record<string, string>)[target];
|
|
34
|
+
throw new Error(`No data could be found for target version: ${version}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (data[target] || []).reduce((result, prData) => result.concat(prData.changes), [] as T[]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets all changes from the specified version changes object. This is helpful in case a migration
|
|
42
|
+
* rule does not distinguish data based on the target version, but for readability the
|
|
43
|
+
* upgrade data is separated for each target version.
|
|
44
|
+
*/
|
|
45
|
+
export function getAllChanges<T>(data: VersionChanges<T>): T[] {
|
|
46
|
+
return Object.keys(data as any)
|
|
47
|
+
.map(targetVersion => getChangesForTarget(targetVersion as TargetVersion, data))
|
|
48
|
+
.reduce((result, versionData) => result.concat(versionData), []);
|
|
49
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {HostTree} from '@angular-devkit/schematics';
|
|
2
|
+
import {UnitTestTree} from '@angular-devkit/schematics/testing';
|
|
3
|
+
import {hasNgModuleImport} from './ng-module-imports';
|
|
4
|
+
|
|
5
|
+
describe('NgModule import utils', () => {
|
|
6
|
+
let host: UnitTestTree;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
host = new UnitTestTree(new HostTree());
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('hasNgModuleImport', () => {
|
|
13
|
+
it('should properly detect imports', () => {
|
|
14
|
+
host.create(
|
|
15
|
+
'/test.ts',
|
|
16
|
+
`
|
|
17
|
+
@NgModule({
|
|
18
|
+
imports: [TestModule],
|
|
19
|
+
})
|
|
20
|
+
export class MyModule {}
|
|
21
|
+
`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(hasNgModuleImport(host, '/test.ts', 'TestModule')).toBe(true);
|
|
25
|
+
expect(hasNgModuleImport(host, '/test.ts', 'NotExistent')).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it(`should detect imports for NgModule's using a namespaced identifier`, () => {
|
|
29
|
+
host.create(
|
|
30
|
+
'/test.ts',
|
|
31
|
+
`
|
|
32
|
+
@myImport.NgModule({
|
|
33
|
+
imports: [TestModule],
|
|
34
|
+
})
|
|
35
|
+
export class MyModule {}
|
|
36
|
+
`,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(hasNgModuleImport(host, '/test.ts', 'TestModule')).toBe(true);
|
|
40
|
+
expect(hasNgModuleImport(host, '/test.ts', 'NotExistent')).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {SchematicsException, Tree} from '@angular-devkit/schematics';
|
|
10
|
+
import * as ts from 'typescript';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Whether the Angular module in the given path imports the specified module class name.
|
|
14
|
+
*/
|
|
15
|
+
export function hasNgModuleImport(tree: Tree, modulePath: string, className: string): boolean {
|
|
16
|
+
const moduleFileContent = tree.read(modulePath);
|
|
17
|
+
|
|
18
|
+
if (!moduleFileContent) {
|
|
19
|
+
throw new SchematicsException(`Could not read Angular module file: ${modulePath}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const parsedFile = ts.createSourceFile(
|
|
23
|
+
modulePath,
|
|
24
|
+
moduleFileContent.toString(),
|
|
25
|
+
ts.ScriptTarget.Latest,
|
|
26
|
+
true,
|
|
27
|
+
);
|
|
28
|
+
const ngModuleMetadata = findNgModuleMetadata(parsedFile);
|
|
29
|
+
|
|
30
|
+
if (!ngModuleMetadata) {
|
|
31
|
+
throw new SchematicsException(`Could not find NgModule declaration inside: "${modulePath}"`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (let property of ngModuleMetadata!.properties) {
|
|
35
|
+
if (
|
|
36
|
+
!ts.isPropertyAssignment(property) ||
|
|
37
|
+
property.name.getText() !== 'imports' ||
|
|
38
|
+
!ts.isArrayLiteralExpression(property.initializer)
|
|
39
|
+
) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (property.initializer.elements.some(element => element.getText() === className)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolves the last identifier that is part of the given expression. This helps resolving
|
|
53
|
+
* identifiers of nested property access expressions (e.g. myNamespace.core.NgModule).
|
|
54
|
+
*/
|
|
55
|
+
function resolveIdentifierOfExpression(expression: ts.Expression): ts.Identifier | null {
|
|
56
|
+
if (ts.isIdentifier(expression)) {
|
|
57
|
+
return expression;
|
|
58
|
+
} else if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.name)) {
|
|
59
|
+
return expression.name;
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Finds a NgModule declaration within the specified TypeScript node and returns the
|
|
66
|
+
* corresponding metadata for it. This function searches breadth first because
|
|
67
|
+
* NgModule's are usually not nested within other expressions or declarations.
|
|
68
|
+
*/
|
|
69
|
+
function findNgModuleMetadata(rootNode: ts.Node): ts.ObjectLiteralExpression | null {
|
|
70
|
+
// Add immediate child nodes of the root node to the queue.
|
|
71
|
+
const nodeQueue: ts.Node[] = [...rootNode.getChildren()];
|
|
72
|
+
|
|
73
|
+
while (nodeQueue.length) {
|
|
74
|
+
const node = nodeQueue.shift()!;
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
ts.isDecorator(node) &&
|
|
78
|
+
ts.isCallExpression(node.expression) &&
|
|
79
|
+
isNgModuleCallExpression(node.expression)
|
|
80
|
+
) {
|
|
81
|
+
return node.expression.arguments[0] as ts.ObjectLiteralExpression;
|
|
82
|
+
} else {
|
|
83
|
+
nodeQueue.push(...node.getChildren());
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Whether the specified call expression is referring to a NgModule definition. */
|
|
91
|
+
function isNgModuleCallExpression(callExpression: ts.CallExpression): boolean {
|
|
92
|
+
if (
|
|
93
|
+
!callExpression.arguments.length ||
|
|
94
|
+
!ts.isObjectLiteralExpression(callExpression.arguments[0])
|
|
95
|
+
) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// The `NgModule` call expression name is never referring to a `PrivateIdentifier`.
|
|
100
|
+
const decoratorIdentifier = resolveIdentifierOfExpression(callExpression.expression);
|
|
101
|
+
return decoratorIdentifier ? decoratorIdentifier.text === 'NgModule' : false;
|
|
102
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {SchematicsException, Tree} from '@angular-devkit/schematics';
|
|
10
|
+
import {Schema as ComponentOptions} from '@schematics/angular/component/schema';
|
|
11
|
+
import {InsertChange} from '@schematics/angular/utility/change';
|
|
12
|
+
import {getWorkspace} from '@schematics/angular/utility/workspace';
|
|
13
|
+
import {findModuleFromOptions as internalFindModule} from '@schematics/angular/utility/find-module';
|
|
14
|
+
import {ProjectDefinition} from '@angular-devkit/core/src/workspace';
|
|
15
|
+
import * as ts from 'typescript';
|
|
16
|
+
import {getProjectMainFile} from './project-main-file';
|
|
17
|
+
import {addImportToModule, getAppModulePath} from './vendored-ast-utils';
|
|
18
|
+
|
|
19
|
+
/** Reads file given path and returns TypeScript source file. */
|
|
20
|
+
export function parseSourceFile(host: Tree, path: string): ts.SourceFile {
|
|
21
|
+
const buffer = host.read(path);
|
|
22
|
+
if (!buffer) {
|
|
23
|
+
throw new SchematicsException(`Could not find file for path: ${path}`);
|
|
24
|
+
}
|
|
25
|
+
return ts.createSourceFile(path, buffer.toString(), ts.ScriptTarget.Latest, true);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Import and add module to root app module. */
|
|
29
|
+
export function addModuleImportToRootModule(
|
|
30
|
+
host: Tree,
|
|
31
|
+
moduleName: string,
|
|
32
|
+
src: string,
|
|
33
|
+
project: ProjectDefinition,
|
|
34
|
+
) {
|
|
35
|
+
const modulePath = getAppModulePath(host, getProjectMainFile(project));
|
|
36
|
+
addModuleImportToModule(host, modulePath, moduleName, src);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Import and add module to specific module path.
|
|
41
|
+
* @param host the tree we are updating
|
|
42
|
+
* @param modulePath src location of the module to import
|
|
43
|
+
* @param moduleName name of module to import
|
|
44
|
+
* @param src src location to import
|
|
45
|
+
*/
|
|
46
|
+
export function addModuleImportToModule(
|
|
47
|
+
host: Tree,
|
|
48
|
+
modulePath: string,
|
|
49
|
+
moduleName: string,
|
|
50
|
+
src: string,
|
|
51
|
+
) {
|
|
52
|
+
const moduleSource = parseSourceFile(host, modulePath);
|
|
53
|
+
|
|
54
|
+
if (!moduleSource) {
|
|
55
|
+
throw new SchematicsException(`Module not found: ${modulePath}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const changes = addImportToModule(moduleSource, modulePath, moduleName, src);
|
|
59
|
+
const recorder = host.beginUpdate(modulePath);
|
|
60
|
+
|
|
61
|
+
changes.forEach(change => {
|
|
62
|
+
if (change instanceof InsertChange) {
|
|
63
|
+
recorder.insertLeft(change.pos, change.toAdd);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
host.commitUpdate(recorder);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Wraps the internal find module from options with undefined path handling */
|
|
71
|
+
export async function findModuleFromOptions(
|
|
72
|
+
host: Tree,
|
|
73
|
+
options: ComponentOptions,
|
|
74
|
+
): Promise<string | undefined> {
|
|
75
|
+
const workspace = await getWorkspace(host);
|
|
76
|
+
|
|
77
|
+
if (!options.project) {
|
|
78
|
+
options.project = Array.from(workspace.projects.keys())[0];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const project = workspace.projects.get(options.project)!;
|
|
82
|
+
|
|
83
|
+
if (options.path === undefined) {
|
|
84
|
+
options.path = `/${project.root}/src/app`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return internalFindModule(host, options);
|
|
88
|
+
}
|