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

[ASI-837] Allow typescript + javascript interoperability in content-node #2816

Merged
merged 11 commits into from
Apr 2, 2022

Conversation

dmanjunath
Copy link
Contributor

@dmanjunath dmanjunath commented Apr 1, 2022

Description

Currently in content-node typescript was hard to integrate because we couldn't have something like
index.ts -> file.js -> new_file.ts where -> means requires()
to incrementally switch to TS.

However, with this option changed we can now have the above dependency graph.

Tests

Tested this locally and took it out to stage creator node 4 to make sure it compiles, comes up and serves requests.

I converted the hashids.js file to hashids.ts and added a log to tracks.js to print out the encoded id for 6. This demonstrates that ts can require a js file which can require another ts file with full interoperability

tracks.js

...
console.log("encode", encode(6))

logs

[nodemon] restarting due to changes...
[nodemon] starting `node --inspect=0.0.0.0:${debuggerPort} --require ts-node/register src/index.ts`
Debugger listening on ws://0.0.0.0:9230/fcd9455d-026f-4c13-873a-ee68b6ad0836
For help, see: https://nodejs.org/en/docs/inspector
Warning: configuration param 'awsBucket' not declared in the schema
configuration param 'awsAccessKeyId' not declared in the schema
configuration param 'awsSecretAccessKey' not declared in the schema
[2022-04-01T21:08:45.390Z]  INFO: audius_creator_node/946 on 4a6076489df1: Loglevel set to: debug
Fri, 01 Apr 2022 21:08:57 GMT sequelize deprecated The logging-option should be either a function or false. Default: console.log at node_modules/sequelize/lib/sequelize.js:196:13
encode AnlGe

How will this change be monitored? Are there sufficient logs?

Services won't start if there's a bug here. Health check would immediately identify this

@dmanjunath dmanjunath marked this pull request as ready for review April 1, 2022 21:19
Copy link
Contributor

@dylanjeffers dylanjeffers left a comment

Choose a reason for hiding this comment

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

great catch! looks like we need to update tests to be ts-compatible, maybe have to add ts-mocha? have a look in libs package.json for an example

@dmanjunath
Copy link
Contributor Author

@dylanjeffers yes! i'm working on that now. thanks for paving the way 🙂

@pull-request-size pull-request-size bot added size/M and removed size/XS labels Apr 1, 2022
@@ -1071,8 +1073,7 @@ describe('test Polling Tracks with real files', function () {
.set('User-Id', userId)
.send(trackMetadata)
.expect(200)
trackMetadataMultihash = trackMetadataResp.body.data.metadataMultihash
trackMetadataFileUUID = trackMetadataResp.body.data.metadataFileUUID
const trackMetadataFileUUID = trackMetadataResp.body.data.metadataFileUUID
Copy link
Contributor Author

@dmanjunath dmanjunath Apr 2, 2022

Choose a reason for hiding this comment

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

these were never actually defined as variables and it was now throwing an error with ts-node

@@ -3,7 +3,7 @@
"baseUrl": "./src",
"pretty": true,
"target": "es2020",
"module": "es2020",
"module": "commonjs",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the actual fix, confirmed by dylan with link to official tsconfig files https://github.com/tsconfig/bases/blob/main/bases/node16-strictest.combined.json#L10

@dmanjunath dmanjunath changed the title Allow typescript + javascript interoperability in content-node [ASI-837] Allow typescript + javascript interoperability in content-node Apr 2, 2022
@@ -27,7 +27,7 @@ const {
} = require('../middlewares')

const { getCID } = require('./files')
const { decode } = require('../hashids.js')
const { decode } = require('../hashids')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have to omit the extension because locally it's reading the ts file but in the prod image it's using a transpiled version of js. the transpiled version should be 1-1 to the ts so functionally the same

@dmanjunath
Copy link
Contributor Author

@dylanjeffers tests pass now, i also took it out to one of our stage content nodes and tested the new function that was moved to typescript so the transpile to the static build/ folder also seems to work. if you wanted to take one more look before merge

Copy link
Contributor

@dylanjeffers dylanjeffers left a comment

Choose a reason for hiding this comment

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

Looks great!

@dmanjunath dmanjunath merged commit 4360da3 into master Apr 2, 2022
@dmanjunath dmanjunath deleted the dm-fix-typescript-requires branch April 2, 2022 18:38
@AudiusProject AudiusProject deleted a comment from linear bot Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants