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

Would you consider exposing a sync resolve function? #46

Closed
johnnyreilly opened this issue Oct 31, 2016 · 5 comments
Closed

Would you consider exposing a sync resolve function? #46

johnnyreilly opened this issue Oct 31, 2016 · 5 comments

Comments

@johnnyreilly
Copy link
Contributor

Both awesome-typescript-loader and ts-loader are presently rolling their own sync resolver functions. It'd be great to get official support for this directly. Is that something you'd consider supporting? I suspect there may well be others out there similarly implementing this by hand as well.

cc @jbrantly @s-panferov

@niieani
Copy link

niieani commented Nov 19, 2016

If possible, it would be useful for my webpack dependency suite too. Would be especially useful if the sync resolve function could return cached values from the async resolve in case the FS is async in the calling context.

@johnnyreilly
Copy link
Contributor Author

So it turns out this is catered for; just not really documented. I've written a blog post about it here. The TL;DR; show me an example is:

const node = require("enhanced-resolve/lib/node");

function makeSyncResolver(options) {
    return node.create.sync(options.resolve);
}

const resolveSync = makeSyncResolver(loader.options);

const resolvedFileName = resolveSync(
    undefined,
    'C:\source\ts-loader\.test\babel-issue92',
    './submodule/submodule'
);

// resolvedFileName: C:\source\ts-loader\.test\babel-issue92\submodule\submodule.tsx

@niieani
Copy link

niieani commented Dec 11, 2016

@johnnyreilly Would this work with a custom fs though?

@johnnyreilly
Copy link
Contributor Author

I haven't tried - have a go!

@mikesherov
Copy link
Contributor

@johnnyreilly please feel free to open a PR to the documentation of this repo (the README) describe this sync resolver. In the meantime, I'm going to consider this issue closed. Thanks!

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

No branches or pull requests

3 participants