Meta: drop magic globals in favor of importing the readme - #5049
Conversation
| rules: [ | ||
| { | ||
| test: /readme\.md?$/, | ||
| loader: './build/readme.loader.cts', |
There was a problem hiding this comment.
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.
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) { |
| 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.
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.
PR welcome to drop this too
Tiny function like
getFilename(import.meta.url)to replace__basefilename
importing the readme
Pros
Cons