-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Rely on local cache instead of npm global dependencies folder
BREAKING CHANGE: - `npm-cross-link` no longer interferes with npm global `node_modules` folder. For any reuse it relies on user local cache directory. - No longer `npm link` is used internally. Any links are configured directly via symlinking
- Loading branch information
Showing
17 changed files
with
179 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,58 @@ | ||
"use strict"; | ||
|
||
const { resolve } = require("path") | ||
, log = require("log").get("npm-cross-link") | ||
, wait = require("timers-ext/promise/sleep") | ||
, rm = require("fs2/rm") | ||
, NpmCrossLinkError = require("./npm-cross-link-error") | ||
, getNpmModulesPath = require("./get-npm-modules-path") | ||
, runProgram = require("./run-program") | ||
, nonOverridableExternals = require("./non-overridable-externals") | ||
, resolveExternalContext = require("./resolve-external-context"); | ||
const log = require("log").get("npm-cross-link") | ||
, wait = require("timers-ext/promise/sleep") | ||
, semver = require("semver") | ||
, installMaintainedPackage = require("./install-maintained-package") | ||
, NpmCrossLinkError = require("./npm-cross-link-error") | ||
, resolveExternalContext = require("./resolve-external-context") | ||
, resolveLocalContext = require("./resolve-local-context") | ||
, cachePackage = require("./cache-package"); | ||
|
||
module.exports = async (packageContext, userConfiguration, inputOptions, progressData) => { | ||
const { name } = packageContext; | ||
const { name, versionRange } = packageContext; | ||
const { packagesMeta } = userConfiguration; | ||
if (packagesMeta[name]) { | ||
throw new NpmCrossLinkError( | ||
`Cannot install "${ name }" globally. It's not recognized as a maintained package` | ||
); | ||
} | ||
if (nonOverridableExternals.has(name)) { | ||
throw new NpmCrossLinkError( | ||
`Cannot install "${ name }" globally. It should not be installed with npm-cross-link` | ||
); | ||
} | ||
const isExternal = !packagesMeta[name]; | ||
|
||
packageContext.installationJobs = new Set(); | ||
|
||
// Ensure to emit "start" event in next event loop | ||
await wait(); | ||
progressData.emit("start", packageContext); | ||
|
||
const linkedPath = (packageContext.linkedPath = resolve(await getNpmModulesPath(), name)); | ||
if (!isExternal) { | ||
const { ongoing, done } = progressData; | ||
// Esure we have it installed locally | ||
if (!ongoing.has(name) && !done.has(name)) { | ||
await installMaintainedPackage({ name }, userConfiguration, inputOptions, progressData); | ||
} | ||
|
||
const externalContext = await resolveExternalContext(packageContext, progressData); | ||
if (!externalContext) { | ||
throw new NpmCrossLinkError( | ||
`Cannot install "${ name }" globally. It's doesn't seem to be published` | ||
if (!versionRange || versionRange === "latest") { | ||
progressData.emit("end", packageContext); | ||
return; | ||
} | ||
|
||
const { localVersion } = resolveLocalContext( | ||
packageContext, userConfiguration, progressData | ||
); | ||
} | ||
const { globallyInstalledVersion, latestVersion } = externalContext; | ||
if (!latestVersion) { | ||
throw new NpmCrossLinkError( | ||
`Cannot install "${ name }" globally. There's no latest version tagged` | ||
|
||
if (localVersion && semver.satisfies(localVersion, versionRange)) { | ||
progressData.emit("end", packageContext); | ||
return; | ||
} | ||
log.error( | ||
"%s will have %s version installed externally as non latest version is referenced", | ||
name, versionRange | ||
); | ||
} | ||
|
||
// Lastest version supported, ensure it's linked | ||
if (globallyInstalledVersion === latestVersion) return; | ||
if (globallyInstalledVersion) { | ||
packageContext.installationType = "update"; | ||
log.notice( | ||
"%s outdated at global folder (got %s expected %s), upgrading", name, | ||
globallyInstalledVersion, latestVersion | ||
const externalContext = await resolveExternalContext(packageContext, progressData); | ||
if (!externalContext) { | ||
throw new NpmCrossLinkError( | ||
`Cannot install "${ name }" globally. It's doesn't seem to be published` | ||
); | ||
} else { | ||
packageContext.installationType = "install"; | ||
log.notice("%s not installed at global folder, linking", name); | ||
} | ||
// Global node_modules hosts outdated version, cleanup | ||
await rm(linkedPath, { loose: true, recursive: true, force: true }); | ||
|
||
await runProgram("npm", ["install", "-g", `${ name }@${ latestVersion }`], { | ||
logger: log.levelRoot.get("npm:link") | ||
}); | ||
|
||
progressData.emit("end", packageContext); | ||
await cachePackage( | ||
name, packageContext.latestSupportedPublishedVersion || versionRange, externalContext | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.