( rootDir: string, viteBasePath: string, userOpts: PluginOptions | undefined )
| 41 | } |
| 42 | |
| 43 | function normalizeOptions( |
| 44 | rootDir: string, |
| 45 | viteBasePath: string, |
| 46 | userOpts: PluginOptions | undefined |
| 47 | ) { |
| 48 | if (!(viteBasePath.startsWith('/') && viteBasePath.endsWith('/'))) { |
| 49 | // TODO v2: make this an error |
| 50 | console.error( |
| 51 | `warning: vite's config.base must begin and end with /. This will be an error in v2. If you have a valid use case, please open an issue.` |
| 52 | ); |
| 53 | if (!viteBasePath.endsWith('/')) { |
| 54 | viteBasePath += '/'; |
| 55 | } |
| 56 | } |
| 57 | const opts: NormalizedPluginOptions = { ...userOpts } as any; |
| 58 | |
| 59 | if (typeof opts.routesDir !== 'string') { |
| 60 | opts.routesDir = resolve(rootDir, 'src', 'routes'); |
| 61 | } else if (!isAbsolute(opts.routesDir)) { |
| 62 | opts.routesDir = resolve(rootDir, opts.routesDir); |
| 63 | } |
| 64 | opts.routesDir = normalizePath(opts.routesDir); |
| 65 | |
| 66 | if (typeof opts.serverPluginsDir !== 'string') { |
| 67 | opts.serverPluginsDir = opts.routesDir; |
| 68 | } else if (!isAbsolute(opts.serverPluginsDir)) { |
| 69 | opts.serverPluginsDir = resolve(rootDir, opts.serverPluginsDir); |
| 70 | } |
| 71 | opts.serverPluginsDir = normalizePath(opts.serverPluginsDir); |
| 72 | |
| 73 | if (typeof (opts as any).baseUrl === 'string') { |
| 74 | // baseUrl deprecated |
| 75 | opts.basePathname = (opts as any).baseUrl; |
| 76 | } |
| 77 | |
| 78 | if (typeof opts.basePathname !== 'string') { |
| 79 | // opts.basePathname is used internally |
| 80 | // but in most cases should be passed in by the vite config "base" property |
| 81 | opts.basePathname = viteBasePath; |
| 82 | } |
| 83 | if (!opts.basePathname.endsWith('/')) { |
| 84 | // TODO v2: make this an error |
| 85 | console.error( |
| 86 | `Warning: qwik-city plugin basePathname must end with /. This will be an error in v2` |
| 87 | ); |
| 88 | opts.basePathname += '/'; |
| 89 | } |
| 90 | |
| 91 | // cleanup basePathname |
| 92 | const url = new URL(opts.basePathname, 'https://qwik.dev/'); |
| 93 | opts.basePathname = url.pathname; |
| 94 | |
| 95 | if (typeof opts.trailingSlash !== 'boolean') { |
| 96 | opts.trailingSlash = true; |
| 97 | } |
| 98 | |
| 99 | opts.mdx = opts.mdx || {}; |
| 100 | opts.platform = opts.platform || {}; |
no test coverage detected
searching dependent graphs…