@ttoss/config 1.37.9 → 1.37.11
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/README.md +139 -3
- package/bin/sort-package-json +47 -0
- package/dist/esm/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +15 -11
- package/tsconfig.json +2 -2
package/README.md
CHANGED
|
@@ -12,13 +12,29 @@ pnpm add -Dw @ttoss/config
|
|
|
12
12
|
|
|
13
13
|
Use the configs of this section on the root of your monorepo.
|
|
14
14
|
|
|
15
|
+
### Quick Setup (Recommended)
|
|
16
|
+
|
|
17
|
+
The easiest way to set up all monorepo configurations at once is using the `@ttoss/monorepo` command:
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
pnpm add -Dw @ttoss/monorepo
|
|
21
|
+
npx @ttoss/monorepo setup-monorepo
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
This command will automatically create all configuration files and install all necessary dependencies for ESLint, Prettier, Husky, commitlint, lint-staged, Lerna, Syncpack, and pnpm workspace.
|
|
25
|
+
|
|
26
|
+
For more details, see [@ttoss/monorepo documentation](https://github.com/ttoss/ttoss/tree/main/packages/monorepo).
|
|
27
|
+
|
|
28
|
+
### Manual Setup
|
|
29
|
+
|
|
30
|
+
Alternatively, you can set up each tool manually:
|
|
31
|
+
|
|
15
32
|
### ESLint and Prettier
|
|
16
33
|
|
|
17
34
|
Install the following packages:
|
|
18
35
|
|
|
19
36
|
```shell
|
|
20
|
-
pnpm add -Dw eslint prettier @ttoss/eslint-config
|
|
21
|
-
|
|
37
|
+
pnpm add -Dw eslint prettier @ttoss/eslint-config @ttoss/config
|
|
22
38
|
```
|
|
23
39
|
|
|
24
40
|
Create the `.prettierrc.js` file and add the following configuration:
|
|
@@ -63,13 +79,133 @@ const { lintstagedConfig } = require('@ttoss/config');
|
|
|
63
79
|
module.exports = lintstagedConfig();
|
|
64
80
|
```
|
|
65
81
|
|
|
82
|
+
The default config runs ESLint on JS/TS files, Prettier on Markdown/JSON/YAML, and automatically sorts `package.json` keys using [sort-package-json](https://github.com/nicolo-ribaudo/sort-package-json). No additional packages needed.
|
|
83
|
+
|
|
66
84
|
Finally, configure Husky:
|
|
67
85
|
|
|
68
86
|
```shell
|
|
69
87
|
npm set-script prepare "husky install"
|
|
70
88
|
pnpm run prepare
|
|
71
89
|
pnpm husky add .husky/commit-msg "pnpm commitlint --edit"
|
|
72
|
-
pnpm husky add .husky/pre-commit "pnpm lint-staged"
|
|
90
|
+
pnpm husky add .husky/pre-commit "pnpm lint-staged && pnpm syncpack:list"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Lerna (optional)
|
|
94
|
+
|
|
95
|
+
[Lerna](https://lerna.js.org/) helps manage versioning and publishing of packages in a monorepo.
|
|
96
|
+
|
|
97
|
+
Install lerna-lite packages:
|
|
98
|
+
|
|
99
|
+
```shell
|
|
100
|
+
pnpm add -Dw @lerna-lite/cli @lerna-lite/version @lerna-lite/changed @lerna-lite/list
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Create the `lerna.json` file and configure it according to your monorepo structure:
|
|
104
|
+
|
|
105
|
+
```json title="lerna.json"
|
|
106
|
+
{
|
|
107
|
+
"$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
|
|
108
|
+
"version": "independent",
|
|
109
|
+
"npmClient": "pnpm",
|
|
110
|
+
"stream": true,
|
|
111
|
+
"command": {
|
|
112
|
+
"publish": {
|
|
113
|
+
"allowBranch": "main",
|
|
114
|
+
"noPrivate": true
|
|
115
|
+
},
|
|
116
|
+
"version": {
|
|
117
|
+
"conventionalCommits": true,
|
|
118
|
+
"createRelease": "github",
|
|
119
|
+
"message": "chore(release): publish packages",
|
|
120
|
+
"syncWorkspaceLock": true,
|
|
121
|
+
"allowPeerDependenciesUpdate": true
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"ignoreChanges": ["**/__fixtures__/**", "**/tests/**"],
|
|
125
|
+
"packages": ["packages/*"]
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Syncpack (optional)
|
|
130
|
+
|
|
131
|
+
[Syncpack](https://jamiemason.github.io/syncpack/) ensures consistent versions of dependencies across all packages in your monorepo.
|
|
132
|
+
|
|
133
|
+
Install syncpack:
|
|
134
|
+
|
|
135
|
+
```shell
|
|
136
|
+
pnpm add -Dw syncpack
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Create the `.syncpackrc.js` file:
|
|
140
|
+
|
|
141
|
+
```js title=".syncpackrc.js"
|
|
142
|
+
const { syncpackConfig } = require('@ttoss/config');
|
|
143
|
+
|
|
144
|
+
module.exports = syncpackConfig();
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Add syncpack scripts to your root `package.json`:
|
|
148
|
+
|
|
149
|
+
```json title="package.json"
|
|
150
|
+
{
|
|
151
|
+
"scripts": {
|
|
152
|
+
"syncpack:fix": "syncpack fix-mismatches",
|
|
153
|
+
"syncpack:list": "syncpack list-mismatches"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### pnpm workspace (required for pnpm monorepos)
|
|
159
|
+
|
|
160
|
+
Create a `pnpm-workspace.yaml` file to define which directories contain packages:
|
|
161
|
+
|
|
162
|
+
```yaml title="pnpm-workspace.yaml"
|
|
163
|
+
packages:
|
|
164
|
+
- 'packages/*'
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Adjust the `packages` array to match your monorepo structure. For example:
|
|
168
|
+
|
|
169
|
+
```yaml title="pnpm-workspace.yaml"
|
|
170
|
+
packages:
|
|
171
|
+
- 'packages/*'
|
|
172
|
+
- 'examples/*'
|
|
173
|
+
- 'apps/*'
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### .gitignore (recommended)
|
|
177
|
+
|
|
178
|
+
Create a `.gitignore` file in the monorepo root to exclude common build artifacts and dependencies:
|
|
179
|
+
|
|
180
|
+
```gitignore title=".gitignore"
|
|
181
|
+
node_modules/
|
|
182
|
+
dist/
|
|
183
|
+
build/
|
|
184
|
+
.build/
|
|
185
|
+
coverage/
|
|
186
|
+
*.log
|
|
187
|
+
.env
|
|
188
|
+
.env.test
|
|
189
|
+
.cache/
|
|
190
|
+
.turbo
|
|
191
|
+
**/i18n/compiled/
|
|
192
|
+
**/i18n/missing/
|
|
193
|
+
**/i18n/unused/
|
|
194
|
+
tsup.config.bundled*.mjs
|
|
195
|
+
package-lock.json
|
|
196
|
+
yarn.lock
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### .npmrc (recommended for pnpm)
|
|
200
|
+
|
|
201
|
+
Create an `.npmrc` file to configure pnpm behavior:
|
|
202
|
+
|
|
203
|
+
```ini title=".npmrc"
|
|
204
|
+
enable-pre-post-scripts=true
|
|
205
|
+
engine-strict=true
|
|
206
|
+
public-hoist-pattern[]=*eslint*
|
|
207
|
+
public-hoist-pattern[]=*prettier*
|
|
208
|
+
public-hoist-pattern[]=@types*
|
|
73
209
|
```
|
|
74
210
|
|
|
75
211
|
## Packages
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
|
|
6
|
+
const { sortPackageJson } = require('sort-package-json');
|
|
7
|
+
|
|
8
|
+
const files = process.argv
|
|
9
|
+
.slice(2)
|
|
10
|
+
.filter((filePath) => path.basename(filePath) === 'package.json');
|
|
11
|
+
|
|
12
|
+
if (files.length === 0) {
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const failedFiles = [];
|
|
17
|
+
|
|
18
|
+
for (const filePath of files) {
|
|
19
|
+
try {
|
|
20
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
21
|
+
const packageJson = JSON.parse(fileContent);
|
|
22
|
+
const sortedPackageJson = sortPackageJson(packageJson);
|
|
23
|
+
const nextContent = `${JSON.stringify(sortedPackageJson, null, 2)}\n`;
|
|
24
|
+
|
|
25
|
+
if (fileContent !== nextContent) {
|
|
26
|
+
fs.writeFileSync(filePath, nextContent);
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
failedFiles.push({
|
|
30
|
+
error,
|
|
31
|
+
filePath,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (failedFiles.length > 0) {
|
|
37
|
+
for (const failedFile of failedFiles) {
|
|
38
|
+
const message =
|
|
39
|
+
failedFile.error instanceof Error
|
|
40
|
+
? failedFile.error.message
|
|
41
|
+
: String(failedFile.error);
|
|
42
|
+
|
|
43
|
+
console.error(`Failed to sort ${failedFile.filePath}: ${message}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -133,7 +133,7 @@ var jestUnitConfig = configCreator({
|
|
|
133
133
|
var defaultConfig4 = {
|
|
134
134
|
"*.{js,jsx,ts,tsx}": "eslint --quiet --fix",
|
|
135
135
|
"*.{md,mdx,html,json,yml,yaml}": "prettier --write",
|
|
136
|
-
"package.json": "
|
|
136
|
+
"package.json": "node ./node_modules/@ttoss/config/bin/sort-package-json"
|
|
137
137
|
};
|
|
138
138
|
var lintstagedConfig = configCreator(defaultConfig4);
|
|
139
139
|
|
package/dist/index.js
CHANGED
|
@@ -177,7 +177,7 @@ var jestUnitConfig = configCreator({
|
|
|
177
177
|
var defaultConfig4 = {
|
|
178
178
|
"*.{js,jsx,ts,tsx}": "eslint --quiet --fix",
|
|
179
179
|
"*.{md,mdx,html,json,yml,yaml}": "prettier --write",
|
|
180
|
-
"package.json": "
|
|
180
|
+
"package.json": "node ./node_modules/@ttoss/config/bin/sort-package-json"
|
|
181
181
|
};
|
|
182
182
|
var lintstagedConfig = configCreator(defaultConfig4);
|
|
183
183
|
|
package/package.json
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/config",
|
|
3
|
-
"version": "1.37.
|
|
3
|
+
"version": "1.37.11",
|
|
4
4
|
"description": "Default configuration for packages.",
|
|
5
|
-
"
|
|
6
|
-
"author": "ttoss",
|
|
7
|
-
"contributors": [
|
|
8
|
-
"Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"
|
|
9
|
-
],
|
|
5
|
+
"keywords": [],
|
|
10
6
|
"repository": {
|
|
11
7
|
"type": "git",
|
|
12
8
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
13
9
|
"directory": "packages/config"
|
|
14
10
|
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "ttoss",
|
|
13
|
+
"contributors": [
|
|
14
|
+
"Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
15
17
|
"main": "dist/index.js",
|
|
16
18
|
"module": "dist/esm/index.js",
|
|
19
|
+
"typings": "dist/index.d.ts",
|
|
20
|
+
"bin": {
|
|
21
|
+
"ttoss-sort-package-json": "./bin/sort-package-json"
|
|
22
|
+
},
|
|
17
23
|
"files": [
|
|
24
|
+
"bin",
|
|
18
25
|
"dist",
|
|
19
26
|
"tsconfig.json",
|
|
20
27
|
"tsconfig.test.json"
|
|
21
28
|
],
|
|
22
|
-
"sideEffects": false,
|
|
23
|
-
"typings": "dist/index.d.ts",
|
|
24
29
|
"dependencies": {
|
|
25
30
|
"@babel/core": "^7.29.0",
|
|
26
31
|
"@babel/plugin-proposal-decorators": "^7.29.0",
|
|
@@ -28,12 +33,12 @@
|
|
|
28
33
|
"@babel/preset-react": "^7.28.5",
|
|
29
34
|
"@babel/preset-typescript": "^7.28.5",
|
|
30
35
|
"@commitlint/config-conventional": "^20.5.0",
|
|
31
|
-
"@formatjs/ts-transformer": "^4.4.
|
|
36
|
+
"@formatjs/ts-transformer": "^4.4.8",
|
|
32
37
|
"babel-plugin-formatjs": "^11.3.2",
|
|
33
38
|
"babel-plugin-transform-import-meta": "^2.3.3",
|
|
34
39
|
"deepmerge": "^4.3.1",
|
|
35
40
|
"identity-obj-proxy": "^3.0.0",
|
|
36
|
-
"
|
|
41
|
+
"sort-package-json": "^3.6.1"
|
|
37
42
|
},
|
|
38
43
|
"devDependencies": {
|
|
39
44
|
"@jest/types": "^30.3.0",
|
|
@@ -43,7 +48,6 @@
|
|
|
43
48
|
"jest": "^30.3.0",
|
|
44
49
|
"tsup": "^8.5.1"
|
|
45
50
|
},
|
|
46
|
-
"keywords": [],
|
|
47
51
|
"publishConfig": {
|
|
48
52
|
"access": "public",
|
|
49
53
|
"provenance": true
|
package/tsconfig.json
CHANGED
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
*/
|
|
23
23
|
"types": ["node"],
|
|
24
24
|
/**
|
|
25
|
-
* `target` to `es2024` because Node.js 24 supports ES2024 features
|
|
26
|
-
*
|
|
25
|
+
* `target` to `es2024` because Node.js 24 supports ES2024 features and
|
|
26
|
+
* esbuild does not yet support `es2025` as a target.
|
|
27
27
|
*/
|
|
28
28
|
"target": "es2024",
|
|
29
29
|
"declaration": true,
|