refactor: enable strict TypeScript options

This commit is contained in:
Simon Chan 2022-02-02 19:14:51 +08:00
parent 594648d033
commit 55cd69d47b
15 changed files with 82 additions and 104 deletions

View file

@ -8,35 +8,12 @@ const temp = path.resolve(__dirname, '..', 'temp', process.pid.toString());
fs.mkdirSync(temp, { recursive: true });
if (process.argv[2] !== '--incremental') {
fs.rmSync(path.resolve(cwd, 'cjs'), { force: true, recursive: true });
fs.rmSync(path.resolve(cwd, 'esm'), { force: true, recursive: true });
fs.rmSync(path.resolve(cwd, 'dts'), { force: true, recursive: true });
}
const tsconfigPath = path.resolve(cwd, 'tsconfig.json');
const tsconfigValue = JSON5.parse(fs.readFileSync(tsconfigPath), 'utf8');
// const cjsTsconfigPath = path.resolve(temp, 'tsconfig.cjs.json');
// const cjsTsconfigValue = {
// ...tsconfigValue,
// extends: tsconfigPath,
// compilerOptions: {
// composite: false,
// outDir: path.resolve(cwd, 'cjs'),
// module: 'CommonJS',
// declaration: false,
// declarationDir: null,
// declarationMap: false,
// typeRoots: [
// ...(tsconfigValue.compilerOptions?.typeRoots || []),
// path.resolve(cwd, 'node_modules', '@types'),
// path.resolve(__dirname, '..', 'node_modules', '@types'),
// ],
// },
// references: [],
// };
// fs.writeFileSync(cjsTsconfigPath, JSON.stringify(cjsTsconfigValue, undefined, 4));
const esmTsconfigPath = path.resolve(temp, 'tsconfig.esm.json');
const testTypes = tsconfigValue.testTypes || ['jest'];
const esmTsconfigValue = {
@ -64,7 +41,6 @@ fs.writeFileSync(esmTsconfigPath, JSON.stringify(esmTsconfigValue, undefined, 4)
const tsc = path.resolve(cwd, 'node_modules', '.bin', 'tsc');
const tscResult = childProcess.spawnSync(tsc, [
'--build',
// cjsTsconfigPath,
esmTsconfigPath,
], {
cwd,

View file

@ -8,10 +8,10 @@
"ESNext"
],
"rootDir": "../../../src",
"outDir": "../../../cjs",
"outDir": "../../../esm",
"sourceMap": true,
"declaration": true,
"declarationDir": "../../../dts",
"declarationDir": "../../../esm",
"declarationMap": true,
"stripInternal": true,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
@ -23,12 +23,17 @@
/* Strict Type-Checking Options */
"strict": true, // /* Enable all strict type-checking options. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedLocals": true, // /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitOverride": true,
"noImplicitReturns": true, // /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, // /* Report errors for fallthrough cases in switch statement. */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"exactOptionalPropertyTypes": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
/* Module Resolution Options */
"moduleResolution": "node", // /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */