-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Meta: drop magic globals in favor of importing the readme
#5049
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
Conversation
| rules: [ | ||
| { | ||
| test: /readme\.md?$/, | ||
| loader: './build/readme.loader.cts', |
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'm using .cts here because .ts produces .js, which is interpreted as ESM due to type:module, but webpack’s ts-node requires it. This instead produces .cjs
| @@ -0,0 +1,8 @@ | |||
| // Can't use modules because this is a bizarropackscript world | |||
| module.exports = async function ReadmeLoader () { | |||
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.
In reality webpack passes the readme’s content here, so it could use it instead of reading it from disk again (future PR?)
| module.exports = async function ReadmeLoader () { | |
| module.exports = async function ReadmeLoader (readmeText) { |
build/readme.loader.cts
Outdated
| module.exports = async function ReadmeLoader () { | ||
| const {getFeatures, getFeaturesMeta} = await import("./readme-parser.js"); | ||
| return ` | ||
| export const features = ${JSON.stringify(getFeatures())}; |
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.
This in reality reads the list of enabled features from the refined-github.ts. It could be replaced by a hook that reads the files directly from webpack’s tree… but this function is also used by the feature checker…
| // Passing `true` as the second argument makes these values dynamic — so every file change will update their value. | ||
| __features__: webpack.DefinePlugin.runtimeValue(() => JSON.stringify(getFeatures()), true), | ||
| __featuresMeta__: webpack.DefinePlugin.runtimeValue(() => JSON.stringify(getFeaturesMeta()), true), | ||
| __filebasename: webpack.DefinePlugin.runtimeValue(info => JSON.stringify(path.parse(info.module.resource).name)), |
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.
PR welcome to drop this too
Tiny function like
getFilename(import.meta.url)to replace__basefilename
importing the readme
Pros
Cons