Skip to content

feat: support package.yaml and package.json5 #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 1, 2019
Merged
Prev Previous commit
Next Next commit
fix: preserve indentation in manifests
  • Loading branch information
zkochan committed May 1, 2019
commit 9cbd5ee42b1510db60e4ee3118c7f56bbbae97a5
1 change: 1 addition & 0 deletions packages/find-packages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async function findPkgs (

return pFilter(
paths
.sort()
.map((manifestPath) => path.join(root, manifestPath))
.map(async (manifestPath) => {
try {
Expand Down
10 changes: 3 additions & 7 deletions packages/find-packages/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ test('json and yaml manifests are also found', async t => {

t.equal(pkgs.length, 3)
t.ok(pkgs[0].path)
t.ok(pkgs[0].manifest)
t.equal(pkgs[0].fileName, 'package.yaml')
t.equal(pkgs[0].manifest.name, 'component-1')
t.ok(pkgs[1].path)
t.ok(pkgs[1].manifest)
t.equal(pkgs[1].fileName, 'package.json5')
t.equal(pkgs[1].manifest.name, 'component-2')
t.ok(pkgs[2].path)
t.ok(pkgs[2].manifest)
t.equal(pkgs[2].fileName, 'package.json')
t.deepEqual([pkgs[0].manifest.name, pkgs[1].manifest.name, pkgs[2].manifest.name].sort(), ['component-1', 'component-2', 'foo'])
t.equal(pkgs[2].manifest.name, 'foo')
t.end()
})
2 changes: 1 addition & 1 deletion packages/pnpm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@pnpm/store-path": "1.0.4",
"@pnpm/types": "3.2.0",
"@pnpm/utils": "0.10.4",
"@pnpm/write-importer-manifest": "0.0.0",
"@types/archy": "0.0.31",
"@types/lru-cache": "^5.1.0",
"@types/minimatch": "^3.0.3",
Expand Down Expand Up @@ -94,6 +93,7 @@
"@pnpm/prepare": "0.0.0",
"@pnpm/read-package-json": "2.0.1",
"@pnpm/tslint-config": "0.0.0",
"@pnpm/write-importer-manifest": "0.0.0",
"@types/byline": "4.2.31",
"@types/common-tags": "1.8.0",
"@types/mkdirp": "0.5.2",
Expand Down
6 changes: 2 additions & 4 deletions packages/pnpm/src/cmd/install.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { readImporterManifestOnly, tryReadImporterManifest } from '@pnpm/read-importer-manifest'
import { getSaveType } from '@pnpm/utils'
import writeImporterManifest from '@pnpm/write-importer-manifest'
import path = require('path')
import {
install,
mutateModules,
Expand Down Expand Up @@ -55,7 +53,7 @@ export default async function installCmd (
storeController: store.ctrl,
}

let { manifest, fileName } = await tryReadImporterManifest(opts.prefix)
let { manifest, writeImporterManifest } = await tryReadImporterManifest(opts.prefix)
if (manifest === null) {
if (opts.update) {
const err = new Error('No package.json found')
Expand Down Expand Up @@ -88,7 +86,7 @@ export default async function installCmd (
targetDependenciesField: getSaveType(installOpts),
},
], installOpts)
await writeImporterManifest(path.join(opts.prefix, fileName), updatedImporter.manifest)
await writeImporterManifest(updatedImporter.manifest)
}

if (opts.linkWorkspacePackages && opts.workspacePrefix) {
Expand Down
9 changes: 4 additions & 5 deletions packages/pnpm/src/cmd/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import readImporterManifest, {
readImporterManifestOnly,
tryReadImporterManifest,
} from '@pnpm/read-importer-manifest'
import writeImporterManifest from '@pnpm/write-importer-manifest'
import pLimit = require('p-limit')
import path = require('path')
import pathAbsolute = require('path-absolute')
Expand Down Expand Up @@ -47,12 +46,12 @@ export default async (

// pnpm link
if (!input || !input.length) {
const { manifest, fileName } = await tryReadImporterManifest(opts.globalPrefix)
const { manifest, writeImporterManifest } = await tryReadImporterManifest(opts.globalPrefix)
const newManifest = await linkToGlobal(cwd, {
...linkOpts,
manifest: manifest || {},
})
await writeImporterManifest(path.join(opts.globalPrefix, fileName), newManifest)
await writeImporterManifest(newManifest)
return
}

Expand Down Expand Up @@ -97,12 +96,12 @@ export default async (
)
})),
)
const { manifest, fileName } = await readImporterManifest(cwd)
const { manifest, writeImporterManifest } = await readImporterManifest(cwd)
const newManifest = await link(pkgPaths, path.join(cwd, 'node_modules'), {
...linkOpts,
manifest,
})
await writeImporterManifest(path.join(cwd, fileName), newManifest)
await writeImporterManifest(newManifest)

await Promise.all(
Array.from(storeControllerCache.values())
Expand Down
4 changes: 2 additions & 2 deletions packages/pnpm/src/cmd/recursive/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import pLimit = require('p-limit')
import { PackageNode } from 'pkgs-graph'
import RecursiveSummary from './recursiveSummary'

export default async (
export default async <T> (
packageChunks: string[][],
graph: {[id: string]: PackageNode<{ fileName: string }>},
graph: {[id: string]: PackageNode<T>},
args: string[],
cmd: string,
opts: {
Expand Down
20 changes: 10 additions & 10 deletions packages/pnpm/src/cmd/recursive/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { PackageNode } from 'pkgs-graph'
import R = require('ramda')
import { PackageSelector } from '../../parsePackageSelectors'

interface PackageGraph {
[id: string]: PackageNode<{ fileName: string }>,
interface PackageGraph<T> {
[id: string]: PackageNode<T>,
}

interface Graph {
[nodeId: string]: string[],
}

export function filterGraph (
pkgGraph: PackageGraph,
export function filterGraph<T> (
pkgGraph: PackageGraph<T>,
packageSelectors: PackageSelector[],
): PackageGraph {
): PackageGraph<T> {
const cherryPickedPackages = [] as string[]
const walkedDependencies = new Set<string>()
const walkedDependents = new Set<string>()
Expand Down Expand Up @@ -46,7 +46,7 @@ export function filterGraph (
return R.pick(Array.from(walked), pkgGraph)
}

function pkgGraphToGraph (pkgGraph: PackageGraph): Graph {
function pkgGraphToGraph<T> (pkgGraph: PackageGraph<T>): Graph {
const graph: Graph = {}
Object.keys(pkgGraph).forEach((nodeId) => {
graph[nodeId] = pkgGraph[nodeId].dependencies
Expand All @@ -68,15 +68,15 @@ function reverseGraph (graph: Graph): Graph {
return reversedGraph
}

function matchPackages (
graph: PackageGraph,
function matchPackages<T> (
graph: PackageGraph<T>,
pattern: string,
) {
return R.keys(graph).filter((id) => graph[id].package.manifest.name && minimatch(graph[id].package.manifest.name, pattern))
}

function matchPackagesByPath (
graph: PackageGraph,
function matchPackagesByPath<T> (
graph: PackageGraph<T>,
pathStartsWith: string,
) {
return R.keys(graph).filter((location) => isSubdir(pathStartsWith, location))
Expand Down
23 changes: 11 additions & 12 deletions packages/pnpm/src/cmd/recursive/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logger from '@pnpm/logger'
import { DependencyManifest, ImporterManifest } from '@pnpm/types'
import { getSaveType } from '@pnpm/utils'
import writeImporterManifest from '@pnpm/write-importer-manifest'
import camelcaseKeys = require('camelcase-keys')
import graphSequencer = require('graph-sequencer')
import isSubdir = require('is-subdir')
Expand Down Expand Up @@ -100,7 +99,7 @@ export default async (
}

export async function recursive (
allPkgs: Array<{fileName: string, path: string, manifest: DependencyManifest}>,
allPkgs: Array<{path: string, manifest: DependencyManifest, writeImporterManifest: (manifest: ImporterManifest) => Promise<void>}>,
input: string[],
opts: PnpmOptions & {
allowNew?: boolean,
Expand All @@ -116,7 +115,7 @@ export async function recursive (
}

const pkgGraphResult = createPkgGraph(allPkgs)
let pkgs: Array<{fileName: string, path: string, manifest: ImporterManifest}>
let pkgs: Array<{path: string, manifest: ImporterManifest, writeImporterManifest: (manifest: ImporterManifest) => Promise<void> }>
if (opts.packageSelectors && opts.packageSelectors.length) {
pkgGraphResult.graph = filterGraph(pkgGraphResult.graph, opts.packageSelectors)
pkgs = allPkgs.filter((pkg: {path: string}) => pkgGraphResult.graph[pkg.path])
Expand All @@ -127,11 +126,11 @@ export async function recursive (
if (pkgs.length === 0) {
return false
}
const manifestsByPath: { [path: string]: { manifest: ImporterManifest, fileName: string } } = {}
const manifestsByPath: { [path: string]: { manifest: ImporterManifest, writeImporterManifest: (manifest: ImporterManifest) => Promise<void> } } = {}
for (const pkg of pkgs) {
manifestsByPath[pkg.path] = {
fileName: pkg.fileName,
manifest: pkg.manifest,
writeImporterManifest: pkg.writeImporterManifest,
}
}

Expand Down Expand Up @@ -238,11 +237,11 @@ export async function recursive (
if (importers.length === 0) return true
const hooks = opts.ignorePnpmfile ? {} : requireHooks(opts.lockfileDirectory, opts)
const mutation = cmdFullName === 'uninstall' ? 'uninstallSome' : (input.length === 0 && !updateToLatest ? 'install' : 'installSome')
const fileNames = [] as string[]
const writeImporterManifests = [] as Array<(manifest: ImporterManifest) => Promise<void>>
const mutatedImporters = await Promise.all<MutatedImporter>(importers.map(async ({ buildIndex, prefix }, index) => {
const localConfigs = await memReadLocalConfigs(prefix)
const { manifest, fileName } = manifestsByPath[prefix]
fileNames[index] = fileName
const { manifest, writeImporterManifest } = manifestsByPath[prefix]
writeImporterManifests[index] = writeImporterManifest
const shamefullyFlatten = typeof localConfigs.shamefullyFlatten === 'boolean'
? localConfigs.shamefullyFlatten
: opts.shamefullyFlatten
Expand Down Expand Up @@ -297,7 +296,7 @@ export async function recursive (
await Promise.all(
mutatedPkgs
.filter((mutatedPkg, index) => mutatedImporters[index].mutation !== 'install')
.map(({ manifest, prefix }, index) => writeImporterManifest(path.join(prefix, fileNames[index]), manifest))
.map(({ manifest, prefix }, index) => writeImporterManifests[index](manifest))
)
return true
}
Expand All @@ -315,7 +314,7 @@ export async function recursive (
return
}

const { manifest, fileName } = manifestsByPath[prefix]
const { manifest, writeImporterManifest } = manifestsByPath[prefix]
let currentInput = [...input]
if (updateToLatest) {
if (!currentInput || !currentInput.length) {
Expand Down Expand Up @@ -356,7 +355,7 @@ export async function recursive (
},
)
if (action !== install) {
await writeImporterManifest(path.join(prefix, fileName), newManifest)
await writeImporterManifest(newManifest)
}
result.passes++
} catch (err) {
Expand Down Expand Up @@ -482,7 +481,7 @@ async function unlinkPkgs (dependencyNames: string[], manifest: ImporterManifest
)
}

function sortPackages (pkgGraph: {[nodeId: string]: PackageNode<{ fileName: string }>}): string[][] {
function sortPackages<T> (pkgGraph: {[nodeId: string]: PackageNode<T>}): string[][] {
const keys = Object.keys(pkgGraph)
const setOfKeys = new Set(keys)
const graph = new Map(
Expand Down
4 changes: 2 additions & 2 deletions packages/pnpm/src/cmd/recursive/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import pLimit = require('p-limit')
import { PackageNode } from 'pkgs-graph'
import RecursiveSummary from './recursiveSummary'

export default async (
export default async <T> (
packageChunks: string[][],
graph: {[id: string]: PackageNode<{ fileName: string }>},
graph: {[id: string]: PackageNode<T>},
args: string[],
cmd: string,
opts: {
Expand Down
8 changes: 3 additions & 5 deletions packages/pnpm/src/cmd/uninstall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import readImporterManifest from '@pnpm/read-importer-manifest'
import writeImporterManifest from '@pnpm/write-importer-manifest'
import path = require('path')
import {
mutateModules,
uninstall,
Expand All @@ -19,9 +17,9 @@ export default async function uninstallCmd (
storeController: store.ctrl,
})
if (opts.lockfileDirectory === opts.prefix) {
const { manifest, fileName } = await readImporterManifest(opts.prefix)
const { manifest, writeImporterManifest } = await readImporterManifest(opts.prefix)
const newManifest = await uninstall(manifest, input, uninstallOpts)
await writeImporterManifest(path.join(opts.prefix, fileName), newManifest)
await writeImporterManifest(newManifest)
return
}
uninstallOpts['localPackages'] = opts.linkWorkspacePackages && opts.workspacePrefix
Expand All @@ -40,5 +38,5 @@ export default async function uninstallCmd (
],
uninstallOpts,
)
await writeImporterManifest(path.join(opts.prefix, currentManifest.fileName), mutationResult.manifest)
await currentManifest.writeImporterManifest(mutationResult.manifest)
}
4 changes: 2 additions & 2 deletions packages/pnpm/src/findWorkspacePackages.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants'
import { DependencyManifest } from '@pnpm/types'
import { DependencyManifest, ImporterManifest } from '@pnpm/types'
import findPackages from 'find-packages'
import path = require('path')
import readYamlFile from 'read-yaml-file'

export default async (workspaceRoot: string): Promise<Array<{path: string, manifest: DependencyManifest, fileName: string}>> => {
export default async (workspaceRoot: string): Promise<Array<{path: string, manifest: DependencyManifest, writeImporterManifest: (manifest: ImporterManifest) => Promise<void>}>> => {
const packagesManifest = await requirePackagesManifest(workspaceRoot)
const pkgs = await findPackages(workspaceRoot, {
ignore: [
Expand Down
1 change: 0 additions & 1 deletion packages/pnpm/test/install/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import crossSpawn = require('cross-spawn')
import delay = require('delay')
import dirIsCaseSensitive from 'dir-is-case-sensitive'
import fs = require('fs')
import isWindows = require('is-windows')
import loadJsonFile = require('load-json-file')
import path = require('path')
import exists = require('path-exists')
Expand Down
12 changes: 9 additions & 3 deletions packages/read-importer-manifest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/read-importer-manifest#readme",
"dependencies": {
"@pnpm/types": "^3.0.0",
"load-json-file": "6.0.0",
"read-json5-file": "0.0.0",
"read-yaml-file": "1.1.0"
"@pnpm/write-importer-manifest": "0.0.0",
"@types/detect-indent": "5.0.0",
"detect-indent": "5.0.0",
"graceful-fs": "4.1.15",
"json5": "2.1.0",
"read-yaml-file": "1.1.0",
"strip-bom": "4.0.0"
},
"devDependencies": {
"@pnpm/read-importer-manifest": "link:",
"@pnpm/tslint-config": "0.0.0",
"@types/graceful-fs": "4.1.3",
"@types/json5": "0.0.30",
"@types/node": "^10.3.2",
"@types/tape": "^4.2.31",
"mos": "^2.0.0-alpha.3",
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy