Skip to content

Commit 0f2dc7a

Browse files
authored
feat: sort wireit (#402)
1 parent 94c3904 commit 0f2dc7a

5 files changed

Lines changed: 101 additions & 0 deletions

File tree

defaultRules.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ _Note: when a specific key order is used, any other keys will be sorted in the e
5353
| binary, | Key order: `module_name`, `module_path`, `remote_path`, `package_name`, `host` |
5454
| scripts | [Script sort](#scripts) |
5555
| betterScripts | [Script sort](#scripts) |
56+
| wireit | [Wireit sort](#wireit) |
5657
| contributes | Key sort |
5758
| activationEvents | Unique items |
5859
| husky | Sorts the `hooks` field using [git hook sort](#git-hooks) |
@@ -161,6 +162,18 @@ Item order:
161162

162163
Keys are sorted alphabetically except for `overrides`, which is placed last. Keys are also sorted in `overrides` and `overrides.options` items.
163164

165+
### Wireit
166+
167+
Script names are sorted alphabetically. Each script's properties use the order from [wireit's own examples](https://github.com/google/wireit), with remaining properties sorted alphabetically:
168+
169+
| Key | Rules |
170+
| ------------ | -------------------------------------------- |
171+
| command | |
172+
| dependencies | Key order (per item): `script`, `cascade` |
173+
| files | |
174+
| output | |
175+
| _remaining_ | Alphabetical, with nested object key sorting |
176+
164177
### Scripts
165178

166179
Keys are sorted alphabetically except for [pre/post scripts](https://docs.npmjs.com/cli/v6/using-npm/scripts#pre--post-scripts). Those are placed before and after their corresponding base npm script.

index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,43 @@ const sortPrettierConfig = pipe([
252252
])
253253

254254
const sortVolta = sortObjectBy(['node', 'npm', 'yarn'])
255+
256+
// https://github.com/google/wireit
257+
const wireitScriptProperties = ['command', 'dependencies', 'files', 'output']
258+
const sortWireitScript = pipe([
259+
sortObjectBy(wireitScriptProperties),
260+
overProperty(
261+
'dependencies',
262+
onArray((deps) => deps.map(sortObjectBy(['script', 'cascade']))),
263+
),
264+
overProperty(
265+
'env',
266+
onObject((env) =>
267+
sortObjectKeys(
268+
Object.fromEntries(
269+
Object.entries(env).map(([key, value]) => [
270+
key,
271+
sortObjectBy(['external', 'default'])(value),
272+
]),
273+
),
274+
),
275+
),
276+
),
277+
overProperty(
278+
'service',
279+
pipe([sortObjectBy(['readyWhen']), overProperty('readyWhen', sortObject)]),
280+
),
281+
])
282+
const sortWireit = onObject((wireit) =>
283+
sortObjectKeys(
284+
Object.fromEntries(
285+
Object.entries(wireit).map(([name, config]) => [
286+
name,
287+
sortWireitScript(config),
288+
]),
289+
),
290+
),
291+
)
255292
const sortDevEngines = overProperty(
256293
'packageManager',
257294
sortObjectBy(['name', 'version', 'onFail']),
@@ -479,6 +516,7 @@ const fields = [
479516
},
480517
{ key: 'scripts', over: sortScripts },
481518
{ key: 'betterScripts', over: sortScripts },
519+
{ key: 'wireit', over: sortWireit },
482520
/* vscode */ { key: 'l10n' },
483521
/* vscode */ { key: 'contributes', over: sortObject },
484522
/* vscode */ { key: 'activationEvents', over: uniq },

tests/fields.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,54 @@ test('badges', (t) => {
258258
)
259259
})
260260

261+
test('wireit', macro.sortObject, {
262+
path: 'wireit',
263+
value: {
264+
test: {
265+
dependencies: ['build'],
266+
command: 'jest',
267+
},
268+
build: {
269+
output: ['lib/**'],
270+
env: {
271+
NODE_ENV: 'production',
272+
CI: { default: 'false', external: true },
273+
},
274+
files: ['src/**/*.ts'],
275+
service: {
276+
readyWhen: { lineMatches: 'server started', z: 'z', a: 'a' },
277+
},
278+
allowUsuallyExcludedPaths: false,
279+
packageLocks: ['pnpm-lock.yaml'],
280+
clean: true,
281+
dependencies: [{ cascade: false, script: '../foo:build' }, 'lint'],
282+
command: 'tsc',
283+
},
284+
},
285+
expect: {
286+
build: {
287+
command: 'tsc',
288+
dependencies: [{ script: '../foo:build', cascade: false }, 'lint'],
289+
files: ['src/**/*.ts'],
290+
output: ['lib/**'],
291+
allowUsuallyExcludedPaths: false,
292+
clean: true,
293+
env: {
294+
CI: { external: true, default: 'false' },
295+
NODE_ENV: 'production',
296+
},
297+
packageLocks: ['pnpm-lock.yaml'],
298+
service: {
299+
readyWhen: { a: 'a', lineMatches: 'server started', z: 'z' },
300+
},
301+
},
302+
test: {
303+
command: 'jest',
304+
dependencies: ['build'],
305+
},
306+
},
307+
})
308+
261309
test('pnpm', macro.sortObject, {
262310
path: 'pnpm',
263311
value: {

tests/snapshots/main.js.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Generated by [AVA](https://avajs.dev).
118118
"unpkg": "unpkg",␊
119119
"version": "version",␊
120120
"volta": "volta",␊
121+
"wireit": "wireit",␊
121122
"workspaces": "workspaces",␊
122123
"xo": "xo"␊
123124
}`,
@@ -171,6 +172,7 @@ Generated by [AVA](https://avajs.dev).
171172
"binary": "binary",␊
172173
"scripts": "scripts",␊
173174
"betterScripts": "betterScripts",␊
175+
"wireit": "wireit",␊
174176
"l10n": "l10n",␊
175177
"contributes": "contributes",␊
176178
"activationEvents": "activationEvents",␊

tests/snapshots/main.js.snap

9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)