Skip to content

Commit eec5950

Browse files
committed
fix: take care of hoisting
1 parent 55caef5 commit eec5950

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

package/native-package/src/optionalDependencies/pickDocument.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,41 @@ type ResponseValue = {
1010
uri: string;
1111
};
1212

13-
let DocumentPicker:
13+
type DocumentPickerType =
1414
| {
1515
pick: (opts?: { allowMultiSelection: boolean; type: string[] }) => Promise<ResponseValue[]>;
1616
types: { allFiles: string };
1717
}
1818
| undefined;
1919

20+
let DocumentPicker: DocumentPickerType;
21+
22+
let OldDocumentPicker: DocumentPickerType;
23+
let NewDocumentPicker: DocumentPickerType;
24+
25+
try {
26+
NewDocumentPicker = require('@react-native-documents/picker');
27+
} catch (err) {
28+
// we log below
29+
}
30+
2031
try {
21-
DocumentPicker = require('@react-native-documents/picker');
32+
OldDocumentPicker = require('react-native-document-picker').default;
2233
} catch (err) {
23-
// we do nothing as the alternative might be used
24-
// console.warn('@react-native-documents/picker is not installed');
34+
// we log below
2535
}
2636

27-
if (!DocumentPicker) {
28-
try {
29-
DocumentPicker = require('react-native-document-picker').default;
30-
console.log(
31-
"You're using the react-native-document-picker library, which is no longer supported and has moved to @react-native-documents/picker. Things might not work as intended. Please migrate to the new library as soon as possible !",
32-
);
33-
} catch (err) {
34-
console.log(
35-
'Neither react-native-document-picker nor @react-native-documents/picker are installed.',
36-
);
37-
}
37+
if (NewDocumentPicker) {
38+
DocumentPicker = NewDocumentPicker;
39+
} else if (OldDocumentPicker) {
40+
DocumentPicker = OldDocumentPicker;
41+
console.log(
42+
"You're using the react-native-document-picker library, which is no longer supported and has moved to @react-native-documents/picker. Things might not work as intended. Please migrate to the new library as soon as possible !",
43+
);
44+
} else {
45+
console.log(
46+
'Neither react-native-document-picker nor @react-native-documents/picker are installed.',
47+
);
3848
}
3949

4050
export const pickDocument = DocumentPicker

0 commit comments

Comments
 (0)