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: support wildcard exports when parsing dependency tree [sc-22632] #1003

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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<void> {
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dep6' // wildcard export
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 'Hello World'
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dep6' // wildcard export
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 'Hello World'
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './dep6' // wildcard export
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 'Hello World'
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -135,6 +137,8 @@ describe('dependency-parser - parser()', () => {
toAbsolutePath('dep1.js'),
toAbsolutePath('dep2.js'),
toAbsolutePath('dep3.js'),
toAbsolutePath('dep5.js'),
toAbsolutePath('dep6.js'),
])
})

Expand All @@ -149,6 +153,8 @@ describe('dependency-parser - parser()', () => {
toAbsolutePath('dep2.mjs'),
toAbsolutePath('dep3.mjs'),
toAbsolutePath('dep4.mjs'),
toAbsolutePath('dep5.mjs'),
toAbsolutePath('dep6.mjs'),
])
})

Expand Down
13 changes: 12 additions & 1 deletion packages/cli/src/services/check-parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
}

Expand All @@ -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)
},
Expand Down
Loading