@@ -20,17 +20,33 @@ import { WorkspaceHost } from '../host';
20
20
import { JsonWorkspaceMetadata , JsonWorkspaceSymbol } from './metadata' ;
21
21
import { createVirtualAstObject } from './utilities' ;
22
22
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
+
23
31
interface ParserContext {
24
32
readonly host : WorkspaceHost ;
25
33
readonly metadata : JsonWorkspaceMetadata ;
26
34
readonly trackChanges : boolean ;
35
+ readonly unprefixedWorkspaceExtensions : ReadonlySet < string > ;
36
+ readonly unprefixedProjectExtensions : ReadonlySet < string > ;
27
37
error ( message : string , node : JsonValue ) : void ;
28
38
warn ( message : string , node : JsonValue ) : void ;
29
39
}
30
40
41
+ export interface JsonWorkspaceOptions {
42
+ allowedProjectExtensions ?: string [ ] ;
43
+ allowedWorkspaceExtensions ?: string [ ] ;
44
+ }
45
+
31
46
export async function readJsonWorkspace (
32
47
path : string ,
33
48
host : WorkspaceHost ,
49
+ options : JsonWorkspaceOptions = { } ,
34
50
) : Promise < WorkspaceDefinition > {
35
51
const raw = await host . readFile ( path ) ;
36
52
if ( raw === undefined ) {
@@ -56,6 +72,14 @@ export async function readJsonWorkspace(
56
72
host,
57
73
metadata : new JsonWorkspaceMetadata ( path , ast , raw ) ,
58
74
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
+ ] ) ,
59
83
error ( message , _node ) {
60
84
// TODO: Diagnostic reporting support
61
85
throw new Error ( message ) ;
@@ -72,10 +96,6 @@ export async function readJsonWorkspace(
72
96
return workspace ;
73
97
}
74
98
75
- const specialWorkspaceExtensions = [ 'cli' , 'defaultProject' , 'newProjectRoot' , 'schematics' ] ;
76
-
77
- const specialProjectExtensions = [ 'cli' , 'schematics' , 'projectType' , 'i18n' ] ;
78
-
79
99
function parseWorkspace ( workspaceNode : Node , context : ParserContext ) : WorkspaceDefinition {
80
100
const jsonMetadata = context . metadata ;
81
101
let projects ;
@@ -99,7 +119,7 @@ function parseWorkspace(workspaceNode: Node, context: ParserContext): WorkspaceD
99
119
100
120
projects = parseProjectsObject ( nodes , context ) ;
101
121
} else {
102
- if ( ! specialWorkspaceExtensions . includes ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
122
+ if ( ! context . unprefixedWorkspaceExtensions . has ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
103
123
context . warn ( `Project extension with invalid name (${ name } ) found.` , name ) ;
104
124
}
105
125
if ( extensions ) {
@@ -201,7 +221,7 @@ function parseProject(
201
221
}
202
222
break ;
203
223
default :
204
- if ( ! specialProjectExtensions . includes ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
224
+ if ( ! context . unprefixedProjectExtensions . has ( name ) && ! / ^ [ a - z ] { 1 , 3 } - .* / . test ( name ) ) {
205
225
context . warn ( `Project extension with invalid name (${ name } ) found.` , name ) ;
206
226
}
207
227
if ( extensions ) {
0 commit comments