Skip to content

Commit

Permalink
Split utils into node utils and common utils
Browse files Browse the repository at this point in the history
Step 1 of N in making a browser friendly typedoc/models entry point for
people who want to import TypeDoc's JSON output and do something with
it.
  • Loading branch information
Gerrit0 committed Dec 16, 2024
1 parent fcd750d commit db2dfca
Show file tree
Hide file tree
Showing 108 changed files with 383 additions and 322 deletions.
80 changes: 80 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,87 @@ const config = {
},
};

const nodeModules = [
"assert",
"assert/strict",
"async_hooks",
"buffer",
"child_process",
"cluster",
"console",
"constants",
"crypto",
"dgram",
"diagnostics_channel",
"dns",
"dns/promises",
"domain",
"events",
"fs",
"fs/promises",
"http",
"http2",
"https",
"inspector",
"inspector/promises",
"module",
"net",
"os",
"path",
"path/posix",
"path/win32",
"perf_hooks",
"process",
"punycode",
"querystring",
"readline",
"readline/promises",
"repl",
"stream",
"stream/consumers",
"stream/promises",
"stream/web",
"string_decoder",
"sys",
"timers",
"timers/promises",
"tls",
"trace_events",
"tty",
"url",
"util",
"util/types",
"v8",
"vm",
"wasi",
"worker_threads",
"zlib",
];

export default tslint.config(
{
files: ["src/**/*.ts"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: ["*/utils-common/*"],
},
],
},
},
{
files: ["src/lib/utils-common/**/*.ts"],
rules: {
"no-restricted-imports": [
"error",
{
paths: nodeModules,
patterns: ["../*"],
},
],
},
},
eslint.configs.recommended,
...tslint.configs.strictTypeChecked,
config,
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
".": "./dist/index.js",
"./tsdoc.json": "./tsdoc.json",
"./package.json": "./package.json",
"./models": "./dist/lib/models/index.js",
"./debug": "./dist/lib/debug/index.js"
},
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -103,5 +104,8 @@
"src/test",
"tmp"
]
},
"imports": {
"#utils": "./dist/lib/utils-common/index.js"
}
}
4 changes: 2 additions & 2 deletions scripts/set_strict.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @ts-check
// Sets the Strict type that TypeDoc uses to enable overloads for consumers only.
// See the rationale in src/lib/utils/general.ts
// See the rationale in src/lib/utils-common/general.ts

import fs from "fs/promises";
import { join } from "path";
import { fileURLToPath } from "url";

const file = join(
fileURLToPath(import.meta.url),
"../../src/lib/utils/general.ts",
"../../src/lib/utils-common/general.ts",
);

const isStrict = process.argv[2] === "true";
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
export { Application, type ApplicationEvents } from "./lib/application.js";

export { EventDispatcher } from "./lib/utils/events.js";
export { resetReflectionID } from "./lib/models/reflections/abstract.js";
/**
* All symbols documented under the Models namespace are also available in the root import.
Expand Down Expand Up @@ -81,7 +80,6 @@ export {
ArgumentsReader,
Option,
CommentStyle,
JSX,
LogLevel,
Logger,
Options,
Expand All @@ -92,7 +90,6 @@ export {
TSConfigReader,
TypeDocReader,
EntryPointStrategy,
EventHooks,
MinimalSourceFile,
normalizePath,
} from "./lib/utils/index.js";
Expand All @@ -119,11 +116,12 @@ export type {
ParameterTypeToOptionTypeMap,
DocumentationEntryPoint,
ManuallyValidatedOption,
EnumKeys,
JsDocCompatibility,
OutputSpecification,
} from "./lib/utils/index.js";

export { JSX, EventDispatcher, EventHooks, type EnumKeys } from "#utils";

export {
JSONOutput,
Serializer,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

import { Options, Option } from "./utils/index.js";
import type { TypeDocOptions } from "./utils/options/declaration.js";
import { unique } from "./utils/array.js";
import { unique } from "#utils";
import { ok } from "assert";
import {
type DocumentationEntryPoint,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/declarationReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @module
*/

import type { Chars } from "../../utils/index.js";
import type { Chars } from "#utils";

