Skip to content

Commit

Permalink
better handling of file editing
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbgt committed Nov 1, 2024
1 parent 0bab90d commit f37e955
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 177 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ We welcome contributions from the community. Please read our [contributing guide

This project is in the early stages of development. We are actively working on the project and will be releasing new features and improvements regularly, which may include a rewrite into a more efficient and generic language like Rust or Go. Please check our issues and project board for more information, and don't for.

- [x] Limited support for NodeJS/Typescript (no require or dynamic imports, no decorators)
- [x] Limited support for NodeJS/Typescript
- [x] Simple UI
- [x] Support NodeJS require and dynamic imports
- [ ] Full support for NodeJS/Typescript
- [ ] Python support with Flask
- [ ] Django support
Expand Down
18 changes: 17 additions & 1 deletion packages/cli/src/helper/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ function getFilePathsFromTree(tree: dependencyTree.Tree) {
return uniqueFilePaths;
}

// Resolve file paths from import/require statements
export function resolveFilePath(
importPath: string,
currentFile: string,
Expand Down Expand Up @@ -169,3 +168,20 @@ export function resolveFilePath(
// Skip external dependencies (e.g., node_modules)
return null;
}

export function removeIndexesFromSourceCode(
sourceCode: string,
indexesToRemove: { startIndex: number; endIndex: number }[],
) {
let newSourceCode = sourceCode;

// sort to start removing from the of the file end
indexesToRemove.sort((a, b) => b.startIndex - a.startIndex);

indexesToRemove.forEach(({ startIndex, endIndex }) => {
newSourceCode =
newSourceCode.slice(0, startIndex) + newSourceCode.slice(endIndex);
});

return newSourceCode;
}
Loading

0 comments on commit f37e955

Please sign in to comment.