require the use of node prefix on native imports

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-01-25 13:47:32 +01:00
parent 4ad63b8d9f
commit 7455dae884
444 changed files with 749 additions and 634 deletions
+4 -2
View File
@@ -15,11 +15,13 @@
* limitations under the License.
*/
const path = require('path');
const path = require('node:path');
// Figure out whether we're running inside the backstage repo or as an installed dependency
/* eslint-disable-next-line no-restricted-syntax */
const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src'));
const isLocal = require('node:fs').existsSync(
path.resolve(__dirname, '../src'),
);
if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) {
require('..');
+2 -2
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
const { join: joinPath } = require('path');
const { join: joinPath } = require('node:path');
/**
* Creates a ESLint configuration that extends the base Backstage configuration.
@@ -235,7 +235,7 @@ function createConfigForRole(dir, role, extraConfig = {}) {
name: '@mui/material',
message: "Please import '@mui/material/...' instead.",
},
...require('module').builtinModules,
...require('node:module').builtinModules,
...(extraConfig.restrictedImports ?? []),
],
// https://mui.com/material-ui/guides/minimizing-bundle-size/
+3 -3
View File
@@ -15,9 +15,9 @@
*/
const fs = require('fs-extra');
const path = require('path');
const crypto = require('crypto');
const glob = require('util').promisify(require('glob'));
const path = require('node:path');
const crypto = require('node:crypto');
const glob = require('node:util').promisify(require('glob'));
const { version } = require('../package.json');
const paths = require('@backstage/cli-common').findPaths(process.cwd());
const {
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
const path = require('path');
const path = require('node:path');
module.exports = {
process(src, filename) {
@@ -14,8 +14,8 @@
* limitations under the License.
*/
const http = require('http');
const https = require('https');
const http = require('node:http');
const https = require('node:https');
const errorMessage = 'Network requests are not allowed in tests';
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
const { createHash } = require('crypto');
const { createHash } = require('node:crypto');
const { transform } = require('sucrase');
const sucrasePkg = require('sucrase/package.json');
+1 -1
View File
@@ -15,7 +15,7 @@
*/
const yaml = require('yaml');
const crypto = require('crypto');
const crypto = require('node:crypto');
function createTransformer(config) {
const process = source => {
+3 -3
View File
@@ -14,15 +14,15 @@
* limitations under the License.
*/
const { pathToFileURL } = require('url');
const { pathToFileURL } = require('node:url');
const { transformSync } = require('@swc/core');
const { addHook } = require('pirates');
const { Module } = require('module');
const { Module } = require('node:module');
// This hooks into module resolution and overrides imports of packages that
// exist in the linked workspace to instead be resolved from the linked workspace.
if (process.env.BACKSTAGE_CLI_LINKED_WORKSPACE) {
const { join: joinPath } = require('path');
const { join: joinPath } = require('node:path');
const { getPackagesSync } = require('@manypkg/get-packages');
const { packages: linkedPackages, root: linkedRoot } = getPackagesSync(
process.env.BACKSTAGE_CLI_LINKED_WORKSPACE,
+4 -4
View File
@@ -14,12 +14,12 @@
* limitations under the License.
*/
import { dirname, extname, resolve as resolvePath } from 'path';
import { fileURLToPath } from 'url';
import { dirname, extname, resolve as resolvePath } from 'node:path';
import { fileURLToPath } from 'node:url';
import { transformFile } from '@swc/core';
import { isBuiltin } from 'node:module';
import { readFile } from 'fs/promises';
import { existsSync } from 'fs';
import { readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
// @ts-check
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { extname } from 'path';
import { extname } from 'node:path';
import { BackstagePackageJson } from '@backstage/cli-node';
export interface EntryPoint {
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import os from 'os';
import os from 'node:os';
import {
parseParallelismOption,
getEnvironmentParallelism,
+4 -4
View File
@@ -14,9 +14,9 @@
* limitations under the License.
*/
import os from 'os';
import os from 'node:os';
import { ErrorLike } from '@backstage/errors';
import { Worker } from 'worker_threads';
import { Worker } from 'node:worker_threads';
const defaultParallelism = Math.ceil(os.cpus().length / 2);
@@ -219,7 +219,7 @@ function workerQueueThread(
data: unknown,
) => Promise<(item: unknown) => Promise<unknown>>,
) {
const { parentPort, workerData } = require('worker_threads');
const { parentPort, workerData } = require('node:worker_threads');
Promise.resolve()
.then(() => workerFuncFactory(workerData))
@@ -321,7 +321,7 @@ function workerThread(
sendMessage: (message: unknown) => void,
) => Promise<unknown>,
) {
const { parentPort, workerData } = require('worker_threads');
const { parentPort, workerData } = require('node:worker_threads');
const sendMessage = (message: unknown) => {
parentPort.postMessage({ type: 'message', message });
+1 -1
View File
@@ -18,7 +18,7 @@ import {
packageFeatureType,
PackageRole,
} from '@backstage/cli-node';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { Project, SourceFile, SyntaxKind, ts, Type } from 'ts-morph';
import { paths } from './paths';
@@ -16,7 +16,7 @@
import { ForwardedError } from '@backstage/errors';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path/posix';
import { resolve as resolvePath } from 'node:path/posix';
export async function resolveLinkedWorkspace(
linkPath: string | undefined,
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { paths } from '../../../../../lib/paths';
import { runBackend } from '../../../lib/runner';
@@ -15,7 +15,7 @@
*/
import { readJson } from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import {
getModuleFederationOptions,
serveBundle,
@@ -17,7 +17,7 @@
import { PackageRole } from '@backstage/cli-node';
import { startBackend, startBackendPlugin } from './startBackend';
import { startFrontend } from './startFrontend';
import { parse, resolve, join } from 'path';
import { parse, resolve, join } from 'node:path';
import { glob } from 'glob';
export function resolveEntryPath(
@@ -16,7 +16,7 @@
import chalk from 'chalk';
import { Command, OptionValues } from 'commander';
import { relative as relativePath } from 'path';
import { relative as relativePath } from 'node:path';
import { buildPackages, getOutputsForRole } from '../../lib/builder';
import { paths } from '../../../../lib/paths';
import {
@@ -16,7 +16,7 @@
import { PackageGraph } from '@backstage/cli-node';
import { findTargetPackages } from './start';
import { posix } from 'path';
import { posix } from 'node:path';
import { paths } from '../../../../lib/paths';
const mocks = {
@@ -19,11 +19,11 @@ import {
PackageGraph,
PackageRole,
} from '@backstage/cli-node';
import { relative as relativePath } from 'path';
import { relative as relativePath } from 'node:path';
import { paths } from '../../../../lib/paths';
import { resolveLinkedWorkspace } from '../package/start/resolveLinkedWorkspace';
import { startPackage } from '../package/start/startPackage';
import { parseArgs } from 'util';
import { parseArgs } from 'node:util';
const ACCEPTED_PACKAGE_ROLES: Array<PackageRole | undefined> = [
'frontend',
@@ -14,9 +14,9 @@
* limitations under the License.
*/
import os from 'os';
import os from 'node:os';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import * as tar from 'tar';
import { createDistWorkspace } from './packager';
import { getEnvironmentParallelism } from '../../../lib/parallel';
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { buildBundle, getModuleFederationOptions } from './bundler';
import { getEnvironmentParallelism } from '../../../lib/parallel';
import { loadCliConfig } from '../../config/lib/config';
@@ -16,13 +16,13 @@
import chalk from 'chalk';
import fs from 'fs-extra';
import { createHash } from 'crypto';
import { createHash } from 'node:crypto';
import {
basename,
extname,
relative as relativePath,
resolve as resolvePath,
} from 'path';
} from 'node:path';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
@@ -17,7 +17,7 @@
import fs from 'fs-extra';
import { rollup, RollupOptions } from 'rollup';
import chalk from 'chalk';
import { relative as relativePath, resolve as resolvePath } from 'path';
import { relative as relativePath, resolve as resolvePath } from 'node:path';
import { paths } from '../../../../lib/paths';
import { makeRollupConfigs } from './config';
import { BuildOptions, Output } from './types';
@@ -19,7 +19,7 @@ import {
dirname,
resolve as resolvePath,
relative as relativePath,
} from 'path';
} from 'node:path';
import { createFilter } from 'rollup-pluginutils';
import {
Plugin,
@@ -16,7 +16,7 @@
import yn from 'yn';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { rspack, Configuration, MultiStats } from '@rspack/core';
import {
measureFileSizesBeforeBuild,
@@ -15,7 +15,7 @@
*/
import { BundlingOptions, ModuleFederationOptions } from './types';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { rspack, Configuration } from '@rspack/core';
import { BundlingPaths } from './paths';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { relative as relativePath } from 'path';
import { relative as relativePath } from 'node:path';
import { getPackages } from '@manypkg/get-packages';
import { rspack } from '@rspack/core';
import { paths } from '../../../../lib/paths';
@@ -19,7 +19,7 @@ import { Config, ConfigReader } from '@backstage/config';
import chokidar from 'chokidar';
import fs from 'fs-extra';
import PQueue from 'p-queue';
import { dirname, join as joinPath, resolve as resolvePath } from 'path';
import { dirname, join as joinPath, resolve as resolvePath } from 'node:path';
import { paths as cliPaths } from '../../../../lib/paths';
const DETECTED_MODULES_MODULE_NAME = '__backstage-autodetected-plugins__';
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { paths } from '../../../../lib/paths';
export type BundlingPathsOptions = {
@@ -17,7 +17,7 @@
import { AppConfig } from '@backstage/config';
import chalk from 'chalk';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import openBrowser from 'react-dev-utils/openBrowser';
import { rspack } from '@rspack/core';
import { RspackDevServer } from '@rspack/dev-server';
@@ -15,7 +15,7 @@
*/
import { serializeError } from '@backstage/errors';
import { ChildProcess } from 'child_process';
import { ChildProcess } from 'node:child_process';
interface RequestMeta {
generation: number;
@@ -20,8 +20,8 @@ import {
join as joinPath,
resolve as resolvePath,
relative as relativePath,
} from 'path';
import { tmpdir } from 'os';
} from 'node:path';
import { tmpdir } from 'node:os';
import * as tar from 'tar';
import partition from 'lodash/partition';
import { paths } from '../../../../lib/paths';
@@ -16,7 +16,7 @@
import fs from 'fs-extra';
import npmPackList from 'npm-packlist';
import { resolve as resolvePath, posix as posixPath } from 'path';
import { resolve as resolvePath, posix as posixPath } from 'node:path';
import { BackstagePackageJson } from '@backstage/cli-node';
import { readEntryPoints } from '../../../../lib/entryPoints';
import { getEntryPointDefaultFeatureType } from '../../../../lib/typeDistProject';
@@ -15,12 +15,12 @@
*/
import { FSWatcher, watch } from 'chokidar';
import type { ChildProcess } from 'child_process';
import type { ChildProcess } from 'node:child_process';
import { ctrlc } from 'ctrlc-windows';
import { IpcServer, ServerDataStore } from '../ipc';
import debounce from 'lodash/debounce';
import { fileURLToPath } from 'url';
import { isAbsolute as isAbsolutePath } from 'path';
import { fileURLToPath } from 'node:url';
import { isAbsolute as isAbsolutePath } from 'node:path';
import { paths } from '../../../../lib/paths';
import spawn from 'cross-spawn';
@@ -19,7 +19,7 @@ import { AppConfig, ConfigReader } from '@backstage/config';
import { paths } from '../../../lib/paths';
import { getPackages } from '@manypkg/get-packages';
import { PackageGraph } from '@backstage/cli-node';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
type Options = {
args: string[];
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import crypto from 'crypto';
import crypto from 'node:crypto';
import openBrowser from 'react-dev-utils/openBrowser';
import { request } from '@octokit/request';
import express, { Express, Request, Response } from 'express';
@@ -15,7 +15,7 @@
*/
import { version as cliVersion } from '../../../../package.json';
import os from 'os';
import os from 'node:os';
import { runOutput } from '@backstage/cli-common';
import { paths } from '../../../lib/paths';
import { Lockfile } from '../../../lib/versioning';
@@ -17,8 +17,8 @@
import chalk from 'chalk';
import fs from 'fs-extra';
import { Command, OptionValues } from 'commander';
import { createHash } from 'crypto';
import { relative as relativePath } from 'path';
import { createHash } from 'node:crypto';
import { relative as relativePath } from 'node:path';
import {
PackageGraph,
BackstagePackageJson,
@@ -124,11 +124,11 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
maxWarnings,
}) => {
const { ESLint } = require('eslint') as typeof import('eslint');
const crypto = require('crypto') as typeof import('crypto');
const crypto = require('node:crypto') as typeof import('crypto');
const globby = require('globby') as typeof import('globby');
const { readFile } =
require('fs/promises') as typeof import('fs/promises');
const workerPath = require('path') as typeof import('path');
require('node:fs/promises') as typeof import('fs/promises');
const workerPath = require('node:path') as typeof import('path');
return async ({
fullDir,
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph } from '@backstage/cli-node';
import { paths } from '../../../../lib/paths';
import { run } from '@backstage/cli-common';
@@ -23,7 +23,11 @@ import {
} from '@backstage/cli-node';
import { OptionValues } from 'commander';
import fs from 'fs-extra';
import { resolve as resolvePath, posix, relative as relativePath } from 'path';
import {
resolve as resolvePath,
posix,
relative as relativePath,
} from 'node:path';
import { paths } from '../../../../lib/paths';
import { publishPreflightCheck } from '../../lib/publishing';
@@ -17,7 +17,7 @@
import chalk from 'chalk';
import { ESLint } from 'eslint';
import { OptionValues } from 'commander';
import { relative as relativePath } from 'path';
import { relative as relativePath } from 'node:path';
import { PackageGraph } from '@backstage/cli-node';
import { paths } from '../../../../lib/paths';
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph } from '@backstage/cli-node';
import { runOutput } from '@backstage/cli-common';
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { getPackages } from '@manypkg/get-packages';
import { PackageRoles } from '@backstage/cli-node';
import { paths } from '../../../lib/paths';
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph, PackageRoles, PackageRole } from '@backstage/cli-node';
const configArgPattern = /--config[=\s][^\s$]+/;
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph, PackageRoles } from '@backstage/cli-node';
const REACT_ROUTER_DEPS = ['react-router', 'react-router-dom'];
@@ -17,14 +17,14 @@ import { BACKSTAGE_JSON, bootstrapEnvProxyAgents } from '@backstage/cli-common';
bootstrapEnvProxyAgents();
import { env } from 'process';
import { env } from 'node:process';
import fs from 'fs-extra';
import chalk from 'chalk';
import { minimatch } from 'minimatch';
import semver from 'semver';
import { OptionValues } from 'commander';
import { isError, NotFoundError } from '@backstage/errors';
import { resolve as resolvePath } from 'path';
import { resolve as resolvePath } from 'node:path';
import { paths } from '../../../../lib/paths';
import { getHasYarnPlugin } from '../../../../lib/yarnPlugin';
import {
@@ -15,7 +15,7 @@
*/
import { BackstagePackageJson, PackageGraph } from '@backstage/cli-node';
import chalk from 'chalk';
import { resolve as resolvePath, join as joinPath } from 'path';
import { resolve as resolvePath, join as joinPath } from 'node:path';
import { OptionValues } from 'commander';
import { readJson, writeJson } from 'fs-extra';
import { minimatch } from 'minimatch';
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import path from 'path';
import path from 'node:path';
import { paths } from '../../../../lib/paths';
const TEAM_ID_RE = /^@[-\w]+\/[-\w]+$/;
@@ -15,7 +15,7 @@
*/
import fs from 'fs-extra';
import { dirname, resolve as resolvePath } from 'path';
import { dirname, resolve as resolvePath } from 'node:path';
import { paths } from '../../../../lib/paths';
import { PortableTemplate, PortableTemplateInput } from '../types';
@@ -17,7 +17,7 @@
import { z } from 'zod';
import fs from 'fs-extra';
import recursiveReaddir from 'recursive-readdir';
import { resolve as resolvePath, relative as relativePath } from 'path';
import { resolve as resolvePath, relative as relativePath } from 'node:path';
import { dirname } from 'node:path';
import { parse as parseYaml } from 'yaml';
import { paths } from '../../../../lib/paths';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { join as joinPath } from 'path';
import { join as joinPath } from 'node:path';
import { PortableTemplateInputRoleParams } from '../types';
export type ResolvePackageParamsOptions = {
@@ -14,13 +14,13 @@
* limitations under the License.
*/
import os from 'os';
import os from 'node:os';
import crypto from 'node:crypto';
import yargs from 'yargs';
// 'jest-cli' is included with jest and should be kept in sync with the installed jest version
// eslint-disable-next-line @backstage/no-undeclared-imports
import { run as runJest, yargsOptions as jestYargsOptions } from 'jest-cli';
import { relative as relativePath } from 'path';
import { relative as relativePath } from 'node:path';
import { Command, OptionValues } from 'commander';
import { Lockfile, PackageGraph } from '@backstage/cli-node';
import { paths } from '../../../../lib/paths';
@@ -14,8 +14,8 @@
* limitations under the License.
*/
import { execFileSync } from 'child_process';
import { resolve as resolvePath } from 'path';
import { execFileSync } from 'node:child_process';
import { resolve as resolvePath } from 'node:path';
import { Output, buildPackage } from '../../modules/build/lib/builder';
const exportValues = {
+1 -1
View File
@@ -22,7 +22,7 @@ import { version } from '../lib/version';
import chalk from 'chalk';
import { exitWithError } from '../lib/errors';
import { ForwardedError } from '@backstage/errors';
import { isPromise } from 'util/types';
import { isPromise } from 'node:util/types';
type UninitializedFeature = CliFeature | Promise<{ default: CliFeature }>;