Skip to content

Commit

Permalink
improve local linking package and changed check
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed May 7, 2021
1 parent 54c71a5 commit f3fc741
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/fyn.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class Fyn {
for (const locals of localsByDepth.reverse()) {
for (const relPath of locals) {
const fullPath = Path.join(this._cwd, relPath);
if ((await this.getLocalPkgInstall(fullPath)).install) {
if ((await this.getLocalPkgInstall(fullPath)).changed) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/local-pkg-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LocalPkgBuilder {
// need to be installed also, even if its own files didn't change.
// Generally this is unnecessary, except if its build process may
// depend on that downstream local package.
if (!checkPkg.install) {
if (!checkPkg.localBuild) {
logger.debug(`local pkg at ${item.fullPath} doesn't need build`, checkPkg);
return;
}
Expand Down
49 changes: 30 additions & 19 deletions lib/pkg-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class PkgInstaller {
}

async install() {
this._stepTime = Date.now();

this.timeCheck("beginning");
const outputDir = this._fyn.getOutputDir();
this._binLinker = new PkgBinLinker({ outputDir, fyn: this._fyn });
// /*deprecated*/ const fynRes = await this._depLinker.readAppFynRes(outputDir);
Expand All @@ -40,6 +43,7 @@ class PkgInstaller {
// go through each package and insert
// _depResolutions into its package.json
const pkgsData = this._data.getPkgsData();
this.timeCheck("queueing packages");
for (const info of this._data.resolvedPackages) {
const depInfo = pkgsData[info.name][info.version];
logger.debug("queuing", depInfo.name, depInfo.version, "for install");
Expand Down Expand Up @@ -264,16 +268,20 @@ class PkgInstaller {
await Fs.$.rimraf(this._fyn.getInstalledPkgDir(depInfo.name, depInfo.version));
}

timeCheck(x) {
const tmp = Date.now();
logger.debug(
`${chalk.green("install time check", x)} ${logFormat.time(tmp - this._stepTime)}`,
new Date()
);
this._stepTime = tmp;
}

_doInstall() {
const start = Date.now();
const appDir = this._fyn.cwd;

let stepTime = start;
const timeCheck = x => {
const tmp = Date.now();
logger.debug(`${chalk.green("install time check", x)} ${logFormat.time(tmp - stepTime)}`);
stepTime = tmp;
};
this.timeCheck("starting preinstall");

return (
Promise.map(
Expand All @@ -290,7 +298,7 @@ class PkgInstaller {
},
{ concurrency: 3 }
)
.tap(() => timeCheck("preInstall"))
.tap(() => this.timeCheck("preInstall"))
.tap(() => {
logger.updateItem(INSTALL_PACKAGE, `linking packages...`);
})
Expand All @@ -309,32 +317,32 @@ class PkgInstaller {
}
return undefined;
})
.tap(() => timeCheck("linking packages"))
.tap(() => this.timeCheck("linking packages"))
.tap(() => logger.debug("linking bin for non-top but promoted packages"))
.return(this.toLink) // Link bin for all none top but promoted pkg first
.each(x => !x.top && x.promoted && this._binLinker.linkBin(x))
.tap(() => timeCheck("linking bin promoted non-top"))
.tap(() => this.timeCheck("linking bin promoted non-top"))
.tap(() => logger.debug("linking bin for FV_DIR packages"))
.return(this.toLink) // Link bin for all pkg under FV_DIR
.each(x => !x.top && !x.promoted && this._binLinker.linkBin(x))
.tap(() => timeCheck("linking bin FV_DIR"))
.tap(() => this.timeCheck("linking bin FV_DIR"))
.return(this.toLink) // link bin for package's dep that conflicts
.each(x => this._binLinker.linkDepBin(x))
.tap(() => timeCheck("linking dep bin"))
.tap(() => this.timeCheck("linking dep bin"))
.then(() => {
// we are about to run install/postInstall scripts
// save pkg JSON to disk in case any updates were done
return this._savePkgJson();
})
.tap(() => timeCheck("first _savePkgJson"))
.tap(() => this.timeCheck("first _savePkgJson"))
.then(() => this._initFvVersions())
.tap(() => timeCheck("_initFvVersions"))
.tap(() => this.timeCheck("_initFvVersions"))
.then(() => this._cleanUp())
.tap(() => timeCheck("_cleanUp"))
.tap(() => this.timeCheck("_cleanUp"))
.then(() => this._cleanOrphanedFv())
.tap(() => timeCheck("_cleanOrphanedFv"))
.tap(() => this.timeCheck("_cleanOrphanedFv"))
.then(() => this._cleanBin())
.tap(() => timeCheck("_cleanBin"))
.tap(() => this.timeCheck("_cleanBin"))
.return(this.postInstall)
.map(
depInfo => {
Expand Down Expand Up @@ -370,12 +378,12 @@ class PkgInstaller {
},
{ concurrency: 3 }
)
.tap(() => timeCheck("postInstall"))
.tap(() => this.timeCheck("postInstall"))
.then(() => {
// Go through save package.json again in case any changed
return this._savePkgJson(true);
})
.tap(() => timeCheck("second _savePkgJson"))
.tap(() => this.timeCheck("second _savePkgJson"))
// .then(() => this._saveLocalFynSymlink())
.return(this.toLink)
.filter(di => {
Expand All @@ -397,7 +405,7 @@ class PkgInstaller {
}
return false;
})
.tap(() => timeCheck("show deprecated"))
.tap(() => this.timeCheck("show deprecated"))
.then(warned => {
if (this._fyn.showDeprecated && _.isEmpty(warned)) {
logger.info(chalk.green("HOORAY!!! None of your dependencies are marked deprecated."));
Expand All @@ -424,8 +432,11 @@ class PkgInstaller {
async _gatherPkg(depInfo) {
const { name, version } = depInfo;
if (depInfo.local) {
this.timeCheck("buildLocal");
await this._buildLocalPkg(depInfo);
this.timeCheck("linkLocal");
await this._linkLocalPkg(depInfo);
this.timeCheck("done link Local");
}

const json = depInfo.json || {};
Expand Down
12 changes: 11 additions & 1 deletion lib/util/check-pkg-need-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { scanFileStats } = require("./stat-dir");
const Fs = require("./file-ops");
const Path = require("path");
const logger = require("../logger");

/**
* Go into a local dep pkg's dir and see if it has one of these npm scripts:
Expand Down Expand Up @@ -57,8 +58,17 @@ async function checkPkgNeedInstall(dir, checkCtime = 0) {

const stats = await scanFileStats(dir);
const ctime = stats.latestMtimeMs;
const changed = ctime > checkCtime;

return { install: ctime > checkCtime, ctime, checkCtime, pkgJson, stats, scripts, hasScript };
return {
changed,
localBuild: changed && hasScript,
checkCtime,
pkgJson,
stats,
scripts,
hasScript
};
} catch (error) {
return { install: false, error };
}
Expand Down
13 changes: 13 additions & 0 deletions lib/util/hard-link-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Fs = require("./file-ops");
const xaa = require("./xaa");
const npmPacklist = require("npm-packlist");
const fynTil = require("./fyntil");
const logger = require("../logger");

async function linkFile(srcFp, destFp, srcStat) {
try {
Expand Down Expand Up @@ -74,6 +75,18 @@ async function generatePackTree(path) {
path
});

logger.debug(
`local package linking - pack tree returned ${files.length} files to link`,
JSON.stringify(files, null, 2)
);

if (files.length > 1000) {
logger.warn(
`Local linking package at ${path} has more than ${files.length} files.
>>> This is unusual, please check package .npmignore or 'files' in package.json <<<`
);
}

const fmap = { [FILES]: [] };

files.sort().forEach(filePath => {
Expand Down

0 comments on commit f3fc741

Please sign in to comment.