Skip to content

Commit 0e5e56d

Browse files
committed
type: fix type issue.
1 parent 5f354a8 commit 0e5e56d

File tree

14 files changed

+57
-42
lines changed

14 files changed

+57
-42
lines changed

core/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"types": "lib/index.d.ts",
88
"scripts": {
99
"start": "npm run watch",
10-
"build": "tsbb build --file-names src/bin/kkt.ts --file-names src/scripts/build.ts --file-names src/scripts/doc.ts --file-names src/scripts/start.ts --file-names src/scripts/testk.ts --no-esm",
11-
"watch": "tsbb watch --file-names src/bin/kkt.ts --file-names src/scripts/build.ts --file-names src/scripts/doc.ts --file-names src/scripts/start.ts --file-names src/scripts/testk.ts --no-esm",
10+
"build": "tsbb build src/*.ts --use-babel --no-esm",
11+
"watch": "tsbb watch src/*.ts --use-babel --no-esm",
1212
"test": "tsbb test",
1313
"coverage": "tsbb test --coverage"
1414
},

core/src/global.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare const require: {
2+
(u: string): any;
3+
cache: {
4+
[key: string]: any;
5+
};
6+
resolve(path: string): string;
7+
};

core/src/overrides/checkRequired.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { OverridePaths } from './paths';
1010
*/
1111
export function checkRequiredFiles(paths: OverridePaths, isNotCheckHTML: boolean) {
1212
const checkRequiredFilesPath = `${reactDevUtils}/checkRequiredFiles`;
13-
require.cache[require.resolve(checkRequiredFilesPath)].exports = (files: fs.PathLike[]) => {
13+
require.cache[require.resolve(checkRequiredFilesPath)].exports = (files: (fs.PathLike | undefined)[] = []) => {
1414
files = files
1515
.map((item) => {
1616
if (/(\.html)$/.test(item as string) && isNotCheckHTML) {
@@ -26,15 +26,17 @@ export function checkRequiredFiles(paths: OverridePaths, isNotCheckHTML: boolean
2626
try {
2727
files.forEach((filePath) => {
2828
currentFilePath = filePath;
29-
fs.accessSync(filePath, fs.constants.F_OK);
29+
filePath && fs.accessSync(filePath, fs.constants.F_OK);
3030
});
3131
return true;
3232
} catch (err) {
33-
const dirName = path.dirname(currentFilePath);
34-
const fileName = path.basename(currentFilePath);
35-
console.log('\x1b[1;31m Could not find a required file. \x1b[0m');
36-
console.log(`\x1b[1;31m Name: \x1b[0m ${fileName}`);
37-
console.log(`\x1b[1;31m Searched in: \x1b[0m \x1b[1;36m${dirName}\x1b[0m`);
33+
if (currentFilePath) {
34+
const dirName = path.dirname(currentFilePath);
35+
const fileName = path.basename(currentFilePath);
36+
console.log('\x1b[1;31m Could not find a required file. \x1b[0m');
37+
console.log(`\x1b[1;31m Name: \x1b[0m ${fileName}`);
38+
console.log(`\x1b[1;31m Searched in: \x1b[0m \x1b[1;36m${dirName}\x1b[0m`);
39+
}
3840
return false;
3941
}
4042
};

core/src/plugins/miniCssExtractPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const miniCssExtractPlugin = (
2323
options: MiniCssExtractPlugin.PluginOptions = {},
2424
) => {
2525
const regexp = /(MiniCssExtractPlugin)/;
26-
conf.plugins = conf.plugins
26+
conf.plugins = (conf.plugins || [])
2727
.map((item) => {
2828
if (item.constructor && item.constructor.name && regexp.test(item.constructor.name)) {
2929
return new MiniCssExtractPlugin({

core/src/plugins/staticDoc.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ export function getDocsData(str: string = '', route = '/_doc'): DocsDataResult {
4141
result.dirPath = arr[0];
4242
result.route = arr[1] || route;
4343
}
44-
if (!result.route.startsWith('/')) {
44+
if (result.route && !result.route.startsWith('/')) {
4545
result.route = '/' + result.route;
4646
}
4747
// relative directory
4848
if (fs.existsSync(path.resolve(dirPath))) {
4949
result.docRoot = path.resolve(dirPath);
50-
result.pkgPath = resolvePackagePath(process.cwd(), process.cwd());
51-
const pkg = fs.readJSONSync(result.pkgPath);
50+
result.pkgPath = resolvePackagePath(process.cwd(), process.cwd()) || '';
51+
const pkg = fs.readJSONSync(result.pkgPath!);
5252
result.name = pkg.name;
5353
result.route = '/';
5454
return result;
5555
}
5656

57-
const [_, name] = dirPath.match(/^([a-zA-Z\-]+|@[a-zA-Z\-]+\/[a-zA-Z\-]+)\/?/i);
57+
const [_, name] = dirPath.match(/^([a-zA-Z\-]+|@[a-zA-Z\-]+\/[a-zA-Z\-]+)\/?/i) || [];
5858
result.name = name;
59-
result.pkgPath = resolvePackagePath(name, process.cwd());
60-
result.root = path.dirname(result.pkgPath).replace(new RegExp(`${name.replace('/', path.sep)}$`, 'ig'), '');
59+
result.pkgPath = resolvePackagePath(name, process.cwd()) || '';
60+
result.root = path.dirname(result.pkgPath!).replace(new RegExp(`${name.replace('/', path.sep)}$`, 'ig'), '');
6161
const [repath] = str.replace(name, '').split(':');
62-
result.docRoot = path.resolve(path.dirname(result.pkgPath) + repath);
62+
result.docRoot = path.resolve(path.dirname(result.pkgPath!) + repath);
6363
return { ...result };
6464
}
6565

@@ -78,7 +78,9 @@ export const staticDocSetupMiddlewares = (
7878
if (options.config?.output?.publicPath && typeof options.config.output.publicPath === 'string') {
7979
routePath = options.config.output.publicPath.replace(/\/+$/, '') + route;
8080
}
81-
devServer.app.use(routePath, express.static(docRoot));
81+
if (routePath && docRoot) {
82+
devServer.app && devServer.app.use(routePath, express.static(docRoot));
83+
}
8284
}
8385
return middlewares;
8486
};

core/src/scripts/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default async function build(argvs: BuildArgs) {
5050
// run original script
5151
await require(`${reactScripts}/scripts/build`);
5252
} catch (error) {
53-
const message = error && error.message ? error.message : '';
53+
const message = error && error instanceof Error && error.message ? error.message : '';
5454
console.log('\x1b[31;1m KKT:BUILD:ERROR: \x1b[0m\n', error);
5555
new Error(`KKT:BUILD:ERROR: \n ${message}`);
5656
process.exit(1);

core/src/scripts/doc.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ export interface DocsArgs extends BuildArgs {
1818
export default async function docs(argv: DocsArgs) {
1919
try {
2020
const { route, docRoot, dirPath, ...other } = getDocsData(argv.path, '/');
21-
app.use(route, express.static(docRoot), (req, res, next) => {
22-
const content = fs.readFileSync(path.resolve(docRoot, './index.html'));
23-
res.send(content.toString());
24-
next();
25-
});
26-
const DEFAULT_PORT = parseInt(process.env.DOC_PORT, 10) || argv.port || 3002;
21+
if (route && docRoot) {
22+
app.use(route, express.static(docRoot), (req, res, next) => {
23+
const content = fs.readFileSync(path.resolve(docRoot, './index.html'));
24+
res.send(content.toString());
25+
next();
26+
});
27+
}
28+
const DEFAULT_PORT = (process.env.DOC_PORT && parseInt(process.env.DOC_PORT, 10)) || argv.port || 3002;
2729
const port = await choosePort(HOST, DEFAULT_PORT);
2830
app.listen(port, () => {
2931
const urls = prepareUrls(
@@ -38,7 +40,7 @@ export default async function docs(argv: DocsArgs) {
3840
console.log(` On Your Network: ${urls.localUrlForTerminal}`);
3941
});
4042
} catch (error) {
41-
const message = error && error.message ? error.message : '';
43+
const message = error && error instanceof Error && error.message ? error.message : '';
4244
console.log('\x1b[31;1m KKT:DOC:ERROR: \x1b[0m\n', error);
4345
new Error(`KKT:BUILD:ERROR: \n ${message}`);
4446
process.exit(1);

core/src/scripts/start.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default async function start(argvs: StartArgs) {
108108
// Keep `evalSourceMapMiddleware`
109109
// middlewares before `redirectServedPath` otherwise will not have any effect
110110
// This lets us fetch source contents from webpack for the error overlay
111-
devServer.app.use(evalSourceMapMiddleware(devServer));
111+
devServer.app && devServer.app.use(evalSourceMapMiddleware(devServer));
112112
if (fs.existsSync(paths.proxySetup)) {
113113
// This registers user provided middleware for proxy reasons
114114
require(paths.proxySetup)(devServer.app);
@@ -119,14 +119,14 @@ export default async function start(argvs: StartArgs) {
119119
}
120120

121121
// Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
122-
devServer.app.use(redirectServedPath(paths.publicUrlOrPath));
122+
devServer.app && devServer.app.use(redirectServedPath(paths.publicUrlOrPath));
123123

124124
// This service worker file is effectively a 'no-op' that will reset any
125125
// previous service worker registered for the same host:port combination.
126126
// We do this in development to avoid hitting the production cache if
127127
// it used the same host and port.
128128
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
129-
devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
129+
devServer.app && devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
130130
const mds = setupMiddlewares ? setupMiddlewares(middlewares, devServer) : middlewares;
131131
return staticDocSetupMiddlewares(mds, devServer, { ...argvs, paths, config: webpackConf });
132132
};
@@ -142,7 +142,7 @@ export default async function start(argvs: StartArgs) {
142142
console.log('❌ KKT:\x1b[31;1mERR\x1b[0m:', err);
143143
return;
144144
}
145-
if (stats.hasErrors()) {
145+
if (stats && stats.hasErrors()) {
146146
clearConsole();
147147
console.log(`❌ KKT:\x1b[31;1mERR\x1b[0m: \x1b[35;1m${today()}\x1b[0m\n`, stats.toString());
148148
return;
@@ -156,7 +156,7 @@ export default async function start(argvs: StartArgs) {
156156
require(`${reactScripts}/scripts/start`);
157157
}
158158
} catch (error) {
159-
const message = error && error.message ? error.message : '';
159+
const message = error && error instanceof Error && error.message ? error.message : '';
160160
console.log('\x1b[31;1m KKT:START:ERROR: \x1b[0m\n', error);
161161
new Error(`KKT:START:ERROR: \n ${message}`);
162162
process.exit(1);

core/src/scripts/testk.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default async function test(argvs: TestArgs) {
1515
// run original script
1616
require(`${reactScripts}/scripts/test`);
1717
} catch (error) {
18-
const message = error && error.message ? error.message : '';
18+
const message = error && error instanceof Error && error.message ? error.message : '';
1919
console.log('\x1b[31;1m KKT:TEST:ERROR: \x1b[0m\n', error);
2020
new Error(`KKT:TEST:ERROR: \n ${message}`);
2121
process.exit(1);

core/src/utils/loaderConf.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function loaderConf(rcPath: string): Promise<KKTRC> {
9595
}
9696
return kktrc;
9797
} catch (error) {
98-
const message = error && error.message ? error.message : '';
98+
const message = error && error instanceof Error && error.message ? error.message : '';
9999
console.log('Invalid \x1b[31;1m .kktrc.js \x1b[0m file.\n', error);
100100
new Error(`Invalid .kktrc.js file. \n ${message}`);
101101
process.exit(1);

core/tsconfig.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"esModuleInterop": true,
5-
"skipLibCheck": true,
4+
"target": "ES5",
5+
"strict": true,
66
"declaration": true,
7-
"target": "es2017",
8-
"noImplicitAny": true,
7+
"esModuleInterop": true,
98
"resolveJsonModule": true,
109
"moduleResolution": "node",
11-
"sourceMap": true,
10+
"skipLibCheck": true,
11+
"noImplicitAny": true,
1212
"outDir": "lib",
1313
"baseUrl": "."
1414
},
15-
"include": ["src/**/*", "src/*"]
15+
"include": ["src/**/*"]
1616
}

packages/less-modules/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"src"
1919
],
2020
"scripts": {
21+
"build": "tsbb build --no-esm",
2122
"watch": "tsbb watch --no-esm"
2223
},
2324
"dependencies": {

packages/less-modules/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const createLessModule = (lessLoaderOptions = {} as LessLoaderOptions) => {
104104
/**
105105
* Use create-react-app to build react libraries. Support for regular less files and *.module.less files.
106106
*/
107-
const module = createLessModule();
108-
(module as any).withLoaderOptions = createLessModule;
107+
const lessmodule = createLessModule();
108+
(lessmodule as any).withLoaderOptions = createLessModule;
109109

110-
export default module;
110+
export default lessmodule;

packages/resolve-fallback/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"assert": "^2.0.0",
2525
"crypto-browserify": "^3.12.0",
26+
"path-browserify": "^1.0.1",
2627
"https-browserify": "^1.0.0",
2728
"os": "^0.1.2",
2829
"os-browserify": "^0.3.0",

0 commit comments

Comments
 (0)