aboutsummaryrefslogtreecommitdiff
path: root/npmPackages/_scripts/pindeps.js
blob: 35459574937fa5044e8434a81e20fdf6e7c94cf0 (plain)
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
const process = require('process');
const path = require('path');

const {
    pipeThrough,
    readPackage
} = require('./package.js');

function pinDependencies(pkg, done) {
    const deps = Object.keys(pkg.dependencies || {});
    const readLocalPkg = (n) => readPackage(path.join('node_modules', n));

    Promise.all(deps.map(readLocalPkg)).then((pkgs) => {
        const pinned = pkgs.reduce((ds, d) => {
            ds[d.info.name] = `^${d.info.version}`;
            return ds;
        }, {});

        pkg.dependencies = pinned;
        done(pkg);
    }).catch((err) => {
        console.error(err);
        process.exit(1);
    });
}

pipeThrough(pinDependencies);