This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: package management tool configuration
- Loading branch information
Showing
4 changed files
with
67 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fs from 'fs-extra' | ||
import yaml from 'js-yaml' | ||
import invariant from 'tiny-invariant' | ||
|
||
export async function configYarn(yarnConfigPath: string) { | ||
const config = await loadYarnConfig(yarnConfigPath) | ||
|
||
// use node-modules for compatible | ||
config.nodeLinker = 'node-modules' | ||
|
||
// make yarn only touch files under /tmp | ||
config.enableGlobalCache = false | ||
config.cacheFolder = '/tmp/home/.yarn-cache' | ||
|
||
// remove custom yarn and plugins | ||
Reflect.deleteProperty(config, 'yarnPath') | ||
Reflect.deleteProperty(config, 'plugins') | ||
|
||
await fs.writeFile(yarnConfigPath, yaml.dump(config)) | ||
} | ||
|
||
async function loadYarnConfig(yarnConfigPath: string): Promise<Record<string, unknown>> { | ||
try { | ||
const content = await fs.readFile(yarnConfigPath, 'utf-8') | ||
const config = yaml.load(content) || ({} as Record<string, unknown>) | ||
invariant(config !== null && typeof config === 'object', 'YAML config invalid') | ||
return config as unknown as Record<string, unknown> | ||
} catch { | ||
return {} | ||
} | ||
} |
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