Skip to content

Commit

Permalink
fix: Do not log debug info unless asked to (#2549) (CP: 24.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Jul 1, 2024
1 parent dc99c78 commit 9861082
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 53 deletions.
74 changes: 38 additions & 36 deletions packages/java/tests/spring/react-signals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"dependencies": {
"@polymer/polymer": "3.5.1",
"@vaadin/bundles": "24.4.0",
"@vaadin/bundles": "24.5.0-alpha3",
"@vaadin/common-frontend": "0.0.19",
"@vaadin/hilla-file-router": "file:../../../../ts/file-router",
"@vaadin/hilla-frontend": "file:../../../../ts/frontend",
Expand All @@ -14,22 +14,23 @@
"@vaadin/hilla-react-form": "file:../../../../ts/react-form",
"@vaadin/hilla-react-i18n": "file:../../../../ts/react-i18n",
"@vaadin/hilla-react-signals": "file:../../../../ts/react-signals",
"@vaadin/polymer-legacy-adapter": "24.4.0",
"@vaadin/react-components": "24.4.0",
"@vaadin/react-components-pro": "24.4.0",
"@vaadin/polymer-legacy-adapter": "24.5.0-alpha3",
"@vaadin/react-components": "24.5.0-alpha3",
"@vaadin/react-components-pro": "24.5.0-alpha3",
"@vaadin/router": "1.7.5",
"@vaadin/vaadin-development-mode-detector": "2.0.7",
"@vaadin/vaadin-lumo-styles": "24.4.0",
"@vaadin/vaadin-themable-mixin": "24.4.0",
"@vaadin/vaadin-lumo-styles": "24.5.0-alpha3",
"@vaadin/vaadin-themable-mixin": "24.5.0-alpha3",
"@vaadin/vaadin-usage-statistics": "2.1.2",
"construct-style-sheets-polyfill": "3.1.0",
"lit": "3.1.4",
"react": "18.3.1",
"react-dom": "18.3.1",
"react": "19.0.0-rc-3563387fe3-20240621",
"react-dom": "19.0.0-rc-3563387fe3-20240621",
"react-router-dom": "6.23.1"
},
"devDependencies": {
"@babel/preset-react": "7.24.7",
"@preact/signals-react-transform": "0.3.1",
"@rollup/plugin-replace": "5.0.7",
"@rollup/pluginutils": "5.1.0",
"@types/react": "18.3.3",
Expand All @@ -50,7 +51,7 @@
"rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0",
"transform-ast": "2.4.4",
"typescript": "5.4.5",
"typescript": "5.5.2",
"vite": "5.3.1",
"vite-plugin-checker": "0.6.4",
"workbox-build": "7.1.1",
Expand All @@ -60,60 +61,61 @@
"vaadin": {
"dependencies": {
"@polymer/polymer": "3.5.1",
"@vaadin/bundles": "24.4.0",
"@vaadin/bundles": "24.5.0-alpha3",
"@vaadin/common-frontend": "0.0.19",
"@vaadin/hilla-file-router": "24.4.2",
"@vaadin/hilla-frontend": "24.4.2",
"@vaadin/hilla-lit-form": "24.4.2",
"@vaadin/hilla-react-auth": "24.4.2",
"@vaadin/hilla-react-crud": "24.4.2",
"@vaadin/hilla-react-form": "24.4.2",
"@vaadin/hilla-react-i18n": "24.4.2",
"@vaadin/hilla-react-signals": "24.4.2",
"@vaadin/polymer-legacy-adapter": "24.4.0",
"@vaadin/react-components": "24.4.0",
"@vaadin/react-components-pro": "24.4.0",
"@vaadin/hilla-file-router": "24.5.0-alpha3",
"@vaadin/hilla-frontend": "24.5.0-alpha3",
"@vaadin/hilla-lit-form": "24.5.0-alpha3",
"@vaadin/hilla-react-auth": "24.5.0-alpha3",
"@vaadin/hilla-react-crud": "24.5.0-alpha3",
"@vaadin/hilla-react-form": "24.5.0-alpha3",
"@vaadin/hilla-react-i18n": "24.5.0-alpha3",
"@vaadin/hilla-react-signals": "24.5.0-alpha3",
"@vaadin/polymer-legacy-adapter": "24.5.0-alpha3",
"@vaadin/react-components": "24.5.0-alpha3",
"@vaadin/react-components-pro": "24.5.0-alpha3",
"@vaadin/router": "1.7.5",
"@vaadin/vaadin-development-mode-detector": "2.0.7",
"@vaadin/vaadin-lumo-styles": "24.4.0",
"@vaadin/vaadin-themable-mixin": "24.4.0",
"@vaadin/vaadin-lumo-styles": "24.5.0-alpha3",
"@vaadin/vaadin-themable-mixin": "24.5.0-alpha3",
"@vaadin/vaadin-usage-statistics": "2.1.2",
"construct-style-sheets-polyfill": "3.1.0",
"lit": "3.1.4",
"react": "18.3.1",
"react-dom": "18.3.1",
"react": "19.0.0-rc-3563387fe3-20240621",
"react-dom": "19.0.0-rc-3563387fe3-20240621",
"react-router-dom": "6.23.1"
},
"devDependencies": {
"@babel/preset-react": "7.24.7",
"@preact/signals-react-transform": "0.3.1",
"@rollup/plugin-replace": "5.0.7",
"@rollup/pluginutils": "5.1.0",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@vaadin/hilla-generator-cli": "24.4.2",
"@vaadin/hilla-generator-core": "24.4.2",
"@vaadin/hilla-generator-plugin-backbone": "24.4.2",
"@vaadin/hilla-generator-plugin-barrel": "24.4.2",
"@vaadin/hilla-generator-plugin-client": "24.4.2",
"@vaadin/hilla-generator-plugin-model": "24.4.2",
"@vaadin/hilla-generator-plugin-push": "24.4.2",
"@vaadin/hilla-generator-plugin-subtypes": "24.4.2",
"@vaadin/hilla-generator-utils": "24.4.2",
"@vaadin/hilla-generator-cli": "24.5.0-alpha3",
"@vaadin/hilla-generator-core": "24.5.0-alpha3",
"@vaadin/hilla-generator-plugin-backbone": "24.5.0-alpha3",
"@vaadin/hilla-generator-plugin-barrel": "24.5.0-alpha3",
"@vaadin/hilla-generator-plugin-client": "24.5.0-alpha3",
"@vaadin/hilla-generator-plugin-model": "24.5.0-alpha3",
"@vaadin/hilla-generator-plugin-push": "24.5.0-alpha3",
"@vaadin/hilla-generator-plugin-subtypes": "24.5.0-alpha3",
"@vaadin/hilla-generator-utils": "24.5.0-alpha3",
"@vitejs/plugin-react": "4.3.1",
"async": "3.2.5",
"glob": "10.4.1",
"rollup-plugin-brotli": "3.1.0",
"rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0",
"transform-ast": "2.4.4",
"typescript": "5.4.5",
"typescript": "5.5.2",
"vite": "5.3.1",
"vite-plugin-checker": "0.6.4",
"workbox-build": "7.1.1",
"workbox-core": "7.1.0",
"workbox-precaching": "7.1.0"
},
"hash": "cda08ca64072727bf7a92596f52d244ce396e1b99170d23f098bba7f4408ec67"
"hash": "d5c7ea8c9c6b48097f664cf25230cf6dba2145df813b49b30bbd7caebb82c972"
},
"overrides": {
"@vaadin/common-frontend": "$@vaadin/common-frontend",
Expand Down
20 changes: 14 additions & 6 deletions packages/ts/file-router/src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export type PluginOptions = Readonly<{
* @defaultValue `false`
*/
isDevMode?: boolean;
/**
* The flag to indicate whether to output debug information
*
* @defaultValue `false`
*/
debug?: boolean;

Check warning on line 45 in packages/ts/file-router/src/vite-plugin.ts

View check run for this annotation

Codecov / codecov/patch

packages/ts/file-router/src/vite-plugin.ts#L40-L45

Added lines #L40 - L45 were not covered by tests
}>;

/**
Expand All @@ -50,6 +56,7 @@ export default function vitePluginFileSystemRouter({
generatedDir = 'frontend/generated/',
extensions = ['.tsx', '.jsx'],
isDevMode = false,
debug = false,
}: PluginOptions = {}): Plugin {
let _viewsDir: URL;
let _outDir: URL;
Expand All @@ -66,18 +73,19 @@ export default function vitePluginFileSystemRouter({
_outDir = pathToFileURL(outDir);
_logger = logger;

_logger.info(`The directory of route files: ${String(_viewsDir)}`);
_logger.info(`The directory of generated files: ${String(_generatedDir)}`);
_logger.info(`The output directory: ${String(_outDir)}`);

if (debug) {
_logger.info(`The directory of route files: ${String(_viewsDir)}`);
_logger.info(`The directory of generated files: ${String(_generatedDir)}`);
_logger.info(`The output directory: ${String(_outDir)}`);
}

Check warning on line 80 in packages/ts/file-router/src/vite-plugin.ts

View check run for this annotation

Codecov / codecov/patch

packages/ts/file-router/src/vite-plugin.ts#L76-L80

Added lines #L76 - L80 were not covered by tests
runtimeUrls = {
json: new URL('file-routes.json', isDevMode ? _generatedDir : _outDir),
code: new URL('file-routes.ts', _generatedDir),
};
},
async buildStart() {
try {
await generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger);
await generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger, debug);
} catch (e: unknown) {
_logger.error(String(e));
}
Expand All @@ -93,7 +101,7 @@ export default function vitePluginFileSystemRouter({
return;
}

generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger).catch((e: unknown) =>
generateRuntimeFiles(_viewsDir, runtimeUrls, extensions, _logger, debug).catch((e: unknown) =>
_logger.error(String(e)),
);
};
Expand Down
22 changes: 15 additions & 7 deletions packages/ts/file-router/src/vite-plugin/generateRuntimeFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,32 @@ async function generateRuntimeFile(url: URL, data: string): Promise<void> {
* @param urls - The URLs of the files to generate.
* @param extensions - The list of extensions that will be collected as routes.
* @param logger - The Vite logger instance.
* @param debug - true to debug
*/
export async function generateRuntimeFiles(
viewsDir: URL,
urls: RuntimeFileUrls,
extensions: readonly string[],
logger: Logger,
debug: boolean,
): Promise<void> {
const routeMeta = existsSync(viewsDir) ? await collectRoutesFromFS(viewsDir, { extensions, logger }) : [];
logger.info('Collected file-based routes');
if (debug) {
logger.info('Collected file-based routes');
}
const runtimeRoutesCode = createRoutesFromMeta(routeMeta, urls);
const viewConfigJson = await createViewConfigJson(routeMeta);

await Promise.all([
generateRuntimeFile(urls.json, viewConfigJson).then(() =>
logger.info(`Frontend route list is generated: ${String(urls.json)}`),
),
generateRuntimeFile(urls.code, runtimeRoutesCode).then(() =>
logger.info(`File Route module is generated: ${String(urls.code)}`),
),
generateRuntimeFile(urls.json, viewConfigJson).then(() => {
if (debug) {
logger.info(`Frontend route list is generated: ${String(urls.json)}`);
}
}),
generateRuntimeFile(urls.code, runtimeRoutesCode).then(() => {
if (debug) {
logger.info(`File Route module is generated: ${String(urls.code)}`);
}
}),
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('@vaadin/hilla-file-router', () => {
});

it('should generate the runtime files', async () => {
await generateRuntimeFiles(viewsDir, runtimeUrls, ['.tsx', '.jsx'], logger);
await generateRuntimeFiles(viewsDir, runtimeUrls, ['.tsx', '.jsx'], logger, true);
expect(existsSync(runtimeUrls.json)).to.be.true;
expect(existsSync(runtimeUrls.code)).to.be.true;
const listener = () => {
Expand All @@ -45,7 +45,7 @@ describe('@vaadin/hilla-file-router', () => {
const json = watch(runtimeUrls.json, listener);
const code = watch(runtimeUrls.code, listener);

await generateRuntimeFiles(viewsDir, runtimeUrls, ['.tsx', '.jsx'], logger);
await generateRuntimeFiles(viewsDir, runtimeUrls, ['.tsx', '.jsx'], logger, true);
await new Promise((resolve) => {
// Wait some time to ensure that the file is not changed
setTimeout(resolve, 100);
Expand All @@ -56,7 +56,7 @@ describe('@vaadin/hilla-file-router', () => {

it('should not throw if views does not exist', async () => {
rmSync(viewsDir, { force: true, recursive: true });
await generateRuntimeFiles(viewsDir, runtimeUrls, ['.tsx', '.jsx'], logger);
await generateRuntimeFiles(viewsDir, runtimeUrls, ['.tsx', '.jsx'], logger, true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('@vaadin/hilla-file-router', () => {
},
watcher,
};
const plugin = vitePluginFileSystemRouter({ isDevMode: true });
const plugin = vitePluginFileSystemRouter({ isDevMode: true, debug: true });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error: the configResolved method could be either a function or an object.
plugin.configResolved({
Expand Down

0 comments on commit 9861082

Please sign in to comment.