Skip to content

Commit 2a59d6e

Browse files
committedJul 5, 2023
fix: Refactor async functions to use async/await and update tsconfig.json
Functions were refactored to use async/await for better readability and maintainability. Also, the tsconfig.json file has been updated throughout various packages to include more test files and configurations, ensuring they are mapped correctly during execution. Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent d091302 commit 2a59d6e

File tree

10 files changed

+43
-51
lines changed

10 files changed

+43
-51
lines changed
 

‎.eslintrc.js

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
const config = require("./packages/eslint-config");
1+
const config = require("./packages/eslint-config/dist");
2+
const globals = require("./packages/eslint-config/dist/globals");
23

34
module.exports = {
45
...config,
5-
env: {
6-
// Your environments (which contains several predefined global variables)
7-
browser: true,
8-
commonjs: true,
9-
es6: true,
10-
node: false,
11-
// mocha: true,
12-
// jquery: true
13-
},
6+
extends: [...config.extends, "./packages/eslint-config/dist/typescript-type-checking"],
147
globals: {
15-
// Your global variables (setting to false means it's not allowed to be reassigned)
16-
//
17-
// myGlobal: false
8+
...config?.globals,
9+
...globals.es2021,
1810
},
1911
overrides: [
12+
...config.overrides,
2013
{
21-
files: ["*.ts", "*.mts", "*.cts", "*.tsx"],
14+
files: ["*.ts", "*.mts", "*.cts", "*.tsx", ".mdx"],
2215
parserOptions: {
23-
project: "./tsconfig.json",
24-
16+
project: true,
2517
tsconfigRootDir: __dirname,
2618
},
2719
},
2820
],
29-
plugins: [],
3021
root: true,
3122
rules: {
23+
...config.rules,
3224
// Customize your rules
3325
"no-console": "off",
3426
"no-secrets/no-secrets": "off",

‎packages/babel-preset/src/postinstall.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ console.log("Configuring @anolilab/babel-preset", projectPath, "\n");
1515
/**
1616
* Writes babel.config.{c|m}js if it doesn't exist. Warns if it exists.
1717
*/
18-
const writeBabelRc = () => {
18+
const writeBabelRc = async () => {
1919
const babelPath = join(projectPath, "babel.config.js");
2020
const content = `${packageIsTypeModule ? "export default" : "module.exports ="} {
2121
presets: ["@anolilab/babel-preset"]
@@ -28,10 +28,10 @@ const writeBabelRc = () => {
2828
Make sure that it includes the following for @anolilab/babel-preset'
2929
to work as it should: { presets: ["@anolilab/babel-preset"] }.`);
3030

31-
return Promise.resolve();
31+
return;
3232
}
3333

34-
return writeFileAsync(babelPath, content, "utf-8");
34+
await writeFileAsync(babelPath, content, "utf-8");
3535
};
3636

3737
// eslint-disable-next-line unicorn/prefer-top-level-await

‎packages/browserslist-config-anolilab/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"display": "Node 16",
44
"extends": "../../tsconfig.json",
5-
"include": ["src/**/*", "*.d.ts"]
5+
"include": ["./src/**/*", "*.d.ts", "./__tests__/**/*", "./vitest.config.ts"]
66
}

