Skip to content

Commit

Permalink
windows absolute path fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Nov 28, 2019
1 parent d4ae699 commit 079124d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/files-to-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ const fsa = require('./utils/fsa')

const MATCH_BRACKETS = RegExp(/\[[^\[\]]+\]/g);

module.exports = async function filesToRoutes({ pages, ignore, dynamicImports }) {
module.exports = async function filesToRoutes({ pages, ignore, dynamicImports, outputFile }) {
ignore = Array.isArray(ignore) ? ignore : [ignore]
const files = await getFiles(pages, ['html', 'svelte'], ignore)
const routes = convertToRoutes(files)

if (!routes.length) console.log('no routes found in ' + pages)

return convertToCodeString(routes, pages, { dynamicImports })
return convertToCodeString(routes, pages, dynamicImports, outputFile )
}


function convertToCodeString(routes, pages, { dynamicImports }) {
function convertToCodeString(routes, pages, dynamicImports, outputFile) {
const imports = dynamicImports ? [] : routes
const basePath = path.relative(path.dirname(outputFile), pages).replace(/\\/g,'/')
const lines = imports.map(
route => `import ${route.component} from '${pages}${route.filepath}'`
route => `import ${route.component} from './${basePath+route.filepath}'`
)

lines.push(
Expand Down Expand Up @@ -76,7 +77,6 @@ async function getFiles(absoluteDir, extensions, ignore, _path = '', _nested = f
const nestedList = await getFiles(_filepath, extensions, ignore, filepath, true, [...layouts])
list.push(...nestedList)
}

if (extensions.includes(ext))
list.push({ filepath, layouts, isLayout, isFallback })
})
Expand Down
7 changes: 4 additions & 3 deletions lib/rollup-plugin-filerouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const renderGeneratedRoutes = async ({
pages,
ignore,
dynamicImports,
outputFile
}) => `
${await filesToRoutes({ pages, ignore, dynamicImports })}
${await filesToRoutes({ pages, ignore, dynamicImports, outputFile })}
export const options = ${JSON.stringify({ unknownPropWarnings })}
`
Expand All @@ -37,7 +38,7 @@ const resolveOutputFile = async input => {
const withWatch = options => {
const {
pages: dir,
watchOutputFile: outputFile,
outputFile,
} = options

log('Watching', dir)
Expand Down Expand Up @@ -127,7 +128,7 @@ module.exports = function svelteFileRouter(inputOptions) {
// The best is probably somewhere under your system's `/tmp`, or your
// project's dist folder.
//
watchOutputFile: './svelte-filerouter-routes.js',
outputFile: './svelte-filerouter-routes.js',
}
const options = Object.assign({}, defaultOptions, inputOptions)

Expand Down

0 comments on commit 079124d

Please sign in to comment.