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

CJS to ESM #7311

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

CJS to ESM #7311

wants to merge 5 commits into from

Conversation

na9da
Copy link
Collaborator

@na9da na9da commented Nov 14, 2024

What this PR does

Convert CJS modules to ESM.

Required for #6998
Depends on: https://github.com/terriajs/terriamap/tree/cjs-to-esm

TODO:

  • Test node build

What this PR does:

  • Removes stale CJS files that are no longer used (395d3b9)

  • Convert CJS style module.exports to ESM style export default ... (7129b24)

  • Convert CJS require() to ESM import statements. (30654f1)
    This requires, in some places:

    • simply swapping require with import
    • creating a stub .d.ts module definition in lib/ThirdParty
    • updating the library to get new bundled type definitions
      • file-saver
      • react-responsive
    • or adding @types/x as dependency
      • @types/proj4

    Remaining require() imports are all for static assets or web workers which can be fixed when upgrading to webpack 5.

  • Remove use strict declaration for .tsx? files.

Test me

Test http://ci.terria.io/cjs-to-esm

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

These are files from TerriaJS V7 not referenced anywhere else.

Some of these might be useful if we want to port them to v8 in the future. If that's the case please refer to https://github.com/terriajs/terriajs/tree/terriajs7
This requires, in some places:
 - simply swapping require with import
 - creating a stub .d.ts module definition in lib/ThirdParty
 - updating the library to get new bundled type definitions
   - file-saver
   - react-responsive
 - or adding @types/x as dependency
   - @types/proj4

Remaining require() imports are all for static assets or web workers which can be fixed when upgrading to webpack 5.
It is redundant when using typescript.
@@ -113,7 +113,7 @@
"dompurify": "^2.3.3",
"fetch-mock": "^9.11.0",
"file-loader": "^3.0.1",
"file-saver": "^1.3.8",
"file-saver": "^2.0.4",
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a file-saver 2.0.5 released 4 years ago, is there a reason to not bump to that version?

@@ -195,6 +195,7 @@
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@types/dateformat": "^3.0.1",
"@types/node": "^18.15.11",
"@types/proj4": "^2.5.5",
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that the type annotations are required by tsc, so without them yarn gulp release will fail. Does yarn gulp release work for an external repository, like TerriaMap, if @types/proj4 is a devDependency here?

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.

2 participants