@jcoreio/toolchain 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslintConfig.cjs +1 -6
- package/package.json +11 -5
- package/plugins/getConfigFiles.cjs +24 -32
- package/plugins/getEslintConfigs.cjs +105 -0
- package/scripts/migrate/migrateEslintConfigs.cjs +2 -16
- package/scripts/migrate/migrateRemoveDevDeps.cjs +7 -0
- package/scripts/runEslint.cjs +1 -27
- package/util/migrateLegacyEslintConfigs.cjs +218 -0
- package/bin/eslint +0 -5
- package/bin/lint-fix.cjs +0 -8
- package/bin/lint-staged +0 -5
- package/bin/prettier +0 -5
- package/bin/resolveBin.cjs +0 -8
- package/bin/semantic-release +0 -5
- package/eslint.extends.cjs +0 -79
- package/plugins/getEslintExtends.cjs +0 -1
package/eslintConfig.cjs
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
const getPluginsArraySync = require('./util/getPluginsArraySync.cjs')
|
|
2
2
|
|
|
3
|
-
module.exports =
|
|
4
|
-
extends: [
|
|
5
|
-
...getPluginsArraySync('getEslintExtends'),
|
|
6
|
-
require.resolve('eslint-config-prettier'),
|
|
7
|
-
],
|
|
8
|
-
}
|
|
3
|
+
module.exports = [...getPluginsArraySync('getEslintConfigs')]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoreio/toolchain",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "base JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/jcoreio/toolchains/tree/main/packages/base",
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@babel/generator": "^7.27.0",
|
|
18
|
+
"@babel/parser": "^7.27.0",
|
|
19
|
+
"@babel/template": "^7.27.0",
|
|
20
|
+
"@babel/types": "^7.27.0",
|
|
21
|
+
"@eslint/compat": "^1.2.8",
|
|
22
|
+
"@eslint/js": "^9.23.0",
|
|
17
23
|
"@jcoreio/eslint-plugin-implicit-dependencies": "^1.1.1",
|
|
18
24
|
"chalk": "^4.0.0",
|
|
19
25
|
"dedent-js": "^1.0.1",
|
|
@@ -23,6 +29,7 @@
|
|
|
23
29
|
"find-up": "^5.0.0",
|
|
24
30
|
"fs-extra": "^10.0.0",
|
|
25
31
|
"glob": "^11.0.0",
|
|
32
|
+
"globals": "^16.0.0",
|
|
26
33
|
"js-yaml": "4.1.0",
|
|
27
34
|
"json5": "^2.2.1",
|
|
28
35
|
"lint-staged": "^15.2.2",
|
|
@@ -43,13 +50,12 @@
|
|
|
43
50
|
"packageManager": "pnpm@10.6.5",
|
|
44
51
|
"devDependencies": {
|
|
45
52
|
"eslint": "*",
|
|
46
|
-
"
|
|
53
|
+
"globals": "*",
|
|
54
|
+
"lint-staged": "*",
|
|
55
|
+
"prettier": "*"
|
|
47
56
|
}
|
|
48
57
|
},
|
|
49
58
|
"bin": {
|
|
50
|
-
"eslint": "./bin/eslint",
|
|
51
|
-
"lint-staged": "./bin/lint-staged",
|
|
52
|
-
"prettier": "./bin/prettier",
|
|
53
59
|
"tc": "./scripts/toolchain.cjs",
|
|
54
60
|
"toolchain": "./scripts/toolchain.cjs"
|
|
55
61
|
},
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
const { name } = require('../package.json')
|
|
2
2
|
const dedent = require('dedent-js')
|
|
3
3
|
const fs = require('../util/projectFs.cjs')
|
|
4
|
-
const JSON5 = require('json5')
|
|
5
4
|
const { isMonorepoSubpackage } = require('../util/findUps.cjs')
|
|
6
5
|
const getPluginsArraySync = require('../util/getPluginsArraySync.cjs')
|
|
7
6
|
const initBuildIgnore = require('../util/initBuildIgnore.cjs')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return JSON5.parse(await fs.readFile('.eslintrc.json', 'utf8'))
|
|
12
|
-
}
|
|
13
|
-
if (await fs.pathExists('.eslintrc')) {
|
|
14
|
-
return JSON5.parse(await fs.readFile('.eslintrc', 'utf8'))
|
|
15
|
-
}
|
|
16
|
-
}
|
|
7
|
+
const migrateLegacyEslintConfigs = require('../util/migrateLegacyEslintConfigs.cjs')
|
|
8
|
+
const chalk = require('chalk')
|
|
9
|
+
const { glob } = require('../util/glob.cjs')
|
|
17
10
|
|
|
18
11
|
module.exports = [
|
|
19
12
|
async function getConfigFiles({ fromVersion }) {
|
|
20
|
-
const { env, rules } = (await getRootEslintConfig()) || {}
|
|
21
13
|
const files = {
|
|
22
14
|
...(isMonorepoSubpackage
|
|
23
15
|
? {}
|
|
@@ -26,29 +18,29 @@ module.exports = [
|
|
|
26
18
|
optional=false
|
|
27
19
|
`,
|
|
28
20
|
}),
|
|
29
|
-
'.
|
|
30
|
-
existing && fromVersion
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
: ''
|
|
21
|
+
'eslint.config.cjs': async (existing) => {
|
|
22
|
+
if (existing && fromVersion) return existing
|
|
23
|
+
const configs = {}
|
|
24
|
+
for (const file of await glob('**/.eslintrc{,.json,.js,.cjs}')) {
|
|
25
|
+
configs[file] = await fs.readFile(file)
|
|
26
|
+
}
|
|
27
|
+
const { migrated, warnings } = await migrateLegacyEslintConfigs(configs)
|
|
28
|
+
if (warnings.length) {
|
|
29
|
+
for (const [file, fileWarnings] of Object.entries(warnings)) {
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.warn(
|
|
32
|
+
chalk.yellow(
|
|
33
|
+
dedent`
|
|
34
|
+
WARNING: ${file} could not be completely migrated because of the following:
|
|
35
|
+
${fileWarnings.map((w) => `- ${w}`).join('\n ')}
|
|
36
|
+
|
|
37
|
+
`
|
|
38
|
+
)
|
|
39
|
+
)
|
|
49
40
|
}
|
|
50
41
|
}
|
|
51
|
-
|
|
42
|
+
return migrated
|
|
43
|
+
},
|
|
52
44
|
'toolchain.config.cjs': async (existing) => {
|
|
53
45
|
if (existing) return existing
|
|
54
46
|
return dedent`
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const js = require('@eslint/js')
|
|
2
|
+
const { defineConfig } = require('eslint/config')
|
|
3
|
+
const { includeIgnoreFile } = require('@eslint/compat')
|
|
4
|
+
const { projectDir } = require('../util/findUps.cjs')
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const fs = require('../util/projectFs.cjs')
|
|
7
|
+
const { globSync } = require('../util/glob.cjs')
|
|
8
|
+
|
|
9
|
+
module.exports = [
|
|
10
|
+
() => {
|
|
11
|
+
const gitignores = globSync('**/.gitignore')
|
|
12
|
+
if (fs.pathExistsSync('.eslintignore')) {
|
|
13
|
+
gitignores.push('.eslintignore')
|
|
14
|
+
}
|
|
15
|
+
return defineConfig([
|
|
16
|
+
...gitignores.map((file) =>
|
|
17
|
+
includeIgnoreFile(path.resolve(projectDir, file))
|
|
18
|
+
),
|
|
19
|
+
js.configs.recommended,
|
|
20
|
+
{
|
|
21
|
+
files: ['**/*.{js,cjs,mjs}'],
|
|
22
|
+
plugins: {
|
|
23
|
+
'@jcoreio/implicit-dependencies': require('@jcoreio/eslint-plugin-implicit-dependencies'),
|
|
24
|
+
},
|
|
25
|
+
rules: {
|
|
26
|
+
'@jcoreio/implicit-dependencies/no-implicit': [
|
|
27
|
+
'error',
|
|
28
|
+
{
|
|
29
|
+
dev: true,
|
|
30
|
+
peer: true,
|
|
31
|
+
optional: true,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
'arrow-spacing': 'error',
|
|
35
|
+
'comma-spacing': 'error',
|
|
36
|
+
'computed-property-spacing': ['error', 'never'],
|
|
37
|
+
'eol-last': 'error',
|
|
38
|
+
'jsx-quotes': 'error',
|
|
39
|
+
'keyword-spacing': 'error',
|
|
40
|
+
'key-spacing': [
|
|
41
|
+
'error',
|
|
42
|
+
{
|
|
43
|
+
mode: 'strict',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
'linebreak-style': 'error',
|
|
47
|
+
'no-console': 'error',
|
|
48
|
+
'no-unused-vars': [
|
|
49
|
+
'error',
|
|
50
|
+
{
|
|
51
|
+
args: 'none',
|
|
52
|
+
varsIgnorePattern: 'React',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
'no-extra-semi': 'error',
|
|
56
|
+
'no-multi-spaces': 'error',
|
|
57
|
+
'no-multiple-empty-lines': 'error',
|
|
58
|
+
'no-trailing-spaces': 'error',
|
|
59
|
+
'no-unexpected-multiline': 'error',
|
|
60
|
+
'no-unreachable': 'error',
|
|
61
|
+
'no-whitespace-before-property': 'error',
|
|
62
|
+
'object-shorthand': ['error', 'always'],
|
|
63
|
+
'padded-blocks': ['error', 'never'],
|
|
64
|
+
semi: ['error', 'never'],
|
|
65
|
+
'space-before-blocks': ['error', 'always'],
|
|
66
|
+
'space-before-function-paren': [
|
|
67
|
+
'error',
|
|
68
|
+
{
|
|
69
|
+
anonymous: 'always',
|
|
70
|
+
named: 'never',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
'space-in-parens': ['error', 'never'],
|
|
74
|
+
'space-infix-ops': ['error', { int32Hint: false }],
|
|
75
|
+
'space-unary-ops': [
|
|
76
|
+
'error',
|
|
77
|
+
{
|
|
78
|
+
words: true,
|
|
79
|
+
nonwords: false,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
'rest-spread-spacing': ['error', 'never'],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
files: ['src/**'],
|
|
87
|
+
ignores: ['**/__tests__/**'],
|
|
88
|
+
plugins: {
|
|
89
|
+
'@jcoreio/implicit-dependencies': require('@jcoreio/eslint-plugin-implicit-dependencies'),
|
|
90
|
+
},
|
|
91
|
+
rules: {
|
|
92
|
+
'@jcoreio/implicit-dependencies/no-implicit': [
|
|
93
|
+
'error',
|
|
94
|
+
{
|
|
95
|
+
dev: false,
|
|
96
|
+
peer: true,
|
|
97
|
+
optional: true,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
require('eslint-config-prettier'),
|
|
103
|
+
])
|
|
104
|
+
},
|
|
105
|
+
]
|
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
const { glob } = require('../../util/glob.cjs')
|
|
2
2
|
const Path = require('path')
|
|
3
|
-
const JSON5 = require('json5')
|
|
4
3
|
const fs = require('../../util/projectFs.cjs')
|
|
5
4
|
|
|
6
5
|
async function migrateEslintConfigs({ fromVersion }) {
|
|
7
|
-
if (fromVersion) {
|
|
8
|
-
// only do this migration on init
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
for (const file of await glob(Path.join('**', '.eslintrc{,.json}'))) {
|
|
12
|
-
const content = JSON5.parse(await fs.readFile(file, 'utf8'))
|
|
13
|
-
if (content.extends) {
|
|
14
|
-
delete content.extends
|
|
15
|
-
await fs.writeFile(file, JSON5.stringify(content, null, 2), 'utf8')
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
6
|
for (const file of [
|
|
7
|
+
...(await glob(Path.join('**', '.eslintrc{,.json}'))),
|
|
19
8
|
'.eslintrc.js',
|
|
20
|
-
'.eslintrc.
|
|
21
|
-
'.eslintrc.yaml',
|
|
22
|
-
'.eslintrc.yml',
|
|
23
|
-
'.eslintrc',
|
|
9
|
+
'.eslintrc.cjs',
|
|
24
10
|
]) {
|
|
25
11
|
const exists = await fs.pathExists(file)
|
|
26
12
|
if (exists) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module.exports = [
|
|
2
2
|
'@babel/cli',
|
|
3
3
|
'@babel/core',
|
|
4
|
+
'@babel/eslint-parser',
|
|
4
5
|
'@babel/plugin-dynamic-import-node',
|
|
5
6
|
'@babel/plugin-external-helpers',
|
|
6
7
|
'@babel/plugin-proposal-class-properties',
|
|
@@ -41,6 +42,7 @@ module.exports = [
|
|
|
41
42
|
'@commitlint/cli',
|
|
42
43
|
'@commitlint/config-conventional',
|
|
43
44
|
'@jcoreio/commitlint-config',
|
|
45
|
+
'@jcoreio/eslint-plugin-implicit-dependencies',
|
|
44
46
|
'@jedwards1211/commitlint-config',
|
|
45
47
|
'@jedwards1211/eslint-config-flow',
|
|
46
48
|
'@jedwards1211/eslint-config-react',
|
|
@@ -52,6 +54,7 @@ module.exports = [
|
|
|
52
54
|
'@semantic-release/release-notes-generator',
|
|
53
55
|
'@typescript-eslint/eslint-plugin',
|
|
54
56
|
'@typescript-eslint/parser',
|
|
57
|
+
'@typescript-eslint/typescript-estree',
|
|
55
58
|
'babel-cli',
|
|
56
59
|
'babel-core',
|
|
57
60
|
'babel-eslint',
|
|
@@ -97,6 +100,10 @@ module.exports = [
|
|
|
97
100
|
'cz-conventional-changelog',
|
|
98
101
|
'coveralls',
|
|
99
102
|
'eslint-watch',
|
|
103
|
+
'eslint-plugin-flowtype',
|
|
104
|
+
'eslint-plugin-ft-flow',
|
|
105
|
+
'eslint-plugin-no-only-tests',
|
|
106
|
+
'eslint-plugin-react',
|
|
100
107
|
'flow-copy-source',
|
|
101
108
|
'flow-watch',
|
|
102
109
|
'husky',
|
package/scripts/runEslint.cjs
CHANGED
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
const fs = require('../util/projectFs.cjs')
|
|
2
1
|
const execa = require('../util/execa.cjs')
|
|
3
|
-
const getPluginsArraySync = require('../util/getPluginsArraySync.cjs')
|
|
4
|
-
|
|
5
|
-
async function eslintArgs() {
|
|
6
|
-
return [
|
|
7
|
-
...((await fs.pathExists('.eslintignore')) ||
|
|
8
|
-
!(await fs.pathExists('.gitignore'))
|
|
9
|
-
? []
|
|
10
|
-
: (await fs.readFile('.gitignore', 'utf8'))
|
|
11
|
-
.split(/\r\n?|\n/gm)
|
|
12
|
-
.flatMap((pattern) =>
|
|
13
|
-
!/^#/.test(pattern.trim())
|
|
14
|
-
? ['--ignore-pattern', pattern.trim()]
|
|
15
|
-
: []
|
|
16
|
-
)),
|
|
17
|
-
'--ignore-pattern',
|
|
18
|
-
'flow-typed/',
|
|
19
|
-
'--ext',
|
|
20
|
-
getPluginsArraySync('lintExtensions').join(','),
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
2
|
|
|
24
3
|
async function runEslint(args = []) {
|
|
25
|
-
await execa('eslint', [...args
|
|
26
|
-
env: {
|
|
27
|
-
...process.env,
|
|
28
|
-
ESLINT_USE_FLAT_CONFIG: 'false',
|
|
29
|
-
},
|
|
30
|
-
})
|
|
4
|
+
await execa('eslint', [...args])
|
|
31
5
|
}
|
|
32
6
|
exports.runEslint = runEslint
|
|
33
7
|
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
const { name } = require('../package.json')
|
|
2
|
+
const { format } = require('prettier')
|
|
3
|
+
const prettierConfig = require('../prettier.config.cjs')
|
|
4
|
+
const { statement, expression, default: template } = require('@babel/template')
|
|
5
|
+
const { generate } = require('@babel/generator')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const t = require('@babel/types')
|
|
8
|
+
|
|
9
|
+
const objectExpression = (props) =>
|
|
10
|
+
t.objectExpression(
|
|
11
|
+
Object.entries(props).flatMap(([key, value]) =>
|
|
12
|
+
value ? [t.objectProperty(t.identifier(key), value)] : []
|
|
13
|
+
)
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
const idOrString = (value) =>
|
|
17
|
+
/^[_a-z$][_a-z0-9$]*$/.test(value)
|
|
18
|
+
? t.identifier(value)
|
|
19
|
+
: t.stringLiteral(value)
|
|
20
|
+
|
|
21
|
+
const member = (object, key) => {
|
|
22
|
+
const prop = idOrString(key)
|
|
23
|
+
return t.memberExpression(object, prop, prop.type !== 'Identifier')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isSimpleObjectExpression(obj) {
|
|
27
|
+
return (
|
|
28
|
+
obj &&
|
|
29
|
+
obj.type === 'ObjectExpression' &&
|
|
30
|
+
obj.properties.every(
|
|
31
|
+
(p) =>
|
|
32
|
+
p.type === 'ObjectProperty' &&
|
|
33
|
+
!p.computed &&
|
|
34
|
+
(p.key.type === 'Identifier' || p.key.type === 'StringLiteral')
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function decodeSimpleObjectExpression(obj) {
|
|
40
|
+
if (!isSimpleObjectExpression(obj)) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
'obj is not an ObjectExpression containing only non-computed identifier- or string-keyed properties'
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
return Object.fromEntries(
|
|
46
|
+
obj.properties.map((p) => [
|
|
47
|
+
p.key.type === 'Identifier' ? p.key.name : p.key.value,
|
|
48
|
+
p.value,
|
|
49
|
+
])
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function migrateLegacyEslintConfigs(configs) {
|
|
54
|
+
const body = [
|
|
55
|
+
statement.ast`const { defineConfig } = require('eslint/config')`,
|
|
56
|
+
]
|
|
57
|
+
const warnings = {}
|
|
58
|
+
let importedGlobals = false
|
|
59
|
+
|
|
60
|
+
function importGlobals() {
|
|
61
|
+
if (importedGlobals) return
|
|
62
|
+
body.push(statement.ast`const globals = require('globals')`)
|
|
63
|
+
importedGlobals = true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const CONFIG = expression.ast(`[...require('${name}/eslintConfig.cjs')]`)
|
|
67
|
+
for (const [file, content] of Object.entries(configs)) {
|
|
68
|
+
function warn(warning) {
|
|
69
|
+
;(warnings[file] || (warnings[file] = [])).push(warning)
|
|
70
|
+
}
|
|
71
|
+
if (/\.[cm]?js$/.test(file)) {
|
|
72
|
+
const { parse } = require('@babel/parser')
|
|
73
|
+
let parsed
|
|
74
|
+
try {
|
|
75
|
+
parsed = parse(content, { sourceType: 'unambiguous' })
|
|
76
|
+
} catch (error) {
|
|
77
|
+
warn(`parse error: ${error.message}`)
|
|
78
|
+
continue
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const exportStatement = parsed.program.body.find(
|
|
82
|
+
(s) =>
|
|
83
|
+
s.type === 'ExpressionStatement' &&
|
|
84
|
+
s.expression.type === 'AssignmentExpression' &&
|
|
85
|
+
generate(s.expression.left).code === 'module.exports' &&
|
|
86
|
+
s.expression.right.type === 'ObjectExpression'
|
|
87
|
+
)
|
|
88
|
+
if (!exportStatement) {
|
|
89
|
+
warn('module.exports = statement not found')
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
const config = exportStatement.expression.right
|
|
93
|
+
|
|
94
|
+
if (!isSimpleObjectExpression(config)) {
|
|
95
|
+
warn(
|
|
96
|
+
'config is not an ObjectExpression or has spread or computed properties'
|
|
97
|
+
)
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
const {
|
|
101
|
+
extends: _extends,
|
|
102
|
+
env: _env,
|
|
103
|
+
rules,
|
|
104
|
+
...rest
|
|
105
|
+
} = decodeSimpleObjectExpression(config)
|
|
106
|
+
|
|
107
|
+
for (const key of Object.keys(rest)) {
|
|
108
|
+
warn(
|
|
109
|
+
`migrating ${generate(member(t.identifier('config'), key)).code} is not currently supported`
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (_extends) {
|
|
114
|
+
const ext = generate(_extends).code
|
|
115
|
+
if (
|
|
116
|
+
ext !== `[require.resolve('@jcoreio/toolchain/eslintConfig.cjs')]` &&
|
|
117
|
+
ext !== `[require.resolve('@jcoreio/toolchain/eslint.config.cjs')]`
|
|
118
|
+
) {
|
|
119
|
+
warn(
|
|
120
|
+
`config.extends has entries other than base @jcoreio/toolchain eslint config`
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let env
|
|
125
|
+
if (_env) {
|
|
126
|
+
if (isSimpleObjectExpression(_env)) {
|
|
127
|
+
env = decodeSimpleObjectExpression(_env)
|
|
128
|
+
for (const key in env) {
|
|
129
|
+
if (env[key].type !== 'BooleanLiteral') {
|
|
130
|
+
warn(
|
|
131
|
+
`config.${generate(member(t.identifier('env'), key)).code} is not a boolean`
|
|
132
|
+
)
|
|
133
|
+
delete env[key]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!Object.keys(env).length) env = undefined
|
|
137
|
+
} else {
|
|
138
|
+
warn(
|
|
139
|
+
`config.env is not an ObjectExpression or has spread or computed properties`
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!env && !rules) continue
|
|
145
|
+
|
|
146
|
+
if (env) importGlobals()
|
|
147
|
+
|
|
148
|
+
CONFIG.elements.push(
|
|
149
|
+
objectExpression({
|
|
150
|
+
files:
|
|
151
|
+
path.dirname(file) !== '.' &&
|
|
152
|
+
t.arrayExpression([t.stringLiteral(path.dirname(file) + '/**')]),
|
|
153
|
+
languageOptions:
|
|
154
|
+
env &&
|
|
155
|
+
objectExpression({
|
|
156
|
+
globals: t.objectExpression(
|
|
157
|
+
Object.keys(env).map((key) =>
|
|
158
|
+
t.spreadElement(member(t.identifier('globals'), key))
|
|
159
|
+
)
|
|
160
|
+
),
|
|
161
|
+
}),
|
|
162
|
+
rules,
|
|
163
|
+
})
|
|
164
|
+
)
|
|
165
|
+
} else {
|
|
166
|
+
const JSON5 = require('json5')
|
|
167
|
+
|
|
168
|
+
const props = JSON5.parse(content)
|
|
169
|
+
const { env, rules, ...rest } = props
|
|
170
|
+
|
|
171
|
+
for (const key of Object.keys(rest)) {
|
|
172
|
+
warn(
|
|
173
|
+
`migrating ${generate(member(t.identifier('config'), key)).code} is not currently supported`
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!env && !rules) continue
|
|
178
|
+
|
|
179
|
+
if (env) importGlobals()
|
|
180
|
+
|
|
181
|
+
CONFIG.elements.push(
|
|
182
|
+
objectExpression({
|
|
183
|
+
files:
|
|
184
|
+
path.dirname(file) !== '.' &&
|
|
185
|
+
t.arrayExpression([t.stringLiteral(path.dirname(file) + '/**')]),
|
|
186
|
+
rules: rules && expression.ast(JSON.stringify(rules)),
|
|
187
|
+
languageOptions:
|
|
188
|
+
env &&
|
|
189
|
+
objectExpression({
|
|
190
|
+
globals: t.objectExpression(
|
|
191
|
+
Object.keys(env).map((key) =>
|
|
192
|
+
t.spreadElement(member(t.identifier('globals'), key))
|
|
193
|
+
)
|
|
194
|
+
),
|
|
195
|
+
}),
|
|
196
|
+
})
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
body.push(template`module.exports = defineConfig(CONFIG)`({ CONFIG }))
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
migrated: await format(
|
|
205
|
+
generate(t.program(body)).code.replace(
|
|
206
|
+
/^module\.exports/m,
|
|
207
|
+
'\nmodule.exports'
|
|
208
|
+
),
|
|
209
|
+
{
|
|
210
|
+
...prettierConfig,
|
|
211
|
+
parser: 'babel',
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
warnings,
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
module.exports = migrateLegacyEslintConfigs
|
package/bin/eslint
DELETED
package/bin/lint-fix.cjs
DELETED
package/bin/lint-staged
DELETED
package/bin/prettier
DELETED
package/bin/resolveBin.cjs
DELETED
package/bin/semantic-release
DELETED
package/eslint.extends.cjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: ['eslint:recommended'],
|
|
3
|
-
plugins: ['@jcoreio/eslint-plugin-implicit-dependencies'],
|
|
4
|
-
rules: {
|
|
5
|
-
'@jcoreio/implicit-dependencies/no-implicit': [
|
|
6
|
-
'error',
|
|
7
|
-
{
|
|
8
|
-
dev: true,
|
|
9
|
-
peer: true,
|
|
10
|
-
optional: true,
|
|
11
|
-
},
|
|
12
|
-
],
|
|
13
|
-
'arrow-spacing': 'error',
|
|
14
|
-
'comma-spacing': 'error',
|
|
15
|
-
'computed-property-spacing': ['error', 'never'],
|
|
16
|
-
'eol-last': 'error',
|
|
17
|
-
'jsx-quotes': 'error',
|
|
18
|
-
'keyword-spacing': 'error',
|
|
19
|
-
'key-spacing': [
|
|
20
|
-
'error',
|
|
21
|
-
{
|
|
22
|
-
mode: 'strict',
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
'linebreak-style': 'error',
|
|
26
|
-
'no-console': 'error',
|
|
27
|
-
'no-unused-vars': [
|
|
28
|
-
'error',
|
|
29
|
-
{
|
|
30
|
-
args: 'none',
|
|
31
|
-
varsIgnorePattern: 'React',
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
'no-extra-semi': 'error',
|
|
35
|
-
'no-multi-spaces': 'error',
|
|
36
|
-
'no-multiple-empty-lines': 'error',
|
|
37
|
-
'no-trailing-spaces': 'error',
|
|
38
|
-
'no-unexpected-multiline': 'error',
|
|
39
|
-
'no-unreachable': 'error',
|
|
40
|
-
'no-whitespace-before-property': 'error',
|
|
41
|
-
'object-shorthand': ['error', 'always'],
|
|
42
|
-
'padded-blocks': ['error', 'never'],
|
|
43
|
-
semi: ['error', 'never'],
|
|
44
|
-
'space-before-blocks': ['error', 'always'],
|
|
45
|
-
'space-before-function-paren': [
|
|
46
|
-
'error',
|
|
47
|
-
{
|
|
48
|
-
anonymous: 'always',
|
|
49
|
-
named: 'never',
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
'space-in-parens': ['error', 'never'],
|
|
53
|
-
'space-infix-ops': ['error', { int32Hint: false }],
|
|
54
|
-
'space-unary-ops': [
|
|
55
|
-
'error',
|
|
56
|
-
{
|
|
57
|
-
words: true,
|
|
58
|
-
nonwords: false,
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
'rest-spread-spacing': ['error', 'never'],
|
|
62
|
-
},
|
|
63
|
-
overrides: [
|
|
64
|
-
{
|
|
65
|
-
files: ['src/**'],
|
|
66
|
-
excludedFiles: ['**/__tests__/**'],
|
|
67
|
-
rules: {
|
|
68
|
-
'@jcoreio/implicit-dependencies/no-implicit': [
|
|
69
|
-
'error',
|
|
70
|
-
{
|
|
71
|
-
dev: false,
|
|
72
|
-
peer: true,
|
|
73
|
-
optional: true,
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = [() => [require.resolve('../eslint.extends.cjs')]]
|