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

cdk: do not minify JS in NPM distribution #26779

Open
2 tasks
moltar opened this issue Aug 16, 2023 · 4 comments
Open
2 tasks

cdk: do not minify JS in NPM distribution #26779

moltar opened this issue Aug 16, 2023 · 4 comments
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront feature-request A feature should be added or improved. p3

Comments

@moltar
Copy link
Contributor

moltar commented Aug 16, 2023

Describe the feature

I'd like to see un-minified JS files in the NPM distribution.

Use Case

It's impossible to debug any traces because the entire JS file is in one line.

Proposed Solution

Do not minify the JS distribution. I don't think saving spaces and new lines lead to that much savings, considering the tar balls are gzip'ed.

Other Information

This is what the contents of one file look like:

"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.Lazy=void 0;const jsiiDeprecationWarnings=require("../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),debug_1=require("./debug"),stack_trace_1=require("./stack-trace"),token_1=require("./token");class Lazy{static stringValue(producer,options={}){return token_1.Token.asString(new LazyString(producer,!1),options)}static string(producer,options={}){try{jsiiDeprecationWarnings.aws_cdk_lib_IStableStringProducer(producer),jsiiDeprecationWarnings.aws_cdk_lib_LazyStringValueOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.string),error}return token_1.Token.asString(new LazyString(producer,!0),options)}static uncachedString(producer,options={}){try{jsiiDeprecationWarnings.aws_cdk_lib_IStringProducer(producer),jsiiDeprecationWarnings.aws_cdk_lib_LazyStringValueOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.uncachedString),error}return token_1.Token.asString(new LazyString(producer,!1),options)}static numberValue(producer){return token_1.Token.asNumber(new LazyNumber(producer,!1))}static number(producer){try{jsiiDeprecationWarnings.aws_cdk_lib_IStableNumberProducer(producer)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.number),error}return token_1.Token.asNumber(new LazyNumber(producer,!0))}static uncachedNumber(producer){try{jsiiDeprecationWarnings.aws_cdk_lib_INumberProducer(producer)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.uncachedNumber),error}return token_1.Token.asNumber(new LazyNumber(producer,!1))}static listValue(producer,options={}){return token_1.Token.asList(new LazyList(producer,!1,options),options)}static uncachedList(producer,options={}){try{jsiiDeprecationWarnings.aws_cdk_lib_IListProducer(producer),jsiiDeprecationWarnings.aws_cdk_lib_LazyListValueOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.uncachedList),error}return token_1.Token.asList(new LazyList(producer,!1,options),options)}static list(producer,options={}){try{jsiiDeprecationWarnings.aws_cdk_lib_IStableListProducer(producer),jsiiDeprecationWarnings.aws_cdk_lib_LazyListValueOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.list),error}return token_1.Token.asList(new LazyList(producer,!0,options),options)}static anyValue(producer,options={}){return new LazyAny(producer,!1,options)}static any(producer,options={}){try{jsiiDeprecationWarnings.aws_cdk_lib_IStableAnyProducer(producer),jsiiDeprecationWarnings.aws_cdk_lib_LazyAnyValueOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.any),error}return new LazyAny(producer,!0,options)}static uncachedAny(producer,options={}){try{jsiiDeprecationWarnings.aws_cdk_lib_IAnyProducer(producer),jsiiDeprecationWarnings.aws_cdk_lib_LazyAnyValueOptions(options)}catch(error){throw process.env.JSII_DEBUG!=="1"&&error.name==="DeprecationError"&&Error.captureStackTrace(error,this.uncachedAny),error}return new LazyAny(producer,!1,options)}constructor(){}}exports.Lazy=Lazy,_a=JSII_RTTI_SYMBOL_1,Lazy[_a]={fqn:"aws-cdk-lib.Lazy",version:"2.91.0"};class LazyBase{constructor(producer,cache){this.producer=producer,this.cache=cache,this.creationStack=(0,debug_1.debugModeEnabled)()?(0,stack_trace_1.captureStackTrace)(this.constructor):[`Execute again with ${debug_1.CDK_DEBUG}=true to capture stack traces`]}resolve(context){return this.cache?this._cached??(this._cached=this.producer.produce(context)):this.producer.produce(context)}toString(){return token_1.Token.asString(this)}toJSON(){return"<unresolved-lazy>"}}class LazyString extends LazyBase{}class LazyNumber extends LazyBase{}class LazyList extends LazyBase{constructor(producer,cache,options={}){super(producer,cache),this.options=options}resolve(context){const resolved=super.resolve(context);if(!(resolved?.length===0&&this.options.omitEmpty))return resolved}}class LazyAny extends LazyBase{constructor(producer,cache,options={}){super(producer,cache),this.options=options}resolve(context){const resolved=super.resolve(context);if(!(Array.isArray(resolved)&&resolved.length===0&&this.options.omitEmptyArray))return resolved}}

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.91.0

