-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
48 changed files
with
1,400 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...s/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'hello' |
1 change: 1 addition & 0 deletions
1
...s/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'world' |
1 change: 1 addition & 0 deletions
1
...s/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 3 |
3 changes: 3 additions & 0 deletions
3
...src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/entrypoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { } from './dep1' | ||
import { } from './dep2.js' | ||
import { } from './dep3.js' |
1 change: 1 addition & 0 deletions
1
...li/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'hello' |
1 change: 1 addition & 0 deletions
1
...li/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'world' |
4 changes: 4 additions & 0 deletions
4
.../services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/entrypoint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { } from './dep1' | ||
import { } from './dep1.ts' | ||
import { } from './dep1.js' | ||
import { } from './dep2' |
1 change: 1 addition & 0 deletions
1
...parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value1 = 'value1' |
1 change: 1 addition & 0 deletions
1
...parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value2 = 'value2' |
1 change: 1 addition & 0 deletions
1
...parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value3 = 'value3' |
3 changes: 3 additions & 0 deletions
3
.../__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/entrypoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { value1 } from './dep1.ts' | ||
export { value2 } from './dep2.js' | ||
export { value3 } from './dep3' |
11 changes: 11 additions & 0 deletions
11
...rser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "nodenext", | ||
"esModuleInterop": true, | ||
"baseUrl": ".", | ||
"noEmit": true, | ||
"allowImportingTsExtensions": true | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ces/check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
1 change: 1 addition & 0 deletions
1
.../check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/.node-version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v22.12.0 |
22 changes: 22 additions & 0 deletions
22
...ck-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/checkly.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { defineConfig } from 'checkly' | ||
|
||
const config = defineConfig({ | ||
projectName: 'TSConfig Paths Sample Project', | ||
logicalId: 'tsconfig-paths-sample-project', | ||
checks: { | ||
frequency: 10, | ||
locations: ['us-east-1'], | ||
tags: ['mac'], | ||
runtimeId: '2024.09', | ||
checkMatch: '**/__checks__/**/*.check.ts', | ||
browserChecks: { | ||
testMatch: '**/__checks__/**/*.spec.ts', | ||
}, | ||
}, | ||
cli: { | ||
runLocation: 'us-east-1', | ||
reporters: ['list'], | ||
}, | ||
}) | ||
|
||
export default config |
1 change: 1 addition & 0 deletions
1
.../check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/file1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'file1' |
1 change: 1 addition & 0 deletions
1
.../check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/file2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'file2' |
1 change: 1 addition & 0 deletions
1
...parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/folder/file1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { value } from './file2' |
1 change: 1 addition & 0 deletions
1
...parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/folder/file2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'file2' |
3 changes: 3 additions & 0 deletions
3
.../check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { value as value1 } from './file1' | ||
export { value as value2 } from './file2' | ||
export { value as value3 } from './folder/file1' |
1 change: 1 addition & 0 deletions
1
...rser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...ck-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@internal/lib", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"clean": "rimraf ./dist", | ||
"prepare": "npm run clean && tsc --build" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^6.0.1", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...k-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib1/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"exclude": [ | ||
"dist", | ||
"node_modules" | ||
], | ||
"include": [ | ||
"./**/*.ts" | ||
], | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "nodenext", | ||
"outDir": "dist", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"declarationMap": true | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib2/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const name = 'lib2' |
1 change: 1 addition & 0 deletions
1
...heck-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib3/foo/bar.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 11517 |
9 changes: 9 additions & 0 deletions
9
...k-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/lib3/jsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "nodenext", | ||
"esModuleInterop": true, | ||
"baseUrl": "." | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ck-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...s/check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "tsconfig-paths-sample-project", | ||
"dependencies": { | ||
"checkly": "^4.15.0" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.49.1", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ck-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/src/entrypoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { value1 } from '@internal/lib1' | ||
import { value } from '@/foo/bar' | ||
import { name } from 'lib2' |
17 changes: 17 additions & 0 deletions
17
.../check-parser/__tests__/check-parser-fixtures/tsconfig-paths-sample-project/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "nodenext", | ||
"esModuleInterop": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"@internal/lib1": [ | ||
"./lib1" | ||
], | ||
"@/*": [ | ||
"./lib3/*" | ||
] | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ices/check-parser/__tests__/check-parser-fixtures/tsconfig-paths-unused/src/entrypoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const value = 'nothing here' |
17 changes: 17 additions & 0 deletions
17
...services/check-parser/__tests__/check-parser-fixtures/tsconfig-paths-unused/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "nodenext", | ||
"esModuleInterop": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"@internal/lib1": [ | ||
"./lib1" | ||
], | ||
"@/*": [ | ||
"./lib3/*" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.