MCPcopy Index your code
hub / github.com/rollup/plugins / getPackageInfo

Function getPackageInfo

packages/node-resolve/src/util.js:42–165  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

40}
41
42export function getPackageInfo(options) {
43 const {
44 cache,
45 extensions,
46 pkg,
47 mainFields,
48 preserveSymlinks,
49 useBrowserOverrides,
50 rootDir,
51 ignoreSideEffectsForRoot
52 } = options;
53 let { pkgPath } = options;
54
55 if (cache.has(pkgPath)) {
56 return cache.get(pkgPath);
57 }
58
59 // browserify/resolve doesn't realpath paths returned in its packageFilter callback
60 if (!preserveSymlinks) {
61 pkgPath = realpathSync(pkgPath);
62 }
63
64 const pkgRoot = dirname(pkgPath);
65
66 const packageInfo = {
67 // copy as we are about to munge the `main` field of `pkg`.
68 packageJson: { ...pkg },
69
70 // path to package.json file
71 packageJsonPath: pkgPath,
72
73 // directory containing the package.json
74 root: pkgRoot,
75
76 // which main field was used during resolution of this module (main, module, or browser)
77 resolvedMainField: 'main',
78
79 // whether the browser map was used to resolve the entry point to this module
80 browserMappedMain: false,
81
82 // the entry point of the module with respect to the selected main field and any
83 // relevant browser mappings.
84 resolvedEntryPoint: ''
85 };
86
87 let overriddenMain = false;
88 for (let i = 0; i < mainFields.length; i++) {
89 const field = mainFields[i];
90 if (typeof pkg[field] === 'string') {
91 pkg.main = pkg[field];
92 packageInfo.resolvedMainField = field;
93 overriddenMain = true;
94 break;
95 }
96 }
97
98 const internalPackageInfo = {
99 cachedPkg: pkg,

Callers 1

filterFunction · 0.90

Calls 5

createFilterFunction · 0.90
hasMethod · 0.80
getMethod · 0.80
keysMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected