steal
steal copied to clipboard
Remove /{name} == /{name}/{name}.js shorthand
Files named ./a/a.js
can currently be required as ./a
. This:
- is not compliant with CommonJS,
- unintuitive to any non-Steal user,
- breaks in all other loaders/bundlers,
- breaks IDEs and other module resolution tooling
👎 because I like this feature. I am fine with us de-emphasizing this in all our docs, but I don’t want to see it taken away completely.
Can you provide a code example? I haven't seen this happen personally.
@matthewp a few times people have done something like require("can-util/js/assign/") which is a steal thing From a thread in #team-open-source Jul 6th at 2:50 PM @matthewp but breaks in webpack, so I wanted to have a lint rule to prevent using that From a thread in #team-open-source Jul 6th at 2:51 PM
I'm recommending to completely remove this Steal thing.
Ah, ok, here the issue is the trailing /
, so require("./a")
should resolve to ./a.js
normally (if not there is a bug) and require("./a/")
is what will resolve to ./a/a.js
. I agree that this is a problem in OS projects that seek to be portable.
I sort of agree with you about this, but I've also seen a lot of users who use this feature. The reason it appears in the canjs code is because people are used to and like the feature in their app code.
It's worth noting that there are several stealjs features that allow people to write non-portable code, such as require("~/foo/bar")
or require("package/foo/bar")
(try the latter out in Node, it doesn't work).
What about a "compatibility mode" that throws when any of these things are used? Maybe something like:
<script src="./node_modules/steal/steal.js" compat-mode></script>
I've suggested that before, but I think you said it seemed bad to have an option that is basically "do things the right way." I care less about ~
and the !conditional/extension
because those things are new and additive to the CommonJS spec whereas this shorthand changes an existing meaning.
I understand people like it but it is jarring to novice and senior developers alike and breaks tooling like IDE autocomplete/auto-refactor. If it can be written as an optional add-on, that is fine because then the deviation is explicitly described and that person has assessed their trade-offs in choosing.
I am also for removing this as this will also not play well with modules they will super seed cjs anyway and depend on urls.