-
Notifications
You must be signed in to change notification settings - Fork 183
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
Lifting files and directories #5449
Comments
BTW, I think this might be a reasonable and simple solution until we have something more formal for #3736 |
I didn't know that, Chris! I prefer something along the modern syntax. |
@skyrpex any suggestions? |
What about a syntax similar to ESM's For example, |
I'm trying to better understand this:
If we don't care about runtime location, just build time location then I'm for just using |
The location is actually not the important piece (at least in most cases). If we go back to the fundamentals. What's the use case for This use case is relevant both for inflight and preflight of course (e.g. I want to bundle a .png as part of my inflight and use it). I am wondering if perhaps we need something a bit more higher level that will allow the compiler/bundler to do the right thing and package the assets into the relevant runtime context. Maybe something like: // this returns an `std.Asset` that represents the entire directory.
// "asset" is a builtin because the path it takes is relative to the *source file*.
let public = asset("./public");
test "print the index file" {
let index = public.readFile("index.html");
log(index);
}
test "print all files" {
for f in public.readdir() {
log(f);
}
} What do you all think? |
I like the asset idea and the solution probably has to be something like that (preflight relative path thing that binds into inflight with a way to access the data). I think it's unfortunate that we'd basically be duplicating the fs API on this though, and limiting to directories seems unnecessary. What if we do keep this scoped to paths and say "if you reference the lifted path inflight, it will exist"
|
@MarkMcCulloh I like this direction. It does imply that we won't be able to do any optimizations (i.e. just lift a single file instead of a directory) but it sounds like a premature optimization. In a sense, this is basically the use case of "lifting files" into inflight, which is not the same as referencing files in the project directory during preflight. I'll split into two issues. |
__dirname
)__dirname
)
__dirname
)__dirname
)
It's not part of the API but the user does still have the single-file option since there's no reason this can't work for individual files too.
The proposed solution of |
I like these ideas.
|
IDE path completion doesn't require special syntax, right now it's sufficient to be in a string and start with Also, unlike I'm not against special syntax, I think it'd be pretty cool, just want to make sure we choose it for a good reason. |
I am repurposing this issue to focus on lifting files and directories instead of |
__dirname
)
Y'all know I think we made a mistake with Maybe all these global builtins function-like should have some mark:
The |
Interesting discussion. So basically, Reminds me of the different asset handling techniques in bundlers. For example, see Vite's Static Asset Handling. You can import an image from a JavaScript file and what you get is the final URL: import imgUrl from './img.png'
document.getElementById('hero-img').src = imgUrl You can also use import suffixes to customize what's being imported: import workletURL from 'extra-scalloped-border/worklet.js?url'
CSS.paintWorklet.addModule(workletURL) or import shaderString from './shader.glsl?raw' |
The distinction with extern is that it's part of a declaration, not a plain expression. This kinda shows how the different syntax is useful, because the expectation of what If the mistake with
This was discussed before when the first globals were added. IMO a marker implies these things are special, but they're just global. |
I guess the difference is that the string passed to If it were a plain function, then it could be used as a value (passed to higher order functions, etc) and would produce the same asset when called in different directories with the same path argument, which sounds like it isn't the case.
It seems like the function is doing something special that can't be achieved in Wing userland |
That's fair, I was more arguing against the I do still think treating |
Yes, that's why I think it must be a special thing. Another way to think about it is to think about it as a primitive type ( let myFile: file = f"./my-file";
myFile.read();
myFile.path
myFile.extname
myFile.dirname The compiler compiles this to: const myFile = new std.File(path.join(__dirname, "./my-file")); Or something like this. What do y'all think? I kind of like the idea of a |
Related: #6108 |
Also Related: #6380 (TSOA resource) |
Use Case
I am looking for a way to reference files or directories (relative to source file).
Proposed Solution
Latest and greatest:
Component
Language Design, Compiler
Community Notes
The text was updated successfully, but these errors were encountered: