X Tutup
Skip to content

refactor(honkit): Convert JavaScript to TypeScript#112

Merged
azu merged 15 commits intomasterfrom
ts-migrate
Aug 24, 2020
Merged

refactor(honkit): Convert JavaScript to TypeScript#112
azu merged 15 commits intomasterfrom
ts-migrate

Conversation

@azu
Copy link
Member

@azu azu commented Aug 19, 2020

This PR convert all JavaScript code to TypeScript in HonKit core.

Airbnb released a migration tool for TypeScript that is called ts-migrate.

We have tried it in HonKit codebase.

Steps

  1. npn install ts-migrate
  2. ts-migrate-full package/honkit
  3. require to import
    https://github.com/azu/commonjs-to-es-module-codemod
  4. Fix a bit of code manually

fix #56
refs #24

}

module.exports = decodeGlobal;
export { decodeGlobal };
Copy link
Member Author

Choose a reason for hiding this comment

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

After did ts-migrate-full, TypeScript show compiler error it

Error:(11, 10) TS2393: Duplicate function implementation.

?? I can not understand it. but I have replaced module.export to export and fixed it.

@azu
Copy link
Member Author

azu commented Aug 19, 2020

We need to fix tsconfig.json at first.

Retry it and I get other error message

Error: [ts-ignore][src/utils/git.ts] Error:
 Error processing request. Cannot read property 'parent' of undefined
TypeError: Cannot read property 'parent' of undefined
    at transformTopLevelDeclaration (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:93386:55)
    at visitDeclarationStatements (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:93323:26)
    at Object.visitNodes (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:74699:48)
    at transformRoot (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:92707:37)
    at transformation (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:93947:24)
    at transformRoot (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:93968:82)
    at Object.map (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:401:29)
    at Object.transformNodes (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:93954:30)
    at Object.getDeclarationDiagnostics (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:92446:25)
    at /Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:101045:27
    at runWithCancellationToken (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:100754:24)
    at getDeclarationDiagnosticsForFileNoCache (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:101042:20)
    at getAndCacheDiagnostics (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:101055:26)
    at getDeclarationDiagnosticsWorker (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:101039:20)
    at getDeclarationDiagnosticsForFile (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:101068:56)
    at getDiagnosticsHelper (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:100693:24)
    at Object.getDeclarationDiagnostics (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:100738:24)
    at Object.getSemanticDiagnostics (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:138883:50)
    at /Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:148619:140
    at IOSession.Session.getDiagnosticsWorker (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:148484:35)
    at IOSession.Session.getSemanticDiagnosticsSync (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:148619:29)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:147955:61)
    at /Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:149555:88
    at IOSession.Session.executeWithRequestId (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:149546:28)
    at IOSession.Session.executeCommand (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:149555:33)
    at IOSession.Session.onMessage (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:149579:35)
    at Interface.<anonymous> (/Users/azu/.nodebrew/node/v14.5.0/lib/node_modules/ts-migrate/node_modules/typescript/lib/tsserver.js:150895:27)
    at Interface.emit (events.js:314:20)
    at Interface._onLine (readline.js:337:10)
    at Interface._normalWrite (readline.js:482:12)
    at Socket.ondata (readline.js:194:10)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:304:12)
    at readableAddChunk (_stream_readable.js:280:9)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)```

@azu azu changed the title try ts-migrate refactor(honkit): Convert JavaScript to TypeScript Aug 24, 2020
#! /usr/bin/env node

require("../lib/bin.js")
require("../lib/src/bin.js")
Copy link
Member Author

Choose a reason for hiding this comment

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

fix to the path, because honkit defined import "../package.json" and it change output path

import encodeGlobal0 from "./encodeGlobal";

export default {
encodePage: encodePage0,
Copy link
Member Author

Choose a reason for hiding this comment

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

https://github.com/azu/commonjs-to-es-module-codemod does not support this convert.
So, I've changed this pattern manually.

@azu azu mentioned this pull request Aug 24, 2020
@azu azu added Type: Refactoring A code change that neither fixes a bug nor adds a feature Type: TypeScript labels Aug 24, 2020
@azu azu merged commit ed8ec44 into master Aug 24, 2020
@azu azu deleted the ts-migrate branch August 24, 2020 15:51
@azu azu mentioned this pull request Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Refactoring A code change that neither fixes a bug nor adds a feature Type: TypeScript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

X Tutup