Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/legacy-kitten-package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@doc-kittens/legacy': major
'@node-core/doc-kit': minor
---

The legacy-format generators (`legacy-html`, `legacy-html-all`,
`legacy-json`, and `legacy-json-all`) now live in the new
`@doc-kittens/legacy` package and are loaded via import specifiers such as
`@doc-kittens/legacy/legacy-html`. The CLI shorthand names are unchanged.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default defineConfig([
},
{
files: [
'packages/core/src/generators/legacy-html/assets/*.js',
'packages/legacy/src/legacy-html/assets/*.js',
'packages/react/src/html/ui/**/*',
],
languageOptions: {
Expand Down
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
"./ast": "./src/generators/ast/index.mjs",
"./ast-js": "./src/generators/ast-js/index.mjs",
"./json-simple": "./src/generators/json-simple/index.mjs",
"./legacy-html": "./src/generators/legacy-html/index.mjs",
"./legacy-html-all": "./src/generators/legacy-html-all/index.mjs",
"./legacy-json": "./src/generators/legacy-json/index.mjs",
"./legacy-json-all": "./src/generators/legacy-json-all/index.mjs",
"./man-page": "./src/generators/man-page/index.mjs",
"./metadata": "./src/generators/metadata/index.mjs",
"./package.json": "./package.json",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/generators/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/
export const publicGenerators = {
'json-simple': '@node-core/doc-kit/json-simple',
'legacy-html': '@node-core/doc-kit/legacy-html',
'legacy-html-all': '@node-core/doc-kit/legacy-html-all',
'legacy-html': '@doc-kittens/legacy/legacy-html',
'legacy-html-all': '@doc-kittens/legacy/legacy-html-all',
'man-page': '@node-core/doc-kit/man-page',
'legacy-json': '@node-core/doc-kit/legacy-json',
'legacy-json-all': '@node-core/doc-kit/legacy-json-all',
'legacy-json': '@doc-kittens/legacy/legacy-json',
'legacy-json-all': '@doc-kittens/legacy/legacy-json-all',
'addon-verify': '@node-core/doc-kit/addon-verify',
'api-links': '@node-core/doc-kit/api-links',
'orama-db': '@doc-kittens/react/orama-db',
Expand Down
44 changes: 0 additions & 44 deletions packages/core/src/utils/__tests__/generators.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
getVersionFromSemVer,
coerceSemVer,
getCompatibleVersions,
legacyToJSON,
} from '../generators.mjs';

describe('groupNodesByModule', () => {
Expand Down Expand Up @@ -80,46 +79,3 @@ describe('getCompatibleVersions', () => {
assert.equal(result.length, 2);
});
});

describe('legacyToJSON', () => {
const base = {
type: 'module',
source: 'lib/fs.js',
introduced_in: 'v0.10.0',
meta: {},
stability: 2,
stabilityText: 'Stable',
classes: [],
methods: ['readFile'],
properties: [],
miscs: [],
modules: ['fs'],
globals: [],
};

it('serialises a normal section with all keys', () => {
const result = JSON.parse(legacyToJSON({ ...base, api: 'fs' }));
assert.ok('type' in result);
assert.ok('methods' in result);
assert.ok('modules' in result);
});

it('omits modules key for index sections', () => {
const result = JSON.parse(legacyToJSON({ ...base, api: 'index' }));
assert.ok(!('modules' in result));
});

it('uses all.json key order when api is null', () => {
const result = JSON.parse(legacyToJSON({ ...base, api: null }));
// all.json only includes miscs, modules, classes, globals, methods
assert.ok('miscs' in result);
assert.ok('modules' in result);
assert.ok(!('type' in result));
assert.ok(!('source' in result));
});

it('passes extra args to JSON.stringify (e.g. indentation)', () => {
const result = legacyToJSON({ ...base, api: 'fs' }, null, 2);
assert.ok(result.includes('\n'));
});
});
52 changes: 0 additions & 52 deletions packages/core/src/utils/generators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,3 @@ export const getCompatibleVersions = (introduced, releases) => {
*/
export const leftHandAssign = (target, source) =>
Object.keys(source).forEach(k => k in target || (target[k] = source[k]));

/**
* Transforms an object to JSON output consistent with the JSON version.
* @param {import('../generators/legacy-json/types').Section} section - The source object
* @param {any[]} args
* @returns {string} - The JSON output
*/
export const legacyToJSON = (
{
api,
type,
source,
introduced_in,
meta,
stability,
stabilityText,
classes,
methods,
properties,
miscs,
modules,
globals,
},
...args
) =>
JSON.stringify(
api == null
? {
// all.json special order
miscs,
modules,
classes,
globals,
methods,
}
: {
type,
source,
introduced_in,
meta,
stability,
stabilityText,
classes,
methods,
properties,
miscs,
// index.json shouldn't have a `modules` key:
...(api === 'index' ? undefined : { modules }),
globals,
},
...args
);
2 changes: 1 addition & 1 deletion packages/core/src/utils/signature/parseList.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function parseListItem(child) {
/**
* Parses a list of nodes and updates the corresponding section object with the extracted information.
* Handles different section types such as methods, properties, and events differently.
* @param {import('../../generators/legacy-json/types').Section} section
* @param {{ [key: string]: unknown }} section - The section object to populate with the parsed values
* @param {import('@types/mdast').RootContent[]} nodes
*/
export function parseList(section, nodes) {
Expand Down
32 changes: 32 additions & 0 deletions packages/legacy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@doc-kittens/legacy",
"type": "module",
"version": "0.0.0",
"description": "Legacy-format generators for @node-core/doc-kit: legacy-html, legacy-html-all, legacy-json, and legacy-json-all",
"repository": {
"type": "git",
"url": "git+https://github.com/nodejs/doc-kit.git",
"directory": "packages/legacy"
},
"exports": {
"./legacy-html": "./src/legacy-html/index.mjs",
"./legacy-html-all": "./src/legacy-html-all/index.mjs",
"./legacy-json": "./src/legacy-json/index.mjs",
"./legacy-json-all": "./src/legacy-json-all/index.mjs",
"./package.json": "./package.json"
},
"files": [
"src",
"!src/**/*.test.mjs",
"!src/**/__tests__",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"dependencies": {
"@node-core/doc-kit": "^1.4.3",
"hastscript": "^9.0.1",
"unist-builder": "^4.0.0",
"unist-util-visit": "^5.1.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import { readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

import getConfig from '../../utils/configuration/index.mjs';
import { minifyHTML } from '../../utils/html-minifier.mjs';
import { getRemarkRehype as remark } from '../../utils/remark.mjs';
import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs';
import { minifyHTML } from '@node-core/doc-kit/utils/html-minifier.mjs';
import { getRemarkRehype as remark } from '@node-core/doc-kit/utils/remark.mjs';

import { replaceTemplateValues } from '../legacy-html/utils/replaceTemplateValues.mjs';
import tableOfContents from '../legacy-html/utils/tableOfContents.mjs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
description:
'Generates the `all.html` file from the `legacy-html` generator, which includes all the modules in one single file',

dependsOn: '@node-core/doc-kit/legacy-html',
dependsOn: '@doc-kittens/legacy/legacy-html',

defaultConfiguration: {
templatePath: legacyHtml.defaultConfiguration.templatePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import { readFile, cp } from 'node:fs/promises';
import { basename, join } from 'node:path';

import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs';
import { writeFile } from '@node-core/doc-kit/utils/file.mjs';
import { groupNodesByModule } from '@node-core/doc-kit/utils/generators.mjs';
import { minifyHTML } from '@node-core/doc-kit/utils/html-minifier.mjs';
import { getRemarkRehypeWithShiki as remark } from '@node-core/doc-kit/utils/remark.mjs';

import buildContent from './utils/buildContent.mjs';
import { replaceTemplateValues } from './utils/replaceTemplateValues.mjs';
import tableOfContents from './utils/tableOfContents.mjs';
import getConfig from '../../utils/configuration/index.mjs';
import { writeFile } from '../../utils/file.mjs';
import { groupNodesByModule } from '../../utils/generators.mjs';
import { minifyHTML } from '../../utils/html-minifier.mjs';
import { getRemarkRehypeWithShiki as remark } from '../../utils/remark.mjs';

/**
* Creates a heading object with the given name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import { join } from 'node:path';

import { GITHUB_EDIT_URL } from '@node-core/doc-kit/utils/configuration/templates.mjs';

import { generate, processChunk } from './generate.mjs';
import { GITHUB_EDIT_URL } from '../../utils/configuration/templates.mjs';

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MetadataEntry } from '../metadata/types';
import type { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types';

export interface TemplateValues {
api: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';

import { setConfig } from '../../../../utils/configuration/index.mjs';
import { setConfig } from '@node-core/doc-kit/utils/configuration/index.mjs';

import buildContent from '../buildContent.mjs';

const createEntry = slug => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';

import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs';
import {
GITHUB_BLOB_URL,
populate,
} from '@node-core/doc-kit/utils/configuration/templates.mjs';
import { UNIST } from '@node-core/doc-kit/utils/queries/index.mjs';
import { getRemarkRehypeWithShiki as remark } from '@node-core/doc-kit/utils/remark.mjs';
import { h as createElement } from 'hastscript';
import { u as createTree } from 'unist-builder';
import { SKIP, visit } from 'unist-util-visit';

import buildExtraContent from './buildExtraContent.mjs';
import { createLegacySlugger } from './slugger.mjs';
import getConfig from '../../../utils/configuration/index.mjs';
import {
GITHUB_BLOB_URL,
populate,
} from '../../../utils/configuration/templates.mjs';
import { UNIST } from '../../../utils/queries/index.mjs';
import { getRemarkRehypeWithShiki as remark } from '../../../utils/remark.mjs';

/**
* Builds a Markdown heading for a given node
*
* @param {import('../../metadata/types').HeadingNode} node The node to build the Markdown heading for
* @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} node The node to build the Markdown heading for
* @param {number} index The index of the current node
* @param {import('unist').Parent} parent The parent node of the current node
* @returns {import('hast').Element} The HTML AST tree of the heading content
Expand Down Expand Up @@ -54,7 +54,7 @@ const buildHeading = ({ data, children, depth }, index, parent, legacySlug) => {
/**
* Builds an HTML Stability element
*
* @param {import('../../metadata/types').StabilityNode} node The HTML AST tree of the Stability Index content
* @param {import('@node-core/doc-kit/generators/metadata/types').StabilityNode} node The HTML AST tree of the Stability Index content
* @param {number} index The index of the current node
* @param {import('unist').Parent} parent The parent node of the current node
*/
Expand All @@ -77,7 +77,7 @@ const buildStability = ({ children, data }, index, parent) => {
/**
* Creates a history table row.
*
* @param {import('../../metadata/types').ChangeEntry} change
* @param {import('@node-core/doc-kit/generators/metadata/types').ChangeEntry} change
*/
const createHistoryTableRow = ({ version: changeVersions, description }) => {
const descriptionNode = remark().parse(description);
Expand All @@ -94,7 +94,7 @@ const createHistoryTableRow = ({ version: changeVersions, description }) => {
/**
* Builds the Metadata Properties into content
*
* @param {import('../../metadata/types').MetadataEntry} node The node to build the properties from
* @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} node The node to build the properties from
* @returns {import('unist').Parent} The HTML AST tree of the properties content
*/
const buildMetadataElement = node => {
Expand Down Expand Up @@ -202,8 +202,8 @@ const buildMetadataElement = node => {
/**
* Builds the whole content of a given node (API module)
*
* @param {Array<import('../../metadata/types').MetadataEntry>} headNodes The API metadata Nodes that are considered the "head" of each module
* @param {Array<import('../../metadata/types').MetadataEntry>} metadataEntries The API metadata Nodes to be transformed into HTML content
* @param {Array<import('@node-core/doc-kit/generators/metadata/types').MetadataEntry>} headNodes The API metadata Nodes that are considered the "head" of each module
* @param {Array<import('@node-core/doc-kit/generators/metadata/types').MetadataEntry>} metadataEntries The API metadata Nodes to be transformed into HTML content
*/
export default (headNodes, metadataEntries) => {
const getLegacySlug = createLegacySlugger();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

import getConfig from '../../../utils/configuration/index.mjs';
import { populate } from '../../../utils/configuration/templates.mjs';
import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs';
import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs';
import {
getCompatibleVersions,
getVersionFromSemVer,
} from '../../../utils/generators.mjs';
} from '@node-core/doc-kit/utils/generators.mjs';

/**
* Builds the Dropdown for the current Table of Contents
Expand Down Expand Up @@ -50,7 +50,7 @@ export const buildNavigation = navigationContents =>
*
* @param {string} path The current API node name
* @param {string} added The version the API was added
* @param {Array<import('../../../parsers/types').ReleaseEntry>} versions All available Node.js releases
* @param {Array<import('@node-core/doc-kit/parsers/types').ReleaseEntry>} versions All available Node.js releases
*/
export const buildVersions = (path, added, versions) => {
const config = getConfig('legacy-html');
Expand Down
Loading