-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(versions): replace how versions are read/written
- Loading branch information
1 parent
240685e
commit e02bc87
Showing
36 changed files
with
926 additions
and
262 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 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,94 @@ | ||
import 'expect-more-jest'; | ||
import { getCorePaths } from './get-core-paths'; | ||
|
||
describe('getCorePaths', () => { | ||
const fn = getCorePaths; | ||
const dev = { | ||
name: 'dev', | ||
path: 'devDependencies', | ||
strategy: 'versionsByName', | ||
}; | ||
|
||
const overrides = { | ||
name: 'overrides', | ||
path: 'overrides', | ||
strategy: 'versionsByName', | ||
}; | ||
|
||
const peer = { | ||
name: 'peer', | ||
path: 'peerDependencies', | ||
strategy: 'versionsByName', | ||
}; | ||
|
||
const pnpmOverrides = { | ||
name: 'pnpmOverrides', | ||
path: 'pnpm.overrides', | ||
strategy: 'versionsByName', | ||
}; | ||
|
||
const prod = { | ||
name: 'prod', | ||
path: 'dependencies', | ||
strategy: 'versionsByName', | ||
}; | ||
|
||
const resolutions = { | ||
name: 'resolutions', | ||
path: 'resolutions', | ||
strategy: 'versionsByName', | ||
}; | ||
|
||
const workspace = { | ||
name: 'workspace', | ||
namePath: 'name', | ||
path: 'version', | ||
strategy: 'name~version', | ||
}; | ||
|
||
const allTypes = [ | ||
dev, | ||
overrides, | ||
peer, | ||
pnpmOverrides, | ||
prod, | ||
resolutions, | ||
workspace, | ||
]; | ||
|
||
it('includes all if none are set', () => { | ||
expect( | ||
fn({ | ||
dev: true, | ||
overrides: true, | ||
peer: true, | ||
pnpmOverrides: true, | ||
prod: true, | ||
resolutions: true, | ||
workspace: true, | ||
}), | ||
).toEqual(allTypes); | ||
}); | ||
|
||
it('includes all if all are set', () => { | ||
expect(fn({})).toEqual(allTypes); | ||
}); | ||
|
||
it('enables one if it is the only one set', () => { | ||
expect(fn({ dev: true })).toEqual([dev]); | ||
expect(fn({ overrides: true })).toEqual([overrides]); | ||
expect(fn({ peer: true })).toEqual([peer]); | ||
expect(fn({ pnpmOverrides: true })).toEqual([pnpmOverrides]); | ||
expect(fn({ prod: true })).toEqual([prod]); | ||
expect(fn({ resolutions: true })).toEqual([resolutions]); | ||
expect(fn({ workspace: true })).toEqual([workspace]); | ||
}); | ||
|
||
it('enables some if only those are set', () => { | ||
expect(fn({ dev: true, prod: true, workspace: true })).toEqual([ | ||
dev, | ||
prod, | ||
workspace, | ||
]); | ||
}); | ||
}); |
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,54 @@ | ||
import { isBoolean, isObject } from 'expect-more'; | ||
import type { Syncpack } from '../../types'; | ||
|
||
type CorePaths = typeof corePaths; | ||
export type CorePathName = keyof CorePaths; | ||
|
||
const corePaths = { | ||
dev: { | ||
path: 'devDependencies', | ||
strategy: 'versionsByName', | ||
}, | ||
overrides: { | ||
path: 'overrides', | ||
strategy: 'versionsByName', | ||
}, | ||
peer: { | ||
path: 'peerDependencies', | ||
strategy: 'versionsByName', | ||
}, | ||
pnpmOverrides: { | ||
path: 'pnpm.overrides', | ||
strategy: 'versionsByName', | ||
}, | ||
prod: { | ||
path: 'dependencies', | ||
strategy: 'versionsByName', | ||
}, | ||
resolutions: { | ||
path: 'resolutions', | ||
strategy: 'versionsByName', | ||
}, | ||
workspace: { | ||
namePath: 'name', | ||
path: 'version', | ||
strategy: 'name~version', | ||
}, | ||
} as const; | ||
|
||
export function getCorePaths( | ||
fromCli: Pick<Partial<Syncpack.Config.Cli>, CorePathName>, | ||
): Syncpack.PathDefinition[] { | ||
const corePathNames = Object.keys(corePaths) as CorePathName[]; | ||
const hasOverride = corePathNames.some((name) => isBoolean(fromCli[name])); | ||
|
||
return corePathNames | ||
.filter((name) => !hasOverride || fromCli[name] === true) | ||
.map(getByName) | ||
.filter(isObject<Syncpack.PathDefinition>); | ||
|
||
function getByName(key: CorePathName): Syncpack.PathDefinition | undefined { | ||
const obj = corePaths[key]; | ||
if (obj) return { ...obj, name: key }; | ||
} | ||
} |
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
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,18 @@ | ||
import { BaseError } from '../../../lib/error'; | ||
import { nameAndVersionProps } from './name-and-version-props'; | ||
import { nameAndVersionString } from './name-and-version-string'; | ||
import { versionString } from './version-string'; | ||
import { versionsByName } from './versions-by-name'; | ||
|
||
export type StrategyByName = typeof strategyByName; | ||
|
||
export const strategyByName = { | ||
'name@version': nameAndVersionString, | ||
'name~version': nameAndVersionProps, | ||
'version': versionString, | ||
'versionsByName': versionsByName, | ||
} as const; | ||
|
||
export function exhaustiveCheck(strategyName: never): never { | ||
throw new BaseError(`Unrecognised strategy "${strategyName}"`); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.ts
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,26 @@ | ||
import type { R } from '@mobily/ts-belt'; | ||
import { O, pipe } from '@mobily/ts-belt'; | ||
import { isNonEmptyString } from 'expect-more'; | ||
import { BaseError } from '../../../../lib/error'; | ||
import { props } from '../../../get-package-json-files/get-patterns/props'; | ||
import type { PackageJsonFile } from '../../../get-package-json-files/package-json-file'; | ||
|
||
// const root: any = this.packageJsonFile.contents; | ||
// if (this.pathDef.name === 'pnpmOverrides') { | ||
// root.pnpm.overrides[this.name] = version; | ||
// } else if (this.pathDef.name !== 'workspace') { | ||
// root[(this.pathDef as any).path][this.name] = version; | ||
// } | ||
|
||
export function getNonEmptyStringProp( | ||
propPath: string, | ||
file: PackageJsonFile, | ||
): R.Result<string, BaseError> { | ||
return pipe( | ||
file.contents, | ||
props(propPath, isNonEmptyString), | ||
O.toResult<string, BaseError>( | ||
new BaseError(`Failed to get ${propPath} in ${file.shortPath}`), | ||
), | ||
); | ||
} |
Oops, something went wrong.