-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed
Labels
Description
🐞 Bug report
Is this a regression?
Yes, the previous version in which this bug was not present was: 9.1.12Description
I updated @schematics/angular
to version 11. After it, I realized that the method buildDefaultPath
was removed from @schematics/angular/utility/project
, and I should use the new one from @schematics/angular/utility/workspace
. But when I'm running tests to test my custom schematics it fails with error.
Part of custom schematics code:
return (tree: Tree, _context: SchematicContext) => {
const workspaceConfigBuffer = tree.read('angular.json');
if (!workspaceConfigBuffer) {
throw new SchematicsException("Not an Angular CLI workspace");
}
const workspaceConfig = JSON.parse(workspaceConfigBuffer.toString());
const projectName = _options.project || workspaceConfig.defaultProject;
console.log(workspaceConfig);
const project = workspaceConfig.projects[projectName];
if (!_options.path) {
_options.path = buildDefaultPath(project); // Here method throw exception
}
// some code below
Here is how I'm creating workspace and application in tests:
const coreOptions: {schema: StoreSchema, workspace: WorkspaceSchema, app: ApplicationSchema} = {
workspace: {
name: 'workspace',
newProjectRoot: 'projects',
version: '11.0.4'
},
app: {
name: 'th-schematics'
},
schema: {
name: 'Admin'
}
};
beforeEach(async () => {
appTree = await schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'workspace',
coreOptions.workspace
).toPromise();
appTree = await schematicRunner.runExternalSchematicAsync(
'@schematics/angular',
'application',
coreOptions.app,
appTree
).toPromise()
});
As I see from code, this method has next line of code const projectDirName = project.extensions['projectType'] === workspace_models_1.ProjectType.Application ? 'app' : 'lib';
But extensions
property doesn't exist in project
. However projectType
exists in project
directly
{
'$schema': './node_modules/@angular/cli/lib/config/schema.json',
version: 1,
newProjectRoot: 'projects',
projects: {
'th-schematics': {
projectType: 'application',
schematics: [Object],
root: 'projects/th-schematics',
sourceRoot: 'projects/th-schematics/src',
prefix: 'app',
architect: [Object]
}
},
defaultProject: 'th-schematics'
}
And it's very strange that square brackets were used for projectType
property.
🔬 Minimal Reproduction
- Install last
🔥 Exception or Error
TypeError: Cannot read property 'projectType' of undefined
at Object.buildDefaultPath (/Users/nechik/_projects/_trailhead/th-framework-schematics/node_modules/@schematics/angular/utility/workspace.js:63:46)
🌍 Your Environment
Angular CLI: 11.0.4
Node: 15.4.0
OS: darwin x64
Angular: undefined
...
Ivy Workspace: Yes
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1100.4 (cli-only)
@angular-devkit/core 11.0.4
@angular-devkit/schematics 11.0.4
@schematics/angular 11.0.4
@schematics/update 0.1100.4 (cli-only)
rxjs 6.6.3
typescript 4.0.5