aureooms/rejuvenate

View on GitHub
src/transforms/package.json:homepage-use-https.js

Summary

Maintainability
A
3 hrs
Test Coverage
import update from '../lib/update.js';

export const description = 'Use https for homepage URL.';

export const commit = {
    scope: 'package.json',
    subject: description,
};

export async function postcondition({readPkg, assert}) {
    const pkgjson = await readPkg();
    const homepage = pkgjson.homepage;
    assert(!homepage || homepage.startsWith('https:'));
}

export async function precondition({readPkg, assert}) {
    const pkgjson = await readPkg();
    const homepage = pkgjson.homepage;
    assert(homepage && homepage.startsWith('http:'));
}

export async function apply({readPkg, writePkg}) {
    await update({
        read: readPkg,
        write: writePkg,
        edit(pkgjson) {
            pkgjson.homepage = pkgjson.homepage.replace(/^http:/, 'https:');
            return pkgjson;
        },
    });
}