Environment details (OS name and version, etc.)

macOS

@moltar moltar added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 16, 2023
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Aug 16, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@peterwoodworth
Copy link
Contributor

You can view the code in our open source library in this same repository, why would looking at the js files be better?

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 16, 2023
@moltar
Copy link
Contributor Author

moltar commented Aug 16, 2023

When I run a cdk command, and it errors out with a stack trace, I can click the file path in the terminal and open the exact location where the error occurred.

Provided that there are numerous versions and package managers organizing the files (e.g. pnpm uses deeply tested paths), it's not easy to find the source file.

@moltar
Copy link
Contributor Author

moltar commented Aug 16, 2023

For example, here's a stack trace I am dealing with right now:

Stack Trace
Error: Resolution error: Logical ID must adhere to the regular expression: /^[A-Za-z][A-Za-z0-9]{1,254}$/, got 'A'.
Object creation stack:
  at Function.uncachedString (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/lazy.js:1:1134)
  at new CfnElement (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/cfn-element.js:1:658)
  at new CfnInclude (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:484)
  at loadDashboardFromTemplate (/home/user/project/src/main.ts:314:20)
  at new MoinMarketingAmcQuickSightStack (/home/user/project/src/main.ts:411:23)
  at Object.<anonymous> (/home/user/project/src/main.ts:436:1)
  at Module._compile (node:internal/modules/cjs/loader:1159:14)
  at Module.m._compile (/home/user/project/node_modules/.pnpm/ts-node@10.9.1_@types+node@18.17.5_typescript@5.1.6/node_modules/ts-node/src/index.ts:1618:23)
  at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
  at Object.require.extensions.<computed> [as .ts] (/home/user/project/node_modules/.pnpm/ts-node@10.9.1_@types+node@18.17.5_typescript@5.1.6/node_modules/ts-node/src/index.ts:1621:12)
  at Module.load (node:internal/modules/cjs/loader:1037:32)
  at Function.Module._load (node:internal/modules/cjs/loader:878:12)
  at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
  at phase4 (/home/user/project/node_modules/.pnpm/ts-node@10.9.1_@types+node@18.17.5_typescript@5.1.6/node_modules/ts-node/src/bin.ts:649:14)
  at bootstrap (/home/user/project/node_modules/.pnpm/ts-node@10.9.1_@types+node@18.17.5_typescript@5.1.6/node_modules/ts-node/src/bin.ts:95:10)
  at main (/home/user/project/node_modules/.pnpm/ts-node@10.9.1_@types+node@18.17.5_typescript@5.1.6/node_modules/ts-node/src/bin.ts:55:10)
  at Object.<anonymous> (/home/user/project/node_modules/.pnpm/ts-node@10.9.1_@types+node@18.17.5_typescript@5.1.6/node_modules/ts-node/src/bin.ts:800:3)
  at Module._compile (node:internal/modules/cjs/loader:1159:14)
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
  at Module.load (node:internal/modules/cjs/loader:1037:32)
  at Function.Module._load (node:internal/modules/cjs/loader:878:12)
  at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
  at node:internal/main/run_main_module:23:47
    at validateLogicalId (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/private/logical-id.js:1:1181)
    at LogicalIDs.applyRename (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/private/logical-id.js:1:618)
    at MoinMarketingAmcQuickSightStack.getLogicalId (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/stack.js:1:7174)
    at CfnInclude.synthesizeLogicalId (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/cfn-element.js:2:683)
    at Object.produce (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/cfn-element.js:1:691)
    at LazyString.resolve (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/lazy.js:1:3929)
    at DefaultTokenResolver.resolveToken (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/resolvable.js:1:1238)
    at resolve (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2510)
    at Object.resolve [as mapToken] (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:892)
    at TokenizedStringFragments.mapTokens (/home/user/project/node_modules/.pnpm/aws-cdk-lib@2.91.0_constructs@10.2.69/node_modules/aws-cdk-lib/core/lib/string-fragments.js:1:1365)

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 17, 2023
@pahud pahud added p3 and removed p2 labels Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront feature-request A feature should be added or improved. p3
Projects
None yet
Development

No branches or pull requests

3 participants