Skip to content

Commit 9d9d060

Browse files
committed
refactor(legacy): extract @doc-kittens/legacy package
1 parent 316965a commit 9d9d060

45 files changed

Lines changed: 231 additions & 167 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@doc-kittens/legacy': major
3+
'@node-core/doc-kit': minor
4+
---
5+
6+
The legacy-format generators (`legacy-html`, `legacy-html-all`,
7+
`legacy-json`, and `legacy-json-all`) now live in the new
8+
`@doc-kittens/legacy` package and are loaded via import specifiers such as
9+
`@doc-kittens/legacy/legacy-html`. The CLI shorthand names are unchanged.

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default defineConfig([
9595
},
9696
{
9797
files: [
98-
'packages/core/src/generators/legacy-html/assets/*.js',
98+
'packages/legacy/src/legacy-html/assets/*.js',
9999
'packages/react/src/html/ui/**/*',
100100
],
101101
languageOptions: {

package-lock.json

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
"./ast": "./src/generators/ast/index.mjs",
2424
"./ast-js": "./src/generators/ast-js/index.mjs",
2525
"./json-simple": "./src/generators/json-simple/index.mjs",
26-
"./legacy-html": "./src/generators/legacy-html/index.mjs",
27-
"./legacy-html-all": "./src/generators/legacy-html-all/index.mjs",
28-
"./legacy-json": "./src/generators/legacy-json/index.mjs",
29-
"./legacy-json-all": "./src/generators/legacy-json-all/index.mjs",
3026
"./man-page": "./src/generators/man-page/index.mjs",
3127
"./metadata": "./src/generators/metadata/index.mjs",
3228
"./package.json": "./package.json",

packages/core/src/generators/index.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
*/
1212
export const publicGenerators = {
1313
'json-simple': '@node-core/doc-kit/json-simple',
14-
'legacy-html': '@node-core/doc-kit/legacy-html',
15-
'legacy-html-all': '@node-core/doc-kit/legacy-html-all',
14+
'legacy-html': '@doc-kittens/legacy/legacy-html',
15+
'legacy-html-all': '@doc-kittens/legacy/legacy-html-all',
1616
'man-page': '@node-core/doc-kit/man-page',
17-
'legacy-json': '@node-core/doc-kit/legacy-json',
18-
'legacy-json-all': '@node-core/doc-kit/legacy-json-all',
17+
'legacy-json': '@doc-kittens/legacy/legacy-json',
18+
'legacy-json-all': '@doc-kittens/legacy/legacy-json-all',
1919
'addon-verify': '@node-core/doc-kit/addon-verify',
2020
'api-links': '@node-core/doc-kit/api-links',
2121
'orama-db': '@doc-kittens/react/orama-db',

packages/core/src/utils/__tests__/generators.test.mjs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
getVersionFromSemVer,
77
coerceSemVer,
88
getCompatibleVersions,
9-
legacyToJSON,
109
} from '../generators.mjs';
1110

1211
describe('groupNodesByModule', () => {
@@ -80,46 +79,3 @@ describe('getCompatibleVersions', () => {
8079
assert.equal(result.length, 2);
8180
});
8281
});
83-
84-
describe('legacyToJSON', () => {
85-
const base = {
86-
type: 'module',
87-
source: 'lib/fs.js',
88-
introduced_in: 'v0.10.0',
89-
meta: {},
90-
stability: 2,
91-
stabilityText: 'Stable',
92-
classes: [],
93-
methods: ['readFile'],
94-
properties: [],
95-
miscs: [],
96-
modules: ['fs'],
97-
globals: [],
98-
};
99-
100-
it('serialises a normal section with all keys', () => {
101-
const result = JSON.parse(legacyToJSON({ ...base, api: 'fs' }));
102-
assert.ok('type' in result);
103-
assert.ok('methods' in result);
104-
assert.ok('modules' in result);
105-
});
106-
107-
it('omits modules key for index sections', () => {
108-
const result = JSON.parse(legacyToJSON({ ...base, api: 'index' }));
109-
assert.ok(!('modules' in result));
110-
});
111-
112-
it('uses all.json key order when api is null', () => {
113-
const result = JSON.parse(legacyToJSON({ ...base, api: null }));
114-
// all.json only includes miscs, modules, classes, globals, methods
115-
assert.ok('miscs' in result);
116-
assert.ok('modules' in result);
117-
assert.ok(!('type' in result));
118-
assert.ok(!('source' in result));
119-
});
120-
121-
it('passes extra args to JSON.stringify (e.g. indentation)', () => {
122-
const result = legacyToJSON({ ...base, api: 'fs' }, null, 2);
123-
assert.ok(result.includes('\n'));
124-
});
125-
});

packages/core/src/utils/generators.mjs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -69,55 +69,3 @@ export const getCompatibleVersions = (introduced, releases) => {
6969
*/
7070
export const leftHandAssign = (target, source) =>
7171
Object.keys(source).forEach(k => k in target || (target[k] = source[k]));
72-
73-
/**
74-
* Transforms an object to JSON output consistent with the JSON version.
75-
* @param {import('../generators/legacy-json/types').Section} section - The source object
76-
* @param {any[]} args
77-
* @returns {string} - The JSON output
78-
*/
79-
export const legacyToJSON = (
80-
{
81-
api,
82-
type,
83-
source,
84-
introduced_in,
85-
meta,
86-
stability,
87-
stabilityText,
88-
classes,
89-
methods,
90-
properties,
91-
miscs,
92-
modules,
93-
globals,
94-
},
95-
...args
96-
) =>
97-
JSON.stringify(
98-
api == null
99-
? {
100-
// all.json special order
101-
miscs,
102-
modules,
103-
classes,
104-
globals,
105-
methods,
106-
}
107-
: {
108-
type,
109-
source,
110-
introduced_in,
111-
meta,
112-
stability,
113-
stabilityText,
114-
classes,
115-
methods,
116-
properties,
117-
miscs,
118-
// index.json shouldn't have a `modules` key:
119-
...(api === 'index' ? undefined : { modules }),
120-
globals,
121-
},
122-
...args
123-
);

packages/core/src/utils/signature/parseList.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function parseListItem(child) {
8585
/**
8686
* Parses a list of nodes and updates the corresponding section object with the extracted information.
8787
* Handles different section types such as methods, properties, and events differently.
88-
* @param {import('../../generators/legacy-json/types').Section} section
88+
* @param {{ [key: string]: unknown }} section - The section object to populate with the parsed values
8989
* @param {import('@types/mdast').RootContent[]} nodes
9090
*/
9191
export function parseList(section, nodes) {

packages/legacy/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@doc-kittens/legacy",
3+
"type": "module",
4+
"version": "0.0.0",
5+
"description": "Legacy-format generators for @node-core/doc-kit: legacy-html, legacy-html-all, legacy-json, and legacy-json-all",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/nodejs/doc-kit.git",
9+
"directory": "packages/legacy"
10+
},
11+
"exports": {
12+
"./legacy-html": "./src/legacy-html/index.mjs",
13+
"./legacy-html-all": "./src/legacy-html-all/index.mjs",
14+
"./legacy-json": "./src/legacy-json/index.mjs",
15+
"./legacy-json-all": "./src/legacy-json-all/index.mjs",
16+
"./package.json": "./package.json"
17+
},
18+
"files": [
19+
"src",
20+
"!src/**/*.test.mjs",
21+
"!src/**/__tests__",
22+
"CHANGELOG.md",
23+
"LICENSE",
24+
"README.md"
25+
],
26+
"dependencies": {
27+
"@node-core/doc-kit": "^1.4.3",
28+
"hastscript": "^9.0.1",
29+
"unist-builder": "^4.0.0",
30+
"unist-util-visit": "^5.1.0"
31+
}
32+
}
File renamed without changes.

0 commit comments

Comments
 (0)