export const MeaningKeywords = [
"class", // SymbolFlags.Class
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/declarationReferenceResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type Reflection,
ReflectionKind,
} from "../../models/index.js";
import { assertNever, filterMap } from "../../utils/index.js";
import { assertNever, filterMap } from "#utils";
import type {
ComponentPath,
DeclarationReference,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/converter/comments/discovery.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ts from "typescript";
import { ReflectionKind } from "../../models/index.js";
import { assertNever, type Logger } from "../../utils/index.js";
import { type Logger } from "../../utils/index.js";
import { CommentStyle } from "../../utils/options/declaration.js";
import { nicePath } from "../../utils/paths.js";
import { ok } from "assert";
import { filter, firstDefined } from "../../utils/array.js";
import { filter, firstDefined, assertNever } from "#utils";

const variablePropertyKinds = [
ts.SyntaxKind.PropertyDeclaration,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/converter/comments/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ts from "typescript";
import { Comment, ReflectionKind } from "../../models/index.js";
import { assertNever, type Logger } from "../../utils/index.js";
import { type Logger } from "../../utils/index.js";
import type {
CommentStyle,
JsDocCompatibility,
Expand All @@ -16,6 +16,7 @@ import {
import { lexLineComments } from "./lineLexer.js";
import { parseComment } from "./parser.js";
import type { FileRegistry } from "../../models/FileRegistry.js";
import { assertNever } from "#utils";

export interface CommentParserConfig {
blockTags: Set<string>;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/converter/comments/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CommentTag,
type InlineTagDisplayPart,
} from "../../models/index.js";
import { assertNever, type Logger, removeIf } from "../../utils/index.js";
import { type Logger } from "../../utils/index.js";
import type { MinimalSourceFile } from "../../utils/minimalSourceFile.js";
import { nicePath } from "../../utils/paths.js";
import { type Token, TokenSyntaxKind } from "./lexer.js";
Expand All @@ -19,6 +19,7 @@ import type {
import { FileRegistry } from "../../models/FileRegistry.js";
import { textContent, TextParserReentryState } from "./textParser.js";
import { hasDeclarationFileExtension } from "../../utils/fs.js";
import { assertNever, removeIf } from "#utils";

interface LookaheadGenerator<T> {
done(): boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/textParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
RelativeLinkDisplayPart,
} from "../../models/index.js";
import type { FileRegistry } from "../../models/FileRegistry.js";
import { HtmlAttributeParser, ParserState } from "../../utils/html.js";
import { HtmlAttributeParser, ParserState } from "#utils";
import { type Token, TokenSyntaxKind } from "./lexer.js";

import MarkdownIt from "markdown-it";
Expand Down
3 changes: 1 addition & 2 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ import {
Option,
MinimalSourceFile,
readFile,
unique,
getDocumentEntryPoints,
} from "../utils/index.js";
import { convertType } from "./types.js";
import { ConverterEvents } from "./converter-events.js";
import { convertSymbol } from "./symbols.js";
import { createMinimatch, matchesAny, nicePath } from "../utils/paths.js";
import type { Minimatch } from "minimatch";
import { hasAllFlags, hasAnyFlag } from "../utils/enum.js";
import { hasAllFlags, hasAnyFlag, unique } from "#utils";
import type { DocumentationEntryPoint } from "../utils/entry-point.js";
import type { CommentParserConfig } from "./comments/index.js";
import type {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/converter/plugins/CommentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
type TypeParameterReflection,
type TypeVisitor,
} from "../../models/index.js";
import { Option } from "../../utils/index.js";
import {
Option,
setIntersection,
filterMap,
partition,
removeIf,
removeIfPresent,
unique,
} from "../../utils/index.js";
import { setIntersection } from "../../utils/set.js";
} from "#utils";
import { ConverterComponent } from "../components.js";
import type { Context } from "../context.js";
import { ConverterEvents } from "../converter-events.js";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/plugins/ImplementsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ReflectionType,
type Type,
} from "../../models/types.js";
import { filterMap, zip } from "../../utils/array.js";
import { filterMap, zip } from "#utils";
import { ConverterComponent } from "../components.js";
import type { Context } from "../context.js";
import { getHumanName } from "../../utils/index.js";
Expand Down
8 changes: 2 additions & 6 deletions src/lib/converter/plugins/InheritDocPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import {
import { ConverterComponent } from "../components.js";
import type { Context } from "../context.js";
import type { Reflection } from "../../models/reflections/abstract.js";
import {
Option,
DefaultMap,
type ValidationOptions,
} from "../../utils/index.js";
import { zip } from "../../utils/array.js";
import { Option, type ValidationOptions } from "../../utils/index.js";
import { zip, DefaultMap } from "#utils";
import { parseDeclarationReference } from "../comments/declarationReference.js";
import { resolveDeclarationReference } from "../comments/declarationReferenceResolver.js";
import { ApplicationEvents } from "../../application-events.js";
Expand Down
7 changes: 1 addition & 6 deletions src/lib/converter/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import {
ReflectionKind,
type UnionType,
} from "../models/index.js";
import {
getEnumFlags,
hasAllFlags,
hasAnyFlag,
removeFlag,
} from "../utils/enum.js";
import { getEnumFlags, hasAllFlags, hasAnyFlag, removeFlag } from "#utils";
import type { Context } from "./context.js";
import { convertDefaultValue } from "./convert-expression.js";
import { convertIndexSignatures } from "./factories/index-signature.js";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
type SomeType,
} from "../models/index.js";
import { ReflectionSymbolId } from "../models/reflections/ReflectionSymbolId.js";
import { zip } from "../utils/array.js";
import { zip } from "#utils";
import type { Context } from "./context.js";
import { ConverterEvents } from "./converter-events.js";
import { convertIndexSignatures } from "./factories/index-signature.js";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/utils/repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawnSync } from "child_process";
import { normalizePath, type Logger } from "../../utils/index.js";
import { NonEnumerable } from "../../utils/general.js";
import { NonEnumerable } from "#utils";
import { dirname, join } from "path";
import { existsSync } from "fs";

Expand Down
2 changes: 1 addition & 1 deletion src/lib/internationalization/internationalization.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ok } from "assert";
import type { Application } from "../application.js";
import { DefaultMap, unique } from "../utils/index.js";
import { DefaultMap, unique } from "#utils";
import { readdirSync } from "fs";
import { join } from "path";
import { ReflectionKind } from "../models/reflections/kind.js";
Expand Down
3 changes: 1 addition & 2 deletions src/lib/models/comments/comment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertNever, removeIf } from "../../utils/index.js";
import { assertNever, removeIf, NonEnumerable } from "#utils";
import type { Reflection } from "../reflections/index.js";
import { ReflectionSymbolId } from "../reflections/ReflectionSymbolId.js";

