Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add eslint 9 config support #762

Merged
merged 18 commits into from
Jul 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: write eslint 9 JS file if eslint version is >= 9
  • Loading branch information
KnightYoshi committed Jun 21, 2024
commit 9c415453dd48b94ece86d05f80d2bb84438175ec
27 changes: 25 additions & 2 deletions packages/wxt/src/core/utils/building/generate-wxt-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import path from 'node:path';
import { Message, parseI18nMessages } from '~/core/utils/i18n';
import { writeFileIfDifferent, getPublicFiles } from '~/core/utils/fs';
import { wxt } from '../../wxt';
import { getEslintVersion } from '~/core/utils/eslint';

/**
* Generate and write all the files inside the `InternalConfig.typesDir` directory.
Expand All @@ -31,7 +32,8 @@ export async function generateTypesDir(
const unimport = createUnimport(wxt.config.imports);
references.push(await writeImportsDeclarationFile(unimport));
if (wxt.config.imports.eslintrc.enabled) {
await writeImportsEslintFile(unimport, wxt.config.imports);
const eslintVersion = await getEslintVersion();
await writeImportsEslintFile(unimport, wxt.config.imports, eslintVersion);
aklinker1 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -62,7 +64,9 @@ async function writeImportsDeclarationFile(unimport: Unimport) {
async function writeImportsEslintFile(
unimport: Unimport,
options: WxtResolvedUnimportOptions,
eslintVersion: string[],
) {
const majorEslintVersion = parseInt(eslintVersion?.[0] ?? '');
const globals: Record<string, EslintGlobalsPropValue> = {};
const eslintrc = { globals };

Expand All @@ -73,7 +77,26 @@ async function writeImportsEslintFile(
.forEach((name) => {
eslintrc.globals[name] = options.eslintrc.globalsPropValue;
});
await fs.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });

const jsonFilePath = options.eslintrc.filePath;
await fs.writeJson(jsonFilePath, eslintrc, { spaces: 2 });

await writeEslintNineFile(majorEslintVersion, jsonFilePath);
}

async function writeEslintNineFile(
majorEslintVersion: number,
jsonFilePath: string,
) {
if (majorEslintVersion >= 9) {
aklinker1 marked this conversation as resolved.
Show resolved Hide resolved
let outputPath = path.dirname(jsonFilePath);
let jsFileName = path.basename(jsonFilePath, '.json') + '.js';
const indexFilePath = path.join(outputPath, jsFileName);
const indexFileContent = `'use strict';
module.exports = require('./${path.basename(jsonFilePath)}');
`;
await fs.writeFile(indexFilePath, indexFileContent);
}
}

async function writePathsDeclarationFile(
Expand Down