diff --git a/.dumi/theme/plugin.ts b/.dumi/theme/plugin.ts index 78b2de1f..507928ca 100644 --- a/.dumi/theme/plugin.ts +++ b/.dumi/theme/plugin.ts @@ -2,7 +2,6 @@ import { createHash } from 'crypto'; import fs from 'fs'; import path from 'path'; import createEmotionServer from '@emotion/server/create-instance'; -import chalk from 'chalk'; import type { IApi, IRoute } from 'dumi'; import ReactTechStack from 'dumi/dist/techStacks/react'; import sylvanas from 'sylvanas'; @@ -126,9 +125,9 @@ class AntdReactTechStack extends ReactTechStack { const resolve = (p: string): string => require.resolve(p); -const RoutesPlugin = (api: IApi) => { +const RoutesPlugin = async (api: IApi) => { // const ssrCssFileName = `ssr-${Date.now()}.css`; - + const chalk = await import('chalk').then((m) => m.default); const writeCSSFile = (key: string, hashKey: string, cssString: string) => { const fileName = `style-${key}.${getHash(hashKey)}.css`; diff --git a/bun.lockb b/bun.lockb index 5cdb4eeb..9a5d3803 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 4daef247..7731616d 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "start": "tsx ./scripts/set-node-options.ts cross-env PORT=8001 dumi dev", "pretest": "npm run version", "test": "jest --config .jest.js --no-cache --collect-coverage", - "test:dekko": "node ./tests/dekko/index.test.js", + "test:dekko": "tsx ./tests/dekko/index.test.ts", "test:image": "jest --config .jest.image.js --no-cache -i -u --forceExit", "test:node": "npm run version && jest --config .jest.node.js --no-cache", "test:package-diff": "antd-tools run package-diff", @@ -164,7 +164,7 @@ "axios": "^1.7.7", "browserslist": "^4.23.3", "browserslist-to-esbuild": "^2.1.1", - "chalk": "^4.1.2", + "chalk": "^5.4.1", "cheerio": "^1.0.0", "circular-dependency-plugin": "^5.2.2", "cli-progress": "^3.12.0", diff --git a/tests/dekko/dist.test.js b/tests/dekko/dist.test.ts similarity index 76% rename from tests/dekko/dist.test.js rename to tests/dekko/dist.test.ts index 35d53352..67e592da 100644 --- a/tests/dekko/dist.test.js +++ b/tests/dekko/dist.test.ts @@ -1,5 +1,5 @@ -const $ = require('dekko'); -const chalk = require('chalk'); +import chalk from 'chalk'; +import $ from 'dekko'; $('dist').isDirectory().hasFile('antdx.js').hasFile('antdx.min.js').hasFile('antdx.min.js.map'); diff --git a/tests/dekko/index.test.js b/tests/dekko/index.test.js deleted file mode 100644 index b6c0e9fd..00000000 --- a/tests/dekko/index.test.js +++ /dev/null @@ -1,4 +0,0 @@ -require('./dist.test'); -require('./lib.test'); -// Not applied yet -// require('./use-client.test'); diff --git a/tests/dekko/index.test.ts b/tests/dekko/index.test.ts new file mode 100644 index 00000000..76699101 --- /dev/null +++ b/tests/dekko/index.test.ts @@ -0,0 +1,4 @@ +import './dist.test'; +import './lib.test'; +// Not applied yet +// import './use-client.test'; diff --git a/tests/dekko/lib.test.js b/tests/dekko/lib.test.ts similarity index 84% rename from tests/dekko/lib.test.js rename to tests/dekko/lib.test.ts index 350a60cf..0cbd0c45 100644 --- a/tests/dekko/lib.test.js +++ b/tests/dekko/lib.test.ts @@ -1,18 +1,18 @@ -const $ = require('dekko'); -const chalk = require('chalk'); +import chalk from 'chalk'; +import $ from 'dekko'; $('lib').isDirectory().hasFile('index.js').hasFile('index.d.ts'); $('lib/*') .filter( - (filename) => + (filename: string) => !filename.endsWith('index.js') && !filename.endsWith('index.d.ts') && !filename.endsWith('.map'), ) .isDirectory() .filter( - (filename) => + (filename: string) => !filename.endsWith('style') && !filename.endsWith('_util') && !filename.endsWith('locale') && diff --git a/tests/dekko/use-client.test.js b/tests/dekko/use-client.test.js deleted file mode 100644 index 3f8997c0..00000000 --- a/tests/dekko/use-client.test.js +++ /dev/null @@ -1,33 +0,0 @@ -const $ = require('dekko'); -const chalk = require('chalk'); -const fs = require('fs'); - -const includeUseClient = (filename) => - fs.readFileSync(filename).toString().includes('"use client"'); - -if (process.env.LIB_DIR === 'dist') { - $('dist/*') - .isFile() - .assert("doesn't contain use client", (filename) => !includeUseClient(filename)); -} else { - $('{es,lib}/index.js') - .isFile() - .assert('contain use client', (filename) => includeUseClient(filename)); - - $('{es,lib}/*/index.js') - .isFile() - .assert('contain use client', (filename) => includeUseClient(filename)); - - // check tsx files - $('{es,lib}/typography/*.js') - .isFile() - .assert('contain use client', (filename) => includeUseClient(filename)); - - $('{es,lib}/typography/Base/*.js') - .isFile() - .filter((filename) => !filename.endsWith('/util.js')) - .assert('contain use client', (filename) => includeUseClient(filename)); -} - -// eslint-disable-next-line no-console -console.log(chalk.green('✨ use client passed!')); diff --git a/tests/dekko/use-client.test.ts b/tests/dekko/use-client.test.ts new file mode 100644 index 00000000..afecc69d --- /dev/null +++ b/tests/dekko/use-client.test.ts @@ -0,0 +1,33 @@ +import fs from 'node:fs'; +import chalk from 'chalk'; +import $ from 'dekko'; + +const includeUseClient = (filename: string) => + fs.readFileSync(filename).toString().includes('"use client"'); + +if (process.env.LIB_DIR === 'dist') { + $('dist/*') + .isFile() + .assert("doesn't contain use client", (filename: string) => !includeUseClient(filename)); +} else { + $('{es,lib}/index.js') + .isFile() + .assert('contain use client', (filename: string) => includeUseClient(filename)); + + $('{es,lib}/*/index.js') + .isFile() + .assert('contain use client', (filename: string) => includeUseClient(filename)); + + // check tsx files + $('{es,lib}/typography/*.js') + .isFile() + .assert('contain use client', (filename: string) => includeUseClient(filename)); + + $('{es,lib}/typography/Base/*.js') + .isFile() + .filter((filename: string) => !filename.endsWith('/util.js')) + .assert('contain use client', (filename: string) => includeUseClient(filename)); +} + +// eslint-disable-next-line no-console +console.log(chalk.green('✨ use client passed!')); diff --git a/typings/custom-typings.d.ts b/typings/custom-typings.d.ts index b4ac4db2..0e5e4784 100644 --- a/typings/custom-typings.d.ts +++ b/typings/custom-typings.d.ts @@ -27,3 +27,5 @@ declare module '@npmcli/run-script' { } declare module '@microflash/rehype-figure'; + +declare module 'dekko';