Skip to content

Commit 3f48b65

Browse files
committed
fix: cover module interop and reuse the preview build
1 parent a9dfbb5 commit 3f48b65

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎.github/workflows/surge-preview.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
with:
4747
surge_token: ${{ env.SURGE_TOKEN }}
4848
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
build: test -d docs-dist
4950
dist: docs-dist
5051
failOnError: false
5152
setCommitStatus: false

‎scripts/update-browser-field.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ const addEntry = (from, to) => {
1313
browserEntries.push([from, to]);
1414
};
1515

16-
// Preserve previous behavior of preferring the ES build for the main entry.
16+
// Redirect the resolved main file for legacy bundlers that do not use exports.
1717
addEntry('./lib/index.js', './es/index.mjs');
1818

19+
/** Keep legacy browser request names while pointing them at the emitted ESM files. */
1920
const addDirMappings = (dirPath, browserPrefix, targetPrefix) => {
2021
if (!fs.existsSync(dirPath)) {
2122
return;

‎src/PickerPanel/index.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface BasePickerPanelProps<DateType extends object = any>
6464
| 'superPrevIcon'
6565
| 'superNextIcon'
6666
>,
67+
// Panel values may be null or multiple; the time default only accepts one date.
6768
Omit<SharedTimeProps<DateType>, 'defaultValue'>,
6869
Pick<React.HTMLAttributes<HTMLDivElement>, 'tabIndex'> {
6970
// Style

‎tests/util.spec.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@
33
import dayjs from 'dayjs';
44
import dayGenerate from '../src/generate/dayjs';
55
import { isInRange } from '../src/utils/dateUtil';
6+
import getDefaultExport from '../src/utils/getDefaultExport';
67

78
global.error = console.error;
89

910
describe('Picker.Util', () => {
11+
describe('getDefaultExport', () => {
12+
it('unwraps a transpiled CommonJS namespace loaded by Node ESM', () => {
13+
const component = () => null;
14+
const namespace = { default: component };
15+
Object.defineProperty(namespace, '__esModule', { value: true });
16+
expect(getDefaultExport(namespace)).toBe(component);
17+
});
18+
19+
it.each([
20+
null,
21+
undefined,
22+
() => null,
23+
{ $$typeof: Symbol.for('react.forward_ref'), render: () => null },
24+
{ default: 'ordinary property' },
25+
{ __esModule: false, default: 'ordinary property' },
26+
{ __esModule: true },
27+
])('preserves an already usable export: %p', (value) => {
28+
expect(getDefaultExport(value)).toBe(value);
29+
});
30+
});
31+
1032
describe('isInRange', () => {
1133
it('not break with null', () => {
1234
expect(isInRange(dayGenerate, null, null, dayjs())).toBeFalsy();

0 commit comments

Comments
 (0)