Skip to content

typescript support#564

Merged
pelikhan merged 8 commits intomainfrom
tssupport
Jul 2, 2024
Merged

typescript support#564
pelikhan merged 8 commits intomainfrom
tssupport

Conversation

@pelikhan
Copy link
Member

@pelikhan pelikhan commented Jul 1, 2024

  • 🥳 Added support for TypeScript! Previously, the tool only supported JavaScript files, but now TypeScript files are also recognized.
  • 🔄 Renamed GENAI_JS_GLOB to GENAI_ANYJS_GLOB to accurately reflect the supported file types (JavaScript and TypeScript).
  • ↗️ Created new tsconfig.json files in many directories across the entire project. This configures the TypeScript compiler for each directory, which allows for more targeted settings per directory.
  • 🚀 Improved the script compiler. It now checks if javascript and typescript files exist in the directory before running the corresponding compilers. This could lead to efficiency improvements.
  • ✂️ Removed a few properties from the Project class. This might be part of a larger move towards reducing the class's responsibility or could be part of some refactoring work.
  • 💡 Added a new summarizer-mts.mts file. This seems like an attempt to test or showcase the new TypeScript support.
  • 🔧 Updated the model completion provider in the VS Code extension. This indicates that the extension now offers better support for both JavaScript and TypeScript.
  • 🚚 Moved some of the logic related to importing files. This could be part of larger changes to how files are processed and handled within the codebase.
  • 🧹 Cleaned up extra indentation, thus making the code more readable.
  • ☁️ Updated bundle prompts to add tsconfig.json. The bundle prompts now include configuration for the TypeScript compiler.

generated by pr-describe

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2024

