Skip to content

Commit 6fbb3d4

Browse files
committed
feat: add workspace support
1 parent c2cd0ed commit 6fbb3d4

File tree

36 files changed

+758
-109
lines changed

36 files changed

+758
-109
lines changed

packages/cli/src/commands/baseCommand.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import prompts from 'prompts'
33
import { Command } from '@oclif/core'
44
import { api } from '../rest/api'
55
import { CommandStyle } from '../helpers/command-style'
6-
import { PackageFilesResolver } from '../services/check-parser/package-files/resolver'
76
import { PackageJsonFile } from '../services/check-parser/package-files/package-json-file'
7+
import { detectNearestPackageJson } from '../services/check-parser/package-files/package-manager'
88

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

2020
async loadPackageJsonOfSelf (): Promise<PackageJsonFile | undefined> {
21-
if (!this.#packageJsonLoader) {
22-
const resolver = new PackageFilesResolver()
23-
this.#packageJsonLoader = resolver.loadPackageJsonFile(__filename)
24-
}
21+
try {
22+
if (!this.#packageJsonLoader) {
23+
this.#packageJsonLoader = detectNearestPackageJson(__dirname)
24+
}
2525

26-
return await this.#packageJsonLoader
26+
return await this.#packageJsonLoader
27+
} catch {
28+
return
29+
}
2730
}
2831

2932
async checkEngineCompatibility (): Promise<void> {

packages/cli/src/commands/import/plan.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ import { ExitError } from '@oclif/core/errors'
2626
import { confirmCommit, performCommitAction } from './commit'
2727
import { confirmApply, performApplyAction } from './apply'
2828
import { generateChecklyConfig } from '../../services/checkly-config-codegen'
29-
import { PackageFilesResolver } from '../../services/check-parser/package-files/resolver'
3029
import { PackageJsonFile } from '../../services/check-parser/package-files/package-json-file'
31-
import { detectPackageManager, knownPackageManagers, PackageManager } from '../../services/check-parser/package-files/package-manager'
30+
import { detectNearestPackageJson, detectPackageManager, knownPackageManagers, PackageManager } from '../../services/check-parser/package-files/package-manager'
3231
import { parseProject } from '../../services/project-parser'
3332
import { Runtime } from '../../rest/runtimes'
3433
import { ConstructExport, Project, Session } from '../../constructs/project'
@@ -704,10 +703,11 @@ ${chalk.cyan('For safety, resources are not deletable until the plan has been co
704703
}
705704

706705
async #loadPackageJson (): Promise<PackageJsonFile | undefined> {
707-
const resolver = new PackageFilesResolver()
708-
return await resolver.loadPackageJsonFile(process.cwd(), {
709-
isDir: true,
710-
})
706+
try {
707+
return await detectNearestPackageJson(process.cwd())
708+
} catch {
709+
return
710+
}
711711
}
712712

713713
#createPackageJson (logicalId: string): PackageJsonFile {

packages/cli/src/constructs/browser-check.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import fs from 'node:fs/promises'
2-
import path from 'node:path'
32

43
import { CheckProps, RuntimeCheck, RuntimeCheckProps } from './check'
54
import { Session, SharedFileRef } from './project'
6-
import { pathToPosix } from '../services/util'
75
import { Content, Entrypoint, isContent, isEntrypoint } from './construct'
86
import { detectSnapshots } from '../services/snapshot-service'
97
import { PlaywrightConfig } from './playwright-config'
@@ -168,7 +166,7 @@ export class BrowserCheck extends RuntimeCheck {
168166
const deps: SharedFileRef[] = []
169167
for (const { filePath, content } of parsed.dependencies) {
170168
deps.push(Session.registerSharedFile({
171-
path: pathToPosix(path.relative(Session.basePath!, filePath)),
169+
path: Session.relativePosixPath(filePath),
172170
content,
173171
}))
174172
}

packages/cli/src/constructs/check-group-v1.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { Diagnostics } from './diagnostics'
1717
import { DeprecatedConstructDiagnostic, DeprecatedPropertyDiagnostic, InvalidPropertyValueDiagnostic } from './construct-diagnostics'
1818
import CheckTypes from '../constants'
1919
import { CheckConfigDefaults } from '../services/checkly-config-loader'
20-
import { pathToPosix } from '../services/util'
2120
import { AlertChannelSubscription } from './alert-channel-subscription'
2221
import { BrowserCheck } from './browser-check'
2322
import { CheckGroupRef } from './check-group-ref'
@@ -438,7 +437,7 @@ export class CheckGroupV1 extends Construct {
438437
},
439438
// the browserChecks props inherited from the group are applied in BrowserCheck.constructor()
440439
}
441-
const checkLogicalId = pathToPosix(path.relative(Session.basePath!, filepath))
440+
const checkLogicalId = Session.relativePosixPath(filepath)
442441
if (checkType === CheckTypes.BROWSER) {
443442
new BrowserCheck(checkLogicalId, props)
444443
} else {

packages/cli/src/constructs/internal/codegen/snippet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ export function parseSnippetDependencies (content: string): string[] {
5454
}
5555

5656
return dependencies
57-
.filter(value => value.startsWith(SNIPPET_PATH_PREFIX))
58-
.map(value => value.slice(SNIPPET_PATH_PREFIX.length))
57+
.filter(({ importPath }) => importPath.startsWith(SNIPPET_PATH_PREFIX))
58+
.map(({ importPath }) => importPath.slice(SNIPPET_PATH_PREFIX.length))
5959
}

packages/cli/src/constructs/project.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Diagnostics } from './diagnostics'
2424
import { ConstructDiagnostics, InvalidPropertyValueDiagnostic } from './construct-diagnostics'
2525
import { ProjectBundle, ProjectDataBundle } from './project-bundle'
2626
import { pathToPosix } from '../services/util'
27+
import { Workspace } from '../services/check-parser/package-files/workspace'
2728

2829
export interface ProjectProps {
2930
/**
@@ -243,6 +244,7 @@ export class Session {
243244
static privateLocations: PrivateLocationApi[]
244245
static parsers = new Map<string, Parser>()
245246
static constructExports: ConstructExport[] = []
247+
static workspace?: Workspace
246248

247249
static async loadFile<T = unknown> (filePath: string): Promise<T> {
248250
const loader = this.loader
@@ -337,6 +339,7 @@ export class Session {
337339
const parser = new Parser({
338340
supportedNpmModules: Object.keys(runtime.dependencies),
339341
checkUnsupportedModules: Session.verifyRuntimeDependencies,
342+
workspace: Session.workspace,
340343
})
341344

342345
Session.parsers.set(runtime.name, parser)

packages/cli/src/services/__tests__/checkly-config-loader.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'node:path'
22

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

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

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

packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/workspace-example/package-lock.json

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "workspace-example",
3+
"version": "1.0.0",
4+
"workspaces": [
5+
"packages/*"
6+
]
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'checkly'
2+
3+
const config = defineConfig({
4+
projectName: 'Workspace Example Project',
5+
logicalId: '56fbaf4d-fc2c-418c-868a-3f461809ed37',
6+
checks: {
7+
checkMatch: '**/__checks__/**/*.check.ts',
8+
tags: [
9+
'mac',
10+
],
11+
},
12+
})
13+
14+
export default config

0 commit comments

Comments
 (0)