Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
60 changes: 60 additions & 0 deletions apps/oxlint/conformance/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e

ESLINT_SHA="8f360ad6a7a743d33a83eed8973ee4a50731e55b" # 10.0.0-rc.0
REACT_SHA="612e371fb215498edde4c853bd1e0c8e9203808f" # 19.2.3
STYLISTIC_SHA="5c4b512a225a314fa5f41eead9fdc4d51fc243d7" # 5.7.1

# Shallow clone a repo at a specific commit.
# Git commands copied from `.github/scripts/clone-parallel.mjs`.
Expand Down Expand Up @@ -60,3 +61,62 @@ yarn add eslint-plugin-react-hooks

# Return to `submodules` directory
cd ../../..

###############################################################################
# Stylistic
###############################################################################

# Clone ESLint Stylistic repo into `submodules/stylistic`
clone stylistic https://github.com/eslint-stylistic/eslint-stylistic.git "$STYLISTIC_SHA"

# Install dependencies.
# No `--ignore-workspace` because `eslint-stylistic` has its own `pnpm-workspace.yaml`.
pnpm install

# Patch `package.json` files to add Node.js subpath imports.
# ESLint Stylistic uses TypeScript `paths` in `tsconfig.base.json` (e.g. `#test`),
# but Node/tsx doesn't respect tsconfig paths. It needs `imports` in `package.json`.
#
# Read path aliases from `tsconfig.base.json` and add them to `package.json` as `imports`.
node -e '
const fs = require("fs");
const path = require("path");

const pluginPkgPath = path.resolve("packages/eslint-plugin/package.json");
const pluginPkg = JSON.parse(fs.readFileSync(pluginPkgPath, "utf8"));

// Read path aliases from `tsconfig.base.json`
const tsconfig = JSON.parse(fs.readFileSync("tsconfig.base.json", "utf8"));
const tsPaths = tsconfig.compilerOptions.paths;

// Convert tsconfig paths format to package.json imports format
// tsconfig: { "#test": ["./shared/test-utils/index.ts"] }
// package.json: { "#test": "./shared/test-utils/index.ts" }
pluginPkg.imports = Object.fromEntries(
Object.entries(tsPaths).map(([alias, targets]) => [alias, targets[0]]),
);

fs.writeFileSync(pluginPkgPath, JSON.stringify(pluginPkg, null, 2) + "\n");
'

# Node.js resolves `imports` from the nearest `package.json` with a `name` field,
# and subpath imports can only reference files within the package (no `../` allowed).
# So create a symlink to the `shared` directory within the `eslint-plugin` package.
ln -s ../../shared packages/eslint-plugin/shared

# Replace top-level await imports in `parsers-jsx.ts` with regular imports.
# `tsx` does not support TLA with CJS output format.
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' '/^export const.*= await import/d' shared/test-utils/parsers-jsx.ts
else
sed -i '/^export const.*= await import/d' shared/test-utils/parsers-jsx.ts
fi

cat >> shared/test-utils/parsers-jsx.ts << 'EOF'
import BABEL_ESLINT from '@babel/eslint-parser';
import TYPESCRIPT_ESLINT from '@typescript-eslint/parser';
export { BABEL_ESLINT, TYPESCRIPT_ESLINT };
EOF

# Return to `submodules` directory
cd ..
Loading
Loading