The changes in the pull request branch involve several modifications in the functionality and constants used across multiple TypeScript files. Here is a summary of the changes:

  • The constant GENAI_JS_GLOB was replaced with GENAI_ANYJS_GLOB in several files. The new constant includes a wider range of file types (**/*.genai.{js,mjs,ts,mts}), which means the system will now work with .ts and .mts files in addition to the previously supported .js and .mjs files. This expands the range of scripts that can be handled.
  • The compileScript function in scripts.ts has been expanded to handle both .js and .ts files. This includes checking if such files exist in the directory and running appropriate commands to compile them.
  • In ast.ts, the TextFile class and its related code have been removed. This may impact other parts of the system that rely on this class.
  • A new constant JS_REGEX has been added in constants.ts, which seems to be used for recognizing .js files.
  • The function importPrompt in importprompt.ts has seen changes. Specifically, an onImport function has been added for tracing file imports and a register function is being imported from the tsx/esm/api module which is used to register the onImport function for callbacks.
  • In file template.ts, the templateIdFromFileName function now considers .mts files in addition to the other types.
  • The activateModelCompletionProvider function in modelcompletionprovider.ts now uses the GENAI_ANYJS_GLOB constant, expanding the file types it supports.
  • The findScripts function in state.ts also now uses the GENAI_ANYJS_GLOB constant, expanding the file types it can find.

Overall, these changes seem to be aimed at expanding the types of scripts that can be handled by the system to include TypeScript files in addition to JavaScript ones. It also includes changes for better tracing of imports.

However, the removal of the TextFile class and related code in ast.ts might impact other parts of the system. Ensure that this class is not used elsewhere, or that all its usages have been properly refactored.

LGTM 🚀

generated by pr-review

@pelikhan pelikhan changed the title Tssupport typescript support Jul 1, 2024
}
const { tsImport, register } = await import("tsx/esm/api")
unregister = register({ onImport })
const module = await tsImport(modulePath, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The promise returned by tsImport function is not handled. This could lead to uncaught promise rejection if the promise is rejected.

generated by pr-review-commit unhandled_promise

```js title="summarize.genai.mjs"
const { summarize } = await import("./summarizer.mjs")
summarize(env.generator, env.files)
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate code block detected. The same code appears twice with the title "summarize.genai.mjs".

generated by pr-docs-review-commit duplicate_code

```js title="summarize.genai.mts"
const { summarize } = await import("./summarizer.mts")
summarize(env.generator, env.files)
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect file extension in code block title. TypeScript files should use the .mts extension, not .genai.mts.

generated by pr-docs-review-commit incorrect_extension

- `.genai.mjs` use module JavaScript syntax and support imports. (`.genai.js` are eval-ed and do not support imports).
- `.genai.mjs` use module JavaScript syntax and support imports.
- `.genai.js` are eval-ed and do not support imports.
- `.genai.mts` are TypeScript module files and support imports, including dynamic imports of other TypeScript files.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect information. .genai.js files can support imports if they are renamed to .genai.mjs.

generated by pr-docs-review-commit incorrect_info

## Module Imports

You can import module installed in your project.
You can import node packages installed in your project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here. It should be "modules" instead of "module".

generated by pr-docs-review-commit typo

```

## File imports
## JavaScript imports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term "File imports" was more accurate as it is not limited to JavaScript files. The change to "JavaScript imports" is misleading.

generated by pr-docs-review-commit incorrect_term


## TypeScript imports

TypeScript (`.mts`) files can be imported using **dynamic** import only.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement "TypeScript (.mts) files can be imported using dynamic import only." is incorrect. TypeScript files can be imported both statically and dynamically, depending on the context and configuration.

generated by pr-docs-review-commit incorrect_statement

## Script files

- GenAIScript will detect any file matching `*.genai.mjs` in your workspace.
- GenAIScript will detect any file matching `*.genai.mjs`, `*.genai.js`, `*.genai.mts` in your workspace.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement is missing information about .genai.ts files, which should be included if TypeScript files are supported.

generated by pr-docs-review-commit missing_info

- `.genai.mjs` use module JavaScript syntax and support imports. (`.genai.js` are eval-ed and do not support imports).
- `.genai.mjs` use module JavaScript syntax and support imports.
- `.genai.js` are eval-ed and do not support imports.
- `.genai.mts` are TypeScript module files and support imports, including dynamic imports of other TypeScript files.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement ".genai.mts are TypeScript module files and support imports, including dynamic imports of other TypeScript files." is misleading because it implies that only dynamic imports are supported for TypeScript files, which is not the case. Static imports are also supported in TypeScript.

generated by pr-docs-review-commit incorrect_statement

## Module Imports

You can import module installed in your project.
You can import node packages installed in your project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term "node packages" should be "Node.js packages" to maintain consistency and accuracy.

generated by pr-docs-review-commit incorrect_statement

- `.genai.mjs` use module JavaScript syntax and support imports. (`.genai.js` are eval-ed and do not support imports).
- `.genai.mjs` use module JavaScript syntax and support imports.
- `.genai.js` are eval-ed and do not support imports.
- `.genai.mts` are TypeScript module files and support imports, including dynamic imports of other TypeScript files.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of file extensions is misleading. It should clarify that .genai.js files do not support ES6 module imports, and .genai.mts files are TypeScript files that support both static and dynamic imports.

generated by pr-docs-review-commit incorrect_extension_description

import.meta.url ??
new URL(__filename ?? host.projectFolder(), "file://").href

trace?.itemValue(`import`, `${modulePath}, parent: ${parentURL}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The promise returned by tsImport function is not properly handled. If it rejects, it will result in an unhandled promise rejection.

generated by pr-review-commit unhandled_promise

}

const current = await tryReadText(host.path.join(folder, defName))
if (defName === "tsconfig.json" && !ts) continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The writeText function is async but it's not awaited, this could lead to unexpected behavior.

generated by pr-review-commit async_without_await

@@ -111,7 +111,7 @@ async function callExpander(
}

try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition r.filename && !JS_REGEX.test(r.filename) is complex and could be simplified or broken down for better readability.

generated by pr-review-commit conditional_complexity

@pelikhan pelikhan merged commit 0447ac5 into main Jul 2, 2024
@pelikhan pelikhan deleted the tssupport branch July 2, 2024 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant