From 0fbd31059fa57cea1b57f17f52d31cfe55bb1aa4 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Tue, 4 Apr 2023 17:06:04 +0800 Subject: [PATCH] refactor: fix ui import --- packages/shared/src/{ => node}/env/GlobalValues.ts | 0 packages/shared/src/{ => node}/env/UrlSet.test.ts | 0 packages/shared/src/{ => node}/env/UrlSet.ts | 0 packages/shared/src/node/env/index.ts | 2 ++ packages/shared/src/{ => node}/env/throw-errors.ts | 0 packages/shared/src/node/index.ts | 1 + packages/shared/src/universal.ts | 2 -- packages/ui/jest.config.ts | 3 ++- packages/ui/package.json | 10 +++++++--- packages/ui/src/App.tsx | 2 +- packages/ui/src/components/PageMeta/index.tsx | 2 +- packages/ui/tsconfig.json | 1 + pnpm-lock.yaml | 12 ++++++++++-- 13 files changed, 25 insertions(+), 10 deletions(-) rename packages/shared/src/{ => node}/env/GlobalValues.ts (100%) rename packages/shared/src/{ => node}/env/UrlSet.test.ts (100%) rename packages/shared/src/{ => node}/env/UrlSet.ts (100%) create mode 100644 packages/shared/src/node/env/index.ts rename packages/shared/src/{ => node}/env/throw-errors.ts (100%) diff --git a/packages/shared/src/env/GlobalValues.ts b/packages/shared/src/node/env/GlobalValues.ts similarity index 100% rename from packages/shared/src/env/GlobalValues.ts rename to packages/shared/src/node/env/GlobalValues.ts diff --git a/packages/shared/src/env/UrlSet.test.ts b/packages/shared/src/node/env/UrlSet.test.ts similarity index 100% rename from packages/shared/src/env/UrlSet.test.ts rename to packages/shared/src/node/env/UrlSet.test.ts diff --git a/packages/shared/src/env/UrlSet.ts b/packages/shared/src/node/env/UrlSet.ts similarity index 100% rename from packages/shared/src/env/UrlSet.ts rename to packages/shared/src/node/env/UrlSet.ts diff --git a/packages/shared/src/node/env/index.ts b/packages/shared/src/node/env/index.ts new file mode 100644 index 000000000..e768e6af3 --- /dev/null +++ b/packages/shared/src/node/env/index.ts @@ -0,0 +1,2 @@ +export { default as UrlSet } from './UrlSet.js'; +export { default as GlobalValues } from './GlobalValues.js'; diff --git a/packages/shared/src/env/throw-errors.ts b/packages/shared/src/node/env/throw-errors.ts similarity index 100% rename from packages/shared/src/env/throw-errors.ts rename to packages/shared/src/node/env/throw-errors.ts diff --git a/packages/shared/src/node/index.ts b/packages/shared/src/node/index.ts index f0318fc3b..5e22e6057 100644 --- a/packages/shared/src/node/index.ts +++ b/packages/shared/src/node/index.ts @@ -1 +1,2 @@ export { default as findPackage } from './find-package.js'; +export * from './env/index.js'; diff --git a/packages/shared/src/universal.ts b/packages/shared/src/universal.ts index 4f8006dbc..7bf661541 100644 --- a/packages/shared/src/universal.ts +++ b/packages/shared/src/universal.ts @@ -1,4 +1,2 @@ export * from './database/index.js'; export * from './utils/index.js'; -export { default as UrlSet } from './env/UrlSet.js'; -export { default as GlobalValues } from './env/GlobalValues.js'; diff --git a/packages/ui/jest.config.ts b/packages/ui/jest.config.ts index 20f112d08..a2dbc3967 100644 --- a/packages/ui/jest.config.ts +++ b/packages/ui/jest.config.ts @@ -10,7 +10,8 @@ const config: Config.InitialOptions = { '\\.(png)$': 'jest-transform-stub', }, moduleNameMapper: { - '^@logto/app-insights/(.*)$': '/node_modules/@logto/app-insights/$1', + '^@logto/app-insights/(.*)$': '/node_modules/@logto/app-insights/lib/$1', + '^@logto/shared/(.*)$': '/node_modules/@logto/shared/lib/$1', }, }), // Will update common config soon diff --git a/packages/ui/package.json b/packages/ui/package.json index dd3545c32..935cd1b56 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -4,7 +4,9 @@ "license": "MPL-2.0", "type": "module", "private": true, - "files": ["dist"], + "files": [ + "dist" + ], "scripts": { "precommit": "lint-staged", "start": "parcel src/index.html", @@ -25,6 +27,7 @@ "@logto/phrases": "workspace:^", "@logto/phrases-ui": "workspace:^", "@logto/schemas": "workspace:^", + "@logto/shared": "workspace:^", "@parcel/compressor-brotli": "2.8.3", "@parcel/compressor-gzip": "2.8.3", "@parcel/core": "2.8.3", @@ -80,7 +83,7 @@ "react-timer-hook": "^3.0.5", "react-top-loading-bar": "^2.3.1", "stylelint": "^15.0.0", - "superstruct": "^0.16.0", + "superstruct": "^1.0.3", "tiny-cookie": "^2.4.1", "ts-jest": "^29.0.5", "typescript": "^5.0.0", @@ -102,7 +105,8 @@ "^/api/.+" ], "alias": { - "@/*": "./src/$1" + "@/*": "./src/$1", + "superstruct": "./node_modules/superstruct/dist/index.mjs" }, "eslintConfig": { "extends": "@silverhand/react", diff --git a/packages/ui/src/App.tsx b/packages/ui/src/App.tsx index ccf245c6e..4eee3cbe4 100644 --- a/packages/ui/src/App.tsx +++ b/packages/ui/src/App.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { Route, Routes, BrowserRouter } from 'react-router-dom'; import AppLayout from './Layout/AppLayout'; diff --git a/packages/ui/src/components/PageMeta/index.tsx b/packages/ui/src/components/PageMeta/index.tsx index 54a26ba6c..bb3e733bf 100644 --- a/packages/ui/src/components/PageMeta/index.tsx +++ b/packages/ui/src/components/PageMeta/index.tsx @@ -1,4 +1,4 @@ -import { appInsightsReact } from '@logto/app-insights/lib/react'; +import { appInsightsReact } from '@logto/app-insights/react'; import { useEffect, useState } from 'react'; import { Helmet } from 'react-helmet'; import { type TFuncKey, useTranslation } from 'react-i18next'; diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json index 7d925ad29..1144dfb82 100644 --- a/packages/ui/tsconfig.json +++ b/packages/ui/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@silverhand/ts-config-react/tsconfig.base", "compilerOptions": { + "moduleResolution": "bundler", "baseUrl": "./", "paths": { "@/*": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ef51f9a6..28e34839c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3802,6 +3802,9 @@ importers: '@logto/schemas': specifier: workspace:^ version: link:../schemas + '@logto/shared': + specifier: workspace:^ + version: link:../shared '@parcel/compressor-brotli': specifier: 2.8.3 version: 2.8.3(@parcel/core@2.8.3) @@ -3968,8 +3971,8 @@ importers: specifier: ^15.0.0 version: 15.0.0 superstruct: - specifier: ^0.16.0 - version: 0.16.0 + specifier: ^1.0.3 + version: 1.0.3 tiny-cookie: specifier: ^2.4.1 version: 2.4.1 @@ -17971,6 +17974,11 @@ packages: resolution: {integrity: sha512-IDQtwnnlaan1NhuHqyD/U11lROYvCQ79JyfwlFU9xEVHzqV/Ys/RrwmHPCG0CVH/1g0BuodEjH1msxK2UHxehA==} dev: true + /superstruct@1.0.3: + resolution: {integrity: sha512-8iTn3oSS8nRGn+C2pgXSKPI3jmpm6FExNazNpjvqS6ZUJQCej3PUXEKM8NjHBOs54ExM+LPW/FBRhymrdcCiSg==} + engines: {node: '>=14.0.0'} + dev: true + /supertest@6.2.2: resolution: {integrity: sha512-wCw9WhAtKJsBvh07RaS+/By91NNE0Wh0DN19/hWPlBOU8tAfOtbZoVSV4xXeoKoxgPx0rx2y+y+8660XtE7jzg==} engines: {node: '>=6.0.0'}