-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(instrumentation-fs): allow realpath.native and realpathSync.native (
#1332) * test(instrumentation-fs): add failing test for bug * fix(instrumentation-fs): allow .native fs funcs * refactor(instrumentation-fs): indexFs change indexFs return types and object properties of return * refactor(instr-fs): use string for two level fns previously ['realpath', 'native'] now 'realpath.native' also moved exported yet private functions to utils file fixed tests to follow these changes refactored patching code to function with added comment * refactor(instrumentation-fs): remove memberToDisplayName * refactor(instrumentation-fs): simplify splitTwoLevels signature * fix(instrumentation-fs): lint * fix(instrumentation-fs): lint (typeof fs) * fix(instrumentation-fs): test types * chore: fix compile and lint * fix(fs): exclude undefined in generic type * test(fs): skip fs functions in node14 which were added later --------- Co-authored-by: Amir Blum <[email protected]> Co-authored-by: Amir Blum <[email protected]>
- Loading branch information
1 parent
3484b75
commit ee0a59a
Showing
6 changed files
with
230 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import type { FunctionPropertyNames, FMember } from './types'; | ||
import type * as fs from 'fs'; | ||
type FS = typeof fs; | ||
|
||
export function splitTwoLevels<FSObject>( | ||
functionName: FMember | ||
): | ||
| [FunctionPropertyNames<FSObject> & string] | ||
| [FunctionPropertyNames<FSObject> & string, string] { | ||
const memberParts = functionName.split('.'); | ||
if (memberParts.length > 1) { | ||
if (memberParts.length !== 2) | ||
throw Error(`Invalid member function name ${functionName}`); | ||
return memberParts as [FunctionPropertyNames<FSObject> & string, string]; | ||
} else { | ||
return [functionName as FunctionPropertyNames<FSObject> & string]; | ||
} | ||
} | ||
|
||
export function indexFs<FSObject extends FS | FS['promises']>( | ||
fs: FSObject, | ||
member: FMember | ||
): { objectToPatch: any; functionNameToPatch: string } { | ||
if (!member) throw new Error(JSON.stringify({ member })); | ||
const splitResult = splitTwoLevels<FSObject>(member); | ||
const [functionName1, functionName2] = splitResult; | ||
if (functionName2) { | ||
return { | ||
objectToPatch: fs[functionName1], | ||
functionNameToPatch: functionName2, | ||
}; | ||
} else { | ||
return { | ||
objectToPatch: fs, | ||
functionNameToPatch: functionName1, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.