Giter Site home page Giter Site logo

Comments (3)

dhh avatar dhh commented on August 15, 2024 1

It's happening to support that library/index.js can be referenced as library.js. But it's not intended that library_index.js is transformed. Please do explore a fix!

from importmap-rails.

mylons avatar mylons commented on August 15, 2024

Ah, it does appear this is happening on purpose. I'm curious why? Should I rename my files?

[ mapping.under, filename.to_s.remove(filename.extname).remove(/\/?index$/).presence ].compact.join("/")

Looking at the rest of the repo it's not obvious as to why a file ending in index should have that removed

from importmap-rails.

Caleb-T-Owens avatar Caleb-T-Owens commented on August 15, 2024

Breaking down the regex, it's scanning for:

  • \/? ← Matches one or zero / characters
  • index ← Matches the word index
  • $ ← Matches the end of a line

This is to try and match the following examples:

  • index.js
  • folder/index.js

But because it looks for 0 or 1 /, it also picks up super_index.js

I'm going to put together a PR updating this regex to /(:\/|^)index$/ which broken down is:

  • (: ← Start non-capturing group
    • \/ ← Matches the / character
    • | ← OR operator
    • ^ ← Matches the start of the string
  • ) ← Close group
  • index ← Matches the word index
  • $ ← Matches the end of a line

Which will still match

  • index.js
  • folder/index.js
    but specifically won't match super_index.js because we're now require either the string to start or the character / right before the word index

from importmap-rails.

Related Issues (20)

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.