Skip to content

Commit

Permalink
Switch from CommonJS to ESM, required for support for TypeDoc 0.27.x
Browse files Browse the repository at this point in the history
  • Loading branch information
awa-xima committed Nov 27, 2024
1 parent 120293a commit 30813c2
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 830 deletions.
852 changes: 77 additions & 775 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "typedoc-plugin-merge-modules",
"version": "6.0.3",
"type": "module",
"description": "Plugin for TypeDoc that merges the content of modules.",
"author": {
"name": "Krisztián Balla",
Expand All @@ -22,11 +23,11 @@
"eslint-plugin-unicorn": "54.0.0",
"prettier": "3.3.3",
"rimraf": "6.0.1",
"typedoc": "0.26.7",
"typedoc": "0.27.0",
"typescript": "5.5.4"
},
"peerDependencies": {
"typedoc": "0.26.x"
"typedoc": "0.27.x"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Application } from "typedoc";
import { Plugin } from "./plugin";
import { PluginConfig } from "./plugin_options";
import type { Application } from "typedoc";
import { Plugin } from "./plugin.js";
import type { PluginConfig } from "./plugin_options.js";

/**
* Type that can be intersected with TypeDoc's config type to have static type checking for the plugin's configuration.
Expand Down
4 changes: 2 additions & 2 deletions src/merger/module_bundle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Comment, DeclarationReflection, DocumentReflection, ProjectReflection, ReflectionKind } from "typedoc";
import { Comment, DeclarationReflection, DocumentReflection, type ProjectReflection, ReflectionKind } from "typedoc";
import {
getNameFromDescriptionTag,
moveDeclarationReflectionToTarget,
moveDocumentReflectionToTarget,
removeTagFromCommentsOf,
} from "../utils";
} from "../utils.js";

/**
* Name of the comment tag that can be used to mark a module as the target module within the bundle.
Expand Down
4 changes: 2 additions & 2 deletions src/merger/module_category_merger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeclarationReflection } from "typedoc";
import { ModuleMerger } from "./module_merger";
import type { DeclarationReflection } from "typedoc";
import { ModuleMerger } from "./module_merger.js";

/**
* Merger that merges the content of modules based on their JSDoc module annotation and category.
Expand Down
8 changes: 4 additions & 4 deletions src/merger/module_merger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin } from "src/plugin";
import { DeclarationReflection, ProjectReflection } from "typedoc";
import { getModulesFrom } from "../utils";
import { ModuleBundle } from "./module_bundle";
import type { Plugin } from "src/plugin.js";
import type { DeclarationReflection, ProjectReflection } from "typedoc";
import { getModulesFrom } from "../utils.js";
import { ModuleBundle } from "./module_bundle.js";

/**
* Merger that merges the content of modules based on their JSDoc module annotation.
Expand Down
8 changes: 4 additions & 4 deletions src/merger/project_merger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProjectReflection } from "typedoc";
import { Plugin } from "../plugin";
import { getModulesFrom } from "../utils";
import { ModuleBundle } from "./module_bundle";
import type { ProjectReflection } from "typedoc";
import type { Plugin } from "../plugin.js";
import { getModulesFrom } from "../utils.js";
import { ModuleBundle } from "./module_bundle.js";

/**
* Merger that moves the content of all modules into the project root.
Expand Down
16 changes: 8 additions & 8 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
Application,
Context,
type Context,
Converter,
DeclarationReflection,
type DeclarationReflection,
EntryPointStrategy,
ProjectReflection,
type ProjectReflection,
ReflectionKind,
} from "typedoc";
import { ModuleCategoryMerger } from "./merger/module_category_merger";
import { ModuleMerger } from "./merger/module_merger";
import { ProjectMerger } from "./merger/project_merger";
import { PluginOptions } from "./plugin_options";
import { tryGetOriginalReflectionName } from "./utils";
import { ModuleCategoryMerger } from "./merger/module_category_merger.js";
import { ModuleMerger } from "./merger/module_merger.js";
import { ProjectMerger } from "./merger/project_merger.js";
import { PluginOptions } from "./plugin_options.js";
import { tryGetOriginalReflectionName } from "./utils.js";

/**
* The "Merge Modules" plugin.
Expand Down
2 changes: 1 addition & 1 deletion src/plugin_options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Application, ParameterType } from "typedoc";
import { type Application, ParameterType } from "typedoc";

/** Type for the plugin's mode. */
type Mode = "project" | "module" | "module-category" | "off";
Expand Down
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
CommentTag,
Context,
type CommentTag,
type Context,
DeclarationReflection,
DocumentReflection,
ProjectReflection,
type DocumentReflection,
type ProjectReflection,
ReflectionKind,
} from "typedoc";
import * as ts from "typescript";
import type * as ts from "typescript";

/**
* Type extending the TypeScript Declaration interface with a possible identifier object as a name.
Expand Down
7 changes: 4 additions & 3 deletions test/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/unbound-method
const { defineConfig } = require("cypress");
import { defineConfig } from "cypress";

module.exports = defineConfig({
const config = defineConfig({
e2e: {
specPattern: "**/*.cy.ts",
supportFile: false,
video: false,
screenshotOnRunFailure: false,
},
});

export default config;
29 changes: 12 additions & 17 deletions test/prepare_test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require("fs");
const path = require("path");
import fs from "node:fs/promises";
import path from "node:path";

console.log("=================================== SETTING UP THE TESTS ===========================================");

if (!fs.existsSync(path.join("..", "dist"))) {
if (
!(await fs
.access(path.join("..", "dist"))
.then(() => true)
.catch(() => false))
) {
console.error("ERROR: Cannot find 'dist' folder. Did you forget to build the plugin with 'npm run build'?");
process.exit(1);
}

console.log("Copying current build of plugin to node_modules for testing...");
const nodeModulesSubDir = path.join("..", "node_modules", "typedoc-plugin-merge-modules");

fs.rm(nodeModulesSubDir, { recursive: true, force: true }, (rmErr) => {
if (rmErr) {
throw rmErr;
}
fs.mkdir(path.join(nodeModulesSubDir, "dist"), { recursive: true }, (mkDirErr) => {
if (mkDirErr) {
throw mkDirErr;
} else {
fs.copyFileSync(path.join("..", "package.json"), path.join(nodeModulesSubDir, "package.json"));
fs.cpSync(path.join("..", "dist"), path.join(nodeModulesSubDir, "dist"), { recursive: true });
}
});
});
await fs.rm(nodeModulesSubDir, { recursive: true, force: true });
await fs.mkdir(path.join(nodeModulesSubDir, "dist"), { recursive: true });
await fs.copyFile(path.join("..", "package.json"), path.join(nodeModulesSubDir, "package.json"));
await fs.cp(path.join("..", "dist"), path.join(nodeModulesSubDir, "dist"), { recursive: true });

console.log("DONE\n");
3 changes: 1 addition & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { execSync } = require("child_process");
import { execSync } from "node:child_process";
const execOptions = { stdio: "inherit" };

console.log("===================================== TEST MERGE OFF ===============================================");
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"compilerOptions": {
"outDir": "dist",
"target": "es2015",
"module": "commonjs",
"module": "node16",
"declaration": true,
"baseUrl": "./",
"strict": true,
"noImplicitOverride": true,
"exactOptionalPropertyTypes": true,
"esModuleInterop": true
"esModuleInterop": true,
"isolatedModules": true,
"verbatimModuleSyntax": true
}
}

0 comments on commit 30813c2

Please sign in to comment.