create-book icon indicating copy to clipboard operation
create-book copied to clipboard

Non-ASCII characters in directory name

Open MurakamiShinyu opened this issue 5 years ago • 1 comments

ディレクトリ名に非ASCII文字が含まれると、create-book が失敗します。

macOS上で npm create book お試し を実行すると、次のようにエラーになります: (「お試し」ディレクトリは生成されるけれど、 "error package.json: Name contains illegal characters")

$ npm create book お試し
? description description
? author name MurakamiShinyu
? author email [email protected]
? license AGPL-3.0
? choose theme @vivliostyle/theme-bunko - 文庫用のテーマ

Creating a new package in /Users/shinyu/viv/test-create-book/お試し.

Installing dependencies.

yarn install v1.22.4
error package.json: Name contains illegal characters
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
(node:87469) UnhandledPromiseRejectionWarning: Error: installDeps failed: 1
    at new EpicfailError (/Users/shinyu/.config/yarn/global/node_modules/epicfail/dist/index.js:84:28)
    at error (/Users/shinyu/.config/yarn/global/node_modules/create-create-app/lib/chunk.PD47mPub.js:221:15)
    at /Users/shinyu/.config/yarn/global/node_modules/create-create-app/lib/chunk.PD47mPub.js:142:7
    at Generator.throw (<anonymous>)
    at rejected (/Users/shinyu/.config/yarn/global/node_modules/create-create-app/lib/chunk.PD47mPub.js:13:29)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:87469) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:87469) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Windows上で npm create book お試し を実行すると、次のようにエラーになり、「お試し」ディレクトリは生成されません:

$ npm create book お試し
? description description
? author name MurakamiShinyu
? author email [email protected]
? license AGPL-3.0
? choose theme @vivliostyle/theme-bunko - 文庫用のテーマ

Creating a new package in D:\viv\test-create-book\お試し.

Error: ENOENT: no such file or directory, open 'D:\viv\test-create-book\お試し\LICENSE'

Windowsでは、https://github.com/vivliostyle/create-book/issues/3 の修正によって、ASCII文字だけの場合には動くようになりました。しかし、この修正(create-create-app の修正 https://github.com/uetchy/create-create-app/pull/17 )で利用した slash には、非ASCII文字が含まれる場合には機能しない問題があります。 それが修正されている slash2 か別の修正に直した方がよいかもしれません。しかしそこだけ直しても、上記 macOS での場合と同じ "error package.json: Name contains illegal characters" になるはずです。

それらが解決できるまでは、ディレクトリ名にASCII文字しか使えないということは制限事項として明記するのがよいと思います。

MurakamiShinyu avatar Jul 30 '20 04:07 MurakamiShinyu

yarnのpackage.json validationでnon-ASCIIを弾いていることが原因であって、つまりnpmがそのような名前を受け入れていないことが理由なので、根本的な解決は出来ないでしょう。代わりにcreate関数のhandleNameプロパティで名前をバリデートして適切なメッセージを返却するように修正したほうが良いでしょう。

https://github.com/yarnpkg/yarn/blob/eb2b565bb9b948e87b11119482ebc184a9d66141/src/util/normalize-manifest/validate.js#L26

uetchy avatar Jul 30 '20 05:07 uetchy