Skip to content

Commit

Permalink
fix: prevent "ExperimentalWarning: Importing JSON" logged to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk authored and vmasek committed Dec 9, 2024
1 parent 688a485 commit 8ce9e63
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
7 changes: 6 additions & 1 deletion packages/cli/src/lib/yargs-cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable max-lines-per-function */

import { blue, dim, green } from 'ansis';
import { createRequire } from 'node:module';
import yargs, {
type Argv,
type CommandModule,
Expand All @@ -9,7 +11,6 @@ import yargs, {
} from 'yargs';
import { type PersistConfig, formatSchema } from '@code-pushup/models';
import { TERMINAL_WIDTH } from '@code-pushup/utils';
import packageJson from '../../package.json' with { type: 'json' };
import {
descriptionStyle,
formatNestedValues,
Expand Down Expand Up @@ -65,6 +66,10 @@ export function yargsCli<T = unknown>(
const examples = cfg.examples ?? [];
const cli = yargs(argv);

const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');

// setup yargs
cli
.updateLocale(yargsDecorator)
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/lib/compare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writeFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { join } from 'node:path';
import {
type Format,
Expand All @@ -17,7 +18,6 @@ import {
scoreReport,
ui,
} from '@code-pushup/utils';
import packageJson from '../../package.json' with { type: 'json' };
import {
type ReportsToCompare,
compareAudits,
Expand Down Expand Up @@ -87,6 +87,10 @@ export function compareReports(reports: Diff<Report>): ReportsDiff {

const duration = calcDuration(start);

const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');

return {
commits,
categories,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/lib/implementation/collect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRequire } from 'node:module';
import type { CoreConfig, Report } from '@code-pushup/models';
import { calcDuration, getLatestCommit } from '@code-pushup/utils';
import packageJson from '../../../package.json' with { type: 'json' };
import type { GlobalOptions } from '../types.js';
import { executePlugins } from './execute-plugin.js';

Expand All @@ -17,6 +17,9 @@ export async function collect(options: CollectOptions): Promise<Report> {
const start = performance.now();
const commit = await getLatestCommit();
const pluginOutputs = await executePlugins(plugins, options);
const packageJson = createRequire(import.meta.url)(
'../../../package.json',
) as typeof import('../../../package.json');
return {
commit,
packageName: packageJson.name,
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-coverage/src/lib/coverage-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Audit, Group, PluginConfig } from '@code-pushup/models';
import { capitalize } from '@code-pushup/utils';
import packageJson from '../../package.json' with { type: 'json' };
import {
type CoveragePluginConfig,
type CoverageType,
Expand Down Expand Up @@ -61,6 +61,10 @@ export async function coveragePlugin(
'bin.js',
);

const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');

return {
slug: 'coverage',
title: 'Code coverage',
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-eslint/src/lib/eslint-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { PluginConfig } from '@code-pushup/models';
import packageJson from '../../package.json' with { type: 'json' };
import { type ESLintPluginConfig, eslintPluginConfigSchema } from './config.js';
import { listAuditsAndGroups } from './meta/index.js';
import { createRunnerConfig } from './runner/index.js';
Expand Down Expand Up @@ -39,6 +39,10 @@ export async function eslintPlugin(
'bin.js',
);

const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');

return {
slug: 'eslint',
title: 'ESLint',
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-js-packages/src/lib/js-packages-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Audit, Group, PluginConfig } from '@code-pushup/models';
import packageJson from '../../package.json' with { type: 'json' };
import {
type DependencyGroup,
type JSPackagesPluginConfig,
Expand Down Expand Up @@ -43,6 +43,10 @@ export async function jsPackagesPlugin(
'bin.js',
);

const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');

return {
slug: 'js-packages',
title: 'JS Packages',
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRequire } from 'node:module';
import type { PluginConfig } from '@code-pushup/models';
import packageJson from '../../package.json' with { type: 'json' };
import { LIGHTHOUSE_PLUGIN_SLUG } from './constants.js';
import { normalizeFlags } from './normalize-flags.js';
import {
Expand All @@ -23,6 +23,10 @@ export function lighthousePlugin(
{ skipAudits, onlyAudits, onlyCategories },
);

const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');

return {
slug: LIGHTHOUSE_PLUGIN_SLUG,
packageName: packageJson.name,
Expand Down

0 comments on commit 8ce9e63

Please sign in to comment.