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

13658 Vue cli to Vite migration #556

Merged

Conversation

JazzarKarim
Copy link
Collaborator

@JazzarKarim JazzarKarim commented Jul 17, 2023

Issue #: /bcgov/entity#17118

Description of changes:

  • Vue CLI to Vite migration

Please see bcgov/entity#13658 (comment) and the comments below for all the details.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the bcrs-entities-create-ui license (Apache 2.0).

@JazzarKarim JazzarKarim changed the title Vue cli to Vite migration (incomplete) Vue cli to Vite migration Aug 1, 2023
@bcgov bcgov deleted a comment from pwei1018 Aug 1, 2023
@bcgov bcgov deleted a comment from pwei1018 Aug 1, 2023
@bcgov bcgov deleted a comment from pwei1018 Aug 1, 2023
@bcgov bcgov deleted a comment from pwei1018 Aug 1, 2023
package.json Outdated
},
"dependencies": {
"@babel/compat-data": "^7.21.5",
"@bcrs-shared-components/approval-type": "1.0.19",
"@bcrs-shared-components/base-address": "2.0.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BaseAddress was previously being used from "sbc-common-components". Now, the component is imported from the "bcrs-shared-components" repo. I've updated all the corresponding imports accordingly too in the code.

Copy link
Collaborator

@seeker25 seeker25 Aug 1, 2023

Choose a reason for hiding this comment

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

Thank you for this, please take it for a spin as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

I know there was a (test?) issue with using the shared BaseAddress component and Karim reverted that change, so it's now out of scope for this PR.

However, Travis, did you manage to use the shared BasedAddress component in an app? And unit test it? Or is there maybe something still wrong/needed with it?

package.json Outdated
"@bcrs-shared-components/breadcrumb": "2.1.15",
"@bcrs-shared-components/business-lookup": "1.1.17",
"@bcrs-shared-components/business-lookup": "1.1.29",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated this component as there's work there to fix an error corresponding to lodash.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice to get rid of lodash eventually

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could write the debounce function ourselves... in the future.

Please test that business-lookup works correctly, since it's been changed a bit since it was last used/tested here. Thx.

Copy link
Collaborator Author

@JazzarKarim JazzarKarim Aug 2, 2023

Choose a reason for hiding this comment

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

BusinessLookup isn't working correctly. I don't think it has anything to do with Vite. Maybe recent changes in the shared repo broke it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not getting any results back:
no results

Copy link
Collaborator

Choose a reason for hiding this comment

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

The new keys have a typo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still not working in the temporary URL. Let's leave it for now and I'll check if it's working when I deploy the branch to DEV. Is that fine?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The API key in the API call request headers is still empty.

Yes, leave it for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it still planned to temporary deploy this to Dev and test it there?

Copy link
Collaborator Author

@JazzarKarim JazzarKarim Aug 3, 2023

Choose a reason for hiding this comment

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

Yes Sev. Currently, I see the Content Security Policy error. It's this and the address complete (they both work fine in local).

"vuetify": "^2.6.15",
"vuex": "^3.6.2"
},
"devDependencies": {
"@originjs/vite-plugin-require-context": "1.0.9",
Copy link
Collaborator Author

@JazzarKarim JazzarKarim Aug 1, 2023

Choose a reason for hiding this comment

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

There is require.context in CompleteResolution.vue. This plugin is to fix that (enables require.context with Vite).

}

window.pdfjsWorker = pdfjsWorker
pdfjs.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've spent hours on trying to get the pdfjs library to work with Vite. This is literally the only way that I got it to work. Unit tests pass.

Here's a link if you want to try it: https://business-create-dev--pr-556-nilgmamu.web.app/incorporation-memorandum?id=TA7zV53Hu5

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The second link is exactly what I used to get it to work 😆

Copy link
Collaborator

@seeker25 seeker25 Aug 2, 2023

Choose a reason for hiding this comment

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

Rofl sorry HAHA i just looked and saw. I think there's a way we could include the library in our build package and refer to that instead of CDN.

