diff --git a/src/index.ts b/src/index.ts index 7b96d293..756d9727 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,9 @@ +import { createRequire } from 'node:module'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + import { baseConfigs } from './configs'; import { rules } from './rules'; -import { - name as packageName, - version as packageVersion, -} from '../package.json'; import type { SupportedTestingFramework } from './utils'; import type { ESLint, Rule, Linter } from 'eslint'; @@ -12,6 +12,18 @@ type ClassicConfigs = Record; type FlatConfigs = Record<`flat/${SupportedTestingFramework}`, Linter.Config>; type PluginConfigs = ClassicConfigs & FlatConfigs; +const require = createRequire(import.meta.url); +const __dirname = dirname(fileURLToPath(import.meta.url)); + +// Reference package.json with `require` so it takes the right "version" +// with semantic release after bundle is generated. +const { name: packageName, version: packageVersion } = require( + resolve(__dirname, '../package.json') +) as { + name: string; + version: string; +}; + const PLUGIN_NAME = 'testing-library' as const; function createPluginFlatConfigs() {