-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make Ext import extensions consitent #2222
Comments
Let's discuss which extensions we want to allow in our Wasp file. The reasonable options I'm aware of are:
User feebackPoints raised by our users in Discord (thread):
So we should also consider how we want to handle Ext imports of non-js files (and if we'll ever have any). My thoughtsI'm leaning towards either option PROS of alowing only
|
What kind of errors do you think of?
I might not be objective, but this was never the point of confusion for me personally. Actually au contraire, I was confused when at some point working with node TS lib I needed to use
I don't understand this at all 👀
The same thing as what most modern bundlers do - handle it "internally" and bundle it. For example, in vite react app (or any other frameworks for that matter), you import your JS / JSX files with a simple file name (without extension) and assets such as PNG, Svgs etc - with extension. I think this is a "expected" behaviour by majority (..I dare speaking for majority...) |
I meant: If we only support extensionless imports, users will more often be correcting how they import things (than they would if we just supported everything).
We had a misunderstanding here.
Haha, no worries, the TS SDK is still in the works so it's normal you don't know the details. The basic idea is, once we implement the TS SDK, specifying files without extensions might be weirder than it is now. More specifically... This app.action('createTask', {
// Import without extension
fn: { name: 'createTask', file: 'actions' },
entities: [Task],
auth: true,
}) Might look stranger than this: app.action('createTask', {
// Import without extension
fn: { name: 'createTask', file: 'actions.js' },
entities: [Task],
auth: true,
}) Since the field's name is
Makes sense. Another thing to maybe consider is what happens when we introduce multiple languages. Extensions may com in handy then (but discussing this is probably looking too far into the future). |
@infomiho suggested (assuming we're sticking with the object ext import syntax) we do something like this: app.action('createTask', {
// Mind the key name changes
fn: { import: 'createTask', from: 'actions' },
entities: [Task],
auth: true,
}) But ideally we'd come up with a plugin that imports stuff normally (this will help us with the LSP as well). |
crazy thought probably, but what about instead of fn: { import: 'createTask', from: 'actions' }, you just import the function and pass it in, like import { createTask } from "@/actions";
app.action('createTask', {
// Mind the key name changes
fn: createTask,
entities: [Task],
auth: true,
}) this removes posslbe ambiguity of how to call files + it is a clear and predictable by devs way. |
Yeah, I think we all agree there 😄
This is precisely the problem - neither do I (yet), but this approach is what I meant when I said:
In any case, I'll be looking into it in the following weeks. Let's hope it's simple enough! |
What did Discord vote say, from what I got most people are for "no extension" option? |
It has issues with differentiating between named and default imports, but I forgot to mention it. Any ideas there? |
We don't allow default imports though, right? So in that way it is not an issue. If we wanted to allow for it, we could I guess add |
@Martinsos we allow default imports in the Wasp file (just tested this now) |
Ooooh you are right, I forgot. We don't allow multiple imports per one statement, but we do allow a default import, or one named import, no more no less. Ok then we will have to figure this out @sodic , sorry for wrong information! |
Summary
Issue spotted with Wasp 0.14.0.
Our allowed external import extensions are all over the place:
wasp start
don't agree on what's allowed.Let's fix this.
Details
There are three implicit categories of external imports (that I've discovered so far, there might be more). Each import falls into one or more of the categories:
Notice how Queries fall into two categories. That's because they're copied into the SDK and also directly imported on the server (we do this to give users better error messages).
Since different imports end up in different build contexts, they are subject to different constraints (one context allows certain extensions, the other allows other extensions), making the behavior look random and confusing to users.
We've made some attempts at fixing this, and we have issues that talk about the problem:
But we never fully committed to properly deciding what we allow and where. The situation got worse after 0.12.0, which introduced an additional context with its own set of import constraints (the SDK).
Solution
Craig made some good points here: #1363 (comment). He talks about two distinct but related problems:
We must:
By "mappings" I mean "mappings in Haskell and resolve configurations in the project."
Extra problem with the SDK build:
It's possible for the SDK build to pass, leaving extensions to cause problems in runtime. It happens with relative import references to files without extensions, and it also happened here: #2096 (comment).
I'm not yet sure 100% how this is possible. I'm guessing:
Ideally, we'd find a way to break the build if the import will be causing issues in runtime.
The text was updated successfully, but these errors were encountered: