Skip to content

Conversation

@SiyaoIsHiding
Copy link
Collaborator

Feel bad for this PR that changes 200+ files 😭
This PR mostly consists of:

  1. Massive renaming file extensions from .js to .ts
  2. Change the CommonJS import syntax (require) to ESM import syntax (import). This step is mostly done by ts2esm tool with some manual fixes.
  3. Api-extractor generated files to track API changes. Including api-extractor.json, dist/cassandra-driver.d.ts, and etc/cassandra-driver.api.md.

The focus of the review of this PR would be on all those index.ts, and metadata files like tsconfig.json. You can also run tsc -p . to inspect the generated .js and .d.ts files.

I tested out with a client project with the following package.json, (remember to change type to module when testing for ESM syntax).

{
  "name": "nodejs-client",
  "version": "1.0.0",
  "description": "",
  "type":"commonjs", // change this to "module" when testing for ESM
  "scripts": {
    "start": "tsc -p . ; node dist/server.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/express": "^5.0.0",
    "@types/node": "^22.10.2",
    "typescript": "^5.7.2"
  },
  "dependencies": {
    "@SiyaoIsHiding/cassandra-driver": "file:../nodejs-driver",
    "express": "^4.21.2"
  }
}

And the following tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "NodeNext",
    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,  
    "strict": true,
    "skipLibCheck": true
  }
}

The following import syntaxes all work. They can be recognized by TypeScript server to compile to JavaScript, the type hinting is correct, and the compiled JavaScript code can run.

const cassandra = require('@SiyaoIsHiding/cassandra-driver');
const {Client} = require('@SiyaoIsHiding/cassandra-driver');
import cassandra, { datastax } from '@SiyaoIsHiding/cassandra-driver';

@SiyaoIsHiding
Copy link
Collaborator Author

I found out this PR is against the wrong branch master. Closing this because I created another PR against the branch typescript.

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