Skip to content

Commit 290886a

Browse files
authored
Merge pull request #1116 from aligent/release/v4.1.0
Release/v4.1.0
2 parents 3b6b005 + 56b78cf commit 290886a

File tree

16 files changed

+337
-310
lines changed

16 files changed

+337
-310
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
applyTo: '**'
3+
---
4+
5+
// This file is automatically generated by Nx Console
6+
7+
You are in an nx workspace using Nx 21.3.11 and yarn as the package manager.
8+
9+
You have access to the Nx MCP server and the tools it provides. Use them. Follow these guidelines in order to best help the user:
10+
11+
# General Guidelines
12+
- When answering questions, use the nx_workspace tool first to gain an understanding of the workspace architecture
13+
- For questions around nx configuration, best practices or if you're unsure, use the nx_docs tool to get relevant, up-to-date docs!! Always use this instead of assuming things about nx configuration
14+
- If the user needs help with an Nx configuration or project graph error, use the 'nx_workspace' tool to get any errors
15+
- To help answer questions about the workspace structure or simply help with demonstrating how tasks depend on each other, use the 'nx_visualize_graph' tool
16+
17+
# Generation Guidelines
18+
If the user wants to generate something, use the following flow:
19+
20+
- learn about the nx workspace and any specifics the user needs by using the 'nx_workspace' tool and the 'nx_project_details' tool if applicable
21+
- get the available generators using the 'nx_generators' tool
22+
- decide which generator to use. If no generators seem relevant, check the 'nx_available_plugins' tool to see if the user could install a plugin to help them
23+
- get generator details using the 'nx_generator_schema' tool
24+
- you may use the 'nx_docs' tool to learn more about a specific generator or technology if you're unsure
25+
- decide which options to provide in order to best complete the user's request. Don't make any assumptions and keep the options minimalistic
26+
- open the generator UI using the 'nx_open_generate_ui' tool
27+
- wait for the user to finish the generator
28+
- read the generator log file using the 'nx_read_generator_log' tool
29+
- use the information provided in the log file to answer the user's question or continue with what they were doing
30+
31+
# Running Tasks Guidelines
32+
If the user wants help with tasks or commands (which include keywords like "test", "build", "lint", or other similar actions), use the following flow:
33+
- Use the 'nx_current_running_tasks_details' tool to get the list of tasks (this can include tasks that were completed, stopped or failed).
34+
- If there are any tasks, ask the user if they would like help with a specific task then use the 'nx_current_running_task_output' tool to get the terminal output for that task/command
35+
- Use the terminal output from 'nx_current_running_task_output' to see what's wrong and help the user fix their problem. Use the appropriate tools if necessary
36+
- If the user would like to rerun the task or command, always use `nx run <taskId>` to rerun in the terminal. This will ensure that the task will run in the nx context and will be run the same way it originally executed
37+
- If the task was marked as "continuous" do not offer to rerun the task. This task is already running and the user can see the output in the terminal. You can use 'nx_current_running_task_output' to get the output of the task to verify the output.
38+
39+
40+

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ yarn nx g service test-app --type=general
6969
# Will create a project called @services/test-app in the services/ folder
7070
```
7171

72+
Newly added service may not be detected by Nx immediately. You will need to update lockfile then reset Nx cache & stop its daemon and update Nx’s internal dependency graph and ensure your workspace is in sync.
73+
74+
```bash
75+
# Update lockfile
76+
yarn install
77+
78+
# Reset Nx cache and stop the daemon
79+
yarn nx reset
80+
81+
# Update Nx's internal dependency graph and ensure workspace is in sync
82+
yarn nx sync
83+
84+
# Alternatively, you can combine them into one line
85+
yarn install && yarn nx reset && yarn nx sync
86+
```
87+
7288
Import and instantiate the service in `ApplicationStage` inside `applications/core/bin/main.ts`:
7389

7490
```typescript
@@ -91,8 +107,6 @@ class ApplicationStage extends Stage {
91107
}
92108
```
93109

94-
Note: You will need to run `yarn install` and `yarn nx sync` before other projects will detect the new service
95-
96110
---
97111

98112
### 🧪 Testing the application
@@ -161,6 +175,7 @@ yarn nx g remove <service-name>
161175

162176
You may need to remove imports of the service from the application first.
163177
You may need to remove references to the service in `nx.json` afterwards.
178+
You may need to run `yarn install` to remove the service reference from the lock file.
164179

165180
### 🧪 Testing with Mock Services
166181

applications/core/bin/main.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
NodeJsFunctionDefaultsInjector,
55
StepFunctionDefaultsInjector,
66
VersionFunctionsAspect,
7-
} from '@libs/cdk-utils';
7+
} from '@libs/cdk-utils/infra';
88
import { App, Aspects, Duration, Stage, Tags, type StageProps } from 'aws-cdk-lib';
99
import { Architecture, Runtime } from 'aws-cdk-lib/aws-lambda';
1010
import type { Construct } from 'constructs';
@@ -48,11 +48,7 @@ new ApplicationStage(app, 'dev', {
4848
propertyInjectors: [
4949
// NOTE: Property Injectors will only apply ONCE each, so adding one here
5050
// overrides the same injector at the app level
51-
new NodeJsFunctionDefaultsInjector({
52-
sourceMap: false,
53-
esm: true,
54-
minify: false,
55-
}).withProps({
51+
new NodeJsFunctionDefaultsInjector({ sourceMap: false }).withProps({
5652
timeout: Duration.seconds(6),
5753
memorySize: 192,
5854
runtime: Runtime.NODEJS_22_X,

libs/cdk-utils/package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
"version": "0.0.1",
44
"type": "module",
55
"exports": {
6-
".": {
7-
"types": "./src/index.ts",
8-
"import": "./src/index.ts",
9-
"default": "./src/index.ts"
10-
},
116
"./infra": {
127
"types": "./src/infra.ts",
138
"import": "./src/infra.ts"
@@ -19,5 +14,17 @@
1914
"./package.json": "./package.json"
2015
},
2116
"main": "./src/index.ts",
22-
"types": "./src/index.ts"
17+
"types": "./src/index.ts",
18+
"nx": {
19+
"targets": {
20+
"build": {
21+
"executor": "nx:run-commands",
22+
"options": {
23+
"command": "tsc --build tsconfig.lib.json",
24+
"color": true,
25+
"cwd": "{projectRoot}"
26+
}
27+
}
28+
}
29+
}
2330
}

libs/cdk-utils/src/infra.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/* v8 ignore start */
2+
export * from './lib/aspects';
23
export * from './lib/constructs';
4+
export * from './lib/injectors';
35
export * from './lib/rules/microservice-checks';

libs/cdk-utils/src/lib/injectors/nodejs-function-defaults-injector.test.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,13 @@ describe('NodeJsFunctionDefaultsInjector', () => {
6666
});
6767

6868
test('merges bundling and environment properties correctly', () => {
69-
PropertyInjectors.of(stack).add(
70-
new NodeJsFunctionDefaultsInjector({
71-
sourceMap: false,
72-
esm: true,
73-
minify: false,
74-
})
75-
);
69+
// Sourcemaps would normally be false in 'dev' configuration
70+
PropertyInjectors.of(stack).add(new NodeJsFunctionDefaultsInjector({ sourceMap: true }));
7671

7772
new NodejsFunction(stack, 'TestFunction', {
7873
runtime: Runtime.NODEJS_22_X,
7974
handler: 'index.handler',
8075
code: Code.fromInline('exports.handler = async () => ({ statusCode: 200 });'),
81-
bundling: {
82-
// Sourcemaps would normally be false in 'dev' configuration
83-
sourceMap: true,
84-
},
8576
environment: {
8677
BUCKET_NAME: 'test-bucket',
8778
},

libs/cdk-utils/src/lib/injectors/nodejs-function-defaults-injector.ts

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
import { type InjectionContext, type IPropertyInjector } from 'aws-cdk-lib';
22
import { Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
3-
import {
4-
NodejsFunction,
5-
OutputFormat,
6-
type NodejsFunctionProps,
7-
} from 'aws-cdk-lib/aws-lambda-nodejs';
3+
import { NodejsFunction, type NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
84
import { logInjector } from './log-injector';
95

10-
/**
11-
* ESM support banner
12-
*
13-
* This is a workaround to support ESM in Lambda functions.
14-
* Aliases are used to avoid name conflicts, this may not be a real issue
15-
*
16-
* @see https://github.com/evanw/esbuild/issues/1944
17-
* @see https://aws.plainenglish.io/significantly-improve-typescript-lambda-function-readability-in-aws-console-613bc5ae98f6
18-
*/
19-
const ESM_SUPPORT_BANNER = [
20-
`import { fileURLToPath } from 'url';`,
21-
`import { createRequire as topLevelCreateRequire } from 'module';`,
22-
`import { dirname as ddirname } from 'path';`,
23-
`const require = topLevelCreateRequire(import.meta.url);`,
24-
`const __filename = fileURLToPath(import.meta.url);`,
25-
`const __dirname = ddirname(__filename);`,
26-
].join(''); // Must be a single line, if the banner has `\n` characters they cause a syntax error
27-
286
/**
297
* Property injector for Node.js Lambda functions with configuration-aware defaults
308
*
@@ -66,23 +44,16 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
6644
*
6745
* @param configuration - Configuration identifier used to select appropriate defaults. Uses production defaults if not specified.
6846
* @param configuration.sourceMap - Whether to enable source maps.
69-
* @param configuration.esm - Whether to enable ESM support.
70-
* @param configuration.minify - Whether to enable minification.
7147
*/
7248
constructor(
7349
private readonly configuration: {
7450
sourceMap: boolean;
75-
esm: boolean;
76-
minify: boolean;
7751
} = {
7852
sourceMap: true,
79-
esm: true,
80-
minify: true,
8153
}
8254
) {
8355
this.defaultProps = {
8456
runtime: Runtime.NODEJS_22_X,
85-
bundling: bundlingProperties(configuration),
8657
tracing: Tracing.ACTIVE,
8758
};
8859
}
@@ -100,8 +71,6 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
10071
* ```typescript
10172
* const customInjector = new NodeJsFunctionDefaultsInjector({
10273
* sourceMaps: false,
103-
* esm: false,
104-
* minify: false,
10574
* })
10675
* .withProps({
10776
* timeout: Duration.minutes(5),
@@ -143,7 +112,7 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
143112
// If source maps are enabled in our bundling, add the required NODE_OPTIONS flag to the environment
144113
const environment = {
145114
...props.environment,
146-
...(props.bundling?.sourceMap ? { NODE_OPTIONS: '--enable-source-maps' } : {}),
115+
...(this.configuration.sourceMap ? { NODE_OPTIONS: '--enable-source-maps' } : {}),
147116
};
148117

149118
return {
@@ -152,37 +121,3 @@ export class NodeJsFunctionDefaultsInjector implements IPropertyInjector {
152121
};
153122
}
154123
}
155-
156-
/**
157-
* Returns configuration-specific bundling properties for Lambda functions
158-
*
159-
* Provides optimized bundling configurations for different environments:
160-
* - 'dev': Fast builds for development (no minification, bundle analysis enabled)
161-
* - 'stg': Balanced configuration for staging
162-
* - Default: Production-optimized (minified, tree-shaking enabled)
163-
*
164-
* @param configuration - Configuration identifier to determine bundling strategy
165-
* @returns Bundling properties optimized for the specified configuration
166-
*/
167-
function bundlingProperties({
168-
sourceMap,
169-
esm,
170-
minify,
171-
}: {
172-
sourceMap: boolean;
173-
esm: boolean;
174-
minify: boolean;
175-
}) {
176-
return {
177-
...(sourceMap && { sourceMap: true }),
178-
...(esm && { format: OutputFormat.ESM, banner: ESM_SUPPORT_BANNER }),
179-
...(minify && {
180-
keepNames: true,
181-
minify: true,
182-
buildArgs: {
183-
bundle: 'true',
184-
treeShaking: 'true',
185-
},
186-
}),
187-
};
188-
}

libs/cdk-utils/vite.config.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { defineConfig, mergeConfig } from 'vitest/config';
22
import { viteBaseConfig } from '../../vite.config.base.mjs';
33

4-
export default mergeConfig(
5-
viteBaseConfig,
6-
defineConfig({
7-
cacheDir: '../../node_modules/.vite/cdk-utils',
8-
test: {
9-
environment: {
10-
NODE_ENV: 'test',
4+
export default defineConfig(configEnv =>
5+
mergeConfig(
6+
viteBaseConfig(configEnv),
7+
defineConfig({
8+
cacheDir: '../../node_modules/.vite/cdk-utils',
9+
test: {
10+
env: { NODE_ENV: 'test' },
1111
},
12-
},
13-
})
12+
})
13+
)
1414
);

nx.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@
3636
"dependsOn": ["^build"],
3737
"inputs": ["production", "^production"]
3838
},
39+
"cdk": {
40+
"dependsOn": ["^build"],
41+
"inputs": ["production", "^production"]
42+
},
3943
"pg": {
4044
"executor": "nx:run-commands",
45+
"dependsOn": ["^build"],
4146
"options": {
4247
"color": true,
4348
"cwd": "{workspaceRoot}/applications/core"

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aligent/app",
3-
"version": "4.0.0",
3+
"version": "4.1.0",
44
"description": "Aligent AWS microservices template using Typescript and AWS CDK",
55
"author": "Aligent Consulting",
66
"type": "module",
@@ -25,13 +25,13 @@
2525
],
2626
"devDependencies": {
2727
"@aligent/ts-code-standards": "^4.0.2",
28-
"@nx/devkit": "21.3.11",
29-
"@nx/esbuild": "21.3.11",
30-
"@nx/eslint": "21.3.11",
31-
"@nx/eslint-plugin": "21.3.11",
32-
"@nx/js": "21.3.11",
33-
"@nx/vite": "21.3.11",
34-
"@nx/web": "21.3.11",
28+
"@nx/devkit": "21.4.0",
29+
"@nx/esbuild": "21.4.0",
30+
"@nx/eslint": "21.4.0",
31+
"@nx/eslint-plugin": "21.4.0",
32+
"@nx/js": "21.4.0",
33+
"@nx/vite": "21.4.0",
34+
"@nx/web": "21.4.0",
3535
"@swc-node/register": "^1.10.10",
3636
"@swc/core": "^1.13.3",
3737
"@swc/helpers": "^0.5.17",
@@ -49,16 +49,16 @@
4949
"esbuild-visualizer": "^0.7.0",
5050
"eslint": "^9.32.0",
5151
"eslint-config-prettier": "10.1.8",
52+
"fast-glob": "^3.3.3",
5253
"jiti": "2.5.1",
5354
"jsonc-eslint-parser": "^2.4.0",
54-
"nx": "21.3.11",
55+
"nx": "21.4.0",
5556
"open": "^10.2.0",
5657
"prettier": "^3.6.2",
5758
"store-parameters": "^1.0.6",
5859
"tslib": "^2.8.1",
5960
"typescript": "~5.9.2",
6061
"vite": "6.3.5",
61-
"vite-tsconfig-paths": "~4.3.2",
6262
"vitest": "^3.2.4"
6363
},
6464
"engines": {

0 commit comments

Comments
 (0)