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

Remove Hoisting #52

Merged
merged 24 commits into from
Apr 7, 2020
Merged

Remove Hoisting #52

merged 24 commits into from
Apr 7, 2020

Conversation

FrankEssenberger
Copy link
Contributor

@FrankEssenberger FrankEssenberger commented Mar 20, 2020

Context

The hoisting from lerna caused problems with changes done to the package-lock.json. In this PR I tried to remove the hoisting. Besides a few minor things (jest needs a tsconfig and noch is not multi module enabled) it work quiete well.

I also needed to adjust some dependencies. I also "fixed" the minimist audit error. I added the minmist in version 1.2.5 to the root dependencies and removed adjusted the package-lock.json by removing the minimist in the optmist dependecy used by handlebar. This removed the audit error. Run npm audit with or without the entry to reproduce the issue.

Today a fix was merged: handlebars-lang/handlebars.js#1658
So we should check if this hack is still necessary once this gets published. For doing it one has to remove minimist and rerun npm i to regenerate the package lock.

General:

  • In the investigation I found that yarn provides more tools for fixing such issues. Especially if we can get rid of lerne by using it.
  • I am not sure about the package-lock.json on the module level. These were generated but do we need them? I simply do not know lerna well enough.

Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

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

I have a few questions in the comments. Also, do we need the package-lock files for sub packages?

package.json Outdated
@@ -21,16 +21,14 @@
"lint": "npx eslint --ext .ts .",
"lint:fix": "npm run lint -- --fix",
"lint:fix-cached": "npm run lint:fix -- --cache",
"postinstall": "npx lerna bootstrap --hoist --force-local --strict",
"postinstall": "npx lerna bootstrap --strict",
Copy link
Contributor

Choose a reason for hiding this comment

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

There is one space too much ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Was --force-local causing issues too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no put it back

