@aws/nx-plugin 1.0.0-rc.48 → 1.0.0-rc.49
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/LICENSE-THIRD-PARTY +15 -0
- package/generators.json +7 -0
- package/migrations.json +5 -0
- package/package.json +4 -1
- package/src/mcp-server/guide-pipeline.js +1 -1
- package/src/mcp-server/guide-pipeline.js.map +1 -1
- package/src/mcp-server/server.js +2 -0
- package/src/mcp-server/server.js.map +1 -1
- package/src/mcp-server/tools/general-guidance.d.ts +1 -1
- package/src/mcp-server/tools/general-guidance.js +1 -0
- package/src/mcp-server/tools/general-guidance.js.map +1 -1
- package/src/mcp-server/tools/upgrade-workspace.d.ts +11 -0
- package/src/mcp-server/tools/upgrade-workspace.js +32 -0
- package/src/mcp-server/tools/upgrade-workspace.js.map +1 -0
- package/src/preset/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/sdk/ts.d.ts +4 -2
- package/src/sdk/ts.js +4 -2
- package/src/sdk/ts.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +2 -1
- package/src/ts/agent/a2a-connection/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/ts/agent/files/ag-ui/index.ts.template +25 -9
- package/src/ts/agent/files/common/agent.ts.template +2 -1
- package/src/ts/agent/gateway-connection/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/ts/agent/mcp-connection/__snapshots__/generator.spec.ts.snap +1 -0
- package/src/ts/nx-migration/files/migration.spec.ts.template +26 -0
- package/src/ts/nx-migration/files/migration.ts.template +55 -0
- package/src/ts/nx-migration/files/prompt.md.template +46 -0
- package/src/ts/nx-migration/generator.d.ts +24 -0
- package/src/ts/nx-migration/generator.js +122 -0
- package/src/ts/nx-migration/generator.js.map +1 -0
- package/src/ts/nx-migration/schema.d.js +6 -0
- package/src/ts/nx-migration/schema.d.js.map +1 -0
- package/src/ts/nx-migration/schema.d.ts +13 -0
- package/src/ts/nx-migration/schema.json +63 -0
- package/src/ts/nx-plugin/utils.d.ts +21 -1
- package/src/ts/nx-plugin/utils.js +43 -29
- package/src/ts/nx-plugin/utils.js.map +1 -1
- package/src/utils/agent-connection/agent-connection.js +4 -0
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-connection/files/core-strands/base/tool-errors-strands.ts.template +22 -0
- package/src/utils/commands.d.ts +4 -3
- package/src/utils/commands.js +6 -2
- package/src/utils/commands.js.map +1 -1
- package/src/utils/migration-versions.d.ts +95 -0
- package/src/utils/migration-versions.js +128 -0
- package/src/utils/migration-versions.js.map +1 -0
- package/src/utils/nx.d.ts +5 -0
- package/src/utils/nx.js +1 -1
- package/src/utils/nx.js.map +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type MigrationReturnObject, type Tree } from '@nx/devkit';
|
|
2
|
+
import { formatFilesInSubtree } from '<%- formatImportPath %>';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <%= description %>
|
|
6
|
+
<%_ if (isHybrid) { _%>
|
|
7
|
+
*
|
|
8
|
+
* Hybrid migration: this codemod does the mechanical part, then the paired
|
|
9
|
+
* prompt (prompt.md) hands off to the user's agent for the rest.
|
|
10
|
+
*
|
|
11
|
+
* How to write a migration:
|
|
12
|
+
* - https://nx.dev/docs/kb/migration-generators
|
|
13
|
+
* - `nextSteps` and `agentContext`: https://nx.dev/docs/reference/devkit/MigrationReturnObject
|
|
14
|
+
*
|
|
15
|
+
* Guardrails:
|
|
16
|
+
* - Pattern-match before writing: skip files that have diverged from the shape
|
|
17
|
+
* your generators produce, and report them via `agentContext` so the prompt
|
|
18
|
+
* can pick them up, rather than clobbering the user's changes.
|
|
19
|
+
* - Idempotent: re-running must be a no-op.
|
|
20
|
+
* - Format what you write: finish with `formatFilesInSubtree` so the files your
|
|
21
|
+
* migration wrote are formatted correctly.
|
|
22
|
+
*/
|
|
23
|
+
<%_ } else { _%>
|
|
24
|
+
*
|
|
25
|
+
* How to write a migration:
|
|
26
|
+
* - https://nx.dev/docs/kb/migration-generators
|
|
27
|
+
* - What `nextSteps` means: https://nx.dev/docs/reference/devkit/MigrationReturnObject
|
|
28
|
+
*
|
|
29
|
+
* Guardrails:
|
|
30
|
+
* - Pattern-match before writing: skip files that have diverged from the shape
|
|
31
|
+
* your generators produce and report them via `nextSteps`, or consider a
|
|
32
|
+
* hybrid migration, rather than clobbering the user's changes.
|
|
33
|
+
* - Idempotent: re-running must be a no-op.
|
|
34
|
+
* - Format what you write: finish with `formatFilesInSubtree` so the files your
|
|
35
|
+
* migration wrote are formatted correctly.
|
|
36
|
+
*/
|
|
37
|
+
<%_ } _%>
|
|
38
|
+
export default async function migration(
|
|
39
|
+
tree: Tree,
|
|
40
|
+
): Promise<MigrationReturnObject> {
|
|
41
|
+
const nextSteps: string[] = [];
|
|
42
|
+
<% if (isHybrid) { %> const agentContext: string[] = [];
|
|
43
|
+
<% } %>
|
|
44
|
+
// TODO: read the workspace's files and update the ones matching the shape
|
|
45
|
+
// your generators produce, noting any you skip in `nextSteps`.
|
|
46
|
+
<% if (isHybrid) { %>
|
|
47
|
+
// `agentContext` reaches the paired prompt under `--agentic` and is dropped
|
|
48
|
+
// otherwise.
|
|
49
|
+
// TODO: describe what changed in `agentContext`, e.g.:
|
|
50
|
+
// agentContext.push('Renamed the `foo` target to `bar` in every project.json.');
|
|
51
|
+
<% } %>
|
|
52
|
+
await formatFilesInSubtree(tree);
|
|
53
|
+
|
|
54
|
+
return { nextSteps<% if (isHybrid) { %>, agentContext<% } %> };
|
|
55
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<%_ if (isHybrid) { _%>
|
|
2
|
+
<!-- Authoring guide (delete before shipping): this file is the `prompt` for the
|
|
3
|
+
agentic half of a hybrid migration. The codemod half (migration.ts) has already
|
|
4
|
+
run its mechanical changes and passes a summary via `agentContext`. The prompt is
|
|
5
|
+
applied by the user's AI coding agent, and shown verbatim to users who run
|
|
6
|
+
`nx migrate` without one, so write self-contained, human-actionable steps.
|
|
7
|
+
See https://nx.dev/docs/kb/migration-generators -->
|
|
8
|
+
<%_ } else { _%>
|
|
9
|
+
<!-- Authoring guide (delete before shipping): this file is the `prompt` for an
|
|
10
|
+
agentic migration. It is applied by the user's AI coding agent, and shown
|
|
11
|
+
verbatim to users who run `nx migrate` without one, so write self-contained,
|
|
12
|
+
human-actionable steps.
|
|
13
|
+
See https://nx.dev/docs/kb/migration-generators -->
|
|
14
|
+
<%_ } _%>
|
|
15
|
+
|
|
16
|
+
# <%= description %>
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
<%_ if (isHybrid) { _%>
|
|
21
|
+
<!-- TODO: describe the breaking change and what remains to be done in
|
|
22
|
+
user-owned code after the codemod has run. -->
|
|
23
|
+
<%_ } else { _%>
|
|
24
|
+
<!-- TODO: describe the breaking change and what the workspace needs to end up
|
|
25
|
+
looking like. -->
|
|
26
|
+
<%_ } _%>
|
|
27
|
+
|
|
28
|
+
## Steps
|
|
29
|
+
|
|
30
|
+
<%_ if (isHybrid) { _%>
|
|
31
|
+
1. <!-- TODO: identify the user-owned call sites the codemod could not update
|
|
32
|
+
(e.g. "handlers that call the renamed API"). -->
|
|
33
|
+
<%_ } else { _%>
|
|
34
|
+
1. <!-- TODO: identify the files/patterns affected (e.g. "search for `oldApi(`
|
|
35
|
+
across the workspace"). -->
|
|
36
|
+
<%_ } _%>
|
|
37
|
+
2. <!-- TODO: describe the transformation with before/after examples. -->
|
|
38
|
+
3. <!-- TODO: how to verify: run `nx run-many --target build --all` (and any
|
|
39
|
+
relevant tests) and confirm they pass. -->
|
|
40
|
+
|
|
41
|
+
## Guard rails
|
|
42
|
+
|
|
43
|
+
- Only change what these instructions describe. Do not reformat unrelated code.
|
|
44
|
+
- Do not weaken or delete tests to make them pass.
|
|
45
|
+
- If a file has been customised in a way these instructions don't cover, leave
|
|
46
|
+
it and note it for the user rather than guessing.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
6
|
+
import { type NxGeneratorInfo } from '../../utils/nx';
|
|
7
|
+
import type { TsNxMigrationGeneratorSchema } from './schema';
|
|
8
|
+
export declare const NX_MIGRATION_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
|
+
/**
|
|
10
|
+
* Scaffolds a migration in an Nx Plugin project and registers it in the
|
|
11
|
+
* plugin's `migrations.json` (creating the manifest and wiring the
|
|
12
|
+
* `nx-migrations` field into the plugin's `package.json` if absent), so
|
|
13
|
+
* `nx migrate` applies it when users upgrade the plugin.
|
|
14
|
+
*
|
|
15
|
+
* Supports all three migration kinds:
|
|
16
|
+
* - `deterministic`: a codemod (`implementation`).
|
|
17
|
+
* - `agentic`: a `prompt` markdown file applied by the user's agent.
|
|
18
|
+
* - `hybrid`: both — the codemod does the mechanical part and returns
|
|
19
|
+
* `agentContext`, then the prompt hands off to the agent for the rest.
|
|
20
|
+
*
|
|
21
|
+
* No `version` is written — the plugin author stamps versions at release time.
|
|
22
|
+
*/
|
|
23
|
+
export declare const tsNxMigrationGenerator: (tree: Tree, options: TsNxMigrationGeneratorSchema) => Promise<GeneratorCallback | void>;
|
|
24
|
+
export default tsNxMigrationGenerator;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { generateFiles, joinPathFragments, OverwriteStrategy, readJson, writeJson } from "@nx/devkit";
|
|
5
|
+
import PackageJson from "../../../package.json" with {
|
|
6
|
+
type: 'json'
|
|
7
|
+
};
|
|
8
|
+
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
9
|
+
import { installDependencies } from "../../utils/install.js";
|
|
10
|
+
import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
11
|
+
import { LATEST_MIGRATIONS_DIR, migrationKey } from "../../utils/migration-versions.js";
|
|
12
|
+
import { kebabCase } from "../../utils/names.js";
|
|
13
|
+
import { getGeneratorInfo, isNxPluginForAwsWorkspace } from "../../utils/nx.js";
|
|
14
|
+
import { sortObjectKeys } from "../../utils/object.js";
|
|
15
|
+
import { addNxPluginDependencies, configureNxPluginPackageJson, readNxPluginProject } from "../nx-plugin/utils.js";
|
|
16
|
+
export const NX_MIGRATION_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
17
|
+
/**
|
|
18
|
+
* Scaffolds a migration in an Nx Plugin project and registers it in the
|
|
19
|
+
* plugin's `migrations.json` (creating the manifest and wiring the
|
|
20
|
+
* `nx-migrations` field into the plugin's `package.json` if absent), so
|
|
21
|
+
* `nx migrate` applies it when users upgrade the plugin.
|
|
22
|
+
*
|
|
23
|
+
* Supports all three migration kinds:
|
|
24
|
+
* - `deterministic`: a codemod (`implementation`).
|
|
25
|
+
* - `agentic`: a `prompt` markdown file applied by the user's agent.
|
|
26
|
+
* - `hybrid`: both — the codemod does the mechanical part and returns
|
|
27
|
+
* `agentContext`, then the prompt hands off to the agent for the rest.
|
|
28
|
+
*
|
|
29
|
+
* No `version` is written — the plugin author stamps versions at release time.
|
|
30
|
+
*/ export const tsNxMigrationGenerator = async (tree, options)=>{
|
|
31
|
+
const name = kebabCase(options.name);
|
|
32
|
+
// Shown by `nx migrate` when the migration runs, so it needs to say something
|
|
33
|
+
const description = options.description ?? 'TODO: Add short description of the migration';
|
|
34
|
+
const kind = options.kind ?? 'deterministic';
|
|
35
|
+
const hasImplementation = kind === 'deterministic' || kind === 'hybrid';
|
|
36
|
+
const hasPrompt = kind === 'agentic' || kind === 'hybrid';
|
|
37
|
+
const isHybrid = kind === 'hybrid';
|
|
38
|
+
const plugin = readNxPluginProject(tree, options.project);
|
|
39
|
+
const sourceRoot = plugin.sourceRoot ?? joinPathFragments(plugin.root, 'src');
|
|
40
|
+
const srcDir = sourceRoot.split('/').filter(Boolean).pop();
|
|
41
|
+
// Migrations are grouped by the release that ships them. A new one lands in
|
|
42
|
+
// `latest` — the release that picks it up moves it into its version folder.
|
|
43
|
+
const migrationPath = `${srcDir}/migrations/${LATEST_MIGRATIONS_DIR}/${name}`;
|
|
44
|
+
const migrationDir = joinPathFragments(sourceRoot, 'migrations', LATEST_MIGRATIONS_DIR, name);
|
|
45
|
+
const key = migrationKey(LATEST_MIGRATIONS_DIR, name);
|
|
46
|
+
const isNxPluginForAws = isNxPluginForAwsWorkspace(tree);
|
|
47
|
+
// Point the plugin at its migrations manifest so `nx migrate` finds them
|
|
48
|
+
const pluginPackageJsonPath = configureNxPluginPackageJson(tree, plugin, 'nx-migrations', {
|
|
49
|
+
migrations: './migrations.json'
|
|
50
|
+
});
|
|
51
|
+
// Migrations sit three levels below the source root, so in this repo the
|
|
52
|
+
// shared utils are relative. Elsewhere they come from the SDK.
|
|
53
|
+
const formatImportPath = isNxPluginForAws ? '../../../utils/format' : `${PackageJson.name}/sdk/utils/format`;
|
|
54
|
+
const testImportPath = isNxPluginForAws ? '../../../utils/test' : `${PackageJson.name}/sdk/utils/test`;
|
|
55
|
+
// One template set covers all kinds — scaffold it, then prune what this kind
|
|
56
|
+
// doesn't use.
|
|
57
|
+
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), migrationDir, {
|
|
58
|
+
name,
|
|
59
|
+
description,
|
|
60
|
+
isHybrid,
|
|
61
|
+
formatImportPath,
|
|
62
|
+
testImportPath
|
|
63
|
+
}, {
|
|
64
|
+
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
65
|
+
});
|
|
66
|
+
if (!hasImplementation) {
|
|
67
|
+
tree.delete(joinPathFragments(migrationDir, 'migration.ts'));
|
|
68
|
+
tree.delete(joinPathFragments(migrationDir, 'migration.spec.ts'));
|
|
69
|
+
}
|
|
70
|
+
if (!hasPrompt) {
|
|
71
|
+
tree.delete(joinPathFragments(migrationDir, 'prompt.md'));
|
|
72
|
+
}
|
|
73
|
+
// Register the migration under its folder-prefixed key. The fields present
|
|
74
|
+
// discriminate the kind for nx, and paths are relative to migrations.json.
|
|
75
|
+
// No version is written, but an already-stamped one is preserved.
|
|
76
|
+
const migrationsJsonPath = joinPathFragments(plugin.root, 'migrations.json');
|
|
77
|
+
const migrationsJson = tree.exists(migrationsJsonPath) ? readJson(tree, migrationsJsonPath) : {
|
|
78
|
+
$schema: 'http://json-schema.org/schema',
|
|
79
|
+
name: readJson(tree, pluginPackageJsonPath).name ?? plugin.name,
|
|
80
|
+
generators: {}
|
|
81
|
+
};
|
|
82
|
+
writeJson(tree, migrationsJsonPath, {
|
|
83
|
+
...migrationsJson,
|
|
84
|
+
generators: sortObjectKeys({
|
|
85
|
+
...migrationsJson.generators,
|
|
86
|
+
[key]: {
|
|
87
|
+
...migrationsJson.generators?.[key]?.version ? {
|
|
88
|
+
version: migrationsJson.generators[key].version
|
|
89
|
+
} : {},
|
|
90
|
+
description,
|
|
91
|
+
...hasImplementation ? {
|
|
92
|
+
implementation: `./${migrationPath}/migration`
|
|
93
|
+
} : {},
|
|
94
|
+
...hasPrompt ? {
|
|
95
|
+
prompt: `./${migrationPath}/prompt.md`
|
|
96
|
+
} : {}
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
// Codemods import @nx/devkit and the @aws/nx-plugin SDK, both of which must
|
|
101
|
+
// resolve for nx to run them
|
|
102
|
+
if (hasImplementation) {
|
|
103
|
+
addNxPluginDependencies(tree, pluginPackageJsonPath);
|
|
104
|
+
}
|
|
105
|
+
await addGeneratorMetricsIfApplicable(tree, [
|
|
106
|
+
NX_MIGRATION_GENERATOR_INFO
|
|
107
|
+
]);
|
|
108
|
+
await formatFilesInSubtree(tree);
|
|
109
|
+
if (hasImplementation && !isNxPluginForAws) {
|
|
110
|
+
return ()=>installDependencies(tree, options.preferInstallDependencies, {
|
|
111
|
+
languages: [
|
|
112
|
+
'typescript'
|
|
113
|
+
],
|
|
114
|
+
ensureResolvable: [
|
|
115
|
+
'@nx/devkit'
|
|
116
|
+
]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
export default tsNxMigrationGenerator;
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-migration/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n writeJson,\n} from '@nx/devkit';\nimport PackageJson from '../../../package.json' with { type: 'json' };\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport {\n LATEST_MIGRATIONS_DIR,\n migrationKey,\n} from '../../utils/migration-versions';\nimport { kebabCase } from '../../utils/names';\nimport {\n getGeneratorInfo,\n isNxPluginForAwsWorkspace,\n type NxGeneratorInfo,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport {\n addNxPluginDependencies,\n configureNxPluginPackageJson,\n readNxPluginProject,\n} from '../nx-plugin/utils';\nimport type { TsNxMigrationGeneratorSchema } from './schema';\n\nexport const NX_MIGRATION_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Scaffolds a migration in an Nx Plugin project and registers it in the\n * plugin's `migrations.json` (creating the manifest and wiring the\n * `nx-migrations` field into the plugin's `package.json` if absent), so\n * `nx migrate` applies it when users upgrade the plugin.\n *\n * Supports all three migration kinds:\n * - `deterministic`: a codemod (`implementation`).\n * - `agentic`: a `prompt` markdown file applied by the user's agent.\n * - `hybrid`: both — the codemod does the mechanical part and returns\n * `agentContext`, then the prompt hands off to the agent for the rest.\n *\n * No `version` is written — the plugin author stamps versions at release time.\n */\nexport const tsNxMigrationGenerator = async (\n tree: Tree,\n options: TsNxMigrationGeneratorSchema,\n): Promise<GeneratorCallback | void> => {\n const name = kebabCase(options.name);\n // Shown by `nx migrate` when the migration runs, so it needs to say something\n const description =\n options.description ?? 'TODO: Add short description of the migration';\n const kind = options.kind ?? 'deterministic';\n\n const hasImplementation = kind === 'deterministic' || kind === 'hybrid';\n const hasPrompt = kind === 'agentic' || kind === 'hybrid';\n const isHybrid = kind === 'hybrid';\n\n const plugin = readNxPluginProject(tree, options.project);\n\n const sourceRoot = plugin.sourceRoot ?? joinPathFragments(plugin.root, 'src');\n const srcDir = sourceRoot.split('/').filter(Boolean).pop();\n // Migrations are grouped by the release that ships them. A new one lands in\n // `latest` — the release that picks it up moves it into its version folder.\n const migrationPath = `${srcDir}/migrations/${LATEST_MIGRATIONS_DIR}/${name}`;\n const migrationDir = joinPathFragments(\n sourceRoot,\n 'migrations',\n LATEST_MIGRATIONS_DIR,\n name,\n );\n const key = migrationKey(LATEST_MIGRATIONS_DIR, name);\n\n const isNxPluginForAws = isNxPluginForAwsWorkspace(tree);\n\n // Point the plugin at its migrations manifest so `nx migrate` finds them\n const pluginPackageJsonPath = configureNxPluginPackageJson(\n tree,\n plugin,\n 'nx-migrations',\n { migrations: './migrations.json' },\n );\n\n // Migrations sit three levels below the source root, so in this repo the\n // shared utils are relative. Elsewhere they come from the SDK.\n const formatImportPath = isNxPluginForAws\n ? '../../../utils/format'\n : `${PackageJson.name}/sdk/utils/format`;\n const testImportPath = isNxPluginForAws\n ? '../../../utils/test'\n : `${PackageJson.name}/sdk/utils/test`;\n\n // One template set covers all kinds — scaffold it, then prune what this kind\n // doesn't use.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n migrationDir,\n { name, description, isHybrid, formatImportPath, testImportPath },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n if (!hasImplementation) {\n tree.delete(joinPathFragments(migrationDir, 'migration.ts'));\n tree.delete(joinPathFragments(migrationDir, 'migration.spec.ts'));\n }\n if (!hasPrompt) {\n tree.delete(joinPathFragments(migrationDir, 'prompt.md'));\n }\n\n // Register the migration under its folder-prefixed key. The fields present\n // discriminate the kind for nx, and paths are relative to migrations.json.\n // No version is written, but an already-stamped one is preserved.\n const migrationsJsonPath = joinPathFragments(plugin.root, 'migrations.json');\n const migrationsJson = tree.exists(migrationsJsonPath)\n ? readJson(tree, migrationsJsonPath)\n : {\n $schema: 'http://json-schema.org/schema',\n name: readJson(tree, pluginPackageJsonPath).name ?? plugin.name,\n generators: {},\n };\n writeJson(tree, migrationsJsonPath, {\n ...migrationsJson,\n generators: sortObjectKeys({\n ...migrationsJson.generators,\n [key]: {\n ...(migrationsJson.generators?.[key]?.version\n ? { version: migrationsJson.generators[key].version }\n : {}),\n description,\n ...(hasImplementation\n ? { implementation: `./${migrationPath}/migration` }\n : {}),\n ...(hasPrompt ? { prompt: `./${migrationPath}/prompt.md` } : {}),\n },\n }),\n });\n\n // Codemods import @nx/devkit and the @aws/nx-plugin SDK, both of which must\n // resolve for nx to run them\n if (hasImplementation) {\n addNxPluginDependencies(tree, pluginPackageJsonPath);\n }\n\n await addGeneratorMetricsIfApplicable(tree, [NX_MIGRATION_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n if (hasImplementation && !isNxPluginForAws) {\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n ensureResolvable: ['@nx/devkit'],\n });\n }\n};\n\nexport default tsNxMigrationGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readJson","writeJson","PackageJson","type","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","LATEST_MIGRATIONS_DIR","migrationKey","kebabCase","getGeneratorInfo","isNxPluginForAwsWorkspace","sortObjectKeys","addNxPluginDependencies","configureNxPluginPackageJson","readNxPluginProject","NX_MIGRATION_GENERATOR_INFO","filename","tsNxMigrationGenerator","tree","options","name","description","kind","hasImplementation","hasPrompt","isHybrid","plugin","project","sourceRoot","root","srcDir","split","filter","Boolean","pop","migrationPath","migrationDir","key","isNxPluginForAws","pluginPackageJsonPath","migrations","formatImportPath","testImportPath","dirname","overwriteStrategy","KeepExisting","delete","migrationsJsonPath","migrationsJson","exists","$schema","generators","version","implementation","prompt","preferInstallDependencies","languages","ensureResolvable"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,SAAS,QACJ,aAAa;AACpB,OAAOC,iBAAiB,6BAA6B;IAAEC,MAAM;AAAO,EAAE;AACtE,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SACEC,qBAAqB,EACrBC,YAAY,QACP,oCAAiC;AACxC,SAASC,SAAS,QAAQ,uBAAoB;AAC9C,SACEC,gBAAgB,EAChBC,yBAAyB,QAEpB,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SACEC,uBAAuB,EACvBC,4BAA4B,EAC5BC,mBAAmB,QACd,wBAAqB;AAG5B,OAAO,MAAMC,8BAA+CN,iBAC1D,YAAYO,QAAQ,EACpB;AAEF;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMC,yBAAyB,OACpCC,MACAC;IAEA,MAAMC,OAAOZ,UAAUW,QAAQC,IAAI;IACnC,8EAA8E;IAC9E,MAAMC,cACJF,QAAQE,WAAW,IAAI;IACzB,MAAMC,OAAOH,QAAQG,IAAI,IAAI;IAE7B,MAAMC,oBAAoBD,SAAS,mBAAmBA,SAAS;IAC/D,MAAME,YAAYF,SAAS,aAAaA,SAAS;IACjD,MAAMG,WAAWH,SAAS;IAE1B,MAAMI,SAASZ,oBAAoBI,MAAMC,QAAQQ,OAAO;IAExD,MAAMC,aAAaF,OAA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mB,MAAMqB,uBAAuBnB,IAAI,IAAIM,OAAON,IAAI;QAC/D+B,YAAY,CAAC;IACf;IACJnD,UAAUkB,MAAM6B,oBAAoB;QAClC,GAAGC,cAAc;QACjBG,YAAYxC,eAAe;YACzB,GAAGqC,eAAeG,UAAU;YAC5B,CAACd,IAAI,EAAE;gBACL,GAAIW,eAAeG,UAAU,EAAE,CAACd,IAAI,EAAEe,UAClC;oBAAEA,SAASJ,eAAeG,UAAU,CAACd,IAAI,CAACe,OAAO;gBAAC,IAClD,CAAC,CAAC;gBACN/B;gBACA,GAAIE,oBACA;oBAAE8B,gBAAgB,CAAC,EAAE,EAAElB,cAAc,UAAU,CAAC;gBAAC,IACjD,CAAC,CAAC;gBACN,GAAIX,YAAY;oBAAE8B,QAAQ,CAAC,EAAE,EAAEnB,cAAc,UAAU,CAAC;gBAAC,IAAI,CAAC,CAAC;YACjE;QACF;IACF;IAEA,4EAA4E;IAC5E,6BAA6B;IAC7B,IAAIZ,mBAAmB;QACrBX,wBAAwBM,MAAMqB;IAChC;IAEA,MAAMlC,gCAAgCa,MAAM;QAACH;KAA4B;IAEzE,MAAMZ,qBAAqBe;IAE3B,IAAIK,qBAAqB,CAACe,kBAAkB;QAC1C,OAAO,IACLlC,oBAAoBc,MAAMC,QAAQoC,yBAAyB,EAAE;gBAC3DC,WAAW;oBAAC;iBAAa;gBACzBC,kBAAkB;oBAAC;iBAAa;YAClC;IACJ;AACF,EAAE;AAEF,eAAexC,uBAAuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-migration/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nexport type NxMigrationKind = 'deterministic' | 'agentic' | 'hybrid';\n\nexport interface TsNxMigrationGeneratorSchema {\n project: string;\n name: string;\n description?: string;\n kind?: NxMigrationKind;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAMC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
export type NxMigrationKind = 'deterministic' | 'agentic' | 'hybrid';
|
|
6
|
+
|
|
7
|
+
export interface TsNxMigrationGeneratorSchema {
|
|
8
|
+
project: string;
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
kind?: NxMigrationKind;
|
|
12
|
+
preferInstallDependencies?: boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "TsNxMigration",
|
|
4
|
+
"title": "Create an Nx Migration",
|
|
5
|
+
"description": "Scaffold a migration for an Nx Plugin, applied by nx migrate when users upgrade",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The Nx Plugin project to add the migration to. We recommend using the ts#nx-plugin generator to create this.",
|
|
11
|
+
"x-priority": "important",
|
|
12
|
+
"x-prompt": "Choose the Nx Plugin project to add the migration to",
|
|
13
|
+
"x-dropdown": "projects",
|
|
14
|
+
"$default": {
|
|
15
|
+
"$source": "argv",
|
|
16
|
+
"index": 0
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"name": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Migration name, in kebab-case (e.g. rename-foo-target)",
|
|
22
|
+
"x-priority": "important",
|
|
23
|
+
"x-prompt": "What is the name of the migration? (kebab-case, e.g. rename-foo-target)"
|
|
24
|
+
},
|
|
25
|
+
"description": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "A description of what the migration does, shown by nx migrate",
|
|
28
|
+
"x-priority": "important",
|
|
29
|
+
"x-prompt": "Describe what the migration does"
|
|
30
|
+
},
|
|
31
|
+
"kind": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "The kind of migration: deterministic (a codemod), agentic (an AI-applied prompt for user-owned code), or hybrid (a codemod that does the mechanical part then hands off to an agent)",
|
|
34
|
+
"enum": ["deterministic", "agentic", "hybrid"],
|
|
35
|
+
"default": "deterministic",
|
|
36
|
+
"x-priority": "important",
|
|
37
|
+
"x-prompt": {
|
|
38
|
+
"message": "What kind of migration is this?",
|
|
39
|
+
"type": "list",
|
|
40
|
+
"items": [
|
|
41
|
+
{
|
|
42
|
+
"value": "deterministic",
|
|
43
|
+
"label": "Deterministic — a codemod with an exact before/after (runs unattended, incl. CI)"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"value": "agentic",
|
|
47
|
+
"label": "Agentic — an AI-applied prompt for changes to user-owned code"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"value": "hybrid",
|
|
51
|
+
"label": "Hybrid — a codemod for the mechanical part that hands off to an agent for the rest"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"preferInstallDependencies": {
|
|
57
|
+
"type": "boolean",
|
|
58
|
+
"description": "Whether to prefer installing dependencies after the generator runs. Set to false to defer installing when batching multiple generators (an install still runs if needed so subsequent generators can compute the Nx project graph); install once at the end.",
|
|
59
|
+
"default": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"required": ["project", "name"]
|
|
63
|
+
}
|
|
@@ -2,8 +2,28 @@
|
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { type Tree } from '@nx/devkit';
|
|
5
|
+
import { type ProjectConfiguration, type Tree } from '@nx/devkit';
|
|
6
|
+
import type { PackageJson } from 'nx/src/utils/package-json';
|
|
7
|
+
/**
|
|
8
|
+
* Read the configuration of a project which can host Nx Plugin generators or
|
|
9
|
+
* migrations, ie a TypeScript project.
|
|
10
|
+
*/
|
|
11
|
+
export declare const readNxPluginProject: (tree: Tree, projectName: string) => ProjectConfiguration;
|
|
12
|
+
/** `package.json` field pointing Nx at one of a plugin's manifests. */
|
|
13
|
+
type NxPluginManifestField = 'generators' | 'nx-migrations';
|
|
14
|
+
/**
|
|
15
|
+
* Create the plugin project's package.json if absent and point it at the given
|
|
16
|
+
* manifest, returning its path.
|
|
17
|
+
*/
|
|
18
|
+
export declare const configureNxPluginPackageJson: <TField extends NxPluginManifestField>(tree: Tree, project: ProjectConfiguration, manifestField: TField, manifestValue: PackageJson[TField]) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Declare the dependencies the plugin's `.ts` files import on both the
|
|
21
|
+
* workspace and the plugin, since both must resolve for Nx to load them. A
|
|
22
|
+
* no-op inside the plugin's own monorepo, where they are already present.
|
|
23
|
+
*/
|
|
24
|
+
export declare const addNxPluginDependencies: (tree: Tree, pluginPackageJsonPath: string) => void;
|
|
6
25
|
/**
|
|
7
26
|
* Configures a TypeScript project as an Nx Plugin
|
|
8
27
|
*/
|
|
9
28
|
export declare const configureTsProjectAsNxPlugin: (tree: Tree, projectName: string) => void;
|
|
29
|
+
export {};
|
|
@@ -7,22 +7,20 @@ import { isEsmWorkspace } from "../../utils/module-format.js";
|
|
|
7
7
|
import { nxPluginSelfDependency, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
8
8
|
import { withVersions } from "../../utils/versions.js";
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
|
|
10
|
+
* Read the configuration of a project which can host Nx Plugin generators or
|
|
11
|
+
* migrations, ie a TypeScript project.
|
|
12
|
+
*/ export const readNxPluginProject = (tree, projectName)=>{
|
|
12
13
|
const project = readProjectConfigurationUnqualified(tree, projectName);
|
|
13
14
|
const tsConfigPath = joinPathFragments(project.root, 'tsconfig.json');
|
|
14
15
|
if (!tree.exists(tsConfigPath)) {
|
|
15
16
|
throw new Error(`Selected plugin project ${projectName} is not a TypeScript project`);
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
// Create a package.json if one doesn't exist, and configure "type", "main"
|
|
25
|
-
// and "generators"
|
|
18
|
+
return project;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Create the plugin project's package.json if absent and point it at the given
|
|
22
|
+
* manifest, returning its path.
|
|
23
|
+
*/ export const configureNxPluginPackageJson = (tree, project, manifestField, manifestValue)=>{
|
|
26
24
|
const pluginPackageJsonPath = joinPathFragments(project.root, 'package.json');
|
|
27
25
|
if (!tree.exists(pluginPackageJsonPath)) {
|
|
28
26
|
writeJson(tree, pluginPackageJsonPath, {
|
|
@@ -31,31 +29,47 @@ import { withVersions } from "../../utils/versions.js";
|
|
|
31
29
|
}
|
|
32
30
|
const esm = isEsmWorkspace(tree);
|
|
33
31
|
updateJson(tree, pluginPackageJsonPath, (pkg)=>{
|
|
34
|
-
// Match the plugin's module system to the workspace. Nx loads `.ts`
|
|
35
|
-
//
|
|
32
|
+
// Match the plugin's module system to the workspace. Nx loads `.ts` files
|
|
33
|
+
// via Node's native type stripping, as ESM (workspace root is
|
|
36
34
|
// `type: module`) or CommonJS accordingly.
|
|
37
35
|
pkg.type ??= esm ? 'module' : 'commonjs';
|
|
38
36
|
pkg.main ??= esm ? './src/index.js' : './src/index';
|
|
39
|
-
pkg
|
|
37
|
+
pkg[manifestField] ??= manifestValue;
|
|
40
38
|
return pkg;
|
|
41
39
|
});
|
|
40
|
+
return pluginPackageJsonPath;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Declare the dependencies the plugin's `.ts` files import on both the
|
|
44
|
+
* workspace and the plugin, since both must resolve for Nx to load them. A
|
|
45
|
+
* no-op inside the plugin's own monorepo, where they are already present.
|
|
46
|
+
*/ export const addNxPluginDependencies = (tree, pluginPackageJsonPath)=>{
|
|
42
47
|
const selfDependency = nxPluginSelfDependency(tree);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
if (Object.keys(selfDependency).length === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const deps = {
|
|
52
|
+
...withVersions([
|
|
53
|
+
'@nx/devkit'
|
|
54
|
+
]),
|
|
55
|
+
...selfDependency
|
|
56
|
+
};
|
|
57
|
+
addDependenciesToPackageJson(tree, {}, deps);
|
|
58
|
+
addDependenciesToPackageJson(tree, deps, {}, pluginPackageJsonPath);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Configures a TypeScript project as an Nx Plugin
|
|
62
|
+
*/ export const configureTsProjectAsNxPlugin = (tree, projectName)=>{
|
|
63
|
+
const project = readNxPluginProject(tree, projectName);
|
|
64
|
+
// Create an empty generators.json if one dosn't exist
|
|
65
|
+
const generatorsJsonPath = joinPathFragments(project.root, 'generators.json');
|
|
66
|
+
if (!tree.exists(generatorsJsonPath)) {
|
|
67
|
+
writeJson(tree, generatorsJsonPath, {
|
|
68
|
+
generators: {}
|
|
69
|
+
});
|
|
58
70
|
}
|
|
71
|
+
const pluginPackageJsonPath = configureNxPluginPackageJson(tree, project, 'generators', './generators.json');
|
|
72
|
+
addNxPluginDependencies(tree, pluginPackageJsonPath);
|
|
59
73
|
};
|
|
60
74
|
|
|
61
75
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-plugin/utils.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type Tree,\n updateJson,\n writeJson,\n} from '@nx/devkit';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport {\n nxPluginSelfDependency,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { withVersions } from '../../utils/versions';\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-plugin/utils.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n updateJson,\n writeJson,\n} from '@nx/devkit';\nimport type { PackageJson } from 'nx/src/utils/package-json';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport {\n nxPluginSelfDependency,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { withVersions } from '../../utils/versions';\n\n/**\n * Read the configuration of a project which can host Nx Plugin generators or\n * migrations, ie a TypeScript project.\n */\nexport const readNxPluginProject = (\n tree: Tree,\n projectName: string,\n): ProjectConfiguration => {\n const project = readProjectConfigurationUnqualified(tree, projectName);\n\n const tsConfigPath = joinPathFragments(project.root, 'tsconfig.json');\n if (!tree.exists(tsConfigPath)) {\n throw new Error(\n `Selected plugin project ${projectName} is not a TypeScript project`,\n );\n }\n\n return project;\n};\n\n/** `package.json` field pointing Nx at one of a plugin's manifests. */\ntype NxPluginManifestField = 'generators' | 'nx-migrations';\n\n/**\n * Create the plugin project's package.json if absent and point it at the given\n * manifest, returning its path.\n */\nexport const configureNxPluginPackageJson = <\n TField extends NxPluginManifestField,\n>(\n tree: Tree,\n project: ProjectConfiguration,\n manifestField: TField,\n manifestValue: PackageJson[TField],\n): string => {\n const pluginPackageJsonPath = joinPathFragments(project.root, 'package.json');\n if (!tree.exists(pluginPackageJsonPath)) {\n writeJson(tree, pluginPackageJsonPath, {\n name: project.name,\n });\n }\n const esm = isEsmWorkspace(tree);\n updateJson(tree, pluginPackageJsonPath, (pkg) => {\n // Match the plugin's module system to the workspace. Nx loads `.ts` files\n // via Node's native type stripping, as ESM (workspace root is\n // `type: module`) or CommonJS accordingly.\n pkg.type ??= esm ? 'module' : 'commonjs';\n pkg.main ??= esm ? './src/index.js' : './src/index';\n pkg[manifestField] ??= manifestValue;\n return pkg;\n });\n return pluginPackageJsonPath;\n};\n\n/**\n * Declare the dependencies the plugin's `.ts` files import on both the\n * workspace and the plugin, since both must resolve for Nx to load them. A\n * no-op inside the plugin's own monorepo, where they are already present.\n */\nexport const addNxPluginDependencies = (\n tree: Tree,\n pluginPackageJsonPath: string,\n): void => {\n const selfDependency = nxPluginSelfDependency(tree);\n if (Object.keys(selfDependency).length === 0) {\n return;\n }\n const deps = {\n ...withVersions(['@nx/devkit']),\n ...selfDependency,\n };\n addDependenciesToPackageJson(tree, {}, deps);\n addDependenciesToPackageJson(tree, deps, {}, pluginPackageJsonPath);\n};\n\n/**\n * Configures a TypeScript project as an Nx Plugin\n */\nexport const configureTsProjectAsNxPlugin = (\n tree: Tree,\n projectName: string,\n) => {\n const project = readNxPluginProject(tree, projectName);\n\n // Create an empty generators.json if one dosn't exist\n const generatorsJsonPath = joinPathFragments(project.root, 'generators.json');\n if (!tree.exists(generatorsJsonPath)) {\n writeJson(tree, generatorsJsonPath, {\n generators: {},\n });\n }\n\n const pluginPackageJsonPath = configureNxPluginPackageJson(\n tree,\n project,\n 'generators',\n './generators.json',\n );\n\n addNxPluginDependencies(tree, pluginPackageJsonPath);\n};\n"],"names":["joinPathFragments","updateJson","writeJson","addDependenciesToPackageJson","isEsmWorkspace","nxPluginSelfDependency","readProjectConfigurationUnqualified","withVersions","readNxPluginProject","tree","projectName","project","tsConfigPath","root","exists","Error","configureNxPluginPackageJson","manifestField","manifestValue","pluginPackageJsonPath","name","esm","pkg","type","main","addNxPluginDependencies","selfDependency","Object","keys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