Conversation
|
I'm not convinced of this. The first problem is that it adds a dependency on chrome-net for all users of this module, even tough not all might need it. Also, I think this is just the wrong place to do it. The way I did this was: var builtins = require('browserify/lib/builtins.js')
var serverBuiltins = {}
Object.keys(builtins).forEach(function (key) {
serverBuiltins[key] = builtins[key]
})
serverBuiltins.net = require.resolve('chrome-net')
serverBuiltins.http = require.resolve('http-node')
var server = browserify({..., builtins: serverBuiltins})(Since https://blog.chromium.org/2016/08/from-chrome-apps-to-web.html I haven't worked on Chrome Apps, not sure if this still works.) Which is not that much configuration. You'd still have to configure browserify to use the With the |
|
@jscissr Thanks for your response. I agree with you that the production dependency on Your approach of just telling browserify to do a total replacement of For example, you can see how we swap out a package specifically for chrome apps here: https://github.com/webtorrent/webtorrent/blob/57945797335368bd81b3a6ab5a417f057e56d1ea/package.json#L29 So given that packages may want to make specific substitutions for different environments (Chrome Apps, Electron, React Native, etc.) I still think the To address your concern about the production dependency on |
I'm attempting to make a defacto standard for specifying Chrome App dependency substitutions using the "chromeapp" field in `package.json`. The "chromeapp" field is just like the "browser" field in `package.json` (see spec here: https://github.com/defunctzombie/package-browser-field-spec) except it's intended for Chrome App targets instead of a generic browser target. Specifically, since Chrome Apps can use raw sockets, we want to replace 'net' and 'dgram' with 'chrome-net' and 'chrome-dgram', respectively.
|
I updated the PR so you can see what I'm now proposing. |
|
@jscissr Ping – do you have any thoughts on this PR? |
|
With your updated PR, I'm not strongly against it anymore. However, I'm still not convinced that it's the best solution for your problem. {
"browser": {
"buffer": "buffer/"
}
}Instead, this is defined in this file: https://github.com/browserify/browserify/blob/master/lib/builtins.js exports.http = require.resolve('http-node')
exports.net = require.resolve('chrome-net')
// ...I personally think this approach would be a much better solution. You're defining these replacement in a single place, rather than in the package.jsons of many different projects. Is there some reason why this would not work for you? Btw, I haven't updated http-node in quite some time. In case you want to do this, it's not a lot of work for http-node itself, the main task was actually to update http-parser-js when I did it. |
|
@goto-bus-stop Do you have thoughts on @jscissr's proposed solution? Also – is it easy to point browserify to a custom |
|
There's currently no command line argument in browserify for using custom builtins, but you can easily do it when using the API (see my comment above). |
|
That seems like a totally good use of |
|
@goto-bus-stop Great! This seems like the best path forward for supporting alternate shims for different environments. Then we won't need to get every package that uses e.g. |
# [1.3.0](v1.2.0...v1.3.0) (2022-01-14) ### Bug Fixes * add semantic release config ([c524325](c524325)) ### Features * webtorrent org, semantic release ([65665fd](65665fd))
I'm attempting to make a defacto standard for specifying Chrome App dependency substitutions using the
"chromeapp"field inpackage.json.The
"chromeapp"field is just like the"browser"field inpackage.jsonexcept it's intended for Chrome Apps instead of a generic browser environment. Bundler tools likebrowserifyorwebpackcan be configured to look for the"chromeapp"field instead of the"browser"field when doing a build for a Chrome App.In this specific package, since Chrome Apps can use raw sockets we want to replace
require('net')withrequire('chrome-net').