-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3eeb6cc
commit d16acd1
Showing
7 changed files
with
193 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
import type { Config } from '../types.js'; | ||
import { normalizeConfig } from '../config.js'; | ||
|
||
export function c(overrides: Partial<Config> = {}): Config { | ||
return { | ||
'write-as': 'pinned' as const, | ||
...overrides, | ||
'update-range': { | ||
'~': [], | ||
'^': [], | ||
...overrides['update-range'], | ||
}, | ||
}; | ||
import type { Config, UserConfig } from '../types.js'; | ||
|
||
export function c(userConfig: UserConfig = {}): Config { | ||
return normalizeConfig(userConfig); | ||
} |
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 { describe, expect as e, it } from 'vitest'; | ||
|
||
import { c } from './-tests/helpers.ts'; | ||
import { getOverride } from './config.js'; | ||
|
||
const expect = e.soft; | ||
|
||
describe('getOverride', () => { | ||
it('resolves a package glob', () => { | ||
expect( | ||
getOverride( | ||
'packages/ember-repl/addon', | ||
c({ | ||
overrides: [ | ||
{ | ||
path: [ | ||
'packages/*/addon/package.json', | ||
'packages/syntax/*/package.json', | ||
], | ||
dependencies: false, | ||
devDependencies: 'pinned', | ||
}, | ||
], | ||
}), | ||
), | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"dependencies": false, | ||
"devDependencies": "pinned", | ||
"path": [ | ||
"packages/*/addon/package.json", | ||
"packages/syntax/*/package.json", | ||
], | ||
} | ||
`); | ||
}); | ||
|
||
it('returns nothing when no match is found', () => { | ||
expect( | ||
getOverride( | ||
'apps/repl', | ||
c({ | ||
overrides: [ | ||
{ | ||
path: ['packages/*/addon/package.json'], | ||
dependencies: false, | ||
devDependencies: 'pinned', | ||
}, | ||
], | ||
}), | ||
), | ||
).toBe(undefined); | ||
}); | ||
}); |
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,56 @@ | ||
import path from 'node:path'; | ||
|
||
import { minimatch } from 'minimatch'; | ||
|
||
/** | ||
* @param {Partial<import('./types.ts').UserConfig>} [ userConfig ] | ||
* @return {import('./types.ts').Config} | ||
*/ | ||
export function normalizeConfig(userConfig) { | ||
let config = userConfig || {}; | ||
|
||
let topLevel = { | ||
'write-as': config['write-as'] || 'pinned', | ||
}; | ||
|
||
/** @type {import('./types.ts').Config['overrides'] } */ | ||
const overrides = | ||
config['overrides']?.map((override) => { | ||
const defaultRange = topLevel['write-as']; | ||
const pathsArray = Array.isArray(override.path) | ||
? override.path | ||
: [override.path]; | ||
|
||
return { | ||
devDependencies: override['devDependencies'] ?? defaultRange, | ||
dependencies: override['dependencies'] ?? defaultRange, | ||
path: pathsArray, | ||
}; | ||
}) || []; | ||
|
||
return { | ||
...topLevel, | ||
'update-range': { | ||
'~': [], | ||
'^': [], | ||
...config['update-range'], | ||
}, | ||
overrides, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {string} relativePath the workspace path | ||
* @param {import('./types.ts').Config} config | ||
*/ | ||
export function getOverride(relativePath, config) { | ||
let { overrides } = config; | ||
|
||
let packageJsonPath = path.join(relativePath, 'package.json'); | ||
|
||
let override = overrides.find((override) => { | ||
return override.path.some((match) => minimatch(packageJsonPath, match)); | ||
}); | ||
|
||
return override; | ||
} |
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
Oops, something went wrong.