Skip to content

Commit

Permalink
chore: add dev:million-lint command (#8032)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Dec 16, 2024
1 parent 1dfcff8 commit 23d9dbe
Show file tree
Hide file tree
Showing 10 changed files with 1,137 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .eslintignore.react-compiler
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
**/static/*
**/coverage/*
**/lib/*
**/__tests__/*
**/node_modules/*
**/dist/*
*.json
Expand All @@ -28,3 +29,4 @@ scripts/*
test/*
**/__workshop__/*
packages/sanity/playwright-ct/**
**/@sanity/cli/templates/**
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ yalc.lock
## Documentation Report
scripts/docs-report.md

# Temporary data collected by Million Lint
**/.million/store.json
dev/test-studio/.react-compiler-bailout-report.json
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ public-hoist-pattern[]=prettier-plugin-packagejson

prefer-workspace-packages = true
link-workspace-packages = deep

; Used so that the Million Lint instrumentation to `packages/sanity` and ``packages/sanity/vision` done in the test studio works, without having to add the dependency everywhere
public-hoist-pattern[]=@million/lint
2 changes: 1 addition & 1 deletion dev/test-next-studio/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"extends": ["//"],
"tasks": {
"build": {
"env": ["REACT_PRODUCTION_PROFILING"],
"env": ["REACT_PRODUCTION_PROFILING", "REACT_MILLION_LINT"],
"outputs": [".next/**", "!.next/cache/**", "out/**"],
"dependsOn": ["^build"]
},
Expand Down
1 change: 1 addition & 0 deletions dev/test-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"styled-components": "^6.1.11"
},
"devDependencies": {
"@million/lint": "^1.0.14",
"babel-plugin-react-compiler": "19.0.0-beta-37ed2a7-20241206",
"chokidar": "^3.6.0",
"vite": "^5.4.11"
Expand Down
38 changes: 37 additions & 1 deletion dev/test-studio/sanity.cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import path from 'node:path'
import {defineCliConfig} from 'sanity/cli'
import {type UserConfig} from 'vite'

const millionLintEnabled = process.env.REACT_MILLION_LINT === 'true'
const millionInclude: string[] = []
try {
if (millionLintEnabled) {
for (const filePath of require('./.react-compiler-bailout-report.json')) {
millionInclude.push(`**/${filePath}`)
}
}
} catch (err) {
throw new Error('Failed to read lint report, did you run `pnpm report:react-compiler-bailout`?', {
cause: err,
})
}

export default defineCliConfig({
api: {
projectId: 'ppsg7ml5',
Expand All @@ -13,12 +27,34 @@ export default defineCliConfig({
// A) `SANITY_STUDIO_REACT_STRICT_MODE=false pnpm dev`
// B) creating a `.env` file locally that sets the same env variable as above
reactStrictMode: true,
reactCompiler: {target: '18'},
reactCompiler: millionLintEnabled
? {
target: '18',
sources: (filename) => {
if (filename.includes('node_modules')) {
return false
}
return millionInclude.every(
(pattern) => !filename.endsWith(`/${pattern.split('**/')[1]}`),
)
},
}
: {target: '18'},
vite(viteConfig: UserConfig): UserConfig {
const reactProductionProfiling = process.env.REACT_PRODUCTION_PROFILING === 'true'

return {
...viteConfig,
plugins: millionLintEnabled
? [
require('@million/lint').vite({
filter: {
include: millionInclude,
},
}),
...(viteConfig.plugins || []),
]
: viteConfig.plugins,
optimizeDeps: {
...viteConfig.optimizeDeps,
include: ['react/jsx-runtime'],
Expand Down
2 changes: 1 addition & 1 deletion dev/test-studio/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"extends": ["//"],
"tasks": {
"build": {
"env": ["REACT_PRODUCTION_PROFILING"],
"env": ["REACT_PRODUCTION_PROFILING", "REACT_MILLION_LINT"],
"outputs": [".sanity/**", "dist/**", "workshop/scopes.js"]
},
"start": {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"check:deps": "pnpm --recursive --parallel exec depcheck",
"check:format": "prettier . --check",
"check:lint": "turbo run lint --continue -- --quiet",
"check:react-compiler": "eslint --no-inline-config --no-eslintrc --ext .cjs,.mjs,.js,.jsx,.ts,.tsx --parser @typescript-eslint/parser --plugin react-compiler --rule 'react-compiler/react-compiler: [warn]' --ignore-path .eslintignore.react-compiler --max-warnings 79 .",
"check:react-compiler": "eslint --cache --no-inline-config --no-eslintrc --ext .cjs,.mjs,.js,.jsx,.ts,.tsx --parser @typescript-eslint/parser --plugin react-compiler --rule 'react-compiler/react-compiler: [warn]' --ignore-path .eslintignore.react-compiler --max-warnings 77 .",
"report:react-compiler-bailout": "eslint --cache --no-inline-config --no-eslintrc --ext .cjs,.mjs,.js,.jsx,.ts,.tsx --parser @typescript-eslint/parser --plugin react-compiler --rule 'react-compiler/react-compiler: [error,{__unstable_donotuse_reportAllBailouts:true}]' --ignore-path .eslintignore.react-compiler -f ./scripts/reactCompilerBailouts.cjs . || true",
"check:test": "run-s test -- --silent",
"check:types": "tsc && turbo run check:types --filter='./packages/*' --filter='./packages/@sanity/*'",
"chore:format:fix": "prettier --cache --write .",
Expand All @@ -41,6 +42,8 @@
"dev:test-studio": "pnpm --filter sanity-test-studio dev",
"dev:test-create-studio": "pnpm --filter test-create-integration-studio dev",
"dev:test-studio-production-profiling": "REACT_PRODUCTION_PROFILING=true turbo run start --filter=sanity-test-studio",
"dev:million-lint": "pnpm report:react-compiler-bailout && pnpm dev:test-studio-million-lint",
"dev:test-studio-million-lint": "REACT_MILLION_LINT=true pnpm --filter sanity-test-studio dev",
"dev:next-studio": "pnpm --filter sanity-test-next-studio dev",
"dev:turbo-studio": "pnpm dev:next-studio --turbo",
"docs:report": "node -r dotenv-flow/config -r esbuild-register scripts/doc-report/docReport",
Expand Down
Loading

0 comments on commit 23d9dbe

Please sign in to comment.