Arbitrary dependencies syntax+approach #87
Replies: 6 comments 3 replies
-
we may be able to draw inspiration from Deno since it relies on url-based npm imports https://docs.deno.com/runtime/manual/node/cdns |
Beta Was this translation helpful? Give feedback.
-
Overall BOS Component SyntaxThe design of imports will be heavily affected by the decision on whether to continue writing BOS components as only the body of a function component or move to writing the full function declaration. Imports must be declared at the top level in JS, so there is no obvious syntax when writing components in their current form Writing the full function declaration would offer some unrelated advantages (e.g. TypeScript, prop handling) so it is already under consideration Full URL vs Package-onlyFor each syntax variation, we can consider two cases: specifying the full dependency URL or specifying only the package+version. If specifying only the package+version, the full dependency URL would be built by either using a package provider configured elsewhere (i.e. gateway settings) or by having the developer create an import map to be applied to their component code. import map example: {
"imports": {
"moment": "https://esm.sh/[email protected]"
}
} Specifying the full URL has simplicity advantages and provides flexibility for developers, but package-only would likely be more robust since multiple package-providers could be used leading to stronger decentralization of the system. If a single package provider going offline or being inaccessible in a certain region prevents a BOS component from rendering, then that negates much of the decentralization benefit of BOS. BrainstormingFunction body onlyAll of the following would be stripped from the source before loading it into the iframe Mock function callTreats import like a function taking a string param of the package const moment = import('[email protected]');
//or
const moment = import('https://esm.sh/[email protected]'); Could be confusing since users may try to use a variable as the param but that would not be allowed since imports must be handled statically CommentSpecifies the package in a comment above a variable which will reference the import after compilation // @import [email protected]
const moment;
//or
// @import https://esm.sh/[email protected]
const moment; Full function declarationThis approach is pretty straightforward and fulfills our goal of being minimally different from vanilla React. Essentially, BOS component source would become a full module and look like a JSX file. import moment from "moment";
// or
import moment from "https://esm.sh/[email protected]"
export function Component(props) {
return <div>{moment().format("[Today is] dddd")}</div>;
} |
Beta Was this translation helpful? Give feedback.
-
Excellent writeup ❤️
I like leaving the CDN host as runtime configuration, but I'm concerned there could be too much variability in how bundles are served and where they are available. It may not make sense for us to maintain compatibility matrices if that's what it comes down to. In any case, giving developers the option to override with an explicit URL would be my preferred approach here. Also a big fan of developer-maintained importmaps that get injected at compile time. Providing developers the option to maintain dependencies centrally across all their Components simplifies maintenance and promotes consistency between interdependent Components.
I agree that this approach could be confusing. Invoking it gives the impression that it's a dynamic import, which is basically the one thing our implementation won't be 😄
I like this approach from an implementation perspective - it's easily parseable and easy to reconcile. But it does feel a bit too much like an interim solution.
I think this is my favorite. It requires some exploration in Component compilation but seems viable. The I am a little concerned about what happens in module scope between the imports and function declaration, but this can always be ignored (to the detriment of any Component code that does reference it). However supporting this also opens the door to defining multiple React components inside a single BOS Component's source, which could be useful as a DX enhancement. |
Beta Was this translation helpful? Give feedback.
-
Great writeup! I'm on the same page as @andy-haynes. Full function declaration would definitely be my vote:
In general, I think it's really important to match the syntax of a typical React application as much as possible. Definitely agree with Andy here on import maps and explicit URL imports. Supporting both would be great:
|
Beta Was this translation helpful? Give feedback.
-
Seems like we're all on the same page here that full function declaration is the preferred solution and can proceed with implementation exploration |
Beta Was this translation helpful? Give feedback.
-
Now that the I'm thinking we support only the following for this implementation:
|
Beta Was this translation helpful? Give feedback.
-
Arbitrary dependency support is one of the most impactful features planned for BWE. The implementation could take a number of different forms. Let's get started on syntax design
The solution should:
The solution need not:
Beta Was this translation helpful? Give feedback.
All reactions