Skip to content

Commit 78ff98d

Browse files
committed
fix: fix release build
1 parent f4d75bf commit 78ff98d

18 files changed

+400
-2989
lines changed

.eslintrc.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@
4343
},
4444
"import/resolver": {
4545
"alias": {
46-
"map": [["~", "./"]],
46+
"map": [
47+
["context", "./src/context"],
48+
["hooks", "./src/hooks"],
49+
["hocs", "./src/hocs"],
50+
["utils", "./src/utils"]
51+
],
4752
"extensions": [".ts", ".js", ".tsx"]
4853
}
4954
}

jest.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module.exports = {
66
collectCoverage: true,
77
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
88
moduleNameMapper: {
9-
'^~(.*)$': '<rootDir>$1',
9+
'^context(.*)$': '<rootDir>/src/context$1',
10+
'^hooks(.*)$': '<rootDir>/src/hooks$1',
11+
'^hocs(.*)$': '<rootDir>/src/hocs$1',
12+
'^utils(.*)$': '<rootDir>/src/utils$1',
1013
},
1114
};

package.json

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
"version": "2.0.1",
44
"description": "Dynamic frontend settings for React applications",
55
"source": "src/index.ts",
6-
"main": "dist/main.js",
6+
"main": "dist",
77
"types": "dist/index.d.ts",
8-
"module": "dist/module.js",
98
"author": "Loadsmart <[email protected]>",
109
"license": "MIT",
1110
"files": [
@@ -18,8 +17,10 @@
1817
"devDependencies": {
1918
"@commitlint/cli": "^13.2.1",
2019
"@commitlint/config-conventional": "^13.2.0",
21-
"@parcel/packager-ts": "^2.0.0",
22-
"@parcel/transformer-typescript-types": "^2.0.0",
20+
"@rollup/plugin-babel": "^5.3.0",
21+
"@rollup/plugin-commonjs": "^21.0.0",
22+
"@rollup/plugin-node-resolve": "^13.0.5",
23+
"@rollup/plugin-typescript": "^8.3.0",
2324
"@semantic-release/commit-analyzer": "^9.0.1",
2425
"@semantic-release/git": "^10.0.0",
2526
"@semantic-release/github": "^8.0.1",
@@ -33,6 +34,8 @@
3334
"@types/react": "^17.0.30",
3435
"@typescript-eslint/eslint-plugin": "^5.0.0",
3536
"@typescript-eslint/parser": "^5.0.0",
37+
"@zerollup/ts-transform-paths": "^1.7.18",
38+
"core-js": "^3.18.3",
3639
"cz-conventional-changelog": "3.3.0",
3740
"eslint": "^8.0.1",
3841
"eslint-import-resolver-alias": "^1.1.2",
@@ -41,21 +44,22 @@
4144
"eslint-plugin-react": "^7.26.1",
4245
"husky": "^7.0.0",
4346
"jest": "^27.2.5",
44-
"parcel": "^2.0.0",
4547
"prettier": "^2.4.1",
4648
"react": "^17.0.2",
4749
"react-dom": "^17.0.2",
4850
"react-test-renderer": "^16.9.0",
51+
"rollup": "^2.58.0",
52+
"rollup-plugin-delete": "^2.0.0",
4953
"semantic-release": "^18.0.0",
5054
"ts-jest": "^27.0.6",
55+
"ttypescript": "^1.5.12",
5156
"typescript": "^4.4.4"
5257
},
5358
"peerDependencies": {
5459
"react": "16"
5560
},
5661
"scripts": {
57-
"watch": "parcel watch",
58-
"build": "parcel build",
62+
"build": "rollup --config",
5963
"lint": "eslint --ext 'js,jsx,ts,tsx' .",
6064
"lint:fix": "eslint --ext 'js,jsx,ts,tsx' . --fix",
6165
"commit": "cz",

rollup.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// import babel from '@rollup/plugin-babel';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import del from 'rollup-plugin-delete';
4+
import resolve from '@rollup/plugin-node-resolve';
5+
import typescript from '@rollup/plugin-typescript';
6+
import ttypescript from 'ttypescript';
7+
8+
import packageJson from './package.json';
9+
10+
const { main, source } = packageJson;
11+
const peerDependencies = Object.keys(packageJson.peerDependencies);
12+
13+
const config = {
14+
input: source,
15+
output: {
16+
dir: main,
17+
format: 'cjs',
18+
sourcemap: true,
19+
},
20+
plugins: [
21+
del({ targets: `${main}/*` }),
22+
typescript({
23+
typescript: ttypescript,
24+
exclude: ['./tests*'],
25+
}),
26+
resolve({
27+
// Source: https://rollupjs.org/guide/en/#peer-dependencies
28+
customResolveOptions: {
29+
moduleDirectories: 'node_modules',
30+
},
31+
}),
32+
commonjs(),
33+
],
34+
external: [...peerDependencies],
35+
};
36+
37+
export default config;

src/context/provider.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { ReactElement, ReactNode } from 'react';
22
import React, { useEffect, useState } from 'react';
33

4-
import type { SettingsProviderValue } from '~/src/context/context';
5-
import { SettingsContext } from '~/src/context/context';
4+
import type { SettingsProviderValue } from 'context/context';
5+
import { SettingsContext } from 'context/context';
66

77
export type SettingsValue = Pick<SettingsProviderValue, 'settings' | 'flags'>;
88

src/hocs/withFeatureFlag.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ComponentType } from 'react';
22
import React from 'react';
33

4-
import { useSettings } from '~/src/hooks/useSettings';
4+
import { useSettings } from 'hooks/useSettings';
55

66
interface Options<T> {
77
flags: string[];

src/hocs/withSettings.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ComponentType } from 'react';
22
import React from 'react';
33

4-
import { useSettings } from '~/src/hooks/useSettings';
4+
import { useSettings } from 'hooks/useSettings';
55

66
interface Options {
77
settingsMap: Record<string, string>;

src/hooks/useSettings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useContext } from 'react';
22

3-
import { SettingsContext } from '~/src/context/context';
4-
import { parseSettings } from '~/src/utils/settings';
3+
import { SettingsContext } from 'context/context';
4+
import { parseSettings } from 'utils/settings';
55

66
export function useSettings(keys: string[]): {
77
values: Array<boolean | null | unknown>;

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { SettingsProvider } from '~/src/context/provider';
2-
export { useSettings } from '~/src/hooks/useSettings';
3-
export { withFeatureFlag } from '~/src/hocs/withFeatureFlag';
4-
export { withSettings } from '~/src/hocs/withSettings';
1+
export { SettingsProvider } from 'context/provider';
2+
export { useSettings } from 'hooks/useSettings';
3+
export { withFeatureFlag } from 'hocs/withFeatureFlag';
4+
export { withSettings } from 'hocs/withSettings';

src/utils/settings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SettingsValue } from '~/src/context/provider';
1+
import type { SettingsValue } from 'context/provider';
22

33
export function parseSettings(keys: string[], settings: SettingsValue): Array<boolean | null | unknown> {
44
return keys.map((key) =>

tests/context/provider.spec.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { act, render, waitFor } from '@testing-library/react';
33

4-
import { SettingsProvider } from '~/src/context/provider';
5-
import type { SettingsProviderValue } from '~/src/context/context';
6-
import { SettingsContext } from '~/src/context/context';
4+
import { SettingsProvider } from 'context/provider';
5+
import type { SettingsProviderValue } from 'context/context';
6+
import { SettingsContext } from 'context/context';
77

88
describe('SettingsProvider', () => {
99
const settings = {

tests/hocs/withFeatureFlag.spec.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { ReactNode } from 'react';
22
import React from 'react';
33
import { render, screen } from '@testing-library/react';
44

5-
import { withFeatureFlag } from '~/src/hocs/withFeatureFlag';
6-
import type { SettingsProviderValue } from '~/src/context/context';
7-
import { SettingsContext } from '~/src/context/context';
5+
import { withFeatureFlag } from 'hocs/withFeatureFlag';
6+
import type { SettingsProviderValue } from 'context/context';
7+
import { SettingsContext } from 'context/context';
88

99
describe('withFeatureFlag', () => {
1010
const Component = () => <div data-testid="component" />;

tests/hocs/withSettings.spec.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { ReactNode } from 'react';
22
import React from 'react';
33
import { render, screen } from '@testing-library/react';
44

5-
import { withSettings } from '~/src/hocs/withSettings';
6-
import type { SettingsProviderValue } from '~/src/context/context';
7-
import { SettingsContext } from '~/src/context/context';
5+
import { withSettings } from 'hocs/withSettings';
6+
import type { SettingsProviderValue } from 'context/context';
7+
import { SettingsContext } from 'context/context';
88

99
describe('withSettings', () => {
1010
const Component = ({ dataTestId, children }: { dataTestId?: string; children: ReactNode }) => (

tests/hooks/useSettings.spec.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { ReactNode } from 'react';
22
import React from 'react';
33
import { renderHook } from '@testing-library/react-hooks';
44

5-
import { useSettings } from '~/src/hooks/useSettings';
6-
import type { SettingsProviderValue } from '~/src/context/context';
7-
import { SettingsContext } from '~/src/context/context';
5+
import type { SettingsProviderValue } from 'context/context';
6+
import { SettingsContext } from 'context/context';
7+
import { useSettings } from 'hooks/useSettings';
88

99
function wrapper(value: Partial<SettingsProviderValue>) {
1010
return function Wrapper({ children }: { children: ReactNode }) {

tests/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["../src/**/*", "./**/*"]
4+
}

tests/utils/settings.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { SettingsValue } from '~/src/context/provider';
2-
import { parseSettings } from '~/src/utils/settings';
1+
import type { SettingsValue } from 'context/provider';
2+
import { parseSettings } from 'utils/settings';
33

44
describe('parseSettings', () => {
55
const settings: SettingsValue = {

tsconfig.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["src/**/*", "tests/**/*"],
2+
"include": ["src/**/*"],
33
"compilerOptions": {
44
"target": "es2021",
55
"strict": true,
@@ -14,8 +14,12 @@
1414
"moduleResolution": "node",
1515
"downlevelIteration": true,
1616
"baseUrl": ".",
17+
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
1718
"paths": {
18-
"~*": ["./*"]
19+
"context/*": ["src/context/*"],
20+
"hooks/*": ["src/hooks/*"],
21+
"hocs/*": ["src/hocs/*"],
22+
"utils/*": ["src/utils/*"]
1923
}
2024
},
2125
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)