Skip to content

Commit

Permalink
Seems like using root instead of the dirname fixes the existing bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Dec 17, 2018
1 parent 4eae10c commit 9b8052f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,24 @@ export default function rebase(options = {}) {
exclude = defaultExclude,
verbose = false,
keepName = false,
folder = ""
folder: assetFolder = ""
} = options

const filter = createFilter(include, exclude)
const wrappers = {}
const assets = {}
const files = {}

let root = null

return {
name: "rollup-plugin-rebase",

/* eslint-disable complexity, max-statements */
async resolveId(importee, importer) {
// console.log("Resolve:", importee)
if (!filter(importee)) {
root = path.dirname(importee)
return null
}

Expand Down Expand Up @@ -115,13 +119,17 @@ export default function rebase(options = {}) {

// Registering for our copying job when the bundle is created (kind of a job queue)
// and respect any sub folder given by the configuration options.
files[fileSource] = path.join(folder, fileTarget)
files[fileSource] = path.join(assetFolder, fileTarget)

// Replacing slashes for Windows, as we need to use POSIX style to be compat
// to Rollup imports / NodeJS resolve implementation.
const assetId = path
.join(path.dirname(importer), folder, fileTarget)
.join(root, assetFolder, fileTarget)
.replace(/\\/g, "/")

// console.log("Importer:", importer)
// console.log("Asset-ID:", assetId)
// console.log("Root-Dir:", root)
const resolvedId = `${assetId}.js`

// Register asset for exclusion handling in this function.
Expand All @@ -146,6 +154,7 @@ export default function rebase(options = {}) {
// This is the magic behind the two-step-resolver and makes it possible
// to have both: tweaked import references and externals together.
const importee = wrappers[id]
// console.log("Load:", importee)
return `export { default } from "${importee}";`
}

Expand Down
4 changes: 2 additions & 2 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function list(root, folder) {
reject(err)
} else {
const content = files.join("\n")
console.log(content)
// console.log(content)
resolve(content)
}
})
Expand All @@ -49,6 +49,6 @@ export async function list(root, folder) {

export async function read(root, file, options = {}) {
const content = await fs.readFile(join(root, file), { encoding: options.encoding || "utf-8" })
console.log(content)
// console.log(content)
return content
}

0 comments on commit 9b8052f

Please sign in to comment.