-
Notifications
You must be signed in to change notification settings - Fork 532
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
Convert webflow example to use esnext modules #15940
Conversation
const extensionsRegex = /\.css$/;
/**
* This uses the node loader API (see https://nodejs.org/docs/latest-v16.x/api/esm.html#loaders)
* to enable webpack-style imports of .css modules.
*
* This is the recommended successor to `require.extensions`, which was used by https://www.npmjs.com/package/ignore-styles
* to accomplish the same thing.
*/
export async function load(url, context, nextLoad) {
if (extensionsRegex.test(url)) {
return {
format: "json",
shortCircuit: true,
source: "{}",
};
}
// Defer to the next hook in the chain.
return nextLoad(url, context);
} but this seems like it'd have more maintenance burden and doesn't handle edge cases as well (e.g. the fact that the loader api changed in 16.12). |
⯅ @fluid-example/bundle-size-tests: +529 Bytes
Baseline commit: fd14d50 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to leave a comment about using --experimental-loader
, but it seems like you did your due-diligence there. I don't know how much we gain from using esm-loader-css
. If the API changes and the package is unmaintained, don't we end up in the same situation as using our own implementation?
export { FlowDocument } from "./document/index.js"; | ||
export { Editor } from "./editor/index.js"; | ||
import { WebFlow, WebflowView } from "./host/index.js"; | ||
export { htmlFormatter } from "./html/formatters.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly for my own understanding, but does anything currently enforce the pattern of creating an index.ts
file and re-exporting from there? If so, does the change to ESNext have any effect on that enforcement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. My understanding of the more recent history of it is that:
index.js
files are handled specially by the CJS module loader in that an import to ./foo
would attempt to look for files ./foo.js
, ./foo/index.js
, and analogous files with any extensions registered by require.extensions
.
I'm guessing this behavior came out of the fact that JS package publishers did not have good ways to "map" the files in their project to valid imports for consumers, so an index convention was settled.
Since then, the esnext format has largely solved that problem (packages can expose subpaths, import specifications are much more well-behaved and understood across the ecosystem) and so does away with the more egregious artifacts of cjs loaders.
All these changes do is basically make "where is this file located" more explicit. You'll still get the same compile-time validation if you try to import from ./has-no-index/index.js
but that folder is bogus.
Perhaps, but the package already does better than writing our own loader in 2 cases:
|
Description
This makes progress toward #15917 by converting @fluid-example/webflow to use esnext modules.
This is the most involved update of any of the packages that depend on
@fluid-internal/test-version-utils
, since ESNext modules don't support therequire.extensions
api (they don't supportrequire
), which was the technique used to make webpack-style CSS imports not blow up when run in a node environment. Instead, it's recommended to use the node esm loader API. Although this API is experimental, it hasn't receive any changes between v16.12 and the node latest (v20.x).