-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add a strict
option for path resolution
#13
Comments
As a workaround, I wrote my own extension. I post it here so that you understand the logic I meant: {
resolveId (file, origin) {
if (file.charAt(0) === '/') {
return file
} else if (file.charAt(0) === '.') {
const basePath = path.dirname(origin)
return fileExists(path.join(basePath, file))
|| fileExists(path.join(basePath, file + '.js'))
} else {
return fileExists(path.join(__dirname, 'src', file))
|| fileExists(path.join(__dirname, 'src', file + '.js'))
|| fileExists(path.join(__dirname, 'src', file, 'index.js'))
}
function fileExists (file) {
try {
let stat = fs.statSync(file);
return stat.isFile() && file || null;
} catch (e) {
return null;
}
}
}
} my options for includepaths({
external: [],
paths: [ 'src' ],
relativeStrict: true,
extensions: [ '.js', '.json', '.html' ]
}), |
I've been thinking about this issue and it seems a bit complicated to cover all cases. What if you have both cases in the same project? e.g a file called If you prepend the file with a slash ('/events') that would in turn shadow imports with an absolute path if the logic changes. Correct me if I'm wrong, but this confusion is caused by a "sloppiness" in the way Node.JS resolves the file paths. What do you think? |
As i understand it, the resolve mechanism is as follows:
I would like to add a "strict" mode so that the first strategy only applies to path starting with either
/
,./
or../
.I currently have a problem with file names (e.g. events) conflicting with node modules, causing
A module cannot import itself
errors.The text was updated successfully, but these errors were encountered: