Merge pull request #2684 from themousepotato/lintrule-dirname-fix
Add a lint rule to avoid using __dirname
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
const path = require('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'));
|
||||
|
||||
if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) {
|
||||
@@ -25,6 +26,7 @@ if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) {
|
||||
} else {
|
||||
require('ts-node').register({
|
||||
transpileOnly: true,
|
||||
/* eslint-disable-next-line no-restricted-syntax */
|
||||
project: path.resolve(__dirname, '../../../tsconfig.json'),
|
||||
compilerOptions: {
|
||||
module: 'CommonJS',
|
||||
|
||||
@@ -67,6 +67,11 @@ module.exports = {
|
||||
selector:
|
||||
'ImportDeclaration[source.value="winston"] ImportDefaultSpecifier',
|
||||
},
|
||||
{
|
||||
message:
|
||||
"`__dirname` doesn't refer to the same dir in production builds, try `resolvePackagePath()` from `@backstage/backend-common` instead.",
|
||||
selector: 'Identifier[name="__dirname"]',
|
||||
},
|
||||
],
|
||||
},
|
||||
overrides: [
|
||||
|
||||
@@ -209,6 +209,7 @@ export async function createBackendConfig(
|
||||
],
|
||||
target: 'node' as const,
|
||||
node: {
|
||||
/* eslint-disable-next-line no-restricted-syntax */
|
||||
__dirname: true,
|
||||
__filename: true,
|
||||
global: true,
|
||||
|
||||
@@ -16,4 +16,5 @@
|
||||
|
||||
import { findPaths } from '@backstage/cli-common';
|
||||
|
||||
/* eslint-disable-next-line no-restricted-syntax */
|
||||
export const paths = findPaths(__dirname);
|
||||
|
||||
Reference in New Issue
Block a user