@@ -152,24 +152,21 @@ const removeCommentLines = (scriptString) => {
152152}
153153
154154const replaceRelativePathByAbsolute = ( script , modelDirectory ) => {
155- if ( ! modelDirectory || typeof modelDirectory !== 'string' ) {
156- return script ;
157- }
158- const stringifiedScript = JSON . stringify ( script ) ;
159- const fixedScript = stringifiedScript . replace ( / ( " \$ r e f " : \s * ) " ( .* ?(?< ! \\ ) ) " / g, ( match , refGroup , relativePath ) => {
160- const isAbsolutePath = relativePath . startsWith ( 'file:' ) ;
161- const isInternetLink = relativePath . startsWith ( 'http:' ) || relativePath . startsWith ( 'https:' ) ;
162- const isModelRef = relativePath . startsWith ( '#' ) ;
163-
164- if ( isAbsolutePath || isInternetLink || isModelRef ) {
165- return match
166- }
167- const absolutePath = path . resolve ( modelDirectory , '..' , relativePath )
168-
169- return `${ refGroup } "file://${ absolutePath } "`
170- } ) ;
171-
172- return JSON . parse ( fixedScript ) ;
155+ if ( ! modelDirectory || typeof modelDirectory !== 'string' ) {
156+ return script ;
157+ }
158+ const stringifiedScript = JSON . stringify ( script ) ;
159+ const fixedScript = stringifiedScript . replace ( / ( " \$ r e f " : \s * ) " ( .* ?(?< ! \\ ) ) " / g, ( match , refGroup , relativePath ) => {
160+ const isAbsolutePath = relativePath . startsWith ( 'file:' ) ;
161+ const isInternetLink = relativePath . startsWith ( 'http:' ) || relativePath . startsWith ( 'https:' ) ;
162+ const isModelRef = relativePath . startsWith ( '#' ) ;
163+ if ( isAbsolutePath || isInternetLink || isModelRef ) {
164+ return match
165+ }
166+ const absolutePath = path . join ( path . dirname ( modelDirectory ) , relativePath ) . replace ( / \\ / g, '/' ) ;
167+ return `${ refGroup } "file://${ absolutePath } "`
168+ } ) ;
169+ return JSON . parse ( fixedScript ) ;
173170}
174171
175172const handleRefInContainers = ( containers , externalDefinitions ) => {
0 commit comments