line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Alien::rollup; |
2
|
2
|
|
|
2
|
|
411880
|
use Mojo::Base 'Mojo::Alien::webpack'; |
|
2
|
|
|
|
|
24
|
|
|
2
|
|
|
|
|
11
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
157
|
use Carp qw(croak); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
110
|
|
5
|
2
|
|
|
2
|
|
34
|
use Mojo::File qw(path tempfile); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
91
|
|
6
|
2
|
|
|
2
|
|
13
|
use File::chdir; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
188
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
50
|
2
|
|
14
|
use constant DEBUG => $ENV{MOJO_ROLLUP_DEBUG} && 1; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2272
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has binary => sub { |
11
|
|
|
|
|
|
|
my $self = shift; |
12
|
|
|
|
|
|
|
return $ENV{MOJO_ROLLUP_BINARY} if $ENV{MOJO_ROLLUP_BINARY}; |
13
|
|
|
|
|
|
|
my $bin = $self->config->to_abs->dirname->child(qw(node_modules .bin rollup)); |
14
|
|
|
|
|
|
|
$self->_d('%s %s', -e $bin ? 'Found' : 'Not installed', $bin) if DEBUG; |
15
|
|
|
|
|
|
|
return -e $bin ? $bin->to_string : 'rollup'; |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has config => sub { path->to_abs->child('rollup.config.js') }; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has dependencies => sub { |
21
|
|
|
|
|
|
|
return { |
22
|
|
|
|
|
|
|
core => [qw(rollup @rollup/plugin-commonjs @rollup/plugin-node-resolve)], |
23
|
|
|
|
|
|
|
css => [qw(cssnano postcss-preset-env rollup-plugin-postcss)], |
24
|
|
|
|
|
|
|
eslint => [qw(@rollup/plugin-eslint)], |
25
|
|
|
|
|
|
|
js => [qw(@babel/core @babel/preset-env @babel/plugin-transform-runtime @rollup/plugin-babel rollup-plugin-terser)], |
26
|
|
|
|
|
|
|
sass => [qw(cssnano @csstools/postcss-sass postcss-preset-env rollup-plugin-postcss sass)], |
27
|
|
|
|
|
|
|
svelte => [qw(rollup-plugin-svelte)], |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub exec { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
my @cmd = ($self->_cmd_build, '--watch'); |
34
|
0
|
|
|
|
|
|
my $home = $self->config->dirname->to_string; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
chdir $home or die "Can't chdir to $home: $!"; |
37
|
0
|
|
|
|
|
|
$ENV{NODE_ENV} = $self->mode; |
38
|
0
|
|
|
|
|
|
$ENV{ROLLUP_ASSETS_DIR} = $self->assets_dir->to_string; |
39
|
0
|
|
|
|
|
|
$ENV{ROLLUP_OUT_DIR} = $self->out_dir->to_string; |
40
|
0
|
|
|
|
|
|
$self->_d('(%s) cd %s && %s', $$, $home, join ' ', @_) if DEBUG; |
41
|
0
|
|
|
|
|
|
{ exec @cmd } |
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
die "Can't exec @cmd: $!"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub watch { |
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
47
|
0
|
0
|
|
|
|
|
return $self if $self->pid; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $home = $self->config->dirname->to_string; |
50
|
0
|
0
|
|
|
|
|
croak "Can't chdir $home: No such file or directory" unless -d $home; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my @cmd = ($self->_cmd_build, '--watch'); |
53
|
0
|
0
|
|
|
|
|
croak "Can't fork: $!" unless defined(my $pid = fork); |
54
|
0
|
0
|
|
|
|
|
return $self if $self->{pid} = $pid; # Parent |
55
|
0
|
|
|
|
|
|
return $self->exec; # Child |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _cmd_build { |
59
|
0
|
|
|
0
|
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
$self->init; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my @cmd = ($self->binary); |
63
|
0
|
0
|
|
|
|
|
croak "Can't run $cmd[0]" unless -x $cmd[0]; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
0
|
|
|
|
$self->{basename} ||= path($cmd[0])->basename; |
66
|
0
|
|
|
|
|
|
push @cmd, '--config' => $self->config->to_string; |
67
|
0
|
|
|
|
|
|
return @cmd; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
|
|
sub _config_include_dir { shift->assets_dir->child('rollup.config.d') } |
71
|
0
|
|
|
0
|
|
|
sub _config_template_name {'rollup.config.js'} |
72
|
0
|
|
|
0
|
|
|
sub _d { my ($class, $format) = (shift, shift); warn sprintf "[Rollup] $format\n", @_ } |
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _run { |
75
|
0
|
|
|
0
|
|
|
my ($self, @cmd) = @_; |
76
|
0
|
|
|
|
|
|
local $CWD = $self->config->dirname->to_string; |
77
|
0
|
|
|
|
|
|
local $ENV{NODE_ENV} = $self->mode; |
78
|
0
|
|
|
|
|
|
local $ENV{ROLLUP_ASSETS_DIR} = $self->assets_dir->to_string; |
79
|
0
|
|
|
|
|
|
local $ENV{ROLLUP_OUT_DIR} = $self->out_dir->to_string; |
80
|
0
|
|
|
|
|
|
$self->_d('cd %s && %s', $CWD, join ' ', @cmd) if DEBUG; |
81
|
0
|
0
|
|
|
|
|
open my $ROLLUP, '-|', @cmd or die "Can't run @cmd: $!"; |
82
|
0
|
0
|
|
|
|
|
return $ROLLUP if defined wantarray; |
83
|
0
|
|
|
|
|
|
DEBUG && print while <$ROLLUP>; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding utf8 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Mojo::Alien::rollup - Runs the external nodejs program rollup |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SYNOPSIS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
use Mojo::Alien::rollup; |
97
|
|
|
|
|
|
|
my $rollup = Mojo::Alien::rollup->new; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Run once |
100
|
|
|
|
|
|
|
$rollup->build; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Build when rollup see files change |
103
|
|
|
|
|
|
|
$rollup->watch |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 DESCRIPTION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L is a class for runnig the external nodejs program |
108
|
|
|
|
|
|
|
L. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 assets_dir |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
See L. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 binary |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$array_ref = $rollup->binary; |
119
|
|
|
|
|
|
|
$rollup = $rollup->binary('rollup'); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The path to the rollup executable. Defaults to C |
122
|
|
|
|
|
|
|
environment variable, or "rollup" inside "./node_modules". Fallback to just |
123
|
|
|
|
|
|
|
"rollup". |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 config |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$path = $rollup->config; |
128
|
|
|
|
|
|
|
$rollup = $rollup->config(path->to_abs->child('rollup.config.js')); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Holds an I path to |
131
|
|
|
|
|
|
|
L. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 dependencies |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$hash_ref = $rollup->dependencies; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
A hash where the keys can match the items in L and the values are |
138
|
|
|
|
|
|
|
lists of packages to install. Keys that does I match items in L |
139
|
|
|
|
|
|
|
will be ignored. This attribute will be used by L. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
These dependencies are predefined: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
core | rollup @rollup/plugin-commonjs @rollup/plugin-node-resolve |
144
|
|
|
|
|
|
|
css | cssnano postcss-preset-env rollup-plugin-postcss |
145
|
|
|
|
|
|
|
eslint | @rollup-plugin-eslint |
146
|
|
|
|
|
|
|
js | @babel/core @babel/preset-env @rollup/plugin-babel rollup-plugin-terser |
147
|
|
|
|
|
|
|
sass | cssnano @csstools/postcss-sass postcss-preset-env rollup-plugin-postcss sass |
148
|
|
|
|
|
|
|
svelte | rollup-plugin-svelte |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 include |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
See L. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 mode |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
See L. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 npm |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
See L. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 out_dir |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
See L. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 METHODS |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 asset_map |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
$hash_ref = $rollup->asset_map; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Parses the filenames in L and returns a hash ref with information |
173
|
|
|
|
|
|
|
about the generated assets. Example return value: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
{ |
176
|
|
|
|
|
|
|
'entry-name.js' => '/path/to/entry-name.development.js', |
177
|
|
|
|
|
|
|
'cool-beans.png' => /path/to/f47352684211060f3e34.png', |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Note that this method is currently EXPERIMENTAL. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 build |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
See L. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 exec |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
See L. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 init |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
See L. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 pid |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
See L. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 stop |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
See L. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 watch |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
See L. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 SEE ALSO |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L and L. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
__DATA__ |