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

Open
wants to merge 3 commits into
base: fdc3-for-web-impl
Choose a base branch
from

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 fdc3 = require('@kite9/fdc3')

console.log("Got FDC3", fdc3)

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: b00d208
Base: fdc3-for-web-impl@70121ac

Type Base This PR
Total Statements Coverage ?  96.37% (?)
Total Branches Coverage ?  82.42% (?)
Total Functions Coverage ?  97.62% (?)
Total Lines Coverage ?  96.42% (?)
Details (changed files)
FileStatementsBranchesFunctionsLines
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% 75% 93.33% 93.61%
packages/fdc3-agent-proxy/src/channels/DefaultPrivateChannel.ts 97.05% 80% 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 100% 100% 100% 100%
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 97.87% 84.61% 100% 97.87%
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 100% 100% 100% 100%
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% 100% 100% 100%
packages/fdc3-get-agent/src/strategies/getAgent.ts 93.02% 76.92% 91.66% 92.3%
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.66%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/BroadcastHandler.ts 95.94% 84.88% 100% 95.62%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/HeartbeatHandler.ts 82% 64.86% 92.85% 83.67%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/IntentHandler.ts 90.81% 72.6% 98.18% 90.18%
toolbox/fdc3-for-web/fdc3-web-impl/src/handlers/OpenHandler.ts 97.75% 81.08% 100% 97.64%
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?

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