File: pkgjs

package info (click to toggle)
pkg-js-tools 0.16.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,992 kB
  • sloc: perl: 4,975; sh: 840; makefile: 36; javascript: 22
file content (223 lines) | stat: -rwxr-xr-x 4,353 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/perl

use strict;
use Debian::PkgJs::Version;
use File::Which;

my @ignoredCommands = qw(
  cache
  config
  dedupe
);

my @commands = qw(
  audit
  bin
  depends
  easy-to-update
  exec
  install
  install-minimal
  lerna
  ln
  ls
  main
  node
  pjson
  rebuild
  run
  utils
  version
);

my @commandsToPass = qw(
  explain
  info
  init
);

my @failCommand = qw(
  add
  dlx
  link
  npm
  pack
  patch
  patch-commit
  remove
  set
  stage
  unlink
  unplug
  up
  why
  constraints
  search
  upgrade-interactive
  plugin
  workspace
  workspaces
);

my @argv;
my $command;

foreach my $arg (@ARGV) {
    exit 0 if grep { $arg eq $_ } @ignoredCommands;
    if ( grep { $arg eq $_ } @failCommand ) {
        print STDERR "Unimplemented command in pkgjs, try with yarnpkg\n";
        exit 1;
    }
    if ( grep { $arg eq $_ } @commandsToPass ) {
        $command =
            which('yarnpkg') ? 'yarnpkg'
          : which('yarn')    ? 'yarn'
          : which('npm')     ? 'npm'
          :                    die(':yarnpkg not installed');
        exec( $command, @ARGV );
    }
    if ( !$command and grep { $arg eq $_ } @commands ) {
        $command = $arg;
    }
    else {
        push @argv, $arg;
    }
    if ( !$command ) {
        if ( $arg =~ /^-(?:-help|h)$/ ) {
            $command = 'help';
        }
        elsif ( $arg =~ /^-(?:-version|v)$/ ) {
            $command = 'version';
        }
    }
}

$command ||= 'install';

# Now we have a knonw command and all arguments are in @argv

if (
    $command =~ qr/^(?:
  audit
  | depends
  | easy-to-update
  | install-minimal
  | lerna
  | ln
  | ls
  | main
  | pjson
  | run
  | utils
)$/xx
  )
{
    exec( "pkgjs-$command", @argv );
}
else {
    my $kc = {
        bin => sub {
            exec( 'which', @_ );
        },
        exec => sub {
            exec( 'node', @_ );
        },
        install => sub {
            if ( $ENV{PKGJS_INSTALL_OPTS} ) {
                exec( 'pkgjs-install',
                    ( split /\s+/, $ENV{PKGJS_INSTALL_OPTS} ) );
            }
            else {
                exec('pkgjs-install-minimal');
            }
        },
        node => sub {
            exec( 'node', @_ );
        },
        rebuild => sub {
            exec( 'pkgjs-run', 'build' );
        },
        version => sub {
            print "$VERSION\n";
            exit 0;
        },
        help => sub {
            print <<'EOF';
pkgjs is a wrapper that emulates yarnpkg, to be used during package build.
EOF
        },
    };
    if ( $kc->{$command} ) {
        $kc->{$command}->(@argv);
    }
    else {
        print STDERR "Unknown command $command\n";
        exit 1;
    }
}

=head1 NAME

pkgjs - Wrapper to pkgjs-* commands, used to replace yarn during Debian
packages build.

=head1 DESCRIPTION

pkgjs is a wrapper to pkgjs-* commands. For example C<pkgjs ln yargs> launches
C<pkgjs-ln yargs>. For some commands, it launches L<yarnpkg(1)> or L<npm(1)>
if available.

=over

=item * Ignored commands I<(do nothing)>: B<cache>, B<config>, B<dedupe>

=item * Commands passed to yarnpkg/npm: B<explain>, B<info>, B<init>

=item * Direct mappings I<(launches the corresponding C<pkgjs-*> command)>:
L<depends|pkgjs-depends(1)>, L<easy-to-update|pkgjs-easy-to-update(1)>,
L<install-minimal|pkgjs-install-minimal(1)>, L<lerna|pkgjs-lerna(1)>,
L<ln|pkgjs-ln(1)>, L<ls|pkgjs-ls(1)>, L<main|pkgjs-main(1)>,
L<pjson|pkgjs-pjson(1)>, L<run|pkgjs-run(1)>, L<utils|pkgjs-utils(1)>

=item * More complex mappings:

=over

=item * B<bin>: launches L<which(1)>

=item * B<exec>: launches L<nodejs(1)>

=item * B<install>:

=over

=item * if C<PKGJS_INSTALL_OPTS> environment variable is set,
launches L<pkgjs-install(1)> with C<PKGJS_INSTALL_OPTS> and given arguments

=item * else launches L<pkgjs-install-minimal(1)>

=back

=back

=back

All other commands will fail.

=head1 AUTHOR

Yadd <yadd@debian.org>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2021 by Yadd <yadd@debian.org>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
.
On Debian systems, the complete text of version 2 of the GNU General
Public License can be found in `/usr/share/common-licenses/GPL-2'

=cut