@@ -20,17 +20,33 @@ import { WorkspaceHost } from '../host';
2020import { JsonWorkspaceMetadata , JsonWorkspaceSymbol } from './metadata' ;
2121import { createVirtualAstObject } from './utilities' ;
2222
23+ const ANGULAR_WORKSPACE_EXTENSIONS = Object . freeze ( [
24+ 'cli' ,
25+ 'defaultProject' ,
26+ 'newProjectRoot' ,
27+ 'schematics' ,
28+ ] ) ;
29+ const ANGULAR_PROJECT_EXTENSIONS = Object . freeze ( [ 'cli' , 'schematics' , 'projectType' , 'i18n' ] ) ;
30+
2331interface ParserContext {
2432 readonly host : WorkspaceHost ;
2533 readonly metadata : JsonWorkspaceMetadata ;
2634 readonly trackChanges : boolean ;
35+ readonly unprefixedWorkspaceExtensions : ReadonlySet < string > ;
36+ readonly unprefixedProjectExtensions : ReadonlySet < string > ;
2737 error ( message : string , node : JsonValue ) : void ;
2838 warn ( message : string , node : JsonValue ) : void ;
2939}
3040
41+ export interface JsonWorkspaceOptions {
42+ allowedProjectExtensions ?: string [ ] ;
43+ allowedWorkspaceExtensions ?: string [ ] ;
44+ }
45+
3146export async function readJsonWorkspace (
3247 path : string ,
3348 host : WorkspaceHost ,
49+ options : JsonWorkspaceOptions = { } ,
3450) : Promise < WorkspaceDefinition > {
3551 const raw = await host . readFile ( path ) ;
3652 if ( raw === undefined ) {
@@ -56,6 +72,14 @@ export async function readJsonWorkspace(
5672 host,
5773 metadata : new JsonWorkspaceMetadata ( path , ast , raw ) ,
5874 trackChanges : true ,
75+ unprefixedWorkspaceExtensions : new Set ( [
76+ ...ANGULAR_WORKSPACE_EXTENSIONS ,
77+ ...( options . allowedWorkspaceExtensions ?? [ ] ) ,
78+ ] ) ,
79+ unprefixedProjectExtensions : new Set ( [
80+ ...ANGULAR_PROJECT_EXTENSIONS ,
81+ ...( options . allowedProjectExtensions ?? [ ] ) ,
82+ ] ) ,
5983 error ( message , _node ) {
6084 // TODO: Diagnostic reporting support
6185 throw new Error ( message ) ;
@@ -72,10 +96,6 @@ export async function readJsonWorkspace(
7296 return workspace ;
7397}
7498
75- const specialWorkspaceExtensions = [ 'cli' , 'defaultProject' , 'newProjectRoot' , 'schematics' ] ;
76-
77- const specialProjectExtensions = [ 'cli' , 'schematics' , 'projectType' , 'i18n' ] ;
78-
7999function parseWorkspace ( workspaceNode : Node , context : ParserContext ) : WorkspaceDefinition {
80100 const jsonMetadata = context . metadata ;
81101 let projects ;
@@ -99,7 +119,7 @@ function parseWorkspace(workspaceNode: Node, context: ParserContext): WorkspaceD
99119
100120 projects = parseProjectsObject ( nodes , context ) ;
101121 } else {
102- if ( ! specialWorkspaceExtensions . includes ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
122+ if ( ! context . unprefixedWorkspaceExtensions . has ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
103123 context . warn ( `Project extension with invalid name (${ name } ) found.` , name ) ;
104124 }
105125 if ( extensions ) {
@@ -201,7 +221,7 @@ function parseProject(
201221 }
202222 break ;
203223 default :
204- if ( ! specialProjectExtensions . includes ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
224+ if ( ! context . unprefixedProjectExtensions . has ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
205225 context . warn ( `Project extension with invalid name (${ name } ) found.` , name ) ;
206226 }
207227 if ( extensions ) {
0 commit comments