Skip to content

Commit 8ce9e63

Browse files
matejchalkvmasek
authored andcommitted
fix: prevent "ExperimentalWarning: Importing JSON" logged to stderr
1 parent 688a485 commit 8ce9e63

File tree

7 files changed

+35
-7
lines changed

7 files changed

+35
-7
lines changed

packages/cli/src/lib/yargs-cli.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable max-lines-per-function */
2+
23
import { blue, dim, green } from 'ansis';
4+
import { createRequire } from 'node:module';
35
import yargs, {
46
type Argv,
57
type CommandModule,
@@ -9,7 +11,6 @@ import yargs, {
911
} from 'yargs';
1012
import { type PersistConfig, formatSchema } from '@code-pushup/models';
1113
import { TERMINAL_WIDTH } from '@code-pushup/utils';
12-
import packageJson from '../../package.json' with { type: 'json' };
1314
import {
1415
descriptionStyle,
1516
formatNestedValues,
@@ -65,6 +66,10 @@ export function yargsCli<T = unknown>(
6566
const examples = cfg.examples ?? [];
6667
const cli = yargs(argv);
6768

69+
const packageJson = createRequire(import.meta.url)(
70+
'../../package.json',
71+
) as typeof import('../../package.json');
72+
6873
// setup yargs
6974
cli
7075
.updateLocale(yargsDecorator)

packages/core/src/lib/compare.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { writeFile } from 'node:fs/promises';
2+
import { createRequire } from 'node:module';
23
import { join } from 'node:path';
34
import {
45
type Format,
@@ -17,7 +18,6 @@ import {
1718
scoreReport,
1819
ui,
1920
} from '@code-pushup/utils';
20-
import packageJson from '../../package.json' with { type: 'json' };
2121
import {
2222
type ReportsToCompare,
2323
compareAudits,
@@ -87,6 +87,10 @@ export function compareReports(reports: Diff<Report>): ReportsDiff {
8787

8888
const duration = calcDuration(start);
8989

90+
const packageJson = createRequire(import.meta.url)(
91+
'../../package.json',
92+
) as typeof import('../../package.json');
93+
9094
return {
9195
commits,
9296
categories,

packages/core/src/lib/implementation/collect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { createRequire } from 'node:module';
12
import type { CoreConfig, Report } from '@code-pushup/models';
23
import { calcDuration, getLatestCommit } from '@code-pushup/utils';
3-
import packageJson from '../../../package.json' with { type: 'json' };
44
import type { GlobalOptions } from '../types.js';
55
import { executePlugins } from './execute-plugin.js';
66

@@ -17,6 +17,9 @@ export async function collect(options: CollectOptions): Promise<Report> {
1717
const start = performance.now();
1818
const commit = await getLatestCommit();
1919
const pluginOutputs = await executePlugins(plugins, options);
20+
const packageJson = createRequire(import.meta.url)(
21+
'../../../package.json',
22+
) as typeof import('../../../package.json');
2023
return {
2124
commit,
2225
packageName: packageJson.name,

packages/plugin-coverage/src/lib/coverage-plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { createRequire } from 'node:module';
12
import { dirname, join } from 'node:path';
23
import { fileURLToPath } from 'node:url';
34
import type { Audit, Group, PluginConfig } from '@code-pushup/models';
45
import { capitalize } from '@code-pushup/utils';
5-
import packageJson from '../../package.json' with { type: 'json' };
66
import {
77
type CoveragePluginConfig,
88
type CoverageType,
@@ -61,6 +61,10 @@ export async function coveragePlugin(
6161
'bin.js',
6262
);
6363

64+
const packageJson = createRequire(import.meta.url)(
65+
'../../package.json',
66+
) as typeof import('../../package.json');
67+
6468
return {
6569
slug: 'coverage',
6670
title: 'Code coverage',

packages/plugin-eslint/src/lib/eslint-plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { createRequire } from 'node:module';
12
import { dirname, join } from 'node:path';
23
import { fileURLToPath } from 'node:url';
34
import type { PluginConfig } from '@code-pushup/models';
4-
import packageJson from '../../package.json' with { type: 'json' };
55
import { type ESLintPluginConfig, eslintPluginConfigSchema } from './config.js';
66
import { listAuditsAndGroups } from './meta/index.js';
77
import { createRunnerConfig } from './runner/index.js';
@@ -39,6 +39,10 @@ export async function eslintPlugin(
3939
'bin.js',
4040
);
4141

42+
const packageJson = createRequire(import.meta.url)(
43+
'../../package.json',
44+
) as typeof import('../../package.json');
45+
4246
return {
4347
slug: 'eslint',
4448
title: 'ESLint',

packages/plugin-js-packages/src/lib/js-packages-plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { createRequire } from 'node:module';
12
import { dirname, join } from 'node:path';
23
import { fileURLToPath } from 'node:url';
34
import type { Audit, Group, PluginConfig } from '@code-pushup/models';
4-
import packageJson from '../../package.json' with { type: 'json' };
55
import {
66
type DependencyGroup,
77
type JSPackagesPluginConfig,
@@ -43,6 +43,10 @@ export async function jsPackagesPlugin(
4343
'bin.js',
4444
);
4545

46+
const packageJson = createRequire(import.meta.url)(
47+
'../../package.json',
48+
) as typeof import('../../package.json');
49+
4650
return {
4751
slug: 'js-packages',
4852
title: 'JS Packages',

packages/plugin-lighthouse/src/lib/lighthouse-plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { createRequire } from 'node:module';
12
import type { PluginConfig } from '@code-pushup/models';
2-
import packageJson from '../../package.json' with { type: 'json' };
33
import { LIGHTHOUSE_PLUGIN_SLUG } from './constants.js';
44
import { normalizeFlags } from './normalize-flags.js';
55
import {
@@ -23,6 +23,10 @@ export function lighthousePlugin(
2323
{ skipAudits, onlyAudits, onlyCategories },
2424
);
2525

26+
const packageJson = createRequire(import.meta.url)(
27+
'../../package.json',
28+
) as typeof import('../../package.json');
29+
2630
return {
2731
slug: LIGHTHOUSE_PLUGIN_SLUG,
2832
packageName: packageJson.name,

0 commit comments

Comments
 (0)