diff --git a/eslint.config.mjs b/eslint.config.mjs index daaf9f61..0f4f8886 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -17,9 +17,15 @@ export default [ }, }, { + // overrides for cjs files + files: ["*.js"], rules: { - "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-require-imports": "off", + }, + }, + { + rules: { + "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unused-vars": "warn", }, }, diff --git a/src/register.ts b/src/register.ts index d951da8a..1da39f14 100755 --- a/src/register.ts +++ b/src/register.ts @@ -96,6 +96,7 @@ register.initialize = function initialize(): { } { let tsNode: typeof TSNode; try { + // eslint-disable-next-line @typescript-eslint/no-require-imports tsNode = require("ts-node"); } catch { throw new Error( diff --git a/src/utils/ts-helpers.ts b/src/utils/ts-helpers.ts index fd895b86..cf784059 100755 --- a/src/utils/ts-helpers.ts +++ b/src/utils/ts-helpers.ts @@ -83,6 +83,7 @@ export function createSyntheticEmitHost( export function getTsNodeRegistrationProperties(tsInstance: typeof ts) { let tsNodeSymbol: typeof REGISTER_INSTANCE; try { + // eslint-disable-next-line @typescript-eslint/no-require-imports tsNodeSymbol = require("ts-node")?.["REGISTER_INSTANCE"]; } catch { return undefined; diff --git a/test/config.ts b/test/config.ts index 11e8b834..5b081415 100755 --- a/test/config.ts +++ b/test/config.ts @@ -1,15 +1,13 @@ import ts from "typescript"; -import TypeScriptThree from "typescript-three"; -import TypeScriptFourSeven from "typescript-four-seven"; +import tsThree from "typescript-three"; +import tsFourSeven from "typescript-four-seven"; import path from "path"; /* ****************************************************************************************************************** */ // region: TS Instances /* ****************************************************************************************************************** */ -export { ts }; -export const tsThree: typeof TypeScriptThree = require("typescript-three"); -export const tsFourSeven: typeof TypeScriptFourSeven = require("typescript-four-seven"); +export { ts, tsThree, tsFourSeven }; // endregion diff --git a/test/tests/extras.test.ts b/test/tests/extras.test.ts index 8cf715ff..cd326aca 100755 --- a/test/tests/extras.test.ts +++ b/test/tests/extras.test.ts @@ -1,4 +1,4 @@ -import { createTsProgram, getEmitResultFromProgram } from "../utils"; +import { createTsProgram, getEmitResultFromProgram, ModuleNotFoundError } from "../utils"; import { projectsPaths } from "../config"; import path from "path"; import ts from "typescript"; @@ -21,7 +21,7 @@ describe(`Extra Tests`, () => { jest.doMock( "ts-node", () => { - require("sdf0s39rf3333d@fake-module"); + throw new ModuleNotFoundError("ts-node"); }, { virtual: true }, ); diff --git a/test/tests/register.test.ts b/test/tests/register.test.ts index e6ca3a88..5380d762 100755 --- a/test/tests/register.test.ts +++ b/test/tests/register.test.ts @@ -4,6 +4,7 @@ import * as tsNode from "ts-node"; import * as transformerModule from "typescript-transform-paths/dist/transformer"; import { REGISTER_INSTANCE } from "ts-node"; import { CustomTransformers, PluginImport, Program } from "typescript"; +import { ModuleNotFoundError } from "../utils"; /* ****************************************************************************************************************** * * Config @@ -91,7 +92,7 @@ describe(`Register script`, () => { jest.doMock( "ts-node", () => { - require("sdf0s39rf3333d@fake-module"); + throw new ModuleNotFoundError("ts-node"); }, { virtual: true }, ); diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index 9fe02ffc..e7fe5ba5 100755 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -185,6 +185,7 @@ export function getTsNodeEmitResult( const compiler = tsNode.create({ transpileOnly: true, transformers: { + // eslint-disable-next-line @typescript-eslint/no-require-imports before: [tstpTransform(void 0, pluginConfig, { ts: require(tsSpecifier) })], }, project: pcl.options.configFilePath, diff --git a/test/utils/index.ts b/test/utils/index.ts index d4e09d7b..8ec4d19a 100755 --- a/test/utils/index.ts +++ b/test/utils/index.ts @@ -1 +1,2 @@ export * from "./helpers"; +export * from "./module-not-found-error"; diff --git a/test/utils/module-not-found-error.ts b/test/utils/module-not-found-error.ts new file mode 100644 index 00000000..9defd405 --- /dev/null +++ b/test/utils/module-not-found-error.ts @@ -0,0 +1,8 @@ +/** Mimicks a module not found nodejs error, see https://nodejs.org/docs/v20.16.0/api/errors.html */ +export class ModuleNotFoundError extends Error { + code = "MODULE_NOT_FOUND"; + + constructor(packageName: string, options?: ErrorOptions) { + super(`Uncaught Error: Cannot find module '${packageName}'`, options); + } +}