Skip to content

Commit 6634b01

Browse files
authored
refactor: options, nodejs version, path resolves (#58)
1 parent 048a70a commit 6634b01

3 files changed

Lines changed: 114 additions & 78 deletions

File tree

Lines changed: 57 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,71 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`options defaults should return specific properties 1`] = `
3+
exports[`options defaults should return specific properties: defaults 1`] = `
44
{
5-
"DEFAULT_OPTIONS": {
6-
"contextPath": "/",
7-
"docsHost": false,
8-
"docsPath": "/documentation",
9-
"http": {
10-
"allowedHosts": [],
11-
"allowedOrigins": [],
12-
"host": "127.0.0.1",
13-
"port": 8080,
5+
"contextPath": "/",
6+
"contextUrl": "file:///",
7+
"docsHost": false,
8+
"docsPath": "/documentation",
9+
"http": {
10+
"allowedHosts": [],
11+
"allowedOrigins": [],
12+
"host": "127.0.0.1",
13+
"port": 8080,
14+
},
15+
"isHttp": false,
16+
"llmsFilesPath": "/llms-files",
17+
"logging": {
18+
"level": "info",
19+
"logger": "@patternfly/patternfly-mcp",
20+
"protocol": false,
21+
"stderr": false,
22+
"transport": "stdio",
23+
},
24+
"name": "@patternfly/patternfly-mcp",
25+
"nodeVersion": 22,
26+
"pfExternal": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content",
27+
"pfExternalAccessibility": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/accessibility",
28+
"pfExternalChartsDesign": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/charts",
29+
"pfExternalDesignComponents": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/components",
30+
"pfExternalDesignLayouts": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/layouts",
31+
"pfExternalExamplesCharts": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-charts/src/victory/components",
32+
"pfExternalExamplesComponents": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-core/src/components",
33+
"pfExternalExamplesLayouts": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-core/src/layouts",
34+
"pfExternalExamplesTable": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-table/src/components",
35+
"repoName": "patternfly-mcp",
36+
"resourceMemoOptions": {
37+
"default": {
38+
"cacheLimit": 3,
1439
},
15-
"isHttp": false,
16-
"llmsFilesPath": "/llms-files",
17-
"logging": {
18-
"level": "info",
19-
"logger": "@patternfly/patternfly-mcp",
20-
"protocol": false,
21-
"stderr": false,
22-
"transport": "stdio",
40+
"fetchUrl": {
41+
"cacheErrors": false,
42+
"cacheLimit": 100,
43+
"expire": 180000,
2344
},
24-
"name": "@patternfly/patternfly-mcp",
25-
"pfExternal": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content",
26-
"pfExternalAccessibility": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/accessibility",
27-
"pfExternalChartsDesign": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/charts",
28-
"pfExternalDesignComponents": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/components",
29-
"pfExternalDesignLayouts": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/layouts",
30-
"pfExternalExamplesCharts": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-charts/src/victory/components",
31-
"pfExternalExamplesComponents": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-core/src/components",
32-
"pfExternalExamplesLayouts": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-core/src/layouts",
33-
"pfExternalExamplesTable": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-table/src/components",
34-
"repoName": "patternfly-mcp",
35-
"resourceMemoOptions": {
36-
"default": {
37-
"cacheLimit": 3,
38-
},
39-
"fetchUrl": {
40-
"cacheErrors": false,
41-
"cacheLimit": 100,
42-
"expire": 180000,
43-
},
44-
"readFile": {
45-
"cacheErrors": false,
46-
"cacheLimit": 50,
47-
"expire": 120000,
48-
},
45+
"readFile": {
46+
"cacheErrors": false,
47+
"cacheLimit": 50,
48+
"expire": 120000,
4949
},
50-
"separator": "
50+
},
51+
"separator": "
5152
5253
---
5354
5455
",
55-
"toolMemoOptions": {
56-
"fetchDocs": {
57-
"cacheErrors": false,
58-
"cacheLimit": 15,
59-
"expire": 60000,
60-
},
61-
"usePatternFlyDocs": {
62-
"cacheErrors": false,
63-
"cacheLimit": 10,
64-
"expire": 60000,
65-
},
56+
"toolMemoOptions": {
57+
"fetchDocs": {
58+
"cacheErrors": false,
59+
"cacheLimit": 15,
60+
"expire": 60000,
61+
},
62+
"usePatternFlyDocs": {
63+
"cacheErrors": false,
64+
"cacheLimit": 10,
65+
"expire": 60000,
6666
},
67-
"urlRegex": /\\^\\(https\\?:\\)\\\\/\\\\//i,
68-
"version": "0.0.0",
6967
},
70-
"LOG_BASENAME": "pf-mcp:log",
71-
"PF_EXTERNAL": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content",
72-
"PF_EXTERNAL_ACCESSIBILITY": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/accessibility",
73-
"PF_EXTERNAL_CHARTS_DESIGN": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/charts",
74-
"PF_EXTERNAL_DESIGN_COMPONENTS": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/components",
75-
"PF_EXTERNAL_DESIGN_LAYOUTS": "https://raw.githubusercontent.com/patternfly/patternfly-org/fb05713aba75998b5ecf5299ee3c1a259119bd74/packages/documentation-site/patternfly-docs/content/design-guidelines/layouts",
76-
"PF_EXTERNAL_EXAMPLES": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages",
77-
"PF_EXTERNAL_EXAMPLES_CHARTS": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-charts/src/victory/components",
78-
"PF_EXTERNAL_EXAMPLES_LAYOUTS": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-core/src/layouts",
79-
"PF_EXTERNAL_EXAMPLES_REACT_CORE": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-core/src/components",
80-
"PF_EXTERNAL_EXAMPLES_TABLE": "https://raw.githubusercontent.com/patternfly/patternfly-react/refs/tags/v6.4.0/packages/react-table/src/components",
81-
"PF_EXTERNAL_EXAMPLES_VERSION": "v6.4.0",
82-
"PF_EXTERNAL_VERSION": "fb05713aba75998b5ecf5299ee3c1a259119bd74",
68+
"urlRegex": /\\^\\(https\\?:\\)\\\\/\\\\//i,
69+
"version": "0.0.0",
8370
}
8471
`;
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
1-
import * as options from '../options.defaults';
1+
import { DEFAULT_OPTIONS, getNodeMajorVersion } from '../options.defaults';
22

33
describe('options defaults', () => {
44
it('should return specific properties', () => {
5-
expect(options).toMatchSnapshot();
5+
expect(DEFAULT_OPTIONS).toMatchSnapshot('defaults');
6+
});
7+
});
8+
9+
describe('getNodeMajorVersion', () => {
10+
it('should get the current Node.js version', () => {
11+
// Purposeful failure in the event the process.versions.node value is not available
12+
expect(getNodeMajorVersion()).not.toBe(0);
13+
});
14+
15+
it.each([
16+
{
17+
description: 'number',
18+
value: 1_000_000
19+
},
20+
{
21+
description: 'string',
22+
value: 'lorem ipsum'
23+
},
24+
{
25+
description: 'null',
26+
value: null
27+
}
28+
])('should handle basic failure, $description', ({ value }) => {
29+
expect(getNodeMajorVersion(value as any)).toBe(0);
630
});
731
});

src/options.defaults.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import { basename, join } from 'node:path';
1+
import { basename, join, resolve } from 'node:path';
2+
import { pathToFileURL } from 'node:url';
23
import packageJson from '../package.json';
34

45
/**
5-
* Application defaults, not user-configurable
6+
* Application defaults, not all fields are user-configurable
67
*
78
* @interface DefaultOptions
89
*
910
* @template TLogOptions The logging options type, defaulting to LoggingOptions.
1011
* @property contextPath - Current working directory.
12+
* @property contextUrl - Current working directory URL.
1113
* @property docsHost - Flag indicating whether to use the docs-host.
1214
* @property docsPath - Path to the documentation directory.
1315
* @property isHttp - Flag indicating whether the server is running in HTTP mode.
1416
* @property {HttpOptions} http - HTTP server options.
1517
* @property llmsFilesPath - Path to the LLMs files directory.
1618
* @property {LoggingOptions} logging - Logging options.
1719
* @property name - Name of the package.
20+
* @property nodeVersion - Node.js major version.
1821
* @property repoName - Name of the repository.
1922
* @property pfExternal - PatternFly external docs URL.
2023
* @property pfExternalDesignComponents - PatternFly design guidelines' components' URL.
2124
* @property pfExternalExamplesComponents - PatternFly examples' core components' URL.
2225
* @property pfExternalExamplesLayouts - PatternFly examples' core layouts' URL.
23-
* @property pfExternalExamplesCharts - PatternFly examples' charts' components' URL.'
26+
* @property pfExternalExamplesCharts - PatternFly examples' charts' components' URL.
2427
* @property pfExternalExamplesTable - PatternFly examples' table components' URL.
2528
* @property pfExternalChartsDesign - PatternFly charts' design guidelines URL.
2629
* @property pfExternalDesignLayouts - PatternFly design guidelines' layouts' URL.
@@ -33,13 +36,15 @@ import packageJson from '../package.json';
3336
*/
3437
interface DefaultOptions<TLogOptions = LoggingOptions> {
3538
contextPath: string;
39+
contextUrl: string;
3640
docsHost: boolean;
3741
docsPath: string;
3842
http: HttpOptions;
3943
isHttp: boolean;
4044
llmsFilesPath: string;
4145
logging: TLogOptions;
4246
name: string;
47+
nodeVersion: number;
4348
pfExternal: string;
4449
pfExternalDesignComponents: string;
4550
pfExternalExamplesComponents: string;
@@ -253,20 +258,39 @@ const PF_EXTERNAL_ACCESSIBILITY = `${PF_EXTERNAL}/accessibility`;
253258
*/
254259
const PF_EXTERNAL_CHARTS_DESIGN = `${PF_EXTERNAL}/design-guidelines/charts`;
255260

261+
/**
262+
* Get the current Node.js major version.
263+
*
264+
* @param nodeVersion
265+
* @returns Node.js major version.
266+
*/
267+
const getNodeMajorVersion = (nodeVersion = process.versions.node) => {
268+
const updatedNodeVersion = nodeVersion || '0.0.0';
269+
const major = Number.parseInt(updatedNodeVersion?.split?.('.')?.[0] || '0', 10);
270+
271+
if (Number.isFinite(major)) {
272+
return major;
273+
}
274+
275+
return 0;
276+
};
277+
256278
/**
257279
* Global default options. Base defaults before CLI/programmatic overrides.
258280
*
259281
* @type {DefaultOptions} Default options object.
260282
*/
261283
const DEFAULT_OPTIONS: DefaultOptions = {
262284
docsHost: false,
263-
contextPath: (process.env.NODE_ENV === 'local' && '/') || process.cwd(),
264-
docsPath: (process.env.NODE_ENV === 'local' && '/documentation') || join(process.cwd(), 'documentation'),
285+
contextPath: (process.env.NODE_ENV === 'local' && '/') || resolve(process.cwd()),
286+
contextUrl: pathToFileURL((process.env.NODE_ENV === 'local' && '/') || resolve(process.cwd())).href,
287+
docsPath: (process.env.NODE_ENV === 'local' && '/documentation') || join(resolve(process.cwd()), 'documentation'),
265288
isHttp: false,
266289
http: HTTP_OPTIONS,
267-
llmsFilesPath: (process.env.NODE_ENV === 'local' && '/llms-files') || join(process.cwd(), 'llms-files'),
290+
llmsFilesPath: (process.env.NODE_ENV === 'local' && '/llms-files') || join(resolve(process.cwd()), 'llms-files'),
268291
logging: LOGGING_OPTIONS,
269292
name: packageJson.name,
293+
nodeVersion: (process.env.NODE_ENV === 'local' && 22) || getNodeMajorVersion(),
270294
pfExternal: PF_EXTERNAL,
271295
pfExternalDesignComponents: PF_EXTERNAL_DESIGN_COMPONENTS,
272296
pfExternalExamplesComponents: PF_EXTERNAL_EXAMPLES_REACT_CORE,
@@ -299,6 +323,7 @@ export {
299323
PF_EXTERNAL_ACCESSIBILITY,
300324
LOG_BASENAME,
301325
DEFAULT_OPTIONS,
326+
getNodeMajorVersion,
302327
type DefaultOptions,
303328
type DefaultOptionsOverrides,
304329
type HttpOptions,

0 commit comments

Comments
 (0)