Skip to content

refactor(docs/ui): migrate to ES modules and add ESLint enforcement#263

Merged
GarthDB merged 2 commits intomainfrom
feat/esm-migration-docs-ui
Feb 17, 2026
Merged

refactor(docs/ui): migrate to ES modules and add ESLint enforcement#263
GarthDB merged 2 commits intomainfrom
feat/esm-migration-docs-ui

Conversation

@GarthDB
Copy link
Copy Markdown
Member

@GarthDB GarthDB commented Feb 17, 2026

Summary

Follow-up to #261 addressing reviewer feedback about the CommonJS → ESM migration in docs/ui.

  • Full CJS → ESM conversion: Converted all require() calls to import statements and all module.exports to export across ~70 JS files in docs/ui/src/
  • ESLint enforcement: Added eslint.config.js (flat config) with no-sequences and no-restricted-syntax rules to prevent CJS regressions and flag the comma-operator pattern going forward; added lint task to moon.yml
  • Bug fix: Corrected setTimeout(fn), 1000setTimeout(fn, 1000) in createSVGswatches.js, createXML.js, and createSVGuiKit.js (the comma operator was silently discarding the delay argument)
  • Dead code removal: Removed fs/posthtml blocks from src/index.js, src/theme.js, and src/tools.js — these Node.js APIs would never execute in a browser context
  • Readability: Refactored comma-operator chained assignments (e.g. (this._swatches = swatches), (this._colorKeys = colorKeys)) into separate statements in initialSequentialScale.js, initialDivergingScale.js, and colorScaleQualitative.js

Test plan

  • Dev server starts cleanly (pnpm moon run ui:dev)
  • Theme page loads and renders color swatches / contrast ratios
  • Scales page renders sequential color gradient with hex output
  • Tools page loads without errors
  • Run pnpm moon run ui:lint to verify ESLint passes with no new violations

Made with Cursor

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>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 17, 2026

⚠️ No Changeset found

Latest commit: 323cd0c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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>
@GarthDB GarthDB merged commit a890f8b into main Feb 17, 2026
3 checks passed
@GarthDB GarthDB deleted the feat/esm-migration-docs-ui branch February 17, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant