GithubHelp home page GithubHelp logo

Comments (2)

matthieusieben avatar matthieusieben commented on July 19, 2024

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 would be as follows

includepaths({
  external: [],
  paths: [ 'src' ],
  relativeStrict: true,
  extensions: [ '.js', '.json', '.html' ]
}),

from rollup-plugin-includepaths.

darlanalves avatar darlanalves commented on July 19, 2024

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 events.js in the root folder (src) and another file trying to use the builtin events module. If both use the same import name ('events'), is impossible to determine which is which.

If you prepend the file with a slash ('/events') that would in turn shadow imports with an absolute path if the logic changes.
If you only resolve files starting with ./ or ../, you have to "hardcode" the entire path to "events.js" somehow.

Correct me if I'm wrong, but this confusion is caused by a "sloppiness" in the way Node.JS resolves the file paths.
ES6 module syntax should always include the file extension in the module path ("events.js"). I'm not sure if that resolves all cases, but I think in your case you should use the file extension to differentiate between a file import ('events.js') and a builtin module import ('events'), rather than changing the resolution logic.

What do you think?

from rollup-plugin-includepaths.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.