Skip to content

Commit 19656b8

Browse files
authored
feat: support tsconfig paths and package-relative imports [sc-22644] (#1006)
* feat: async dependency collector * refactor: switch to a sync implementation to avoid changes to constructs * refactor: remove unnecessary try/catch * feat: look up original TS sources when dealing with folders as modules * fix: include package.json when resolving module folders * feat: let parser know how tsconfig paths were resolved for a file This optionally allows the parser to massage the file structure into an alternate output format. * feat: add jsconfig.json support * fix: supported module check was accidentally negated * feat: bundle relevant tsconfig/jsconfig.json files These files are currently not utilized by the backend but they might be in the near future. * feat: cache all source files and set up unique IDs for later dedup purposes * feat: add tests for tsconfig behavior * feat: more complete support for imports with extensions * chore: remove unused code * fix: remove mistakenly implemented useless package-relative path support * fix: remove unused variable * fix: remove unused variable * feat: cache common dependencies within a Session Shares a common Parser (or Parsers, one per runtime) within a Session and avoids unnecessary AST walks for filePaths the parser has already seen when parsing other entrypoints. Share PackageFilesResolver so that its file caches can be shared within the same Parser (which is now also shared within the Session), and cache its result per filePath to avoid duplicate work. Helps use cases where there are multiple entrypoints that share common libraries. * fix: remove allowImportingTsExtensions support Does not play well during a nested lookup when we're looking up a path that we've already resolved to a candidate with a .ts extension earlier in the process. Not a super useful feature anyway. * chore: empty out package-lock.json in fixtures, keep file * feat: support `index.json` which apparently works
1 parent 5dbc83f commit 19656b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1400
-111
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Check, CheckProps } from './check'
33
import { HttpHeader } from './http-header'
44
import { Session } from './project'
55
import { QueryParam } from './query-param'
6-
import { Parser } from '../services/check-parser/parser'
76
import { pathToPosix } from '../services/util'
87
import { printDeprecationWarning } from '../reporters/util'
98
import { Content, Entrypoint } from './construct'
@@ -352,10 +351,7 @@ export class ApiCheck extends Check {
352351
if (!runtime) {
353352
throw new Error(`${runtimeId} is not supported`)
354353
}
355-
const parser = new Parser({
356-
supportedNpmModules: Object.keys(runtime.dependencies),
357-
checkUnsupportedModules: Session.verifyRuntimeDependencies,
358-
})
354+
const parser = Session.getParser(runtime)
359355
const parsed = parser.parse(absoluteEntrypoint)
360356
// Maybe we can get the parsed deps with the content immediately
361357

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from 'path'
22
import { Check, CheckProps } from './check'
33
import { Session } from './project'
4-
import { Parser } from '../services/check-parser/parser'
54
import { CheckConfigDefaults } from '../services/checkly-config-loader'
65
import { pathToPosix } from '../services/util'
76
import { Content, Entrypoint } from './construct'
@@ -119,10 +118,7 @@ export class BrowserCheck extends Check {
119118
if (!runtime) {
120119
throw new Error(`${runtimeId} is not supported`)
121120
}
122-
const parser = new Parser({
123-
supportedNpmModules: Object.keys(runtime.dependencies),
124-
checkUnsupportedModules: Session.verifyRuntimeDependencies,
125-
})
121+
const parser = Session.getParser(runtime)
126122
const parsed = parser.parse(entry)
127123
// Maybe we can get the parsed deps with the content immediately
128124

packages/cli/src/constructs/multi-step-check.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from 'path'
22
import { Check, CheckProps } from './check'
33
import { Session } from './project'
4-
import { Parser } from '../services/check-parser/parser'
54
import { CheckConfigDefaults } from '../services/checkly-config-loader'
65
import { pathToPosix } from '../services/util'
76
import { Content, Entrypoint } from './construct'
@@ -104,10 +103,7 @@ export class MultiStepCheck extends Check {
104103
if (!runtime) {
105104
throw new Error(`${runtimeId} is not supported`)
106105
}
107-
const parser = new Parser({
108-
supportedNpmModules: Object.keys(runtime.dependencies),
109-
checkUnsupportedModules: Session.verifyRuntimeDependencies,
110-
})
106+
const parser = Session.getParser(runtime)
111107
const parsed = parser.parse(entry)
112108
// Maybe we can get the parsed deps with the content immediately
113109

packages/cli/src/constructs/project.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as api from '../rest/api'
22
import { CheckConfigDefaults } from '../services/checkly-config-loader'
3+
import { Parser } from '../services/check-parser/parser'
34
import { Construct } from './construct'
45
import { ValidationError } from './validator-error'
56

@@ -147,6 +148,7 @@ export class Session {
147148
static loadingChecklyConfigFile: boolean
148149
static checklyConfigFileConstructs?: Construct[]
149150
static privateLocations: PrivateLocationApi[]
151+
static parsers = new Map<string, Parser>()
150152

151153
static registerConstruct (construct: Construct) {
152154
if (Session.project) {
@@ -191,4 +193,20 @@ export class Session {
191193
}
192194
return Session.availableRuntimes[effectiveRuntimeId]
193195
}
196+
197+
static getParser (runtime: Runtime): Parser {
198+
const cachedParser = Session.parsers.get(runtime.name)
199+
if (cachedParser !== undefined) {
200+
return cachedParser
201+
}
202+
203+
const parser = new Parser({
204+
supportedNpmModules: Object.keys(runtime.dependencies),
205+
checkUnsupportedModules: Session.verifyRuntimeDependencies,
206+
})
207+
208+
Session.parsers.set(runtime.name, parser)
209+
210+
return parser
211+
}
194212
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 'hello'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 'world'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { } from './dep1'
2+
import { } from './dep2.js'
3+
import { } from './dep3.js'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 'hello'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const value = 'world'

0 commit comments

Comments
 (0)