Skip to content

Commit

Permalink
Replace yaml with lighter js-yaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Apr 5, 2023
1 parent 1677619 commit 5439c87
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"globby": "^11.0.4",
"hosted-git-info": "^5.1.0",
"ini": "^4.0.0",
"js-yaml": "^4.1.0",
"json-parse-helpfulerror": "^1.0.3",
"jsonlines": "^0.1.1",
"lodash": "^4.17.21",
Expand All @@ -80,8 +81,7 @@
"spawn-please": "^2.0.1",
"strip-json-comments": "^5.0.0",
"untildify": "^4.0.0",
"update-notifier": "^6.0.2",
"yaml": "^2.2.1"
"update-notifier": "^6.0.2"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand All @@ -91,6 +91,7 @@
"@types/cli-table": "^0.3.1",
"@types/hosted-git-info": "^3.0.2",
"@types/ini": "^1.3.31",
"@types/js-yaml": "^4.0.5",
"@types/json-parse-helpfulerror": "^1.0.1",
"@types/jsonlines": "^0.1.2",
"@types/lodash": "^4.14.192",
Expand Down
8 changes: 5 additions & 3 deletions src/lib/getAllPackages.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import fs from 'fs/promises'
import globby from 'globby'
import yaml from 'js-yaml'
import path from 'path'
import untildify from 'untildify'
import yaml from 'yaml'
import { Options } from '../types/Options'
import { PackageFile } from '../types/PackageFile'
import { PackageInfo } from '../types/PackageInfo'
import findPackage from './findPackage'
import loadPackageInfoFromFile from './loadPackageInfoFromFile'
import programError from './programError'

type PnpmWorkspaces = string[] | { packages: string[] }

/** Reads, parses, and resolves workspaces from a pnpm-workspace file at the same path as the package file. */
const readPnpmWorkspaces = async (pkgPath: string): Promise<string[] | { packages: string[] } | null> => {
const readPnpmWorkspaces = async (pkgPath: string): Promise<PnpmWorkspaces | null> => {
const pnpmWorkspacesPath = path.join(path.dirname(pkgPath), 'pnpm-workspace.yaml')
let pnpmWorkspaceFile: string
try {
pnpmWorkspaceFile = await fs.readFile(pnpmWorkspacesPath, 'utf-8')
} catch (e) {
return null
}
return yaml.parse(pnpmWorkspaceFile)
return yaml.load(pnpmWorkspaceFile) as PnpmWorkspaces
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/package-managers/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { EventEmitter, once } from 'events'
import memoize from 'fast-memoize'
import fs from 'fs/promises'
import yaml from 'js-yaml'
import jsonlines from 'jsonlines'
import curry from 'lodash/curry'
import os from 'os'
import path from 'path'
import spawn from 'spawn-please'
import yaml from 'yaml'
import exists from '../lib/exists'
import findLockfile from '../lib/findLockfile'
import { keyValueBy } from '../lib/keyValueBy'
Expand Down Expand Up @@ -112,8 +112,8 @@ const npmConfigFromYarn = memoize(async (options: Options): Promise<NpmConfig> =
const yarnrcUserExists = await exists(yarnrcUserPath)
const yarnrcLocal = yarnrcLocalExists ? await fs.readFile(yarnrcLocalPath, 'utf-8') : ''
const yarnrcUser = yarnrcUserExists ? await fs.readFile(yarnrcUserPath, 'utf-8') : ''
const yarnConfigLocal: YarnConfig = yaml.parse(yarnrcLocal)
const yarnConfigUser: YarnConfig = yaml.parse(yarnrcUser)
const yarnConfigLocal: YarnConfig = yaml.load(yarnrcLocal) as YarnConfig
const yarnConfigUser: YarnConfig = yaml.load(yarnrcUser) as YarnConfig

let npmConfig: Index<string | boolean> = {
...keyValueBy(yarnConfigUser?.npmScopes || {}, npmRegistryKeyValue),
Expand Down

0 comments on commit 5439c87

Please sign in to comment.