cdk-booster 1.0.1

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.
Files changed (53) hide show
  1. package/LICENSE +353 -0
  2. package/LICENSE.md +350 -0
  3. package/README.md +114 -0
  4. package/dist/cdk-booster.d.ts +29 -0
  5. package/dist/cdk-booster.mjs +733 -0
  6. package/dist/cdkFrameworkWorker.mjs +50 -0
  7. package/dist/configuration.d.ts +16 -0
  8. package/dist/configuration.mjs +29 -0
  9. package/dist/constants.d.ts +1 -0
  10. package/dist/constants.mjs +3 -0
  11. package/dist/getConfigFromCliArgs.d.ts +7 -0
  12. package/dist/getConfigFromCliArgs.mjs +23 -0
  13. package/dist/getDirname.d.ts +10 -0
  14. package/dist/getDirname.mjs +19 -0
  15. package/dist/logger.d.ts +51 -0
  16. package/dist/logger.mjs +83 -0
  17. package/dist/types/bundleSettings.d.ts +6 -0
  18. package/dist/types/bundleSettings.mjs +1 -0
  19. package/dist/types/cbConfig.d.ts +8 -0
  20. package/dist/types/cbConfig.mjs +1 -0
  21. package/dist/types/lambdaBundle.d.ts +11 -0
  22. package/dist/types/lambdaBundle.mjs +1 -0
  23. package/dist/utils/findPackageJson.d.ts +6 -0
  24. package/dist/utils/findPackageJson.mjs +33 -0
  25. package/dist/version.d.ts +5 -0
  26. package/dist/version.mjs +25 -0
  27. package/node_modules/chalk/license +9 -0
  28. package/node_modules/chalk/package.json +83 -0
  29. package/node_modules/chalk/readme.md +297 -0
  30. package/node_modules/chalk/source/index.d.ts +325 -0
  31. package/node_modules/chalk/source/index.js +225 -0
  32. package/node_modules/chalk/source/utilities.js +33 -0
  33. package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
  34. package/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
  35. package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
  36. package/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
  37. package/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
  38. package/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
  39. package/node_modules/commander/LICENSE +22 -0
  40. package/node_modules/commander/Readme.md +1159 -0
  41. package/node_modules/commander/esm.mjs +16 -0
  42. package/node_modules/commander/index.js +24 -0
  43. package/node_modules/commander/lib/argument.js +149 -0
  44. package/node_modules/commander/lib/command.js +2778 -0
  45. package/node_modules/commander/lib/error.js +39 -0
  46. package/node_modules/commander/lib/help.js +747 -0
  47. package/node_modules/commander/lib/option.js +379 -0
  48. package/node_modules/commander/lib/suggestSimilar.js +101 -0
  49. package/node_modules/commander/package-support.json +16 -0
  50. package/node_modules/commander/package.json +82 -0
  51. package/node_modules/commander/typings/esm.d.mts +3 -0
  52. package/node_modules/commander/typings/index.d.ts +1113 -0
  53. package/package.json +100 -0
