MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / getModulePackageName

Function getModulePackageName

config/plugin.config.js:6–24  ·  view source on GitHub ↗
(module)

Source from the content-addressed store, hash-verified

4
5
6function getModulePackageName (module) {
7 if (!module.context) return null;
8 const nodeModulesPath = path.join(__dirname, '../node_modules/');
9
10 if (module.context.substring(0, nodeModulesPath.length) !== nodeModulesPath) {
11 return null;
12 }
13
14 const moduleRelativePath = module.context.substring(nodeModulesPath.length);
15 const [moduleDirName] = moduleRelativePath.split(path.sep);
16 let packageName = moduleDirName; // handle tree shaking
17
18 if (packageName && packageName.match('^_')) {
19 // eslint-disable-next-line prefer-destructuring
20 packageName = packageName.match(/^_(@?[^@]+)/)[1];
21 }
22
23 return packageName;
24}
25
26
27

Callers 2

webpackPluginFunction · 0.85
nameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected