Skip to content
Draft
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
15 changes: 9 additions & 6 deletions packages/cli/src/commands/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import prompts from 'prompts'
import { Command } from '@oclif/core'
import { api } from '../rest/api'
import { CommandStyle } from '../helpers/command-style'
import { PackageFilesResolver } from '../services/check-parser/package-files/resolver'
import { PackageJsonFile } from '../services/check-parser/package-files/package-json-file'
import { detectNearestPackageJson } from '../services/check-parser/package-files/package-manager'

export type BaseCommandClass = typeof Command & {
coreCommand: boolean
Expand All @@ -18,12 +18,15 @@ export abstract class BaseCommand extends Command {
#packageJsonLoader?: Promise<PackageJsonFile | undefined>

async loadPackageJsonOfSelf (): Promise<PackageJsonFile | undefined> {
if (!this.#packageJsonLoader) {
const resolver = new PackageFilesResolver()
this.#packageJsonLoader = resolver.loadPackageJsonFile(__filename)
}
try {
if (!this.#packageJsonLoader) {
this.#packageJsonLoader = detectNearestPackageJson(__dirname)
}

return await this.#packageJsonLoader
return await this.#packageJsonLoader
} catch {
return
}
}

async checkEngineCompatibility (): Promise<void> {
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/commands/import/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import { ExitError } from '@oclif/core/errors'
import { confirmCommit, performCommitAction } from './commit'
import { confirmApply, performApplyAction } from './apply'
import { generateChecklyConfig } from '../../services/checkly-config-codegen'
import { PackageFilesResolver } from '../../services/check-parser/package-files/resolver'
import { PackageJsonFile } from '../../services/check-parser/package-files/package-json-file'
import { detectPackageManager, knownPackageManagers, PackageManager } from '../../services/check-parser/package-files/package-manager'
import { detectNearestPackageJson, detectPackageManager, knownPackageManagers, PackageManager } from '../../services/check-parser/package-files/package-manager'
import { parseProject } from '../../services/project-parser'
import { Runtime } from '../../rest/runtimes'
import { ConstructExport, Project, Session } from '../../constructs/project'
Expand Down Expand Up @@ -704,10 +703,11 @@ ${chalk.cyan('For safety, resources are not deletable until the plan has been co
}

async #loadPackageJson (): Promise<PackageJsonFile | undefined> {
const resolver = new PackageFilesResolver()
return await resolver.loadPackageJsonFile(process.cwd(), {
isDir: true,
})
try {
return await detectNearestPackageJson(process.cwd())
} catch {
return
}
}

#createPackageJson (logicalId: string): PackageJsonFile {
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/constructs/browser-check.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import fs from 'node:fs/promises'
import path from 'node:path'

import { CheckProps, RuntimeCheck, RuntimeCheckProps } from './check'
import { Session, SharedFileRef } from './project'
import { pathToPosix } from '../services/util'
import { Content, Entrypoint, isContent, isEntrypoint } from './construct'
import { detectSnapshots } from '../services/snapshot-service'
import { PlaywrightConfig } from './playwright-config'
Expand Down Expand Up @@ -168,7 +166,7 @@ export class BrowserCheck extends RuntimeCheck {
const deps: SharedFileRef[] = []
for (const { filePath, content } of parsed.dependencies) {
deps.push(Session.registerSharedFile({
path: pathToPosix(path.relative(Session.basePath!, filePath)),
path: Session.relativePosixPath(filePath),
content,
}))
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/constructs/check-group-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Diagnostics } from './diagnostics'
import { DeprecatedConstructDiagnostic, DeprecatedPropertyDiagnostic, InvalidPropertyValueDiagnostic } from './construct-diagnostics'
import CheckTypes from '../constants'
import { CheckConfigDefaults } from '../services/checkly-config-loader'
import { pathToPosix } from '../services/util'
import { AlertChannelSubscription } from './alert-channel-subscription'
import { BrowserCheck } from './browser-check'
import { CheckGroupRef } from './check-group-ref'
Expand Down Expand Up @@ -438,7 +437,7 @@ export class CheckGroupV1 extends Construct {
},
// the browserChecks props inherited from the group are applied in BrowserCheck.constructor()
}
const checkLogicalId = pathToPosix(path.relative(Session.basePath!, filepath))
const checkLogicalId = Session.relativePosixPath(filepath)
if (checkType === CheckTypes.BROWSER) {
new BrowserCheck(checkLogicalId, props)
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/constructs/internal/codegen/snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ export function parseSnippetDependencies (content: string): string[] {
}

return dependencies
.filter(value => value.startsWith(SNIPPET_PATH_PREFIX))
.map(value => value.slice(SNIPPET_PATH_PREFIX.length))
.filter(({ importPath }) => importPath.startsWith(SNIPPET_PATH_PREFIX))
.map(({ importPath }) => importPath.slice(SNIPPET_PATH_PREFIX.length))
}
3 changes: 3 additions & 0 deletions packages/cli/src/constructs/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Diagnostics } from './diagnostics'
import { ConstructDiagnostics, InvalidPropertyValueDiagnostic } from './construct-diagnostics'
import { ProjectBundle, ProjectDataBundle } from './project-bundle'
import { pathToPosix } from '../services/util'
import { Workspace } from '../services/check-parser/package-files/workspace'

export interface ProjectProps {
/**
Expand Down Expand Up @@ -243,6 +244,7 @@ export class Session {
static privateLocations: PrivateLocationApi[]
static parsers = new Map<string, Parser>()
static constructExports: ConstructExport[] = []
static workspace?: Workspace

static async loadFile<T = unknown> (filePath: string): Promise<T> {
const loader = this.loader
Expand Down Expand Up @@ -337,6 +339,7 @@ export class Session {
const parser = new Parser({
supportedNpmModules: Object.keys(runtime.dependencies),
checkUnsupportedModules: Session.verifyRuntimeDependencies,
workspace: Session.workspace,
})

Session.parsers.set(runtime.name, parser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'node:path'

import { describe, it, expect } from 'vitest'

import { loadChecklyConfig } from '../checkly-config-loader'
import { loadChecklyConfig, defaultFilenames } from '../checkly-config-loader'
import { splitConfigFilePath } from '../util'

describe('loadChecklyConfig()', () => {
Expand All @@ -25,8 +25,10 @@ describe('loadChecklyConfig()', () => {
try {
await loadChecklyConfig(configDir)
} catch (e: any) {
expect(e.message).toContain(`Unable to locate a config at ${configDir} with ${
['checkly.config.ts', 'checkly.config.mts', 'checkly.config.cts', 'checkly.config.js', 'checkly.config.mjs', 'checkly.config.cjs'].join(', ')}.`)
expect(e.message).toContain(`Unable to detect a Checkly configuration file`)
for (const filename of defaultFilenames) {
expect(e.message).toContain(filename)
}
}
})
it('config TS file should export an object', async () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "workspace-example",
"version": "1.0.0",
"workspaces": [
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'checkly'

const config = defineConfig({
projectName: 'Workspace Example Project',
logicalId: '56fbaf4d-fc2c-418c-868a-3f461809ed37',
checks: {
checkMatch: '**/__checks__/**/*.check.ts',
tags: [
'mac',
],
},
})

