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) { 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'), ]) }) 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) },