Skip to content

Commit b976c58

Browse files
authored
fix(schematics): remove experimental workspace API type usage (#2644)
This change removes usage of the experimental workspace API. Only two types were used within the schematics. The experimental workspace API is no longer present as of Angular v11.
1 parent 7e1918a commit b976c58

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

src/schematics/interfaces.ts

+10
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ export interface FSHost {
7474
writeFileSync(src: string, data: string): void;
7575
renameSync(src: string, dest: string): void;
7676
}
77+
78+
export interface WorkspaceProject {
79+
projectType?: string;
80+
architect?: Record<string, { builder: string; options?: Record<string, any> }>;
81+
}
82+
83+
export interface Workspace {
84+
defaultProject?: string;
85+
projects: Record<string, WorkspaceProject>;
86+
}

src/schematics/ng-add-ssr.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { SchematicsException, Tree, SchematicContext } from '@angular-devkit/schematics';
2-
import { experimental } from '@angular-devkit/core';
32
import {
43
addDependencies,
54
generateFirebaseRc,
@@ -8,15 +7,15 @@ import {
87
safeReadJSON,
98
stringifyFormatted
109
} from './ng-add-common';
11-
import { FirebaseJSON } from './interfaces';
10+
import { FirebaseJSON, Workspace, WorkspaceProject } from './interfaces';
1211

1312
import { default as defaultDependencies, firebaseFunctions as firebaseFunctionsDependencies } from './versions.json';
1413
import { dirname, join } from 'path';
1514

1615
// We consider a project to be a universal project if it has a `server` architect
1716
// target. If it does, it knows how to build the application's server.
1817
export const isUniversalApp = (
19-
project: experimental.workspace.WorkspaceProject
18+
project: WorkspaceProject
2019
) => project.architect && project.architect.server;
2120

2221
function emptyFirebaseJson(source: string) {
@@ -106,10 +105,10 @@ export const addFirebaseFunctionsDependencies = (tree: Tree, context: SchematicC
106105
};
107106

108107
export const setupUniversalDeployment = (config: {
109-
project: experimental.workspace.WorkspaceProject;
108+
project: WorkspaceProject;
110109
options: NgAddNormalizedOptions;
111110
workspacePath: string;
112-
workspace: experimental.workspace.WorkspaceSchema;
111+
workspace: Workspace;
113112
tree: Tree;
114113
}) => {
115114
const { tree, workspacePath, workspace, options } = config;

src/schematics/ng-add-static.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { SchematicsException, Tree, SchematicContext } from '@angular-devkit/schematics';
2-
import { experimental } from '@angular-devkit/core';
32
import {
43
addDependencies,
54
generateFirebaseRc,
@@ -8,7 +7,7 @@ import {
87
safeReadJSON,
98
stringifyFormatted
109
} from './ng-add-common';
11-
import { FirebaseJSON } from './interfaces';
10+
import { FirebaseJSON, Workspace, WorkspaceProject } from './interfaces';
1211

1312
import { default as defaultDependencies } from './versions.json';
1413

@@ -82,10 +81,10 @@ export const addFirebaseHostingDependencies = (tree: Tree, context: SchematicCon
8281
};
8382

8483
export const setupStaticDeployment = (config: {
85-
project: experimental.workspace.WorkspaceProject;
84+
project: WorkspaceProject;
8685
options: NgAddNormalizedOptions;
8786
workspacePath: string;
88-
workspace: experimental.workspace.WorkspaceSchema;
87+
workspace: Workspace;
8988
tree: Tree;
9089
}) => {
9190
const { tree, workspacePath, workspace, options } = config;

src/schematics/ng-add.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { SchematicContext, SchematicsException, Tree } from '@angular-devkit/schematics';
22
import { NodePackageInstallTask, RunSchematicTask } from '@angular-devkit/schematics/tasks';
3-
import { experimental, JsonParseMode, parseJson } from '@angular-devkit/core';
3+
import { JsonParseMode, parseJson } from '@angular-devkit/core';
44
import { listProjects, projectPrompt, projectTypePrompt } from './utils';
5-
5+
import { Workspace } from './interfaces';
66
import { DeployOptions, NgAddNormalizedOptions } from './ng-add-common';
77
import { addFirebaseFunctionsDependencies, setupUniversalDeployment } from './ng-add-ssr';
88
import { addFirebaseHostingDependencies, setupStaticDeployment } from './ng-add-static';
99

1010
function getWorkspace(
1111
host: Tree
12-
): { path: string; workspace: experimental.workspace.WorkspaceSchema } {
12+
): { path: string; workspace: Workspace } {
1313
const possibleFiles = ['/angular.json', '/.angular.json'];
1414
const path = possibleFiles.filter(p => host.exists(p))[0];
1515

@@ -19,12 +19,12 @@ function getWorkspace(
1919
}
2020
const content = configBuffer.toString();
2121

22-
let workspace: experimental.workspace.WorkspaceSchema;
22+
let workspace: Workspace;
2323
try {
2424
workspace = (parseJson(
2525
content,
2626
JsonParseMode.Loose
27-
) as {}) as experimental.workspace.WorkspaceSchema;
27+
) as {}) as Workspace;
2828
} catch (e) {
2929
throw new SchematicsException(`Could not parse angular.json: ` + e.message);
3030
}

src/schematics/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { experimental } from '@angular-devkit/core';
21
import { readFileSync } from 'fs';
3-
import { FirebaseRc, Project } from './interfaces';
2+
import { FirebaseRc, Project, WorkspaceProject } from './interfaces';
43
import { join } from 'path';
54
import { isUniversalApp } from './ng-add-ssr';
65

@@ -56,7 +55,7 @@ export const projectPrompt = (projects: Project[]) => {
5655
});
5756
};
5857

59-
export const projectTypePrompt = (project: experimental.workspace.WorkspaceProject) => {
58+
export const projectTypePrompt = (project: WorkspaceProject) => {
6059
if (isUniversalApp(project)) {
6160
return require('inquirer').prompt({
6261
type: 'confirm',

0 commit comments

Comments
 (0)