liferay / liferay-frontend-projects

A monorepo containing assorted Frontend Infrastructure Team projects
Other
69 stars 68 forks source link

Adding node shims for a third-party dependency #901

Open thektan opened 2 years ago

thektan commented 2 years ago

Issue type (mark with x)

Description

I previously created a thread in #t-dxp-frontend-infra here: https://liferay.slack.com/archives/CNBG06JS3/p1648595258944989

I'm trying to add a third-party dependency @apidevtools/json-schema-ref-parser (https://github.com/APIDevTools/json-schema-ref-parser) to traverse a JSON schema for autocompletion in a code editor. The package uses require('http') and require('https'). In portal I get errors of missing dependency:

[
    "Missing dependency 'liferay!search-experiences-web$http' of '@liferay!search-experiences-web$apidevtools/json-schema-ref-parser@9.0.9/lib/resolvers/http'",
    "Missing dependency 'liferay!search-experiences-web$https' of '@liferay!search-experiences-web$apidevtools/json-schema-ref-parser@9.0.9/lib/resolvers/http'",
    "Missing version constraints for 'liferay!search-experiences-web$http' in package.json of '@liferay!search-experiences-web$apidevtools/json-schema-ref-parser@9.0.9' (required from its 'lib/resolvers/http' module)",
    "Missing version constraints for 'liferay!search-experiences-web$https' in package.json of '@liferay!search-experiences-web$apidevtools/json-schema-ref-parser@9.0.9' (required from its 'lib/resolvers/http' module)"
]

A github issue (https://github.com/APIDevTools/json-schema-ref-parser/issues/254#issuecomment-1049481948) about these missing packages resolves this issue by adding polyfills stream-http and https-browserify using the webpack.config.js configuration:

module.exports = {
  resolve: {
    fallback: {
      https: require.resolve("https-browserify"),
      http: require.resolve("stream-http")
    },

Desired behavior: Can something similar to the webpack.config.js be done (or supported if it doesn't exist) to resolve the missing dependencies?

Current behavior: Unable to resolve the missing node http and https dependencies to use the @apidevtools/json-schema-ref-parser package.

bryceosterhaus commented 2 years ago

Hey @thektan! Thanks for opening this. How urgent is this need? We can fit it in at some point, but just want to get an idea of how soon we need to work on it.

thektan commented 2 years ago

Hi @bryceosterhaus! I was able to write a basic $ref resolver which works for simple paths in the same file. It works for our use case at the moment so this is not as urgently needed anymore.

It'd still be helpful to eventually use this library to resolve references to other files so we could organize and reduce duplicated schema, but I'd say this not as important anymore.

bryceosterhaus commented 2 years ago

@thektan good to know! Let us know if/when this becomes more urgent. We will keep this in our backlog and hope to address it soon, however we are working on some new build and bundle processes and we may not need node shims in the future, so its possible this may resolve itself with new techniques.