Skip to content

Commit

Permalink
pass context and not projectRoot to usesEslint utility
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Jul 20, 2023
1 parent 357daf9 commit c825ad5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/frameworks/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const configure = async (ctx: PagesGeneratorContext) => {
export const shouldInstallNextOnPagesEslintPlugin = async (
ctx: PagesGeneratorContext
): Promise<boolean> => {
const eslintUsage = usesEslint(ctx.project.name);
const eslintUsage = usesEslint(ctx);

if (!eslintUsage.used) return false;

Expand Down
9 changes: 5 additions & 4 deletions packages/create-cloudflare/src/helpers/files.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs, { existsSync } from "fs";
import { crash } from "./cli";
import type { PagesGeneratorContext } from "types";

export const writeFile = (path: string, content: string) => {
try {
Expand Down Expand Up @@ -69,26 +70,26 @@ type EslintUsageInfo =
- https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-formats
- https://eslint.org/docs/latest/use/configure/configuration-files-new )
*/
export const usesEslint = (projectRoot = "."): EslintUsageInfo => {
export const usesEslint = (ctx: PagesGeneratorContext): EslintUsageInfo => {
for (const ext of eslintRcExts) {
const eslintRcFilename = `.eslintrc.${ext}` as EslintRcFileName;
if (existsSync(`${projectRoot}/${eslintRcFilename}`)) {
if (existsSync(`${ctx.project.path}/${eslintRcFilename}`)) {
return {
used: true,
configType: eslintRcFilename,
};
}
}

if (existsSync(`${projectRoot}/eslint.config.js`)) {
if (existsSync(`${ctx.project.path}/eslint.config.js`)) {
return {
used: true,
configType: "eslint.config.js",
};
}

try {
const pkgJson = readJSON(`${projectRoot}/package.json`);
const pkgJson = readJSON(`${ctx.project.path}/package.json`);
if (pkgJson.eslintConfig) {
return {
used: true,
Expand Down

0 comments on commit c825ad5

Please sign in to comment.