@regardio/dev 1.11.0 → 1.11.1
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/dist/bin/lint-package.js +20 -8
- package/package.json +2 -2
- package/src/bin/lint-package.ts +23 -8
package/dist/bin/lint-package.js
CHANGED
|
@@ -18,21 +18,24 @@ else {
|
|
|
18
18
|
bin = 'npx sort-package-json';
|
|
19
19
|
}
|
|
20
20
|
const args = process.argv.slice(2);
|
|
21
|
-
const
|
|
21
|
+
const fixMode = args.includes('--fix');
|
|
22
|
+
const files = args.filter((arg) => arg !== '--fix');
|
|
23
|
+
const targets = files.length > 0 ? files : ['package.json'];
|
|
22
24
|
try {
|
|
23
|
-
|
|
25
|
+
const checkFlag = fixMode ? '' : '--check';
|
|
26
|
+
execSync(`${bin} ${checkFlag} ${targets.join(' ')}`.trim(), { stdio: 'inherit' });
|
|
24
27
|
}
|
|
25
28
|
catch {
|
|
26
29
|
process.exit(1);
|
|
27
30
|
}
|
|
28
|
-
function fixExportsOrder(filePath) {
|
|
31
|
+
function fixExportsOrder(filePath, fix) {
|
|
29
32
|
const fullPath = resolve(process.cwd(), filePath);
|
|
30
33
|
if (!existsSync(fullPath))
|
|
31
|
-
return;
|
|
34
|
+
return false;
|
|
32
35
|
const content = readFileSync(fullPath, 'utf-8');
|
|
33
36
|
const pkg = JSON.parse(content);
|
|
34
37
|
if (!pkg.exports || typeof pkg.exports !== 'object')
|
|
35
|
-
return;
|
|
38
|
+
return false;
|
|
36
39
|
let modified = false;
|
|
37
40
|
function reorderConditions(obj) {
|
|
38
41
|
if (typeof obj !== 'object' || obj === null)
|
|
@@ -65,10 +68,19 @@ function fixExportsOrder(filePath) {
|
|
|
65
68
|
return result;
|
|
66
69
|
}
|
|
67
70
|
pkg.exports = reorderConditions(pkg.exports);
|
|
68
|
-
if (modified) {
|
|
71
|
+
if (modified && fix) {
|
|
69
72
|
writeFileSync(fullPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
70
73
|
}
|
|
74
|
+
return modified;
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
let hasExportsIssues = false;
|
|
77
|
+
for (const file of targets) {
|
|
78
|
+
const needsFix = fixExportsOrder(file, fixMode);
|
|
79
|
+
if (needsFix && !fixMode) {
|
|
80
|
+
console.error(`${file}: exports condition order is incorrect (types must come before default)`);
|
|
81
|
+
hasExportsIssues = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (hasExportsIssues) {
|
|
85
|
+
process.exit(1);
|
|
74
86
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://www.schemastore.org/package.json",
|
|
3
3
|
"name": "@regardio/dev",
|
|
4
|
-
"version": "1.11.
|
|
4
|
+
"version": "1.11.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Regardio developer tooling for testing, linting, and build workflows",
|
|
7
7
|
"keywords": [
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"npm-run-all": "4.1.5",
|
|
112
112
|
"postcss": "8.5.6",
|
|
113
113
|
"rimraf": "6.1.2",
|
|
114
|
-
"sort-package-json": "3.
|
|
114
|
+
"sort-package-json": "3.6.0",
|
|
115
115
|
"tsx": "4.21.0",
|
|
116
116
|
"typescript": "5.9.3",
|
|
117
117
|
"vite": "7.3.1",
|
package/src/bin/lint-package.ts
CHANGED
|
@@ -26,11 +26,14 @@ if (existsSync(sortPkgBin)) {
|
|
|
26
26
|
|
|
27
27
|
// Get args passed to this script
|
|
28
28
|
const args = process.argv.slice(2);
|
|
29
|
-
const
|
|
29
|
+
const fixMode = args.includes('--fix');
|
|
30
|
+
const files = args.filter((arg) => arg !== '--fix');
|
|
31
|
+
const targets = files.length > 0 ? files : ['package.json'];
|
|
30
32
|
|
|
31
33
|
// Run sort-package-json
|
|
32
34
|
try {
|
|
33
|
-
|
|
35
|
+
const checkFlag = fixMode ? '' : '--check';
|
|
36
|
+
execSync(`${bin} ${checkFlag} ${targets.join(' ')}`.trim(), { stdio: 'inherit' });
|
|
34
37
|
} catch {
|
|
35
38
|
process.exit(1);
|
|
36
39
|
}
|
|
@@ -38,15 +41,16 @@ try {
|
|
|
38
41
|
/**
|
|
39
42
|
* Fix exports condition order: types must come before default for TypeScript.
|
|
40
43
|
* See: https://www.typescriptlang.org/docs/handbook/esm-node.html
|
|
44
|
+
* Returns true if the file needs changes.
|
|
41
45
|
*/
|
|
42
|
-
function fixExportsOrder(filePath: string):
|
|
46
|
+
function fixExportsOrder(filePath: string, fix: boolean): boolean {
|
|
43
47
|
const fullPath = resolve(process.cwd(), filePath);
|
|
44
|
-
if (!existsSync(fullPath)) return;
|
|
48
|
+
if (!existsSync(fullPath)) return false;
|
|
45
49
|
|
|
46
50
|
const content = readFileSync(fullPath, 'utf-8');
|
|
47
51
|
const pkg = JSON.parse(content) as Record<string, unknown>;
|
|
48
52
|
|
|
49
|
-
if (!pkg.exports || typeof pkg.exports !== 'object') return;
|
|
53
|
+
if (!pkg.exports || typeof pkg.exports !== 'object') return false;
|
|
50
54
|
|
|
51
55
|
let modified = false;
|
|
52
56
|
|
|
@@ -88,12 +92,23 @@ function fixExportsOrder(filePath: string): void {
|
|
|
88
92
|
|
|
89
93
|
pkg.exports = reorderConditions(pkg.exports as Record<string, unknown>);
|
|
90
94
|
|
|
91
|
-
if (modified) {
|
|
95
|
+
if (modified && fix) {
|
|
92
96
|
writeFileSync(fullPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
93
97
|
}
|
|
98
|
+
|
|
99
|
+
return modified;
|
|
94
100
|
}
|
|
95
101
|
|
|
96
102
|
// Fix exports order in each file
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
let hasExportsIssues = false;
|
|
104
|
+
for (const file of targets) {
|
|
105
|
+
const needsFix = fixExportsOrder(file, fixMode);
|
|
106
|
+
if (needsFix && !fixMode) {
|
|
107
|
+
console.error(`${file}: exports condition order is incorrect (types must come before default)`);
|
|
108
|
+
hasExportsIssues = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (hasExportsIssues) {
|
|
113
|
+
process.exit(1);
|
|
99
114
|
}
|