Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix undefined process in package #1997

Merged
merged 1 commit into from
Mar 7, 2025
Merged

Conversation

artemmufazalov
Copy link
Member

@artemmufazalov artemmufazalov commented Mar 6, 2025

When ydb-embedded-ui is used as package, there is an error, that process is not defined. That's why I import package json directly

CI Results

Test Status: ⚠️ FLAKY

📊 Full Report

Total Passed Failed Flaky Skipped
264 261 0 2 1
Test Changes Summary ⏭️1

⏭️ Skipped Tests (1)

  1. Streaming query shows some results and banner when stop button is clicked (tenant/queryEditor/queryEditor.test.ts)

Bundle Size: ✅

Current: 80.81 MB | Main: 80.81 MB
Diff: 0.15 KB (-0.00%)

✅ Bundle size unchanged.

ℹ️ CI Information
  • Test recordings for failed tests are available in the full report.
  • Bundle size is measured for the entire 'dist' directory.
  • 📊 indicates links to detailed reports.
  • 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.

@@ -164,8 +164,7 @@
"source-map-explorer": "^2.5.3",
"stylelint": "^15.11.0",
"ts-jest": "^29.2.5",
"typescript": "^5.7.3",
"webpack": "^5.98.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to install it explicitly

@artemmufazalov artemmufazalov force-pushed the fix-undefined-process branch from ad5f2e1 to 602fd97 Compare March 6, 2025 11:41
@artemmufazalov artemmufazalov marked this pull request as ready for review March 6, 2025 12:39
@artemmufazalov artemmufazalov requested a review from sareyu March 6, 2025 12:40
@@ -141,7 +143,7 @@ export const autocompleteOnEnterSetting: SettingProps = {
export const interfaceVersionInfoField: SettingsInfoFieldProps = {
title: i18n('settings.about.interfaceVersionInfoField.title'),
type: 'info',
content: process.env.UI_VERSION,
content: packageJson.version,
Copy link
Collaborator

@astandrik astandrik Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried sth like window.ui_version? the same way it is used for react_app_disable_checks

Still feel that using package.json directly may have pitfalls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried index.html, the problem is that webpack.DefinePlugin does not expose vars to html files, so we can use them in js, but not in index.html (but all envs passed in command or taken from .env file work fine).

// Add DefinePlugin to expose just the version
config.plugins.push(
new webpack.DefinePlugin({
'process.env.UI_VERSION': JSON.stringify(packageJson.version),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's wrong with this approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env values are embedded in build, so in build I have
version: process.env.UI_VERSION -> version: 8.11.0

However, when we use it as a package, we have only process.env.UI_VERSION in our code, when we import it and try to open in UI we receive process is not defined error, no variables are exposed

Copy link
Collaborator

@sareyu sareyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@astandrik
Copy link
Collaborator

astandrik commented Mar 7, 2025

Could you try this approach?

https://github.com/ydb-platform/ydb-embedded-ui/pull/2005/files

@artemmufazalov
Copy link
Member Author

Could you try this approach?

https://github.com/ydb-platform/ydb-embedded-ui/pull/2005/files

Please, describe, how it should work in case of package? There is no vars from webpack.DefinePlugin there

@astandrik
Copy link
Collaborator

Could you try this approach?
https://github.com/ydb-platform/ydb-embedded-ui/pull/2005/files

Please, describe, how it should work in case of package? There is no vars from webpack.DefinePlugin there

You right - it wont work for package

Maybe

import {version} from './package.json';

would work?

Here is some discussion on this topic https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-the-version-from-the-package-json-file-in-node-js-code

The idea of exposing entire package.json intuitively feels unsecure

However, our code is open-source and package.json is already visible in github to everyone - so its not a problem

Could we give it the last try with import {version} from './package.json'; and if it wont work - proceed with requiring the whole package.json

@artemmufazalov
Copy link
Member Author

Could we give it the last try with import {version} from './package.json'; and if it wont work - proceed with requiring the whole package.json

There is another error
Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon)

@artemmufazalov
Copy link
Member Author

Could we give it the last try with import {version} from './package.json'; and if it wont work - proceed with requiring the whole package.json

There is another error Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon)

Actually, it works, but the error is displayed

Screenshot 2025-03-07 at 12 24 27 Screenshot 2025-03-07 at 12 23 42

Copy link
Collaborator

@astandrik astandrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at least we tried :_)

@artemmufazalov artemmufazalov added this pull request to the merge queue Mar 7, 2025
Merged via the queue into main with commit 0b6b99d Mar 7, 2025
8 checks passed
@artemmufazalov artemmufazalov deleted the fix-undefined-process branch March 7, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants