Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to resolve absolute path relative to options.rootDir #1398

Closed
buckle2000 opened this issue May 20, 2018 · 0 comments
Closed

Option to resolve absolute path relative to options.rootDir #1398

buckle2000 opened this issue May 20, 2018 · 0 comments

Comments

@buckle2000
Copy link
Contributor

buckle2000 commented May 20, 2018

🙋 feature request

Add an option to set "relative" absolute path.

🤔 Expected Behavior

If option --root-dir is given to parcel, absolute path should resolve relative to that path.

Example: parcel src/index.html --root-dir src

😯 Current Behavior

Any absolute path in assets is resolved to filesystem root /.

💁 Possible Solution

When resolving dependencies, change all path.resolve to the following function:

const rootDir = '/home/user/some/path'

function resolvePath(...paths) {
    const rawPath = path.resolve(...paths)
    if (rootDir !== undefined) {
        if (path.isAbsolute(rawPath)) {
            return path.join(rootDir, rawPath)
        } else {
            return rawPath
        }
    } else {
        return rawPath
    }
}

For example, change
const absPath = Path.resolve(Path.dirname(asset.name), dep.name);
to
const absPath = resolvePath(Path.dirname(asset.name), dep.name);

🔦 Context

Closes #1352

💻 Examples

@buckle2000 buckle2000 changed the title Option to set --root-dir Option to set --root-dir for absolute path May 21, 2018
@buckle2000 buckle2000 changed the title Option to set --root-dir for absolute path Option to resolve absolute path relative to options.rootDir May 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants