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

Conflicting resolution priority between local theme and npm package #524

Open
u1f992 opened this issue Oct 4, 2024 · 3 comments
Open

Conflicting resolution priority between local theme and npm package #524

u1f992 opened this issue Oct 4, 2024 · 3 comments

Comments

@u1f992
Copy link
Sponsor Contributor

u1f992 commented Oct 4, 2024

themeに指定したディレクトリ名と同名のパッケージがnpmに存在する場合、ローカルのパッケージよりnpmのパッケージが優先されます。以下の例ではcssディレクトリが無視されcssがインストールされます。

> vivliostyle --version
cli: 8.15.0
core: 2.30.4

$ tree .
.
├── css
│   ├── package.json
│   └── style.css
├── manuscript.md
└── vivliostyle.config.js

vivliostyle.config.js

const vivliostyleConfig = {
  title: '_',
  author: '_',
  theme: 'css',
  entry: ['manuscript.md'],
  output: 'output.pdf',
  
  workspaceDir: '.vivliostyle',
};

module.exports = vivliostyleConfig;

css/package.json

{
    "name": "css",
    "main": "style.css"
}
$ cat .vivliostyle/themes/packages/css/Readme.md 
# css [![Build Status](https://travis-ci.org/reworkcss/css.svg?branch=master)](https://travis-ci.org/reworkcss/css)

CSS parser / stringifier.

## Installation
……

theme./cssのように指定することで回避できますが、他フィールドがファイル名のみの表記で正常に処理される(manuscript.mdoutput.pdf)ことを鑑みると、一貫性を欠いた挙動に感じられます。また、非公開のテーマについてnpmに同名のパッケージがあるか確認することもまずないかと思います。この場合にはローカルのディレクトリ指定が優先されたほうが有用ではないでしょうか。

@spring-raining
Copy link
Member

spring-raining commented Oct 5, 2024

theme の名前からそのパッケージがnpm registryのものかローカル環境のものかを判定するロジックは @npmcli/arborist npm-package-arg というライブラリを用いており、静的に (npm registryを確認することなく) 実施されるよう設計されています。もし提案するように css という名前からローカル環境のパッケージを使用するような実装にする場合、

  • npm registryに css というパッケージが存在するかを確認
  • 存在しない、もしくはVivliostyle Themeパッケージでない場合、ローカル環境のパッケージを使用

というステップがビルド時に追加されることになり、相当な時間がビルド時間にかかってしまうことからそのままこの提案を受け入れることは難しいです。
ただ、npm packageのインポートに失敗したときに同名のディレクトリがローカル環境にあった場合に、./css という名前に変更するようエラーメッセージとして提案する、といった改善は良いかと思います。

@spring-raining
Copy link
Member

spring-raining commented Oct 5, 2024

なお、 foo/bar のように名前が / が含まれており、かつ名前の先頭が @ で始まらない場合は判定結果に関わらずローカル環境のパッケージを使用するようになっています。参考: #373

@u1f992
Copy link
Sponsor Contributor Author

u1f992 commented Oct 7, 2024

ありがとうございます。おっしゃる通りレジストリを見に行くのは実用的ではなさそうです。
しかし村上さんの「最後のスラッシュがなくても、そのディレクトリがある場合は、ディレクトリの指定として扱われるべきでしょう。」という発言からはいっそう、theme: 'css'と指定されていればcssディレクトリを見に行くべきだと感じられます……。

  • npm registryにcssというパッケージが存在するかを確認
  • 存在しない、もしくはVivliostyle Themeパッケージでない場合、ローカル環境のパッケージを使用

この実装案が少しわからなかったのですが、素朴な案として「npm-package-argにかける前に、パスとして解釈して存在するか・Vivliostyle Themeパッケージか判別する」処理を挟むのは不都合がありそうでしょうか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants