diff --git a/packages/cli/jest.config.ts b/packages/cli/jest.config.ts index f9b0afe8b..b6fcd166f 100644 --- a/packages/cli/jest.config.ts +++ b/packages/cli/jest.config.ts @@ -7,6 +7,7 @@ const config: Config.InitialOptions = { roots: ['./src'], moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1', + '^(chalk|inquirer|ora)$': '/../shared/src/utils/module-proxy.ts', }, }), // Will update common config soon diff --git a/packages/cli/package.json b/packages/cli/package.json index d86f4bea6..a8cd4fcd9 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -44,7 +44,7 @@ "@logto/schemas": "workspace:^", "@logto/shared": "workspace:^", "@silverhand/essentials": "^1.3.0", - "chalk": "^4.1.2", + "chalk": "^5.0.0", "decamelize": "^5.0.0", "dotenv": "^16.0.0", "fs-extra": "^10.1.0", diff --git a/packages/core/jest.config.ts b/packages/core/jest.config.ts index 6c3df1991..4888767bc 100644 --- a/packages/core/jest.config.ts +++ b/packages/core/jest.config.ts @@ -8,10 +8,11 @@ const config: Config.InitialOptions = { moduleNameMapper: { '^#src/(.*)\\.js(x)?$': '/src/$1', '^(\\.{1,2}/.*)\\.js$': '$1', + '^(chalk|inquirer|ora)$': '/../shared/src/utils/module-proxy.ts', }, }), // Will update common config soon - transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@logto))/)'], + transformIgnorePatterns: ['node_modules/(?!(.*(nanoid|jose|ky|@logto|got))/)'], }; export default config; diff --git a/packages/core/package.json b/packages/core/package.json index 834c7a317..a1af7df8e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -32,7 +32,7 @@ "@logto/schemas": "workspace:^", "@logto/shared": "workspace:^", "@silverhand/essentials": "^1.3.0", - "chalk": "^4", + "chalk": "^5.0.0", "clean-deep": "^3.4.0", "date-fns": "^2.29.3", "debug": "^4.3.4", diff --git a/packages/shared/src/utils/index.ts b/packages/shared/src/utils/index.ts index 8bfcfa7f3..7941ccd79 100644 --- a/packages/shared/src/utils/index.ts +++ b/packages/shared/src/utils/index.ts @@ -1,3 +1,4 @@ export * from './id.js'; export * from './function.js'; +export { default as moduleProxy } from './module-proxy.js'; export { default as findPackage } from './find-package.js'; diff --git a/packages/shared/src/utils/module-proxy.ts b/packages/shared/src/utils/module-proxy.ts new file mode 100644 index 000000000..e97f4bc9f --- /dev/null +++ b/packages/shared/src/utils/module-proxy.ts @@ -0,0 +1,16 @@ +// For testing +// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment +const proxy: ProxyConstructor = new Proxy( + {}, + { + get(_, name) { + if (name === 'default') { + return proxy; + } + + return jest.fn(); + }, + } +); + +export default proxy; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e8f55bfc1..6cfae7078 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,7 +36,7 @@ importers: '@types/semver': ^7.3.12 '@types/tar': ^6.1.2 '@types/yargs': ^17.0.13 - chalk: ^4.1.2 + chalk: ^5.0.0 decamelize: ^5.0.0 dotenv: ^16.0.0 eslint: ^8.21.0 @@ -65,7 +65,7 @@ importers: '@logto/schemas': link:../schemas '@logto/shared': link:../shared '@silverhand/essentials': 1.3.0 - chalk: 4.1.2 + chalk: 5.1.2 decamelize: 5.0.1 dotenv: 16.0.0 fs-extra: 10.1.0 @@ -278,7 +278,7 @@ importers: '@types/node': ^16.0.0 '@types/oidc-provider': ^7.12.0 '@types/supertest': ^2.0.11 - chalk: ^4 + chalk: ^5.0.0 clean-deep: ^3.4.0 copyfiles: ^2.4.1 date-fns: ^2.29.3 @@ -335,7 +335,7 @@ importers: '@logto/schemas': link:../schemas '@logto/shared': link:../shared '@silverhand/essentials': 1.3.0 - chalk: 4.1.2 + chalk: 5.1.2 clean-deep: 3.4.0 date-fns: 2.29.3 debug: 4.3.4 @@ -5416,6 +5416,11 @@ packages: ansi-styles: 4.3.0 supports-color: 7.2.0 + /chalk/5.1.2: + resolution: {integrity: sha512-E5CkT4jWURs1Vy5qGJye+XwCkNj7Od3Af7CP6SujMetSMkLs8Do2RWJK5yx1wamHV/op8Rz+9rltjaTQWDnEFQ==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + dev: false + /char-regex/1.0.2: resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==} engines: {node: '>=10'}