Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

fix usage as a commonjs module - #41

Merged
wtrocki merged 1 commit into
masterfrom
commonjs-fix
Jan 31, 2018
Merged

fix usage as a commonjs module#41
wtrocki merged 1 commit into
masterfrom
commonjs-fix

Conversation

@evanshortiss

@evanshortiss evanshortiss commented Dec 13, 2017

Copy link
Copy Markdown
Member

Work that should address #40. Need to test in my project, but the example is still working after this change.

}; No newline at end of file
};

require('./lawnchairHtml5FileSystem')(Lawnchair)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Instead of using concat, these are loaded via require now so browserify will pick them up.

Comment thread Gruntfile.js
crypto: {
src:[
"libs/cryptojs/cryptojs-core.js",
"libs/cryptojs/cryptojs-enc-base64.js",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Most of these were referenced but no longer exist.

@evanshortiss
evanshortiss requested a review from wtrocki December 13, 2017 02:00
Comment thread Gruntfile.js
}
},
concat: {
lawnchair: {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is no longer required thanks to browserify.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah. This is just leftover from js-sdk. Sadly we need to still bundle lawnchair as source code weren't released for the last couple years and we made some fixes directly upstream to maintain it :)

@@ -1,105 +1,107 @@
Lawnchair.adapter('memory', (function(){
module.exports = function (Lawnchair) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Formatting got a little wild here. Should we run add standard and use standard --fix or similar to keep things consistent? Maybe an .editorconfig too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, or we could move them out into its own module. It shouldn't be in this repo I think.

@paolobueno paolobueno Dec 13, 2017

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think these should reside in require('lawnchair').memoryAdapter.

I'm not sure where the code for these adapters come from originally, since I couldn't find them standalone on npm or on the original repository for lawnchair...

For styling I think we might be a litle closer to semi-standard than standard, just because semicolons are a hot topic. We have a recommended set of styles for our own code somewhere but I couldn't find it right now, going to look further.

EDIT: so it seems the code for most of these adapters is already inside the original repo, just not exposed by the module as commonjs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure where the code for these adapters come from originally, since I couldn't find them standalone on npm or on the original repository for lawnchair...

They were renamed, removed etc. long time ago.
We using some really old ones. Here is tag that has some of them:
https://github.com/brianleroux/lawnchair/tree/0.6.4/src/adapters

@evanshortiss

Copy link
Copy Markdown
Member Author

Fix confirmed in ng4 Ionic project that uses this module.

@wtrocki
wtrocki requested a review from paolobueno December 13, 2017 10:47
@wtrocki wtrocki self-assigned this Dec 13, 2017

@wei-lee wei-lee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for now this is ok. But in the long term, I suggest we move Lawnchair to its own repo, or get rid of it completely.

@wtrocki

wtrocki commented Dec 13, 2017

Copy link
Copy Markdown
Member

@evanshortiss Thank you so much for starting and providing solution for this important issue.
I have reviewed your contribution and added other interesting parties to have full overview about directions we should take to resolve this issue completely. Your fix resolves original issue, but for sync maintainers it's also important to make sure that we all are aware of the possible impact and changes this will trigger.

We talked about this issue a lot with @paolobueno

Background

I'm going to provide some background to explain why we have some external source code in our module. We put lawnchair in our code because original library weren't published for years:
https://github.com/brianleroux/lawnchair/releases

Every time browser api changes we making fix in upstream and backport changes in lib folder to make it compatible. For example:
brianleroux/lawnchair#229

Lawnchair doesn't support common.js modules - extensions are just mounted to global var. Concat were used as hack and were causing issues from the beginning.

Suggested fix

In my opinion the best course of the action will be to install Lawnchair as dependency.

We have two options:

  1. Wait for maintainer to publish
    Paolo done fix to include src folder in the module.
    We asked for module to be released and waiting for response:
    Include src/ in published package brianleroux/lawnchair#233

If you guys can +1 this idea this may definitely help.
When getting package this way we will still need to figure out how to enable browserify.

  1. Bring Lawnchair under our umbrella and release it to npm together with all storage drivers. Then we can just have it as dependency in sync and prevent from any issues. This will also allow us to move to more modern web common.js engines like webpack (this was spiked by @paolobueno )

Current fix

This fix may be the first step to extract Lawnchair out of the sync module. However I do not understand why we committing both source and generated code. We can make assumption that this is library and remove source code as we no longer have ability to concatenate that.
I also noticed some changes in actual library code - did we done update?
Making changes in this code will also complicate future updates with upstream - it's not that big issue IMHO but it's definitely something to be aware of.

@wtrocki wtrocki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreeing with Wei, but I would like to understand why we have both generated content and source code before we merge this PR.

@wei-lee

wei-lee commented Dec 13, 2017

Copy link
Copy Markdown
Contributor

yeah, I think the generated file can be removed now. It's not required anymore.

@paolobueno

Copy link
Copy Markdown

Actually the author has shown himself willing to merge changes and do a release. I'd PR'd from a personal fork but we could definitely have one in the feedhenry org to move forward faster if we wish to.

The minimal fix in brianleroux/lawnchair#233 is still not enough, it's missing practically what @evanshortiss is doing here, making the adapters commonjs modules instead of them expecting to be run on top of Lawnchair as a global.

@evanshortiss

Copy link
Copy Markdown
Member Author

Agreed @wtrocki. If it is published to npm that'd be great and solve our headache here so long as what @paolobueno says is also addressed 👍 Have added +1

Bring Lawnchair under our umbrella and release it to npm together with all storage drivers. Then we can just have it as dependency in sync and prevent from any issues

I tried to help get it published a long time ago actually! So if it doesn't see activity soon then maybe you're right, we could publish it under @rhm/lawnchair or a similar npm org.

@wtrocki

wtrocki commented Dec 18, 2017

Copy link
Copy Markdown
Member

As this may cause some problems in automation etc. I have done prerelease to test it in together with fh-js-sdk and other projects:

fh-sync-js@1.2.2-pre41

@evanshortiss We kinda need consensus here. I think that we may integrate this fix and then look towards using our own version of lawnchair. Do you think we should close this PR and go directly to our version?

@david-martin - What's your take on this?

@wtrocki

wtrocki commented Dec 18, 2017

Copy link
Copy Markdown
Member

@evanshortiss - I can confirm that this fixes problem with browserify.
Works fine and passes all the tests.

@evanshortiss

Copy link
Copy Markdown
Member Author

@wtrocki I'm happy with either approach really.

I suppose the upside of merging this is that it fixes the module temporarily until we can look into using our own version.

@@ -0,0 +1,1354 @@
/**

@wtrocki wtrocki Dec 18, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we remove this file?

@wtrocki

wtrocki commented Dec 18, 2017

Copy link
Copy Markdown
Member

@evanshortiss - Let's merge it then. Just one small thing to clear that out.

@wtrocki
wtrocki requested a review from aidenkeating January 31, 2018 12:20
@wtrocki
wtrocki merged commit 7ffbb90 into master Jan 31, 2018
@wtrocki
wtrocki deleted the commonjs-fix branch January 31, 2018 12:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants