@aws/nx-plugin 1.0.0-rc.66 → 1.0.0-rc.68
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/migrations.json +11 -1
- package/package.json +1 -1
- package/src/migrations/latest/smithy-server-package-rename/metadata.json +3 -0
- package/src/migrations/latest/smithy-server-package-rename/migration.d.ts +6 -0
- package/src/migrations/latest/smithy-server-package-rename/migration.js +123 -0
- package/src/migrations/latest/smithy-server-package-rename/migration.js.map +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/build-system-prompt.ts.fixture +23 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/build-user-prompt.ts.fixture +96 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/config-path.ts.fixture +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/file-to-translate.ts.fixture +10 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/get-files-to-translate.ts.fixture +96 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/header.ts.fixture +15 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/log.ts.fixture +18 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/main-call.ts.fixture +6 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/main.ts.fixture +79 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/project-root.ts.fixture +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/run-with-concurrency.ts.fixture +57 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/scripts-dir.ts.fixture +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/files/translate-file-for-language.ts.fixture +61 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/already-migrated.grit +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/build-system-prompt.grit +6 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/build-user-prompt.grit +6 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/config-path.grit +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/file-to-translate.grit +11 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/get-files-to-translate.grit +7 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/log.grit +3 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/main-call.grit +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/main.grit +8 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/project-root.grit +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/run-with-concurrency.grit +6 -0
- package/src/migrations/latest/translate-script-whole-file-writes/grit/translate-file-for-language.grit +6 -0
- package/src/migrations/latest/translate-script-whole-file-writes/metadata.json +3 -0
- package/src/migrations/latest/translate-script-whole-file-writes/migration.d.ts +2 -0
- package/src/migrations/latest/translate-script-whole-file-writes/migration.js +103 -0
- package/src/migrations/latest/translate-script-whole-file-writes/migration.js.map +1 -0
- package/src/migrations/latest/translate-script-whole-file-writes/test-fixtures/released-script-first.ts.fixture +430 -0
- package/src/migrations/latest/translate-script-whole-file-writes/test-fixtures/released-script.ts.fixture +431 -0
- package/src/py/agent/a2a-connection/generator.d.ts +1 -1
- package/src/py/agent/gateway-connection/generator.d.ts +1 -1
- package/src/py/agent/mcp-connection/generator.d.ts +1 -1
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +3 -3
- package/src/smithy/ts/api/files/handler.ts.template +1 -1
- package/src/smithy/ts/api/files/local-server.ts.template +1 -1
- package/src/smithy/ts/api/generator.d.ts +2 -2
- package/src/smithy/ts/api/generator.js +2 -2
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +269 -148
- package/src/ts/rdb/smithy-connection/__snapshots__/generator.spec.ts.snap +6 -6
- package/src/utils/versions.d.ts +3 -3
- package/src/utils/versions.js +3 -3
- package/src/utils/versions.js.map +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
async function translateFileForLanguage(
|
|
2
|
+
file: FileToTranslate,
|
|
3
|
+
targetLang: string,
|
|
4
|
+
): Promise<void> {
|
|
5
|
+
const targetAbsPath = path.join(DOCS_DIR, targetLang, file.relativePath);
|
|
6
|
+
|
|
7
|
+
let lastError: unknown;
|
|
8
|
+
for (let attempt = 1; attempt <= TRANSLATE_MAX_ATTEMPTS; attempt++) {
|
|
9
|
+
const agent = new Agent({
|
|
10
|
+
model: new BedrockModel({
|
|
11
|
+
modelId: config.modelId,
|
|
12
|
+
region: process.env.AWS_REGION ?? config.awsRegion,
|
|
13
|
+
maxTokens: 64_000,
|
|
14
|
+
temperature: 0.2,
|
|
15
|
+
// Translating a long file can stream for several minutes, well past the
|
|
16
|
+
// AWS SDK's two-minute default socket timeout.
|
|
17
|
+
clientConfig: { requestHandler: { requestTimeout: 15 * 60_000 } },
|
|
18
|
+
}),
|
|
19
|
+
systemPrompt: buildSystemPrompt(targetLang),
|
|
20
|
+
tools: [fileEditor],
|
|
21
|
+
printer: !!options.verbose,
|
|
22
|
+
});
|
|
23
|
+
agent.addHook(BeforeToolCallEvent, rejectOutsideDocsDir);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const result = await agent.invoke(buildUserPrompt(file, targetLang));
|
|
27
|
+
if (result.stopReason !== 'endTurn') {
|
|
28
|
+
log.warn(
|
|
29
|
+
`agent stopped with reason=${result.stopReason} while translating ${file.relativePath} → ${targetLang} — inspect output above`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
lastError = undefined;
|
|
33
|
+
} catch (err) {
|
|
34
|
+
lastError = err;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Judge the file on disk rather than on whether the agent wrote it: the
|
|
38
|
+
// stream often drops after a successful write, and an agent handed an
|
|
39
|
+
// already-correct translation may rightly decide there is nothing to do.
|
|
40
|
+
if (fs.existsSync(targetAbsPath)) {
|
|
41
|
+
try {
|
|
42
|
+
assertFrontmatterIsParseable(await fs.readFile(targetAbsPath, 'utf-8'));
|
|
43
|
+
await restoreCodeBlocks(file.sourceAbsPath, targetAbsPath);
|
|
44
|
+
return;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
lastError = err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
lastError ??= new Error('no translation exists at the target path');
|
|
50
|
+
|
|
51
|
+
if (attempt < TRANSLATE_MAX_ATTEMPTS) {
|
|
52
|
+
const delayMs = 2000 * attempt;
|
|
53
|
+
log.warn(
|
|
54
|
+
`translation attempt ${attempt}/${TRANSLATE_MAX_ATTEMPTS} for ${file.relativePath} → ${targetLang} failed (${lastError instanceof Error ? lastError.message : String(lastError)}); retrying in ${delayMs}ms`,
|
|
55
|
+
);
|
|
56
|
+
await sleep(delayMs);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
throw lastError;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function_declaration($name) where { $name <: `restoreCodeBlocks` }
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function_declaration($name, $body) as $decl where {
|
|
2
|
+
$name <: `buildUserPrompt`,
|
|
3
|
+
$body <: contains `const targetLangRoot = path.join(DOCS_DIR, targetLang)`,
|
|
4
|
+
$body <: contains `const existingTranslationExists = fs.existsSync(targetAbsPath)`,
|
|
5
|
+
$decl => `__GRIT_INSERT_PLACEHOLDER__`
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
`const CONFIG_PATH = path.resolve($dir, 'translate.config.json');` => `__GRIT_INSERT_PLACEHOLDER__`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface_declaration($name, $body) as $decl where {
|
|
2
|
+
$name <: `FileToTranslate`,
|
|
3
|
+
$body <: contains `relativePath: string`,
|
|
4
|
+
$body <: contains `sourceAbsPath: string`,
|
|
5
|
+
$body <: contains `sourceContent: string`,
|
|
6
|
+
$body <: contains `diff: string`,
|
|
7
|
+
$body <: not contains property_signature(name = $field) where {
|
|
8
|
+
$field <: not or { `relativePath`, `sourceAbsPath`, `sourceContent`, `diff` }
|
|
9
|
+
},
|
|
10
|
+
$decl => `__GRIT_INSERT_PLACEHOLDER__`
|
|
11
|
+
}
|
package/src/migrations/latest/translate-script-whole-file-writes/grit/get-files-to-translate.grit
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
function_declaration($name, $body) as $decl where {
|
|
2
|
+
$name <: `getFilesToTranslate`,
|
|
3
|
+
$body <: contains `const { files: uncommitted } = await git.status()`,
|
|
4
|
+
$body <: contains `const includedSet = new Set(includedGlob.map((p) => path.resolve(p)))`,
|
|
5
|
+
$body <: contains `const changed = allCandidates.filter((abs) => includedSet.has(abs))`,
|
|
6
|
+
$decl => `__GRIT_INSERT_PLACEHOLDER__`
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
`main().catch($handler);` => `__GRIT_INSERT_PLACEHOLDER__`
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
function_declaration($name, $body) as $decl where {
|
|
2
|
+
$name <: `main`,
|
|
3
|
+
$body <: contains `log.error('No target languages configured')`,
|
|
4
|
+
$body <: contains `log.info('Nothing to translate.')`,
|
|
5
|
+
$body <: contains `log.info('Done.')`,
|
|
6
|
+
$body <: contains `await runWithConcurrency(tasks, concurrency)`,
|
|
7
|
+
$decl => `__GRIT_INSERT_PLACEHOLDER__`
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
`const PROJECT_ROOT = path.resolve($dir, '..');` => `__GRIT_INSERT_PLACEHOLDER__`
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function_declaration($name, $body) as $decl where {
|
|
2
|
+
$name <: `translateFileForLanguage`,
|
|
3
|
+
$body <: contains `agent.addHook(BeforeToolCallEvent, rejectOutsideDocsDir)`,
|
|
4
|
+
$body <: contains `const result = await agent.invoke(buildUserPrompt(file, targetLang))`,
|
|
5
|
+
$decl => `__GRIT_INSERT_PLACEHOLDER__`
|
|
6
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { readFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { getProjects, joinPathFragments } from "@nx/devkit";
|
|
7
|
+
import { TS_ASTRO_DOCS_GENERATOR_INFO } from "../../../ts/astro-docs/generator.js";
|
|
8
|
+
import { insertViaGritQL, matchGritQL } from "../../../utils/ast.js";
|
|
9
|
+
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
10
|
+
import { isEsmWorkspace } from "../../../utils/module-format.js";
|
|
11
|
+
import { getPackageManagerDisplayCommands } from "../../../utils/pkg-manager.js";
|
|
12
|
+
/**
|
|
13
|
+
* Rewrite the docs translate script so it writes whole translated files.
|
|
14
|
+
*
|
|
15
|
+
* The script used to tell the agent to update an existing translation with
|
|
16
|
+
* `str_replace` edits. A replacement that did not match cleanly duplicated or
|
|
17
|
+
* spliced sections, and nothing checked the result, so the damage was committed.
|
|
18
|
+
* The rewrite also fixes incremental runs, which never matched a changed file in
|
|
19
|
+
* a generated workspace, and raises the Bedrock socket timeout that made every
|
|
20
|
+
* large file fail.
|
|
21
|
+
*
|
|
22
|
+
* Most of the script changed, so it is rewritten a declaration at a time. Each
|
|
23
|
+
* pattern in `grit/` matches one declaration as a previous release wrote it and
|
|
24
|
+
* rewrites it to a placeholder, which `insertViaGritQL` swaps for today's version
|
|
25
|
+
* from `files/`. Routing the replacement through a placeholder keeps it out of the
|
|
26
|
+
* pattern: the script is full of template literals, and a GritQL snippet
|
|
27
|
+
* containing a backtick cannot be parsed.
|
|
28
|
+
*
|
|
29
|
+
* Each pattern recognises its declaration by name *and* by statements the released
|
|
30
|
+
* body contained, so a declaration the user has edited no longer matches. The
|
|
31
|
+
* rewrite is all or nothing — every pattern must match before anything is written
|
|
32
|
+
* — so an edited script keeps its whole file and is reported through `nextSteps`
|
|
33
|
+
* rather than being half-rewritten from two different versions.
|
|
34
|
+
*/ /**
|
|
35
|
+
* The declarations that changed, in the order they appear in the script. Each name
|
|
36
|
+
* pairs a `grit/<name>.grit` pattern matching its previous form with a
|
|
37
|
+
* `files/<name>.ts.fixture` holding its replacement, which carries any new
|
|
38
|
+
* declarations that follow it.
|
|
39
|
+
*
|
|
40
|
+
* `grit/already-migrated.grit` stands apart: it recognises today's script rather
|
|
41
|
+
* than rewriting anything.
|
|
42
|
+
*/ const REWRITES = [
|
|
43
|
+
'project-root',
|
|
44
|
+
'config-path',
|
|
45
|
+
'file-to-translate',
|
|
46
|
+
'log',
|
|
47
|
+
'get-files-to-translate',
|
|
48
|
+
'build-system-prompt',
|
|
49
|
+
'build-user-prompt',
|
|
50
|
+
'translate-file-for-language',
|
|
51
|
+
'run-with-concurrency',
|
|
52
|
+
'main',
|
|
53
|
+
'main-call'
|
|
54
|
+
];
|
|
55
|
+
/** A leading block comment, which GritQL does not match. */ const HEADER_COMMENT = /^\/\*\*[\s\S]*?\*\/\n/;
|
|
56
|
+
const readGritPattern = (name)=>`language js\n${readFileSync(join(import.meta.dirname, 'grit', `${name}.grit`), 'utf-8').trim()}`;
|
|
57
|
+
const readReplacement = (name)=>readFileSync(join(import.meta.dirname, 'files', `${name}.ts.fixture`), 'utf-8');
|
|
58
|
+
/** Fills in the values the generator interpolates when it vends the script. */ const render = (tree, source, fullyQualifiedName)=>source.replace(/<% if \(esm\) \{ %>(.*?)<% \} else \{ %>(.*?)<% \} %>/g, isEsmWorkspace(tree) ? '$1' : '$2').replace(/<%= pkgMgrCmd %>/g, getPackageManagerDisplayCommands().exec).replace(/<%= fullyQualifiedName %>/g, fullyQualifiedName);
|
|
59
|
+
const editedNextStep = (projectName)=>`${projectName}: its scripts/translate.ts has been customised, so it was left as it is. The script now writes each translation as a whole file rather than editing it in place — see https://awslabs.github.io/nx-plugin-for-aws/guides/astro-docs/ for the version it expects.`;
|
|
60
|
+
export default async function migration(tree) {
|
|
61
|
+
const nextSteps = [];
|
|
62
|
+
for (const [name, project] of getProjects(tree)){
|
|
63
|
+
const metadata = project.metadata;
|
|
64
|
+
if (metadata?.generator !== TS_ASTRO_DOCS_GENERATOR_INFO.id) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
// Absent when the docs site was generated with --noTranslation.
|
|
68
|
+
const scriptPath = joinPathFragments(project.root, 'scripts', 'translate.ts');
|
|
69
|
+
if (!tree.exists(scriptPath)) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Already migrated: matched by a declaration only today's script has, so a
|
|
73
|
+
// second run is a no-op rather than a rewrite.
|
|
74
|
+
if (await matchGritQL(tree, scriptPath, readGritPattern('already-migrated'))) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// All or nothing: every declaration must still be the one a release vended,
|
|
78
|
+
// so a partly edited script is never left half-rewritten.
|
|
79
|
+
const matches = await Promise.all(REWRITES.map((rewrite)=>matchGritQL(tree, scriptPath, readGritPattern(rewrite))));
|
|
80
|
+
if (!matches.every(Boolean)) {
|
|
81
|
+
nextSteps.push(editedNextStep(name));
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// The header is a leading comment, which GritQL does not reach. Anchored to
|
|
85
|
+
// the start of the file so the replacement cannot match anything else.
|
|
86
|
+
tree.write(scriptPath, (tree.read(scriptPath, 'utf-8') ?? '').replace(HEADER_COMMENT, render(tree, readReplacement('header'), name)));
|
|
87
|
+
// The first release resolved paths from `__dirname` directly, with no
|
|
88
|
+
// `SCRIPTS_DIR` for the rewrites below to build on.
|
|
89
|
+
const script = tree.read(scriptPath, 'utf-8') ?? '';
|
|
90
|
+
if (!/^const SCRIPTS_DIR /m.test(script)) {
|
|
91
|
+
tree.write(scriptPath, script.replace(/^const PROJECT_ROOT /m, `${render(tree, readReplacement('scripts-dir'), name).trimEnd()}\nconst PROJECT_ROOT `));
|
|
92
|
+
}
|
|
93
|
+
for (const rewrite of REWRITES){
|
|
94
|
+
await insertViaGritQL(tree, scriptPath, readGritPattern(rewrite), render(tree, readReplacement(rewrite), name).trimEnd());
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
await formatFilesInSubtree(tree);
|
|
98
|
+
return {
|
|
99
|
+
nextSteps
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/migrations/latest/translate-script-whole-file-writes/migration.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport {\n getProjects,\n joinPathFragments,\n type MigrationReturnObject,\n type Tree,\n} from '@nx/devkit';\nimport { TS_ASTRO_DOCS_GENERATOR_INFO } from '../../../ts/astro-docs/generator';\nimport { insertViaGritQL, matchGritQL } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { isEsmWorkspace } from '../../../utils/module-format';\nimport { getPackageManagerDisplayCommands } from '../../../utils/pkg-manager';\n\n/**\n * Rewrite the docs translate script so it writes whole translated files.\n *\n * The script used to tell the agent to update an existing translation with\n * `str_replace` edits. A replacement that did not match cleanly duplicated or\n * spliced sections, and nothing checked the result, so the damage was committed.\n * The rewrite also fixes incremental runs, which never matched a changed file in\n * a generated workspace, and raises the Bedrock socket timeout that made every\n * large file fail.\n *\n * Most of the script changed, so it is rewritten a declaration at a time. Each\n * pattern in `grit/` matches one declaration as a previous release wrote it and\n * rewrites it to a placeholder, which `insertViaGritQL` swaps for today's version\n * from `files/`. Routing the replacement through a placeholder keeps it out of the\n * pattern: the script is full of template literals, and a GritQL snippet\n * containing a backtick cannot be parsed.\n *\n * Each pattern recognises its declaration by name *and* by statements the released\n * body contained, so a declaration the user has edited no longer matches. The\n * rewrite is all or nothing — every pattern must match before anything is written\n * — so an edited script keeps its whole file and is reported through `nextSteps`\n * rather than being half-rewritten from two different versions.\n */\n\n/**\n * The declarations that changed, in the order they appear in the script. Each name\n * pairs a `grit/<name>.grit` pattern matching its previous form with a\n * `files/<name>.ts.fixture` holding its replacement, which carries any new\n * declarations that follow it.\n *\n * `grit/already-migrated.grit` stands apart: it recognises today's script rather\n * than rewriting anything.\n */\nconst REWRITES = [\n 'project-root',\n 'config-path',\n 'file-to-translate',\n 'log',\n 'get-files-to-translate',\n 'build-system-prompt',\n 'build-user-prompt',\n 'translate-file-for-language',\n 'run-with-concurrency',\n 'main',\n 'main-call',\n] as const;\n\n/** A leading block comment, which GritQL does not match. */\nconst HEADER_COMMENT = /^\\/\\*\\*[\\s\\S]*?\\*\\/\\n/;\n\nconst readGritPattern = (name: string): string =>\n `language js\\n${readFileSync(join(import.meta.dirname, 'grit', `${name}.grit`), 'utf-8').trim()}`;\n\nconst readReplacement = (name: string): string =>\n readFileSync(\n join(import.meta.dirname, 'files', `${name}.ts.fixture`),\n 'utf-8',\n );\n\n/** Fills in the values the generator interpolates when it vends the script. */\nconst render = (\n tree: Tree,\n source: string,\n fullyQualifiedName: string,\n): string =>\n source\n .replace(\n /<% if \\(esm\\) \\{ %>(.*?)<% \\} else \\{ %>(.*?)<% \\} %>/g,\n isEsmWorkspace(tree) ? '$1' : '$2',\n )\n .replace(/<%= pkgMgrCmd %>/g, getPackageManagerDisplayCommands().exec)\n .replace(/<%= fullyQualifiedName %>/g, fullyQualifiedName);\n\nconst editedNextStep = (projectName: string): string =>\n `${projectName}: its scripts/translate.ts has been customised, so it was left as it is. The script now writes each translation as a whole file rather than editing it in place — see https://awslabs.github.io/nx-plugin-for-aws/guides/astro-docs/ for the version it expects.`;\n\nexport default async function migration(\n tree: Tree,\n): Promise<MigrationReturnObject> {\n const nextSteps: string[] = [];\n\n for (const [name, project] of getProjects(tree)) {\n const metadata = project.metadata as { generator?: string } | undefined;\n if (metadata?.generator !== TS_ASTRO_DOCS_GENERATOR_INFO.id) {\n continue;\n }\n\n // Absent when the docs site was generated with --noTranslation.\n const scriptPath = joinPathFragments(\n project.root,\n 'scripts',\n 'translate.ts',\n );\n if (!tree.exists(scriptPath)) {\n continue;\n }\n\n // Already migrated: matched by a declaration only today's script has, so a\n // second run is a no-op rather than a rewrite.\n if (\n await matchGritQL(tree, scriptPath, readGritPattern('already-migrated'))\n ) {\n continue;\n }\n\n // All or nothing: every declaration must still be the one a release vended,\n // so a partly edited script is never left half-rewritten.\n const matches = await Promise.all(\n REWRITES.map((rewrite) =>\n matchGritQL(tree, scriptPath, readGritPattern(rewrite)),\n ),\n );\n if (!matches.every(Boolean)) {\n nextSteps.push(editedNextStep(name));\n continue;\n }\n\n // The header is a leading comment, which GritQL does not reach. Anchored to\n // the start of the file so the replacement cannot match anything else.\n tree.write(\n scriptPath,\n (tree.read(scriptPath, 'utf-8') ?? '').replace(\n HEADER_COMMENT,\n render(tree, readReplacement('header'), name),\n ),\n );\n\n // The first release resolved paths from `__dirname` directly, with no\n // `SCRIPTS_DIR` for the rewrites below to build on.\n const script = tree.read(scriptPath, 'utf-8') ?? '';\n if (!/^const SCRIPTS_DIR /m.test(script)) {\n tree.write(\n scriptPath,\n script.replace(\n /^const PROJECT_ROOT /m,\n `${render(tree, readReplacement('scripts-dir'), name).trimEnd()}\\nconst PROJECT_ROOT `,\n ),\n );\n }\n\n for (const rewrite of REWRITES) {\n await insertViaGritQL(\n tree,\n scriptPath,\n readGritPattern(rewrite),\n render(tree, readReplacement(rewrite), name).trimEnd(),\n );\n }\n }\n\n await formatFilesInSubtree(tree);\n\n return { nextSteps };\n}\n"],"names":["readFileSync","join","getProjects","joinPathFragments","TS_ASTRO_DOCS_GENERATOR_INFO","insertViaGritQL","matchGritQL","formatFilesInSubtree","isEsmWorkspace","getPackageManagerDisplayCommands","REWRITES","HEADER_COMMENT","readGritPattern","name","dirname","trim","readReplacement","render","tree","source","fullyQualifiedName","replace","exec","editedNextStep","projectName","migration","nextSteps","project","metadata","generator","id","scriptPath","root","exists","matches","Promise","all","map","rewrite","every","Boolean","push","write","read","script","test","trimEnd"],"mappings":"AAAA;;;CAGC,GACD,SAASA,YAAY,QAAQ,UAAU;AACvC,SAASC,IAAI,QAAQ,YAAY;AACjC,SACEC,WAAW,EACXC,iBAAiB,QAGZ,aAAa;AACpB,SAASC,4BAA4B,QAAQ,sCAAmC;AAChF,SAASC,eAAe,EAAEC,WAAW,QAAQ,wBAAqB;AAClE,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,cAAc,QAAQ,kCAA+B;AAC9D,SAASC,gCAAgC,QAAQ,gCAA6B;AAE9E;;;;;;;;;;;;;;;;;;;;;;CAsBC,GAED;;;;;;;;CAQC,GACD,MAAMC,WAAW;IACf;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,0DAA0D,GAC1D,MAAMC,iBAAiB;AAEvB,MAAMC,kBAAkB,CAACC,OACvB,CAAC,aAAa,EAAEb,aAAaC,KAAK,YAAYa,OAAO,EAAE,QAAQ,GAAGD,KAAK,KAAK,CAAC,GAAG,SAASE,IAAI,IAAI;AAEnG,MAAMC,kBAAkB,CAACH,OACvBb,aACEC,KAAK,YAAYa,OAAO,EAAE,SAAS,GAAGD,KAAK,WAAW,CAAC,GACvD;AAGJ,6EAA6E,GAC7E,MAAMI,SAAS,CACbC,MACAC,QACAC,qBAEAD,OACGE,OAAO,CACN,0DACAb,eAAeU,QAAQ,OAAO,MAE/BG,OAAO,CAAC,qBAAqBZ,mCAAmCa,IAAI,EACpED,OAAO,CAAC,8BAA8BD;AAE3C,MAAMG,iBAAiB,CAACC,cACtB,GAAGA,YAAY,gQAAgQ,CAAC;AAElR,eAAe,eAAeC,UAC5BP,IAAU;IAEV,MAAMQ,YAAsB,EAAE;IAE9B,KAAK,MAAM,CAACb,MAAMc,QAAQ,IAAIzB,YAAYgB,MAAO;QAC/C,MAAMU,WAAWD,QAAQC,QAAQ;QACjC,IAAIA,UAAUC,cAAczB,6BAA6B0B,EAAE,EAAE;YAC3D;QACF;QAEA,gEAAgE;QAChE,MAAMC,aAAa5B,kBACjBwB,QAAQK,IAAI,EACZ,WACA;QAEF,IAAI,CAACd,KAAKe,MAAM,CAACF,aAAa;YAC5B;QACF;QAEA,2EAA2E;QAC3E,+CAA+C;QAC/C,IACE,MAAMzB,YAAYY,MAAMa,YAAYnB,gBAAgB,sBACpD;YACA;QACF;QAEA,4EAA4E;QAC5E,0DAA0D;QAC1D,MAAMsB,UAAU,MAAMC,QAAQC,GAAG,CAC/B1B,SAAS2B,GAAG,CAAC,CAACC,UACZhC,YAAYY,MAAMa,YAAYnB,gBAAgB0B;QAGlD,IAAI,CAACJ,QAAQK,KAAK,CAACC,UAAU;YAC3Bd,UAAUe,IAAI,CAAClB,eAAeV;YAC9B;QACF;QAEA,4EAA4E;QAC5E,uEAAuE;QACvEK,KAAKwB,KAAK,CACRX,YACA,AAACb,CAAAA,KAAKyB,IAAI,CAACZ,YAAY,YAAY,EAAC,EAAGV,OAAO,CAC5CV,gBACAM,OAAOC,MAAMF,gBAAgB,WAAWH;QAI5C,sEAAsE;QACtE,oDAAoD;QACpD,MAAM+B,SAAS1B,KAAKyB,IAAI,CAACZ,YAAY,YAAY;QACjD,IAAI,CAAC,uBAAuBc,IAAI,CAACD,SAAS;YACxC1B,KAAKwB,KAAK,CACRX,YACAa,OAAOvB,OAAO,CACZ,yBACA,GAAGJ,OAAOC,MAAMF,gBAAgB,gBAAgBH,MAAMiC,OAAO,GAAG,qBAAqB,CAAC;QAG5F;QAEA,KAAK,MAAMR,WAAW5B,SAAU;YAC9B,MAAML,gBACJa,MACAa,YACAnB,gBAAgB0B,UAChBrB,OAAOC,MAAMF,gBAAgBsB,UAAUzB,MAAMiC,OAAO;QAExD;IACF;IAEA,MAAMvC,qBAAqBW;IAE3B,OAAO;QAAEQ;IAAU;AACrB"}
|