1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = getModuleName;
|
---|
7 | {
|
---|
8 | const originalGetModuleName = getModuleName;
|
---|
9 |
|
---|
10 | exports.default = getModuleName = function getModuleName(rootOpts, pluginOpts) {
|
---|
11 | var _pluginOpts$moduleId, _pluginOpts$moduleIds, _pluginOpts$getModule, _pluginOpts$moduleRoo;
|
---|
12 |
|
---|
13 | return originalGetModuleName(rootOpts, {
|
---|
14 | moduleId: (_pluginOpts$moduleId = pluginOpts.moduleId) != null ? _pluginOpts$moduleId : rootOpts.moduleId,
|
---|
15 | moduleIds: (_pluginOpts$moduleIds = pluginOpts.moduleIds) != null ? _pluginOpts$moduleIds : rootOpts.moduleIds,
|
---|
16 | getModuleId: (_pluginOpts$getModule = pluginOpts.getModuleId) != null ? _pluginOpts$getModule : rootOpts.getModuleId,
|
---|
17 | moduleRoot: (_pluginOpts$moduleRoo = pluginOpts.moduleRoot) != null ? _pluginOpts$moduleRoo : rootOpts.moduleRoot
|
---|
18 | });
|
---|
19 | };
|
---|
20 | }
|
---|
21 |
|
---|
22 | function getModuleName(rootOpts, pluginOpts) {
|
---|
23 | const {
|
---|
24 | filename,
|
---|
25 | filenameRelative = filename,
|
---|
26 | sourceRoot = pluginOpts.moduleRoot
|
---|
27 | } = rootOpts;
|
---|
28 | const {
|
---|
29 | moduleId,
|
---|
30 | moduleIds = !!moduleId,
|
---|
31 | getModuleId,
|
---|
32 | moduleRoot = sourceRoot
|
---|
33 | } = pluginOpts;
|
---|
34 | if (!moduleIds) return null;
|
---|
35 |
|
---|
36 | if (moduleId != null && !getModuleId) {
|
---|
37 | return moduleId;
|
---|
38 | }
|
---|
39 |
|
---|
40 | let moduleName = moduleRoot != null ? moduleRoot + "/" : "";
|
---|
41 |
|
---|
42 | if (filenameRelative) {
|
---|
43 | const sourceRootReplacer = sourceRoot != null ? new RegExp("^" + sourceRoot + "/?") : "";
|
---|
44 | moduleName += filenameRelative.replace(sourceRootReplacer, "").replace(/\.(\w*?)$/, "");
|
---|
45 | }
|
---|
46 |
|
---|
47 | moduleName = moduleName.replace(/\\/g, "/");
|
---|
48 |
|
---|
49 | if (getModuleId) {
|
---|
50 | return getModuleId(moduleName) || moduleName;
|
---|
51 | } else {
|
---|
52 | return moduleName;
|
---|
53 | }
|
---|
54 | } |
---|