@produck/agent-toolkit 0.8.2 → 0.9.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/README.md +22 -22
- package/bin/agent-toolkit.mjs +33 -8
- package/bin/build-publish-assets.mjs +132 -24
- package/bin/command/enforce-node-baseline/index.mjs +18 -5
- package/bin/command/preflight/index.mjs +20 -4
- package/bin/command/run-capture/index.mjs +7 -1
- package/bin/command/shared/workspace-validation.mjs +9 -3
- package/bin/command/sync-coverage/index.mjs +103 -48
- package/bin/command/sync-coverage/required-c8-config.json +15 -0
- package/bin/command/sync-editorconfig/index.mjs +2 -1
- package/bin/command/sync-format/index.mjs +92 -37
- package/bin/command/sync-git/index.mjs +97 -35
- package/bin/command/sync-install/index.mjs +10 -3
- package/bin/command/sync-instructions/index.mjs +35 -10
- package/bin/command/sync-lint/eslint.config.template.mjs +32 -0
- package/bin/command/sync-lint/index.mjs +63 -32
- package/bin/command/sync-publish/help.txt +4 -2
- package/bin/command/sync-publish/index.mjs +126 -35
- package/bin/command/validate-commit-msg/index.mjs +46 -25
- package/package.json +5 -3
- package/publish-assets/eslint.config.template.mjs +32 -0
- package/publish-assets/gitignore +3 -0
- package/publish-assets/instructions/produck/20-produck-commit.instructions.md +3 -3
- package/publish-assets/instructions/produck/stale.instructions.md +1 -0
- package/publish-assets/instructions/produck/tooling-version-baseline.json +36 -1
- package/publish-assets/lerna.json +14 -0
- package/publish-assets/prettierrc +11 -0
|
@@ -10,8 +10,14 @@ const HELP_FILE = path.resolve(COMMAND_DIR, 'help.txt');
|
|
|
10
10
|
const PACKAGE_ROOT = path.resolve(COMMAND_DIR, '../../..');
|
|
11
11
|
const REPO_ROOT = path.resolve(PACKAGE_ROOT, '../..');
|
|
12
12
|
const TOOLING_BASELINE_CANDIDATE_PATHS = [
|
|
13
|
-
path.resolve(
|
|
14
|
-
|
|
13
|
+
path.resolve(
|
|
14
|
+
REPO_ROOT,
|
|
15
|
+
'.github/distribution/produck/tooling-version-baseline.json',
|
|
16
|
+
),
|
|
17
|
+
path.resolve(
|
|
18
|
+
PACKAGE_ROOT,
|
|
19
|
+
'publish-assets/instructions/produck/tooling-version-baseline.json',
|
|
20
|
+
),
|
|
15
21
|
];
|
|
16
22
|
const GLOB_TOKEN_PATTERN = /[*?{}[\]]/;
|
|
17
23
|
const REQUIRED_ROOT_COVERAGE_SCRIPT_KEY = 'produck:coverage';
|
|
@@ -19,23 +25,13 @@ const REQUIRED_ROOT_COVERAGE_SCRIPT_VALUE =
|
|
|
19
25
|
'c8 --config .c8rc.json npm run test --workspaces --if-present';
|
|
20
26
|
const REQUIRED_COVERAGE_SCRIPT_KEY = 'produck:coverage';
|
|
21
27
|
const REQUIRED_TEST_SCRIPT_KEY = 'test';
|
|
22
|
-
const DEFAULT_TEST_SCRIPT_VALUE =
|
|
28
|
+
const DEFAULT_TEST_SCRIPT_VALUE =
|
|
29
|
+
'node -e "console.log(\'No tests configured\')"';
|
|
23
30
|
const REQUIRED_C8_CONFIG_FILE = '.c8rc.json';
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
branches: 99.5,
|
|
29
|
-
exclude: ['**/node_modules/**', '**/coverage/**', '**/dist/**', '**/build/**', '**/out/**'],
|
|
30
|
-
functions: 99.5,
|
|
31
|
-
include: ['src/**', 'extension/**'],
|
|
32
|
-
reporter: ['lcov', 'html', 'text-summary'],
|
|
33
|
-
statements: 99.5,
|
|
34
|
-
lines: 99.5,
|
|
35
|
-
},
|
|
36
|
-
null,
|
|
37
|
-
2,
|
|
38
|
-
)}\n`;
|
|
31
|
+
const REQUIRED_C8_CONFIG_TEMPLATE_FILE = path.resolve(
|
|
32
|
+
COMMAND_DIR,
|
|
33
|
+
'required-c8-config.json',
|
|
34
|
+
);
|
|
39
35
|
|
|
40
36
|
export function printSyncCoverageHelp() {
|
|
41
37
|
printTextResource(HELP_FILE);
|
|
@@ -51,12 +47,16 @@ function parseJsonFile(filePath, label) {
|
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
function loadToolingBaseline() {
|
|
54
|
-
const toolingBaselinePath = TOOLING_BASELINE_CANDIDATE_PATHS.find(
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
const toolingBaselinePath = TOOLING_BASELINE_CANDIDATE_PATHS.find(
|
|
51
|
+
(candidatePath) => {
|
|
52
|
+
return fs.existsSync(candidatePath);
|
|
53
|
+
},
|
|
54
|
+
);
|
|
57
55
|
|
|
58
56
|
if (!toolingBaselinePath) {
|
|
59
|
-
console.error(
|
|
57
|
+
console.error(
|
|
58
|
+
'Tooling baseline file does not exist in expected locations:',
|
|
59
|
+
);
|
|
60
60
|
for (const candidatePath of TOOLING_BASELINE_CANDIDATE_PATHS) {
|
|
61
61
|
console.error(`- ${candidatePath}`);
|
|
62
62
|
}
|
|
@@ -65,7 +65,9 @@ function loadToolingBaseline() {
|
|
|
65
65
|
|
|
66
66
|
const baseline = parseJsonFile(toolingBaselinePath, 'Tooling baseline file');
|
|
67
67
|
if (typeof baseline.schemaVersion !== 'number') {
|
|
68
|
-
console.error(
|
|
68
|
+
console.error(
|
|
69
|
+
`Tooling baseline schemaVersion must be a number: ${toolingBaselinePath}`,
|
|
70
|
+
);
|
|
69
71
|
process.exit(2);
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -109,6 +111,21 @@ function readFileIfExists(filePath) {
|
|
|
109
111
|
return fs.readFileSync(filePath, 'utf8');
|
|
110
112
|
}
|
|
111
113
|
|
|
114
|
+
function loadRequiredC8ConfigContent() {
|
|
115
|
+
if (!fs.existsSync(REQUIRED_C8_CONFIG_TEMPLATE_FILE)) {
|
|
116
|
+
console.error(
|
|
117
|
+
`Required c8 config template does not exist: ${REQUIRED_C8_CONFIG_TEMPLATE_FILE}`,
|
|
118
|
+
);
|
|
119
|
+
process.exit(2);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const template = parseJsonFile(
|
|
123
|
+
REQUIRED_C8_CONFIG_TEMPLATE_FILE,
|
|
124
|
+
'Required c8 config template',
|
|
125
|
+
);
|
|
126
|
+
return `${JSON.stringify(template, null, 2)}\n`;
|
|
127
|
+
}
|
|
128
|
+
|
|
112
129
|
function resolveWorkspacePaths(cwd, options) {
|
|
113
130
|
const manual = getMulti(options, '--workspace');
|
|
114
131
|
if (manual.length > 0) {
|
|
@@ -116,11 +133,10 @@ function resolveWorkspacePaths(cwd, options) {
|
|
|
116
133
|
}
|
|
117
134
|
|
|
118
135
|
const rootPackageJsonPath = path.resolve(cwd, 'package.json');
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const rootPackageJson = parseJsonFile(rootPackageJsonPath, 'Root package.json');
|
|
136
|
+
const rootPackageJson = parseJsonFile(
|
|
137
|
+
rootPackageJsonPath,
|
|
138
|
+
'Root package.json',
|
|
139
|
+
);
|
|
124
140
|
if (!Array.isArray(rootPackageJson.workspaces)) {
|
|
125
141
|
return [];
|
|
126
142
|
}
|
|
@@ -132,20 +148,29 @@ function resolveWorkspacePaths(cwd, options) {
|
|
|
132
148
|
|
|
133
149
|
const hasGlob = workspaces.some((entry) => GLOB_TOKEN_PATTERN.test(entry));
|
|
134
150
|
if (hasGlob) {
|
|
135
|
-
console.error(
|
|
151
|
+
console.error(
|
|
152
|
+
'Root package.json `workspaces` must use explicit paths without glob tokens',
|
|
153
|
+
);
|
|
136
154
|
process.exit(2);
|
|
137
155
|
}
|
|
138
156
|
|
|
139
157
|
return workspaces;
|
|
140
158
|
}
|
|
141
159
|
|
|
142
|
-
function syncRootCoverage(
|
|
160
|
+
function syncRootCoverage(
|
|
161
|
+
cwd,
|
|
162
|
+
mode,
|
|
163
|
+
requiredC8Version,
|
|
164
|
+
requiredC8ConfigContent,
|
|
165
|
+
) {
|
|
143
166
|
const rootPackageJsonPath = path.resolve(cwd, 'package.json');
|
|
144
167
|
const c8ConfigPath = path.resolve(cwd, REQUIRED_C8_CONFIG_FILE);
|
|
145
168
|
const currentC8ConfigContent = readFileIfExists(c8ConfigPath);
|
|
146
169
|
const pkg = parseJsonFile(rootPackageJsonPath, 'Root package.json');
|
|
147
170
|
const scripts =
|
|
148
|
-
pkg.scripts &&
|
|
171
|
+
pkg.scripts &&
|
|
172
|
+
typeof pkg.scripts === 'object' &&
|
|
173
|
+
!Array.isArray(pkg.scripts)
|
|
149
174
|
? { ...pkg.scripts }
|
|
150
175
|
: {};
|
|
151
176
|
const devDependencies =
|
|
@@ -162,20 +187,27 @@ function syncRootCoverage(cwd, mode, requiredC8Version) {
|
|
|
162
187
|
typeof devDependencies.c8 === 'string' ? devDependencies.c8 : null;
|
|
163
188
|
const matchesRequiredRootCoverageBefore =
|
|
164
189
|
previousRootCoverageScript === REQUIRED_ROOT_COVERAGE_SCRIPT_VALUE;
|
|
165
|
-
const matchesRequiredC8DevDependencyBefore =
|
|
166
|
-
|
|
190
|
+
const matchesRequiredC8DevDependencyBefore =
|
|
191
|
+
previousC8DevDependency === requiredC8Version;
|
|
192
|
+
const matchesRequiredC8ConfigBefore =
|
|
193
|
+
currentC8ConfigContent === requiredC8ConfigContent;
|
|
167
194
|
const requiresUpdate =
|
|
168
195
|
!matchesRequiredRootCoverageBefore ||
|
|
169
196
|
!matchesRequiredC8DevDependencyBefore ||
|
|
170
197
|
!matchesRequiredC8ConfigBefore;
|
|
171
198
|
|
|
172
199
|
if (mode === 'sync' && requiresUpdate) {
|
|
173
|
-
scripts[REQUIRED_ROOT_COVERAGE_SCRIPT_KEY] =
|
|
200
|
+
scripts[REQUIRED_ROOT_COVERAGE_SCRIPT_KEY] =
|
|
201
|
+
REQUIRED_ROOT_COVERAGE_SCRIPT_VALUE;
|
|
174
202
|
pkg.scripts = scripts;
|
|
175
203
|
devDependencies.c8 = requiredC8Version;
|
|
176
204
|
pkg.devDependencies = devDependencies;
|
|
177
|
-
fs.writeFileSync(
|
|
178
|
-
|
|
205
|
+
fs.writeFileSync(
|
|
206
|
+
rootPackageJsonPath,
|
|
207
|
+
`${JSON.stringify(pkg, null, 2)}\n`,
|
|
208
|
+
'utf8',
|
|
209
|
+
);
|
|
210
|
+
fs.writeFileSync(c8ConfigPath, requiredC8ConfigContent, 'utf8');
|
|
179
211
|
}
|
|
180
212
|
|
|
181
213
|
return {
|
|
@@ -184,7 +216,7 @@ function syncRootCoverage(cwd, mode, requiredC8Version) {
|
|
|
184
216
|
rootCoverageScriptKey: REQUIRED_ROOT_COVERAGE_SCRIPT_KEY,
|
|
185
217
|
rootCoverageScriptValue: REQUIRED_ROOT_COVERAGE_SCRIPT_VALUE,
|
|
186
218
|
c8ConfigFile: REQUIRED_C8_CONFIG_FILE,
|
|
187
|
-
c8ConfigContent:
|
|
219
|
+
c8ConfigContent: requiredC8ConfigContent,
|
|
188
220
|
c8DevDependency: requiredC8Version,
|
|
189
221
|
},
|
|
190
222
|
status: {
|
|
@@ -192,11 +224,17 @@ function syncRootCoverage(cwd, mode, requiredC8Version) {
|
|
|
192
224
|
matchesRequiredC8DevDependencyBefore,
|
|
193
225
|
matchesRequiredC8ConfigBefore,
|
|
194
226
|
matchesRequiredRootCoverageAfter:
|
|
195
|
-
requiresUpdate && mode === 'sync'
|
|
227
|
+
requiresUpdate && mode === 'sync'
|
|
228
|
+
? true
|
|
229
|
+
: matchesRequiredRootCoverageBefore,
|
|
196
230
|
matchesRequiredC8DevDependencyAfter:
|
|
197
|
-
requiresUpdate && mode === 'sync'
|
|
231
|
+
requiresUpdate && mode === 'sync'
|
|
232
|
+
? true
|
|
233
|
+
: matchesRequiredC8DevDependencyBefore,
|
|
198
234
|
matchesRequiredC8ConfigAfter:
|
|
199
|
-
requiresUpdate && mode === 'sync'
|
|
235
|
+
requiresUpdate && mode === 'sync'
|
|
236
|
+
? true
|
|
237
|
+
: matchesRequiredC8ConfigBefore,
|
|
200
238
|
updated: requiresUpdate && mode === 'sync',
|
|
201
239
|
},
|
|
202
240
|
};
|
|
@@ -250,7 +288,9 @@ function reconcileCoverageScript(
|
|
|
250
288
|
}
|
|
251
289
|
|
|
252
290
|
const scripts =
|
|
253
|
-
pkg.scripts &&
|
|
291
|
+
pkg.scripts &&
|
|
292
|
+
typeof pkg.scripts === 'object' &&
|
|
293
|
+
!Array.isArray(pkg.scripts)
|
|
254
294
|
? { ...pkg.scripts }
|
|
255
295
|
: {};
|
|
256
296
|
const devDependencies =
|
|
@@ -274,9 +314,11 @@ function reconcileCoverageScript(
|
|
|
274
314
|
result.previousCoverage = previousCoverage;
|
|
275
315
|
result.previousTestScript = previousTestScript;
|
|
276
316
|
result.previousC8DevDependency = previousC8DevDependency;
|
|
277
|
-
result.matchesRequiredCoverageBefore =
|
|
317
|
+
result.matchesRequiredCoverageBefore =
|
|
318
|
+
previousCoverage === requiredCoverageScript;
|
|
278
319
|
result.hasRequiredTestScriptBefore = previousTestScript !== null;
|
|
279
|
-
result.matchesRequiredC8DevDependencyBefore =
|
|
320
|
+
result.matchesRequiredC8DevDependencyBefore =
|
|
321
|
+
previousC8DevDependency === requiredC8Version;
|
|
280
322
|
|
|
281
323
|
if (
|
|
282
324
|
(!result.matchesRequiredCoverageBefore ||
|
|
@@ -291,7 +333,11 @@ function reconcileCoverageScript(
|
|
|
291
333
|
devDependencies.c8 = requiredC8Version;
|
|
292
334
|
pkg.scripts = scripts;
|
|
293
335
|
pkg.devDependencies = devDependencies;
|
|
294
|
-
fs.writeFileSync(
|
|
336
|
+
fs.writeFileSync(
|
|
337
|
+
packageJsonPath,
|
|
338
|
+
`${JSON.stringify(pkg, null, 2)}\n`,
|
|
339
|
+
'utf8',
|
|
340
|
+
);
|
|
295
341
|
result.updated = true;
|
|
296
342
|
}
|
|
297
343
|
|
|
@@ -308,9 +354,11 @@ function reconcileCoverageScript(
|
|
|
308
354
|
? requiredC8Version
|
|
309
355
|
: previousC8DevDependency;
|
|
310
356
|
|
|
311
|
-
result.matchesRequiredCoverageAfter =
|
|
357
|
+
result.matchesRequiredCoverageAfter =
|
|
358
|
+
result.updated || result.matchesRequiredCoverageBefore;
|
|
312
359
|
result.hasRequiredTestScriptAfter =
|
|
313
|
-
(mode === 'sync' && !result.hasRequiredTestScriptBefore) ||
|
|
360
|
+
(mode === 'sync' && !result.hasRequiredTestScriptBefore) ||
|
|
361
|
+
result.hasRequiredTestScriptBefore;
|
|
314
362
|
result.matchesRequiredC8DevDependencyAfter =
|
|
315
363
|
result.updated || result.matchesRequiredC8DevDependencyBefore;
|
|
316
364
|
return result;
|
|
@@ -321,9 +369,11 @@ export function runSyncCoverage(options) {
|
|
|
321
369
|
const check = hasFlag(options, '--check');
|
|
322
370
|
const dryRun = hasFlag(options, '--dry-run');
|
|
323
371
|
const jsonFile = getSingle(options, '--json', '');
|
|
324
|
-
const { baseline: toolingBaseline, toolingBaselinePath } =
|
|
372
|
+
const { baseline: toolingBaseline, toolingBaselinePath } =
|
|
373
|
+
loadToolingBaseline();
|
|
325
374
|
const requiredCoverageScript = buildRequiredCoverageScript(toolingBaseline);
|
|
326
375
|
const requiredC8Version = buildRequiredC8DevDependency(toolingBaseline);
|
|
376
|
+
const requiredC8ConfigContent = loadRequiredC8ConfigContent();
|
|
327
377
|
|
|
328
378
|
if (!fs.existsSync(cwd)) {
|
|
329
379
|
console.error(`CWD does not exist: ${cwd}`);
|
|
@@ -331,7 +381,12 @@ export function runSyncCoverage(options) {
|
|
|
331
381
|
}
|
|
332
382
|
|
|
333
383
|
const mode = dryRun ? 'dry-run' : check ? 'check' : 'sync';
|
|
334
|
-
const root = syncRootCoverage(
|
|
384
|
+
const root = syncRootCoverage(
|
|
385
|
+
cwd,
|
|
386
|
+
mode,
|
|
387
|
+
requiredC8Version,
|
|
388
|
+
requiredC8ConfigContent,
|
|
389
|
+
);
|
|
335
390
|
const workspacePaths = resolveWorkspacePaths(cwd, options);
|
|
336
391
|
|
|
337
392
|
const report = {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"check-coverage": true,
|
|
3
|
+
"exclude": [
|
|
4
|
+
"**/node_modules/**",
|
|
5
|
+
"**/coverage/**",
|
|
6
|
+
"**/dist/**",
|
|
7
|
+
"**/build/**",
|
|
8
|
+
"**/out/**"
|
|
9
|
+
],
|
|
10
|
+
"reporter": ["lcov", "html", "text-summary"],
|
|
11
|
+
"branches": 99.5,
|
|
12
|
+
"functions": 99.5,
|
|
13
|
+
"statements": 99.5,
|
|
14
|
+
"lines": 99.5
|
|
15
|
+
}
|
|
@@ -39,7 +39,8 @@ export function runSyncEditorconfig(options) {
|
|
|
39
39
|
const editorconfigPath = path.resolve(cwd, EDITORCONFIG_FILE);
|
|
40
40
|
const currentContent = readFileIfExists(editorconfigPath);
|
|
41
41
|
const fileExists = currentContent !== null;
|
|
42
|
-
const upToDate =
|
|
42
|
+
const upToDate =
|
|
43
|
+
fileExists && currentContent === REQUIRED_EDITORCONFIG_CONTENT;
|
|
43
44
|
|
|
44
45
|
const mismatches = [];
|
|
45
46
|
if (!upToDate) {
|
|
@@ -10,13 +10,23 @@ const HELP_FILE = path.resolve(COMMAND_DIR, 'help.txt');
|
|
|
10
10
|
const PACKAGE_ROOT = path.resolve(COMMAND_DIR, '../../..');
|
|
11
11
|
const REPO_ROOT = path.resolve(PACKAGE_ROOT, '../..');
|
|
12
12
|
const TOOLING_BASELINE_CANDIDATE_PATHS = [
|
|
13
|
-
path.resolve(
|
|
14
|
-
|
|
13
|
+
path.resolve(
|
|
14
|
+
REPO_ROOT,
|
|
15
|
+
'.github/distribution/produck/tooling-version-baseline.json',
|
|
16
|
+
),
|
|
17
|
+
path.resolve(
|
|
18
|
+
PACKAGE_ROOT,
|
|
19
|
+
'publish-assets/instructions/produck/tooling-version-baseline.json',
|
|
20
|
+
),
|
|
15
21
|
];
|
|
16
22
|
const PRETTIER_CONFIG_FILE = '.prettierrc';
|
|
17
23
|
const PRETTIER_IGNORE_FILE = '.prettierignore';
|
|
18
24
|
const REQUIRED_PRETTIER_DEV_DEPENDENCY_KEY = 'prettier';
|
|
19
25
|
|
|
26
|
+
const PRETTIER_CONFIG_SOURCE_CANDIDATE_PATHS = [
|
|
27
|
+
path.resolve(REPO_ROOT, '.prettierrc'),
|
|
28
|
+
path.resolve(PACKAGE_ROOT, 'publish-assets/prettierrc'),
|
|
29
|
+
];
|
|
20
30
|
const PRETTIER_IGNORE_SOURCE_CANDIDATE_PATHS = [
|
|
21
31
|
path.resolve(REPO_ROOT, '.prettierignore'),
|
|
22
32
|
path.resolve(PACKAGE_ROOT, 'publish-assets/prettierignore'),
|
|
@@ -25,26 +35,37 @@ const PRETTIER_IGNORE_SOURCE_CANDIDATE_PATHS = [
|
|
|
25
35
|
const REQUIRED_FORMAT_SCRIPT_KEY = 'produck:format';
|
|
26
36
|
const REQUIRED_FORMAT_SCRIPT_VALUE =
|
|
27
37
|
'prettier --write . --ignore-path .prettierignore --ignore-path .gitignore';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
|
|
39
|
+
function loadPrettierConfigContent() {
|
|
40
|
+
const sourcePath = PRETTIER_CONFIG_SOURCE_CANDIDATE_PATHS.find((p) =>
|
|
41
|
+
fs.existsSync(p),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (!sourcePath) {
|
|
45
|
+
console.error('Org .prettierrc source not found in expected locations:');
|
|
46
|
+
for (const p of PRETTIER_CONFIG_SOURCE_CANDIDATE_PATHS) {
|
|
47
|
+
console.error(`- ${p}`);
|
|
48
|
+
}
|
|
49
|
+
process.exit(2);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const parsed = parseJsonFile(sourcePath, '.prettierrc source');
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
sourcePath,
|
|
56
|
+
content: `${JSON.stringify(parsed, null, 2)}\n`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
42
59
|
|
|
43
60
|
function loadPrettierIgnoreContent() {
|
|
44
|
-
const sourcePath = PRETTIER_IGNORE_SOURCE_CANDIDATE_PATHS.find((p) =>
|
|
61
|
+
const sourcePath = PRETTIER_IGNORE_SOURCE_CANDIDATE_PATHS.find((p) =>
|
|
62
|
+
fs.existsSync(p),
|
|
63
|
+
);
|
|
45
64
|
|
|
46
65
|
if (!sourcePath) {
|
|
47
|
-
console.error(
|
|
66
|
+
console.error(
|
|
67
|
+
'Org .prettierignore source not found in expected locations:',
|
|
68
|
+
);
|
|
48
69
|
for (const p of PRETTIER_IGNORE_SOURCE_CANDIDATE_PATHS) {
|
|
49
70
|
console.error(`- ${p}`);
|
|
50
71
|
}
|
|
@@ -79,12 +100,16 @@ function parseJsonFile(filePath, label) {
|
|
|
79
100
|
}
|
|
80
101
|
|
|
81
102
|
function loadToolingBaseline() {
|
|
82
|
-
const toolingBaselinePath = TOOLING_BASELINE_CANDIDATE_PATHS.find(
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
const toolingBaselinePath = TOOLING_BASELINE_CANDIDATE_PATHS.find(
|
|
104
|
+
(candidatePath) => {
|
|
105
|
+
return fs.existsSync(candidatePath);
|
|
106
|
+
},
|
|
107
|
+
);
|
|
85
108
|
|
|
86
109
|
if (!toolingBaselinePath) {
|
|
87
|
-
console.error(
|
|
110
|
+
console.error(
|
|
111
|
+
'Tooling baseline file does not exist in expected locations:',
|
|
112
|
+
);
|
|
88
113
|
for (const candidatePath of TOOLING_BASELINE_CANDIDATE_PATHS) {
|
|
89
114
|
console.error(`- ${candidatePath}`);
|
|
90
115
|
}
|
|
@@ -92,7 +117,9 @@ function loadToolingBaseline() {
|
|
|
92
117
|
}
|
|
93
118
|
|
|
94
119
|
const baseline = parseJsonFile(toolingBaselinePath, 'Tooling baseline file');
|
|
95
|
-
const prettierVersion = String(
|
|
120
|
+
const prettierVersion = String(
|
|
121
|
+
baseline?.tools?.prettier?.version || '',
|
|
122
|
+
).trim();
|
|
96
123
|
|
|
97
124
|
if (!prettierVersion) {
|
|
98
125
|
console.error(
|
|
@@ -125,10 +152,18 @@ export function runSyncFormat(options) {
|
|
|
125
152
|
const pkg = parseJsonFile(rootPackageJsonPath, 'Root package.json');
|
|
126
153
|
const toolingBaseline = loadToolingBaseline();
|
|
127
154
|
const requiredPrettierVersion = toolingBaseline.prettierVersion;
|
|
128
|
-
const {
|
|
129
|
-
|
|
155
|
+
const {
|
|
156
|
+
sourcePath: prettierConfigSourcePath,
|
|
157
|
+
content: requiredPrettierConfigContent,
|
|
158
|
+
} = loadPrettierConfigContent();
|
|
159
|
+
const {
|
|
160
|
+
sourcePath: prettierIgnoreSourcePath,
|
|
161
|
+
content: REQUIRED_PRETTIER_IGNORE_CONTENT,
|
|
162
|
+
} = loadPrettierIgnoreContent();
|
|
130
163
|
const scripts =
|
|
131
|
-
pkg.scripts &&
|
|
164
|
+
pkg.scripts &&
|
|
165
|
+
typeof pkg.scripts === 'object' &&
|
|
166
|
+
!Array.isArray(pkg.scripts)
|
|
132
167
|
? { ...pkg.scripts }
|
|
133
168
|
: {};
|
|
134
169
|
const devDependencies =
|
|
@@ -153,9 +188,12 @@ export function runSyncFormat(options) {
|
|
|
153
188
|
const previousPrettierIgnore = readFileIfExists(prettierIgnorePath);
|
|
154
189
|
|
|
155
190
|
const matchesRequiredFormat = previousFormat === REQUIRED_FORMAT_SCRIPT_VALUE;
|
|
156
|
-
const matchesRequiredPrettierConfig =
|
|
157
|
-
|
|
158
|
-
const
|
|
191
|
+
const matchesRequiredPrettierConfig =
|
|
192
|
+
previousPrettierConfig === requiredPrettierConfigContent;
|
|
193
|
+
const matchesRequiredPrettierDep =
|
|
194
|
+
previousPrettierDep === requiredPrettierVersion;
|
|
195
|
+
const matchesRequiredPrettierIgnore =
|
|
196
|
+
previousPrettierIgnore === REQUIRED_PRETTIER_IGNORE_CONTENT;
|
|
159
197
|
|
|
160
198
|
const requiresUpdate =
|
|
161
199
|
!matchesRequiredFormat ||
|
|
@@ -167,12 +205,21 @@ export function runSyncFormat(options) {
|
|
|
167
205
|
scripts[REQUIRED_FORMAT_SCRIPT_KEY] = REQUIRED_FORMAT_SCRIPT_VALUE;
|
|
168
206
|
pkg.scripts = scripts;
|
|
169
207
|
|
|
170
|
-
devDependencies[REQUIRED_PRETTIER_DEV_DEPENDENCY_KEY] =
|
|
208
|
+
devDependencies[REQUIRED_PRETTIER_DEV_DEPENDENCY_KEY] =
|
|
209
|
+
requiredPrettierVersion;
|
|
171
210
|
pkg.devDependencies = devDependencies;
|
|
172
211
|
|
|
173
|
-
fs.writeFileSync(
|
|
174
|
-
|
|
175
|
-
|
|
212
|
+
fs.writeFileSync(
|
|
213
|
+
rootPackageJsonPath,
|
|
214
|
+
`${JSON.stringify(pkg, null, 2)}\n`,
|
|
215
|
+
'utf8',
|
|
216
|
+
);
|
|
217
|
+
fs.writeFileSync(prettierConfigPath, requiredPrettierConfigContent, 'utf8');
|
|
218
|
+
fs.writeFileSync(
|
|
219
|
+
prettierIgnorePath,
|
|
220
|
+
REQUIRED_PRETTIER_IGNORE_CONTENT,
|
|
221
|
+
'utf8',
|
|
222
|
+
);
|
|
176
223
|
}
|
|
177
224
|
|
|
178
225
|
const report = {
|
|
@@ -185,22 +232,30 @@ export function runSyncFormat(options) {
|
|
|
185
232
|
formatScriptKey: REQUIRED_FORMAT_SCRIPT_KEY,
|
|
186
233
|
formatScriptValue: REQUIRED_FORMAT_SCRIPT_VALUE,
|
|
187
234
|
prettierConfigPath: path.relative(cwd, prettierConfigPath),
|
|
235
|
+
prettierConfigSourcePath,
|
|
188
236
|
prettierIgnorePath: path.relative(cwd, prettierIgnorePath),
|
|
189
237
|
prettierIgnoreSourcePath,
|
|
190
|
-
managedDevDependencies: {
|
|
238
|
+
managedDevDependencies: {
|
|
239
|
+
[REQUIRED_PRETTIER_DEV_DEPENDENCY_KEY]: requiredPrettierVersion,
|
|
240
|
+
},
|
|
191
241
|
},
|
|
192
242
|
status: {
|
|
193
243
|
matchesRequiredFormatBefore: matchesRequiredFormat,
|
|
194
244
|
matchesRequiredPrettierConfigBefore: matchesRequiredPrettierConfig,
|
|
195
245
|
matchesRequiredPrettierDepBefore: matchesRequiredPrettierDep,
|
|
196
246
|
matchesRequiredPrettierIgnoreBefore: matchesRequiredPrettierIgnore,
|
|
197
|
-
matchesRequiredFormatAfter:
|
|
247
|
+
matchesRequiredFormatAfter:
|
|
248
|
+
requiresUpdate && mode === 'sync' ? true : matchesRequiredFormat,
|
|
198
249
|
matchesRequiredPrettierConfigAfter:
|
|
199
|
-
requiresUpdate && mode === 'sync'
|
|
250
|
+
requiresUpdate && mode === 'sync'
|
|
251
|
+
? true
|
|
252
|
+
: matchesRequiredPrettierConfig,
|
|
200
253
|
matchesRequiredPrettierDepAfter:
|
|
201
254
|
requiresUpdate && mode === 'sync' ? true : matchesRequiredPrettierDep,
|
|
202
255
|
matchesRequiredPrettierIgnoreAfter:
|
|
203
|
-
requiresUpdate && mode === 'sync'
|
|
256
|
+
requiresUpdate && mode === 'sync'
|
|
257
|
+
? true
|
|
258
|
+
: matchesRequiredPrettierIgnore,
|
|
204
259
|
updated: requiresUpdate && mode === 'sync',
|
|
205
260
|
},
|
|
206
261
|
};
|