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

Add main minified dist file as exportable asset #682

Merged
merged 2 commits into from
Nov 14, 2021

Conversation

exsilium
Copy link
Contributor

Note: the engine.io.js file is the generated output of make engine.io.js, and should not be manually modified.

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behaviour

With the recent introduction of the exports block to package.json, modern node limits the files which can be imported from the module. Previously it was possible to import the main dist file directly. Now with the introduction of the exports block one receives an error trying to import the engine.io.min.js file:

[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/engine.io.min.js' is not defined by "exports"

Proposal to add at least the minified file to be exportable.

New behaviour

Does not introduce new behaviour, restores old one where it was possible to import any file from the package as there was no exports block on the package level defined - thus node allowed to export any file.

Other information (e.g. related issues)

The complete file list could be expanded to all the .js files listed in ./dist in case any other file is consumed directly.

@darrachequesne
Copy link
Member

Thanks for the pull request! While we're at it, how about expanding it to all .js/.map files in the dist directory?

Out of curiosity, could you please explain your use case?

@exsilium
Copy link
Contributor Author

exsilium commented Nov 14, 2021

Hi @darrachequesne! Thanks, as for the background I maintain a fairly large codebase at #pylonide/pylon - a web based IDE that depends on engine.io. The way that client side static assets are made available is via a separate static middleware to where assets are fed by resolving the module path name via require.resolve(). Eg. to make engine.io client side library available and mountable by the client I do the following:

imports["static"].addStatics([{
  path: PATH.dirname(require.resolve("engine.io-client/dist/engine.io.min.js")),
  mount: "/engine.io",
  rjs: [
    {
      "name": "engine.io",
      "location": "engine.io",
      "main": "engine.io.js"
    }
  ]
}]);

This method has worked very well so far unless packages introduce exports block that restricts exporting to certain files only. I've now committed modification to include all the ./dist/*.js files as exportable. Maps are excluded. Exports are explicit - meaning no subpath pattern was used as recommended by the core documentation in case of small number of total exports needed.

@darrachequesne darrachequesne merged commit 8de51c3 into socketio:master Nov 14, 2021
@darrachequesne
Copy link
Member

@exsilium thanks for the explanation 👍

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.

2 participants