Skip to content

Commit

Permalink
feat: do not use ~/.node as default value for COREPACK_HOME (#152)
Browse files Browse the repository at this point in the history
* feat: do not use `~/.node` as default value for `COREPACK_HOME`

Fixes: #145
Refs: nodejs/node#43859

* fixup! feat: do not use `~/.node` as default value for `COREPACK_HOME`

* Update sources/folderUtils.ts

Co-authored-by: Kristoffer K. <merceyz@users.noreply.github.com>

* Update README

* migrate old corepack home folder

Co-authored-by: Kristoffer K. <merceyz@users.noreply.github.com>
  • Loading branch information
aduh95 and merceyz committed Aug 15, 2022
1 parent a6b8b93 commit 09e24cf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ This command will retrieve the given package manager from the specified archive

- `COREPACK_ENABLE_NETWORK` can be set to `0` to prevent Corepack from accessing the network (in which case you'll be responsible for hydrating the package manager versions that will be required for the projects you'll run, using `corepack hydrate`).

- `COREPACK_HOME` can be set in order to define where Corepack should install the package managers. By default it is set to `$HOME/.node/corepack`.
- `COREPACK_HOME` can be set in order to define where Corepack should install
the package managers. By default it is set to `%LOCALAPPDATA%\node\corepack`
on Windows, and to `$HOME/.cache/node/corepack` everywhere else.

- `COREPACK_ROOT` has no functional impact on Corepack itself; it's automatically being set in your environment by Corepack when it shells out to the underlying package managers, so that they can feature-detect its presence (useful for commands like `yarn init`).

Expand Down
41 changes: 36 additions & 5 deletions sources/folderUtils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import {mkdirSync} from 'fs';
import {homedir, tmpdir} from 'os';
import {join} from 'path';
import type { NodeError } from './nodeUtils';
import {existsSync, mkdirSync, renameSync} from 'fs';
import {homedir, tmpdir} from 'os';
import {join} from 'path';
import process from 'process';

import type {NodeError} from './nodeUtils';

export function getInstallFolder() {
return process.env.COREPACK_HOME ?? join(homedir(), `.node/corepack`);
if (process.env.COREPACK_HOME == null) {
// TODO: remove this block on the next major.
const oldCorepackDefaultHome = join(homedir(), `.node`, `corepack`);
const newCorepackDefaultHome = join(
process.env.XDG_CACHE_HOME ??
process.env.LOCALAPPDATA ??
join(
homedir(),
process.platform === `win32` ? `AppData/Local` : `.cache`,
),
`node/corepack`,
);
if (
existsSync(oldCorepackDefaultHome) &&
!existsSync(newCorepackDefaultHome)
) {
mkdirSync(newCorepackDefaultHome, {recursive: true});
renameSync(oldCorepackDefaultHome, newCorepackDefaultHome);
}
return newCorepackDefaultHome;
}
return (
process.env.COREPACK_HOME ??
join(
process.env.XDG_CACHE_HOME ??
process.env.LOCALAPPDATA ??
join(homedir(), process.platform === `win32` ? `AppData/Local` : `.cache`),
`node/corepack`,
)
);
}

export function getTemporaryFolder(target: string = tmpdir()) {
Expand Down

0 comments on commit 09e24cf

Please sign in to comment.