@ms-cloudpack/config 0.38.21 → 0.38.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AppConfig } from '@ms-cloudpack/common-types';
|
|
2
2
|
/**
|
|
3
3
|
* Expand template variables in module resolution paths.
|
|
4
|
-
* Currently supports {configDir} to reference the configuration file's directory.
|
|
4
|
+
* Currently supports `{configDir}` to reference the configuration file's directory.
|
|
5
5
|
*/
|
|
6
6
|
export declare function expandModulePaths(params: {
|
|
7
7
|
appConfig: AppConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandModulePaths.d.ts","sourceRoot":"","sources":["../../src/readConfig/expandModulePaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"expandModulePaths.d.ts","sourceRoot":"","sources":["../../src/readConfig/expandModulePaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAK5D;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiC5F"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
const configDirTemplate = '{configDir}';
|
|
3
|
-
function countOccurrences(str, substring) {
|
|
4
|
-
let count = 0;
|
|
5
|
-
let index = 0;
|
|
6
|
-
while ((index = str.indexOf(substring, index)) !== -1) {
|
|
7
|
-
count++;
|
|
8
|
-
index += substring.length;
|
|
9
|
-
}
|
|
10
|
-
return count;
|
|
11
|
-
}
|
|
12
3
|
/**
|
|
13
4
|
* Expand template variables in module resolution paths.
|
|
14
|
-
* Currently supports {configDir} to reference the configuration file's directory.
|
|
5
|
+
* Currently supports `{configDir}` to reference the configuration file's directory.
|
|
15
6
|
*/
|
|
16
7
|
export function expandModulePaths(params) {
|
|
17
8
|
const { appConfig: { resolve }, configPath, } = params;
|
|
@@ -23,22 +14,17 @@ export function expandModulePaths(params) {
|
|
|
23
14
|
}
|
|
24
15
|
const configDir = path.dirname(configPath);
|
|
25
16
|
// Process each module path and expand template variables
|
|
26
|
-
resolve.modules = resolve.modules.map((
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return modulePath;
|
|
32
|
-
}
|
|
33
|
-
if (templateCount > 1) {
|
|
34
|
-
throw new Error(`Multiple template variables not allowed in the same path: "${modulePath}"`);
|
|
17
|
+
resolve.modules = resolve.modules.map((origModulePath) => {
|
|
18
|
+
let modulePath = origModulePath;
|
|
19
|
+
if (modulePath.startsWith(configDirTemplate)) {
|
|
20
|
+
// Replace template at start of path with actual directory
|
|
21
|
+
modulePath = modulePath.replace(configDirTemplate, configDir);
|
|
35
22
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
throw new Error(`${configDirTemplate} template variable
|
|
23
|
+
if (modulePath.includes(configDirTemplate)) {
|
|
24
|
+
// There were multiple occurrences, or it was not at the start
|
|
25
|
+
throw new Error(`${configDirTemplate} template variable is only allowed at the beginning of a \`resolve.modules\` path. Received: "${modulePath}"`);
|
|
39
26
|
}
|
|
40
|
-
|
|
41
|
-
return modulePath.replace(configDirTemplate, configDir);
|
|
27
|
+
return modulePath;
|
|
42
28
|
});
|
|
43
29
|
}
|
|
44
30
|
//# sourceMappingURL=expandModulePaths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expandModulePaths.js","sourceRoot":"","sources":["../../src/readConfig/expandModulePaths.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC
|
|
1
|
+
{"version":3,"file":"expandModulePaths.js","sourceRoot":"","sources":["../../src/readConfig/expandModulePaths.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAoD;IACpF,MAAM,EACJ,SAAS,EAAE,EAAE,OAAO,EAAE,EACtB,UAAU,GACX,GAAG,MAAM,CAAC;IAEX,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,8CAA8C,UAAU,GAAG,CAAC,CAAC;IAC/E,CAAC;IAED,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAE3C,yDAAyD;IACzD,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE;QACvD,IAAI,UAAU,GAAG,cAAc,CAAC;QAChC,IAAI,UAAU,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC7C,0DAA0D;YAC1D,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,UAAU,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC3C,8DAA8D;YAC9D,MAAM,IAAI,KAAK,CACb,GAAG,iBAAiB,iGAAiG,UAAU,GAAG,CACnI,CAAC;QACJ,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { AppConfig } from '@ms-cloudpack/common-types';\nimport path from 'path';\n\nconst configDirTemplate = '{configDir}';\n\n/**\n * Expand template variables in module resolution paths.\n * Currently supports `{configDir}` to reference the configuration file's directory.\n */\nexport function expandModulePaths(params: { appConfig: AppConfig; configPath: string }): void {\n const {\n appConfig: { resolve },\n configPath,\n } = params;\n\n if (!path.isAbsolute(configPath)) {\n throw new Error(`configPath must be an absolute path, got: \"${configPath}\"`);\n }\n\n if (!resolve?.modules) {\n return;\n }\n\n const configDir = path.dirname(configPath);\n\n // Process each module path and expand template variables\n resolve.modules = resolve.modules.map((origModulePath) => {\n let modulePath = origModulePath;\n if (modulePath.startsWith(configDirTemplate)) {\n // Replace template at start of path with actual directory\n modulePath = modulePath.replace(configDirTemplate, configDir);\n }\n\n if (modulePath.includes(configDirTemplate)) {\n // There were multiple occurrences, or it was not at the start\n throw new Error(\n `${configDirTemplate} template variable is only allowed at the beginning of a \\`resolve.modules\\` path. Received: \"${modulePath}\"`,\n );\n }\n\n return modulePath;\n });\n}\n"]}
|