【发布时间】:2019-04-05 03:47:10
【问题描述】:
tl;dr 我想用我的 Perl 库发送一个 package.json,运行 yarn install(或在安装过程中的 npm install)并使用 Perl 模块安装下载的 JavaScript 依赖项。
我有以下dist.ini:
name = Foobar
version = 1.2.3
license = Perl_5
copyright_holder = Yours Truly
copyright_year = 2018
[@Filter]
-bundle = @Basic
-remove = GatherDir
[Git::GatherDir]
[Web::FileHeader]
header_filename = EMM-include.pm
file_match = ^Makefile\.PL$
文件EMM-include.pm 包含一个MY::postamble 方法:
package MY;
use strict;
use Cwd qw(abs_path);
use File::Spec;
sub postamble {
my ($self) = @_;
my $here = Cwd::abs_path();
my $libdir = File::Spec->catdir($here, 'lib', 'Foobar');
chdir $libdir or die;
0 == system 'yarn', 'install' or die;
chdir $here or die;
return '';
}
插件[Web::FileHeader] 获取文件并将其修补到Makefile.PL 的开头。
然后有一个lib/Foobar/package.json:
{
"name": "foobar",
"version": "1.2.3",
"main": "index.js",
"dependencies": {
"ajv": "^6.5.4"
}
}
来自EMM-include.pm 的MY::postamble 部分调用yarn install(如果没有yarn,则将其替换为npm install)并使用ajv 及其依赖项填充目录lib/Foobar/node_modules。
最后,必须有一个模块lib/Foobar.pm:
package Foobar;
# ABSTRACT: Just a test.
1;
几乎按预期工作:可以使用dzil build 创建分发。在分发目录中,perl Makefile.PL 调用yarn install,目录lib/Foobar/node_modules 被填充,但其中的文件没有与make install 一起安装。
如果我第二次运行 perl Makefile.PL,一切正常,JavaScript 依赖项将其变为 blib/ 和 make install 将安装 JavaScript 模块和 Perl 模块。
将 JavaScript 依赖项与分发一起提供不是一种选择。它们已经太多了,而且它们可能有冲突的许可证(我在这里使用的是 GPLv3)。在运行时下载deps,安装后大多会因为缺少权限而失败。
的确,这与Dist::Zilla 没有太大关系,而是ExtUtils::MakeMaker 的问题。但我实际上在这里使用Dist::Zilla。
如果重要的话,真正的分布是https://github.com/gflohr/qgoda,而在撰写本文时的最后一次提交是https://github.com/gflohr/qgoda/commit/3f34a3dfec8da665061432c3a8f7bd8eef28b95e。
【问题讨论】:
-
我明天的下一个尝试是查找由
yarn/npm安装的所有文件,然后将它们添加到Makefile变量TO_INST_PM。我在正确的轨道上吗?还是有更简单的方法?
标签: perl makemaker dist-zilla