Skip to content

Commit 15555e0

Browse files
authored
better handling of file editing (#25)
* better handling of file editing * changelog
1 parent 0bab90d commit 15555e0

File tree

6 files changed

+215
-177
lines changed

6 files changed

+215
-177
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ We welcome contributions from the community. Please read our [contributing guide
164164

165165
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.
166166

167-
- [x] Limited support for NodeJS/Typescript (no require or dynamic imports, no decorators)
167+
- [x] Limited support for NodeJS/Typescript
168168
- [x] Simple UI
169-
- [x] Support NodeJS require and dynamic imports
170169
- [ ] Full support for NodeJS/Typescript
171170
- [ ] Python support with Flask
172171
- [ ] Django support

packages/cli/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
Use indexes when editing file instead of search/replace
6+
57
## [0.0.16] - 2024-10-30
68

79
Add support for dynamic import in javascript

packages/cli/src/helper/file.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ function getFilePathsFromTree(tree: dependencyTree.Tree) {
129129
return uniqueFilePaths;
130130
}
131131

132-
// Resolve file paths from import/require statements
133132
export function resolveFilePath(
134133
importPath: string,
135134
currentFile: string,
@@ -169,3 +168,20 @@ export function resolveFilePath(
169168
// Skip external dependencies (e.g., node_modules)
170169
return null;
171170
}
171+
172+
export function removeIndexesFromSourceCode(
173+
sourceCode: string,
174+
indexesToRemove: { startIndex: number; endIndex: number }[],
175+
) {
176+
let newSourceCode = sourceCode;
177+
178+
// sort to start removing from the of the file end
179+
indexesToRemove.sort((a, b) => b.startIndex - a.startIndex);
180+
181+
indexesToRemove.forEach(({ startIndex, endIndex }) => {
182+
newSourceCode =
183+
newSourceCode.slice(0, startIndex) + newSourceCode.slice(endIndex);
184+
});
185+
186+
return newSourceCode;
187+
}

0 commit comments

Comments
 (0)