accessToken: string,
uri: string = destinationServiceUri
) {
return abc(uri, {
Copy link
Contributor

Choose a reason for hiding this comment

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

abc is not the best of names. What is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was a temp name renamed after the draft stage was left.

mockInstanceDestinationsCall([], 200, providerServiceToken),
mockSubaccountDestinationsCall([], 200, providerServiceToken),
mockSingleDestinationCall(oauthSingleResponse, 200, destinationName, userApprovedSubscriberServiceToken)
mockInstanceDestinationsCall(nock, [], 200, subscriberServiceToken),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this change necessary. It seems to me like a sensible default...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the nock is imported from various node modules it is failing when used from different modules. There is something static involved. That is why I pass the nock imported in this test to the method located in a different one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh. Can you share more details here? Is that related to a version upgrade? I never noticed this problem before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it is not related to an update. It is related to the previous hoisting. Situation before:
root

|---node_modules
|      |---nock
|---package_1
      |---node_modules
            |---ref_to_nock_root
|---package_2
      |---node_modules
            |---ref_to_nock_root

So when you did a require(nock) in package_1 or package_2 it was taking the same sources. Withtout the hoisting this has changed to:
root

|---package_1
      |---node_modules
            |---nock
|---package_2
      |---node_modules
            |---nock

So when you do a require(nock) in package_1 for example in the destination-service-mocks.ts of core/test-util and then in the request-builder.spec.ts of the test-packages/integration-tests you load different source files. In principle this should not make a difference, but I found that there must be some encapsulation involved which breaks the matching on the first loaded nock. In other words the method nock.activeMocks() in package_1 do not show active mocks created by the second required nock in the package_2 and when calls are executed the mocks are not triggered.

Thats is why I pass the reference to the imported nock to the methods in the other packages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, that's evil... With that context this change makes a lot more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

But couldn't that be solved by only having nock on the root level? According to (my understanding of) the node resolution algorithm, the root level node_module would be used and it would always be the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

technically yes, but I'm not a fan. You're essentially coupling the package to the project root. I am afraid that this a decision that has consequences that are not immediately obvious. Also it's something that you need to know when working with the project. If someone who's new to the project tries to run tests, then gets an error at runtime because nock isn't found, then looks at the package json and sees that nock isn't even listed as dependency and then adds it, I wouldn't blame them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already discussed with Marika on this topic and I have no strong opinions. In principle it would be strict to have only linting etc. things on root and all package related stuff on the sub-packages. However this is also kind of inconvinient because something is needed everywhere so why putting it N times?

My real Problem overall is: It should be consistent. Either put everything on root, or only the minimal stuff. Which one we chose I do not really care.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am in favor of putting it in the root except for dependencies that are run from the command line (there it has to be in the same context). I think dragging the dependency through the tests is worse than someone running npm install in a subpackage only. That can be covered by documentation and reviews.
I am also ok with doing this one we move to yarn.

"@types/jest": "^25.1.4",
"jsonwebtoken": "^8.5.1",
"bignumber.js": "8.1.1",
"nock": "^12.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really necessary? As far as I understand if this is available on root level we don't need to add it to the packages, except for executables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to remove it and got compilation errors.

@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? Or is it just a left-over from trying things out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is necessary. It turns out that ts-jest needs a tsconfig.json implcitly.

@@ -16,6 +16,8 @@
},
"license": "Apache-2.0",
"dependencies": {
"@sap-cloud-sdk/core": "^1.18.1"
"@sap-cloud-sdk/core": "^1.18.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? (Same as above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to remove it and got compilation errors.

…ilities

# Conflicts:
#	package-lock.json
#	package.json
#	packages/core/test/scp-cf/destination-accessor.spec.ts
#	packages/core/test/test-util/destination-service-mocks.ts
#	test-packages/integration-tests/package.json
@FrankEssenberger FrankEssenberger marked this pull request as ready for review April 1, 2020 15:52
…ilities

# Conflicts:
#	package-lock.json
#	test-packages/integration-tests/package.json
@FrankEssenberger
Copy link
Contributor Author

Update: Hadlebars is updated with version 4.7.4 to not use the old minimist. So a npm audit fix was able to resolve the issue.

…ilities

# Conflicts:
#	package-lock.json
#	test-packages/integration-tests/package.json
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

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

I now tried this locally, npm i takes forever...

@FrankEssenberger
Copy link
Contributor Author

I just made a test. I removed the all node_modules folders and then the whole npm i took around 50 secs including the compile steps:

added 948 packages from 764 contributors and audited 42165 packages in 50.488s

If I use npm ci it is a bit less:

added 948 packages in 45.761s

In the VPN it was around 10sec longer. On master using the hoisting it took my machine

added 969 packages from 773 contributors and audited 42060 packages in 61.443s

but it was already hot from the previous build so I guess the effect of heating up is more than the additional download time? In the pipeline I see times between 50 and 70 sec for the build with hoisting.

So it seems like the times are not really increased by the change. I do not know, perhaps also other colleagues can try it out.

…ilities

# Conflicts:
#	package-lock.json
#	package.json
#	test-packages/integration-tests/package.json
…ilities

# Conflicts:
#	test-packages/test-services/package.json
Copy link
Contributor

@marikaner marikaner left a comment

Choose a reason for hiding this comment

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

I am not very happy with the nock thingy, other than that I think this looks fine

mockInstanceDestinationsCall([], 200, providerServiceToken),
mockSubaccountDestinationsCall([], 200, providerServiceToken),
mockSingleDestinationCall(oauthSingleResponse, 200, destinationName, userApprovedSubscriberServiceToken)
mockInstanceDestinationsCall(nock, [], 200, subscriberServiceToken),
Copy link
Contributor

Choose a reason for hiding this comment

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

I am in favor of putting it in the root except for dependencies that are run from the command line (there it has to be in the same context). I think dragging the dependency through the tests is worse than someone running npm install in a subpackage only. That can be covered by documentation and reviews.
I am also ok with doing this one we move to yarn.

@FrankEssenberger FrankEssenberger merged commit 38e94f4 into master Apr 7, 2020
@FrankEssenberger FrankEssenberger deleted the Fix_handle_vulnerabilities branch April 7, 2020 11:27
marikaner pushed a commit to denidaja/cloud-sdk that referenced this pull request Apr 14, 2020
marikaner added a commit that referenced this pull request Apr 14, 2020
* Issue #1000 fix, logger showing undefinedon Error objects.

* Issue #1027, allow setting log level globally

* Reordering priorities of level setter. Adding unit test for Error object and additional tests for logger levels.

* Proper cleanup on logger level at the end of each test. Allowing falsy parameter at setLogLevel

* Fixing some of the documentation comments

* feat: Add custom query parameters option (#74)

* chore: Automate generation of documentation and changelog (#72)

* Improve generate docs

* Add after bump script

* Improve changelog

* Add after bump script

* Add change log to draft

* Fix linting

* Add npx

* Add scripts

* remove dash

* Try as before

* Add tests

* Y u no work?

* Fix typo

* More output

* Limits?

* Try limit

* Clean up

* Add get-changelog action

* Fix cases

* Fix order

* Just echo?

* Fix typo

* Cleanup

* Gix test services script

* Add latest version

* Fix Re-export issue

* Fix reexport for 1.18.1

* Fix docs for 1.18.0

* Also update DOCUMENTATION.md

* Add docs index

* Update package lock

* Remove duplicate redirect

* Update changelog

* v1.19.0

* Revert "v1.19.0"

This reverts commit e41efe7.

* chore: Add changed files to staging area

* v1.19.0

* Revert "v1.19.0"

This reverts commit 0278a98.

* Revert "chore: Add changed files to staging area"

This reverts commit 30d499c.

* chore: Add files to staging after version

* v1.19.0

* Revert "v1.19.0"

This reverts commit e2616a6.

* chore: Fix typo in build.yml

* v1.19.0

* chore: Update changelog

* Remove Hoisting (#52)

* release date and blog post (#76)

* More tests in destination accessor (#75)

Co-authored-by: Marika Marszalkowski <marika.marszalkowski@sap.com>
Co-authored-by: Frank Essenberger <56544999+FrankEssenberger@users.noreply.github.com>
Co-authored-by: Jordan Dukadinov <jdukadinov@gmail.com>
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.

None yet

3 participants