‎packages/commitlint-config/src/postinstall.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ console.log("Configuring @anolilab/commitlint-config", projectPath, "\n");
1515
/**
1616
* Writes commitlint.config.js if it doesn't exist. Warns if it exists.
1717
*/
18-
const writeCommitLintConfig = () => {
18+
const writeCommitLintConfig = async () => {
1919
const commitlintPath = join(projectPath, "commitlint.config.js");
2020

2121
// eslint-disable-next-line security/detect-non-literal-fs-filename
2222
if (existsSync(commitlintPath)) {
2323
console.warn("⚠️ commitlint.config.js already exists;");
2424

25-
return Promise.resolve();
25+
return;
2626
}
2727

2828
const content = `${packageIsTypeModule ? "export default" : "module.exports ="} {
@@ -35,20 +35,20 @@ const writeCommitLintConfig = () => {
3535
3636
`;
3737

38-
return writeFileAsync(commitlintPath, content, "utf-8");
38+
await writeFileAsync(commitlintPath, content, "utf-8");
3939
};
4040

4141
/**
4242
* Writes .czrc if it doesn't exist. Warns if it exists.
4343
*/
44-
const writeCzrc = () => {
44+
const writeCzrc = async () => {
4545
const filePath = join(projectPath, ".czrc");
4646

4747
// eslint-disable-next-line security/detect-non-literal-fs-filename
4848
if (existsSync(filePath)) {
4949
console.warn("⚠️ .czrc already exists;");
5050

51-
return Promise.resolve();
51+
return;
5252
}
5353

5454
const content = `{
@@ -57,7 +57,7 @@ const writeCzrc = () => {
5757
5858
`;
5959

60-
return writeFileAsync(filePath, content, "utf-8");
60+
await writeFileAsync(filePath, content, "utf-8");
6161
};
6262

6363
// eslint-disable-next-line unicorn/prefer-top-level-await

‎packages/package-json-utils/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"display": "Node 16",
44
"extends": "../../tsconfig.json",
5-
"include": ["src/**/*", "*.d.ts"]
5+
"include": ["src/**/*", "*.d.ts", "__tests__/**/*", "vitest.config.ts"]
66
}

‎packages/prettier-config/src/postinstall.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const configFile = ".prettierrc";
1919
/**
2020
* Writes .prettierrc.${m|c}js if it doesn't exist. Warns if it exists.
2121
*/
22-
const writePrettierRc = () => {
22+
const writePrettierRc = async () => {
2323
// eslint-disable-next-line no-restricted-syntax
2424
for (const filename of [
2525
configFile,
@@ -39,13 +39,13 @@ const writePrettierRc = () => {
3939
Make sure that it includes the following for @anolilab/prettier-config to work as it should:
4040
${JSON.stringify(content, undefined, 4)}\n`);
4141

42-
return Promise.resolve();
42+
return;
4343
}
4444
}
4545

4646
const prettierPath = join(projectPath, ".prettierrc.js");
4747

48-
return writeFileAsync(
48+
await writeFileAsync(
4949
prettierPath,
5050
`${packageIsTypeModule ? 'import config from "@anolilab/prettier-config";' : 'var config = require("@anolilab/prettier-config");'}
5151
@@ -60,17 +60,17 @@ ${packageIsTypeModule ? "export default" : "module.exports ="} {
6060
/**
6161
* Writes .prettierignore if it doesn't exist. Warns if it exists.
6262
*/
63-
const writePrettierIgnore = () => {
63+
const writePrettierIgnore = async () => {
6464
const prettierPath = join(projectPath, ".prettierignore");
6565

6666
// eslint-disable-next-line security/detect-non-literal-fs-filename
6767
if (existsSync(prettierPath)) {
6868
console.warn("⚠️ .prettierignore already exists");
6969

70-
return Promise.resolve();
70+
return;
7171
}
7272

73-
return writeFileAsync(
73+
await writeFileAsync(
7474
prettierPath,
7575
`${["*.md", "*.sh", "*.yml", "*.svg", "*.gif", "*.log", ".DS_Store", "CNAME", "AUTHORS", "LICENSE", "es/", "lib/", "dist/", "coverage/"].join("\n")}\n`,
7676
"utf8",

‎packages/semantic-release-preset/src/postinstall.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ console.log("Configuring @anolilab/semantic-release-preset", projectPath, "\n");
1515
/**
1616
* Writes .releaserc.json if it doesn't exist. Warns if it exists.
1717
*/
18-
const writeReleaseRc = () => {
18+
const writeReleaseRc = async () => {
1919
if (
2020
pkg &&
2121
(hasDevDependencies(["multi-semantic-release", "@qiwi/multi-semantic-release"]) ||
2222
hasDependencies(["multi-semantic-release", "@qiwi/multi-semantic-release"]))
2323
) {
2424
console.warn("⚠️ found use of multi-semantic-release;");
2525

26-
return Promise.resolve();
26+
return;
2727
}
2828

2929
const releaseRcPath = join(projectPath, ".releaserc.json");
@@ -32,7 +32,7 @@ const writeReleaseRc = () => {
3232
if (existsSync(releaseRcPath)) {
3333
console.warn("⚠️ .releaserc.json already exists;");
3434

35-
return Promise.resolve();
35+
return;
3636
}
3737

3838
const content = `{
@@ -41,7 +41,7 @@ const writeReleaseRc = () => {
4141
4242
`;
4343

44-
return writeFileAsync(releaseRcPath, content, "utf-8");
44+
await writeFileAsync(releaseRcPath, content, "utf-8");
4545
};
4646

4747
// eslint-disable-next-line unicorn/prefer-top-level-await

‎packages/stylelint-config/src/postinstall.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const file = ".stylelintrc";
1717
/**
1818
* Writes .stylelintrc.cjs if it doesn't exist. Warns if it exists.
1919
*/
20-
const writeStylelintRc = () => {
20+
const writeStylelintRc = async () => {
2121
// eslint-disable-next-line no-restricted-syntax
2222
for (const filename of [file, `${file}.js`, `${file}.cjs`, `${file}.json`, `${file}.yaml`, `${file}.yml`, `stylelint.config.js`, `stylelint.config.cjs`]) {
2323
// eslint-disable-next-line security/detect-non-literal-fs-filename
@@ -26,7 +26,7 @@ const writeStylelintRc = () => {
2626
'⚠️ .stylelintrc.js already exists; Make sure that it includes the following for @anolilab/stylelint-config to work as it should: { "extends": ["@anolilab/stylelint-config"] }.',
2727
);
2828

29-
return Promise.resolve();
29+
return;
3030
}
3131
}
3232

@@ -39,13 +39,13 @@ const writeStylelintRc = () => {
3939
4040
`;
4141

42-
return writeFileAsync(stylelintPath, content, "utf-8");
42+
await writeFileAsync(stylelintPath, content, "utf-8");
4343
};
4444

4545
/**
4646
* Writes .stylelintignore if it doesn't exist. Warns if it exists.
4747
*/
48-
const writeStylelintIgnore = () => {
48+
const writeStylelintIgnore = async () => {
4949
const stylelintIgnorePath = join(projectPath, ".stylelintignore");
5050
const content = `package.json
5151
package-lock.json
@@ -58,10 +58,10 @@ node_modules/**
5858
`;
5959
// eslint-disable-next-line security/detect-non-literal-fs-filename
6060
if (existsSync(stylelintIgnorePath)) {
61-
return Promise.resolve();
61+
return;
6262
}
6363

64-
return writeFileAsync(stylelintIgnorePath, content, "utf-8");
64+
await writeFileAsync(stylelintIgnorePath, content, "utf-8");
6565
};
6666

6767
// eslint-disable-next-line unicorn/prefer-top-level-await

‎packages/stylelint-config/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"display": "Node 16",
44
"extends": "../../tsconfig.json",
5-
"include": ["src/**/*", "*.d.ts"]
5+
"include": ["src/**/*", "*.d.ts", "__tests__/**/*", "vitest.config.ts"]
66
}

‎packages/textlint-config/src/postinstall.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ console.log("Configuring @anolilab/textlint-config", projectPath, "\n");
1515
/**
1616
* Writes .textlintrc if it doesn't exist. Warns if it exists.
1717
*/
18-
const writeTextLintRc = () => {
18+
const writeTextLintRc = async () => {
1919
const filePath = join(projectPath, ".textlintrc");
2020
const content = `{
2121
"@textlint/markdown": {
@@ -161,27 +161,27 @@ const writeTextLintRc = () => {
161161
Make sure that it includes the following for @anolilab/textlint-config'
162162
to work as it should: ${content}.`);
163163

164-
return Promise.resolve();
164+
return;
165165
}
166166

167-
return writeFileAsync(filePath, content, "utf-8");
167+
await writeFileAsync(filePath, content, "utf-8");
168168
};
169169

170170
/**
171171
* Writes .textlintignore if it doesn't exist. Warns if it exists.
172172
*/
173-
const writeTextLintIgnore = () => {
173+
const writeTextLintIgnore = async () => {
174174
const filePath = join(projectPath, ".textlintignore");
175175
const content = "";
176176

177177
// eslint-disable-next-line security/detect-non-literal-fs-filename
178178
if (existsSync(filePath)) {
179179
console.warn("⚠️ .textlintignore already exists;");
180180

181-
return Promise.resolve();
181+
return;
182182
}
183183

184-
return writeFileAsync(filePath, content, "utf-8");
184+
await writeFileAsync(filePath, content, "utf-8");
185185
};
186186

187187
// eslint-disable-next-line unicorn/prefer-top-level-await

0 commit comments

Comments
 (0)
Please sign in to comment.