Conversation
… fix Astro type usage (b/567662586)
There was a problem hiding this comment.
Code Review
This pull request upgrades the astro dependency to version 7.3.5 and refactors the configuration loading in src/frameworks/astro/utils.ts to use a local LegacyAstroConfigModule interface. Feedback on the changes points out a violation of the repository style guide regarding the use of any and unknown types, suggesting a more robust type definition for the Astro configuration and logging parameters.
| interface LegacyAstroConfigModule { | ||
| openConfig: (options: { | ||
| cmd: string; | ||
| cwd: string; | ||
| logging: unknown; | ||
| }) => Promise<{ astroConfig: any }>; | ||
| } | ||
| const { openConfig }: LegacyAstroConfigModule = await dynamicImport(configPath); | ||
| const logging: unknown = undefined; | ||
| const { astroConfig } = await openConfig({ cmd: "build", cwd, logging }); | ||
| config = astroConfig; |
There was a problem hiding this comment.
According to the repository style guide (GEMINI.md, line 37), we should never use any or unknown as an escape hatch. Instead, we should define proper interfaces/types.
We can define a proper LegacyAstroConfig interface representing the expected shape of the Astro configuration object, and type logging as undefined since it is not used here.
interface LegacyAstroConfig {
outDir: string | URL;
publicDir: string | URL;
output: string;
adapter?: { name: string };
}
interface LegacyAstroConfigModule {
openConfig: (options: {
cmd: string;
cwd: string;
logging?: undefined;
}) => Promise<{ astroConfig: LegacyAstroConfig }>;
}
const { openConfig }: LegacyAstroConfigModule = await dynamicImport(configPath);
const logging = undefined;
const { astroConfig } = await openConfig({ cmd:
Resolves Buganizer b/567662586
Proposed Improvement
Upgraded the
astrodevDependency from^2.2.3to^7.3.5and regeneratednpm-shrinkwrap.jsonusingnpm@11.9.Key changes:
package.json, bumpedastroto^7.3.5.src/frameworks/astro/utils.ts, replaced thetypeof import("astro/dist/core/config/config")type annotation for legacyopenConfigwith an explicit localLegacyAstroConfigModuleinterface. Astro 7 no longer exportsopenConfig, but runtime user projects on older Astro versions (<2.9.7) still dynamically import it when detected. The local interface maintains complete backward compatibility for those user projects without causing TypeScript compilation errors against Astro 7.npm-shrinkwrap.jsonwithnpx -y npm@11.9 install --package-lock-only --ignore-scripts.astro,@astrojs/markdown-remark,devalue,deepmerge-ts,cookie, and the nested legacyundicicopies in@astrojs/telemetryand@astrojs/webapi).Verification
npm run build: Passed cleanly.npm run lint:quiet: Passed with 0 errors.npm run test:compile: Passed with 0 errors.npx mocha 'src/frameworks/astro/**/*.spec.ts': All 9 tests passing.npm audit: Verified that vulnerabilities fromastro,devalue,deepmerge-ts,@astrojs/*, andcookieare resolved.