Replies: 2 comments 4 replies
-
|
I suggest that we support both |
Beta Was this translation helpful? Give feedback.
-
|
It looks good to me for the content you provided. On top of that, another goal of this RFC is to maintain a unified experience for both rust and node users.
This is a real pain in the ass for us to handle the conversion. Is there any possibility we can simplify this? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The Interfaces for Users
Expected
We need to provide a set of interfaces which is easy for users to understand and use. Among module bundler for JavaScript, Webpack is the most widely used and mature tool that provides a set of well known concepts, so we tried to align the configuration files of the implemented features on JavaScript side with it as much as possible.
Detailed design
Let's take the design of the
resolveas an example.Webpack implements a complex set of features with
enhanced-resolve, In addition to the most basic features such asextensions,mainFiles, It also provides some less commonly used fields such asbyDependency, let's discuss the different scenarios based on the above cases one by one.aliasaliasFieldscacheWithContextconditionNamesdescriptionFilesenforceExtensionextensionAliasextensionsfallbackmainFieldsmainFilesexportsFieldsmodulesunsafeCacheuseSyncFileSystemCallspluginspreferRelativepreferAbsolutesymlinkscachePredicaterestrictionsrootsimportsFieldsbyDependencyFor the most foundation and important features, such as order 1, 2, 4, 8, 11, 17, 19, there is no ambiguity about theses basic functions, either in terms of interface meaning or in terms of function usage, and as the most basic functions of the bundler, we should ensure that the usage is consistent with that in Webpack.
For those interfaces that are essential, but the effect is not completely consistent, such as 5, 10, 13, 12, 23, we had to redesign the API. For example,
enhanced-resolveprovide a field calledmodules, its default value is['node_modules'], and it means to when trying to resolve a file imported from a library, the value in themodulesarray will be used as the directory of the library. However, it is known that libraries downloaded from npm are generally stored in thenode_modulesdirectory of the current project, of course, bower is special cases, but I don't think we should pay for changing special circumstances. The rest fields have similar problems.For features that are not implemented, such as 7, 9, 16, 18, 20, 22, 24, they can be grouped into two categories, those that are not supported at the moment because their functionality is less used, such as the new field
extensionsAliasadded in version 5.10.0. The other is a feature that cannot be implemented due to its own technical selection, such asplugins.For these features which are not implemented by
enhanced-resolvebut had implemented byrspack, such as the shared cache among different resolver, we should design the API according to the corresponded features.Also, here are some explications on why the API is aligned in JavaScript side: due to the Rust is a strongly typed language, so we had to use the explicit type in Rust side, for example for the field of
resolve.alias, we need to use an enum type such asAliasMap::IgnoredorAliasMap::To('./a.js'), it's very inconvenient.Test for API
For testing of interfaces, the solution of Webpack is worthy of reference, as it puts all API-related test cases into a folder called tests/configCases, which is worth we can learn from.
Three Sections
The project is used to build JavaScript projects, so the configuration interfaces are divided into three:
The flow of data is:
node interface -----------------> binding options ----------------> rust interface normalized normalizedBeta Was this translation helpful? Give feedback.
All reactions