Skip to content

Upgrade kuromojin #2

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

Merged
merged 2 commits into from
Jan 4, 2021
Merged

Upgrade kuromojin #2

merged 2 commits into from
Jan 4, 2021

Conversation

hata6502
Copy link
Member

No description provided.

Copy link
Member

@azu azu left a comment

Choose a reason for hiding this comment

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

Thanks for PR.

I've commented

import { RuleHelper } from "textlint-rule-helper";
import kuromojin from "kuromojin";
const { RuleHelper } = require("textlint-rule-helper");
const kuromojin = require("kuromojin");
Copy link
Member

Choose a reason for hiding this comment

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

Why use require?

Copy link
Member Author

Choose a reason for hiding this comment

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

When I use import kuromojin from "kuromojin";, the following error occured in yarn test.

  1) no-dropping-i
       見てます。:
     TypeError: Cannot read property 'tokenize' of undefined
      at /home/hata/textlint-rule-no-dropping-i/src/no-dropping-i.js:23:30
      at /home/hata/textlint-rule-no-dropping-i/node_modules/@textlint/kernel/src/task/promise-event-emitter.ts:27:35
      at Array.forEach (<anonymous>)
      at RuleTypeEmitter.PromiseEventEmitter.emit (node_modules/@textlint/kernel/src/task/promise-event-emitter.ts:26:38)
      at Controller.enter (node_modules/@textlint/kernel/src/task/textlint-core-task.ts:157:53)
      at Controller.__execute (node_modules/@textlint/ast-traverse/src/index.ts:51:31)
      at Controller.traverse (node_modules/@textlint/ast-traverse/src/index.ts:132:28)
      at TextLintCoreTask.startTraverser (node_modules/@textlint/kernel/src/task/textlint-core-task.ts:152:28)
      at TextLintCoreTask.start (node_modules/@textlint/kernel/src/task/linter-task.ts:43:14)
      at /home/hata/textlint-rule-no-dropping-i/node_modules/@textlint/kernel/src/task/task-runner.ts:28:18
      at new Promise (<anonymous>)
      at Function.TaskRunner.process (node_modules/@textlint/kernel/src/task/task-runner.ts:16:16)
      at LinterProcessor.process (node_modules/@textlint/kernel/src/linter/linter-processor.ts:55:27)
      at TextlintKernel._parallelProcess (node_modules/@textlint/kernel/src/textlint-kernel.ts:155:14)
      at /home/hata/textlint-rule-no-dropping-i/node_modules/@textlint/kernel/src/textlint-kernel.ts:83:25

And, it seems src/no-dropping-i.js uses CommonJS module.exports.

module.exports = function(context) {

So, I rewrote to CommonJS require().


Alternative solution: import * as

import * as kuromojin from "kuromojin";

いつも Twitter 経由で JSer.info を見させてもらっています。
本年はありがとうございました。

Copy link
Member

@azu azu Dec 31, 2020

Choose a reason for hiding this comment

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

tokenize is named exports.
We should use named import to import tokenize.

import { tokenize } from "kuromoji"

I like es imports.

Copy link
Member

@azu azu Dec 31, 2020

Choose a reason for hiding this comment

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

📝 We will change exports to export default, but it requires major updates.
(also rewrite it by TypeScript?)

Copy link
Member Author

@hata6502 hata6502 Dec 31, 2020

Choose a reason for hiding this comment

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

Fixed to use ESModules import.

@hata6502 hata6502 requested a review from azu December 31, 2020 05:21
@azu azu merged commit 0aff60a into textlint-ja:master Jan 4, 2021
@azu
Copy link
Member

azu commented Jan 4, 2021

@hata6502 hata6502 deleted the upgrade-kuromojin branch January 4, 2021 11:28
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