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

Get ready to publish Alloy as an NPM repo #637

Merged
merged 33 commits into from
Jan 28, 2021
Merged

Get ready to publish Alloy as an NPM repo #637

merged 33 commits into from
Jan 28, 2021

Conversation

jonsnyder
Copy link
Contributor

Description

This PR gets the repo ready to be published as an NPM library. Other PRs will automate the build process. The NPM library publishes an ES6 module which exposes the baseCode, core initialization, and the createEventMergeId functions. The built baseCode and standalone javascript files are not published in the NPM library. If you want to use the built versions you should use the version on the CDN.

See #632

There are three entry points now:

  1. src/baseCode.js - used to generate the base code snippet
  2. src/standAlone.js - used to generate the standalone code
  3. src/index.js - used to generate the ES6 modules

I was also able to remove the REACTOR pre-processor statements, as the launch extension can use the ES6 module and the createEventMergeId directly.

Related Issue

https://jira.corp.adobe.com/browse/CORE-52500

Motivation and Context

  1. We don't want to have to copy built files as part of the Launch Extension release process. The launch extension can use the NPM library to integrate.
  2. Publishing an NPM library allows customers to integrate with their javascript build system.
  3. If we were to export more modules we could allow customers to do custom builds. (i.e. exclude the personalization module).

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA or I'm an Adobe employee.
  • I have made any necessary test changes and all tests pass.
  • I have run the Sandbox successfully.

@@ -1,8 +1,13 @@
{
"name": "@adobe/alloy",
"version": "2.3.0",
"description": "Client-Side SDK for Unified Data Collection",
"main": "src/core/index.js",
"description": "Adobe Experience Platform Web SDK",
Copy link
Contributor

Choose a reason for hiding this comment

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

Finally :)

package.json Outdated
}
],
"dependencies": {
"css.escape": "^1.5.1",
"typescript": "^4.0.5",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does that pull typescript into the library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I didn't mean to add this as a dependency. Thanks for catching.

Copy link
Contributor

@Aaronius Aaronius left a comment

Choose a reason for hiding this comment

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

Thanks for moving this forward Jon. I left some comments that we should probably resolve.

README.md Outdated Show resolved Hide resolved
README.md Outdated
window.alloy("sendEvent", { ... });
```

The ES6 exports are exposed via the NPM "module" property, so you may need to adjust your rollup system to look for the module property.
Copy link
Contributor

Choose a reason for hiding this comment

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

"rollup system" should probably be "bundler" or "JavaScript bundler".

Copy link
Contributor

Choose a reason for hiding this comment

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

Couple questions here:

(1) Are you aware of any bundlers that don't support module by default? I'm aware it isn't standard, but I think it's been supported by default for 2+ years on the major bundlers. If so, this line may not be providing value and just introducing cognitive load, but who knows. If you keep it, it might be better to say something like "are exposed by the NPM package via the module field of its package.json, so you may...". If I'm a consumer having problems, that might give me more context for googling. 🤷‍♂️

(2) I'm trying to think through why we're creating main.js and modules.js as bundles. Normally what I've seen is that you would just run all the source code files through babel and dump all the resulting files into, say, an es5 directory, then point the main field in package.json to es5/index.js. For the es6 variant, you may just be able to point the module field in package.json to src/index.js.

One of the benefits of not generating bundles for the npm package consumers is that if the consuming application already has a dependency that matches one of our dependencies, the final application bundle only needs to include the dependency code once. Currently, we only have a couple dependencies, so that chance is somewhat low, but that may grow over time

One effect of taking this approach is that the extension will need to do some bundling before getting packaged and uploaded. But, I believe this would mean that you would be able to move the Launch core module dependencies from peerDependencies back to dependencies in this repo. When you do the bundling for the extension, I believe you'd just mark Launch core module dependencies as "externals" so that Launch can provide them instead of bundling them in from node_modules.

Sorry, I should've thought through this during my previous review as it definitely affects what I was saying in https://github.com/adobe/alloy/pull/632/files#r518529523.

README.md Outdated
## Installation

There are three supported ways to use Alloy.
1. Using Adobe Launch, install the Adobe Experience Platform Web SDK Extension.
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically we should change "Adobe Launch" to "Adobe Experience Platform Launch" and remove "the" from before "Adobe Experience Platform Web SDK". We should probably lowercase "Extension" because "Adobe Experience Platform Web SDK Extension" isn't a brand itself and "Extension" alone isn't a pronoun.

README.md Outdated
2. Use the pre-built, minified version available via a CDN. You could also self-host this version.
3. Use the NPM library which exports an ES6 module.

### Using the launch extension
Copy link
Contributor

Choose a reason for hiding this comment

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

"launch" here is a secondary reference so it should probably be "Experience Platform Launch" (my understanding is we can can drop the "Adobe" on secondary references).

README.md Outdated

### Using the launch extension

For documentation on the AEP Web SDK Launch Extension see the [launch documentation](https://docs.adobe.com/content/help/en/launch/using/extensions-ref/adobe-extension/aep-extension/overview.html)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lowercase "Extension" and change "launch" to "Experience Platform Launch".

README.md Outdated

For documentation on the AEP Web SDK Launch Extension see the [launch documentation](https://docs.adobe.com/content/help/en/launch/using/extensions-ref/adobe-extension/aep-extension/overview.html)

### Using the stand alone version
Copy link
Contributor

Choose a reason for hiding this comment

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

"standalone" is one word.

README.md Outdated

The ES6 exports are exposed via the NPM "module" property, so you may need to adjust your rollup system to look for the module property.


Copy link
Contributor

Choose a reason for hiding this comment

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

I still think all this documentation should be consolidated into the user docs like I mentioned in #632 (comment). It sounds like you might disagree, but you did mention you were considering at least trimming down this readme to the es6 installation instructions.

src/baseCode/index.js Show resolved Hide resolved
@jonsnyder
Copy link
Contributor Author

@Aaronius can you take another look at this PR?

@jonsnyder
Copy link
Contributor Author

@Aaronius can you take another look at this PR? I implemented the createInstance method like you suggested in the docs PR.

Copy link
Contributor

@Aaronius Aaronius left a comment

Choose a reason for hiding this comment

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

I like.

src/index.js Outdated
export default instanceName => {
const { executeCommand: instance, logger } = createExecuteCommand(
instanceName
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would make more sense to create the "log controller" here and pass it into createExecuteCommand rather than creating the log controller inside createExecuteCommand and exporting logger?

@@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import createInstance from "../../../../src/core/createInstance";
import createInstance from "../../../../src/core/createInstanceFunction";
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want to rename createInstance to createInstanceFunction here.

package.json Outdated
@@ -68,6 +74,8 @@
"uuid": "^3.3.2"
},
"devDependencies": {
"@adobe/alloy": "file:./",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now this just references the current directory, but when we publish the NPM library I will change this to reference the actual version.

Copy link
Contributor

@jfkhoury jfkhoury left a comment

Choose a reason for hiding this comment

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

Great work @jonsnyder !!

I recommend testing the built library manually in the sandbox since there's so many changes :)

@jonsnyder jonsnyder merged commit 2bee677 into main Jan 28, 2021
@jonsnyder jonsnyder deleted the npmLibrary branch January 28, 2021 16:19
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