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 source code to TypeScript #343

Open
styfle opened this issue Apr 1, 2019 · 17 comments
Open

Change source code to TypeScript #343

styfle opened this issue Apr 1, 2019 · 17 comments
Labels
enhancement New feature or request

Comments

@styfle
Copy link
Member

styfle commented Apr 1, 2019

We like TypeScript. Let's write the source code for ncc in TypeScript.

Note: default exports are painful to deal with CJS/ESM interop so maybe use a named export instead.

@styfle styfle added the enhancement New feature or request label Apr 1, 2019
@styfle styfle self-assigned this Apr 1, 2019
@fkhadra
Copy link
Contributor

fkhadra commented Apr 2, 2019

Hey are you looking for help ?

@styfle
Copy link
Member Author

styfle commented Apr 2, 2019

@fkhadra Yes, if you are interested.

I was going to use this tsconfig.json:

{
  "compilerOptions": {
    "declaration": true,
    "esModuleInterop": true,
    "lib": ["esnext"],
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "./dist",
    "types": ["node"],
    "strict": true,
    "target": "esnext",
    "typeRoots": [
      "./types",
      "./node_modules/@types"
    ]
  }
}

Do you want to make a PR?

@axetroy
Copy link
Contributor

axetroy commented Apr 2, 2019

There is no doubt that Typescript is undoubtedly the best programming method at this moment.

you can consider refactoring with Typescript before project become bigger and bigger.

@fkhadra
Copy link
Contributor

fkhadra commented Apr 2, 2019

Hey @styfle sure for the PR, it would be nice. Is there a commit convention that I have to follow ? Thank you

@styfle
Copy link
Member Author

styfle commented Apr 2, 2019

@fkhadra No, we squash on merge

@fkhadra
Copy link
Contributor

fkhadra commented Apr 3, 2019

Hey @styfle, I started to work on it. https://github.com/fkhadra/ncc/tree/move-to-ts

I took your tsconfig and changed the outDir to ’./tsbuild’ just the time to migrate all the code base.

When I migrate a file to typescript I require the compiled version as shown below then I run all the test suite to ensure that nothing is broken.

const { shebangRegExp } = require('../tsbuild/utils/shebang');

I saw that the default export of get-package-base file was not used so I removed it.

I have migrated the files inside the src/utils directory to TS at that time.

What do you think about that workflow ? Do you have a better idea ? Thank you

@styfle
Copy link
Member Author

styfle commented Apr 3, 2019

@fkhadra That sound about right. Can you submit the PR so I can review?

@styfle
Copy link
Member Author

styfle commented Apr 3, 2019

FYI, we don't need to change the source code of tests right now. Let's prove that tests still work without changing them.

@fkhadra
Copy link
Contributor

fkhadra commented Apr 4, 2019

@styfle I underestimated the work needed to migrate to typescript 😭, I think that some task needs to be done up front.

There are 2 tests that fail when I add the latest version of typescript 3.4.1 or @types/node. The test that failing are the one related to typescript. I'm trying to find why.

The issue can be reproduced as follow:

  • clone the repository(wanted to get a fresh copy)
  • yarn (install packages)
  • yarn test

Screenshot 2019-04-04 at 21 17 33

- yarn add typescript@latest - yarn test

Screenshot 2019-04-04 at 21 20 36

Ncc uses arg v2, we can upgrade to the latest version(v4) without touching a single line of code. The nice thing is that the v4 ship with a ts definition file. I can make a separate PR for that one if you want to.

PS: Should I open an issue for the typescript dependency ?

@styfle
Copy link
Member Author

styfle commented Apr 4, 2019

Yes please upgrade arg, thanks! 👍

styfle pushed a commit that referenced this issue Apr 4, 2019
This version include a type definition for typescript. This will help for #343
@styfle
Copy link
Member Author

styfle commented Apr 19, 2019

@fkhadra Any update on this?

We had to add types to the node builder recently because ncc doesn't expose any 😢

https://github.com/zeit/now-builders/blob/375874e9894facb87dfc7e1dd254a6ad5a919dd9/packages/now-node/src/watcher.ts

@fkhadra
Copy link
Contributor

fkhadra commented Apr 19, 2019

Hey @styfle, I still have the issue #343 (comment) regarding the tests.
I don't know what I'm missing about that one. Do you have any idea ?

@styfle
Copy link
Member Author

styfle commented Apr 19, 2019

@fkhadra I thought the problem was with arg but I guess that was not related to the test failures.

Where is the repo? The link you posted above is dead: https://github.com/fkhadra/ncc/tree/move-to-ts

Maybe you could submit a PR?

@fkhadra
Copy link
Contributor

fkhadra commented Apr 19, 2019

@styfle you can reproduce the issue with the current master branch. You don't even need to change a single line of code :(.

I deleted my repo since I wanted to fix this issue first.

@fkhadra
Copy link
Contributor

fkhadra commented Apr 22, 2019

Hey @styfle were you able to reproduce the issue ?

@styfle
Copy link
Member Author

styfle commented Apr 30, 2019

@fkhadra Sorry, too busy to look into this one since its lower priority right now.

@fabiospampinato
Copy link

Note: default exports are painful to deal with CJS/ESM interop so maybe use a named export instead.

FYI, if I'm understanding this correctly, I have a bit of a package that allows default exports to be imported normally, with require ( 'pkgname' ), under CJS.

@styfle styfle removed their assignment Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants