New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[node] bigint options for fstat and lstat #50120
[node] bigint options for fstat and lstat #50120
Conversation
@xandris Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause this is a widely-used package, a DT maintainer will need to review it before it can be merged. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 50120,
"author": "xandris",
"headCommitOid": "1e39b21b87ab4fe6bc6d43739fa5cbcde9f801ec",
"lastPushDate": "2021-02-03T06:23:08.000Z",
"lastActivityDate": "2021-02-19T00:03:57.000Z",
"maintainerBlessed": false,
"mergeOfferDate": "2021-02-18T16:28:25.000Z",
"mergeRequestDate": "2021-02-19T00:03:57.000Z",
"mergeRequestUser": "xandris",
"hasMergeConflict": false,
"isFirstContribution": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "node",
"kind": "edit",
"files": [
{
"path": "types/node/fs.d.ts",
"kind": "definition"
},
{
"path": "types/node/fs/promises.d.ts",
"kind": "definition"
},
{
"path": "types/node/test/fs.ts",
"kind": "test"
},
{
"path": "types/node/v12/fs.d.ts",
"kind": "definition"
},
{
"path": "types/node/v13/fs.d.ts",
"kind": "definition"
}
],
"owners": [
"Microsoft",
"DefinitelyTyped",
"jkomyno",
"a-tarasyuk",
"alvis",
"r3nya",
"btoueg",
"brunoscheufler",
"smac89",
"touffy",
"DeividasBakanas",
"eyqs",
"Hannes-Magnusson-CK",
"KSXGitHub",
"hoo29",
"kjin",
"ajafff",
"islishude",
"mwiktorczyk",
"mohsen1",
"n-e",
"galkin",
"parambirs",
"eps1lon",
"SimonSchick",
"ThomasdenH",
"WilcoBakker",
"wwwy3y3",
"samuela",
"kuehlein",
"j-oliveras",
"bhongy",
"chyzwar",
"trivikr",
"nguymin4",
"yoursunny",
"qwelias",
"ExE-Boss",
"Ryan-Willpower",
"peterblazejewicz",
"addaleax",
"JasonHK",
"victorperin",
"ZYSzys"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "orta",
"date": "2021-02-18T16:27:45.000Z",
"isMaintainer": true
}
],
"ciResult": "pass"
} |
🔔 @microsoft @DefinitelyTyped @jkomyno @a-tarasyuk @alvis @r3nya @btoueg @BrunoScheufler @smac89 @Touffy @DeividasBakanas @eyqs @Hannes-Magnusson-CK @KSXGitHub @hoo29 @kjin @ajafff @islishude @mwiktorczyk @mohsen1 @n-e @galkin @parambirs @eps1lon @SimonSchick @ThomasdenH @WilcoBakker @wwwy3y3 @samuela @kuehlein @j-oliveras @bhongy @chyzwar @trivikr @nguymin4 @yoursunny @qwelias @ExE-Boss @Ryan-Willpower @peterblazejewicz @addaleax @JasonHK @victorperin @ZYSzys — please review this PR in the next few days. Be sure to explicitly select |
@xandris The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings. Let’s review the numbers, shall we? node/v14.14Comparison details for node/14.14 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. node/v14.14Comparison details for node/14.14 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. node/v14.14Comparison details for node/14.14 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. |
Half baked, closing for now |
@xandris The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
I don't know what's going on in the CI build but I don't *think* I broke
it! 😥
|
Okay, last tweak incoming. The inference should support these cases:
Based on this playground I think I need 3 overloads for opts in the final position, and a fourth for the callback case where the opts in the middle of the parameter list. So, almost there, just need to make the bigint: false case with an optional param and put the false case first. I think I was imagining some case where TypeScript would automatically deduce the general case from the false and true cases, but it's probably a good thing it doesn't! |
@xandris The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
@xandris The CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
Re-pinging owners now that the CI is green and the code has stabilized @microsoft @DefinitelyTyped @jkomyno @a-tarasyuk @alvis @r3nya @btoueg @BrunoScheufler @smac89 @Touffy @DeividasBakanas @eyqs @Flarna @Hannes-Magnusson-CK @KSXGitHub @hoo29 @kjin @ajafff @islishude @mwiktorczyk @mohsen1 @n-e @galkin @parambirs @eps1lon @SimonSchick @ThomasdenH @WilcoBakker @wwwy3y3 @samuela @kuehlein @j-oliveras @bhongy @chyzwar @trivikr @nguymin4 @yoursunny @qwelias @ExE-Boss @Ryan-Willpower @peterblazejewicz @addaleax @JasonHK @victorperin @ZYSzys |
export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void; | ||
export function stat(path: PathLike, options: StatOptions & { bigint?: false } | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void; | ||
export function stat(path: PathLike, options: StatOptions & { bigint: true }, callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void): void; | ||
export function stat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void; |
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 think the options === undefined
case is not optimal here as the result should be of type Stats
.
I think omitting | undefined
here is better because this case is handled correct by the overload two lines above.
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.
Its possible you could have a weakly defined StatOptions | undefined
that you want to pass in, which should be legal. Since you can't differentiate between whether its a Stats
or BigIntStats
due to the weaker type, I would expect that to be the result. This definition looks fine to me.
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.
Also, the undefined
case should hit the first overload (with & { bigint?: false }
), which will correctly return Stats
.
export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void; | ||
export function stat(path: PathLike, options: StatOptions & { bigint?: false } | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void; | ||
export function stat(path: PathLike, options: StatOptions & { bigint: true }, callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void): void; |
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 advantage of StatOptions & { bigint: true }
compared to BigIntOptions
used till now?
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.
It actually looks easier to see why this matters with the options inline.
export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void; | ||
export function stat(path: PathLike, options: StatOptions & { bigint?: false } | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void; |
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.
There is quite some copy paste of this compound type.
What about adding something like this instead:
interface NoBigIntOptions {
bigint?: false;
}
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.
It actually looks easier to see why this matters with the options inline. Are you recommending it be StatOptions & NoBigIntOptions
? Or are you recommending a NoBigIntOptions
interface that inherits from StatOptions
? If the latter, The naming of BigIntOptions
/NoBigIntOptions
seems very ambiguous to me. Personally, I'd rather see either:
StatOptions & { bigint: true }
(as is written), orBigIntStatOptions
/NoBigIntStatOptions
(indicating the specific variations ofStatOptions
Personally I think (1) is easier to read and reason over.
|
||
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime. | ||
export namespace stat { | ||
/** | ||
* Asynchronous stat(2) - Get file status. | ||
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol. | ||
*/ | ||
function __promisify__(path: PathLike, options: BigIntOptions): Promise<BigIntStats>; |
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.
Should BigIntOptions
be deprecated since it's not referenced in the API anymore?
@Flarna do you have any other comments or feedback on this one? If not, I'll go ahead and approve. |
Re-ping @microsoft, @DefinitelyTyped, @jkomyno, @a-tarasyuk, @alvis, @r3nya, @btoueg, @BrunoScheufler, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @KSXGitHub, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @n-e, @galkin, @parambirs, @eps1lon, @SimonSchick, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @j-oliveras, @bhongy, @chyzwar, @trivikr, @nguymin4, @yoursunny, @qwelias, @ExE-Boss, @Ryan-Willpower, @peterblazejewicz, @addaleax, @JasonHK, @victorperin, @ZYSzys: This PR has been out for over a week, yet I haven't seen any reviews. Could someone please give it some attention? Thanks! |
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.
Giving Ron's approval, as this looks right to me after a read through of the discussion
@xandris Everything looks good here. Great job! I am ready to merge this PR (at 1e39b21) on your behalf. If you'd like that to happen, please post a comment saying:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ (@microsoft, @DefinitelyTyped, @jkomyno, @a-tarasyuk, @alvis, @r3nya, @btoueg, @BrunoScheufler, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @KSXGitHub, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @n-e, @galkin, @parambirs, @eps1lon, @SimonSchick, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @j-oliveras, @bhongy, @chyzwar, @trivikr, @nguymin4, @yoursunny, @qwelias, @ExE-Boss, @Ryan-Willpower, @peterblazejewicz, @addaleax, @JasonHK, @victorperin, @ZYSzys: you can do this too.) |
Ready to merge |
I just published |
I just published |
I just published |
…lstat by @xandris * [node] bigint options for fstat and lstat * [node] fixes for stat, fstat, lstat in all modes Changes the overloads to be more in line with the mkdir recursive API by consistently using StatOptions, making the bigint field optional, and using { bigint: true } and { bigint?: false } cases to discriminate between Stats and BigIntStats where possible. Also fs.promises.fstat doesn't seem to have ever existed. * [node] more stat/lstat/fstat overload tweaks, more tests * node: fix some copypasta in v12
…lstat by @xandris * [node] bigint options for fstat and lstat * [node] fixes for stat, fstat, lstat in all modes Changes the overloads to be more in line with the mkdir recursive API by consistently using StatOptions, making the bigint field optional, and using { bigint: true } and { bigint?: false } cases to discriminate between Stats and BigIntStats where possible. Also fs.promises.fstat doesn't seem to have ever existed. * [node] more stat/lstat/fstat overload tweaks, more tests * node: fix some copypasta in v12
According to the Node Filesystem API, these methods all support an
opts
parameter that allows it to returnbigint
stats:stat
lstat
fstat
They support the
bigint
option in the following modes:util.promisify
fs.promises
Each call signature can handle these arguments:
Stats
Stats
Stats
{ bigint: false }
yieldsStats
{ bigint: true }
yieldsBigIntStats
The work was already done for
stat
andstatSync
, so this PR just extends that tolstat
andfstat
async and sync variants and makes the call signatures a bit more liberal.I switched the call signatures from using the
BigIntOptions
type to using types likeStatOptions & { bigint: true }
where needed. This is the approach already taken bymkdir
to handle therecursive
option, for example. Also, it's acceptable to pass in an empty options object, so I madeStatOptions.bigint
optional.fs.promises.fstat
doesn't appear to have ever existed. (I looked at all the Node JS API documents going back to version 10.) This PR removes it. This functionality is implemented byFileHandle.stat
.These definitions go back to Node 10, but the
v10
andv11
variants didn't have the other definitions for bigint stats, so I didn't touch those.Please fill in this template.
npm test <package to test>
.Select one of these and delete the others:
If changing an existing definition: