Skip to content

Commit b35bca5

Browse files
committed
fix: run prettier
1 parent 210247e commit b35bca5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+928
-1004
lines changed

bin/apply.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
const apply = require('../lib/apply/index.js')
44

55
const main = async () => {
6-
const {
7-
npm_config_global: globalMode,
8-
npm_config_local_prefix: root,
9-
} = process.env
6+
const { npm_config_global: globalMode, npm_config_local_prefix: root } = process.env
107

118
// do nothing in global mode or when the local prefix isn't set
129
if (globalMode === 'true' || !root) {
@@ -16,7 +13,7 @@ const main = async () => {
1613
await apply(root)
1714
}
1815

19-
module.exports = main().catch((err) => {
16+
module.exports = main().catch(err => {
2017
console.error(err.stack)
2118
process.exitCode = 1
2219
})

bin/check.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const check = require('../lib/check/index.js')
44
const output = require('../lib/util/output.js')
55

66
const main = async () => {
7-
const {
8-
npm_config_local_prefix: root,
9-
} = process.env
7+
const { npm_config_local_prefix: root } = process.env
108

119
if (!root) {
1210
throw new Error('This package requires npm >7.21.1')
@@ -20,7 +18,7 @@ const main = async () => {
2018
}
2119
}
2220

23-
module.exports = main().catch((err) => {
21+
module.exports = main().catch(err => {
2422
console.error(err.stack)
2523
process.exitCode = 1
2624
})

bin/release-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ReleaseManager.run({
1919
},
2020
}).values,
2121
})
22-
.then((result) => {
22+
.then(result => {
2323
core.setOutput('result', result)
2424
return null
2525
})

bin/release-please.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,27 @@ ReleasePlease.run({
1818
// `RELEASE_PLEASE_<manfiestOverrideConfigName>`
1919
// (eg`RELEASE_PLEASE_lastReleaseSha=<SHA>`) to set one-off config items for
2020
// the release please run without needing to commit and push the config.
21-
overrides: Object.fromEntries(Object.entries(process.env)
22-
.filter(([k, v]) => k.startsWith('RELEASE_PLEASE_') && v != null)
23-
.map(([k, v]) => [k.replace('RELEASE_PLEASE_', ''), v])),
24-
}).then(({ pr, releases }) => {
25-
if (pr) {
26-
core.setOutput('pr', JSON.stringify(pr))
27-
core.setOutput('pr-branch', pr.headBranchName)
28-
core.setOutput('pr-number', pr.number)
29-
core.setOutput('pr-sha', pr.sha)
30-
}
21+
overrides: Object.fromEntries(
22+
Object.entries(process.env)
23+
.filter(([k, v]) => k.startsWith('RELEASE_PLEASE_') && v != null)
24+
.map(([k, v]) => [k.replace('RELEASE_PLEASE_', ''), v]),
25+
),
26+
})
27+
.then(({ pr, releases }) => {
28+
if (pr) {
29+
core.setOutput('pr', JSON.stringify(pr))
30+
core.setOutput('pr-branch', pr.headBranchName)
31+
core.setOutput('pr-number', pr.number)
32+
core.setOutput('pr-sha', pr.sha)
33+
}
3134

32-
if (releases) {
33-
core.setOutput('releases', JSON.stringify(releases))
34-
}
35+
if (releases) {
36+
core.setOutput('releases', JSON.stringify(releases))
37+
}
3538

36-
return null
37-
}).catch(err => {
38-
core.setFailed('Release Please failed')
39-
core.error(err)
40-
})
39+
return null
40+
})
41+
.catch(err => {
42+
core.setFailed('Release Please failed')
43+
core.error(err)
44+
})

lib/apply/apply-files.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,21 @@ const run = async (dir, files, options) => {
66
const { rm, add } = files
77

88
log.verbose('apply-files', 'rm', rm)
9-
await rmEach(dir, rm, options, (f) => fs.rm(f))
9+
await rmEach(dir, rm, options, f => fs.rm(f))
1010

1111
log.verbose('apply-files', 'add', add)
12-
await parseEach(dir, add, options, {}, (p) => p.applyWrite())
12+
await parseEach(dir, add, options, {}, p => p.applyWrite())
1313
}
1414

15-
module.exports = [{
16-
run: (options) => run(
17-
options.config.repoDir,
18-
options.config.repoFiles,
19-
options
20-
),
21-
when: ({ config: c }) => c.applyRepo && c.needsUpdate,
22-
name: 'apply-repo',
23-
}, {
24-
run: (options) => run(
25-
options.config.moduleDir,
26-
options.config.moduleFiles,
27-
options
28-
),
29-
when: ({ config: c }) => c.applyModule && c.needsUpdate,
30-
name: 'apply-module',
31-
}]
15+
module.exports = [
16+
{
17+
run: options => run(options.config.repoDir, options.config.repoFiles, options),
18+
when: ({ config: c }) => c.applyRepo && c.needsUpdate,
19+
name: 'apply-repo',
20+
},
21+
{
22+
run: options => run(options.config.moduleDir, options.config.moduleFiles, options),
23+
when: ({ config: c }) => c.applyModule && c.needsUpdate,
24+
name: 'apply-module',
25+
},
26+
]

lib/apply/apply-version.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ const { log } = require('proc-log')
22
const PackageJson = require('@npmcli/package-json')
33

44
const run = async ({ config: c }) => {
5-
const {
6-
moduleDir: dir,
7-
__CONFIG_KEY__: key,
8-
__VERSION__: version,
9-
} = c
5+
const { moduleDir: dir, __CONFIG_KEY__: key, __VERSION__: version } = c
106

117
log.verbose('apply-version', dir)
128

lib/apply/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
const run = require('../index.js')
22

3-
module.exports = (root) => run(root, [
4-
require('./apply-files.js'),
5-
require('./apply-version.js'),
6-
])
3+
module.exports = root => run(root, [require('./apply-files.js'), require('./apply-version.js')])

lib/check/check-apply.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ const solution = 'npx template-oss-apply --force'
88

99
const run = async (type, dir, files, options) => {
1010
const res = []
11-
const rel = (f) => relative(options.root, f)
11+
const rel = f => relative(options.root, f)
1212
const { add: addFiles, rm: rmFiles } = files
1313

14-
const rm = await rmEach(dir, rmFiles, options, (f) => rel(f))
15-
const [add, update] = partition(await parseEach(dir, addFiles, options, {}, async (p) => {
16-
const diff = await p.applyDiff()
17-
const target = rel(p.target)
18-
if (diff === null) {
19-
// needs to be added
20-
return target
21-
} else if (diff === true) {
22-
// its ok, no diff, this is filtered out
23-
return null
24-
}
25-
return { file: target, diff }
26-
}), (d) => typeof d === 'string')
14+
const rm = await rmEach(dir, rmFiles, options, f => rel(f))
15+
const [add, update] = partition(
16+
await parseEach(dir, addFiles, options, {}, async p => {
17+
const diff = await p.applyDiff()
18+
const target = rel(p.target)
19+
if (diff === null) {
20+
// needs to be added
21+
return target
22+
} else if (diff === true) {
23+
// its ok, no diff, this is filtered out
24+
return null
25+
}
26+
return { file: target, diff }
27+
}),
28+
d => typeof d === 'string',
29+
)
2730

2831
log.verbose('check-apply', 'rm', rm)
2932
if (rm.length) {
@@ -44,31 +47,28 @@ const run = async (type, dir, files, options) => {
4447
}
4548

4649
log.verbose('check-apply', 'update', update)
47-
res.push(...update.sort((a, b) => localeCompare(a.file, b.file)).map(({ file, diff }) => ({
48-
title: `The ${type} file ${basename(file)} needs to be updated:`,
49-
body: [`${file}\n${'='.repeat(40)}\n${diff}`],
50-
solution,
51-
})))
50+
res.push(
51+
...update
52+
.sort((a, b) => localeCompare(a.file, b.file))
53+
.map(({ file, diff }) => ({
54+
title: `The ${type} file ${basename(file)} needs to be updated:`,
55+
body: [`${file}\n${'='.repeat(40)}\n${diff}`],
56+
solution,
57+
})),
58+
)
5259

5360
return res
5461
}
5562

56-
module.exports = [{
57-
run: (options) => run(
58-
'repo',
59-
options.config.repoDir,
60-
options.config.repoFiles,
61-
options
62-
),
63-
when: ({ config: c }) => c.applyRepo,
64-
name: 'check-repo',
65-
}, {
66-
run: (options) => run(
67-
'module',
68-
options.config.moduleDir,
69-
options.config.moduleFiles,
70-
options
71-
),
72-
when: ({ config: c }) => c.applyModule,
73-
name: 'check-module',
74-
}]
63+
module.exports = [
64+
{
65+
run: options => run('repo', options.config.repoDir, options.config.repoFiles, options),
66+
when: ({ config: c }) => c.applyRepo,
67+
name: 'check-repo',
68+
},
69+
{
70+
run: options => run('module', options.config.moduleDir, options.config.moduleFiles, options),
71+
when: ({ config: c }) => c.applyModule,
72+
name: 'check-module',
73+
},
74+
]

lib/check/check-changelog.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ const run = async ({ root, path }) => {
1414
if (!mustStart.test(content)) {
1515
return {
1616
title: `The ${relative(root, changelog)} is incorrect:`,
17-
body: [
18-
'The changelog should start with',
19-
`"# Changelog\n\n#"`,
20-
],
17+
body: ['The changelog should start with', `"# Changelog\n\n#"`],
2118
solution: 'reformat the changelog to have the correct heading',
2219
}
2320
}

lib/check/check-engines.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ const run = async ({ root, path, pkg, config: { omitEngines = [] } }) => {
2727
}
2828

2929
if (invalid.length) {
30-
const title = `The following production dependencies are not compatible with ` +
30+
const title =
31+
`The following production dependencies are not compatible with ` +
3132
`\`engines.node: ${engines}\` found in \`${pkgPath}\`:`
3233
return {
3334
title,
34-
body: invalid.map((dep) => [
35-
`${dep.name}:`,
36-
` engines.node: ${dep.engines}`,
37-
` location: ${dep.location}`,
38-
].join('\n')).join('\n'),
35+
body: invalid
36+
.map(dep => [`${dep.name}:`, ` engines.node: ${dep.engines}`, ` location: ${dep.location}`].join('\n'))
37+
.join('\n'),
3938
solution: 'Remove them or move them to devDependencies.',
4039
}
4140
}

lib/check/check-gitignore.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ const NAME = 'check-gitignore'
1313
const run = async ({ root, path, config }) => {
1414
log.verbose(NAME, { root, path })
1515

16-
const relativeToRoot = (f) => relative(root, resolve(path, f))
16+
const relativeToRoot = f => relative(root, resolve(path, f))
1717

1818
// use the root to detect a git repo but the project directory (path) for the
1919
// ignore check
2020
const ignoreFile = resolve(path, '.gitignore')
21-
if (!await git.is({ cwd: root }) || !existsSync(ignoreFile)) {
21+
if (!(await git.is({ cwd: root })) || !existsSync(ignoreFile)) {
2222
log.verbose(NAME, 'no git or no gitignore')
2323
return null
2424
}
2525

2626
log.verbose(NAME, `using ignore file ${ignoreFile}`)
2727

28-
const res = await git.spawn([
29-
'ls-files',
30-
'--cached',
31-
'--ignored',
32-
// https://git-scm.com/docs/git-ls-files#_exclude_patterns
33-
`--${config.isRoot ? 'exclude-from' : 'exclude-per-directory'}=${basename(ignoreFile)}`,
34-
], { cwd: path })
28+
const res = await git.spawn(
29+
[
30+
'ls-files',
31+
'--cached',
32+
'--ignored',
33+
// https://git-scm.com/docs/git-ls-files#_exclude_patterns
34+
`--${config.isRoot ? 'exclude-from' : 'exclude-per-directory'}=${basename(ignoreFile)}`,
35+
],
36+
{ cwd: path },
37+
)
3538

3639
log.verbose(NAME, 'ls-files', res)
3740

3841
// TODO: files should be filtered if they have already been moved/deleted
3942
// but not committed. Currently you must commit for this check to pass.
40-
const files = res.stdout
41-
.trim()
42-
.split('\n')
43-
.filter(Boolean)
43+
const files = res.stdout.trim().split('\n').filter(Boolean)
4444

4545
if (!files.length) {
4646
return null
@@ -49,7 +49,7 @@ const run = async ({ root, path, config }) => {
4949
const ignores = (await fs.readFile(ignoreFile))
5050
.toString()
5151
.split(/\r?\n/)
52-
.filter((l) => l && !l.trim().startsWith('#'))
52+
.filter(l => l && !l.trim().startsWith('#'))
5353

5454
const relIgnore = relativeToRoot(ignoreFile)
5555

lib/check/check-required.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@ const npa = require('npm-package-arg')
33
const { partition } = require('lodash')
44
const hasPackage = require('../util/has-package.js')
55

6-
const rmCommand = (specs) =>
7-
`npm rm ${specs.map((s) => s.name).join(' ')}`.trim()
6+
const rmCommand = specs => `npm rm ${specs.map(s => s.name).join(' ')}`.trim()
87

9-
const installCommand = (specs, flags) => specs.length ?
10-
`npm i ${specs.map((s) => `${s.name}@${s.fetchSpec}`).join(' ')} ${flags.join(' ')}`.trim() : ''
8+
const installCommand = (specs, flags) =>
9+
specs.length ? `npm i ${specs.map(s => `${s.name}@${s.fetchSpec}`).join(' ')} ${flags.join(' ')}`.trim() : ''
1110

1211
// ensure required packages are present in the correct place
1312
const run = ({ pkg, path, config: { requiredPackages = {} } }) => {
1413
// keys are the dependency location in package.json
1514
// values are a filtered list of parsed specs that dont exist in the current package
1615
// { [location]: [spec1, spec2] }
17-
const requiredByLocation = Object.entries(requiredPackages)
18-
.reduce((acc, [location, pkgs]) => {
19-
acc[location] = pkgs
20-
.filter((spec) => !hasPackage(pkg, spec, [location], path))
21-
.map((spec) => npa(spec))
22-
log.verbose(location, pkg, pkgs)
23-
return acc
24-
}, {})
16+
const requiredByLocation = Object.entries(requiredPackages).reduce((acc, [location, pkgs]) => {
17+
acc[location] = pkgs.filter(spec => !hasPackage(pkg, spec, [location], path)).map(spec => npa(spec))
18+
log.verbose(location, pkg, pkgs)
19+
return acc
20+
}, {})
2521

2622
const requiredEntries = Object.entries(requiredByLocation)
2723

@@ -30,19 +26,21 @@ const run = ({ pkg, path, config: { requiredPackages = {} } }) => {
3026
if (requiredEntries.flatMap(([, specs]) => specs).length) {
3127
return requiredEntries.map(([location, specs]) => {
3228
const locationFlag = hasPackage.flags[location]
33-
const [exactSpecs, saveSpecs] = partition(specs, (s) => s.type === 'version')
29+
const [exactSpecs, saveSpecs] = partition(specs, s => s.type === 'version')
3430

3531
log.verbose('check-required', location, specs)
3632

3733
return {
3834
title: `The following required ${location} were not found:`,
39-
body: specs.map((s) => s.rawSpec === '*' ? s.name : `${s.name}@${s.rawSpec}`),
35+
body: specs.map(s => (s.rawSpec === '*' ? s.name : `${s.name}@${s.rawSpec}`)),
4036
// solution is to remove any existing all at once but add back in by --save-<location>
4137
solution: [
4238
rmCommand(specs),
4339
installCommand(saveSpecs, [locationFlag]),
4440
installCommand(exactSpecs, [locationFlag, '--save-exact']),
45-
].filter(Boolean).join(' && '),
41+
]
42+
.filter(Boolean)
43+
.join(' && '),
4644
}
4745
})
4846
}

0 commit comments

Comments
 (0)