From ec1661ad679181c251c548b92a7ee8cb3f9ff5f1 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Fri, 13 Dec 2024 17:44:51 +0900 Subject: [PATCH 1/3] feat: add a hidden flag to output the project bundle for debug purposes The new flag, `--debug-bundle`, outputs the project bundle payload as-is after the project has been parsed. The bundle is output to a file, by default `./debug-bundle.json`. A different file can be chosen with the new `--debug-bundle-output-file` flag, which is also hidden. --- packages/cli/src/commands/deploy.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index 07992498..166209a3 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -1,3 +1,4 @@ +import * as fs from 'fs/promises' import * as api from '../rest/api' import config from '../services/config' import prompts from 'prompts' @@ -61,6 +62,16 @@ export default class Deploy extends AuthCommand { allowNo: true, env: 'CHECKLY_VERIFY_RUNTIME_DEPENDENCIES', }), + 'debug-bundle': Flags.boolean({ + description: 'Output the project bundle to a file without deploying any resources.', + default: false, + hidden: true, + }), + 'debug-bundle-output-file': Flags.string({ + description: 'The file to output the debug debug bundle to.', + default: './debug-bundle.json', + hidden: true, + }), } async run (): Promise { @@ -73,6 +84,8 @@ export default class Deploy extends AuthCommand { output, config: configFilename, 'verify-runtime-dependencies': verifyRuntimeDependencies, + 'debug-bundle': debugBundle, + 'debug-bundle-output-file': debugBundleOutputFile, } = flags const { configDirectory, configFilenames } = splitConfigFilePath(configFilename) const { @@ -120,6 +133,13 @@ export default class Deploy extends AuthCommand { } } + if (debugBundle) { + const output = JSON.stringify(projectPayload, null, 2) + await fs.writeFile(debugBundleOutputFile, output, 'utf8') + this.log(`Successfully wrote debug bundle to "${debugBundleOutputFile}".`) + return + } + const { data: account } = await api.accounts.get(config.getAccountId()) if (!force && !preview) { From e3340825132f3ef75d90d1f6b08801cd7b2ec59a Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Fri, 13 Dec 2024 17:55:31 +0900 Subject: [PATCH 2/3] feat: support wildcard exports when parsing code for dependencies Previously only named exports were supported. --- packages/cli/src/services/check-parser/parser.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/services/check-parser/parser.ts b/packages/cli/src/services/check-parser/parser.ts index 1bb60bda..821b0c19 100644 --- a/packages/cli/src/services/check-parser/parser.ts +++ b/packages/cli/src/services/check-parser/parser.ts @@ -251,6 +251,11 @@ export class Parser { if (node.source.type !== 'Literal') return Parser.registerDependency(node.source.value, localDependencies, npmDependencies) }, + ExportAllDeclaration (node: any) { + if (node.source === null) return + if (node.source.type !== 'Literal') return + Parser.registerDependency(node.source.value, localDependencies, npmDependencies) + }, } } @@ -264,7 +269,13 @@ export class Parser { ExportNamedDeclaration (node: TSESTree.ExportNamedDeclaration) { // The statement isn't importing another dependency if (node.source === null) return - // For now, we only support literal strings in the import statement + // For now, we only support literal strings in the export statement + if (node.source.type !== tsParser.TSESTree.AST_NODE_TYPES.Literal) return + Parser.registerDependency(node.source.value, localDependencies, npmDependencies) + }, + ExportAllDeclaration (node: TSESTree.ExportAllDeclaration) { + if (node.source === null) return + // For now, we only support literal strings in the export statement if (node.source.type !== tsParser.TSESTree.AST_NODE_TYPES.Literal) return Parser.registerDependency(node.source.value, localDependencies, npmDependencies) }, From 96c41c0747e8ffa11c5c47f85ef900418c75dea2 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Fri, 13 Dec 2024 18:22:35 +0900 Subject: [PATCH 3/3] feat: use wildcard export in tests Additionally, to make sure that not all files in the tree are getting included automatically (which would have invalidated the wildcard export tests), an unreachable file that should not appear in the list of dependencies was added to the relevant examples. --- .../check-parser-fixtures/common-esm-example/dep5.mjs | 1 + .../check-parser-fixtures/common-esm-example/dep6.mjs | 1 + .../check-parser-fixtures/common-esm-example/entrypoint.mjs | 1 + .../common-esm-example/unreachable.mjs | 4 ++++ .../check-parser-fixtures/esmodules-example/dep5.js | 1 + .../check-parser-fixtures/esmodules-example/dep6.js | 1 + .../check-parser-fixtures/esmodules-example/entrypoint.js | 1 + .../check-parser-fixtures/esmodules-example/unreachable.js | 4 ++++ .../check-parser-fixtures/simple-example/unreachable.js | 4 ++++ .../check-parser-fixtures/typescript-example/dep5.ts | 1 + .../check-parser-fixtures/typescript-example/dep6.ts | 1 + .../check-parser-fixtures/typescript-example/entrypoint.ts | 1 + .../check-parser-fixtures/typescript-example/unreachable.ts | 4 ++++ .../services/check-parser/__tests__/check-parser.spec.ts | 6 ++++++ 14 files changed, 31 insertions(+) create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep5.mjs create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep6.mjs create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/unreachable.mjs create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep5.js create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep6.js create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/unreachable.js create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/simple-example/unreachable.js create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep5.ts create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep6.ts create mode 100644 packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/unreachable.ts diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep5.mjs b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep5.mjs new file mode 100644 index 00000000..97e6ca0f --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep5.mjs @@ -0,0 +1 @@ +export * from './dep6' // wildcard export diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep6.mjs b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep6.mjs new file mode 100644 index 00000000..88f52791 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/dep6.mjs @@ -0,0 +1 @@ +export const value = 'Hello World' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/entrypoint.mjs b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/entrypoint.mjs index 589dea66..6593fda0 100644 --- a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/entrypoint.mjs +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/entrypoint.mjs @@ -2,6 +2,7 @@ import dep2 from './dep2' import { dep3 } from './dep3' export { value } from './dep1' export { dep4 } from './dep4.mjs' +export { value as otherValue } from './dep5.mjs' /* eslint-disable no-console */ console.log('Received ', dep2, dep3) diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/unreachable.mjs b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/unreachable.mjs new file mode 100644 index 00000000..cd173c91 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/common-esm-example/unreachable.mjs @@ -0,0 +1,4 @@ +// This file is intentionally not reachable from the entrypoint and should +// not appear in the list of dependencies. + +export const unreachable = true diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep5.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep5.js new file mode 100644 index 00000000..97e6ca0f --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep5.js @@ -0,0 +1 @@ +export * from './dep6' // wildcard export diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep6.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep6.js new file mode 100644 index 00000000..88f52791 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/dep6.js @@ -0,0 +1 @@ +export const value = 'Hello World' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/entrypoint.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/entrypoint.js index ce369a73..51d2f577 100644 --- a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/entrypoint.js +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/entrypoint.js @@ -1,6 +1,7 @@ import dep2 from './dep2' import { dep3 } from './dep3' export { value } from './dep1' +export { value as otherValue } from './dep5' /* eslint-disable no-console */ console.log('Received ', dep2, dep3) diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/unreachable.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/unreachable.js new file mode 100644 index 00000000..cd173c91 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/esmodules-example/unreachable.js @@ -0,0 +1,4 @@ +// This file is intentionally not reachable from the entrypoint and should +// not appear in the list of dependencies. + +export const unreachable = true diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/simple-example/unreachable.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/simple-example/unreachable.js new file mode 100644 index 00000000..cd173c91 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/simple-example/unreachable.js @@ -0,0 +1,4 @@ +// This file is intentionally not reachable from the entrypoint and should +// not appear in the list of dependencies. + +export const unreachable = true diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep5.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep5.ts new file mode 100644 index 00000000..97e6ca0f --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep5.ts @@ -0,0 +1 @@ +export * from './dep6' // wildcard export diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep6.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep6.ts new file mode 100644 index 00000000..88f52791 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/dep6.ts @@ -0,0 +1 @@ +export const value = 'Hello World' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/entrypoint.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/entrypoint.ts index 5188ef42..ccb5050b 100644 --- a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/entrypoint.ts +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/entrypoint.ts @@ -7,6 +7,7 @@ import * as moduleImport from './module' import * as modulePackage from './module-package' import { ExternalFirstPage } from './pages/external.first.page.js' import { ExternalSecondPage } from './pages/external.second.page' +export { value } from './dep5' // named export export function doMath (num: number): number { return add(num, subtract(10, 7)) diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/unreachable.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/unreachable.ts new file mode 100644 index 00000000..efc0c087 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/typescript-example/unreachable.ts @@ -0,0 +1,4 @@ +// This file is intentionally not reachable from the entrypoint and should +// not appear in the list of dependencies. + +export const value = 'Hello World' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts b/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts index decf5d73..783e77a5 100644 --- a/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts +++ b/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts @@ -116,6 +116,8 @@ describe('dependency-parser - parser()', () => { toAbsolutePath('dep2.ts'), toAbsolutePath('dep3.ts'), toAbsolutePath('dep4.js'), + toAbsolutePath('dep5.ts'), + toAbsolutePath('dep6.ts'), toAbsolutePath('module-package', 'main.js'), toAbsolutePath('module-package', 'package.json'), toAbsolutePath('module', 'index.ts'), @@ -135,6 +137,8 @@ describe('dependency-parser - parser()', () => { toAbsolutePath('dep1.js'), toAbsolutePath('dep2.js'), toAbsolutePath('dep3.js'), + toAbsolutePath('dep5.js'), + toAbsolutePath('dep6.js'), ]) }) @@ -149,6 +153,8 @@ describe('dependency-parser - parser()', () => { toAbsolutePath('dep2.mjs'), toAbsolutePath('dep3.mjs'), toAbsolutePath('dep4.mjs'), + toAbsolutePath('dep5.mjs'), + toAbsolutePath('dep6.mjs'), ]) })