Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): bundle dependencies #18667

Merged
merged 82 commits into from Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
6b738cd
mid work
iliapolo Jan 24, 2022
476d1f0
link to issues
iliapolo Jan 24, 2022
8e7abd6
mid work
iliapolo Jan 25, 2022
6ce1d2c
mid work
iliapolo Jan 26, 2022
c080106
Merge branch 'master' into epolon/cli-bundle
iliapolo Jan 26, 2022
a1991fe
compile
iliapolo Jan 26, 2022
39eb196
Merge branch 'master' into epolon/cli-bundle
iliapolo Jan 26, 2022
613dbf8
yargs types
iliapolo Jan 26, 2022
d526cf9
lint
iliapolo Jan 26, 2022
fffa051
mid work
iliapolo Feb 1, 2022
93b0028
mid work
iliapolo Feb 6, 2022
8ecdd89
mid work
iliapolo Feb 6, 2022
aaf5fc7
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 6, 2022
7e96b49
mid work
iliapolo Feb 6, 2022
71e5e0b
mid work
iliapolo Feb 7, 2022
aa6e99c
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 7, 2022
e504608
mid work
iliapolo Feb 7, 2022
caa9bc6
mid work
iliapolo Feb 7, 2022
b0c3c31
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 7, 2022
1067fb6
mid work
iliapolo Feb 9, 2022
f3262bd
mid work
iliapolo Feb 9, 2022
123fb5d
mid work
iliapolo Feb 9, 2022
658351d
mid work
iliapolo Feb 10, 2022
8640e74
mid work
iliapolo Feb 10, 2022
773f0be
mid work
iliapolo Feb 10, 2022
da16164
mid work
iliapolo Feb 10, 2022
30e9b58
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 10, 2022
c529c2c
mid work
iliapolo Feb 12, 2022
b529ad9
fix package
iliapolo Feb 12, 2022
b24c681
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 12, 2022
dd8cb79
linter
iliapolo Feb 12, 2022
f0325c6
fix test
iliapolo Feb 12, 2022
8ec6010
standard line endings
iliapolo Feb 12, 2022
6f6c54e
debug
iliapolo Feb 12, 2022
40c5dd7
allow custom notice file path
iliapolo Feb 12, 2022
1bcb3b9
fix message
iliapolo Feb 12, 2022
3e582ed
debug
iliapolo Feb 12, 2022
b494fb9
dont attribute cdk-assets
iliapolo Feb 12, 2022
d8a9568
revert unncessary changes
iliapolo Feb 12, 2022
a6aeb2a
revert bin
iliapolo Feb 12, 2022
d5a53d1
cleanup
iliapolo Feb 12, 2022
785ee3c
better algo for detecting external dependency version
iliapolo Feb 13, 2022
aedfa2b
more cleanup
iliapolo Feb 14, 2022
79da8ba
added resource
iliapolo Feb 14, 2022
df33d0d
review
iliapolo Feb 14, 2022
ba42055
one more resource
iliapolo Feb 14, 2022
f2e413d
added build+test for node-bundle package
iliapolo Feb 14, 2022
ca79b7d
fix warnings check
iliapolo Feb 15, 2022
8e4a232
split pack command to write + pack
iliapolo Feb 15, 2022
f3af9b1
use validate --fix instead of fix
iliapolo Feb 15, 2022
9b8d528
bundle index.js
iliapolo Feb 16, 2022
81c585a
fix resources
iliapolo Feb 16, 2022
9f5a431
default entrypoint
iliapolo Feb 16, 2022
97779dd
mid work
iliapolo Feb 17, 2022
ff68201
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 17, 2022
23a71e3
merge
iliapolo Feb 17, 2022
65577cd
handle multiple major versions of the same dep
iliapolo Feb 17, 2022
9d6b3da
Merge branch 'epolon/third-party-licenses' into epolon/cli-bundle
iliapolo Feb 17, 2022
6564a15
switch to THIRD_PARTY_LICENSES
iliapolo Feb 17, 2022
a040e10
readme
iliapolo Feb 17, 2022
d07b881
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 17, 2022
4ba0273
optional entrypoint
iliapolo Feb 18, 2022
d989b09
fix cli handling empty arrays
iliapolo Feb 20, 2022
ffba06a
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 20, 2022
515aa48
more docs
iliapolo Feb 22, 2022
e770d96
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 22, 2022
1319efb
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 22, 2022
52233c6
add referal to the THIRD_PARTY_LICENSES file
iliapolo Feb 23, 2022
4b6c90c
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 23, 2022
4a9d43b
make package private
iliapolo Feb 23, 2022
d9ac029
review
iliapolo Feb 23, 2022
ac6f266
regen cli usage
iliapolo Feb 23, 2022
fadbee2
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 23, 2022
0f58de4
Update tools/@aws-cdk/node-bundle/src/api/_attributions.ts
iliapolo Feb 23, 2022
dfc8790
chore: npm-check-updates && yarn upgrade (#19109)
iliapolo Feb 23, 2022
bba506e
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 23, 2022
0e9a151
fix attributions
iliapolo Feb 23, 2022
26933d8
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 23, 2022
bdee73b
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 23, 2022
6df4268
fix externals
iliapolo Feb 23, 2022
2e50f7f
external usage disclaimer
iliapolo Feb 23, 2022
a1c8a5f
Merge branch 'master' into epolon/cli-bundle
iliapolo Feb 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cloudformation-diff/lib/format-table.ts
@@ -1,5 +1,5 @@
import * as chalk from 'chalk';
import * as stringWidth from 'string-width';
import stringWidth from 'string-width';
import * as table from 'table';

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/cloudformation-diff/lib/iam/statement.ts
@@ -1,6 +1,9 @@
import * as deepEqual from 'fast-deep-equal';
import { deepRemoveUndefined } from '../util';

// namespace object imports won't work in the bundle for function exports
// eslint-disable-next-line @typescript-eslint/no-require-imports
const deepEqual = require('fast-deep-equal');
iliapolo marked this conversation as resolved.
Show resolved Hide resolved

export class Statement {
/**
* Statement ID
Expand Down
12 changes: 12 additions & 0 deletions packages/aws-cdk/NOTICE
@@ -1,2 +1,14 @@
AWS Cloud Development Kit (AWS CDK)
Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
3,768 changes: 3,768 additions & 0 deletions packages/aws-cdk/THIRD_PARTY_LICENSES

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/aws-cdk/lib/api/bootstrap/bootstrap-environment.ts
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import * as cxapi from '@aws-cdk/cx-api';
import { warning } from '../../logging';
import { loadStructuredFile, toYAML } from '../../serialize';
import { rootDir } from '../../util/directories';
import { SdkProvider } from '../aws-auth';
import { DeployStackResult } from '../deploy-stack';
import { BootstrapEnvironmentOptions, BootstrappingParameters } from './bootstrap-props';
Expand Down Expand Up @@ -170,7 +171,7 @@ export class Bootstrapper {
case 'custom':
return loadStructuredFile(this.source.templateFile);
case 'default':
return loadStructuredFile(path.join(__dirname, 'bootstrap-template.yaml'));
return loadStructuredFile(path.join(rootDir(), 'lib', 'api', 'bootstrap', 'bootstrap-template.yaml'));
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
case 'legacy':
return legacyBootstrapTemplate(params);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/aws-cdk/lib/api/cloudformation-deployments.ts
Expand Up @@ -5,7 +5,9 @@ import * as fs from 'fs-extra';
import { Tag } from '../cdk-toolkit';
import { debug, warning } from '../logging';
import { publishAssets } from '../util/asset-publishing';
import { Mode, SdkProvider, ISDK } from './aws-auth';
import { Mode } from './aws-auth/credentials';
import { ISDK } from './aws-auth/sdk';
import { SdkProvider } from './aws-auth/sdk-provider';
import { deployStack, DeployStackResult, destroyStack } from './deploy-stack';
import { LazyListStackResources, ListStackResources } from './evaluate-cloudformation-template';
import { ToolkitInfo } from './toolkit-info';
Expand Down
6 changes: 5 additions & 1 deletion packages/aws-cdk/lib/api/cxapp/cloud-assembly.ts
@@ -1,11 +1,15 @@
import * as cxapi from '@aws-cdk/cx-api';
import * as chalk from 'chalk';
import * as minimatch from 'minimatch';
import * as semver from 'semver';
import { error, print, warning } from '../../logging';
import { flatten } from '../../util';
import { versionNumber } from '../../version';

// namespace object imports won't work in the bundle for function exports
// eslint-disable-next-line @typescript-eslint/no-require-imports
const minimatch = require('minimatch');


export enum DefaultSelection {
/**
* Returns an empty selection in case there are no selectors.
Expand Down
5 changes: 4 additions & 1 deletion packages/aws-cdk/lib/api/cxapp/environments.ts
@@ -1,8 +1,11 @@
import * as cxapi from '@aws-cdk/cx-api';
import * as minimatch from 'minimatch';
import { SdkProvider } from '../aws-auth';
import { StackCollection } from './cloud-assembly';

// namespace object imports won't work in the bundle for function exports
// eslint-disable-next-line @typescript-eslint/no-require-imports
const minimatch = require('minimatch');

export function looksLikeGlob(environment: string) {
return environment.indexOf('*') > -1;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/aws-cdk/lib/api/hotswap/lambda-functions.ts
@@ -1,11 +1,14 @@
import { Writable } from 'stream';
import * as archiver from 'archiver';
import * as AWS from 'aws-sdk';
import { flatMap } from '../../util';
import { ISDK } from '../aws-auth';
import { CfnEvaluationException, EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-template';
import { ChangeHotswapImpact, ChangeHotswapResult, HotswapOperation, HotswappableChangeCandidate } from './common';

// namespace object imports won't work in the bundle for function exports
// eslint-disable-next-line @typescript-eslint/no-require-imports
const archiver = require('archiver');
iliapolo marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns `ChangeHotswapImpact.REQUIRES_FULL_DEPLOYMENT` if the change cannot be short-circuited,
* `ChangeHotswapImpact.IRRELEVANT` if the change is irrelevant from a short-circuit perspective
Expand Down Expand Up @@ -366,7 +369,7 @@ function zipString(fileName: string, rawString: string): Promise<Buffer> {

const archive = archiver('zip');

archive.on('error', (err) => {
archive.on('error', (err: any) => {
reject(err);
});

Expand Down
4 changes: 3 additions & 1 deletion packages/aws-cdk/lib/api/util/display.ts
@@ -1,4 +1,6 @@
import * as wrapAnsi from 'wrap-ansi';
// namespace object imports won't work in the bundle for function exports
// eslint-disable-next-line @typescript-eslint/no-require-imports
const wrapAnsi = require('wrap-ansi');

/**
* A class representing rewritable display lines
Expand Down
27 changes: 16 additions & 11 deletions packages/aws-cdk/lib/cli.ts
Expand Up @@ -2,8 +2,8 @@ import 'source-map-support/register';
import * as cxapi from '@aws-cdk/cx-api';
import '@jsii/check-node/run';
import * as chalk from 'chalk';
import * as yargs from 'yargs';

import type { Argv } from 'yargs';
import { SdkProvider } from '../lib/api/aws-auth';
import { BootstrapSource, Bootstrapper } from '../lib/api/bootstrap';
import { CloudFormationDeployments } from '../lib/api/cloudformation-deployments';
Expand All @@ -24,6 +24,11 @@ import { serializeStructure } from '../lib/serialize';
import { Command, Configuration, Settings } from '../lib/settings';
import * as version from '../lib/version';

// https://github.com/yargs/yargs/issues/1929
// https://github.com/evanw/esbuild/issues/1492
// eslint-disable-next-line @typescript-eslint/no-require-imports
const yargs = require('yargs');

/* eslint-disable max-len */
/* eslint-disable @typescript-eslint/no-shadow */ // yargs

Expand Down Expand Up @@ -72,14 +77,14 @@ async function parseCommandLineArguments() {
.option('staging', { type: 'boolean', desc: 'Copy assets to the output directory (use --no-staging to disable, needed for local debugging the source files with SAM CLI)', default: true })
.option('output', { type: 'string', alias: 'o', desc: 'Emits the synthesized cloud assembly into a directory (default: cdk.out)', requiresArg: true })
.option('no-color', { type: 'boolean', desc: 'Removes colors and other style from console output', default: false })
.command(['list [STACKS..]', 'ls [STACKS..]'], 'Lists all stacks in the app', yargs => yargs
.command(['list [STACKS..]', 'ls [STACKS..]'], 'Lists all stacks in the app', (yargs: Argv) => yargs
.option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }),
)
.command(['synthesize [STACKS..]', 'synth [STACKS..]'], 'Synthesizes and prints the CloudFormation template for this stack', yargs => yargs
.command(['synthesize [STACKS..]', 'synth [STACKS..]'], 'Synthesizes and prints the CloudFormation template for this stack', (yargs: Argv) => yargs
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only synthesize requested stacks, don\'t include dependencies' })
.option('validation', { type: 'boolean', desc: 'After synthesis, validate stacks with the "validateOnSynth" attribute set (can also be controlled with CDK_VALIDATION)', default: true })
.option('quiet', { type: 'boolean', alias: 'q', desc: 'Do not output CloudFormation Template to stdout', default: false }))
.command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs
.command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', (yargs: Argv) => yargs
.option('bootstrap-bucket-name', { type: 'string', alias: ['b', 'toolkit-bucket-name'], desc: 'The name of the CDK toolkit bucket; bucket will be created and must not exist', default: undefined })
.option('bootstrap-kms-key-id', { type: 'string', desc: 'AWS KMS master key ID used for the SSE-KMS encryption', default: undefined, conflicts: 'bootstrap-customer-key' })
.option('bootstrap-customer-key', { type: 'boolean', desc: 'Create a Customer Master Key (CMK) for the bootstrap bucket (you will be charged but can customize permissions, modern bootstrapping only)', default: undefined, conflicts: 'bootstrap-kms-key-id' })
Expand All @@ -96,7 +101,7 @@ async function parseCommandLineArguments() {
.option('toolkit-stack-name', { type: 'string', desc: 'The name of the CDK toolkit stack to create', requiresArg: true })
.option('template', { type: 'string', requiresArg: true, desc: 'Use the template from the given file instead of the built-in one (use --show-template to obtain an example)' }),
)
.command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', yargs => yargs
.command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', (yargs: Argv) => yargs
.option('all', { type: 'boolean', default: false, desc: 'Deploy all available stacks' })
.option('build-exclude', { type: 'array', alias: 'E', nargs: 1, desc: 'Do not rebuild asset with the given ID. Can be specified multiple times', default: [] })
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only deploy requested stacks, don\'t include dependencies' })
Expand Down Expand Up @@ -141,7 +146,7 @@ async function parseCommandLineArguments() {
"Only in effect if specified alongside the '--watch' option",
}),
)
.command('watch [STACKS..]', "Shortcut for 'deploy --watch'", yargs => yargs
.command('watch [STACKS..]', "Shortcut for 'deploy --watch'", (yargs: Argv) => yargs
// I'm fairly certain none of these options, present for 'deploy', make sense for 'watch':
// .option('all', { type: 'boolean', default: false, desc: 'Deploy all available stacks' })
// .option('ci', { type: 'boolean', desc: 'Force CI detection', default: process.env.CI !== undefined })
Expand Down Expand Up @@ -181,27 +186,27 @@ async function parseCommandLineArguments() {
"'true' by default, use --no-logs to turn off",
}),
)
.command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs
.command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', (yargs: Argv) => yargs
.option('all', { type: 'boolean', default: false, desc: 'Destroy all available stacks' })
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only destroy requested stacks, don\'t include dependees' })
.option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' }))
.command('diff [STACKS..]', 'Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found', yargs => yargs
.command('diff [STACKS..]', 'Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found', (yargs: Argv) => yargs
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only diff requested stacks, don\'t include dependencies' })
.option('context-lines', { type: 'number', desc: 'Number of context lines to include in arbitrary JSON diff rendering', default: 3, requiresArg: true })
.option('template', { type: 'string', desc: 'The path to the CloudFormation template to compare with', requiresArg: true })
.option('strict', { type: 'boolean', desc: 'Do not filter out AWS::CDK::Metadata resources', default: false })
.option('security-only', { type: 'boolean', desc: 'Only diff for broadened security changes', default: false })
.option('fail', { type: 'boolean', desc: 'Fail with exit code 1 in case of diff', default: false }))
.command('metadata [STACK]', 'Returns all metadata associated with this stack')
.command('init [TEMPLATE]', 'Create a new, empty CDK project from a template.', yargs => yargs
.command('init [TEMPLATE]', 'Create a new, empty CDK project from a template.', (yargs: Argv) => yargs
.option('language', { type: 'string', alias: 'l', desc: 'The language to be used for the new project (default can be configured in ~/.cdk.json)', choices: initTemplateLanguages })
.option('list', { type: 'boolean', desc: 'List the available templates' })
.option('generate-only', { type: 'boolean', default: false, desc: 'If true, only generates project files, without executing additional operations such as setting up a git repo, installing dependencies or compiling the project' }),
)
.command('context', 'Manage cached context values', yargs => yargs
.command('context', 'Manage cached context values', (yargs: Argv) => yargs
.option('reset', { alias: 'e', desc: 'The context key (or its index) to reset', type: 'string', requiresArg: true })
.option('clear', { desc: 'Clear all context', type: 'boolean' }))
.command(['docs', 'doc'], 'Opens the reference documentation in a browser', yargs => yargs
.command(['docs', 'doc'], 'Opens the reference documentation in a browser', (yargs: Argv) => yargs
.option('browser', {
alias: 'b',
desc: 'the command to use to open the browser, using %u as a placeholder for the path of the file to open',
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk/lib/command-api.ts
@@ -1,4 +1,4 @@
import * as yargs from 'yargs';
import type { Arguments } from 'yargs';
import { SdkProvider } from './api/aws-auth';
import { Configuration } from './settings';

Expand All @@ -15,7 +15,7 @@ import { Configuration } from './settings';
* The parts of the world that our command functions have access to
*/
export interface CommandOptions {
args: yargs.Arguments;
args: Arguments;
configuration: Configuration;
aws: SdkProvider;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/aws-cdk/lib/init.ts
Expand Up @@ -5,7 +5,7 @@ import * as chalk from 'chalk';
import * as fs from 'fs-extra';
import * as semver from 'semver';
import { error, print, warning } from './logging';
import { cdkHomeDir } from './util/directories';
import { cdkHomeDir, rootDir } from './util/directories';
import { versionNumber } from './version';

export type InvokeHook = (targetDirectory: string) => Promise<void>;
Expand Down Expand Up @@ -156,11 +156,11 @@ export class InitTemplate {
}

private expand(template: string, project: ProjectInfo) {
const MATCH_VER_BUILD = /\+[a-f0-9]+$/; // Matches "+BUILD" in "x.y.z-beta+BUILD"
// eslint-disable-next-line @typescript-eslint/no-require-imports
const cdkVersion = require('../package.json').version.replace(MATCH_VER_BUILD, '');
// eslint-disable-next-line @typescript-eslint/no-require-imports
const constructsVersion = require('../package.json').devDependencies.constructs.replace(MATCH_VER_BUILD, '');
const manifest = require(path.join(rootDir(), 'package.json'));
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
const MATCH_VER_BUILD = /\+[a-f0-9]+$/; // Matches "+BUILD" in "x.y.z-beta+BUILD"
const cdkVersion = manifest.version.replace(MATCH_VER_BUILD, '');
const constructsVersion = manifest.devDependencies.constructs.replace(MATCH_VER_BUILD, '');
return template.replace(/%name%/g, project.name)
.replace(/%name\.camelCased%/g, camelCase(project.name))
.replace(/%name\.PascalCased%/g, camelCase(project.name, { pascalCase: true }))
Expand Down Expand Up @@ -212,7 +212,7 @@ function versionedTemplatesDir(): Promise<string> {
currentVersion = '1.0.0';
}
const majorVersion = semver.major(currentVersion);
resolve(path.join(__dirname, 'init-templates', `v${majorVersion}`));
resolve(path.join(rootDir(), 'lib', 'init-templates', `v${majorVersion}`));
});
}

Expand Down
19 changes: 10 additions & 9 deletions packages/aws-cdk/lib/logging.ts
Expand Up @@ -13,6 +13,16 @@ const logger = (stream: Writable, styles?: StyleFn[]) => (fmt: string, ...args:
stream.write(str + '\n');
};

export enum LogLevel {
/** Not verbose at all */
DEFAULT = 0,
/** Pretty verbose */
DEBUG = 1,
/** Extremely verbose */
TRACE = 2
}


export let logLevel = LogLevel.DEFAULT;

export function setLogLevel(newLogLevel: LogLevel) {
Expand Down Expand Up @@ -47,12 +57,3 @@ export type LoggerFunction = (fmt: string, ...args: any[]) => void;
export function prefix(prefixString: string, fn: LoggerFunction): LoggerFunction {
return (fmt: string, ...args: any[]) => fn(`%s ${fmt}`, prefixString, ...args);
}

export const enum LogLevel {
/** Not verbose at all */
DEFAULT = 0,
/** Pretty verbose */
DEBUG = 1,
/** Extremely verbose */
TRACE = 2
}
17 changes: 17 additions & 0 deletions packages/aws-cdk/lib/util/directories.ts
@@ -1,3 +1,4 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';

Expand All @@ -9,4 +10,20 @@ export function cdkHomeDir() {

export function cdkCacheDir() {
return path.join(cdkHomeDir(), 'cache');
}

export function rootDir() {

function _rootDir(dirname: string): string {
const manifestPath = path.join(dirname, 'package.json');
if (fs.existsSync(manifestPath)) {
return dirname;
}
if (path.dirname(dirname) === dirname) {
throw new Error('Unable to find package manifest');
}
return _rootDir(path.dirname(dirname));
}

return _rootDir(__dirname);
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 3 additions & 3 deletions packages/aws-cdk/lib/version.ts
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'fs-extra';
import * as semver from 'semver';
import { debug, print } from '../lib/logging';
import { formatAsBanner } from '../lib/util/console-formatters';
import { cdkCacheDir } from './util/directories';
import { cdkCacheDir, rootDir } from './util/directories';
import { getLatestVersionFromNpm } from './util/npm';

const ONE_DAY_IN_SECONDS = 1 * 24 * 60 * 60;
Expand All @@ -17,12 +17,12 @@ export const DISPLAY_VERSION = `${versionNumber()} (build ${commit()})`;

export function versionNumber(): string {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require('../package.json').version.replace(/\+[0-9a-f]+$/, '');
return require(path.join(rootDir(), 'package.json')).version.replace(/\+[0-9a-f]+$/, '');
}

function commit(): string {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require('../build-info.json').commit;
return require(path.join(rootDir(), 'build-info.json')).commit;
}

export class VersionCheckTTL {
Expand Down
22 changes: 20 additions & 2 deletions packages/aws-cdk/package.json
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint && madge --circular --extensions js lib",
"lint": "cdk-lint",
"pkglint": "pkglint -f",
"test": "cdk-test",
"integ": "jest --testMatch '**/?(*.)+(integ-test).js'",
Expand All @@ -28,7 +28,25 @@
"build+test+extract": "yarn build+test"
},
"cdk-package": {
"shrinkWrap": true
"bundle": {
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
"externals": [
"fsevents:optional"
],
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
"resources": {
"../../node_modules/vm2/lib/bridge.js": "lib/bridge.js",
"../../node_modules/vm2/lib/setup-sandbox.js": "lib/setup-sandbox.js"
},
"licenses": [
iliapolo marked this conversation as resolved.
Show resolved Hide resolved
"Apache-2.0",
"MIT",
"BSD-3-Clause",
"ISC",
"BSD-2-Clause",
"0BSD"
],
"dontAttribute": "^@aws-cdk/|^cdk-assets$",
"test": "bin/cdk --version"
}
},
"author": {
"name": "Amazon Web Services",
Expand Down