File: download_npm_deps_manually.sh

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (49 lines) | stat: -rwxr-xr-x 1,482 bytes parent folder | download | duplicates (7)
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
#!/bin/bash

# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Script for downloading some WebUI's NPM deps without using `npm install`.
# Unfortunately `npm install` downloads a lot of unnecessary dependencies in
# many cases. This is especially true for cases like 'mocha'and 'chai', which
# even though come already bundled, NPM still downloads about ~8MB of
# unnecessary dependencies.
#
# To address the problem above and avoid blowing up the size of the generated
# node_modules.tar.gz file, this script directly downloads just the necessary
# packages, since NPM does not provide such functionality built-in, see
# https://github.com/npm/npm/issues/340.

set -eu

tmp_dir="node_modules_manual"
mkdir -p "${tmp_dir}"

CHAI_VERSION="5.1.1"
MOCHA_VERSION="10.4.0"

download_package() {
  local PACKAGE="$1"
  local VERSION="$2"

  # Manually download from NPM.
  npm pack --silent ${PACKAGE}@${VERSION} --pack-destination ${tmp_dir}

  # Extract.
  tar xfz ${tmp_dir}/${PACKAGE}-${VERSION}.tgz -C ${tmp_dir}

  # Delete destination folder if it already exists.
  rm -rf node_modules/${PACKAGE}

  # Place in node_modules/ folder. Any further filtering of files happens in the
  # parent script.
  mv ${tmp_dir}/package node_modules/${PACKAGE}
}

download_package "chai" ${CHAI_VERSION}
rm -rf ${tmp_dir}/package
download_package "mocha" ${MOCHA_VERSION}

# Clean up.
rm -rf "$tmp_dir"