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

Replace sub-module's relative require #48

Open
stevenvachon opened this issue Mar 4, 2017 · 6 comments
Open

Replace sub-module's relative require #48

stevenvachon opened this issue Mar 4, 2017 · 6 comments

Comments

@stevenvachon
Copy link

stevenvachon commented Mar 4, 2017

.transform("aliasify", { global:true, aliases:{ "whatwg-url/lib/utf8": "utf8-typed" }})

I've even tried using the full path as the key:

.transform("aliasify", { global:true, aliases:{ [require.resolve("whatwg-url/lib/utf8")] : "utf8-typed" }})

The file that I'm trying to alias is, by default, required internally with require("./utf8").

Instead, the above aliases function as if being ignored.

@stevenvachon
Copy link
Author

stevenvachon commented Mar 6, 2017

I was able to get it to work by using the exact require input as the key:

.transform("aliasify", { global:true, aliases:{ "./utf8": "utf8-typed" }})

which is unsafe as any dependency could have such a require argument.

@stevenvachon
Copy link
Author

stevenvachon commented Mar 7, 2017

Solving this would likely require the use of require.resolve() and I don't know how that will affect things. If it proves to be impossible, viralify is an option, but kinda hacky as it actually overwrites the package.json file of the specific dependencies.

@stevenvachon
Copy link
Author

Dead project?

@jwalton
Copy link
Contributor

jwalton commented Aug 1, 2018

Well, not a lively project. :) But I get way too many emails from github and unfortunately it's easy for issues from less-lively projects to slip through the cracks.

So, you're trying to make it so when whatwg-url tries to internally import "./lib/utf8" (or some variation on that), you want to replace this with require('utf8-typed')? Tricky.

We do support "options" for the right hand side of aliases. For example:

aliases: {
    "d3": {"relative": "./shims/d3.js"}
}

@jwalton
Copy link
Contributor

jwalton commented Aug 1, 2018

(Hit enter too soon)

So if you can solve this with require.resolve(), you could maybe pass in an option to turn that on. Something like:

aliases: {
   "whatwg-url/lib/utf8": {replacement: "utf8-typed", resolve: true}
}

(Maybe you can come up with a better name than resolve for that option. :P)

Sound reasonable?

@stevenvachon
Copy link
Author

Sounds reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants