@@ -989,17 +989,21 @@ Each key in `packages` is a unique identifier for a package entry:
989989 "app" : {
990990 "name" : " my-app" ,
991991 "path" : " ./packages/app" ,
992- "dependencies" : [" utils" , " ui-lib" ]
992+ "dependencies" : {
993+ "@myorg/utils" : " utils" ,
994+ "@myorg/ui-lib" : " ui-lib"
995+ }
993996 },
994997 "utils" : {
995998 "name" : " @myorg/utils" ,
996- "path" : " ./packages/utils" ,
997- "dependencies" : []
999+ "path" : " ./packages/utils"
9981000 },
9991001 "ui-lib" : {
10001002 "name" : " @myorg/ui-lib" ,
10011003 "path" : " ./packages/ui-lib" ,
1002- "dependencies" : [" utils" ]
1004+ "dependencies" : {
1005+ "@myorg/utils" : " utils"
1006+ }
10031007 }
10041008 }
10051009}
@@ -1011,8 +1015,10 @@ Each package entry has the following fields:
10111015 the package directory.
10121016* ` name ` {string} The package name used in import specifiers. If omitted, the
10131017 package cannot be imported by name but can still import its dependencies.
1014- * ` dependencies ` {string\[ ] } Array of package keys that this package is allowed
1015- to import. Defaults to an empty array.
1018+ * ` dependencies ` {Object} An object mapping bare specifiers to package keys.
1019+ Each key is the import name used in source code, and each value is the
1020+ corresponding package key in the ` packages ` object. Defaults to an empty
1021+ object.
10161022
10171023### Resolution algorithm
10181024
@@ -1022,9 +1028,9 @@ When a bare specifier is encountered:
10221028 if the file path is within any package's ` path ` .
102310292 . If the importing file is not within any mapped package, a
10241030 ` MODULE_NOT_FOUND ` error is thrown.
1025- 3 . Node.js searches the importing package 's ` dependencies ` array for an entry
1026- whose ` name ` matches the specifier's package name .
1027- 4 . If found, the specifier resolves to that dependency 's ` path ` .
1031+ 3 . Node.js looks up the specifier 's package name in the importing package's
1032+ ` dependencies ` object to find the corresponding package key .
1033+ 4 . If found, the specifier resolves to the target package 's ` path ` .
102810345 . If the package exists in the map but is not in ` dependencies ` , an
10291035 [ ` ERR_PACKAGE_MAP_ACCESS_DENIED ` ] [ ] error is thrown.
103010366 . If the package does not exist in the map at all, a
@@ -1046,31 +1052,34 @@ then used to resolve the final file path.
10461052
10471053### Multiple package versions
10481054
1049- Different packages can depend on different versions of the same package by
1050- using distinct keys:
1055+ Different packages can depend on different versions of the same package.
1056+ Because ` dependencies ` maps bare specifiers to package keys, two packages
1057+ can map the same specifier to different targets:
10511058
10521059``` json
10531060{
10541061 "packages" : {
10551062 "app" : {
10561063 "name" : " app" ,
10571064 "path" : " ./app" ,
1058- "dependencies" : [" component-v2" ]
1065+ "dependencies" : {
1066+ "component" : " component-v2"
1067+ }
10591068 },
10601069 "legacy" : {
10611070 "name" : " legacy" ,
10621071 "path" : " ./legacy" ,
1063- "dependencies" : [" component-v1" ]
1072+ "dependencies" : {
1073+ "component" : " component-v1"
1074+ }
10641075 },
10651076 "component-v1" : {
10661077 "name" : " component" ,
1067- "path" : " ./vendor/component-1.0.0" ,
1068- "dependencies" : []
1078+ "path" : " ./vendor/component-1.0.0"
10691079 },
10701080 "component-v2" : {
10711081 "name" : " component" ,
1072- "path" : " ./vendor/component-2.0.0" ,
1073- "dependencies" : []
1082+ "path" : " ./vendor/component-2.0.0"
10741083 }
10751084 }
10761085}
0 commit comments