forked from jaredpalmer/tsdx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into transpile-only
* master: (26 commits) (deps/lint): upgrade @typescript-eslint to support ?. and ?? (jaredpalmer#377) (ci): add a lint job so PRs will require passing lint (jaredpalmer#378) (clean): remove .rts_cache_* from storybook gitignore (jaredpalmer#375) Add optional chaining and nullish coalescing operators support (jaredpalmer#370) Added Storybook template (jaredpalmer#318) (fix/ci): GitHub Actions should run on PRs as well (fix/format): formatting of jaredpalmer#366 didn't pass lint Add prepare script to generated project (jaredpalmer#334) default jest to watch mode when not in CI (jaredpalmer#366) (fix): respect tsconfig esModuleInterop flag (jaredpalmer#327) fix: minor typo update rollup deps and plugins update to ts 3.7 Remove unnecessary yarn install command in GH action update README.md update README.md Use node_modules/.cache/... as cacheRoot (jaredpalmer#329) fix(lint): Only default to src test if they exist (jaredpalmer#344) Fix error when providing babel/preset-env without options (jaredpalmer#350) Replaced some sync methods for their async version ...
- Loading branch information
Showing
51 changed files
with
1,952 additions
and
1,090 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
*.log | ||
.DS_Store | ||
node_modules | ||
.rts2_cache_cjs | ||
.rts2_cache_esm | ||
.rts2_cache_umd | ||
.rts2_cache_system | ||
dist | ||
tester | ||
tester-react | ||
package-lock.json | ||
# Local Netlify folder | ||
.netlify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,57 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import util from 'util'; | ||
import { CLIEngine } from 'eslint'; | ||
import { PackageJson } from './types'; | ||
import { getReactVersion } from './utils'; | ||
|
||
interface CreateEslintConfigArgs { | ||
pkg: PackageJson; | ||
rootDir: string; | ||
writeFile: boolean; | ||
} | ||
export function createEslintConfig({ | ||
export async function createEslintConfig({ | ||
pkg, | ||
rootDir, | ||
writeFile, | ||
}: CreateEslintConfigArgs): CLIEngine.Options['baseConfig'] { | ||
}: CreateEslintConfigArgs): Promise<CLIEngine.Options['baseConfig']> { | ||
const isReactLibrary = Boolean(getReactVersion(pkg)); | ||
|
||
const config = { | ||
extends: [ | ||
'react-app', | ||
'prettier/@typescript-eslint', | ||
'plugin:prettier/recommended', | ||
], | ||
settings: { | ||
react: { | ||
// Fix for https://github.com/jaredpalmer/tsdx/issues/279 | ||
version: isReactLibrary ? 'detect' : '999.999.999', | ||
}, | ||
}, | ||
}; | ||
|
||
if (writeFile) { | ||
const file = path.join(rootDir, '.eslintrc.js'); | ||
if (fs.existsSync(file)) { | ||
if (!writeFile) { | ||
return config; | ||
} | ||
|
||
const file = path.join(rootDir, '.eslintrc.js'); | ||
try { | ||
await util.promisify(fs.writeFile)( | ||
file, | ||
`module.exports = ${JSON.stringify(config, null, 2)}`, | ||
{ flag: 'wx' } | ||
); | ||
} catch (e) { | ||
if (e.code === 'EEXIST') { | ||
console.error( | ||
'Error trying to save the Eslint configuration file:', | ||
`${file} already exists.` | ||
); | ||
} else { | ||
try { | ||
fs.writeFileSync( | ||
file, | ||
`module.exports = ${JSON.stringify(config, null, 2)}` | ||
); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
console.error(e); | ||
} | ||
} | ||
|
||
return config; | ||
return config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.