@aws/nx-plugin 1.0.0-rc.63 → 1.0.0-rc.65
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 +17 -2
- package/package.json +1 -1
- package/src/mcp-server/guide-pipeline.js.map +1 -1
- package/src/migrations/latest/rolldown-code-splitting/metadata.json +3 -0
- package/src/migrations/latest/rolldown-code-splitting/migration.d.ts +6 -0
- package/src/migrations/latest/rolldown-code-splitting/migration.js +57 -0
- package/src/migrations/latest/rolldown-code-splitting/migration.js.map +1 -0
- package/src/{smithy/project/files/service/build.Dockerfile.template → migrations/latest/smithy-build-without-docker/legacy-service.Dockerfile.fixture} +2 -2
- package/src/migrations/latest/smithy-build-without-docker/metadata.json +3 -0
- package/src/migrations/latest/smithy-build-without-docker/migration.d.ts +6 -0
- package/src/migrations/latest/smithy-build-without-docker/migration.js +154 -0
- package/src/migrations/latest/smithy-build-without-docker/migration.js.map +1 -0
- package/src/migrations/latest/smithy-ssdk-bundle-pins/rc57-service.Dockerfile.fixture +95 -0
- package/src/migrations/latest/vite-config-import-meta-dirname/metadata.json +3 -0
- package/src/migrations/latest/vite-config-import-meta-dirname/migration.d.ts +6 -0
- package/src/migrations/latest/vite-config-import-meta-dirname/migration.js +71 -0
- package/src/migrations/latest/vite-config-import-meta-dirname/migration.js.map +1 -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/generator.d.ts +8 -0
- package/src/py/agent/mcp-connection/generator.d.ts +1 -1
- package/src/py/fast-api/generator.d.ts +4 -0
- package/src/py/mcp-server/generator.d.ts +8 -0
- package/src/py/rdb/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/py/rdb/files/migrations/env.py.template +1 -1
- package/src/py/rdb/generator.d.ts +8 -0
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +163 -260
- package/src/smithy/project/files/service/smithy-build.json.template +5 -5
- package/src/smithy/project/files/shapes/smithy-build.json.template +1 -1
- package/src/smithy/project/files/ssdk-bundle/ssdk.rolldown.config.mjs.template +52 -0
- package/src/smithy/project/generator.d.ts +76 -18
- package/src/smithy/project/generator.js +160 -38
- package/src/smithy/project/generator.js.map +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +22 -3
- package/src/smithy/ts/api/generator.d.ts +4 -0
- package/src/ts/agent/generator.d.ts +8 -0
- package/src/ts/lib/__snapshots__/vitest.spec.ts.snap +1 -1
- package/src/ts/lib/vitest.js +12 -0
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/mcp-server/generator.d.ts +8 -0
- package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/ts/nx-generator/files/local/generator.spec.ts.template +1 -1
- package/src/ts/nx-migration/files/migration.spec.ts.template +1 -1
- package/src/ts/nx-migration/generator.js +7 -1
- package/src/ts/nx-migration/generator.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/rdb/generator.d.ts +8 -0
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +10 -10
- package/src/ts/react-website/app/generator.js +1 -1
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/utils/bundle/bundle.js +1 -1
- package/src/utils/bundle/bundle.js.map +1 -1
- package/src/utils/docker.d.ts +2 -0
- package/src/utils/fs.d.ts +8 -0
- package/src/utils/fs.js +11 -0
- package/src/utils/fs.js.map +1 -1
- package/src/utils/smithy.d.ts +59 -0
- package/src/utils/smithy.js +73 -0
- package/src/utils/smithy.js.map +1 -0
- package/src/utils/version-upgrade-migration/sync-embedded-versions.d.ts +2 -2
- package/src/utils/version-upgrade-migration/sync-embedded-versions.js +53 -5
- package/src/utils/version-upgrade-migration/sync-embedded-versions.js.map +1 -1
- package/src/utils/versions.d.ts +33 -1
- package/src/utils/versions.js +26 -1
- package/src/utils/versions.js.map +1 -1
- package/src/smithy/project/files/shapes/build.Dockerfile.template +0 -33
|
@@ -3,40 +3,98 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
6
|
+
import { FsCommands } from '../../utils/fs';
|
|
6
7
|
import { type NxGeneratorInfo } from '../../utils/nx';
|
|
7
8
|
import type { SmithyProjectGeneratorSchema } from './schema';
|
|
9
|
+
/** The metadata this generator records, which its predicates read. */
|
|
10
|
+
export interface SmithyProjectMetadata {
|
|
11
|
+
readonly smithyType: NonNullable<SmithyProjectGeneratorSchema['type']>;
|
|
12
|
+
readonly namespace: string;
|
|
13
|
+
}
|
|
8
14
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
15
|
+
* Everything a Smithy build runs, all of it workspace tooling in the root
|
|
16
|
+
* manifest rather than anything the model itself imports.
|
|
17
|
+
*
|
|
18
|
+
* Neither the Smithy CLI nor `mise` is among them: the compile target fetches mise
|
|
19
|
+
* with `npx` and mise resolves the CLI, so neither is a workspace dependency — see
|
|
20
|
+
* `utils/smithy.ts`.
|
|
13
21
|
*/
|
|
14
|
-
export declare const SSDK_BUNDLE_DEPENDENCIES: readonly [{
|
|
15
|
-
readonly name: "rolldown";
|
|
16
|
-
}, {
|
|
17
|
-
readonly name: "rolldown-plugin-dts";
|
|
18
|
-
}, {
|
|
19
|
-
readonly name: "@rollup/plugin-esm-shim";
|
|
20
|
-
}];
|
|
21
22
|
export declare const DEPENDENCIES: import("../../utils/declared-dependencies").DependencyDeclaration<readonly [{
|
|
22
23
|
readonly name: "ncp";
|
|
24
|
+
} & {
|
|
25
|
+
versionOnly: true;
|
|
23
26
|
}, {
|
|
24
27
|
readonly name: "rimraf";
|
|
25
|
-
}, {
|
|
26
|
-
readonly name: "make-dir-cli";
|
|
27
|
-
}, {
|
|
28
|
-
readonly name: "rolldown";
|
|
29
28
|
} & {
|
|
30
29
|
versionOnly: true;
|
|
31
30
|
}, {
|
|
32
|
-
readonly name: "
|
|
31
|
+
readonly name: "make-dir-cli";
|
|
33
32
|
} & {
|
|
34
33
|
versionOnly: true;
|
|
35
34
|
}, {
|
|
36
|
-
readonly name: "
|
|
35
|
+
readonly name: "cpy-cli";
|
|
37
36
|
} & {
|
|
38
37
|
versionOnly: true;
|
|
39
|
-
}
|
|
38
|
+
}, {
|
|
39
|
+
readonly name: "rolldown";
|
|
40
|
+
readonly dev: true;
|
|
41
|
+
readonly root: true;
|
|
42
|
+
readonly when: (metadata: SmithyProjectMetadata) => boolean;
|
|
43
|
+
}, {
|
|
44
|
+
readonly name: "rolldown-plugin-dts";
|
|
45
|
+
readonly dev: true;
|
|
46
|
+
readonly root: true;
|
|
47
|
+
readonly when: (metadata: SmithyProjectMetadata) => boolean;
|
|
48
|
+
}, {
|
|
49
|
+
readonly name: "typescript";
|
|
50
|
+
readonly dev: true;
|
|
51
|
+
readonly root: true;
|
|
52
|
+
readonly when: (metadata: SmithyProjectMetadata) => boolean;
|
|
53
|
+
}], readonly import("../../utils/declared-dependencies").DeclaredPyDependency<"a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "mcp" | "pip-check-updates" | "pip-licenses" | "ruff" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", SmithyProjectMetadata>[]>;
|
|
40
54
|
export declare const SMITHY_PROJECT_GENERATOR_INFO: NxGeneratorInfo;
|
|
55
|
+
/**
|
|
56
|
+
* The commands that build a Smithy project's model, run from the workspace root.
|
|
57
|
+
*
|
|
58
|
+
* This is the whole of a shape library's build. A service's Server SDK is built
|
|
59
|
+
* separately by {@link smithyGenerateSsdkCommands}, from the codegen output this
|
|
60
|
+
* leaves under {@link SMITHY_OUT_DIR}.
|
|
61
|
+
*/
|
|
62
|
+
export declare const smithyCompileCommands: (cmd: FsCommands<typeof DEPENDENCIES>, type: SmithyProjectGeneratorSchema["type"]) => string[];
|
|
63
|
+
/**
|
|
64
|
+
* The commands that turn a service's generated TypeScript Server SDK into the
|
|
65
|
+
* single module its consumer imports, run from the workspace root.
|
|
66
|
+
*
|
|
67
|
+
* Only a service has one, and it reads what the model build left behind, so this
|
|
68
|
+
* runs after `compile`.
|
|
69
|
+
*/
|
|
70
|
+
export declare const smithyGenerateSsdkCommands: () => string[];
|
|
71
|
+
/**
|
|
72
|
+
* What the model build publishes, listed per artifact rather than as the whole
|
|
73
|
+
* `build` directory: a service's `generate-ssdk` writes into that directory too, and
|
|
74
|
+
* restoring `compile` from cache would otherwise discard the Server SDK beside it.
|
|
75
|
+
*/
|
|
76
|
+
export declare const smithyCompileOutputs: (type: SmithyProjectGeneratorSchema["type"]) => string[];
|
|
77
|
+
/**
|
|
78
|
+
* The target that builds a service's Server SDK, shared with the migration moving
|
|
79
|
+
* an existing project onto it.
|
|
80
|
+
*/
|
|
81
|
+
export declare const smithyGenerateSsdkTarget: () => {
|
|
82
|
+
cache: boolean;
|
|
83
|
+
outputs: string[];
|
|
84
|
+
executor: string;
|
|
85
|
+
dependsOn: string[];
|
|
86
|
+
options: {
|
|
87
|
+
commands: string[];
|
|
88
|
+
parallel: boolean;
|
|
89
|
+
cwd: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Write the rolldown config that bundles a service's generated Server SDK.
|
|
94
|
+
*
|
|
95
|
+
* Shared with the migration moving an existing project off the container build,
|
|
96
|
+
* so a migrated project's config cannot drift from a freshly generated one.
|
|
97
|
+
*/
|
|
98
|
+
export declare const writeSsdkBundleConfig: (tree: Tree, projectRoot: string) => void;
|
|
41
99
|
export declare const smithyProjectGenerator: (tree: Tree, options: SmithyProjectGeneratorSchema) => Promise<GeneratorCallback>;
|
|
42
100
|
export default smithyProjectGenerator;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { addProjectConfiguration, generateFiles, joinPathFragments, OverwriteStrategy } from "@nx/devkit";
|
|
5
5
|
import { getTsLibDetails } from "../../ts/lib/generator.js";
|
|
6
|
-
import {
|
|
6
|
+
import { addTsDependencies } from "../../utils/add-dependencies.js";
|
|
7
7
|
import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
|
|
8
8
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
9
9
|
import { FS_DEPENDENCIES, FsCommands } from "../../utils/fs.js";
|
|
@@ -12,33 +12,139 @@ import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
|
12
12
|
import { toClassName, toKebabCase } from "../../utils/names.js";
|
|
13
13
|
import { getNpmScope } from "../../utils/npm-scope.js";
|
|
14
14
|
import { addGeneratorMetadata, getGeneratorInfo, projectExists } from "../../utils/nx.js";
|
|
15
|
-
import {
|
|
15
|
+
import { getRelativePathToRootByDirectory } from "../../utils/paths.js";
|
|
16
|
+
import { smithyCliCommand, smithyMavenVersions, warnIfSmithyMissing } from "../../utils/smithy.js";
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
name: '@rollup/plugin-esm-shim'
|
|
30
|
-
}
|
|
31
|
-
];
|
|
32
|
-
export const DEPENDENCIES = declareDependencies()({
|
|
18
|
+
* Only a service project generates a Server SDK, so only a service needs the
|
|
19
|
+
* bundler that turns it into the single module its backend imports. A shape
|
|
20
|
+
* library assembles a model and stops.
|
|
21
|
+
*/ const isService = (metadata)=>metadata.smithyType === 'service';
|
|
22
|
+
/**
|
|
23
|
+
* Everything a Smithy build runs, all of it workspace tooling in the root
|
|
24
|
+
* manifest rather than anything the model itself imports.
|
|
25
|
+
*
|
|
26
|
+
* Neither the Smithy CLI nor `mise` is among them: the compile target fetches mise
|
|
27
|
+
* with `npx` and mise resolves the CLI, so neither is a workspace dependency — see
|
|
28
|
+
* `utils/smithy.ts`.
|
|
29
|
+
*/ export const DEPENDENCIES = declareDependencies()({
|
|
33
30
|
ts: [
|
|
34
|
-
|
|
35
|
-
...ownedElsewhere(
|
|
31
|
+
// Added to the root by `FsCommands` as it builds each command.
|
|
32
|
+
...ownedElsewhere(FS_DEPENDENCIES),
|
|
33
|
+
{
|
|
34
|
+
name: 'rolldown',
|
|
35
|
+
dev: true,
|
|
36
|
+
root: true,
|
|
37
|
+
when: isService
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'rolldown-plugin-dts',
|
|
41
|
+
dev: true,
|
|
42
|
+
root: true,
|
|
43
|
+
when: isService
|
|
44
|
+
},
|
|
45
|
+
// Resolved by `rolldown-plugin-dts` to emit the bundled declaration.
|
|
46
|
+
{
|
|
47
|
+
name: 'typescript',
|
|
48
|
+
dev: true,
|
|
49
|
+
root: true,
|
|
50
|
+
when: isService
|
|
51
|
+
}
|
|
36
52
|
]
|
|
37
53
|
});
|
|
38
54
|
export const SMITHY_PROJECT_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
55
|
+
/**
|
|
56
|
+
* Where the Smithy CLI writes its artifacts, and where the build publishes the
|
|
57
|
+
* ones consumers read. Both sit under `dist` so a build writes nothing into the
|
|
58
|
+
* project, keeping the source tree clean and the target's outputs cacheable.
|
|
59
|
+
*
|
|
60
|
+
* The CLI's own output is kept beside the published tree rather than inside it:
|
|
61
|
+
* it holds the generated SSDK package and its installed `node_modules`, which
|
|
62
|
+
* must not be mistaken for a build artifact.
|
|
63
|
+
*/ const SMITHY_OUT_DIR = 'dist/{projectRoot}/smithy';
|
|
64
|
+
const BUILD_DIR = 'dist/{projectRoot}/build';
|
|
65
|
+
/** The projection every generated `smithy-build.json` builds. */ const SOURCE_PROJECTION = `${SMITHY_OUT_DIR}/source`;
|
|
66
|
+
/** Where the generated TypeScript Server SDK lands before it is bundled. */ const SSDK_CODEGEN_DIR = `${SOURCE_PROJECTION}/typescript-ssdk-codegen`;
|
|
67
|
+
/**
|
|
68
|
+
* The commands that build a Smithy project's model, run from the workspace root.
|
|
69
|
+
*
|
|
70
|
+
* This is the whole of a shape library's build. A service's Server SDK is built
|
|
71
|
+
* separately by {@link smithyGenerateSsdkCommands}, from the codegen output this
|
|
72
|
+
* leaves under {@link SMITHY_OUT_DIR}.
|
|
73
|
+
*/ export const smithyCompileCommands = (cmd, type)=>[
|
|
74
|
+
cmd.rm(BUILD_DIR),
|
|
75
|
+
cmd.rm(SMITHY_OUT_DIR),
|
|
76
|
+
cmd.mkdir(BUILD_DIR),
|
|
77
|
+
// `imports` in smithy-build.json resolve relative to that file, so a shape
|
|
78
|
+
// library is referenced by its path from the consuming project.
|
|
79
|
+
`${smithyCliCommand()} build -c {projectRoot}/smithy-build.json --output ${SMITHY_OUT_DIR}`,
|
|
80
|
+
...type === 'shapes' ? [
|
|
81
|
+
cmd.cp(`${SOURCE_PROJECTION}/model/model.json`, `${BUILD_DIR}/model.json`)
|
|
82
|
+
] : [
|
|
83
|
+
// Named after the service shape by the OpenAPI plugin, so it is matched
|
|
84
|
+
// rather than named, and published under a stable name.
|
|
85
|
+
cmd.cpGlobToFile(`${SOURCE_PROJECTION}/openapi/*.openapi.json`, `${BUILD_DIR}/openapi`, 'openapi.json')
|
|
86
|
+
]
|
|
87
|
+
];
|
|
88
|
+
/**
|
|
89
|
+
* The commands that turn a service's generated TypeScript Server SDK into the
|
|
90
|
+
* single module its consumer imports, run from the workspace root.
|
|
91
|
+
*
|
|
92
|
+
* Only a service has one, and it reads what the model build left behind, so this
|
|
93
|
+
* runs after `compile`.
|
|
94
|
+
*/ export const smithyGenerateSsdkCommands = ()=>[
|
|
95
|
+
// `npm` regardless of the workspace's package manager: this installs a generated
|
|
96
|
+
// package under `dist` that is not a workspace member, and npm ships with Node so
|
|
97
|
+
// it is always present. It reads the user's `.npmrc`, so a private registry still
|
|
98
|
+
// applies. `--include=dev` because the bundler resolves types from the generated
|
|
99
|
+
// package's devDependencies, which `NODE_ENV=production` would otherwise omit.
|
|
100
|
+
`npm install --prefix ${SSDK_CODEGEN_DIR} --include=dev --ignore-scripts --no-audit --no-fund`,
|
|
101
|
+
// Bundled straight from the generated TypeScript sources, emitting the module and
|
|
102
|
+
// its declarations together — see ssdk.rolldown.config.mjs for why the sources
|
|
103
|
+
// rather than a `tsc` pre-pass.
|
|
104
|
+
`rolldown -c {projectRoot}/ssdk.rolldown.config.mjs`
|
|
105
|
+
];
|
|
106
|
+
/**
|
|
107
|
+
* What the model build publishes, listed per artifact rather than as the whole
|
|
108
|
+
* `build` directory: a service's `generate-ssdk` writes into that directory too, and
|
|
109
|
+
* restoring `compile` from cache would otherwise discard the Server SDK beside it.
|
|
110
|
+
*/ export const smithyCompileOutputs = (type)=>[
|
|
111
|
+
`{workspaceRoot}/${SMITHY_OUT_DIR}`,
|
|
112
|
+
type === 'shapes' ? `{workspaceRoot}/${BUILD_DIR}/model.json` : `{workspaceRoot}/${BUILD_DIR}/openapi`
|
|
113
|
+
];
|
|
114
|
+
/**
|
|
115
|
+
* The target that builds a service's Server SDK, shared with the migration moving
|
|
116
|
+
* an existing project onto it.
|
|
117
|
+
*/ export const smithyGenerateSsdkTarget = ()=>({
|
|
118
|
+
cache: true,
|
|
119
|
+
outputs: [
|
|
120
|
+
`{workspaceRoot}/${BUILD_DIR}/ssdk`
|
|
121
|
+
],
|
|
122
|
+
executor: 'nx:run-commands',
|
|
123
|
+
dependsOn: [
|
|
124
|
+
'compile'
|
|
125
|
+
],
|
|
126
|
+
options: {
|
|
127
|
+
commands: smithyGenerateSsdkCommands(),
|
|
128
|
+
parallel: false,
|
|
129
|
+
cwd: '{workspaceRoot}'
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* Write the rolldown config that bundles a service's generated Server SDK.
|
|
134
|
+
*
|
|
135
|
+
* Shared with the migration moving an existing project off the container build,
|
|
136
|
+
* so a migrated project's config cannot drift from a freshly generated one.
|
|
137
|
+
*/ export const writeSsdkBundleConfig = (tree, projectRoot)=>generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'ssdk-bundle'), projectRoot, // The config's paths are workspace-root relative, so it needs only the
|
|
138
|
+
// project's root — the compile target runs from the workspace root.
|
|
139
|
+
{
|
|
140
|
+
projectRoot
|
|
141
|
+
}, // Generated configuration rather than anything the user edits, so a re-run
|
|
142
|
+
// refreshes it — unlike the models beside it.
|
|
143
|
+
{
|
|
144
|
+
overwriteStrategy: OverwriteStrategy.Overwrite
|
|
145
|
+
});
|
|
39
146
|
export const smithyProjectGenerator = async (tree, options)=>{
|
|
40
147
|
const cmd = new FsCommands(tree, DEPENDENCIES);
|
|
41
|
-
const containers = await resolveContainers(tree, 'inherit');
|
|
42
148
|
const type = options.type ?? 'service';
|
|
43
149
|
// Create project.json
|
|
44
150
|
const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);
|
|
@@ -50,28 +156,27 @@ export const smithyProjectGenerator = async (tree, options)=>{
|
|
|
50
156
|
projectType: 'library',
|
|
51
157
|
targets: {
|
|
52
158
|
build: {
|
|
53
|
-
dependsOn: [
|
|
159
|
+
dependsOn: type === 'shapes' ? [
|
|
54
160
|
'compile'
|
|
161
|
+
] : [
|
|
162
|
+
'compile',
|
|
163
|
+
'generate-ssdk'
|
|
55
164
|
]
|
|
56
165
|
},
|
|
57
166
|
compile: {
|
|
58
167
|
cache: true,
|
|
59
|
-
outputs:
|
|
60
|
-
'{workspaceRoot}/dist/{projectRoot}/build'
|
|
61
|
-
],
|
|
168
|
+
outputs: smithyCompileOutputs(type),
|
|
62
169
|
executor: 'nx:run-commands',
|
|
63
170
|
options: {
|
|
64
|
-
commands:
|
|
65
|
-
cmd.rm('dist/{projectRoot}/build'),
|
|
66
|
-
cmd.mkdir('dist/{projectRoot}/build'),
|
|
67
|
-
// The workspace build context lets a project's Dockerfile copy in
|
|
68
|
-
// the built models of shape libraries it depends on. Commands run
|
|
69
|
-
// from the workspace root, so it is the current directory.
|
|
70
|
-
`${containers} build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}`
|
|
71
|
-
],
|
|
171
|
+
commands: smithyCompileCommands(cmd, type),
|
|
72
172
|
parallel: false,
|
|
73
173
|
cwd: '{workspaceRoot}'
|
|
74
174
|
}
|
|
175
|
+
},
|
|
176
|
+
// Only a service generates a Server SDK, and it is built from what the
|
|
177
|
+
// model build leaves behind.
|
|
178
|
+
...type === 'shapes' ? {} : {
|
|
179
|
+
'generate-ssdk': smithyGenerateSsdkTarget()
|
|
75
180
|
}
|
|
76
181
|
}
|
|
77
182
|
});
|
|
@@ -86,23 +191,40 @@ export const smithyProjectGenerator = async (tree, options)=>{
|
|
|
86
191
|
serviceNameClassName,
|
|
87
192
|
serviceNameKebabCase,
|
|
88
193
|
scope,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
194
|
+
projectRoot: dir,
|
|
195
|
+
relativePathToWorkspaceRoot: getRelativePathToRootByDirectory(dir),
|
|
196
|
+
...smithyMavenVersions()
|
|
92
197
|
}, {
|
|
93
198
|
// Smithy models are user-owned — a re-run must not discard edits
|
|
94
199
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
95
200
|
});
|
|
96
|
-
|
|
201
|
+
if (type === 'service') {
|
|
202
|
+
writeSsdkBundleConfig(tree, dir);
|
|
203
|
+
}
|
|
204
|
+
// Recorded here and read by the declaration's predicates, so the packages
|
|
205
|
+
// added below are exactly the ones the version sync will own.
|
|
206
|
+
const metadata = {
|
|
97
207
|
smithyType: type,
|
|
98
|
-
namespace
|
|
208
|
+
namespace
|
|
209
|
+
};
|
|
210
|
+
addGeneratorMetadata(tree, fullyQualifiedName, SMITHY_PROJECT_GENERATOR_INFO, {
|
|
211
|
+
...metadata,
|
|
99
212
|
...type === 'service' ? {
|
|
100
213
|
apiName: options.name
|
|
101
214
|
} : {}
|
|
102
215
|
});
|
|
216
|
+
// No projectRoot: a Smithy model project has no manifest of its own, and every
|
|
217
|
+
// dependency here is workspace tooling the build runs rather than anything the
|
|
218
|
+
// model imports.
|
|
219
|
+
addTsDependencies(tree, DEPENDENCIES, {
|
|
220
|
+
metadata
|
|
221
|
+
});
|
|
103
222
|
await addGeneratorMetricsIfApplicable(tree, [
|
|
104
223
|
SMITHY_PROJECT_GENERATOR_INFO
|
|
105
224
|
]);
|
|
225
|
+
// On Windows the build runs the Smithy CLI from the PATH rather than through
|
|
226
|
+
// mise, so flag a missing prerequisite while the project is still being set up.
|
|
227
|
+
warnIfSmithyMissing();
|
|
106
228
|
await formatFilesInSubtree(tree);
|
|
107
229
|
return ()=>installDependencies(tree, options.preferInstallDependencies, {
|
|
108
230
|
languages: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n} from '@nx/devkit';\nimport { getTsLibDetails } from '../../ts/lib/generator';\nimport { resolveContainers } from '../../utils/containers';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toClassName, toKebabCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport { type ITsDepVersion, TS_VERSIONS } from '../../utils/versions';\nimport type { SmithyProjectGeneratorSchema } from './schema';\n\n/**\n * Packages `build.Dockerfile` installs into the build image to bundle the Smithy\n * SSDK. Pinned in the file body rather than declared in a manifest, so declaring\n * them here — never installed into the workspace — is what keeps the version sync\n * moving them forward.\n */\nexport const SSDK_BUNDLE_DEPENDENCIES = [\n { name: 'rolldown' },\n { name: 'rolldown-plugin-dts' },\n { name: '@rollup/plugin-esm-shim' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...FS_DEPENDENCIES, ...ownedElsewhere(SSDK_BUNDLE_DEPENDENCIES)],\n});\n\nexport const SMITHY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const smithyProjectGenerator = async (\n tree: Tree,\n options: SmithyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const cmd = new FsCommands(tree, DEPENDENCIES);\n const containers = await resolveContainers(tree, 'inherit');\n const type = options.type ?? 'service';\n\n // Create project.json\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n\n if (!projectExists(tree, fullyQualifiedName)) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'library',\n targets: {\n build: {\n dependsOn: ['compile'],\n },\n compile: {\n cache: true,\n outputs: ['{workspaceRoot}/dist/{projectRoot}/build'],\n executor: 'nx:run-commands',\n options: {\n commands: [\n cmd.rm('dist/{projectRoot}/build'),\n cmd.mkdir('dist/{projectRoot}/build'),\n // The workspace build context lets a project's Dockerfile copy in\n // the built models of shape libraries it depends on. Commands run\n // from the workspace root, so it is the current directory.\n `${containers} build -f {projectRoot}/build.Dockerfile --build-context workspace=. --target export --output type=local,dest=dist/{projectRoot}/build {projectRoot}`,\n ],\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n },\n },\n });\n }\n\n const serviceName = options.serviceName ?? options.name;\n const serviceNameClassName = toClassName(serviceName);\n const serviceNameKebabCase = toKebabCase(serviceName);\n const scope = getNpmScope(tree);\n const namespace = options.namespace ?? toKebabCase(scope).replace(/-/g, '.');\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', type),\n dir,\n {\n namespace,\n serviceNameClassName,\n serviceNameKebabCase,\n scope,\n rolldownVersion: TS_VERSIONS.rolldown,\n rolldownDtsVersion: TS_VERSIONS['rolldown-plugin-dts'],\n esmShimVersion: TS_VERSIONS['@rollup/plugin-esm-shim'],\n },\n {\n // Smithy models are user-owned — a re-run must not discard edits\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n SMITHY_PROJECT_GENERATOR_INFO,\n {\n smithyType: type,\n namespace,\n ...(type === 'service' ? { apiName: options.name } : {}),\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [SMITHY_PROJECT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default smithyProjectGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","getTsLibDetails","resolveContainers","declareDependencies","ownedElsewhere","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","getNpmScope","addGeneratorMetadata","getGeneratorInfo","projectExists","TS_VERSIONS","SSDK_BUNDLE_DEPENDENCIES","name","DEPENDENCIES","ts","SMITHY_PROJECT_GENERATOR_INFO","filename","smithyProjectGenerator","tree","options","cmd","containers","type","fullyQualifiedName","dir","root","sourceRoot","projectType","targets","build","dependsOn","compile","cache","outputs","executor","commands","rm","mkdir","parallel","cwd","serviceName","serviceNameClassName","serviceNameKebabCase","scope","namespace","replace","dirname","rolldownVersion","rolldown","rolldownDtsVersion","esmShimVersion","overwriteStrategy","KeepExisting","smithyType","apiName","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAEZ,aAAa;AACpB,SAASC,eAAe,QAAQ,4BAAyB;AACzD,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAoC;AAC3C,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAiB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,WAAW,EAAEC,WAAW,QAAQ,uBAAoB;AAC7D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAiB;AACxB,SAA6BC,WAAW,QAAQ,0BAAuB;AAGvE;;;;;CAKC,GACD,OAAO,MAAMC,2BAA2B;IACtC;QAAEC,MAAM;IAAW;IACnB;QAAEA,MAAM;IAAsB;IAC9B;QAAEA,MAAM;IAA0B;CACnC,CAAuD;AAExD,OAAO,MAAMC,eAAehB,sBAAsB;IAChDiB,IAAI;WAAId;WAAoBF,eAAea;KAA0B;AACvE,GAAG;AAEH,OAAO,MAAMI,gCAAiDP,iBAC5D,YAAYQ,QAAQ,EACpB;AAEF,OAAO,MAAMC,yBAAyB,OACpCC,MACAC;IAEA,MAAMC,MAAM,IAAInB,WAAWiB,MAAML;IACjC,MAAMQ,aAAa,MAAMzB,kBAAkBsB,MAAM;IACjD,MAAMI,OAAOH,QAAQG,IAAI,IAAI;IAE7B,sBAAsB;IACtB,MAAM,EAAEC,kBAAkB,EAAEC,GAAG,EAAE,GAAG7B,gBAAgBuB,MAAMC;IAE1D,IAAI,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BAAoBgB,MAAMC,QAAQoC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAevC,uBAAuB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n} from '@nx/devkit';\nimport { getTsLibDetails } from '../../ts/lib/generator';\nimport { addTsDependencies } from '../../utils/add-dependencies';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toClassName, toKebabCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths';\nimport {\n smithyCliCommand,\n smithyMavenVersions,\n warnIfSmithyMissing,\n} from '../../utils/smithy';\nimport type { SmithyProjectGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface SmithyProjectMetadata {\n readonly smithyType: NonNullable<SmithyProjectGeneratorSchema['type']>;\n readonly namespace: string;\n}\n\n/**\n * Only a service project generates a Server SDK, so only a service needs the\n * bundler that turns it into the single module its backend imports. A shape\n * library assembles a model and stops.\n */\nconst isService = (metadata: SmithyProjectMetadata) =>\n metadata.smithyType === 'service';\n\n/**\n * Everything a Smithy build runs, all of it workspace tooling in the root\n * manifest rather than anything the model itself imports.\n *\n * Neither the Smithy CLI nor `mise` is among them: the compile target fetches mise\n * with `npx` and mise resolves the CLI, so neither is a workspace dependency — see\n * `utils/smithy.ts`.\n */\nexport const DEPENDENCIES = declareDependencies<SmithyProjectMetadata>()({\n ts: [\n // Added to the root by `FsCommands` as it builds each command.\n ...ownedElsewhere(FS_DEPENDENCIES),\n { name: 'rolldown', dev: true, root: true, when: isService },\n { name: 'rolldown-plugin-dts', dev: true, root: true, when: isService },\n // Resolved by `rolldown-plugin-dts` to emit the bundled declaration.\n { name: 'typescript', dev: true, root: true, when: isService },\n ],\n});\n\nexport const SMITHY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Where the Smithy CLI writes its artifacts, and where the build publishes the\n * ones consumers read. Both sit under `dist` so a build writes nothing into the\n * project, keeping the source tree clean and the target's outputs cacheable.\n *\n * The CLI's own output is kept beside the published tree rather than inside it:\n * it holds the generated SSDK package and its installed `node_modules`, which\n * must not be mistaken for a build artifact.\n */\nconst SMITHY_OUT_DIR = 'dist/{projectRoot}/smithy';\nconst BUILD_DIR = 'dist/{projectRoot}/build';\n\n/** The projection every generated `smithy-build.json` builds. */\nconst SOURCE_PROJECTION = `${SMITHY_OUT_DIR}/source`;\n\n/** Where the generated TypeScript Server SDK lands before it is bundled. */\nconst SSDK_CODEGEN_DIR = `${SOURCE_PROJECTION}/typescript-ssdk-codegen`;\n\n/**\n * The commands that build a Smithy project's model, run from the workspace root.\n *\n * This is the whole of a shape library's build. A service's Server SDK is built\n * separately by {@link smithyGenerateSsdkCommands}, from the codegen output this\n * leaves under {@link SMITHY_OUT_DIR}.\n */\nexport const smithyCompileCommands = (\n cmd: FsCommands<typeof DEPENDENCIES>,\n type: SmithyProjectGeneratorSchema['type'],\n): string[] => [\n cmd.rm(BUILD_DIR),\n cmd.rm(SMITHY_OUT_DIR),\n cmd.mkdir(BUILD_DIR),\n // `imports` in smithy-build.json resolve relative to that file, so a shape\n // library is referenced by its path from the consuming project.\n `${smithyCliCommand()} build -c {projectRoot}/smithy-build.json --output ${SMITHY_OUT_DIR}`,\n ...(type === 'shapes'\n ? [\n cmd.cp(\n `${SOURCE_PROJECTION}/model/model.json`,\n `${BUILD_DIR}/model.json`,\n ),\n ]\n : [\n // Named after the service shape by the OpenAPI plugin, so it is matched\n // rather than named, and published under a stable name.\n cmd.cpGlobToFile(\n `${SOURCE_PROJECTION}/openapi/*.openapi.json`,\n `${BUILD_DIR}/openapi`,\n 'openapi.json',\n ),\n ]),\n];\n\n/**\n * The commands that turn a service's generated TypeScript Server SDK into the\n * single module its consumer imports, run from the workspace root.\n *\n * Only a service has one, and it reads what the model build left behind, so this\n * runs after `compile`.\n */\nexport const smithyGenerateSsdkCommands = (): string[] => [\n // `npm` regardless of the workspace's package manager: this installs a generated\n // package under `dist` that is not a workspace member, and npm ships with Node so\n // it is always present. It reads the user's `.npmrc`, so a private registry still\n // applies. `--include=dev` because the bundler resolves types from the generated\n // package's devDependencies, which `NODE_ENV=production` would otherwise omit.\n `npm install --prefix ${SSDK_CODEGEN_DIR} --include=dev --ignore-scripts --no-audit --no-fund`,\n // Bundled straight from the generated TypeScript sources, emitting the module and\n // its declarations together — see ssdk.rolldown.config.mjs for why the sources\n // rather than a `tsc` pre-pass.\n `rolldown -c {projectRoot}/ssdk.rolldown.config.mjs`,\n];\n\n/**\n * What the model build publishes, listed per artifact rather than as the whole\n * `build` directory: a service's `generate-ssdk` writes into that directory too, and\n * restoring `compile` from cache would otherwise discard the Server SDK beside it.\n */\nexport const smithyCompileOutputs = (\n type: SmithyProjectGeneratorSchema['type'],\n): string[] => [\n `{workspaceRoot}/${SMITHY_OUT_DIR}`,\n type === 'shapes'\n ? `{workspaceRoot}/${BUILD_DIR}/model.json`\n : `{workspaceRoot}/${BUILD_DIR}/openapi`,\n];\n\n/**\n * The target that builds a service's Server SDK, shared with the migration moving\n * an existing project onto it.\n */\nexport const smithyGenerateSsdkTarget = () => ({\n cache: true,\n outputs: [`{workspaceRoot}/${BUILD_DIR}/ssdk`],\n executor: 'nx:run-commands',\n dependsOn: ['compile'],\n options: {\n commands: smithyGenerateSsdkCommands(),\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n});\n\n/**\n * Write the rolldown config that bundles a service's generated Server SDK.\n *\n * Shared with the migration moving an existing project off the container build,\n * so a migrated project's config cannot drift from a freshly generated one.\n */\nexport const writeSsdkBundleConfig = (tree: Tree, projectRoot: string): void =>\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'ssdk-bundle'),\n projectRoot,\n // The config's paths are workspace-root relative, so it needs only the\n // project's root — the compile target runs from the workspace root.\n { projectRoot },\n // Generated configuration rather than anything the user edits, so a re-run\n // refreshes it — unlike the models beside it.\n { overwriteStrategy: OverwriteStrategy.Overwrite },\n );\n\nexport const smithyProjectGenerator = async (\n tree: Tree,\n options: SmithyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const cmd = new FsCommands(tree, DEPENDENCIES);\n const type = options.type ?? 'service';\n\n // Create project.json\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n\n if (!projectExists(tree, fullyQualifiedName)) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'library',\n targets: {\n build: {\n dependsOn:\n type === 'shapes' ? ['compile'] : ['compile', 'generate-ssdk'],\n },\n compile: {\n cache: true,\n outputs: smithyCompileOutputs(type),\n executor: 'nx:run-commands',\n options: {\n commands: smithyCompileCommands(cmd, type),\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n },\n // Only a service generates a Server SDK, and it is built from what the\n // model build leaves behind.\n ...(type === 'shapes'\n ? {}\n : { 'generate-ssdk': smithyGenerateSsdkTarget() }),\n },\n });\n }\n\n const serviceName = options.serviceName ?? options.name;\n const serviceNameClassName = toClassName(serviceName);\n const serviceNameKebabCase = toKebabCase(serviceName);\n const scope = getNpmScope(tree);\n const namespace = options.namespace ?? toKebabCase(scope).replace(/-/g, '.');\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', type),\n dir,\n {\n namespace,\n serviceNameClassName,\n serviceNameKebabCase,\n scope,\n projectRoot: dir,\n relativePathToWorkspaceRoot: getRelativePathToRootByDirectory(dir),\n ...smithyMavenVersions(),\n },\n {\n // Smithy models are user-owned — a re-run must not discard edits\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n if (type === 'service') {\n writeSsdkBundleConfig(tree, dir);\n }\n\n // Recorded here and read by the declaration's predicates, so the packages\n // added below are exactly the ones the version sync will own.\n const metadata: SmithyProjectMetadata = { smithyType: type, namespace };\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n SMITHY_PROJECT_GENERATOR_INFO,\n {\n ...metadata,\n ...(type === 'service' ? { apiName: options.name } : {}),\n },\n );\n\n // No projectRoot: a Smithy model project has no manifest of its own, and every\n // dependency here is workspace tooling the build runs rather than anything the\n // model imports.\n addTsDependencies(tree, DEPENDENCIES, { metadata });\n\n await addGeneratorMetricsIfApplicable(tree, [SMITHY_PROJECT_GENERATOR_INFO]);\n\n // On Windows the build runs the Smithy CLI from the PATH rather than through\n // mise, so flag a missing prerequisite while the project is still being set up.\n warnIfSmithyMissing();\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default smithyProjectGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","getTsLibDetails","addTsDependencies","declareDependencies","ownedElsewhere","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","getNpmScope","addGeneratorMetadata","getGeneratorInfo","projectExists","getRelativePathToRootByDirectory","smithyCliCommand","smithyMavenVersions","warnIfSmithyMissing","isService","metadata","smithyType","DEPENDENCIES","ts","name","dev","root","when","SMITHY_PROJECT_GENERATOR_INFO","filename","SMITHY_OUT_DIR","BUILD_DIR","SOURCE_PROJECTION","SSDK_CODEGEN_DIR","smithyCompileCommands","cmd","type","rm","mkdir","cp","cpGlobToFile","smithyGenerateSsdkCommands","smithyCompileOutputs","smithyGenerateSsdkTarget","cache","outputs","executor","dependsOn","options","commands","parallel","cwd","writeSsdkBundleConfig","tree","projectRoot","dirname","overwriteStrategy","Overwrite","smithyProjectGenerator","fullyQualifiedName","dir","sourceRoot","projectType","targets","build","compile","serviceName","serviceNameClassName","serviceNameKebabCase","scope","namespace","replace","relativePathToWorkspaceRoot","KeepExisting","apiName","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAEZ,aAAa;AACpB,SAASC,eAAe,QAAQ,4BAAyB;AACzD,SAASC,iBAAiB,QAAQ,kCAA+B;AACjE,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAoC;AAC3C,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAiB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,WAAW,EAAEC,WAAW,QAAQ,uBAAoB;AAC7D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAiB;AACxB,SAASC,gCAAgC,QAAQ,uBAAoB;AACrE,SACEC,gBAAgB,EAChBC,mBAAmB,EACnBC,mBAAmB,QACd,wBAAqB;AAS5B;;;;CAIC,GACD,MAAMC,YAAY,CAACC,WACjBA,SAASC,UAAU,KAAK;AAE1B;;;;;;;CAOC,GACD,OAAO,MAAMC,eAAepB,sBAA6C;IACvEqB,IAAI;QACF,+DAA+D;WAC5DpB,eAAeE;QAClB;YAAEmB,MAAM;YAAYC,KAAK;YAAMC,MAAM;YAAMC,MAAMR;QAAU;QAC3D;YAAEK,MAAM;YAAuBC,KAAK;YAAMC,MAA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1751
1751
|
},
|
|
1752
1752
|
"targets": {
|
|
1753
1753
|
"build": {
|
|
1754
|
-
"dependsOn": ["compile"]
|
|
1754
|
+
"dependsOn": ["compile", "generate-ssdk"]
|
|
1755
1755
|
},
|
|
1756
1756
|
"compile": {
|
|
1757
1757
|
"cache": true,
|
|
1758
|
-
"outputs": [
|
|
1758
|
+
"outputs": [
|
|
1759
|
+
"{workspaceRoot}/dist/{projectRoot}/smithy",
|
|
1760
|
+
"{workspaceRoot}/dist/{projectRoot}/build/openapi"
|
|
1761
|
+
],
|
|
1759
1762
|
"executor": "nx:run-commands",
|
|
1760
1763
|
"options": {
|
|
1761
1764
|
"commands": [
|
|
1762
1765
|
"rimraf dist/{projectRoot}/build",
|
|
1766
|
+
"rimraf dist/{projectRoot}/smithy",
|
|
1763
1767
|
"make-dir dist/{projectRoot}/build",
|
|
1764
|
-
"
|
|
1768
|
+
"npx -y mise@2026.8.3 exec smithy@1.72.1 -- smithy build -c {projectRoot}/smithy-build.json --output dist/{projectRoot}/smithy",
|
|
1769
|
+
"cpy \\"dist/{projectRoot}/smithy/source/openapi/*.openapi.json\\" dist/{projectRoot}/build/openapi --flat --rename=openapi.json"
|
|
1770
|
+
],
|
|
1771
|
+
"parallel": false,
|
|
1772
|
+
"cwd": "{workspaceRoot}"
|
|
1773
|
+
}
|
|
1774
|
+
},
|
|
1775
|
+
"generate-ssdk": {
|
|
1776
|
+
"cache": true,
|
|
1777
|
+
"outputs": ["{workspaceRoot}/dist/{projectRoot}/build/ssdk"],
|
|
1778
|
+
"executor": "nx:run-commands",
|
|
1779
|
+
"dependsOn": ["compile"],
|
|
1780
|
+
"options": {
|
|
1781
|
+
"commands": [
|
|
1782
|
+
"npm install --prefix dist/{projectRoot}/smithy/source/typescript-ssdk-codegen --include=dev --ignore-scripts --no-audit --no-fund",
|
|
1783
|
+
"rolldown -c {projectRoot}/ssdk.rolldown.config.mjs"
|
|
1765
1784
|
],
|
|
1766
1785
|
"parallel": false,
|
|
1767
1786
|
"cwd": "{workspaceRoot}"
|
|
@@ -50,6 +50,10 @@ export declare const DEPENDENCIES: import("../../../utils/declared-dependencies"
|
|
|
50
50
|
readonly name: "make-dir-cli";
|
|
51
51
|
} & {
|
|
52
52
|
versionOnly: true;
|
|
53
|
+
}, {
|
|
54
|
+
readonly name: "cpy-cli";
|
|
55
|
+
} & {
|
|
56
|
+
versionOnly: true;
|
|
53
57
|
}, {
|
|
54
58
|
readonly name: "@aws-sdk/client-api-gateway";
|
|
55
59
|
readonly when: (m: IacMetadata) => boolean;
|
|
@@ -144,6 +144,10 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies").D
|
|
|
144
144
|
readonly name: "make-dir-cli";
|
|
145
145
|
} & {
|
|
146
146
|
versionOnly: true;
|
|
147
|
+
}, {
|
|
148
|
+
readonly name: "cpy-cli";
|
|
149
|
+
} & {
|
|
150
|
+
versionOnly: true;
|
|
147
151
|
}, {
|
|
148
152
|
readonly name: "ncp";
|
|
149
153
|
} & {
|
|
@@ -156,6 +160,10 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies").D
|
|
|
156
160
|
readonly name: "make-dir-cli";
|
|
157
161
|
} & {
|
|
158
162
|
versionOnly: true;
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "cpy-cli";
|
|
165
|
+
} & {
|
|
166
|
+
versionOnly: true;
|
|
159
167
|
}, {
|
|
160
168
|
readonly name: "constructs";
|
|
161
169
|
readonly when: (m: IacMetadata) => boolean;
|
|
@@ -4,7 +4,7 @@ exports[`vitest utils > should generate a valid vitest.config.mts without a doub
|
|
|
4
4
|
"import { defineConfig } from 'vitest/config';
|
|
5
5
|
|
|
6
6
|
export default defineConfig(() => ({
|
|
7
|
-
root:
|
|
7
|
+
root: import.meta.dirname,
|
|
8
8
|
cacheDir: '../node_modules/.vite/test',
|
|
9
9
|
test: {
|
|
10
10
|
passWithNoTests: true,
|
package/src/ts/lib/vitest.js
CHANGED
|
@@ -9,6 +9,17 @@ import { forDependencies } from "../../utils/declared-dependencies.js";
|
|
|
9
9
|
import { addDependenciesToPackageJson } from "../../utils/dependencies.js";
|
|
10
10
|
import { withVersions } from "../../utils/versions.js";
|
|
11
11
|
const readGritPattern = (name)=>readFileSync(join(import.meta.dirname, 'grit', `${name}.grit`), 'utf-8').trim();
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the config's `root` from `import.meta.dirname`.
|
|
14
|
+
*
|
|
15
|
+
* `@nx/js` writes `root: __dirname`, which Vite's native config loader does not
|
|
16
|
+
* provide — it warns today and will reject once `configLoader: 'native'` becomes
|
|
17
|
+
* the default. Scoped with `some` to a direct property of the object the config
|
|
18
|
+
* factory returns, so a nested `root` (a `test.alias` entry, say) is untouched.
|
|
19
|
+
*/ const ROOT_IMPORT_META_DIRNAME = `\`defineConfig(() => ({ $props }))\` where {
|
|
20
|
+
$props <: some \`root: __dirname\` as $root,
|
|
21
|
+
$root => \`root: import.meta.dirname\`
|
|
22
|
+
}`;
|
|
12
23
|
/** Dependencies a caller must declare to configure vitest. */ export const VITEST_DEPENDENCIES = [
|
|
13
24
|
{
|
|
14
25
|
name: 'vite'
|
|
@@ -28,6 +39,7 @@ export const configureVitest = async (tree, options, declaration)=>{
|
|
|
28
39
|
].find((config)=>tree.exists(config));
|
|
29
40
|
if (configPath) {
|
|
30
41
|
await applyGritQL(tree, configPath, readGritPattern('vitest-pass-with-no-tests'));
|
|
42
|
+
await applyGritQL(tree, configPath, ROOT_IMPORT_META_DIRNAME);
|
|
31
43
|
const nxJson = readNxJson(tree);
|
|
32
44
|
updateNxJson(tree, {
|
|
33
45
|
...nxJson,
|
package/src/ts/lib/vitest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/vitest.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { readNxJson, type Tree, updateNxJson } from '@nx/devkit';\nimport { readFileSync } from 'fs';\nimport { join } from 'path';\nimport { applyGritQL } from '../../utils/ast';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../utils/declared-dependencies';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies';\nimport { type ITsDepVersion, withVersions } from '../../utils/versions';\nimport type { ConfigureProjectOptions } from './types';\n\nconst readGritPattern = (name: string): string =>\n readFileSync(\n join(import.meta.dirname, 'grit', `${name}.grit`),\n 'utf-8',\n ).trim();\n\n/** Dependencies a caller must declare to configure vitest. */\nexport const VITEST_DEPENDENCIES = [\n { name: 'vite' },\n { name: 'vitest' },\n { name: '@vitest/coverage-v8' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport const configureVitest = async <const D extends DependencyDeclaration>(\n tree: Tree,\n options: ConfigureProjectOptions,\n declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D>,\n) => {\n // Find vitest.config.mts or vite.config.mts\n const configPath = [\n join(options.dir, 'vitest.config.mts'),\n join(options.dir, 'vite.config.mts'),\n ].find((config) => tree.exists(config));\n\n if (configPath) {\n await applyGritQL(\n tree,\n configPath,\n readGritPattern('vitest-pass-with-no-tests'),\n );\n\n const nxJson = readNxJson(tree);\n updateNxJson(tree, {\n ...nxJson,\n targetDefaults: {\n ...(nxJson.targetDefaults ?? {}),\n '@nx/vitest:test': {\n cache: true,\n inputs: ['default', '^production'],\n configurations: {\n 'update-snapshot': {\n args: '--update',\n },\n },\n ...nxJson.targetDefaults['@nx/vitest:test'],\n },\n },\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n {},\n withVersions(forDependencies<typeof VITEST_DEPENDENCIES>(declaration), [\n 'vite',\n 'vitest',\n '@vitest/coverage-v8',\n ]),\n );\n};\n"],"names":["readNxJson","updateNxJson","readFileSync","join","applyGritQL","forDependencies","addDependenciesToPackageJson","withVersions","readGritPattern","name","dirname","trim","VITEST_DEPENDENCIES","configureVitest","tree","options","declaration","configPath","dir","find","config","exists","nxJson","targetDefaults","cache","inputs","configurations","args"],"mappings":"AAAA;;;CAGC,GACD,SAASA,UAAU,EAAaC,YAAY,QAAQ,aAAa;AACjE,SAASC,YAAY,QAAQ,KAAK;AAClC,SAASC,IAAI,QAAQ,OAAO;AAC5B,SAASC,WAAW,QAAQ,qBAAkB;AAC9C,SAEEC,eAAe,QAEV,uCAAoC;AAC3C,SAASC,4BAA4B,QAAQ,8BAA2B;AACxE,SAA6BC,YAAY,QAAQ,0BAAuB;AAGxE,MAAMC,kBAAkB,CAACC,OACvBP,aACEC,KAAK,YAAYO,OAAO,EAAE,QAAQ,GAAGD,KAAK,KAAK,CAAC,GAChD,SACAE,IAAI;AAER,4DAA4D,GAC5D,OAAO,MAAMC,sBAAsB;IACjC;
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/vitest.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { readNxJson, type Tree, updateNxJson } from '@nx/devkit';\nimport { readFileSync } from 'fs';\nimport { join } from 'path';\nimport { applyGritQL } from '../../utils/ast';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../utils/declared-dependencies';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies';\nimport { type ITsDepVersion, withVersions } from '../../utils/versions';\nimport type { ConfigureProjectOptions } from './types';\n\nconst readGritPattern = (name: string): string =>\n readFileSync(\n join(import.meta.dirname, 'grit', `${name}.grit`),\n 'utf-8',\n ).trim();\n\n/**\n * Resolve the config's `root` from `import.meta.dirname`.\n *\n * `@nx/js` writes `root: __dirname`, which Vite's native config loader does not\n * provide — it warns today and will reject once `configLoader: 'native'` becomes\n * the default. Scoped with `some` to a direct property of the object the config\n * factory returns, so a nested `root` (a `test.alias` entry, say) is untouched.\n */\nconst ROOT_IMPORT_META_DIRNAME = `\\`defineConfig(() => ({ $props }))\\` where {\n $props <: some \\`root: __dirname\\` as $root,\n $root => \\`root: import.meta.dirname\\`\n}`;\n\n/** Dependencies a caller must declare to configure vitest. */\nexport const VITEST_DEPENDENCIES = [\n { name: 'vite' },\n { name: 'vitest' },\n { name: '@vitest/coverage-v8' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport const configureVitest = async <const D extends DependencyDeclaration>(\n tree: Tree,\n options: ConfigureProjectOptions,\n declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D>,\n) => {\n // Find vitest.config.mts or vite.config.mts\n const configPath = [\n join(options.dir, 'vitest.config.mts'),\n join(options.dir, 'vite.config.mts'),\n ].find((config) => tree.exists(config));\n\n if (configPath) {\n await applyGritQL(\n tree,\n configPath,\n readGritPattern('vitest-pass-with-no-tests'),\n );\n\n await applyGritQL(tree, configPath, ROOT_IMPORT_META_DIRNAME);\n\n const nxJson = readNxJson(tree);\n updateNxJson(tree, {\n ...nxJson,\n targetDefaults: {\n ...(nxJson.targetDefaults ?? {}),\n '@nx/vitest:test': {\n cache: true,\n inputs: ['default', '^production'],\n configurations: {\n 'update-snapshot': {\n args: '--update',\n },\n },\n ...nxJson.targetDefaults['@nx/vitest:test'],\n },\n },\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n {},\n withVersions(forDependencies<typeof VITEST_DEPENDENCIES>(declaration), [\n 'vite',\n 'vitest',\n '@vitest/coverage-v8',\n ]),\n );\n};\n"],"names":["readNxJson","updateNxJson","readFileSync","join","applyGritQL","forDependencies","addDependenciesToPackageJson","withVersions","readGritPattern","name","dirname","trim","ROOT_IMPORT_META_DIRNAME","VITEST_DEPENDENCIES","configureVitest","tree","options","declaration","configPath","dir","find","config","exists","nxJson","targetDefaults","cache","inputs","configurations","args"],"mappings":"AAAA;;;CAGC,GACD,SAASA,UAAU,EAAaC,YAAY,QAAQ,aAAa;AACjE,SAASC,YAAY,QAAQ,KAAK;AAClC,SAASC,IAAI,QAAQ,OAAO;AAC5B,SAASC,WAAW,QAAQ,qBAAkB;AAC9C,SAEEC,eAAe,QAEV,uCAAoC;AAC3C,SAASC,4BAA4B,QAAQ,8BAA2B;AACxE,SAA6BC,YAAY,QAAQ,0BAAuB;AAGxE,MAAMC,kBAAkB,CAACC,OACvBP,aACEC,KAAK,YAAYO,OAAO,EAAE,QAAQ,GAAGD,KAAK,KAAK,CAAC,GAChD,SACAE,IAAI;AAER;;;;;;;CAOC,GACD,MAAMC,2BAA2B,CAAC;;;CAGjC,CAAC;AAEF,4DAA4D,GAC5D,OAAO,MAAMC,sBAAsB;IACjC;QAAEJ,MAAM;IAAO;IACf;QAAEA,MAAM;IAAS;IACjB;QAAEA,MAAM;IAAsB;CAC/B,CAAuD;AAExD,OAAO,MAAMK,kBAAkB,OAC7BC,MACAC,SACAC;IAEA,4CAA4C;IAC5C,MAAMC,aAAa;QACjBf,KAAKa,QAAQG,GAAG,EAAE;QAClBhB,KAAKa,QAAQG,GAAG,EAAE;KACnB,CAACC,IAAI,CAAC,CAACC,SAAWN,KAAKO,MAAM,CAACD;IAE/B,IAAIH,YAAY;QACd,MAAMd,YACJW,MACAG,YACAV,gBAAgB;QAGlB,MAAMJ,YAAYW,MAAMG,YAAYN;QAEpC,MAAMW,SAASvB,WAAWe;QAC1Bd,aAAac,MAAM;YACjB,GAAGQ,MAAM;YACTC,gBAAgB;gBACd,GAAID,OAAOC,cAAc,IAAI,CAAC,CAAC;gBAC/B,mBAAmB;oBACjBC,OAAO;oBACPC,QAAQ;wBAAC;wBAAW;qBAAc;oBAClCC,gBAAgB;wBACd,mBAAmB;4BACjBC,MAAM;wBACR;oBACF;oBACA,GAAGL,OAAOC,cAAc,CAAC,kBAAkB;gBAC7C;YACF;QACF;IACF;IAEAlB,6BACES,MACA,CAAC,GACDR,aAAaF,gBAA4CY,cAAc;QACrE;QACA;QACA;KACD;AAEL,EAAE"}
|
|
@@ -45,6 +45,10 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies").D
|
|
|
45
45
|
readonly name: "make-dir-cli";
|
|
46
46
|
} & {
|
|
47
47
|
versionOnly: true;
|
|
48
|
+
}, {
|
|
49
|
+
readonly name: "cpy-cli";
|
|
50
|
+
} & {
|
|
51
|
+
versionOnly: true;
|
|
48
52
|
}, {
|
|
49
53
|
readonly name: "rolldown";
|
|
50
54
|
} & {
|
|
@@ -61,6 +65,10 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies").D
|
|
|
61
65
|
readonly name: "make-dir-cli";
|
|
62
66
|
} & {
|
|
63
67
|
versionOnly: true;
|
|
68
|
+
}, {
|
|
69
|
+
readonly name: "cpy-cli";
|
|
70
|
+
} & {
|
|
71
|
+
versionOnly: true;
|
|
64
72
|
}, {
|
|
65
73
|
readonly name: "constructs";
|
|
66
74
|
readonly when: (m: IacMetadata) => boolean;
|
|
@@ -206,7 +206,7 @@ exports[`nx-generator generator > within @aws/nx-plugin > should update generato
|
|
|
206
206
|
exports[`nx-generator generator > within another workspace > should generate an example schema, generator and test > local-generator.spec.ts 1`] = `
|
|
207
207
|
"import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
208
208
|
import { Tree } from '@nx/devkit';
|
|
209
|
-
import { fooBarGenerator } from './generator';
|
|
209
|
+
import { fooBarGenerator } from './generator.js';
|
|
210
210
|
|
|
211
211
|
describe('foo#bar generator', () => {
|
|
212
212
|
let tree: Tree;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
2
2
|
import { Tree } from '@nx/devkit';
|
|
3
|
-
import { <%- nameCamelCase %>Generator } from './generator';
|
|
3
|
+
import { <%- nameCamelCase %>Generator } from './generator<% if (esm) { %>.js<% } %>';
|
|
4
4
|
|
|
5
5
|
describe('<%- name %> generator', () => {
|
|
6
6
|
let tree: Tree;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Tree } from '@nx/devkit';
|
|
2
2
|
import { createTreeUsingTsSolutionSetup } from '<%- testImportPath %>';
|
|
3
|
-
import migration from './migration';
|
|
3
|
+
import migration from './migration<% if (esm) { %>.js<% } %>';
|
|
4
4
|
|
|
5
5
|
describe('<%= name %> migration', () => {
|
|
6
6
|
let tree: Tree;
|