diff --git a/.gitignore b/.gitignore index 2df1644..8d46df6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,7 @@ dist !.yarn/releases !.yarn/sdks !.yarn/versions -.yarnrc.yml.temp \ No newline at end of file +.yarnrc.yml.temp + +# rollup +.rollup.cache \ No newline at end of file diff --git a/package.json b/package.json index d7da622..63b3edb 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,24 @@ { "name": "@ummgoban/shared", - "version": "0.0.1-alpha.9", + "version": "0.0.1-alpha.19", "description": "ummgoban 공통 패키지", "main": "dist/index.js", "module": "dist/index.esm.js", "types": "dist/index.d.ts", "exports": { ".": { + "types": "./dist/index.d.ts", "import": "./dist/index.esm.js", - "require": "./dist/index.js", - "types": "./dist/index.d.ts" + "require": "./dist/index.js" }, - "./react": { - "types": "./dist/ummgoban-react/index.d.ts" - }, - "./types": { - "types": "./dist/lib/types/index.d.ts" - }, - "./utils": { - "types": "./dist/lib/utils/index.d.ts" - }, - "./http": { - "types": "./dist/ummgoban-http/index.d.ts" + "./network": { + "types": "./dist/network/index.d.ts" }, - "./error": { - "types": "./dist/ummgoban-http/error/index.d.ts" + "./lib": { + "types": "./dist/lib/index.d.ts" }, - "./api-client": { - "types": "./dist/ummgoban-http/api-client/index.d.ts" + "./react": { + "types": "./dist/react/index.d.ts" } }, "files": [ @@ -56,11 +47,13 @@ "registry": "https://npm.pkg.github.com/" }, "peerDependencies": { + "axios": ">=1.7.4", "react": ">=18.0.0" }, "devDependencies": { "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-commonjs": "^28.0.0", + "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^16.0.0", "@rollup/plugin-typescript": "^12.0.0", "@testing-library/dom": "^10.4.0", @@ -72,6 +65,7 @@ "@typescript-eslint/eslint-plugin": "^8.23.0", "@typescript-eslint/parser": "^8.23.0", "@vitejs/plugin-react": "^4.5.0", + "axios": "^1.7.4", "dotenv": "^16.4.7", "eslint": "^9.27.0", "eslint-config-prettier": "^10.1.5", @@ -82,15 +76,12 @@ "jiti": "^2.4.2", "jsdom": "^26.1.0", "prettier": "^3.5.3", + "react": "^18.0.0", "react-dom": "^18.0.0", "rollup": "^4.41.1", "tslib": "^2.8.1", "typescript": "^5.0.0", "vite": "^6.3.5", "vitest": "^3.1.4" - }, - "dependencies": { - "axios": "^1.7.4", - "react": "^18.0.0" } } diff --git a/rollup.config.mjs b/rollup.config.mjs index 3a5f3b2..b00b3a1 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -2,6 +2,7 @@ import typescript from '@rollup/plugin-typescript'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import alias from '@rollup/plugin-alias'; +import json from '@rollup/plugin-json'; import path from 'path'; import {fileURLToPath} from 'url'; @@ -23,13 +24,18 @@ export default { sourcemap: true, }, ], - external: [...Object.keys(pkg.peerDependencies || {}), ...Object.keys(pkg.dependencies || {})], + external: [...Object.keys(pkg.peerDependencies || {}), ...Object.keys(pkg.dependencies || {}), 'axios', 'react'], plugins: [ alias({ entries: [{find: '@', replacement: path.resolve(__dirname, 'src')}], }), - nodeResolve({extensions: ['.js', '.jsx', '.ts', '.tsx']}), + nodeResolve({ + extensions: ['.js', '.jsx', '.ts', '.tsx'], + browser: true, + preferBuiltins: false, + }), commonjs(), + json(), typescript({ tsconfig: './tsconfig.build.json', declaration: true, diff --git a/src/index.ts b/src/index.ts index 82f398b..f41904b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ -// http -export * from './ummgoban-http'; +// network +export * from './network'; // lib export * from './lib'; // react -export * from './ummgoban-react'; +export * from './react'; diff --git a/src/lib/index.ts b/src/lib/index.ts index 30bedc0..689a90e 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,5 +1,5 @@ // utils -export * from './uitls'; +export * from './utils'; // types export * from './types'; diff --git a/src/lib/uitls/hash/hash.spec.ts b/src/lib/utils/hash/hash.spec.ts similarity index 100% rename from src/lib/uitls/hash/hash.spec.ts rename to src/lib/utils/hash/hash.spec.ts diff --git a/src/lib/uitls/hash/hash.ts b/src/lib/utils/hash/hash.ts similarity index 100% rename from src/lib/uitls/hash/hash.ts rename to src/lib/utils/hash/hash.ts diff --git a/src/lib/uitls/hash/index.ts b/src/lib/utils/hash/index.ts similarity index 100% rename from src/lib/uitls/hash/index.ts rename to src/lib/utils/hash/index.ts diff --git a/src/lib/uitls/index.ts b/src/lib/utils/index.ts similarity index 100% rename from src/lib/uitls/index.ts rename to src/lib/utils/index.ts diff --git a/src/network/api-client/api-client.spec.ts b/src/network/api-client/api-client.spec.ts new file mode 100644 index 0000000..304e6f3 --- /dev/null +++ b/src/network/api-client/api-client.spec.ts @@ -0,0 +1,47 @@ +import ApiClient from './api-client'; +import type {ApiClientOptions} from './api-client'; + +describe('ApiClient', () => { + it('should be defined', () => { + expect(ApiClient).toBeDefined(); + }); + + it('should throw error when getInstance is called before create', () => { + expect(() => ApiClient.getInstance()).toThrowError( + 'ApiClient is not initialized:\nApiClient.create() must be called before getInstance()', + ); + }); + + it('should create instance', () => { + const spyGetStorage = vi.fn(() => Promise.resolve(null)); + const spySetStorage = vi.fn(() => Promise.resolve()); + const spyRefreshAccessToken = vi.fn(() => Promise.resolve(null)); + + const options: ApiClientOptions = { + serverApiBaseUrl: 'https://api.example.com', + sessionOptions: { + getStorage: spyGetStorage, + setStorage: spySetStorage, + refreshAccessToken: spyRefreshAccessToken, + }, + }; + const instance = ApiClient.create(options); + expect(instance).toBeDefined(); + expect(spyGetStorage).not.toHaveBeenCalled(); + expect(spySetStorage).not.toHaveBeenCalled(); + expect(spyRefreshAccessToken).not.toHaveBeenCalled(); + }); + + it('should get instance', () => { + const options: ApiClientOptions = { + serverApiBaseUrl: 'https://api.example.com', + sessionOptions: { + getStorage: () => Promise.resolve(null), + setStorage: () => Promise.resolve(), + refreshAccessToken: () => Promise.resolve(null), + }, + }; + const instance = ApiClient.create(options); + expect(ApiClient.getInstance()).toBe(instance); + }); +}); diff --git a/src/ummgoban-http/api-client/api-client.ts b/src/network/api-client/api-client.ts similarity index 99% rename from src/ummgoban-http/api-client/api-client.ts rename to src/network/api-client/api-client.ts index 6c3079a..75881ef 100644 --- a/src/ummgoban-http/api-client/api-client.ts +++ b/src/network/api-client/api-client.ts @@ -1,8 +1,7 @@ import axios, {AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig, AxiosError} from 'axios'; import {CustomError} from '../error'; - -import {SessionType, StorageKeyType} from '@/lib/types'; +import {SessionType, StorageKeyType} from 'lib/types'; export interface ApiClientOptions { serverApiBaseUrl: string; diff --git a/src/ummgoban-http/api-client/index.ts b/src/network/api-client/index.ts similarity index 63% rename from src/ummgoban-http/api-client/index.ts rename to src/network/api-client/index.ts index 9419526..e758515 100644 --- a/src/ummgoban-http/api-client/index.ts +++ b/src/network/api-client/index.ts @@ -1,5 +1,4 @@ import ApiClient from './api-client'; import type {ApiClientOptions} from './api-client'; -export default ApiClient; -export {ApiClientOptions}; +export {ApiClient, ApiClientOptions}; diff --git a/src/ummgoban-http/error/http-error.type.ts b/src/network/error/http-error.type.ts similarity index 100% rename from src/ummgoban-http/error/http-error.type.ts rename to src/network/error/http-error.type.ts diff --git a/src/ummgoban-http/error/index.ts b/src/network/error/index.ts similarity index 100% rename from src/ummgoban-http/error/index.ts rename to src/network/error/index.ts diff --git a/src/ummgoban-http/index.ts b/src/network/index.ts similarity index 100% rename from src/ummgoban-http/index.ts rename to src/network/index.ts diff --git a/src/ummgoban-react/index.ts b/src/react/index.ts similarity index 100% rename from src/ummgoban-react/index.ts rename to src/react/index.ts diff --git a/src/ummgoban-react/provider/combine-provider.spec.tsx b/src/react/provider/combine-provider.spec.tsx similarity index 92% rename from src/ummgoban-react/provider/combine-provider.spec.tsx rename to src/react/provider/combine-provider.spec.tsx index f311ef3..d1d9fd6 100644 --- a/src/ummgoban-react/provider/combine-provider.spec.tsx +++ b/src/react/provider/combine-provider.spec.tsx @@ -29,7 +29,7 @@ const TestMultiComponent = () => { describe('CombineProviders', () => { it('should render children with a single provider', () => { - const providers = [{provider: TestProvider, props: {value: {value: 'test'}}}] as const satisfies Providers< + const providers = [{provider: TestProvider, props: {value: {value: 'test'}}}] satisfies Providers< [ProviderEntry] >; const CombineProviders = combineProviders(providers); @@ -46,7 +46,7 @@ describe('CombineProviders', () => { const providers = [ {provider: TestProvider, props: {value: {value: 'test'}}}, {provider: ThemeProvider, props: {value: {theme: 'dark'}}}, - ] as const satisfies Providers<[ProviderEntry, ProviderEntry]>; + ] satisfies Providers<[ProviderEntry, ProviderEntry]>; const CombineProviders = combineProviders(providers); render( diff --git a/src/ummgoban-react/provider/combine-provider.tsx b/src/react/provider/combine-provider.tsx similarity index 97% rename from src/ummgoban-react/provider/combine-provider.tsx rename to src/react/provider/combine-provider.tsx index 3d4ab7f..3f564fb 100644 --- a/src/ummgoban-react/provider/combine-provider.tsx +++ b/src/react/provider/combine-provider.tsx @@ -24,7 +24,7 @@ export type Providers[]> = T; * const providers = [ * {provider: ThemeProvider, props: {value: {theme: 'dark'}}}, * {provider: TestProvider, props: {value: {value: 'test'}}}, - * ] as const satisfies Providers<[ + * ] satisfies Providers<[ * ProviderEntry, * ProviderEntry, * ]>; diff --git a/src/ummgoban-react/provider/index.ts b/src/react/provider/index.ts similarity index 100% rename from src/ummgoban-react/provider/index.ts rename to src/react/provider/index.ts diff --git a/tsconfig.json b/tsconfig.json index c8ad032..c692b5b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,8 @@ "allowSyntheticDefaultImports": true, "baseUrl": "./src", "paths": { - "@/*": ["*"] + "react": ["node_modules/react"], + "@ummgoban/*": ["src/*"] } }, "include": ["src/**/*", "vitest.setup.ts", "jest-dom.d.ts"], diff --git a/yarn.lock b/yarn.lock index 980d3f9..5e5bd17 100644 --- a/yarn.lock +++ b/yarn.lock @@ -797,6 +797,20 @@ __metadata: languageName: node linkType: hard +"@rollup/plugin-json@npm:^6.1.0": + version: 6.1.0 + resolution: "@rollup/plugin-json@npm:6.1.0" + dependencies: + "@rollup/pluginutils": ^5.1.0 + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + checksum: cc018d20c80242a2b8b44fae61a968049cf31bb8406218187cc7cda35747616594e79452dd65722e7da6dd825b392e90d4599d43cd4461a02fefa2865945164e + languageName: node + linkType: hard + "@rollup/plugin-node-resolve@npm:^16.0.0": version: 16.0.1 resolution: "@rollup/plugin-node-resolve@npm:16.0.1" @@ -1308,6 +1322,7 @@ __metadata: dependencies: "@rollup/plugin-alias": ^5.1.1 "@rollup/plugin-commonjs": ^28.0.0 + "@rollup/plugin-json": ^6.1.0 "@rollup/plugin-node-resolve": ^16.0.0 "@rollup/plugin-typescript": ^12.0.0 "@testing-library/dom": ^10.4.0 @@ -1338,6 +1353,7 @@ __metadata: vite: ^6.3.5 vitest: ^3.1.4 peerDependencies: + axios: ">=1.7.4" react: ">=18.0.0" languageName: unknown linkType: soft