korbit-ai[bot] commented on code in PR #32261: URL: https://github.com/apache/superset/pull/32261#discussion_r1959327831
########## scripts/check-type.js: ########## @@ -0,0 +1,242 @@ +#!/usr/bin/env node + +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// @ts-check +const { exit } = require("node:process"); +const { join, dirname, normalize, sep } = require("node:path"); +const { readdir, stat } = require("node:fs/promises"); +const { existsSync } = require("node:fs"); +const { chdir, cwd } = require("node:process"); +const { createRequire } = require("node:module"); + +const SUPERSET_ROOT = dirname(__dirname); +const PACKAGE_ARG_REGEX = /^package=/; +const EXCLUDE_DECLARATION_DIR_REGEX = /^excludeDeclarationDir=/; +const DECLARATION_FILE_REGEX = /\.d\.ts$/; + +void (async () => { + const args = process.argv.slice(2); + const { + matchedArgs: [packageArg, excludeDeclarationDirArg], + remainingArgs, + } = extractArgs(args, [PACKAGE_ARG_REGEX, EXCLUDE_DECLARATION_DIR_REGEX]); + + if (!packageArg) { + console.error("package is not specified"); + exit(1); + } + + const packageRootDir = await getPackage(packageArg); + const updatedArgs = removePackageSegment(remainingArgs, packageRootDir); + const argsStr = updatedArgs.join(" "); + + const excludedDeclarationDirs = getExcludedDeclarationDirs( + excludeDeclarationDirArg + ); + let declarationFiles = await getFilesRecursively( + packageRootDir, + DECLARATION_FILE_REGEX, + excludedDeclarationDirs + ); + declarationFiles = removePackageSegment(declarationFiles, packageRootDir); + const declarationFilesStr = declarationFiles.join(" "); + + const packageRootDirAbsolute = join(SUPERSET_ROOT, packageRootDir); + const tsConfig = getTsConfig(packageRootDirAbsolute); + const command = `--noEmit --allowJs --composite false --project ${tsConfig} ${argsStr} ${declarationFilesStr}`; + + try { + chdir(packageRootDirAbsolute); + // Please ensure that tscw-config is installed in the package being type-checked. + const tscw = packageRequire("tscw-config"); + const child = await tscw`${command}`; + + if (child.stdout) { + console.log(child.stdout); + } + + if (child.stderr) { + console.error(child.stderr); + } + + exit(child.exitCode); + } catch (e) { + console.error("Failed to execute type checking:", e); + console.error("Package:", packageRootDir); + console.error("Command:", `tscw ${command}`); + exit(1); + } +})(); + +/** + * @param {string} dir + * @param {RegExp} regex + * @param {string[]} excludedDirs + * + * @returns {Promise<string[]>} + */ + +async function getFilesRecursively(dir, regex, excludedDirs) { + try { + const files = await readdir(dir, { withFileTypes: true }); + const recursivePromises = []; + const result = []; + + for (const file of files) { + const fullPath = join(dir, file.name); + const shouldExclude = excludedDirs.includes(file.name); Review Comment: ### Incorrect Directory Exclusion Logic <sub></sub> <details> <summary>Tell me more</summary> ###### What is the issue? The directory exclusion logic only checks the directory name, not the full path, which could accidentally exclude directories that happen to have the same name but are in different paths. ###### Why this matters This could lead to skipping type-checking of TypeScript declaration files in valid directories that shouldn't be excluded, potentially missing type errors. ###### Suggested change ∙ *Feature Preview* Modify the exclusion check to compare full paths instead of just directory names: ```javascript const shouldExclude = excludedDirs.some(excludedDir => normalize(fullPath).includes(normalize(excludedDir)) ); ``` </details> <sub> [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c1754f35-a74d-4618-b37d-5f731c3a7cb2?suggestedFixEnabled=true) 💬 Chat with Korbit by mentioning @korbit-ai. </sub> <!--- korbi internal id:28dc373b-9337-44ea-9ca9-3cc620f4696e --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