@@ -0,0 +1,50 @@
1
+ // @ts-nocheck
2
+ import { workerData, parentPort } from 'node:worker_threads';
3
+ import { pathToFileURL } from 'url';
4
+ import { Logger } from './logger.mjs';
5
+
6
+ Logger.setVerbose(workerData.verbose);
7
+ process.env.CDK_OUTDIR = 'cdk.out';
8
+ process.env.CDK_BOOSTER_INSPECT = 'true';
9
+
10
+ Logger.verbose(`[Worker] Started`);
11
+
12
+ parentPort.on('message', async (data) => {
13
+ try {
14
+ // this is global variable to store the data from the CDK code once it is executed
15
+ global.lambdas = [];
16
+
17
+ Logger.verbose(`[Worker] Received message`, data);
18
+
19
+ // execute code to get the data into global.lambdas
20
+ await import(pathToFileURL(data.compileOutput).href);
21
+
22
+ const cloudAssembly = await global.cdkApp.synth();
23
+ global.cdkApp.synth = () => undefined; // prevent call
24
+ const missing = !!cloudAssembly.manifest.missing;
25
+
26
+ if (!global.lambdas || global.lambdas?.length === 0) {
27
+ throw new Error('No Lambda functions found in the CDK code');
28
+ }
29
+
30
+ const lambdas = global.lambdas;
31
+
32
+ Logger.verbose(
33
+ `[Worker] Sending found Lambdas`,
34
+ JSON.stringify(lambdas, null, 2),
35
+ );
36
+ Logger.verbose(
37
+ `[Worker] ${missing ? 'Some resources are missing and need to be looked up. Synth will have to be run twice.' : 'All resources are resolved.'}`,
38
+ );
39
+
40
+ // send the data back to the main thread
41
+ parentPort.postMessage({ lambdas, missing });
42
+ } catch (error) {
43
+ Logger.error(`[Worker] Error`, error);
44
+ throw error;
45
+ }
46
+ });
47
+
48
+ process.on('unhandledRejection', (error) => {
49
+ Logger.error(`[Worker] Unhandled Rejection`, error);
50
+ });
@@ -0,0 +1,16 @@
1
+ import { CbConfig } from './types/cbConfig.js';
2
+ /**
3
+ * Read configuration from CLI args, config file or wizard
4
+ */
5
+ declare function readConfig(): Promise<void>;
6
+ /**
7
+ * Set the configuration
8
+ * @param newConfig
9
+ */
10
+ declare function setConfig(newConfig: CbConfig): void;
11
+ export declare const Configuration: {
12
+ readConfig: typeof readConfig;
13
+ readonly config: CbConfig;
14
+ setConfig: typeof setConfig;
15
+ };
16
+ export {};
@@ -0,0 +1,29 @@
1
+ // @ts-ignore // does not have types
2
+ import { getConfigFromCliArgs } from './getConfigFromCliArgs.mjs';
3
+ import { Logger } from './logger.mjs';
4
+ let config;
5
+ /**
6
+ * Read configuration from CLI args, config file or wizard
7
+ */
8
+ async function readConfig() {
9
+ const configFromCliArgs = await getConfigFromCliArgs();
10
+ Configuration.setConfig(configFromCliArgs); // not complete config
11
+ Logger.setVerbose(configFromCliArgs.verbose === true);
12
+ }
13
+ /**
14
+ * Set the configuration
15
+ * @param newConfig
16
+ */
17
+ function setConfig(newConfig) {
18
+ config = newConfig;
19
+ }
20
+ export const Configuration = {
21
+ readConfig,
22
+ get config() {
23
+ if (!config) {
24
+ throw new Error('Config not initialized. Call readConfig() first.');
25
+ }
26
+ return config;
27
+ },
28
+ setConfig,
29
+ };
@@ -0,0 +1 @@
1
+ export declare const outputFolder: string;
@@ -0,0 +1,3 @@
1
+ import * as path from 'path';
2
+ // we drop temporary files in this folder
3
+ export const outputFolder = path.join('cdk.out', 'cdk-booster');
@@ -0,0 +1,7 @@
1
+ import { CbConfig } from './types/cbConfig.js';
2
+ /**
3
+ * Get configuration from CLI arguments
4
+ * @param supportedFrameworks Supported frameworks
5
+ * @returns Configuration
6
+ */
7
+ export declare function getConfigFromCliArgs(): Promise<CbConfig>;
@@ -0,0 +1,23 @@
1
+ import { Command } from 'commander';
2
+ import { getVersion } from './version.mjs';
3
+ /**
4
+ * Get configuration from CLI arguments
5
+ * @param supportedFrameworks Supported frameworks
6
+ * @returns Configuration
7
+ */
8
+ export async function getConfigFromCliArgs() {
9
+ const version = await getVersion();
10
+ const program = new Command();
11
+ program.name('cdk-booster').description('CDK Booster').version(version);
12
+ program.option('-v, --verbose', 'Verbose logging');
13
+ program.arguments('<string>');
14
+ program.parse(process.argv);
15
+ const args = program.opts();
16
+ const entryFile = program.args[0];
17
+ if (!entryFile) {
18
+ program.outputHelp();
19
+ throw new Error('Entry file is required');
20
+ }
21
+ args.entryFile = entryFile;
22
+ return args;
23
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Get the dirname of the CDK Booster NPM module
3
+ * @returns
4
+ */
5
+ export declare function getModuleDirname(): string;
6
+ /**
7
+ * Get the dirname of the project
8
+ * @returns
9
+ */
10
+ export declare function getProjectDirname(): string;
@@ -0,0 +1,19 @@
1
+ import * as path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ const __filename = fileURLToPath(import.meta.url);
4
+ const __dirname = path.dirname(__filename);
5
+ const projectDirname = path.resolve('.');
6
+ /**
7
+ * Get the dirname of the CDK Booster NPM module
8
+ * @returns
9
+ */
10
+ export function getModuleDirname() {
11
+ return __dirname;
12
+ }
13
+ /**
14
+ * Get the dirname of the project
15
+ * @returns
16
+ */
17
+ export function getProjectDirname() {
18
+ return projectDirname;
19
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Log a message
3
+ * @param args The arguments to log
4
+ */
5
+ declare function log(...args: any[]): void;
6
+ /**
7
+ * Log an important message
8
+ * @param args The arguments to log
9
+ */
10
+ declare function important(...args: any[]): void;
11
+ /**
12
+ * Log an error message in red
13
+ * @param args The arguments to log
14
+ */
15
+ declare function error(...args: any[]): void;
16
+ /**
17
+ * Log a warning message in orange
18
+ * @param args The arguments to log
19
+ */
20
+ declare function warn(...args: any[]): void;
21
+ /**
22
+ * Log an info message in green
23
+ * @param args The arguments to log
24
+ */
25
+ declare function info(...args: any[]): void;
26
+ /**
27
+ * Log a verbose message if verbose is enabled. Log the message in grey.
28
+ * @param args The arguments to log
29
+ */
30
+ declare function verbose(...args: any[]): void;
31
+ /**
32
+ * Set the verbosity of logging
33
+ * @param enabled Whether verbose logging should be enabled
34
+ */
35
+ declare function setVerbose(enabled: boolean): void;
36
+ /**
37
+ * Check if verbose logging is enabled
38
+ * @returns Whether verbose logging is enabled
39
+ */
40
+ declare function isVerbose(): boolean;
41
+ export declare const Logger: {
42
+ log: typeof log;
43
+ error: typeof error;
44
+ warn: typeof warn;
45
+ important: typeof important;
46
+ info: typeof info;
47
+ verbose: typeof verbose;
48
+ setVerbose: typeof setVerbose;
49
+ isVerbose: typeof isVerbose;
50
+ };
51
+ export {};
@@ -0,0 +1,83 @@
1
+ import chalk from 'chalk';
2
+ let verboseEnabled = false;
3
+ const logPrefix = '[🚀 CDK Booster]';
4
+ /**
5
+ * Log a message
6
+ * @param args The arguments to log
7
+ */
8
+ function log(...args) {
9
+ args = [logPrefix, ...args].map((arg) => {
10
+ if (typeof arg === 'string') {
11
+ // Regular expression to find text within square brackets
12
+ return arg.replace(/\[(.*?)\]/g, (match) => chalk.gray(match)); // Colorizes the entire bracketed content
13
+ }
14
+ return arg;
15
+ });
16
+ console.log(...args);
17
+ }
18
+ /**
19
+ * Log an important message
20
+ * @param args The arguments to log
21
+ */
22
+ function important(...args) {
23
+ args = [logPrefix, ...args].map((arg) => typeof arg === 'string' ? chalk.yellow(arg) : arg);
24
+ console.log(...args);
25
+ }
26
+ /**
27
+ * Log an error message in red
28
+ * @param args The arguments to log
29
+ */
30
+ function error(...args) {
31
+ args = [logPrefix, ...args].map((arg) => typeof arg === 'string' ? chalk.red(arg) : arg);
32
+ console.error(...args);
33
+ }
34
+ /**
35
+ * Log a warning message in orange
36
+ * @param args The arguments to log
37
+ */
38
+ function warn(...args) {
39
+ args = [logPrefix, ...args].map((arg) => typeof arg === 'string' ? chalk.yellow(arg) : arg);
40
+ console.warn(...args);
41
+ }
42
+ /**
43
+ * Log an info message in green
44
+ * @param args The arguments to log
45
+ */
46
+ function info(...args) {
47
+ args = [logPrefix, ...args].map((arg) => typeof arg === 'string' ? chalk.greenBright(arg) : arg);
48
+ console.info(...args);
49
+ }
50
+ /**
51
+ * Log a verbose message if verbose is enabled. Log the message in grey.
52
+ * @param args The arguments to log
53
+ */
54
+ function verbose(...args) {
55
+ if (verboseEnabled) {
56
+ args = [logPrefix, ...args].map((arg) => typeof arg === 'string' ? chalk.grey(arg) : arg);
57
+ console.info(...args);
58
+ }
59
+ }
60
+ /**
61
+ * Set the verbosity of logging
62
+ * @param enabled Whether verbose logging should be enabled
63
+ */
64
+ function setVerbose(enabled) {
65
+ verboseEnabled = enabled;
66
+ }
67
+ /**
68
+ * Check if verbose logging is enabled
69
+ * @returns Whether verbose logging is enabled
70
+ */
71
+ function isVerbose() {
72
+ return verboseEnabled;
73
+ }
74
+ export const Logger = {
75
+ log,
76
+ error,
77
+ warn,
78
+ important,
79
+ info,
80
+ verbose,
81
+ setVerbose,
82
+ isVerbose,
83
+ };
@@ -0,0 +1,6 @@
1
+ import * as esbuild from 'esbuild';
2
+ export type BundleSettings = Pick<esbuild.BuildOptions, 'target' | 'format' | 'minify' | 'sourcemap' | 'sourcesContent' | 'external' | 'loader' | 'define' | 'logLevel' | 'keepNames' | 'tsconfig' | 'banner' | 'footer' | 'mainFields' | 'inject'> & {
3
+ readonly esbuildArgs?: {
4
+ [key: string]: string | boolean;
5
+ };
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export type CbConfig = {
2
+ /**
3
+ * Verbose logging
4
+ * @default false
5
+ */
6
+ verbose?: boolean;
7
+ entryFile: string;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { BundleSettings } from './bundleSettings.js';
2
+ export type LambdaBundle = {
3
+ outfile: string;
4
+ command: string;
5
+ entryPoint: string;
6
+ out: string;
7
+ commandBeforeBundling: string | undefined;
8
+ commandAfterBundling: string | undefined;
9
+ environment: Record<string, string | undefined>;
10
+ projectRoot: string | undefined;
11
+ } & BundleSettings;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Find the package.json file for a given code path
3
+ * @param codePath
4
+ * @returns
5
+ */
6
+ export declare function findPackageJson(codePath: any): Promise<string | undefined>;
@@ -0,0 +1,33 @@
1
+ import * as path from 'path';
2
+ import * as fs from 'fs/promises';
3
+ /**
4
+ * Find the package.json file for a given code path
5
+ * @param codePath
6
+ * @returns
7
+ */
8
+ export async function findPackageJson(codePath) {
9
+ const handlerParsedPath = path.parse(codePath);
10
+ const packageJsonRoot = await findAboveFolderWithAFile(handlerParsedPath.dir, 'package.json');
11
+ const packageJsonPath = packageJsonRoot
12
+ ? path.resolve(path.join(packageJsonRoot, 'package.json'))
13
+ : undefined;
14
+ return packageJsonPath;
15
+ }
16
+ /**
17
+ * Find the nearest folder above with a given file
18
+ * @param dir
19
+ * @param file
20
+ * @returns
21
+ */
22
+ async function findAboveFolderWithAFile(dir, file) {
23
+ if (dir === '/')
24
+ return undefined;
25
+ try {
26
+ // Check if the file exists in the current directory
27
+ await fs.access(path.join(dir, file));
28
+ return dir;
29
+ }
30
+ catch {
31
+ return findAboveFolderWithAFile(path.resolve(path.join(dir, '..')), file);
32
+ }
33
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get the version of the package
3
+ * @returns the version of the package
4
+ */
5
+ export declare function getVersion(): Promise<string>;
@@ -0,0 +1,25 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { getModuleDirname } from './getDirname.mjs';
4
+ let versionStored = undefined;
5
+ /**
6
+ * Get the version of the package
7
+ * @returns the version of the package
8
+ */
9
+ export async function getVersion() {
10
+ if (versionStored) {
11
+ return versionStored;
12
+ }
13
+ const pachageJsonPath = path.join(getModuleDirname(), '../', 'package.json');
14
+ try {
15
+ const packageJson = await fs.promises.readFile(pachageJsonPath, 'utf-8');
16
+ const { version } = JSON.parse(packageJson);
17
+ versionStored = version;
18
+ return version;
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Error reading version from ${pachageJsonPath}: ${error.message}`, {
22
+ cause: error,
23
+ });
24
+ }
25
+ }
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "chalk",
3
+ "version": "5.6.0",
4
+ "description": "Terminal string styling done right",
5
+ "license": "MIT",
6
+ "repository": "chalk/chalk",
7
+ "funding": "https://github.com/chalk/chalk?sponsor=1",
8
+ "type": "module",
9
+ "main": "./source/index.js",
10
+ "exports": "./source/index.js",
11
+ "imports": {
12
+ "#ansi-styles": "./source/vendor/ansi-styles/index.js",
13
+ "#supports-color": {
14
+ "node": "./source/vendor/supports-color/index.js",
15
+ "default": "./source/vendor/supports-color/browser.js"
16
+ }
17
+ },
18
+ "types": "./source/index.d.ts",
19
+ "sideEffects": false,
20
+ "engines": {
21
+ "node": "^12.17.0 || ^14.13 || >=16.0.0"
22
+ },
23
+ "scripts": {
24
+ "test": "xo && c8 ava && tsd",
25
+ "bench": "matcha benchmark.js"
26
+ },
27
+ "files": [
28
+ "source",
29
+ "!source/index.test-d.ts"
30
+ ],
31
+ "keywords": [
32
+ "color",
33
+ "colour",
34
+ "colors",
35
+ "terminal",
36
+ "console",
37
+ "cli",
38
+ "string",
39
+ "ansi",
40
+ "style",
41
+ "styles",
42
+ "tty",
43
+ "formatting",
44
+ "rgb",
45
+ "256",
46
+ "shell",
47
+ "xterm",
48
+ "log",
49
+ "logging",
50
+ "command-line",
51
+ "text"
52
+ ],
53
+ "devDependencies": {
54
+ "@types/node": "^16.11.10",
55
+ "ava": "^3.15.0",
56
+ "c8": "^7.10.0",
57
+ "color-convert": "^2.0.1",
58
+ "execa": "^6.0.0",
59
+ "log-update": "^5.0.0",
60
+ "matcha": "^0.7.0",
61
+ "tsd": "^0.19.0",
62
+ "xo": "^0.57.0",
63
+ "yoctodelay": "^2.0.0"
64
+ },
65
+ "xo": {
66
+ "rules": {
67
+ "unicorn/prefer-string-slice": "off",
68
+ "@typescript-eslint/consistent-type-imports": "off",
69
+ "@typescript-eslint/consistent-type-exports": "off",
70
+ "@typescript-eslint/consistent-type-definitions": "off",
71
+ "unicorn/expiring-todo-comments": "off"
72
+ }
73
+ },
74
+ "c8": {
75
+ "reporter": [
76
+ "text",
77
+ "lcov"
78
+ ],
79
+ "exclude": [
80
+ "source/vendor"
81
+ ]
82
+ }
83
+ }