ant-design/tests/dekko/use-client.test.js
Dunqing f0c105d262
feat: insert use client automatically at compilations instead of hardcode (#44608)
* feat: remove the hardcode of `use client`

* chore: update `@ant-design/tools`

* test: update

* fix: incorrect dictionary

* chore: update dep

* ci: check use client

* chore: update ci

* fix: should be LIB_DIR

* ci: should only run in dist

* chore: update check tsx files
2023-09-04 19:27:20 +08:00

33 lines
956 B
JavaScript

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()
.assert('contain use client', (filename) => includeUseClient(filename));
}
// eslint-disable-next-line no-console
console.log(chalk.green('✨ use client passed!'));