Skip to content

fix: Compile TS to JS during packaging - #8000

Merged
camdecoster merged 9 commits into
mainfrom
cam/7995/convert-ts-js-publish
Sep 1, 2026
Merged

fix: Compile TS to JS during packaging#8000
camdecoster merged 9 commits into
mainfrom
cam/7995/convert-ts-js-publish

Conversation

@camdecoster

Copy link
Copy Markdown
Contributor

Description

Compile TS down to JS during packaging (before publishing) to fix issue with Node resolution.

Closes #7995.

Also fixes TS issues discovered during investigation:

  • Fix Data type references
  • Update D3 types and move to dependency

Changes

  • Add script to compile TS to JS during packaging
  • Add test to check Node resolution
  • Add test to CI workflow
  • Exclude .ts files from packaging
  • Fix type references

Testing

  • Be on main
  • Run npm ci
  • Run the following command:
npm pack --pack-destination /tmp
mkdir -p /tmp/plotly-verify && cd /tmp/plotly-verify && npm init -y && npm i /tmp/plotly.js-4.0.0.tgz
node -e "console.log(require.resolve('plotly.js/src/lib/mod'))"
  • Note the resolution error
  • Switch to this branch
  • Run through the steps again
  • Note that there's no error

Notes

  • The error stemmed from the fact that Node doesn't resolve TS files when they're installed in node_modules
  • plotly.js points to its source in package.json (see main). Node therefore follows that path to resolve the package and it throws an error when it encounters a TS file.
  • This fix converts everything to JS before publishing so that the resolution completes correctly
  • Two other errors were fixed while working on this update:
    • The Data type in index.d.ts was being imported incorrectly
    • The d3 types were being imported incorrectly

@KoolADE85 KoolADE85 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple comments on the testing, but the solution itself is working well on my end.

Comment thread tasks/util/node_resolve_probe.js Outdated
Comment on lines +11 to +12
const { createRequire } = require('node:module');
const path = require('node:path');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude took me down this path as well while I was testing this out. To me, it feels a bit "one step removed" from a real-world validation. Could we instead write a more idiomatic import Plotly from "plotly.js"; and then assert the same things?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was all an attempt to run without npm install, but it's too complicated. I'll remove it in favor of GHA.

Comment thread tasks/test_node_resolve.mjs Outdated

@KoolADE85 KoolADE85 Sep 1, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason you write this as a util here?
To me, the file reads like a github action written in javascript. And it's doing some bizarre setup along the way that make the assertions seem a bit artificial.

Meanwhile, what we actually care about:

  1. Install the lib
  2. Import the lib
  3. Assert it worked

And that seems like an ideal case for a GH action or even just a unit test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I liked having the test locally, but it does fit better in GHA. I'll remove this file.

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per your suggestion, I moved the test into GHA and removed the local files.

Comment thread tasks/util/node_resolve_probe.js Outdated
Comment on lines +11 to +12
const { createRequire } = require('node:module');
const path = require('node:path');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was all an attempt to run without npm install, but it's too complicated. I'll remove it in favor of GHA.

Comment thread tasks/test_node_resolve.mjs Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I liked having the test locally, but it does fit better in GHA. I'll remove this file.

@KoolADE85 KoolADE85 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@camdecoster
camdecoster merged commit 389d256 into main Sep 1, 2026
85 of 86 checks passed
@camdecoster
camdecoster deleted the cam/7995/convert-ts-js-publish branch September 1, 2026 21:03
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.

[BUG]: v4.0.0 publishes uncompiled .ts sources that are required extensionless — package fails to load under Node's CJS resolver

2 participants