Copy link
Collaborator

@seeker25 seeker25 Aug 2, 2023

Choose a reason for hiding this comment

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

  const pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry');

  pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

Maybe possible to download the CDN and include it that way? Haven't tried, relying on CDN sucks

https://stackoverflow.com/questions/73979621/how-do-i-use-pdfjs-with-vue3-and-vite

Copy link
Collaborator Author

@JazzarKarim JazzarKarim Aug 2, 2023

Choose a reason for hiding this comment

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

Travis, you're incredible. Something of the sorts works. Now, I don't have to add the pdfjs library to the CSP anymore which is what I would've preferred! Thank you so much Travis!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Travis, please check latest commit. I managed to get pdfjs to work without CDN and with the unit tests to run also.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we do need an external JS library (at runtime) then I recommend we cache it locally (as we've done with address-complete). No CDN.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. Makes sense.

@@ -15,15 +15,14 @@ import { CorpTypeCd, FilingTypes } from '@/enums'
import { CourtOrderStepIF, DefineCompanyIF, EffectiveDateTimeIF, IncorporationAgreementIF, NameRequestIF,
OrgPersonIF, PeopleAndRoleIF, ShareStructureIF, TombstoneIF } from '@/interfaces'
import { ShareClassIF } from '@bcrs-shared-components/interfaces'

Vue.use(Vuetify)
import { vi } from 'vitest'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Jest is replaced by vi in Vite. The methods work similar and have similar names as below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I've actually haven't stumbled upon the vitest.

I've seen that vi is the one that's being widely used: https://vitest.dev/api/vi.html

I'm guessing they're the same.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, I have no further comments on this.

