Skip to content

fix: Compile TS to JS during packaging - #8000

Open
camdecoster wants to merge 6 commits into
mainfrom
cam/7995/convert-ts-js-publish
Open

fix: Compile TS to JS during packaging#8000
camdecoster wants to merge 6 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants