@anolilab/eslint-config 7.2.1 → 7.2.2
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/CHANGELOG.md +7 -0
- package/dist/postinstall.js +9 -9
- package/dist/postinstall.js.map +1 -1
- package/dist/postinstall.mjs +9 -9
- package/dist/postinstall.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## @anolilab/eslint-config [7.2.2](https://github.com/anolilab/javascript-style-guide/compare/@anolilab/eslint-config@7.2.1...@anolilab/eslint-config@7.2.2) (2023-06-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* extended postinstall script file checking ([5f867d7](https://github.com/anolilab/javascript-style-guide/commit/5f867d7b4d3acc9f2af4651b23f8e1a0d206e923))
|
|
7
|
+
|
|
1
8
|
## @anolilab/eslint-config [7.2.1](https://github.com/anolilab/javascript-style-guide/compare/@anolilab/eslint-config@7.2.0...@anolilab/eslint-config@7.2.1) (2023-06-25)
|
|
2
9
|
|
|
3
10
|
|
package/dist/postinstall.js
CHANGED
|
@@ -5,26 +5,28 @@ var fs = require('fs');
|
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var util = require('util');
|
|
7
7
|
|
|
8
|
-
process.env.CI&&process.exit(0);var
|
|
9
|
-
`);var
|
|
8
|
+
process.env.CI&&process.exit(0);var f=util.promisify(fs.writeFile);console.log("Configuring @anolilab/eslint-config",packageJsonUtils.projectPath,`
|
|
9
|
+
`);var s=".eslintrc",d=()=>{for(let o of [s,`${s}.js`,`${s}.cjs`,`${s}.json`,`${s}.yaml`,`${s}.yml`])if(fs.existsSync(path.join(packageJsonUtils.projectPath,o)))return console.warn(`\u26A0\uFE0F ${o} already exists;
|
|
10
|
+
Make sure that it includes the following for @anolilab/eslint-config'
|
|
11
|
+
to work as it should: { extends: ["@anolilab/eslint-config"] }.`),Promise.resolve();let t=path.join(packageJsonUtils.projectPath,".eslintrc.js"),a="",c=`
|
|
10
12
|
parserOptions: {
|
|
11
13
|
ecmaVersion: "latest",
|
|
12
14
|
sourceType: ${packageJsonUtils.packageIsTypeModule?'"module"':'"commonjs"'},
|
|
13
|
-
},`,
|
|
15
|
+
},`,p=path.join(packageJsonUtils.projectPath,"tsconfig.json");if(fs.existsSync(p)){let o=JSON.parse(fs.readFileSync(p,"utf8")),e="latest";o.compilerOptions?.target&&(e=o.compilerOptions.target,e=e.toLowerCase()==="es2022"||e.toLowerCase()==="esnext"?"latest":e.toLowerCase().replace("es",""),e!=="latest"&&e!=="2022"&&e!=="2021"&&e!=="6"&&(a=`, "plugin:es-x/restrict-to-es${e}"`)),c=`
|
|
14
16
|
parserOptions: {
|
|
15
17
|
project: "./tsconfig.json",
|
|
16
18
|
ecmaVersion: ${e==="latest"?`"${e}"`:e},
|
|
17
19
|
sourceType: ${packageJsonUtils.packageIsTypeModule?'"module"':'"commonjs"'},
|
|
18
|
-
},`;}let
|
|
20
|
+
},`;}let m=`/** @ts-check */
|
|
19
21
|
/** @type {import('eslint').Linter.Config} */
|
|
20
22
|
${packageJsonUtils.packageIsTypeModule?"export default":"module.exports ="} {
|
|
21
23
|
root: true,
|
|
22
|
-
extends: ["@anolilab/eslint-config"${
|
|
24
|
+
extends: ["@anolilab/eslint-config"${a}],
|
|
23
25
|
ignorePatterns: ["!**/*"],
|
|
24
26
|
env: {
|
|
25
27
|
// Your environments (which contains several predefined global variables)
|
|
26
28
|
// Most environments are loaded automatically if our rules are added
|
|
27
|
-
},${
|
|
29
|
+
},${c}
|
|
28
30
|
globals: {
|
|
29
31
|
// Your global variables (setting to false means it's not allowed to be reassigned)
|
|
30
32
|
// myGlobal: false
|
|
@@ -58,8 +60,6 @@ ${packageJsonUtils.packageIsTypeModule?"export default":"module.exports ="} {
|
|
|
58
60
|
},
|
|
59
61
|
],
|
|
60
62
|
};
|
|
61
|
-
`;return fs.existsSync(t)?(console.warn(
|
|
62
|
-
Make sure that it includes the following for @anolilab/eslint-config'
|
|
63
|
-
to work as it should: { extends: ["@anolilab/eslint-config"] }.`),Promise.resolve()):p(t,f,"utf-8")},d=()=>{let t=path.join(packageJsonUtils.projectPath,".eslintignore");return fs.existsSync(t)?(console.warn("\u26A0\uFE0F .eslintignore already exists"),Promise.resolve()):p(t,"","utf-8")};(async()=>{try{await Promise.all([h(),d()]),console.log("\u{1F60E} Everything went well, have fun!"),process.exit(0);}catch(t){console.log("\u{1F62C} something went wrong:"),console.error(t),process.exit(1);}})();
|
|
63
|
+
`;return f(t,m,"utf8")},w=()=>{let t=path.join(packageJsonUtils.projectPath,".eslintignore");return fs.existsSync(t)?(console.warn("\u26A0\uFE0F .eslintignore already exists"),Promise.resolve()):f(t,"","utf8")};(async()=>{try{await Promise.all([d(),w()]),console.log("\u{1F60E} Everything went well, have fun!"),process.exit(0);}catch(t){console.log("\u{1F62C} something went wrong:"),console.error(t),process.exit(1);}})();
|
|
64
64
|
//# sourceMappingURL=out.js.map
|
|
65
65
|
//# sourceMappingURL=postinstall.js.map
|
package/dist/postinstall.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/postinstall.ts"],"names":["packageIsTypeModule","projectPath","existsSync","readFileSync","writeFile","join","promisify","writeFileAsync","writeEslintRc","eslintPath","pluginExtends","parserOptions","tsconfigPath","tsConfig","ecmaVersion","content","writeEslintIgnore","eslintIgnorePath","error"],"mappings":"AAAA,OAAS,uBAAAA,EAAqB,eAAAC,MAAmB,+BACjD,OAAS,cAAAC,EAAY,gBAAAC,EAAc,aAAAC,MAAiB,KACpD,OAAS,QAAAC,MAAY,OACrB,OAAS,aAAAC,MAAiB,OAGtB,QAAQ,IAAI,IAEZ,QAAQ,KAAK,CAAC,EAGlB,IAAMC,EAAiBD,EAAUF,CAAS,EAE1C,QAAQ,IAAI,sCAAuCH,EAAa;AAAA,CAAI,
|
|
1
|
+
{"version":3,"sources":["../src/postinstall.ts"],"names":["packageIsTypeModule","projectPath","existsSync","readFileSync","writeFile","join","promisify","writeFileAsync","configFile","writeEslintRc","filename","eslintPath","pluginExtends","parserOptions","tsconfigPath","tsConfig","ecmaVersion","content","writeEslintIgnore","eslintIgnorePath","error"],"mappings":"AAAA,OAAS,uBAAAA,EAAqB,eAAAC,MAAmB,+BACjD,OAAS,cAAAC,EAAY,gBAAAC,EAAc,aAAAC,MAAiB,KACpD,OAAS,QAAAC,MAAY,OACrB,OAAS,aAAAC,MAAiB,OAGtB,QAAQ,IAAI,IAEZ,QAAQ,KAAK,CAAC,EAGlB,IAAMC,EAAiBD,EAAUF,CAAS,EAE1C,QAAQ,IAAI,sCAAuCH,EAAa;AAAA,CAAI,EAEpE,IAAMO,EAAa,YAMbC,EAAgB,IAAM,CAExB,QAAWC,IAAY,CAACF,EAAY,GAAGA,OAAiB,GAAGA,QAAkB,GAAGA,SAAmB,GAAGA,SAAmB,GAAGA,OAAgB,EACxI,GAAIN,EAAWG,EAAKJ,EAAaS,CAAQ,CAAC,EACtC,eAAQ,KAAK,iBAAOA;AAAA;AAAA,gEAEgC,EAE7C,QAAQ,QAAQ,EAI/B,IAAMC,EAAaN,EAAKJ,EAAa,cAAc,EAE/CW,EAAgB,GAChBC,EAAgB;AAAA;AAAA;AAAA,sBAGFb,EAAsB,WAAa;AAAA,QAG/Cc,EAAeT,EAAKJ,EAAa,eAAe,EAEtD,GAAIC,EAAWY,CAAY,EAAG,CAC1B,IAAMC,EAAW,KAAK,MAAMZ,EAAaW,EAAc,MAAM,CAAC,EAE1DE,EAAc,SAEdD,EAAS,iBAAiB,SAC1BC,EAAcD,EAAS,gBAAgB,OAEvCC,EAAcA,EAAY,YAAY,IAAM,UAAYA,EAAY,YAAY,IAAM,SAAW,SAAWA,EAAY,YAAY,EAAE,QAAQ,KAAM,EAAE,EAElJA,IAAgB,UAAYA,IAAgB,QAAUA,IAAgB,QAAUA,IAAgB,MAChGJ,EAAgB,gCAAgCI,OAIxDH,EAAgB;AAAA;AAAA;AAAA,uBAGDG,IAAgB,SAAW,IAAIA,KAAiBA;AAAA,sBACjDhB,EAAsB,WAAa;AAAA,OAErD,CAEA,IAAMiB,EAAU;AAAA;AAAA,EAElBjB,EAAsB,iBAAmB;AAAA;AAAA,yCAEFY;AAAA;AAAA;AAAA;AAAA;AAAA,QAKjCC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCJ,OAAON,EAAeI,EAAYM,EAAS,MAAM,CACrD,EAKMC,EAAoB,IAAM,CAC5B,IAAMC,EAAmBd,EAAKJ,EAAa,eAAe,EAE1D,OAAIC,EAAWiB,CAAgB,GAC3B,QAAQ,KAAK,4CAAkC,EAExC,QAAQ,QAAQ,GAGpBZ,EAAeY,EAAkB,GAAI,MAAM,CACtD,GAGC,SAAY,CACT,GAAI,CAEA,MAAM,QAAQ,IAAI,CAACV,EAAc,EAAGS,EAAkB,CAAC,CAAC,EAExD,QAAQ,IAAI,4CAAqC,EAGjD,QAAQ,KAAK,CAAC,CAClB,OAASE,EAAP,CACE,QAAQ,IAAI,kCAA2B,EACvC,QAAQ,MAAMA,CAAK,EAGnB,QAAQ,KAAK,CAAC,CAClB,CACJ,GAAG","sourcesContent":["import { packageIsTypeModule, projectPath } from \"@anolilab/package-json-utils\";\nimport { existsSync, readFileSync, writeFile } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport type { TsConfigJson } from \"type-fest\";\n\nif (process.env[\"CI\"]) {\n // eslint-disable-next-line unicorn/no-process-exit\n process.exit(0);\n}\n\nconst writeFileAsync = promisify(writeFile);\n\nconsole.log(\"Configuring @anolilab/eslint-config\", projectPath, \"\\n\");\n\nconst configFile = \".eslintrc\";\n\n/**\n * Writes .eslintrc.js if it doesn't exist. Warns if it exists.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst writeEslintRc = () => {\n // eslint-disable-next-line no-restricted-syntax\n for (const filename of [configFile, `${configFile}.js`, `${configFile}.cjs`, `${configFile}.json`, `${configFile}.yaml`, `${configFile}.yml`]) {\n if (existsSync(join(projectPath, filename))) {\n console.warn(`⚠️ ${filename} already exists;\nMake sure that it includes the following for @anolilab/eslint-config'\nto work as it should: { extends: [\"@anolilab/eslint-config\"] }.`);\n\n return Promise.resolve();\n }\n }\n\n const eslintPath = join(projectPath, \".eslintrc.js\");\n\n let pluginExtends = \"\";\n let parserOptions = `\n parserOptions: {\n ecmaVersion: \"latest\",\n sourceType: ${packageIsTypeModule ? '\"module\"' : '\"commonjs\"'},\n },`;\n\n const tsconfigPath = join(projectPath, \"tsconfig.json\");\n\n if (existsSync(tsconfigPath)) {\n const tsConfig = JSON.parse(readFileSync(tsconfigPath, \"utf8\")) as TsConfigJson;\n\n let ecmaVersion = \"latest\";\n\n if (tsConfig.compilerOptions?.target) {\n ecmaVersion = tsConfig.compilerOptions.target;\n\n ecmaVersion = ecmaVersion.toLowerCase() === \"es2022\" || ecmaVersion.toLowerCase() === \"esnext\" ? \"latest\" : ecmaVersion.toLowerCase().replace(\"es\", \"\");\n\n if (ecmaVersion !== \"latest\" && ecmaVersion !== \"2022\" && ecmaVersion !== \"2021\" && ecmaVersion !== \"6\") {\n pluginExtends = `, \"plugin:es-x/restrict-to-es${ecmaVersion}\"`;\n }\n }\n\n parserOptions = `\n parserOptions: {\n project: \"./tsconfig.json\",\n ecmaVersion: ${ecmaVersion === \"latest\" ? `\"${ecmaVersion}\"` : ecmaVersion},\n sourceType: ${packageIsTypeModule ? '\"module\"' : '\"commonjs\"'},\n },`;\n }\n\n const content = `/** @ts-check */\n/** @type {import('eslint').Linter.Config} */\n${packageIsTypeModule ? \"export default\" : \"module.exports =\"} {\n root: true,\n extends: [\"@anolilab/eslint-config\"${pluginExtends}],\n ignorePatterns: [\"!**/*\"],\n env: {\n // Your environments (which contains several predefined global variables)\n // Most environments are loaded automatically if our rules are added\n },${parserOptions}\n globals: {\n // Your global variables (setting to false means it's not allowed to be reassigned)\n // myGlobal: false\n },\n rules: {\n // Customize your rules\n },\n overrides: [\n {\n files: [\n \"*.ts\",\n \"*.tsx\",\n \"*.mts\",\n \"*.cts\",\n \"*.js\",\n \"*.jsx\",\n ],\n // Set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting\n parserOptions: {},\n rules: {},\n },\n {\n files: [\"*.ts\", \"*.tsx\", \"*.mts\", \"*.cts\"],\n // Set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting\n parserOptions: {},\n rules: {},\n },\n {\n files: [\"*.js\", \"*.jsx\"],\n rules: {},\n },\n ],\n};\n`;\n\n return writeFileAsync(eslintPath, content, \"utf8\");\n};\n\n/**\n * Writes .eslintignore if it doesn't exist. Warns if it exists.\n */\nconst writeEslintIgnore = () => {\n const eslintIgnorePath = join(projectPath, \".eslintignore\");\n\n if (existsSync(eslintIgnorePath)) {\n console.warn(\"⚠️ .eslintignore already exists\");\n\n return Promise.resolve();\n }\n\n return writeFileAsync(eslintIgnorePath, \"\", \"utf8\");\n};\n\n// eslint-disable-next-line unicorn/prefer-top-level-await\n(async () => {\n try {\n // eslint-disable-next-line compat/compat\n await Promise.all([writeEslintRc(), writeEslintIgnore()]);\n\n console.log(\"😎 Everything went well, have fun!\");\n\n // eslint-disable-next-line unicorn/no-process-exit\n process.exit(0);\n } catch (error) {\n console.log(\"😬 something went wrong:\");\n console.error(error);\n\n // eslint-disable-next-line unicorn/no-process-exit\n process.exit(1);\n }\n})();\n"]}
|
package/dist/postinstall.mjs
CHANGED
|
@@ -3,26 +3,28 @@ import { writeFile, existsSync, readFileSync } from 'fs';
|
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { promisify } from 'util';
|
|
5
5
|
|
|
6
|
-
process.env.CI&&process.exit(0);var
|
|
7
|
-
`);var
|
|
6
|
+
process.env.CI&&process.exit(0);var f=promisify(writeFile);console.log("Configuring @anolilab/eslint-config",projectPath,`
|
|
7
|
+
`);var s=".eslintrc",d=()=>{for(let o of [s,`${s}.js`,`${s}.cjs`,`${s}.json`,`${s}.yaml`,`${s}.yml`])if(existsSync(join(projectPath,o)))return console.warn(`\u26A0\uFE0F ${o} already exists;
|
|
8
|
+
Make sure that it includes the following for @anolilab/eslint-config'
|
|
9
|
+
to work as it should: { extends: ["@anolilab/eslint-config"] }.`),Promise.resolve();let t=join(projectPath,".eslintrc.js"),a="",c=`
|
|
8
10
|
parserOptions: {
|
|
9
11
|
ecmaVersion: "latest",
|
|
10
12
|
sourceType: ${packageIsTypeModule?'"module"':'"commonjs"'},
|
|
11
|
-
},`,
|
|
13
|
+
},`,p=join(projectPath,"tsconfig.json");if(existsSync(p)){let o=JSON.parse(readFileSync(p,"utf8")),e="latest";o.compilerOptions?.target&&(e=o.compilerOptions.target,e=e.toLowerCase()==="es2022"||e.toLowerCase()==="esnext"?"latest":e.toLowerCase().replace("es",""),e!=="latest"&&e!=="2022"&&e!=="2021"&&e!=="6"&&(a=`, "plugin:es-x/restrict-to-es${e}"`)),c=`
|
|
12
14
|
parserOptions: {
|
|
13
15
|
project: "./tsconfig.json",
|
|
14
16
|
ecmaVersion: ${e==="latest"?`"${e}"`:e},
|
|
15
17
|
sourceType: ${packageIsTypeModule?'"module"':'"commonjs"'},
|
|
16
|
-
},`;}let
|
|
18
|
+
},`;}let m=`/** @ts-check */
|
|
17
19
|
/** @type {import('eslint').Linter.Config} */
|
|
18
20
|
${packageIsTypeModule?"export default":"module.exports ="} {
|
|
19
21
|
root: true,
|
|
20
|
-
extends: ["@anolilab/eslint-config"${
|
|
22
|
+
extends: ["@anolilab/eslint-config"${a}],
|
|
21
23
|
ignorePatterns: ["!**/*"],
|
|
22
24
|
env: {
|
|
23
25
|
// Your environments (which contains several predefined global variables)
|
|
24
26
|
// Most environments are loaded automatically if our rules are added
|
|
25
|
-
},${
|
|
27
|
+
},${c}
|
|
26
28
|
globals: {
|
|
27
29
|
// Your global variables (setting to false means it's not allowed to be reassigned)
|
|
28
30
|
// myGlobal: false
|
|
@@ -56,8 +58,6 @@ ${packageIsTypeModule?"export default":"module.exports ="} {
|
|
|
56
58
|
},
|
|
57
59
|
],
|
|
58
60
|
};
|
|
59
|
-
`;return existsSync(t)?(console.warn(
|
|
60
|
-
Make sure that it includes the following for @anolilab/eslint-config'
|
|
61
|
-
to work as it should: { extends: ["@anolilab/eslint-config"] }.`),Promise.resolve()):p(t,f,"utf-8")},d=()=>{let t=join(projectPath,".eslintignore");return existsSync(t)?(console.warn("\u26A0\uFE0F .eslintignore already exists"),Promise.resolve()):p(t,"","utf-8")};(async()=>{try{await Promise.all([h(),d()]),console.log("\u{1F60E} Everything went well, have fun!"),process.exit(0);}catch(t){console.log("\u{1F62C} something went wrong:"),console.error(t),process.exit(1);}})();
|
|
61
|
+
`;return f(t,m,"utf8")},w=()=>{let t=join(projectPath,".eslintignore");return existsSync(t)?(console.warn("\u26A0\uFE0F .eslintignore already exists"),Promise.resolve()):f(t,"","utf8")};(async()=>{try{await Promise.all([d(),w()]),console.log("\u{1F60E} Everything went well, have fun!"),process.exit(0);}catch(t){console.log("\u{1F62C} something went wrong:"),console.error(t),process.exit(1);}})();
|
|
62
62
|
//# sourceMappingURL=out.js.map
|
|
63
63
|
//# sourceMappingURL=postinstall.mjs.map
|
package/dist/postinstall.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/postinstall.ts"],"names":["packageIsTypeModule","projectPath","existsSync","readFileSync","writeFile","join","promisify","writeFileAsync","writeEslintRc","eslintPath","pluginExtends","parserOptions","tsconfigPath","tsConfig","ecmaVersion","content","writeEslintIgnore","eslintIgnorePath","error"],"mappings":"AAAA,OAAS,uBAAAA,EAAqB,eAAAC,MAAmB,+BACjD,OAAS,cAAAC,EAAY,gBAAAC,EAAc,aAAAC,MAAiB,KACpD,OAAS,QAAAC,MAAY,OACrB,OAAS,aAAAC,MAAiB,OAGtB,QAAQ,IAAI,IAEZ,QAAQ,KAAK,CAAC,EAGlB,IAAMC,EAAiBD,EAAUF,CAAS,EAE1C,QAAQ,IAAI,sCAAuCH,EAAa;AAAA,CAAI,
|
|
1
|
+
{"version":3,"sources":["../src/postinstall.ts"],"names":["packageIsTypeModule","projectPath","existsSync","readFileSync","writeFile","join","promisify","writeFileAsync","configFile","writeEslintRc","filename","eslintPath","pluginExtends","parserOptions","tsconfigPath","tsConfig","ecmaVersion","content","writeEslintIgnore","eslintIgnorePath","error"],"mappings":"AAAA,OAAS,uBAAAA,EAAqB,eAAAC,MAAmB,+BACjD,OAAS,cAAAC,EAAY,gBAAAC,EAAc,aAAAC,MAAiB,KACpD,OAAS,QAAAC,MAAY,OACrB,OAAS,aAAAC,MAAiB,OAGtB,QAAQ,IAAI,IAEZ,QAAQ,KAAK,CAAC,EAGlB,IAAMC,EAAiBD,EAAUF,CAAS,EAE1C,QAAQ,IAAI,sCAAuCH,EAAa;AAAA,CAAI,EAEpE,IAAMO,EAAa,YAMbC,EAAgB,IAAM,CAExB,QAAWC,IAAY,CAACF,EAAY,GAAGA,OAAiB,GAAGA,QAAkB,GAAGA,SAAmB,GAAGA,SAAmB,GAAGA,OAAgB,EACxI,GAAIN,EAAWG,EAAKJ,EAAaS,CAAQ,CAAC,EACtC,eAAQ,KAAK,iBAAOA;AAAA;AAAA,gEAEgC,EAE7C,QAAQ,QAAQ,EAI/B,IAAMC,EAAaN,EAAKJ,EAAa,cAAc,EAE/CW,EAAgB,GAChBC,EAAgB;AAAA;AAAA;AAAA,sBAGFb,EAAsB,WAAa;AAAA,QAG/Cc,EAAeT,EAAKJ,EAAa,eAAe,EAEtD,GAAIC,EAAWY,CAAY,EAAG,CAC1B,IAAMC,EAAW,KAAK,MAAMZ,EAAaW,EAAc,MAAM,CAAC,EAE1DE,EAAc,SAEdD,EAAS,iBAAiB,SAC1BC,EAAcD,EAAS,gBAAgB,OAEvCC,EAAcA,EAAY,YAAY,IAAM,UAAYA,EAAY,YAAY,IAAM,SAAW,SAAWA,EAAY,YAAY,EAAE,QAAQ,KAAM,EAAE,EAElJA,IAAgB,UAAYA,IAAgB,QAAUA,IAAgB,QAAUA,IAAgB,MAChGJ,EAAgB,gCAAgCI,OAIxDH,EAAgB;AAAA;AAAA;AAAA,uBAGDG,IAAgB,SAAW,IAAIA,KAAiBA;AAAA,sBACjDhB,EAAsB,WAAa;AAAA,OAErD,CAEA,IAAMiB,EAAU;AAAA;AAAA,EAElBjB,EAAsB,iBAAmB;AAAA;AAAA,yCAEFY;AAAA;AAAA;AAAA;AAAA;AAAA,QAKjCC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoCJ,OAAON,EAAeI,EAAYM,EAAS,MAAM,CACrD,EAKMC,EAAoB,IAAM,CAC5B,IAAMC,EAAmBd,EAAKJ,EAAa,eAAe,EAE1D,OAAIC,EAAWiB,CAAgB,GAC3B,QAAQ,KAAK,4CAAkC,EAExC,QAAQ,QAAQ,GAGpBZ,EAAeY,EAAkB,GAAI,MAAM,CACtD,GAGC,SAAY,CACT,GAAI,CAEA,MAAM,QAAQ,IAAI,CAACV,EAAc,EAAGS,EAAkB,CAAC,CAAC,EAExD,QAAQ,IAAI,4CAAqC,EAGjD,QAAQ,KAAK,CAAC,CAClB,OAASE,EAAP,CACE,QAAQ,IAAI,kCAA2B,EACvC,QAAQ,MAAMA,CAAK,EAGnB,QAAQ,KAAK,CAAC,CAClB,CACJ,GAAG","sourcesContent":["import { packageIsTypeModule, projectPath } from \"@anolilab/package-json-utils\";\nimport { existsSync, readFileSync, writeFile } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport type { TsConfigJson } from \"type-fest\";\n\nif (process.env[\"CI\"]) {\n // eslint-disable-next-line unicorn/no-process-exit\n process.exit(0);\n}\n\nconst writeFileAsync = promisify(writeFile);\n\nconsole.log(\"Configuring @anolilab/eslint-config\", projectPath, \"\\n\");\n\nconst configFile = \".eslintrc\";\n\n/**\n * Writes .eslintrc.js if it doesn't exist. Warns if it exists.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst writeEslintRc = () => {\n // eslint-disable-next-line no-restricted-syntax\n for (const filename of [configFile, `${configFile}.js`, `${configFile}.cjs`, `${configFile}.json`, `${configFile}.yaml`, `${configFile}.yml`]) {\n if (existsSync(join(projectPath, filename))) {\n console.warn(`⚠️ ${filename} already exists;\nMake sure that it includes the following for @anolilab/eslint-config'\nto work as it should: { extends: [\"@anolilab/eslint-config\"] }.`);\n\n return Promise.resolve();\n }\n }\n\n const eslintPath = join(projectPath, \".eslintrc.js\");\n\n let pluginExtends = \"\";\n let parserOptions = `\n parserOptions: {\n ecmaVersion: \"latest\",\n sourceType: ${packageIsTypeModule ? '\"module\"' : '\"commonjs\"'},\n },`;\n\n const tsconfigPath = join(projectPath, \"tsconfig.json\");\n\n if (existsSync(tsconfigPath)) {\n const tsConfig = JSON.parse(readFileSync(tsconfigPath, \"utf8\")) as TsConfigJson;\n\n let ecmaVersion = \"latest\";\n\n if (tsConfig.compilerOptions?.target) {\n ecmaVersion = tsConfig.compilerOptions.target;\n\n ecmaVersion = ecmaVersion.toLowerCase() === \"es2022\" || ecmaVersion.toLowerCase() === \"esnext\" ? \"latest\" : ecmaVersion.toLowerCase().replace(\"es\", \"\");\n\n if (ecmaVersion !== \"latest\" && ecmaVersion !== \"2022\" && ecmaVersion !== \"2021\" && ecmaVersion !== \"6\") {\n pluginExtends = `, \"plugin:es-x/restrict-to-es${ecmaVersion}\"`;\n }\n }\n\n parserOptions = `\n parserOptions: {\n project: \"./tsconfig.json\",\n ecmaVersion: ${ecmaVersion === \"latest\" ? `\"${ecmaVersion}\"` : ecmaVersion},\n sourceType: ${packageIsTypeModule ? '\"module\"' : '\"commonjs\"'},\n },`;\n }\n\n const content = `/** @ts-check */\n/** @type {import('eslint').Linter.Config} */\n${packageIsTypeModule ? \"export default\" : \"module.exports =\"} {\n root: true,\n extends: [\"@anolilab/eslint-config\"${pluginExtends}],\n ignorePatterns: [\"!**/*\"],\n env: {\n // Your environments (which contains several predefined global variables)\n // Most environments are loaded automatically if our rules are added\n },${parserOptions}\n globals: {\n // Your global variables (setting to false means it's not allowed to be reassigned)\n // myGlobal: false\n },\n rules: {\n // Customize your rules\n },\n overrides: [\n {\n files: [\n \"*.ts\",\n \"*.tsx\",\n \"*.mts\",\n \"*.cts\",\n \"*.js\",\n \"*.jsx\",\n ],\n // Set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting\n parserOptions: {},\n rules: {},\n },\n {\n files: [\"*.ts\", \"*.tsx\", \"*.mts\", \"*.cts\"],\n // Set parserOptions.project for the project to allow TypeScript to create the type-checker behind the scenes when we run linting\n parserOptions: {},\n rules: {},\n },\n {\n files: [\"*.js\", \"*.jsx\"],\n rules: {},\n },\n ],\n};\n`;\n\n return writeFileAsync(eslintPath, content, \"utf8\");\n};\n\n/**\n * Writes .eslintignore if it doesn't exist. Warns if it exists.\n */\nconst writeEslintIgnore = () => {\n const eslintIgnorePath = join(projectPath, \".eslintignore\");\n\n if (existsSync(eslintIgnorePath)) {\n console.warn(\"⚠️ .eslintignore already exists\");\n\n return Promise.resolve();\n }\n\n return writeFileAsync(eslintIgnorePath, \"\", \"utf8\");\n};\n\n// eslint-disable-next-line unicorn/prefer-top-level-await\n(async () => {\n try {\n // eslint-disable-next-line compat/compat\n await Promise.all([writeEslintRc(), writeEslintIgnore()]);\n\n console.log(\"😎 Everything went well, have fun!\");\n\n // eslint-disable-next-line unicorn/no-process-exit\n process.exit(0);\n } catch (error) {\n console.log(\"😬 something went wrong:\");\n console.error(error);\n\n // eslint-disable-next-line unicorn/no-process-exit\n process.exit(1);\n }\n})();\n"]}
|