export default defineConfig(() => {
return {
define: {
'import.meta.env.ABOUT_TEXT':
Copy link
Collaborator Author

@JazzarKarim JazzarKarim Aug 1, 2023

Choose a reason for hiding this comment

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

This was in vue.config.js. It is now here and instead of importing it using process.env.ABOUT_TEXT, we use now import.meta.env.ABOUT_TEXT.

: aboutText2 ? `"${aboutText2}"`
: ''
},
envPrefix: 'VUE_APP_', // Need to remove this after fixing vaults. Use import.meta.env with VUE_APP.
Copy link
Collaborator Author

@JazzarKarim JazzarKarim Aug 1, 2023

Choose a reason for hiding this comment

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

Usually, if you want to import.meta.env, the environment variables must be prefixed with VITE_. This overrides that and makes import.meta.env work with VUE_APP_ as before.

The reason why I didn't rename environment variables to have a prefix of VITE_ is because of the ops code in one of the directories. That's how we usually populate our environment variables like the Genesys web message for example (from 1Password).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you try renaming the env variables in vaults.env? If that didn't work then we'll need @pwei1018 to help with this (when he returns from vacation).

Copy link
Collaborator Author

@JazzarKarim JazzarKarim Aug 2, 2023

Choose a reason for hiding this comment

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

Sev, can I please see what the variables look like in 1Password? You showed me the vaults once but I can't remember. Did they have the keys prefixed with VUE_APP?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The variables in 1Password do not start with VUE_APP. That's a local renaming of the env keys. The variables in 1P are the last token on each line:

image

Eg, AUTH_API_URL

Copy link
Collaborator

@severinbeauvais severinbeauvais Aug 2, 2023

Choose a reason for hiding this comment

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

I don't know if you can simply rename the env keys. I'm guessing there's a GCP step that uses vaults.env to look up the keys, assigns them to env keys, and then bakes them into the app js bundle.

I think that .env is our local way of having the keys without going through GCP.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sev, I've tried to change the environment variables prefix to VITE_ and test in the temporary URL. It doesn't work 😟

Check this link: https://business-create-dev--pr-556-nilgmamu.web.app/registration-define-business?id=T9SwNW7ISG

The web messaging doesn't appear. Looks like the environment variable wasn't populated. I'm guessing there is some configuration needed to be done like you mentioned. I'll be reverting this change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And I guess you're not merging this until we figure it out. @seeker25 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it should be fine for the time being Sev. When I have VUE_APP as the prefix, all environment variables get populated correctly. I can see the web messaging etc..

It's just the address complete variable that's not getting populated. Also, I'm merging now not to main, but to a new branch 17118-vite-test-branch

Please let me know if that's OK with you Sev.

Copy link
Collaborator

@severinbeauvais severinbeauvais Aug 2, 2023

Choose a reason for hiding this comment

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

Right, you have that config to override the prefix.

Ok to try merging to a branch and deploying it to Dev! Maybe post a message to let other devs know.

@@ -17,6 +17,6 @@
</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script type="module" src="/src/main.ts"></script>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In Vite, the index.html is moved to the root directory and is changed accordingly. No more <%= BASE_URL %>.

"@bcrs-shared-components/limited-restoration-panel": "1.0.5",
"@bcrs-shared-components/mixins": "1.1.10",
"@bcrs-shared-components/mixins": "1.1.20",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've also updated a bunch of the useful packages as above like the enums, interfaces, and mixins.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, those are generally safe to update since we usually only add things to them.

@JazzarKarim
Copy link
Collaborator Author

/gcbrun

@pwei1018
Copy link
Collaborator

pwei1018 commented Aug 2, 2023

Temporary Url for review: https://business-create-dev--pr-556-nilgmamu.web.app

@JazzarKarim
Copy link
Collaborator Author

JazzarKarim commented Aug 2, 2023

@severinbeauvais 3 tests (lines) that I can't seem to fix:

  • App.spec.ts at line 1094 (currently commented out)
  • Actions.spec.ts at line 522 (currently commented out)
  • CompleteResolution.spec.ts at line 8 (currently commented out)

Shall I spend more time on trying to fix them? Please Sev I'd like your advice and thank you!

@severinbeauvais
Copy link
Collaborator

@severinbeauvais 3 tests (lines) that I can't seem to fix:

  • App.spec.ts at line 1094 (currently commented out)

The test is looking for the SbcFeeSummary but not finding it. Does the actual code display it in locally or temp URL?

  • Actions.spec.ts at line 522 (currently commented out)

It's odd that mockUpdateFiling was called but hasn't returned. Since the mock returns a promise, does the mock have to be awaited (not in the test but in the code)?

  • CompleteResolution.spec.ts at line 8 (currently commented out)

Any idea why CP voluntary dissolution fails? Due to PDF stuff maybe?

Shall I spend more time on trying to fix them? Please Sev I'd like your advice and thank you!

Let me have a look at these. Make sure you have tested as many flows as possible through Create UI (maybe keep a list of them for Riyaz to see). And then let's get this PR merged asap.

@ketaki-deodhar @leodube-aot Please make time asap to go over this so you are aware of the changes (and in case one of you makes the same changes to Filings UI or Edit UI). Thanks.

@severinbeauvais
Copy link
Collaborator

severinbeauvais commented Aug 3, 2023

At least one of the unit test issues is because isJestRunning is false in Vitest.

I think you can change the computed to:

get isVitestRunning (): boolean {
  return !!import.meta.env.VITEST
}

A better option would be to mock the feature flags so that we don't use this check in production code, but we can do that in a future ticket (out of scope for now).

@JazzarKarim
Copy link
Collaborator Author

@severinbeauvais Sev, I'm taking a look and going through the code based off your last two comments. Thank you so much.

I'm looking into them right now.

@JazzarKarim
Copy link
Collaborator Author

JazzarKarim commented Aug 3, 2023

All unit tests have been fixed now.

@JazzarKarim
Copy link
Collaborator Author

/gcbrun

@pwei1018
Copy link
Collaborator

pwei1018 commented Aug 3, 2023

Temporary Url for review: https://business-create-dev--pr-556-nilgmamu.web.app

@JazzarKarim JazzarKarim changed the base branch from main to 17118-vite-test-branch August 3, 2023 19:49
src/main.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@severinbeauvais severinbeauvais left a comment

Choose a reason for hiding this comment

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

Amazing work, Karim! This was a hard one, lots of researching and testing needed.

I know it's not over because we're going to test this change in Dev, but that can be a future PR if needed.

Copy link
Collaborator

@leodube-aot leodube-aot left a comment

Choose a reason for hiding this comment

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

Great job Karim!

Copy link
Collaborator

@ketaki-deodhar ketaki-deodhar left a comment

Choose a reason for hiding this comment

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

Awesome job Karim! Lots of learning here

@JazzarKarim JazzarKarim merged commit d8005dd into bcgov:17118-vite-test-branch Aug 3, 2023
4 checks passed
severinbeauvais added a commit that referenced this pull request Aug 4, 2023
* Vue cli to Vite migration (incomplete)

* Migrated Vue CLI to Vite + all necessary changes

* fix AddressComplete not initialized due to missing script and/or key

* another try to fix addresscomplete

* another try to fix addresscomplete

* testing addresscomplete

* another test for addresscomplete

* revert addresscomplete change

* removed useless dependency

* added blob to content security policy

* changed CSP

* Another attempt to fix CSP

* Fixed pdfjs library + unit tests + removed pdfjs script

* small removals of useless stuff

* updated pdfjs library

* attempting with jsdom

* going back to happy-dom after fixing tests with threads

* Fixed icon + small cleanup in response to comments

* Trying out VITE_ prefix

* Reverting VITE_ to VUE_APP_

* restoring regenerator-runtime dependency

* Removed services package and returned core-js package

* fixed environment prefix issue

* updated business lookup

* added missing keys

* Fixed typo

* Fixed occasional issue arising from baseaddress after changing the import to shared components

* Fixed App and CompleteResolution unit tests

* Fixed some comments after moving from Jest to Vitest

* More jest to vitest fixes

* Fixed Actions unit test + little cleanup

* Changed VITEST_WORKER_ID to VITEST

Co-authored-by: JazzarKarim <122301442+JazzarKarim@users.noreply.github.com>
@severinbeauvais severinbeauvais changed the title Vue cli to Vite migration 13658 Vue cli to Vite migration Aug 4, 2023
@severinbeauvais
Copy link
Collaborator

Yesterday, we merged this PR into a feature branch in bcgov with the intent to temporarily deploy the branch to Dev to test the environment keys. However, the CD action failed (skipped) because the feature branch did not follow the correct naming convention.

So we renamed the feature branch... but the CD action still failed.

So I created another feature branch (correctly named)... but the CD action still failed.

I renamed the original feature branch to its original name (to avoid confusion). The new feature branch is named "feature-vite-test-branch-2".

@pwei1018 Can we get your help on this, please?

JazzarKarim added a commit that referenced this pull request Aug 8, 2023
* Vue cli to Vite migration (incomplete)

* Migrated Vue CLI to Vite + all necessary changes

* fix AddressComplete not initialized due to missing script and/or key

* another try to fix addresscomplete

* another try to fix addresscomplete

* testing addresscomplete

* another test for addresscomplete

* revert addresscomplete change

* removed useless dependency

* added blob to content security policy

* changed CSP

* Another attempt to fix CSP

* Fixed pdfjs library + unit tests + removed pdfjs script

* small removals of useless stuff

* updated pdfjs library

* attempting with jsdom

* going back to happy-dom after fixing tests with threads

* Fixed icon + small cleanup in response to comments

* Trying out VITE_ prefix

* Reverting VITE_ to VUE_APP_

* restoring regenerator-runtime dependency

* Removed services package and returned core-js package

* fixed environment prefix issue

* updated business lookup

* added missing keys

* Fixed typo

* Fixed occasional issue arising from baseaddress after changing the import to shared components

* Fixed App and CompleteResolution unit tests

* Fixed some comments after moving from Jest to Vitest

* More jest to vitest fixes

* Fixed Actions unit test + little cleanup

* Changed VITEST_WORKER_ID to VITEST
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.

6 participants