Expand All @@ -7,7 +7,6 @@ import type {
Deserializer,
JSONOutput,
} from "../../serialization/index.js";
import { NonEnumerable } from "../../utils/general.js";

/**
* Represents a parsed piece of a comment.
Expand Down
6 changes: 3 additions & 3 deletions src/lib/models/reflections/ReflectionSymbolId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "../../utils/fs.js";
import { normalizePath } from "../../utils/paths.js";
import { getQualifiedName } from "../../utils/tsutils.js";
import { optional, validate } from "../../utils/validation.js";
import { Validation } from "#utils";
import type { DeclarationReference } from "../../converter/index.js";
import { splitUnquotedString } from "./utils.js";

Expand Down Expand Up @@ -133,10 +133,10 @@ function resolveDeclarationMaps(file: string): string {
}

if (
validate(
Validation.validate(
{
file: String,
sourceRoot: optional(String),
sourceRoot: Validation.optional(String),
sources: [Array, String],
},
sourceMap,
Expand Down
3 changes: 1 addition & 2 deletions src/lib/models/reflections/abstract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Comment } from "../comments/comment.js";
import { splitUnquotedString } from "./utils.js";
import type { ProjectReflection } from "./project.js";
import type { NeverIfInternal } from "../../utils/index.js";
import { type NeverIfInternal, NonEnumerable } from "#utils";
import { ReflectionKind } from "./kind.js";
import type {
Serializer,
Expand All @@ -11,7 +11,6 @@ import type {
import type { ReflectionVariant } from "./variant.js";
import type { DeclarationReflection } from "./declaration.js";
import type { DocumentReflection } from "./document.js";
import { NonEnumerable } from "../../utils/general.js";
import type {
Internationalization,
TranslatedString,
Expand Down
Loading

0 comments on commit db2dfca

Please sign in to comment.