Skip to content

Commit

Permalink
feat: support skipNestedGitUpdate option
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Oct 24, 2018
1 parent 3239e84 commit 1fe3351
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
13 changes: 9 additions & 4 deletions bin/dev-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ process.on("unhandledRejection", reason => { throw reason; });
require("log4-nodejs")({ defaultNamespace: "dev-package" });

const meta = require("../package")
, argv = require("minimist")(process.argv.slice(2));
, argv = require("minimist")(process.argv.slice(2), { boolean: "skip-nested-git-update" });

const usage = `dev-package v${ meta.version } - Install dev package
Expand All @@ -20,8 +20,9 @@ where <command> is one of:
Options:
--version, -v Display version
--help, -h Show this message
--skip-nested-git-update Do not run 'git pull' on dependencies
--version, -v Display version
--help, -h Show this message
`;

Expand Down Expand Up @@ -91,7 +92,11 @@ installPackage.on("end", ({ packageName: endedPackageName }) => {
updateProgress();
});
resolveUserConfiguration()
.then(configuration => installPackage(packageName, configuration))
.then(configuration =>
installPackage(packageName, configuration, {
skipNestedGitUpdate: argv["skip-nested-git-update"]
})
)
.catch(error => {
if (error instanceof DevPackageError) {
process.stdout.write(`\n${ clc.red(error.message) }\n`);
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use strict";

const ensureString = require("es5-ext/object/validate-stringifiable-value")
const toPlainObject = require("es5-ext/object/normalize-options")
, ensureString = require("es5-ext/object/validate-stringifiable-value")
, ensureConfiguration = require("./lib/ensure-configuration")
, installPackage = require("./lib/install-package");

module.exports = (packageName, configuration) =>
installPackage(ensureString(packageName), ensureConfiguration(configuration));
module.exports = (packageName, configuration, options = {}) =>
installPackage(
ensureString(packageName), ensureConfiguration(configuration), toPlainObject(options)
);
18 changes: 10 additions & 8 deletions lib/install-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ const { resolve } = require("path")
const ongoingMap = new Map();
const done = new Set();

const setupDependency = async (packagePath, dependencyName, configuration) => {
const setupDependency = async (packagePath, dependencyName, configuration, options) => {
const { packagesMeta } = configuration;
if (packagesMeta[dependencyName]) {
if (ongoingMap.has(dependencyName)) {
ongoingMap.get(dependencyName).push(() => setupNpmLink(packagePath, dependencyName));
return;
}
if (!done.has(dependencyName)) await module.exports(dependencyName, configuration);
if (!done.has(dependencyName)) await module.exports(dependencyName, configuration, options);
}
await setupNpmLink(packagePath, dependencyName);
};

const setupDependencies = async (packageName, configuration) => {
const setupDependencies = async (packageName, configuration, options) => {
const { packagesMeta, packagesPath } = configuration;
const packagePath = resolve(packagesPath, packageName);
const packagePkgJson = require(resolve(packagePath, "package.json"));
Expand All @@ -41,7 +41,7 @@ const setupDependencies = async (packageName, configuration) => {

log.info("for %s setup dependencies %o", packageName, dependencies);
for (const dependencyName of dependencies) {
await setupDependency(packagePath, dependencyName, configuration);
await setupDependency(packagePath, dependencyName, configuration, options);
}

// Eventual optional dependencies
Expand All @@ -50,7 +50,7 @@ const setupDependencies = async (packageName, configuration) => {
if (dependencies.has(dependencyName)) continue;
dependencies.add(dependencyName);
if (packagesMeta[dependencyName]) {
await setupDependency(packagePath, dependencyName, configuration);
await setupDependency(packagePath, dependencyName, configuration, options);
continue;
}
try { await setupNpmLink(packagePath, dependencyName); }
Expand Down Expand Up @@ -129,7 +129,7 @@ const finalize = async packageName => {
module.exports.emit("end", { packageName });
};

module.exports = ee(async (packageName, configuration) => {
module.exports = ee(async (packageName, configuration, options) => {
const { hooks, packagesPath, packagesMeta } = configuration;
const packagePath = resolve(packagesPath, packageName);

Expand All @@ -143,13 +143,15 @@ module.exports = ee(async (packageName, configuration) => {
ongoingMap.set(packageName, pendingJobs);

// Setup repository
await setupRepository(packagePath, packagesMeta[packageName].repoUrl);
await setupRepository(packagePath, packagesMeta[packageName].repoUrl, options);

// Cleanup eventual npm crashes
await cleanupNpmInstall(packagePath);

// Setup dependencies
const dependencies = await setupDependencies(packageName, configuration);
const dependencies = await setupDependencies(packageName, configuration, {
skipGitUpdate: options.skipNestedGitUpdate || options.skipGitUpdate
});

// Link package
await linkPackage(packagePath, packageName);
Expand Down
7 changes: 5 additions & 2 deletions lib/setup-repository.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"use strict";

const log = require("log4").get("dev-package")
const isObject = require("es5-ext/object/is-object")
, log = require("log4").get("dev-package")
, isDirectory = require("./is-directory")
, runProgram = require("./run-program");

module.exports = async (repoPath, repoUrl) => {
module.exports = async (repoPath, repoUrl, options = {}) => {
if (!isObject(options)) options = {};
if (await isDirectory(repoPath)) {
if (options.skipGitUpdate) return;
// Confirm directory is clean
const { stdout } = await runProgram("git", ["status", "--porcelain"], { cwd: repoPath });
if (stdout) throw new Error(`Repository ${ repoPath } is not clean:\n${ stdout }`);
Expand Down

0 comments on commit 1fe3351

Please sign in to comment.