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

[WIP] resolve '~/' to root path of project #466

Closed
wants to merge 6 commits into from

Conversation

fansenze
Copy link
Contributor

@fansenze fansenze commented Jan 2, 2018

resolve '~' to root path of project

i support use ~

#336

Copy link
Member

@DeMoorJasper DeMoorJasper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!
This should however not resolve to cwd, because this would break if u start a project from a different folder than where the startpoint is located and any usage of '~' inside node_modules.
(U could have a look at my PR for a slightly more accurate but not perfect root solution #290 )

@fansenze
Copy link
Contributor Author

fansenze commented Jan 3, 2018

@DeMoorJasper
i think / may be relative path , also i think can use ~/
~ only related to version of package, has nothing to do with path

@DeMoorJasper DeMoorJasper changed the title Feat: resolve path [WIP] Feat: resolve path Jan 3, 2018
@DeMoorJasper DeMoorJasper changed the title [WIP] Feat: resolve path [WIP] resolve '~' to root path of project Jan 3, 2018
@fansenze fansenze changed the title [WIP] resolve '~' to root path of project [WIP] resolve '~/' to root path of project Jan 4, 2018
@@ -9,6 +9,19 @@ class Resolver {
constructor(options = {}) {
this.options = options;
this.cache = new Map();
this.pathIndicators = {
// resolve '~/' to root path of project
'~/': path.dirname(this.options.cacheDir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would break if source is in another directory than where u executed the parcel command.
This kinda is the same as your previous cwd() implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most projects only need to run under their current directory as the root directory on it, because of the need for convenient reference to resource files

resolvePath(filename) {
for (let [indicator, exactPath] of Object.entries(this.pathIndicators)) {
if (filename.startsWith(indicator)) {
return path.resolve(exactPath, filename.slice(indicator.length));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this also handle urlImports in for example html?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it cann't handle in html which is entry

@nehaleem
Copy link

nehaleem commented Jan 9, 2018

I think, this is not needed. Isnt better just use https://github.com/tleunen/babel-plugin-module-resolver ?

@DeMoorJasper
Copy link
Member

@nehaleem a root resolver should be in Parcel by default, also for html assets which do need to support '/' but this PR could be easily achieved with babel-plugin-module-resolver.
You can have a look at #290

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

Successfully merging this pull request may close these issues.

3 participants