-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Shorten minified error URL to reduce production bundle size #4677
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "mobx": patch | ||
| --- | ||
|
|
||
| Shorten minified error URL to reduce production bundle size. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const { writeFileSync } = require("fs") | ||
| const { relative, resolve } = require("path") | ||
|
|
||
| const repoRoot = resolve(__dirname, "../..") | ||
| const errorsPath = resolve(repoRoot, "packages/mobx/src/errors.ts") | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mweststrate the change was merged but it doesn't seem to be deploying to prod. I can’t see the logs, but my suspicion is that the Node version is outdated wherever we build the docs. Node 24 locally imports the |
||
| const outputPath = resolve(repoRoot, "docs/errors.md") | ||
|
|
||
| globalThis.__DEV__ = true | ||
| const { niceErrors } = require(errorsPath) | ||
|
|
||
|
kubk marked this conversation as resolved.
|
||
| function formatMarkdownCell(message) { | ||
| let value = message | ||
|
|
||
| if (typeof message === "function") { | ||
| // Render dynamic errors with visible placeholders instead of real runtime values | ||
| const match = message.toString().match(/^[^(]*\(([^)]*)\)/) | ||
| const params = match ? match[1] : "" | ||
| const names = params.split(",").map(name => name.trim()).filter(Boolean) | ||
| const args = names.map(name => `{${name}}`) | ||
| value = message(...args).replace("String", args[0]) | ||
| } | ||
|
|
||
| // Keep the generated table valid Markdown | ||
| return String(value).replace(/\r?\n/g, "<br />").replace(/\|/g, "\\|") | ||
| } | ||
|
|
||
| function renderDocs(errors) { | ||
| const rows = Object.keys(errors) | ||
| .sort((left, right) => Number(left) - Number(right)) | ||
| .map(code => `| ${code} | ${formatMarkdownCell(errors[code])} |`) | ||
| .join("\n") | ||
|
|
||
| return `--- | ||
| title: MobX error codes | ||
| sidebar_label: Error codes | ||
| hide_title: true | ||
| custom_edit_url: https://github.com/mobxjs/mobx/edit/main/packages/mobx/src/errors.ts | ||
| --- | ||
|
|
||
| <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CEBD4KQ7&placement=mobxjsorg" id="_carbonads_js"></script> | ||
|
|
||
| # MobX error codes | ||
|
|
||
| In development builds, MobX throws full error messages. Production builds replace known messages with short numeric codes to keep the published bundle smaller. | ||
|
|
||
| | Code | Message | | ||
| | ---- | ------- | | ||
| ${rows} | ||
| ` | ||
| } | ||
|
|
||
| const docs = renderDocs(niceErrors) | ||
| writeFileSync(outputPath, docs) | ||
|
|
||
| console.log(`Generated ${relative(repoRoot, outputPath)} from ${relative(repoRoot, errorsPath)}`) | ||
Uh oh!
There was an error while loading. Please reload this page.