[yocto] [npm] duplicate code

Stefan Herbrechtsmeier stefan at herbrechtsmeier.net
Tue Oct 8 13:04:17 PDT 2019


Hi Josef,

Am 08.10.19 um 07:12 schrieb Josef Holzmayr:
> On Mon, Oct 07, 2019 at 09:33:46PM +0200, Stefan Herbrechtsmeier wrote:
>> Hi Jean-Marie,
>>
>> Am 07.10.19 um 14:16 schrieb Jean-marie Lemetayer:
>>>> I thought about your idea of using Yocto to manage NPM package dependencies and I ran into an issue. NPM projects can have multiple dependencies on a single package, and sometimes with multiple versions. NPM will manage this by creating sub 'node_modules' tree.
>>>
>>> Here is an example with a newly created angular application. The app depends on 3 different version of 'ansi-regex'. NPM will install the packages this way:
>>> node_modules/ansi-regex @ 2.1.1
>>> node_modules/cliui/node_modules/ansi-regex @ 3.0.0
>>> node_modules/inquirer/node_modules/ansi-regex @ 4.1.0
>>> node_modules/string-width/node_modules/ansi-regex @ 3.0.0
>>> node_modules/@angular/compiler-cli/node_modules/ansi-regex @ 4.1.0
>>
>> I use symbolic links instead of folders, append the major version to the
>> folder name and move the folders into the main node_modules folder. At the
>> moment I use one version per major version or first version unequal to zero:
>>
>> node_modules/ansi-regex-2
>> node_modules/ansi-regex-3
>> node_modules/ansi-regex-4
>> node_modules/cliui-X/node_modules/ansi-regex -> ../../ansi-regex-3
>> node_modules/inquirer-X/node_modules/ansi-regex -> ../../ansi-regex-3
>> node_modules/string-width-X/node_modules/ansi-regex  -> ../../ansi-regex-3
>> node_modules/@angular/compiler-cli-X/node_modules/ansi-regex  ->
>> ../../../ansi-regex-4
>> node_modules/abc-X/node_modules/ansi-regex -> ../../ansi-regex-2
>> node_modules/abc-X/node_modules/cliui -> ../../cliui-X
>> node_modules/abc-X/node_modules/inquirer -> ../../inquirer-X
>> node_modules/abc-X/node_modules/string-width -> ../../string-width
>> node_modules/abc-X/node_modules/@angular/compiler-cli ->
>> ../../../@angular/compiler-cli-X
>>
>>
>>> How can you handle that with Yocto ? I am not sure but I think it is not possible.
>> It is possible and Yocto could do even more. If you take a look at the
>> package ansi-regex you realize that the project increase the major version
>> only because they change the minimum required nodejs version. This means you
>> could replace all ansi-regex version by the last version, add some symbolic
>> links to the ansi-regex package and provide all versions by the same
>> package.
> 
> I think it would be dangerous to assume this holds true for other
> packages too.

I don't assume this. It is a manual optimization of individual recipes. 
The OE package name (PN) for a NPM package consists of the NPM package 
name and the major version. An individual recipe could contain multiple 
RPROVIDES for different major version if the API is compatible.

In the semantic versioning world as npm packages expectexd
> to behave - and nodejs itself certainly does! - a change in the major
> version means a breaking change of some kind.

And one of this breaking change is the update of the minimal Node.js 
version.

Regards
   Stefan


More information about the yocto mailing list