@@ -24,7 +24,7 @@ import {
24
24
PluginDirectUsageOptions ,
25
25
DEFAULT_OPTIONS ,
26
26
} from './options' ;
27
- import type { SpecProps , ApiDocProps } from './types/common' ;
27
+ import type { SpecDataResult , ApiDocProps } from './types/common' ;
28
28
import { loadSpecWithConfig } from './loadSpec' ;
29
29
import { loadRedoclyConfig } from './loadRedoclyConfig' ;
30
30
@@ -33,6 +33,10 @@ const version = require('../package.json').version;
33
33
34
34
export { PluginOptions , PluginDirectUsageOptions , loadRedoclyConfig } ;
35
35
36
+ function getIsExternalUrl ( url = '' ) {
37
+ return [ 'http://' , 'https://' ] . some ( ( protocol ) => url . startsWith ( protocol ) ) ;
38
+ }
39
+
36
40
export default function redocPlugin (
37
41
context : LoadContext ,
38
42
opts : PluginOptions ,
@@ -45,12 +49,13 @@ export default function redocPlugin(
45
49
const { debug, spec, url : downloadUrl , config, themeId } = options ;
46
50
47
51
let url = downloadUrl ;
48
- const isSpecFile = fs . existsSync ( spec ) ;
52
+ const isExternalUrl = getIsExternalUrl ( url ) ;
53
+
49
54
const fileName = path . join (
50
55
'redocusaurus' ,
51
56
`${ options . id || 'api-spec' } .yaml` ,
52
57
) ;
53
- let filesToWatch : string [ ] = isSpecFile ? [ path . resolve ( spec ) ] : [ ] ;
58
+ let filesToWatch : string [ ] = ! isExternalUrl ? [ path . resolve ( spec ) ] : [ ] ;
54
59
55
60
if ( debug ) {
56
61
console . error ( '[REDOCUSAURUS_PLUGIN] Opts Input:' , opts ) ;
@@ -67,7 +72,7 @@ export default function redocPlugin(
67
72
68
73
let bundledSpec : Document , problems : NormalizedProblem [ ] ;
69
74
70
- if ( ! isSpecFile ) {
75
+ if ( isExternalUrl ) {
71
76
// If spec is a remote url then add it as download url also as a default
72
77
url = url || spec ;
73
78
if ( debug ) {
@@ -123,10 +128,9 @@ export default function redocPlugin(
123
128
throw new Error ( `[Redocusaurus] Spec could not be parsed: ${ spec } ` ) ;
124
129
}
125
130
126
- const data : SpecProps = {
131
+ const data : SpecDataResult = {
127
132
url,
128
133
themeId,
129
- isSpecFile,
130
134
// eslint-disable-next-line @typescript-eslint/no-explicit-any
131
135
spec : content . converted as any ,
132
136
} ;
@@ -165,7 +169,7 @@ export default function redocPlugin(
165
169
}
166
170
} ,
167
171
async postBuild ( { content } ) {
168
- if ( ! isSpecFile || downloadUrl ) {
172
+ if ( isExternalUrl || downloadUrl ) {
169
173
return ;
170
174
}
171
175
// Create a static file from bundled spec
0 commit comments