export default config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "bar",
"version": "1.0.0",
"main": "dist/index.js",
"exports": {
".": "./dist/index.js"
},
"dependencies": {
"foo": "*",
"baz": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiCheck } from 'checkly/constructs'

new ApiCheck('api-check-1', {
name: 'API Check #1',
request: {
url: 'https://api.checklyhq.com',
method: 'GET',
},
setupScript: {
entrypoint: './setup.ts'
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { value } from '@lib/helper'

console.log(value)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { value } from '@lib/helper'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { value } from 'foo'
export { value as value2 } from 'baz/lib/dep2'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"declaration": true,
"module": "nodenext",
"esModuleInterop": true,
"outDir": "dist",
"rootDirs": [
"src",
],
"baseUrl": "./src",
"strict": true,
"target": "esnext",
"sourceMap": true,
"paths": {
"@lib/*": [
"./lib/*"
]
}
},
"include": [
"src/**/*",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "baz",
"version": "1.0.0",
"main": "dist/index.js",
"exports": {
".": "./dist/index.js",
"./lib/dep2": "./dist/lib/dep2.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { value } from './lib/dep1'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"declaration": true,
"module": "nodenext",
"esModuleInterop": true,
"outDir": "dist",
"rootDirs": [
"src"
],
"strict": true,
"target": "esnext",
"sourceMap": true
},
"include": [
"src/**/*"
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "foo",
"version": "1.0.0",
"main": "dist/index.js",
"exports": {
".": "./dist/index.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { value } from './lib/dep1'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"declaration": true,
"module": "nodenext",
"esModuleInterop": true,
"outDir": "dist",
"rootDirs": [
"src"
],
"strict": true,
"target": "esnext",
"sourceMap": true
},
"include": [
"src/**/*"
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ export class JsonSourceFile<Schema> {
// Ignore.
}
}

static async loadFromFilePath<Schema> (filePath: string): Promise<JsonSourceFile<Schema> | undefined> {
const sourceFile = await SourceFile.loadFromFilePath(filePath)
if (!sourceFile) {
return
}

return JsonSourceFile.loadFromSourceFile(sourceFile)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class UninitializedJsonTextSourceFileParserState extends SourceFileParser {

async #parser (): Promise<SourceFileParser> {
try {
const { parseJsonText, convertToObject } = await import('typescript')
const typescriptExports = await import('typescript')
const { parseJsonText, convertToObject } = typescriptExports.default

const parser = new SourceFileParserFuncState(<T>(sourceFile: SourceFile) => {
const errors: any[] = []
Expand Down
Loading
Loading