-
Notifications
You must be signed in to change notification settings - Fork 26
feat(npm-aqua-compiler): create package #401
Conversation
| return await gatherImportsFromArborist(arb); | ||
| } | ||
|
|
||
| export async function gatherImportsFromArborist( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the reason to have this as a separate function? do we plan on using it separately from the gatherImportsFromNpm function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Probably we need a former function only
| const arb = new Arborist({ path }); | ||
|
|
||
| return await gatherImportsFromArborist(arb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const arb = new Arborist({ path }); | |
| return await gatherImportsFromArborist(arb); | |
| return gatherImportsFromArborist(new Arborist({ path })); |
|
|
||
| for (const edge of node.edgesOut.values()) { | ||
| // Skip dependencies that are not installed. | ||
| if (edge.to === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for me it vscode says that edge.to is never null. Is it on practice sometimes null? If so - for me eslint has a warining here because of that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in slack, types for arborist are improper. While I was testing this code, I got null in edge.to. As far as I understand, this will be null for not installed deps (for some reason). @akim-bow please try to test this function on some big project with a lot of deps.
| item.tag === "labeledProduct" ? Object.values(item.fields) : item.items; | ||
|
|
||
| if (args.length === 1) { | ||
| if ("0" in args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are actually different. Previously you checked the length is exactly equal to one. Now you are checking that first element exists. Does it make sense to still check the the length is exactly === 1. Can it ever be !== 1? If this is something aqua compiler enforces - I would probably check the case when it's not 1 and maybe throw error - this we will get a chance to discover some unexpected bug
the same question to think about is for the same check you are doing bellow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wil recheck these in other files
| if (!("demoCalc" in functions)) { | ||
| throw new Error("Aqua code must contain demoCalc function"); | ||
| } | ||
|
|
||
| const { script } = functions["demoCalc"]; | ||
|
|
||
| if (!("Calc" in typedServices)) { | ||
| throw new Error("Aqua code must contain Calc service"); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both can be asserts, because it's inside test. You can leave it as it currently is as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer to do assert in test
|
|
||
| setTimeout(() => { | ||
| rejectCallback(err); | ||
| rejectCallback(err ?? "Error hasn't been provided"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am currious when that can happen. I think would be a bit weird to see in the console "Error hasn't been provided"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can happen if someone wrote incorrect air code and hasn't passed any args there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to a more lucky description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still I think it's hard to understand for the user what is he supposed to do. If it's most likely a problem with the complier - then the error should say that as well
packages/core/js-client/src/api.ts
Outdated
|
|
||
| if (serviceImplValue === undefined) { | ||
| throw new Error( | ||
| `Expected to have ${schemaKey} in service implementation according to schema`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this happen if user didn't implement the service he was supposed to implement? Or when does it happen?
I would prefer a more actionable error. Users wouldn't know what's the schema what's the key and where, especially if they don't use typescript
| def.arrow.codomain.items.length === 1 && | ||
| "0" in def.arrow.codomain.items | ||
| ? def.arrow.codomain.items[0] | ||
| : def.arrow.codomain; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you want to extract this pattern to some function? It is repeated at least 3 times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably possible with this
function isArrayWithOneElement<T>(arr: Array<T>): arr is [T] {
return arr.length === 1 && arr[0] !== undefined;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will keep it in mind. This PR already bloated too much, i will do this in the next PR.
| @@ -0,0 +1 @@ | |||
| package-lock.json No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not storing package-lock.json in git?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure should i keep it or no.
When this file is present and some dependencies changes e.g. someone adds more packages to tests, npm just breaks without meaningful error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this file in git there is a less chance to fight with strange bugs when developing tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the other side this file will keep the tests more persistent, would be easier to track changes. Probably i will keep it, thanks.
| export async function gatherImportsFromNpm( | ||
| path: string, | ||
| ): Promise<Record<string, string[]>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not return imports according to the latest spec.
https://www.notion.so/fluencenetwork/Aqua-Imports-Spec-082d48d2d7184b05a3f47f35b781c843
Type of new imports is Record<string, Record<string, string[] | string>>. Read more in the doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I totally forgot we decided on a different structure. Thanks for the catch.
|
A vast part of changes are not related to DXJ-566 in any way as far as I understand. Why do like so... |
Yeah would probably better to do refactoring in a separate PR, would be easier to review. But I support this refactoring in generall, even though I agree this is probably not the best place to do that as part of this PR |
shamsartem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice. thanks
No description provided.