winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.73k stars 185 forks source link

Missing `fs.appendFile` #5392

Closed eladb closed 3 months ago

eladb commented 5 months ago

Use Case

Append to files

Proposed Solution

No response

Implementation Notes

No response

Component

No response

Community Notes

staycoolcall911 commented 5 months ago

@Chriscbr - could you please decide the API here?

Chriscbr commented 5 months ago
pub static appendFile(path: string, data: string, options: AppendFileOptions?);
revitalbarletz commented 5 months ago

I will appreciate more details here please @Chriscbr & @eladb

Chriscbr commented 5 months ago

@revitalbarletz this is a new method that can be added to the fs module here: https://github.com/winglang/wing/blob/main/libs/wingsdk/src/fs/fs.ts

It should take a path to a file and insert new data at the end of the file.

For the implementation in JavaScript see also https://stackoverflow.com/questions/3459476/how-to-append-to-a-file-in-node

CJLA commented 4 months ago

@eladb I am interested to work on this issue.

staycoolcall911 commented 4 months ago

You got it @CJLA 👍 Let us know if you have any questions or need some pointers.

revitalbarletz commented 4 months ago

@CJLA let us know how it goes and if you need any assistance here!

CJLA commented 4 months ago

I am getting this error:

Parsing error: Cannot read file '__dirname/tsconfig.dev.json'

on the first line of https://github.com/winglang/wing/blob/main/libs/wingsdk/src/fs/fs.ts where it is importing the fs module.

The parser and parserOptions in eslintrc.json are currently: "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2018, "sourceType": "module", "project": "./tsconfig.dev.json" },

I tried adding: "tsconfigRootDir": "__dirname", to the parserOptions as suggested here: https://stackoverflow.com/questions/64933543/parsing-error-cannot-read-file-tsconfig-json-eslint and here: https://bobbyhadz.com/blog/typescript-parsing-error-cannot-read-file

but I get this error instead:

'__dirname/tsconfig.dev.json'

This is with the project opened in VSCode (the first time I have cloned the repo and setup the work environment). Any suggestions?

CJLA commented 3 months ago

I found existing unit tests in: https://github.com/winglang/wing/blob/main/examples/tests/sdk_tests/fs/basic.test.w

I added a method, appendFile to the fs module which calls the fs.appendFile method. I attempted to write a unit test in the test file, but when I call fs.appendFile, it doesn't recognize it (unknown symbol, "appendFile").

tsuf239 commented 3 months ago

Hi @CJLA, what command are you using to test the file? Did you try running pnpm wing test examples/tests/sdk_tests/fs/basic.test.w at the root directory?

tsuf239 commented 3 months ago

Did you solve the error above?

I am getting this error: Parsing error: Cannot read file '__dirname/tsconfig.dev.json'

CJLA commented 3 months ago

@tsuf239 I haven't run the test file because the error is occurring as I type the code. For example, if I add this code to the test: fs.appendFile(filepath, appendData); the linter highlights appendFile and says unknown symbol, "appendFile", even after I have created that method in thefs` module.

CJLA commented 3 months ago

Did you solve the error above?

I am getting this error: Parsing error: Cannot read file '__dirname/tsconfig.dev.json'

No I haven't solved this one yet. I'm hesitant to alter the .eslintrc.json file if the problem is local to my machine. Also the comments in that file say to edit the .projenrc.ts file to make modifications and it is not yet apparent what edits to make.

tsuf239 commented 3 months ago

@tsuf239 I haven't run the test file because the error is occurring as I type the code. For example, if I add this code to the test: fs.appendFile(filepath, appendData); the linter highlights appendFile and says unknown symbol, "appendFile", even after I have created that method in thefs` module.

it's ok! the linter is connected to the globally installed wing version, and your changes are on the local version,so they aren't reflected in the linter- you can ignore them for now :)

tsuf239 commented 3 months ago

Did you solve the error above?

I am getting this error: Parsing error: Cannot read file '__dirname/tsconfig.dev.json'

No I haven't solved this one yet. I'm hesitant to alter the .eslintrc.json file if the problem is local to my machine. Also the comments in that file say to edit the .projenrc.ts file to make modifications and it is not yet apparent what edits to make.

Maybe here? https://github.com/winglang/wing/blob/main/libs/wingsdk/.projenrc.ts#L205-L248 or somewhere nearby?

monadabot commented 3 months ago

Congrats! :rocket: This was released in Wing 0.59.32.