refactor(docs/ui): migrate to ES modules and add ESLint enforcement#263
Merged
refactor(docs/ui): migrate to ES modules and add ESLint enforcement#263
Conversation
Convert all CommonJS require()/module.exports usage in docs/ui/src to ES module import/export syntax for consistency with the rest of the codebase. Adds ESLint flat config with rules to enforce ESM going forward and flag any future CJS regressions. - Convert ~70 JS files from module.exports to named/default exports - Convert all require() calls to import statements (d3.js, utils.js, predefinedColorNames.js, and others) - Fix bug in createSVGswatches.js, createXML.js, createSVGuiKit.js where setTimeout(fn), 1000 was used instead of setTimeout(fn, 1000) - Remove dead code (fs/posthtml blocks) from src/index.js, src/theme.js, src/tools.js that would never execute in a browser context - Refactor comma-operator assignment patterns in initialSequentialScale.js, initialDivergingScale.js, colorScaleQualitative.js into separate statements (addresses PR #261 review feedback) - Add eslint.config.js with no-sequences and no-restricted-syntax rules to disallow require() and module.exports - Add eslint devDependency and lint task to moon.yml Co-authored-by: Cursor <cursoragent@cursor.com>
|
d3.js exports a single merged default object (export default d3plus),
so consumers must use `import d3 from './d3'` rather than
`import * as d3 from './d3'`. The namespace import returns
`{ default: d3plus }`, making d3.hsluv / d3.rgb / d3.lch undefined
at runtime and breaking the Parcel build.
Fixes: ui:buildSite CI failure
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #261 addressing reviewer feedback about the CommonJS → ESM migration in
docs/ui.require()calls toimportstatements and allmodule.exportstoexportacross ~70 JS files indocs/ui/src/eslint.config.js(flat config) withno-sequencesandno-restricted-syntaxrules to prevent CJS regressions and flag the comma-operator pattern going forward; addedlinttask tomoon.ymlsetTimeout(fn), 1000→setTimeout(fn, 1000)increateSVGswatches.js,createXML.js, andcreateSVGuiKit.js(the comma operator was silently discarding the delay argument)fs/posthtmlblocks fromsrc/index.js,src/theme.js, andsrc/tools.js— these Node.js APIs would never execute in a browser context(this._swatches = swatches), (this._colorKeys = colorKeys)) into separate statements ininitialSequentialScale.js,initialDivergingScale.js, andcolorScaleQualitative.jsTest plan
pnpm moon run ui:dev)pnpm moon run ui:lintto verify ESLint passes with no new violationsMade with Cursor