Skip to content

refactor: vendor used typescript ast utils from @schematics/angular #18155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cdk/schematics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export * from './utils';
export * from './ng-update/public-api';
export * from './update-tool/public-api';

// Re-exported so that Angular Material schematic code can consume the
// vendored "@schematics/angular" AST utils.
export * from './utils/vendored-ast-utils';

// Re-export parse5 from the CDK. Material schematics code cannot simply import
// "parse5" because it could result in a different version. As long as we import
// it from within the CDK, it will always be the correct version that is specified
Expand Down
10 changes: 4 additions & 6 deletions src/cdk/schematics/utils/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
import {WorkspaceProject} from '@angular-devkit/core/src/experimental/workspace';
import {SchematicsException, Tree} from '@angular-devkit/schematics';
import {Schema as ComponentOptions} from '@schematics/angular/component/schema';
import {addImportToModule} from '@schematics/angular/utility/ast-utils';
import {InsertChange} from '@schematics/angular/utility/change';
import {getWorkspace} from '@schematics/angular/utility/config';
import {findModuleFromOptions as internalFindModule} from '@schematics/angular/utility/find-module';
import {getAppModulePath} from '@schematics/angular/utility/ng-ast-utils';
import * as ts from 'typescript';
import {getProjectMainFile} from './project-main-file';
import {ts, typescript} from './version-agnostic-typescript';

import {addImportToModule, getAppModulePath} from './vendored-ast-utils';

/** Reads file given path and returns TypeScript source file. */
export function getSourceFile(host: Tree, path: string): typescript.SourceFile {
export function parseSourceFile(host: Tree, path: string): ts.SourceFile {
const buffer = host.read(path);
if (!buffer) {
throw new SchematicsException(`Could not find file for path: ${path}`);
Expand All @@ -44,7 +42,7 @@ export function addModuleImportToRootModule(host: Tree, moduleName: string, src:
export function addModuleImportToModule(host: Tree, modulePath: string, moduleName: string,
src: string) {

const moduleSource = getSourceFile(host, modulePath);
const moduleSource = parseSourceFile(host, modulePath);

if (!moduleSource) {
throw new SchematicsException(`Module not found: ${modulePath}`);
Expand Down
12 changes: 6 additions & 6 deletions src/cdk/schematics/utils/build-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import {
} from '@angular-devkit/schematics';
import {FileSystemSchematicContext} from '@angular-devkit/schematics/tools';
import {Schema as ComponentOptions, Style} from '@schematics/angular/component/schema';
import {
addDeclarationToModule,
addEntryComponentToModule,
addExportToModule,
} from '@schematics/angular/utility/ast-utils';
import {InsertChange} from '@schematics/angular/utility/change';
import {getWorkspace} from '@schematics/angular/utility/config';
import {buildRelativePath, findModuleFromOptions} from '@schematics/angular/utility/find-module';
Expand All @@ -36,9 +31,14 @@ import {buildDefaultPath} from '@schematics/angular/utility/project';
import {validateHtmlSelector, validateName} from '@schematics/angular/utility/validation';
import {readFileSync, statSync} from 'fs';
import {dirname, join, resolve} from 'path';
import * as ts from 'typescript';
import {
addDeclarationToModule,
addEntryComponentToModule,
addExportToModule,
} from '../utils/vendored-ast-utils';
import {getProjectFromWorkspace} from './get-project';
import {getDefaultComponentOptions} from './schematic-options';
import {ts} from './version-agnostic-typescript';

/**
* List of style extensions which are CSS compatible. All supported CLI style extensions can be
Expand Down
1 change: 0 additions & 1 deletion src/cdk/schematics/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ export * from './project-main-file';
export * from './project-style-file';
export * from './project-targets';
export * from './schematic-options';
export * from './version-agnostic-typescript';
Loading