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

Fdc3 for web impl commonjs #1452

Merged
merged 14 commits into from
Dec 18, 2024
Merged

Conversation

robmoffat
Copy link
Member

@robmoffat robmoffat commented Nov 28, 2024

This is to complete #1297 and address #1351, adds rollup to the fdc3 package so that common-js is still supported.

Since I know CJS is used in node, I ran the following:

var fdc3CJS= require('@kite9/fdc3-commonjs')

console.log("Got FDC3", fdc3CJS)

From within the fdc3-for-web/demo process and got back:

Got FDC3 {
  AgentError: {
    AgentNotFound: 'AgentNotFound',
    AccessDenied: 'AccessDenied',
    ErrorOnConnect: 'ErrorOnConnect',
    InvalidFailover: 'InvalidFailover'
  },
  OpenError: {
    AppNotFound: 'AppNotFound',
    ErrorOnLaunch: 'ErrorOnLaunch',
...
  Convert: [class Convert],
  addContextListener: [Function: addContextListener],
  addEventListener: [Function: addEventListener],
  addIntentListener: [Function: addIntentListener],
  broadcast: [Function: broadcast],
  compareVersionNumbers: [Function: compareVersionNumbers],
  createPrivateChannel: [Function: createPrivateChannel],
  fdc3Ready: [Function: fdc3Ready],
  findInstances: [Function: findInstances],
  findIntent: [Function: findIntent],
  findIntentsByContext: [Function: findIntentsByContext],
  getAgent: [Function: getAgent],
  getAppMetadata: [Function: getAppMetadata],
  getCurrentChannel: [Function: getCurrentChannel],
  getInfo: [Function: getInfo],
  getOrCreateChannel: [Function: getOrCreateChannel],
  getSystemChannels: [Function: getSystemChannels],
  getUserChannels: [Function: getUserChannels],
  isStandardContextType: [Function: isStandardContextType],
  isStandardIntent: [Function: isStandardIntent],
  joinChannel: [Function: joinChannel],
  joinUserChannel: [Function: joinUserChannel],
  leaveCurrentChannel: [Function: leaveCurrentChannel],
  open: [Function: open],
  raiseIntent: [Function: raiseIntent],
  raiseIntentForContext: [Function: raiseIntentForContext],
  versionIsAtLeast: [Function: versionIsAtLeast]
}

Which looks ok to me? Obviously, I can't call getAgent, so not sure how further to test this.

Nb, this is very much simplified from the original rollup.config.js (preserved in the packages/fdc3/old dir) but I think a lot of the assumptions of that are not necessarily relevant anymore, perhaps?

@robmoffat robmoffat requested a review from a team as a code owner November 28, 2024 16:54
Copy link

netlify bot commented Nov 28, 2024

Deploy Preview for fdc3 ready!

Name Link
🔨 Latest commit 74f383b
🔍 Latest deploy log https://app.netlify.com/sites/fdc3/deploys/6748a04dde422900086315e9
😎 Deploy Preview https://deploy-preview-1452--fdc3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Nov 28, 2024

Coverage Report

Commit: d9529a9
Base: fdc3-for-web-impl@c459f07

Type Base This PR
Total Statements Coverage ?  95.92% (?)
Total Branches Coverage ?  81.72% (?)
Total Functions Coverage ?  97.36% (?)
Total Lines Coverage ?  95.99% (?)
Details (changed files)
FileStatementsBranchesFunctionsLines
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/BroadcastHandler.ts 95.33% 84.26% 100% 95.1%
Details (all files)
FileStatementsBranchesFunctionsLines
packages/fdc3-agent-proxy/src/BasicDesktopAgent.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/index.ts 100% 100% 71.42% 100%
packages/fdc3-agent-proxy/src/apps/DefaultAppSupport.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/channels/DefaultChannel.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/channels/DefaultChannelSupport.ts 94.64% 75% 93.33% 94.33%
packages/fdc3-agent-proxy/src/channels/DefaultPrivateChannel.ts 97.05% 75% 100% 97.05%
packages/fdc3-agent-proxy/src/handshake/DefaultHandshakeSupport.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/intents/DefaultIntentResolution.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/intents/DefaultIntentSupport.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/listeners/AbstractListener.ts 94.44% 83.33% 100% 94.44%
packages/fdc3-agent-proxy/src/listeners/DefaultContextListener.ts 100% 92.3% 100% 100%
packages/fdc3-agent-proxy/src/listeners/DefaultIntentListener.ts 100% 80% 100% 100%
packages/fdc3-agent-proxy/src/listeners/EventListener.ts 90% 50% 80% 90%
packages/fdc3-agent-proxy/src/listeners/HeartbeatListener.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/listeners/PrivateChannelEventListener.ts 100% 100% 100% 100%
packages/fdc3-agent-proxy/src/messaging/AbstractMessaging.ts 92.3% 78.94% 93.75% 92.15%
packages/fdc3-get-agent/src/Fdc3Version.ts 100% 100% 100% 100%
packages/fdc3-get-agent/src/index.ts 100% 100% 100% 100%
packages/fdc3-get-agent/src/messaging/AbstractWebMessaging.ts 100% 66.66% 100% 100%
packages/fdc3-get-agent/src/messaging/MessagePortMessaging.ts 95% 75% 100% 95%
packages/fdc3-get-agent/src/messaging/message-port.ts 96.29% 92.85% 100% 96.29%
packages/fdc3-get-agent/src/strategies/ElectronEventLoader.ts 100% 100% 100% 100%
packages/fdc3-get-agent/src/strategies/PostMessageLoader.ts 98.27% 70% 100% 98.24%
packages/fdc3-get-agent/src/strategies/TimeoutLoader.ts 100% 85.71% 100% 100%
packages/fdc3-get-agent/src/strategies/getAgent.ts 92.68% 76.92% 91.66% 92.1%
packages/fdc3-get-agent/src/ui/AbstractUIComponent.ts 100% 83.33% 100% 100%
packages/fdc3-get-agent/src/ui/DefaultDesktopAgentChannelSelector.ts 100% 66.66% 100% 100%
packages/fdc3-get-agent/src/ui/DefaultDesktopAgentIntentResolver.ts 100% 75% 100% 100%
packages/fdc3-get-agent/src/ui/NullChannelSelector.ts 100% 100% 100% 100%
packages/fdc3-get-agent/src/ui/NullIntentResolver.ts 100% 100% 66.66% 100%
packages/fdc3-standard/src/index.ts 100% 100% 0% 100%
packages/fdc3-standard/src/api/Errors.ts 100% 100% 100% 100%
packages/fdc3-standard/src/api/GetAgent.ts 100% 100% 100% 100%
packages/fdc3-standard/src/api/Methods.ts 94.04% 84.05% 96.29% 95%
packages/fdc3-standard/src/api/RecommendedChannels.ts 100% 100% 100% 100%
packages/fdc3-standard/src/context/ContextType.ts 100% 100% 100% 100%
packages/fdc3-standard/src/intents/Intents.ts 100% 100% 100% 100%
packages/fdc3-standard/src/internal/contextConfiguration.ts 100% 100% 100% 100%
packages/fdc3-standard/src/internal/intentConfiguration.ts 100% 100% 100% 100%
packages/fdc3-standard/src/internal/typeHelpers.ts 100% 100% 100% 100%
toolbox/fdc3-for-web/fdc3-web-impl/src/BasicFDC3Server.ts 100% 100% 100% 100%
toolbox/fdc3-for-web/fdc3-web-impl/src/ServerContext.ts 100% 100% 100% 100%
toolbox/fdc3-for-web/fdc3-web-impl/src/directory/BasicDirectory.ts 96.77% 84.21% 100% 96.42%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/BroadcastHandler.ts 95.33% 84.26% 100% 95.1%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/HeartbeatHandler.ts 82.35% 64.86% 92.85% 84%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/IntentHandler.ts 90.81% 72.6% 98.18% 90.24%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/OpenHandler.ts 96.77% 79.48% 100% 96.77%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/support.ts 100% 100% 100% 100%

Copy link

424 passed

@kriswest kriswest changed the base branch from main to fdc3-for-web-impl November 28, 2024 16:59
This was linked to issues Nov 28, 2024
Copy link

424 passed

@kriswest
Copy link
Contributor

The old config built two sets of files into the module, which consumers could switch between by setting a NODE_ENV variable, which this config won't produce. I'm no export on these config, but it also looks like you are only producing common.js files, and in their development form (all comments etc. retained as terser is not used to dtrip them out).

Copy link

424 passed

@robmoffat
Copy link
Member Author

robmoffat commented Nov 28, 2024

HI @kriswest,

Yes that's right. The main difference between the two versions being that the production one was minified using terser.

Based on @thorsent's feedback about this, it seems like the use case for CJS is automated tests on very legacy versions of node. Given that, it seemed best that we provide the un-minified version by default so at least people can figure out where their tests are going wrong.

@kriswest
Copy link
Contributor

One of the participating teams fed back that they were still using CommonJS in builds.

The advantage of having both types in the module is that, based on whether you are doing a dev or prod build, it includes the relevant version. If you then bundle and treeshake your own app you app code only then includes the version you use, so prod builds are leaner, while dev builds are unminimized, including comments, maps etc.. I have no idea if an app can do that minification itself if we don't.

At least thats my (limited) understanding. @julianna-ciq probably understands it better?

@robmoffat
Copy link
Member Author

Do we actually know who is using CJS? It might be simpler to just ask that one person! I have a feeling this is super-niche and not worth spending a lot of time on, but at the same time it'd be nice not to give that one person a headache.

@kriswest
Copy link
Contributor

@Roaders commented in a meeting - however, we don't know every app and team thats consuming the FDC3 npm module. Its gets around 8k downloads a week from NPM...

@robmoffat
Copy link
Member Author

robmoffat commented Nov 29, 2024

The reason it's so different is that basically I had to start over and read the rollup docs on how to do this - the original script (preserved) didn't work out-of-the-box.

As I looked into it, it seemed like a lot of the original rollup config probably wasn't relevant to what we were doing anymore. For example, it referenced react, but we don't have any react in the fdc3 module.

So it's tricky. We could spend effort trying to preserve the NODE_ENV stuff if that's what you want? But (going by @thorsent's notes) it seems like an odd thing to have in there just to reduce the size of a download for the node environment, especially given the node environment is going to be pulling in the entire dependency into it's node_modules: effectively having a minified version is just going to increase the size of the download!

@kriswest
Copy link
Contributor

The react reference is only a minor part of that config (a couple of lines), the majority is related to preparing the variations on the module. I'm not convinced its producing both CommonJs and ES6 versions now. Also, the goal is not to reduce the module size downloaded by NPM, but rather the output bundle size of a project consuming the module. The module is going to increase in size with 2.2 and the loss of a minified version to pull in may exacerbate that increase in size for downstream projects.

I think we need to understand the impact of changes to the module, before releasing a version with those changes.

@kriswest
Copy link
Contributor

The react part of the config is probably inherited from tsdx's rollup config, as that is what was originally used to build the module (and also where the dev/prod build setup comes from).

@robmoffat
Copy link
Member Author

@kriswest did this get raised in the SWG meeting last week at all?

@kriswest
Copy link
Contributor

I mentioned it, few opinions were offered and no conclusion drawn unfortunately

@robmoffat
Copy link
Member Author

Shall I close this then?

Copy link

424 passed

@kriswest
Copy link
Contributor

Shall I close this then?

Sorry to clarify my previous response: I mentioned the idea to publish two modules, ES6 and CommonJS, allowing for a simple resolution for anyone's build that gets broken by switching to ES6 only and there were no objections. I think @novavi liked the idea of being able to track usage and retire the CommonJs module when its not in use.

Hence, I think we should proceed as we've discussed offline @robmoffat, and it looks like you are on your way there already.

Copy link

424 passed

@robmoffat
Copy link
Member Author

yeah think this is done as discussed. WDYT?

Copy link
Contributor

@kriswest kriswest left a comment

Choose a reason for hiding this comment

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

Needs a changelog adding (for the siwtch to searpate ES6 and commonJS modules).

Also, these packages will (I assume!) publish with the readme file from each package. fdc3-commonjs is lacking a Readme file currently as is fdc3, see https://www.npmjs.com/package/@kite9/fdc3 for what that looks like.

In the past the NPM package has inherited the repositoy's README file, which is not ideal. This is good oppurtunity to develop something more relevant, including content for both App and Desktop Agent developers as very basic getting started content. Each readme should also include an early reference to the other package and an explanation of which to use.

README.md Outdated Show resolved Hide resolved
Copy link

424 passed

Co-authored-by: Kris West <kris.west@interop.io>
Copy link

424 passed

Copy link

424 passed

1 similar comment
Copy link

424 passed

Copy link
Contributor

@kriswest kriswest left a comment

Choose a reason for hiding this comment

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

LGTM

packages/fdc3/README.md Outdated Show resolved Hide resolved
packages/fdc3/README.md Outdated Show resolved Hide resolved
robmoffat and others added 4 commits December 18, 2024 15:16
Co-authored-by: Kris West <kris.west@interop.io>
Co-authored-by: Kris West <kris.west@interop.io>
Co-authored-by: Kris West <kris.west@interop.io>
Co-authored-by: Kris West <kris.west@interop.io>
Copy link

424 passed

3 similar comments
Copy link

424 passed

Copy link

424 passed

Copy link

424 passed

@robmoffat robmoffat merged commit 2f5429a into fdc3-for-web-impl Dec 18, 2024
4 checks passed
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.

CommonJs vs ES6 FDC3 monorepo
3 participants