Skip to content

Commit 761013c

Browse files
committed
code review
1 parent c98c6d6 commit 761013c

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

bin/commands/generate.mjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ export default new Command('generate')
2929

3030
// Options that need to be converted into a configuration
3131
.addOption(
32-
new Option(
33-
'-i, --input <patterns...>',
34-
'Input file patterns (glob)'
35-
).makeOptionMandatory()
32+
new Option('-i, --input <patterns...>', 'Input file patterns (glob)')
3633
)
3734
.addOption(
38-
new Option('-t, --target <generator...>', 'Target generator(s)')
39-
.makeOptionMandatory()
40-
.choices(Object.keys(publicGenerators))
35+
new Option('-t, --target <generator...>', 'Target generator(s)').choices(
36+
Object.keys(publicGenerators)
37+
)
4138
)
4239
.addOption(
4340
new Option('--ignore <patterns...>', 'Ignore file patterns (glob)')

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The `global` object contains settings that apply to all generators unless overri
6161
| Property | Type | Description | Default |
6262
| ------------ | ------------------ | ------------------------------------------ | -------------------------------------------------- |
6363
| `version` | `string \| SemVer` | Documentation version | `process.version` |
64-
| `minify` | `boolean` | Whether to minify output | `false` |
64+
| `minify` | `boolean` | Whether to minify output | `true` |
6565
| `repository` | `string` | GitHub repository in `owner/repo` format | `'nodejs/node'` |
6666
| `ref` | `string` | Git reference (branch, tag, or commit SHA) | `'HEAD'` |
6767
| `baseURL` | `string \| URL` | Base URL for documentation | `'https://nodejs.org/docs'` |

src/generators/sitemap/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
.filter(entry => entry.heading.depth === 1)
4141
.map(entry => createPageSitemapEntry(entry, config.baseURL, lastmod));
4242

43-
const { href: loc } = new URL('/latest/api/', config.baseURL);
43+
const { href: loc } = new URL('latest/api/', config.baseURL);
4444

4545
/**
4646
* @typedef {import('./types').SitemapEntry}

src/generators/web/ui/components/NavBar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default () => {
2828
/>
2929
<a
3030
href={`https://github.com/${STATIC_DATA.repository}`}
31-
aria-label={`${STATIC_DATA.title} Github`}
31+
aria-label={`${STATIC_DATA.title} GitHub`}
3232
className={styles.ghIconWrapper}
3333
>
3434
<GitHubIcon />

src/utils/configuration/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { coerce } from 'semver';
66
import { CHANGELOG_URL, populate } from './templates.mjs';
77
import { allGenerators } from '../../generators/index.mjs';
88
import { parseChangelog, parseIndex } from '../../parsers/markdown.mjs';
9+
import { enforceArray } from '../array.mjs';
910
import { leftHandAssign } from '../generators.mjs';
1011
import { lazy } from '../misc.mjs';
1112
import { importFromURL } from '../url.mjs';
@@ -89,7 +90,7 @@ const merge = (objs, maxDepth, currentDepth = 0) => {
8990
* Loads a configuration file from a URL or file path.
9091
*
9192
* @param {string} filePath - The URL or file path to the configuration file
92-
* @returns {Promise<Object>} The imported configuration object, or an empty object if no path provided
93+
* @returns {Promise<Partial<import('./types').Configuration>>} The imported configuration object, or an empty object if no path provided
9394
*/
9495
export const loadConfigFile = filePath =>
9596
filePath ? importFromURL(filePath) : {};
@@ -154,6 +155,7 @@ export const createConfigFromCLIOptions = options => ({
154155
*/
155156
export const createRunConfiguration = async options => {
156157
const config = await loadConfigFile(options.configFile);
158+
config.target &&= enforceArray(config.target);
157159

158160
// Merge with defaults
159161
// We set maxDepth as 2, as that's the depth of

src/utils/url.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFile } from 'node:fs/promises';
2-
import { extname } from 'node:path';
2+
import { extname, isAbsolute, join } from 'node:path';
3+
import { pathToFileURL } from 'node:url';
34

45
/**
56
* Converts a value to a parsed URL object.
@@ -34,11 +35,13 @@ export const loadFromURL = async url => {
3435
* @returns {Promise<any>} The imported module
3536
*/
3637
export const importFromURL = async url => {
37-
const useJSONAssertion = extname(url) === '.json';
38+
const useJSONAssertion = extname(String(parsed)) === '.json';
39+
40+
const parsed = toParsedURL(url);
3841

3942
const imported = await import(
40-
url,
41-
useJSONAssertion && { with: { type: 'json' } }
43+
parsed ?? pathToFileURL(isAbsolute(url) ? url : join(process.cwd(), url)),
44+
useJSONAssertion ? { with: { type: 'json' } } : {}
4245
);
4346

4447
return imported.default ?? imported;

0 commit comments

Comments
 (0)