Skip to content
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

Change imports for Node.js compatibility #4375

Closed
wants to merge 1 commit into from

Conversation

Johennes
Copy link
Contributor

@Johennes Johennes commented Aug 23, 2024

Fixes: #4287

This changes all imports to load .js files which seems to be the only way to make Node.js understand them.

This yarn builds and lets me run the Node.js example locally. However, tests are totally broken.

The replacements were done with the following shell script with folder imports scraped from #4373 (NB: this uses BSD sed):

while read -r file; do
    # Append .js to all imports
    sed -i '' -E 's/from "(\..*)"/from "\1.js"/' "$file"
    sed -i '' -E 's/import "(\..*)"/import "\1.js"/' "$file"

    # Fix folder imports to load index.js
    sed -i '' -E 's/\.\.js"/.\/index.js"/' "$file"
    sed -i '' -E 's/(\/algorithms)\.js"/\1\/index.js"/' "$file"
    sed -i '' -E 's/(\/channels)\.js"/\1\/index.js"/' "$file"
    sed -i '' -E 's/(\/crypto-api)\.js"/\1\/index.js"/' "$file"
    sed -i '' -E 's/(\/crypto)\.js"/\1\/index.js"/' "$file"
    sed -i '' -E 's/(\/http-api)\.js"/\1\/index.js"/' "$file"
    sed -i '' -E 's/(\/oidc)\.js"/\1\/index.js"/' "$file"
    sed -i '' -E 's/(\/store)\.js"/\1\/index.js"/' "$file"
    sed -i '' -E 's/(\/transports)\.js"/\1\/index.js"/' "$file"

    # Undo some of what we did above
    sed -i '' -E 's/(@types\/.*)\/index.js"/\1.js"/' "$file"
done < <(find src -name "*.ts")

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label Aug 23, 2024
@Johennes Johennes closed this Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

matrix-js-sdk no longer works in node
1 participant