Skip to content

Commit f48f74c

Browse files
committed
Introduce cjs/esm builds for browser & nodejs
1 parent e7e4369 commit f48f74c

28 files changed

+1508
-633
lines changed

.mocharc.js

-13
This file was deleted.

demo/CloseAdditionalControlsButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { MosaicWindowContext } from '../src';
66

77
export class CloseAdditionalControlsButton extends React.PureComponent {
88
static contextType = MosaicWindowContext;
9-
context!: MosaicWindowContext;
9+
declare context: React.ContextType<typeof MosaicWindowContext>;
1010

1111
render() {
1212
return (

demo/ExampleApp.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Classes, HTMLSelect } from '@blueprintjs/core';
22
import { IconNames } from '@blueprintjs/icons';
33
import classNames from 'classnames';
4-
import dropRight from 'lodash/dropRight';
4+
import { dropRight } from 'lodash-es';
55
import React from 'react';
66

77
import {

package.json

+23-29
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33
"version": "6.1.0",
44
"description": "A React Tiling Window Manager",
55
"license": "Apache-2.0",
6-
"main": "./lib/cjs/index.js",
7-
"module": "./lib/esm/index.js",
8-
"typings": "./lib/index.d.ts",
6+
"main": "./index.mjs",
7+
"type": "module",
98
"exports": {
9+
"./react-mosaic-component.css": "./react-mosaic-component.css",
10+
"./package.json": "./package.json",
1011
".": {
11-
"import": "./lib/esm/index.js",
12-
"require": "./lib/cjs/index.js"
13-
},
14-
"./react-mosaic-component.css": {
15-
"import": "./react-mosaic-component.css",
16-
"require": "./react-mosaic-component.css"
12+
"import": "./index.mjs",
13+
"default": "./index.cjs"
1714
}
1815
},
1916
"style": "./react-mosaic-component.css",
20-
"files": ["/lib", "react-mosaic-component.css"],
2117
"repository": {
2218
"type": "git",
2319
"url": "https://github.com/nomcopter/react-mosaic.git"
@@ -35,19 +31,19 @@
3531
"*.css"
3632
],
3733
"scripts": {
38-
"build": "npm-run-all clean -lp build:**",
34+
"build": "npm-run-all clean -lp build:** && run-s copy",
3935
"build:less": "lessc --autoprefix=defaults styles/index.less react-mosaic-component.css",
40-
"build:esm": "tsc --project tsconfig-build.json --declaration false --rootDir src --module esnext --outDir ./lib/esm",
41-
"build:cjs": "tsc --project tsconfig-build.json --declaration false --rootDir src --module commonjs --outDir ./lib/cjs",
42-
"build:declaration": "tsc --project tsconfig-build.json --rootDir src --outDir ./lib --emitDeclarationOnly",
36+
"build:js": "tsup",
37+
"build:check": "tsc --noEmit",
38+
"copy": "shx cp package.json ./lib/package.json && shx cp README.md ./lib/README.md && shx cp LICENSE ./lib/LICENSE && shx cp react-mosaic-component.css ./lib/react-mosaic-component.css",
39+
"check": "attw --pack lib --entrypoints .",
4340
"bundle": "shx rm -rf docs/ && webpack --config webpack/bundle.ts",
4441
"clean": "shx rm -rf lib/",
4542
"start": "webpack-dev-server --config webpack/hot.ts",
46-
"prettier:run": "prettier 'styles/*.less' '*.md' '{,.}*.yml' '.circleci/*.yml'",
43+
"prettier:run": "prettier \"styles/*.less\" \"*.md\" \"{,.}*.yml\" \".circleci/*.yml\"",
4744
"test": "npm-run-all build -lp test:**",
48-
"test:lint": "tslint -c tslint.yml -p tsconfig.json -e test",
49-
"test:unit": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} mocha",
50-
"test:format": "yarn run prettier:run --list-different",
45+
"test-disabled:lint": "tslint -c tslint.yml -p tsconfig.json -e test",
46+
"test:unit": "vitest run",
5147
"fix": "npm-run-all -lp fix:**",
5248
"fix:format": "yarn run prettier:run --write",
5349
"fix:lint": "yarn run test:lint --fix",
@@ -57,7 +53,7 @@
5753
"classnames": "^2.3.2",
5854
"dnd-core": "16.0.1",
5955
"immutability-helper": "^3.1.1",
60-
"lodash": "^4.17.21",
56+
"lodash-es": "^4.17.21",
6157
"prop-types": "^15.8.1",
6258
"rdndmb-html5-to-touch": "^8.0.0",
6359
"react-dnd": "^16.0.1",
@@ -67,47 +63,45 @@
6763
"uuid": "^9.0.0"
6864
},
6965
"devDependencies": {
66+
"@arethetypeswrong/cli": "0.16.1",
7067
"@blueprintjs/core": "^4.15.1",
7168
"@blueprintjs/icons": "^4.13.1",
7269
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
73-
"@types/chai": "^4.3.0",
7470
"@types/classnames": "^2.3.1",
7571
"@types/dom4": "^2.0.2",
76-
"@types/lodash": "^4.14.191",
77-
"@types/mocha": "^7.0.2",
72+
"@types/lodash-es": "4.17.12",
7873
"@types/prop-types": "^15.7.5",
7974
"@types/react": "^18.0.28",
8075
"@types/react-dom": "^18.0.10",
8176
"@types/uuid": "^9.0.0",
8277
"@types/webpack": "^5.28.0",
83-
"chai": "^4.3.6",
8478
"cross-env": "7.0.3",
8579
"css-loader": "^6.7.3",
80+
"esbuild-plugin-file-path-extensions": "^2.1.2",
8681
"html-loader": "^4.2.0",
8782
"html-webpack-plugin": "^5.5.0",
8883
"jsdom": "^15.2.1",
8984
"jsdom-global": "^3.0.2",
9085
"less": "^3.13.1",
9186
"less-loader": "^11.1.0",
9287
"less-plugin-autoprefix": "^2.0.0",
93-
"mocha": "^6.2.3",
94-
"mocha-junit-reporter": "^1.23.3",
9588
"mock-require": "^3.0.3",
9689
"npm-run-all": "^4.1.5",
97-
"prettier": "^2.8.4",
90+
"prettier": "2.8.4",
9891
"react": "^18.2.0",
9992
"react-dom": "^18.2.0",
10093
"react-refresh": "^0.14.0",
101-
"source-map-loader": "^4.0.1",
10294
"shx": "0.3.4",
95+
"source-map-loader": "^4.0.1",
10396
"style-loader": "^3.3.1",
10497
"ts-loader": "^9.4.2",
105-
"ts-node": "^10.9.1",
10698
"tslint": "^6.1.3",
10799
"tslint-config-prettier": "^1.18.0",
108100
"tslint-plugin-prettier": "^2.3.0",
109101
"tslint-react": "^5.0.0",
110-
"typescript": "^4.9.5",
102+
"tsup": "^8.2.4",
103+
"typescript": "5.5.4",
104+
"vitest": "^2.0.5",
111105
"webpack": "^5.75.0",
112106
"webpack-cli": "^5.0.1",
113107
"webpack-dev-server": "^4.11.1",

src/Mosaic.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import classNames from 'classnames';
22
import { DragDropManager } from 'dnd-core';
3-
import countBy from 'lodash/countBy';
4-
import keys from 'lodash/keys';
5-
import pickBy from 'lodash/pickBy';
3+
import { countBy, keys, pickBy } from 'lodash-es';
64
import { HTML5toTouch } from 'rdndmb-html5-to-touch';
75
import React from 'react';
86
import { DndProvider } from 'react-dnd';
@@ -82,7 +80,7 @@ export interface MosaicUncontrolledProps<T extends MosaicKey> extends MosaicBase
8280

8381
export type MosaicProps<T extends MosaicKey> = MosaicControlledProps<T> | MosaicUncontrolledProps<T>;
8482

85-
function isUncontrolled<T extends MosaicKey>(props: MosaicProps<T>): props is MosaicUncontrolledProps<T> {
83+
function isUncontrolled<T extends MosaicKey>(props: MosaicProps<T>): props is Readonly<MosaicUncontrolledProps<T>> {
8684
return (props as MosaicUncontrolledProps<T>).initialValue != null;
8785
}
8886

src/MosaicRoot.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import flatten from 'lodash/flatten';
1+
import { flatten } from 'lodash-es';
22
import React from 'react';
33
import { MosaicContext } from './contextTypes';
44
import { Split } from './Split';
@@ -14,7 +14,7 @@ export interface MosaicRootProps<T extends MosaicKey> {
1414

1515
export class MosaicRoot<T extends MosaicKey> extends React.PureComponent<MosaicRootProps<T>> {
1616
static contextType = MosaicContext;
17-
context!: MosaicContext<T>;
17+
declare context: React.ContextType<typeof MosaicContext>;
1818

1919
render() {
2020
const { root } = this.props;

src/MosaicWindow.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import classNames from 'classnames';
2-
import defer from 'lodash/defer';
3-
import dropRight from 'lodash/dropRight';
4-
import isEmpty from 'lodash/isEmpty';
5-
import isEqual from 'lodash/isEqual';
6-
import values from 'lodash/values';
2+
import { defer, dropRight, isEmpty, isEqual, values } from 'lodash-es';
73
import React, { useContext } from 'react';
84
import {
95
ConnectDragPreview,
@@ -82,7 +78,7 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
8278
renderToolbar: null,
8379
};
8480
static contextType = MosaicContext;
85-
context!: MosaicContext<T>;
81+
declare context: React.ContextType<typeof MosaicContext>;
8682

8783
state: InternalMosaicWindowState = {
8884
additionalControlsOpen: false,
@@ -245,6 +241,7 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
245241
};
246242

247243
private readonly childContext: MosaicWindowContext = {
244+
// @ts-ignore
248245
blueprintNamespace: this.context.blueprintNamespace,
249246
mosaicWindowActions: {
250247
split: this.split,

src/MosaicZeroState.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import noop from 'lodash/noop';
2+
import { noop } from 'lodash-es';
33
import React from 'react';
44

55
import { MosaicContext } from './contextTypes';
@@ -12,7 +12,7 @@ export interface MosaicZeroStateProps<T extends MosaicKey> {
1212

1313
export class MosaicZeroState<T extends MosaicKey> extends React.PureComponent<MosaicZeroStateProps<T>> {
1414
static contextType = MosaicContext;
15-
context!: MosaicContext<T>;
15+
declare context: React.ContextType<typeof MosaicContext>;
1616

1717
render() {
1818
return (

src/RootDropTargets.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import values from 'lodash/values';
2+
import { values } from 'lodash-es';
33
import React from 'react';
44
import { useDrop } from 'react-dnd';
55

src/Split.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import classNames from 'classnames';
2-
import clamp from 'lodash/clamp';
3-
import throttle from 'lodash/throttle';
2+
import { clamp } from 'lodash-es';
3+
import { throttle } from 'lodash-es';
44
import React from 'react';
55

66
import { EnabledResizeOptions, MosaicDirection } from './types';

src/buttons/ExpandButton.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import classNames from 'classnames';
22
import React from 'react';
33

4-
import { MosaicContext, MosaicRootActions, MosaicWindowContext } from '../contextTypes';
4+
import { MosaicContext, type MosaicRootActions, MosaicWindowContext } from '../contextTypes';
55
import { OptionalBlueprint } from '../util/OptionalBlueprint';
6-
import { DefaultToolbarButton, MosaicButtonProps } from './MosaicButton';
6+
import { DefaultToolbarButton, type MosaicButtonProps } from './MosaicButton';
77

88
export class ExpandButton extends React.PureComponent<MosaicButtonProps> {
99
static contextType = MosaicWindowContext;
10-
context!: MosaicWindowContext;
10+
declare context: React.ContextType<typeof MosaicWindowContext>;
1111

1212
render() {
1313
return (

src/buttons/RemoveButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DefaultToolbarButton, MosaicButtonProps } from './MosaicButton';
77

88
export class RemoveButton extends React.PureComponent<MosaicButtonProps> {
99
static contextType = MosaicWindowContext;
10-
context!: MosaicWindowContext;
10+
declare context: React.ContextType<typeof MosaicWindowContext>;
1111

1212
render() {
1313
return (

src/buttons/ReplaceButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import noop from 'lodash/noop';
2+
import { noop } from 'lodash-es';
33
import React from 'react';
44

55
import { MosaicWindowContext } from '../contextTypes';
@@ -8,7 +8,7 @@ import { DefaultToolbarButton, MosaicButtonProps } from './MosaicButton';
88

99
export class ReplaceButton extends React.PureComponent<MosaicButtonProps> {
1010
static contextType = MosaicWindowContext;
11-
context!: MosaicWindowContext;
11+
declare context: React.ContextType<typeof MosaicWindowContext>;
1212

1313
render() {
1414
return (

src/buttons/SplitButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from 'classnames';
2-
import noop from 'lodash/noop';
2+
import { noop } from 'lodash-es';
33
import React from 'react';
44

55
import { MosaicWindowContext } from '../contextTypes';
@@ -8,7 +8,7 @@ import { DefaultToolbarButton, MosaicButtonProps } from './MosaicButton';
88

99
export class SplitButton extends React.PureComponent<MosaicButtonProps> {
1010
static contextType = MosaicWindowContext;
11-
context!: MosaicWindowContext;
11+
declare context: React.ContextType<typeof MosaicWindowContext>;
1212

1313
render() {
1414
return (

src/index.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
1616
*/
1717
export {
1818
Mosaic,
19-
MosaicProps,
20-
MosaicUncontrolledProps,
21-
MosaicControlledProps,
19+
type MosaicProps,
20+
type MosaicUncontrolledProps,
21+
type MosaicControlledProps,
2222
MosaicWithoutDragDropContext,
2323
} from './Mosaic';
2424
export {
25-
MosaicNode,
25+
type MosaicNode,
2626
MosaicDragType,
27-
MosaicDirection,
28-
MosaicBranch,
29-
CreateNode,
30-
MosaicParent,
31-
MosaicPath,
32-
MosaicUpdate,
33-
MosaicUpdateSpec,
34-
TileRenderer,
27+
type MosaicDirection,
28+
type MosaicBranch,
29+
type CreateNode,
30+
type MosaicParent,
31+
type MosaicPath,
32+
type MosaicUpdate,
33+
type MosaicUpdateSpec,
34+
type TileRenderer,
3535
} from './types';
36-
export { MosaicContext, MosaicRootActions, MosaicWindowActions, MosaicWindowContext } from './contextTypes';
36+
export { MosaicContext, type MosaicRootActions, type MosaicWindowActions, MosaicWindowContext } from './contextTypes';
3737
export {
3838
buildSpecFromUpdate,
3939
createDragToUpdates,
@@ -53,9 +53,9 @@ export {
5353
getPathToCorner,
5454
isParent,
5555
} from './util/mosaicUtilities';
56-
export { MosaicWindow, MosaicWindowProps } from './MosaicWindow';
57-
export { createDefaultToolbarButton, DefaultToolbarButton, MosaicButtonProps } from './buttons/MosaicButton';
58-
export { MosaicZeroState, MosaicZeroStateProps } from './MosaicZeroState';
56+
export { MosaicWindow, type MosaicWindowProps } from './MosaicWindow';
57+
export { createDefaultToolbarButton, DefaultToolbarButton, type MosaicButtonProps } from './buttons/MosaicButton';
58+
export { MosaicZeroState, type MosaicZeroStateProps } from './MosaicZeroState';
5959
export { Separator } from './buttons/Separator';
6060
export { ExpandButton } from './buttons/ExpandButton';
6161
export { ReplaceButton } from './buttons/ReplaceButton';

src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Spec } from 'immutability-helper';
1+
import type { Spec } from 'immutability-helper';
22

33
/**
44
* Valid node types

src/util/OptionalBlueprint.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Classes } from '@blueprintjs/core';
22
import type { IconNames } from '@blueprintjs/icons';
33
import classNames from 'classnames';
4-
import kebabCase from 'lodash/kebabCase';
4+
import { kebabCase } from 'lodash-es';
55
import * as React from 'react';
66
import { MosaicContext } from '../contextTypes';
77

src/util/mosaicUpdates.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import update from 'immutability-helper';
2-
import drop from 'lodash/drop';
3-
import dropRight from 'lodash/dropRight';
4-
import isEqual from 'lodash/isEqual';
5-
import last from 'lodash/last';
6-
import set from 'lodash/set';
7-
import take from 'lodash/take';
2+
import { drop, dropRight, isEqual, last, set, take } from 'lodash-es';
83
import { MosaicDropTargetPosition } from '../internalTypes';
9-
import {
4+
import type {
105
MosaicBranch,
116
MosaicDirection,
127
MosaicKey,
@@ -18,9 +13,6 @@ import {
1813
} from '../types';
1914
import { getAndAssertNodeAtPathExists, getOtherBranch } from './mosaicUtilities';
2015

21-
// https://github.com/Microsoft/TypeScript/issues/9944
22-
export { MosaicParent };
23-
2416
/**
2517
* Used to prepare `update` for `immutability-helper`
2618
* @param mosaicUpdate

0 commit comments

Comments
 (0)