@@ -10,15 +10,39 @@ const IDENTIFIER_PREFIX_LENGTH = IDENTIFIER_PREFIX.length;
10
10
const IDENTIFIER_PREFIX_RE = new RegExp ( `^${ IDENTIFIER_PREFIX } ` ) ;
11
11
export const EMBEDDED_DEFINITION_TAG = "#blockDefinitionURL" ;
12
12
13
- export function isBroccoliTreeIdentifier ( identifier : string | null ) : identifier is string {
13
+ export function isBroccoliTreeIdentifier ( identifier : string | null ) : boolean {
14
14
return ! ! ( identifier && IDENTIFIER_PREFIX_RE . test ( identifier ) ) ;
15
15
}
16
16
17
- export function identToPath ( identifier : string ) : string {
18
- return identifier . substring ( IDENTIFIER_PREFIX_LENGTH ) ;
17
+ export function identToPath ( input : MergedFileSystem , identifier : string ) : string {
18
+ if ( ! isBroccoliTreeIdentifier ( identifier ) ) {
19
+ return identifier ;
20
+ }
21
+ let relativePath = identifier . substring ( IDENTIFIER_PREFIX_LENGTH ) ;
22
+ if ( ! input . existsSync ( relativePath ) ) {
23
+ debug ( `Couldn't find ${ relativePath } . Looking in addon-tree-output.` ) ;
24
+ let addonRelativePath = `addon-tree-output/${ relativePath } ` ;
25
+ if ( input . existsSync ( addonRelativePath ) ) {
26
+ relativePath = addonRelativePath ;
27
+ } else {
28
+ let addonModulesRelativePath = `addon-tree-output/modules/${ relativePath } ` ;
29
+ if ( input . existsSync ( addonModulesRelativePath ) ) {
30
+ relativePath = addonModulesRelativePath ;
31
+ }
32
+ }
33
+ }
34
+ return relativePath ;
19
35
}
20
36
21
37
export function pathToIdent ( relativePath : string ) : string {
38
+ if ( isBroccoliTreeIdentifier ( relativePath ) ) {
39
+ return relativePath ;
40
+ }
41
+ if ( relativePath . startsWith ( "addon-tree-output/modules/" ) ) {
42
+ relativePath = relativePath . substring ( 26 ) ;
43
+ } else if ( relativePath . startsWith ( "addon-tree-output/" ) ) {
44
+ relativePath = relativePath . substring ( 18 ) ;
45
+ }
22
46
return IDENTIFIER_PREFIX + relativePath ;
23
47
}
24
48
@@ -38,7 +62,7 @@ export class BroccoliTreeImporter extends BaseImporter {
38
62
identifier ( fromIdentifier : string | null , importPath : string , config : Readonly < Configuration > ) : string {
39
63
if ( isBroccoliTreeIdentifier ( fromIdentifier ) ) {
40
64
if ( importPath . startsWith ( "./" ) || importPath . startsWith ( "../" ) ) {
41
- let parsedPath = path . parse ( identToPath ( fromIdentifier ) ) ;
65
+ let parsedPath = path . parse ( identToPath ( this . input , fromIdentifier ! ) ) ;
42
66
// We have to make resolve think the path is absolute or else it will
43
67
// prepend the current working directory.
44
68
let dir = "/" + parsedPath . dir ;
@@ -55,7 +79,7 @@ export class BroccoliTreeImporter extends BaseImporter {
55
79
56
80
async import ( identifier : string , config : Readonly < Configuration > ) : Promise < ImportedFile | ImportedCompiledCssFile > {
57
81
if ( isBroccoliTreeIdentifier ( identifier ) ) {
58
- let relativePath = identToPath ( identifier ) ;
82
+ let relativePath = identToPath ( this . input , identifier ) ;
59
83
let contents = this . input . readFileSync ( relativePath , "utf8" ) ;
60
84
let syntax = syntaxFromExtension ( path . extname ( relativePath ) ) ;
61
85
let defaultName = path . parse ( relativePath ) . name ;
@@ -111,7 +135,7 @@ export class BroccoliTreeImporter extends BaseImporter {
111
135
112
136
defaultName ( identifier : string , configuration : Readonly < Configuration > ) : string {
113
137
if ( isBroccoliTreeIdentifier ( identifier ) ) {
114
- let relativePath = identToPath ( identifier ) ;
138
+ let relativePath = identToPath ( this . input , identifier ) ;
115
139
let defaultName = path . basename ( relativePath ) ;
116
140
defaultName = defaultName . replace ( / .b l o c k $ / , "" ) ;
117
141
return defaultName ;
@@ -122,7 +146,7 @@ export class BroccoliTreeImporter extends BaseImporter {
122
146
123
147
filesystemPath ( identifier : string , config : Readonly < Configuration > ) : string | null {
124
148
if ( isBroccoliTreeIdentifier ( identifier ) ) {
125
- let relativePath = identToPath ( identifier ) ;
149
+ let relativePath = identToPath ( this . input , identifier ) ;
126
150
return relativePath ;
127
151
} else {
128
152
return this . fallbackImporter . filesystemPath ( identifier , config ) ;
@@ -131,7 +155,7 @@ export class BroccoliTreeImporter extends BaseImporter {
131
155
132
156
debugIdentifier ( identifier : string , config : Readonly < Configuration > ) : string {
133
157
if ( isBroccoliTreeIdentifier ( identifier ) ) {
134
- let relativePath = identToPath ( identifier ) ;
158
+ let relativePath = identToPath ( this . input , identifier ) ;
135
159
return relativePath ;
136
160
} else {
137
161
return this . fallbackImporter . debugIdentifier ( identifier , config ) ;
@@ -140,7 +164,7 @@ export class BroccoliTreeImporter extends BaseImporter {
140
164
141
165
syntax ( identifier : string , config : Readonly < Configuration > ) : Syntax {
142
166
if ( isBroccoliTreeIdentifier ( identifier ) ) {
143
- let relativePath = identToPath ( identifier ) ;
167
+ let relativePath = identToPath ( this . input , identifier ) ;
144
168
let syntax = syntaxFromExtension ( path . extname ( relativePath ) ) ;
145
169
return syntax ;
146
170
} else {
0 commit comments