renovate 44.171.0 → 44.171.2
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.
- package/dist/instrumentation/reporting.js +5 -1
- package/dist/instrumentation/reporting.js.map +1 -1
- package/dist/modules/datasource/common.d.ts +4 -0
- package/dist/modules/datasource/common.js +16 -1
- package/dist/modules/datasource/common.js.map +1 -1
- package/dist/modules/datasource/crate/index.js +4 -1
- package/dist/modules/datasource/crate/index.js.map +1 -1
- package/dist/modules/datasource/custom/index.js +5 -1
- package/dist/modules/datasource/custom/index.js.map +1 -1
- package/dist/modules/datasource/custom/utils.js +2 -1
- package/dist/modules/datasource/custom/utils.js.map +1 -1
- package/dist/modules/datasource/docker/common.js +1 -1
- package/dist/modules/datasource/git-refs/base.js +2 -1
- package/dist/modules/datasource/git-refs/base.js.map +1 -1
- package/dist/modules/datasource/index.js +20 -10
- package/dist/modules/datasource/index.js.map +1 -1
- package/dist/modules/datasource/metadata.js +36 -9
- package/dist/modules/datasource/metadata.js.map +1 -1
- package/dist/modules/manager/bun/extract.js +7 -2
- package/dist/modules/manager/bun/extract.js.map +1 -1
- package/dist/modules/manager/fingerprint.generated.js +4 -4
- package/dist/modules/manager/fingerprint.generated.js.map +1 -1
- package/dist/modules/manager/npm/extract/index.js +3 -2
- package/dist/modules/manager/npm/extract/index.js.map +1 -1
- package/dist/modules/manager/npm/extract/post/monorepo.js +6 -3
- package/dist/modules/manager/npm/extract/post/monorepo.js.map +1 -1
- package/dist/modules/manager/npm/npmrc.js +162 -11
- package/dist/modules/manager/npm/npmrc.js.map +1 -1
- package/dist/modules/manager/npmrc.js +35 -0
- package/dist/modules/manager/npmrc.js.map +1 -0
- package/dist/modules/manager/pep621/processors/uv.js +9 -3
- package/dist/modules/manager/pep621/processors/uv.js.map +1 -1
- package/dist/modules/manager/pipenv/artifacts.js +16 -5
- package/dist/modules/manager/pipenv/artifacts.js.map +1 -1
- package/dist/util/cache/package/index.js +7 -4
- package/dist/util/cache/package/index.js.map +1 -1
- package/dist/util/cache/repository/http-cache.js +10 -0
- package/dist/util/cache/repository/http-cache.js.map +1 -1
- package/dist/util/cache/sanitize-key.js +63 -0
- package/dist/util/cache/sanitize-key.js.map +1 -0
- package/dist/util/git/auth.js +22 -2
- package/dist/util/git/auth.js.map +1 -1
- package/dist/util/git/index.d.ts +2 -0
- package/dist/util/git/index.js +1 -1
- package/dist/util/git/index.js.map +1 -1
- package/dist/util/host-rules.d.ts +33 -2
- package/dist/util/host-rules.js +237 -12
- package/dist/util/host-rules.js.map +1 -1
- package/dist/util/http/cache/abstract-http-cache-provider.js +17 -0
- package/dist/util/http/cache/abstract-http-cache-provider.js.map +1 -1
- package/dist/util/http/cache/memory-http-cache-provider.js +1 -0
- package/dist/util/http/cache/memory-http-cache-provider.js.map +1 -1
- package/dist/util/http/cache/persisted-headers.js +27 -0
- package/dist/util/http/cache/persisted-headers.js.map +1 -0
- package/dist/util/http/cache/repository-http-cache-provider.js +7 -4
- package/dist/util/http/cache/repository-http-cache-provider.js.map +1 -1
- package/dist/util/http/host-rules.js +2 -15
- package/dist/util/http/host-rules.js.map +1 -1
- package/dist/util/http/http.js +1 -1
- package/dist/util/jsonata.js +1 -1
- package/dist/util/merge-confidence/index.js +1 -1
- package/dist/util/url.d.ts +38 -0
- package/dist/util/url.js +100 -2
- package/dist/util/url.js.map +1 -1
- package/dist/workers/repository/cache.js +9 -1
- package/dist/workers/repository/cache.js.map +1 -1
- package/dist/workers/repository/init/merge.js +1 -1
- package/dist/workers/repository/init/merge.js.map +1 -1
- package/dist/workers/repository/onboarding/branch/rebase.js +1 -1
- package/dist/workers/repository/onboarding/pr/index.js +1 -1
- package/dist/workers/repository/process/extract-update.js +53 -5
- package/dist/workers/repository/process/extract-update.js.map +1 -1
- package/dist/workers/repository/process/fetch.js +2 -1
- package/dist/workers/repository/process/fetch.js.map +1 -1
- package/dist/workers/repository/process/lookup/digest.js +8 -4
- package/dist/workers/repository/process/lookup/digest.js.map +1 -1
- package/dist/workers/repository/process/lookup/index.js +13 -8
- package/dist/workers/repository/process/lookup/index.js.map +1 -1
- package/dist/workers/repository/update/branch/index.js +5 -3
- package/dist/workers/repository/update/branch/index.js.map +1 -1
- package/dist/workers/repository/updates/branch-name.js +5 -4
- package/dist/workers/repository/updates/branch-name.js.map +1 -1
- package/dist/workers/repository/updates/flatten.js +2 -2
- package/dist/workers/repository/updates/flatten.js.map +1 -1
- package/dist/workers/repository/updates/generate.js +5 -4
- package/dist/workers/repository/updates/generate.js.map +1 -1
- package/package.json +2 -2
- package/renovate-schema.json +2 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { regEx } from "../../../util/regex.js";
|
|
2
2
|
import { GlobalConfig } from "../../../config/global.js";
|
|
3
3
|
import { logger } from "../../../logger/index.js";
|
|
4
|
+
import { hasUrlCredentials } from "../../../util/url.js";
|
|
4
5
|
import { findLocalSiblingOrParent, readLocalFile } from "../../../util/fs/index.js";
|
|
5
6
|
import { parseNpmrc, renderNpmrc } from "./npmrc-parser.js";
|
|
6
|
-
import { isString } from "@sindresorhus/is";
|
|
7
|
+
import { isString, isUndefined } from "@sindresorhus/is";
|
|
7
8
|
//#region lib/modules/manager/npm/npmrc.ts
|
|
8
9
|
/**
|
|
9
10
|
* Mirrors npm's environment-reference grammar. Escape handling remains
|
|
@@ -50,6 +51,7 @@ function sanitizeRepoNpmrc(repoNpmrc, npmrcFileName) {
|
|
|
50
51
|
if (removedPackageLockSetting) logger.debug("Stripping package-lock setting from .npmrc");
|
|
51
52
|
if (removedEnvironmentVariableReferenceLine) logger.debug({ npmrcFileName }, "Stripping .npmrc file of lines with variables");
|
|
52
53
|
return {
|
|
54
|
+
fileName: npmrcFileName,
|
|
53
55
|
content: renderNpmrc(retainedLines),
|
|
54
56
|
detectedLineEnding: document.detectedLineEnding
|
|
55
57
|
};
|
|
@@ -61,35 +63,184 @@ function mergeNpmrcDocuments(configNpmrc, sanitizedRepoNpmrc) {
|
|
|
61
63
|
return `${configNpmrc}${configDocument.detectedLineEnding ?? sanitizedRepoNpmrc.detectedLineEnding ?? "\n"}${sanitizedRepoNpmrc.content}`;
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
66
|
+
* Whether the repository `.npmrc` is ignored in favour of a configured `npmrc` without `npmrcMerge`.
|
|
67
|
+
*/
|
|
68
|
+
function isRepoNpmrcIgnored(config) {
|
|
69
|
+
return isString(config.npmrc) && !config.npmrcMerge;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
64
72
|
* Combines the configured `npmrc` with the sanitized repository `.npmrc`, honouring `npmrcMerge`.
|
|
65
73
|
*
|
|
66
74
|
* @returns the `npmrc` to use for the package file, or `undefined` when there is neither
|
|
67
75
|
*/
|
|
68
|
-
function applyConfigNpmrc(config, repoNpmrc
|
|
76
|
+
function applyConfigNpmrc(config, repoNpmrc) {
|
|
69
77
|
if (!repoNpmrc) return isString(config.npmrc) ? config.npmrc : void 0;
|
|
70
|
-
if (
|
|
71
|
-
logger.info({ npmrcFileName }, "Repo .npmrc file is ignored due to config.npmrc with config.npmrcMerge=false");
|
|
78
|
+
if (isRepoNpmrcIgnored(config)) {
|
|
79
|
+
logger.info({ npmrcFileName: repoNpmrc.fileName }, "Repo .npmrc file is ignored due to config.npmrc with config.npmrcMerge=false");
|
|
72
80
|
return config.npmrc;
|
|
73
81
|
}
|
|
74
82
|
return mergeNpmrcDocuments(config.npmrc, repoNpmrc);
|
|
75
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* The npm settings holding a secret: the auth settings, and `key` with an inline client key; `username`, `email`, `cert`, `certfile` and `keyfile` are not.
|
|
86
|
+
*
|
|
87
|
+
* @see https://docs.npmjs.com/cli/configuring-npm/npmrc#auth-related-configuration
|
|
88
|
+
*/
|
|
89
|
+
const credentialKeyRegex = regEx(/(?:^|:)(?:_auth|_authToken|_password|key)$/i);
|
|
90
|
+
const singleEnvironmentVariableReferenceRegex = regEx(/^\$\{[a-z_][a-z\d_]*\}$/i);
|
|
91
|
+
/**
|
|
92
|
+
* Whether `value` is exactly one `${NAME}` environment variable reference.
|
|
93
|
+
*/
|
|
94
|
+
function isSingleEnvironmentVariableReference(value) {
|
|
95
|
+
return isString(value) && singleEnvironmentVariableReferenceRegex.test(value);
|
|
96
|
+
}
|
|
97
|
+
function hasRegistryUrlCredentials(value) {
|
|
98
|
+
if (!isString(value)) return false;
|
|
99
|
+
return hasUrlCredentials(value.startsWith("//") ? `https:${value}` : value);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Whether the registry URL of a `//host/:setting` or `https://host/:setting` key, the part before its last `:`, carries credentials.
|
|
103
|
+
*/
|
|
104
|
+
function hasKeyUrlCredentials(key) {
|
|
105
|
+
const separatorIndex = key.lastIndexOf(":");
|
|
106
|
+
if (separatorIndex === -1) return false;
|
|
107
|
+
return hasRegistryUrlCredentials(key.slice(0, separatorIndex));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Whether the sanitized repository `.npmrc` carries credentials: an `_auth`, `_authToken`, `_password` or `key` setting other than exactly one `${NAME}` reference, or a URL with credentials in its userinfo, in a setting's key or value.
|
|
111
|
+
*/
|
|
112
|
+
function hasNpmrcCredentials(repoNpmrc) {
|
|
113
|
+
const settings = parseNpmrc(repoNpmrc.content).lines.filter((line) => line.type === "setting");
|
|
114
|
+
for (const line of settings) {
|
|
115
|
+
if (hasKeyUrlCredentials(line.key)) return true;
|
|
116
|
+
if (isSingleEnvironmentVariableReference(line.value)) continue;
|
|
117
|
+
if (credentialKeyRegex.test(line.key) || hasRegistryUrlCredentials(line.value)) return true;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Matches the characters which start a comment in an `.npmrc`, at the start of a line or inline.
|
|
123
|
+
*/
|
|
124
|
+
const npmrcCommentRegex = regEx(/[#;]/);
|
|
125
|
+
/**
|
|
126
|
+
* Whether the repository `.npmrc` has content `hasNpmrcCredentials()` does not read: a `#` or `;` anywhere, which may start a comment, or a non-blank line which is neither a setting nor a section.
|
|
127
|
+
*/
|
|
128
|
+
function hasUnreadContent(repoNpmrc) {
|
|
129
|
+
return npmrcCommentRegex.test(repoNpmrc.content) || parseNpmrc(repoNpmrc.content).lines.some((line) => line.type === "other" && !!line.raw.trim());
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns why `repoNpmrc` is not cached, or `null` when it is cached.
|
|
133
|
+
*/
|
|
134
|
+
function getUncachedNpmrcReason(repoNpmrc) {
|
|
135
|
+
if (hasNpmrcCredentials(repoNpmrc)) return "credentials";
|
|
136
|
+
if (hasUnreadContent(repoNpmrc)) return "unread-content";
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns shallow copies of the package files without their `npmrc`, as they are put into the repository cache.
|
|
141
|
+
*
|
|
142
|
+
* A repository `.npmrc` carrying credentials, or with a comment or another line which is not checked for credentials, is dropped as well and the copy is marked with its `uncachedNpmrcFileName`. So is a copy of a package file with an `npmrcFileName` but without `npmrc`, whose repository `.npmrc` cannot be read.
|
|
143
|
+
*/
|
|
144
|
+
function stripNpmrc(packageFiles) {
|
|
145
|
+
const result = [];
|
|
146
|
+
const reasonByContent = /* @__PURE__ */ new Map();
|
|
147
|
+
for (const packageFile of packageFiles) {
|
|
148
|
+
const copy = { ...packageFile };
|
|
149
|
+
delete copy.npmrc;
|
|
150
|
+
const npmrcFileName = copy.managerData?.npmrcFileName;
|
|
151
|
+
if (npmrcFileName && !isString(packageFile.npmrc)) copy.managerData = {
|
|
152
|
+
...copy.managerData,
|
|
153
|
+
uncachedNpmrcFileName: npmrcFileName
|
|
154
|
+
};
|
|
155
|
+
const repoNpmrc = copy.managerData?.repoNpmrc;
|
|
156
|
+
if (repoNpmrc) {
|
|
157
|
+
let reason = reasonByContent.get(repoNpmrc.content);
|
|
158
|
+
if (reason === void 0) {
|
|
159
|
+
reason = getUncachedNpmrcReason(repoNpmrc);
|
|
160
|
+
reasonByContent.set(repoNpmrc.content, reason);
|
|
161
|
+
}
|
|
162
|
+
if (reason === "credentials") logger.once.warn({ npmrcFileName: repoNpmrc.fileName }, "A repository .npmrc contains credentials, which are not cached: configure them through hostRules or the npmrc option instead");
|
|
163
|
+
else if (reason === "unread-content") logger.once.debug({ npmrcFileName: repoNpmrc.fileName }, "A repository .npmrc contains comments or lines which are not settings, so it is not cached");
|
|
164
|
+
if (reason) {
|
|
165
|
+
copy.managerData = {
|
|
166
|
+
...copy.managerData,
|
|
167
|
+
uncachedNpmrcFileName: repoNpmrc.fileName
|
|
168
|
+
};
|
|
169
|
+
delete copy.managerData.repoNpmrc;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
result.push(copy);
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Whether `packageFile` was extracted with an `npmrc` from `resolveNpmrc()`, which also sets its `npmrcFileName`, `null` without a repository `.npmrc`.
|
|
178
|
+
*/
|
|
179
|
+
function hasResolvedNpmrc(packageFile) {
|
|
180
|
+
return !isUndefined(packageFile.managerData?.npmrcFileName);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Returns shallow copies of cached package files with their `npmrc` rebuilt from the cached repository `.npmrc` and the config, or read from disk again for a file with an `uncachedNpmrcFileName`.
|
|
184
|
+
* A package file extracted without `npmrc`, such as a `pnpm-workspace.yaml` or `.yarnrc.yml` catalog, is copied without one.
|
|
185
|
+
*/
|
|
186
|
+
async function restoreNpmrc(packageFiles, config) {
|
|
187
|
+
const result = [];
|
|
188
|
+
const npmrcByFileName = /* @__PURE__ */ new Map();
|
|
189
|
+
for (const packageFile of packageFiles) {
|
|
190
|
+
if (!hasResolvedNpmrc(packageFile)) {
|
|
191
|
+
result.push({ ...packageFile });
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
let npmrc;
|
|
195
|
+
const uncachedNpmrcFileName = packageFile.managerData?.uncachedNpmrcFileName;
|
|
196
|
+
if (uncachedNpmrcFileName) {
|
|
197
|
+
if (!npmrcByFileName.has(uncachedNpmrcFileName)) {
|
|
198
|
+
const read = await readRepoNpmrc(uncachedNpmrcFileName, config);
|
|
199
|
+
npmrcByFileName.set(uncachedNpmrcFileName, read.npmrc);
|
|
200
|
+
}
|
|
201
|
+
npmrc = npmrcByFileName.get(uncachedNpmrcFileName);
|
|
202
|
+
} else npmrc = applyConfigNpmrc(config, packageFile.managerData?.repoNpmrc);
|
|
203
|
+
result.push({
|
|
204
|
+
...packageFile,
|
|
205
|
+
npmrc
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Whether any of the cached package files has an `uncachedNpmrcFileName`.
|
|
212
|
+
*/
|
|
213
|
+
function hasUncachedNpmrc(packageFiles) {
|
|
214
|
+
return packageFiles.some((packageFile) => !!packageFile.managerData?.uncachedNpmrcFileName);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Reads and sanitizes the repository `.npmrc` and combines it with the configured `npmrc`.
|
|
218
|
+
*
|
|
219
|
+
* @returns the `npmrc` to use, `undefined` when the repository `.npmrc` cannot be read, and the sanitized repository `.npmrc` when it is readable and not ignored
|
|
220
|
+
*/
|
|
221
|
+
async function readRepoNpmrc(npmrcFileName, config) {
|
|
222
|
+
const content = await readLocalFile(npmrcFileName, "utf8");
|
|
223
|
+
if (!isString(content)) return { npmrc: void 0 };
|
|
224
|
+
const repoNpmrc = sanitizeRepoNpmrc(content, npmrcFileName);
|
|
225
|
+
const npmrc = applyConfigNpmrc(config, repoNpmrc);
|
|
226
|
+
if (isRepoNpmrcIgnored(config)) return { npmrc };
|
|
227
|
+
return {
|
|
228
|
+
npmrc,
|
|
229
|
+
repoNpmrc
|
|
230
|
+
};
|
|
231
|
+
}
|
|
76
232
|
async function resolveNpmrc(packageFile, config) {
|
|
77
233
|
const npmrcFileName = await findLocalSiblingOrParent(packageFile, ".npmrc");
|
|
78
234
|
if (!npmrcFileName) return {
|
|
79
235
|
npmrc: applyConfigNpmrc(config, void 0),
|
|
80
236
|
npmrcFileName
|
|
81
237
|
};
|
|
82
|
-
const repoNpmrcContent = await readLocalFile(npmrcFileName, "utf8");
|
|
83
|
-
if (!isString(repoNpmrcContent)) return {
|
|
84
|
-
npmrc: void 0,
|
|
85
|
-
npmrcFileName
|
|
86
|
-
};
|
|
87
238
|
return {
|
|
88
|
-
|
|
239
|
+
...await readRepoNpmrc(npmrcFileName, config),
|
|
89
240
|
npmrcFileName
|
|
90
241
|
};
|
|
91
242
|
}
|
|
92
243
|
//#endregion
|
|
93
|
-
export { applyConfigNpmrc, resolveNpmrc };
|
|
244
|
+
export { applyConfigNpmrc, hasNpmrcCredentials, hasUncachedNpmrc, resolveNpmrc, restoreNpmrc, stripNpmrc };
|
|
94
245
|
|
|
95
246
|
//# sourceMappingURL=npmrc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"npmrc.js","names":[],"sources":["../../../../lib/modules/manager/npm/npmrc.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { logger } from '../../../logger/index.ts';\nimport {\n findLocalSiblingOrParent,\n readLocalFile,\n} from '../../../util/fs/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { parseNpmrc, renderNpmrc } from './npmrc-parser.ts';\nimport type {\n NpmrcConfig,\n NpmrcLine,\n NpmrcLineEnding,\n NpmrcResult,\n NpmrcSettingLine,\n SanitizedRepoNpmrc,\n} from './types.ts';\n\n/**\n * Mirrors npm's environment-reference grammar. Escape handling remains\n * procedural because RE2 does not support lookbehind.\n */\nconst environmentVariableReferenceRegex = regEx(\n // oxlint-disable-next-line prefer-named-capture-group -- Only the full match and its position are used.\n /\\$\\{([^${}?]+)(\\?)?\\}/g,\n);\n\nfunction containsEnvironmentVariableReference(value: unknown): boolean {\n if (!isString(value)) {\n return false;\n }\n\n for (const match of value.matchAll(environmentVariableReferenceRegex)) {\n let escapeCount = 0;\n let escapeIndex = match.index - 1;\n while (value[escapeIndex] === '\\\\') {\n escapeCount += 1;\n escapeIndex -= 1;\n }\n\n if (escapeCount % 2 === 0) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction hasEnvironmentVariableReference(line: NpmrcSettingLine): boolean {\n return (\n containsEnvironmentVariableReference(line.key) ||\n containsEnvironmentVariableReference(line.value)\n );\n}\n\nfunction sanitizeRepoNpmrc(\n repoNpmrc: string,\n npmrcFileName: string,\n): SanitizedRepoNpmrc {\n const document = parseNpmrc(repoNpmrc);\n const retainedLines: NpmrcLine[] = [];\n const allowEnvironmentVariableReferences = GlobalConfig.get('exposeAllEnv');\n let removedEnvironmentVariableReferenceLine = false;\n let removedPackageLockSetting = false;\n\n for (const line of document.lines) {\n if (line.type !== 'setting' || line.section !== null) {\n retainedLines.push(line);\n continue;\n }\n\n if (line.key === 'package-lock') {\n removedPackageLockSetting = true;\n continue;\n }\n\n if (\n !allowEnvironmentVariableReferences &&\n hasEnvironmentVariableReference(line)\n ) {\n removedEnvironmentVariableReferenceLine = true;\n continue;\n }\n\n retainedLines.push(line);\n }\n\n if (removedPackageLockSetting) {\n logger.debug('Stripping package-lock setting from .npmrc');\n }\n\n if (removedEnvironmentVariableReferenceLine) {\n logger.debug(\n { npmrcFileName },\n 'Stripping .npmrc file of lines with variables',\n );\n }\n\n return {\n content: renderNpmrc(retainedLines),\n detectedLineEnding: document.detectedLineEnding,\n };\n}\n\nfunction mergeNpmrcDocuments(\n configNpmrc: string | undefined,\n sanitizedRepoNpmrc: SanitizedRepoNpmrc,\n): string {\n if (!configNpmrc) {\n return sanitizedRepoNpmrc.content;\n }\n\n const configDocument = parseNpmrc(configNpmrc);\n if (configDocument.trailingLineEnding) {\n return `${configNpmrc}${sanitizedRepoNpmrc.content}`;\n }\n\n const separator: Exclude<NpmrcLineEnding, ''> =\n configDocument.detectedLineEnding ??\n sanitizedRepoNpmrc.detectedLineEnding ??\n '\\n';\n\n return `${configNpmrc}${separator}${sanitizedRepoNpmrc.content}`;\n}\n\n/**\n * Combines the configured `npmrc` with the sanitized repository `.npmrc`, honouring `npmrcMerge`.\n *\n * @returns the `npmrc` to use for the package file, or `undefined` when there is neither\n */\nexport function applyConfigNpmrc(\n config: NpmrcConfig,\n repoNpmrc: SanitizedRepoNpmrc | undefined,\n npmrcFileName?: string | null,\n): string | undefined {\n if (!repoNpmrc) {\n return isString(config.npmrc) ? config.npmrc : undefined;\n }\n\n if (isString(config.npmrc) && !config.npmrcMerge) {\n logger.info(\n { npmrcFileName },\n 'Repo .npmrc file is ignored due to config.npmrc with config.npmrcMerge=false',\n );\n\n return config.npmrc;\n }\n\n return mergeNpmrcDocuments(config.npmrc, repoNpmrc);\n}\n\nexport async function resolveNpmrc(\n packageFile: string,\n config: NpmrcConfig,\n): Promise<NpmrcResult> {\n const npmrcFileName = await findLocalSiblingOrParent(packageFile, '.npmrc');\n if (!npmrcFileName) {\n return {\n npmrc: applyConfigNpmrc(config, undefined),\n npmrcFileName,\n };\n }\n\n const repoNpmrcContent = await readLocalFile(npmrcFileName, 'utf8');\n\n if (!isString(repoNpmrcContent)) {\n return { npmrc: undefined, npmrcFileName };\n }\n\n const repoNpmrc = sanitizeRepoNpmrc(repoNpmrcContent, npmrcFileName);\n return {\n npmrc: applyConfigNpmrc(config, repoNpmrc, npmrcFileName),\n npmrcFileName,\n };\n}\n"],"mappings":";;;;;;;;;;;AAsBA,MAAM,oCAAoC,MAExC,wBACF;AAEA,SAAS,qCAAqC,OAAyB;CACrE,IAAI,CAAC,SAAS,KAAK,GACjB,OAAO;CAGT,KAAK,MAAM,SAAS,MAAM,SAAS,iCAAiC,GAAG;EACrE,IAAI,cAAc;EAClB,IAAI,cAAc,MAAM,QAAQ;EAChC,OAAO,MAAM,iBAAiB,MAAM;GAClC,eAAe;GACf,eAAe;EACjB;EAEA,IAAI,cAAc,MAAM,GACtB,OAAO;CAEX;CAEA,OAAO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B,aACA,QACsB;CACtB,MAAM,gBAAgB,MAAM,yBAAyB,aAAa,QAAQ;CAC1E,IAAI,CAAC,eACH,OAAO;EACL,OAAO,iBAAiB,QAAQ,KAAA,CAAS;EACzC;CACF;CAGF,MAAM,mBAAmB,MAAM,cAAc,eAAe,MAAM;CAElE,IAAI,CAAC,SAAS,gBAAgB,GAC5B,OAAO;EAAE,OAAO,KAAA;EAAW;CAAc;CAI3C,OAAO;EACL,OAAO,iBAAiB,QAFR,kBAAkB,kBAAkB,aAEZ,GAAG,aAAa;EACxD;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"npmrc.js","names":[],"sources":["../../../../lib/modules/manager/npm/npmrc.ts"],"sourcesContent":["import { isString, isUndefined } from '@sindresorhus/is';\nimport { GlobalConfig } from '../../../config/global.ts';\nimport { logger } from '../../../logger/index.ts';\nimport {\n findLocalSiblingOrParent,\n readLocalFile,\n} from '../../../util/fs/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { hasUrlCredentials } from '../../../util/url.ts';\nimport type { NpmrcPackageFile } from '../types.ts';\nimport { parseNpmrc, renderNpmrc } from './npmrc-parser.ts';\nimport type {\n NpmManagerData,\n NpmrcConfig,\n NpmrcLine,\n NpmrcLineEnding,\n NpmrcResult,\n NpmrcSettingLine,\n SanitizedRepoNpmrc,\n} from './types.ts';\n\n/**\n * Mirrors npm's environment-reference grammar. Escape handling remains\n * procedural because RE2 does not support lookbehind.\n */\nconst environmentVariableReferenceRegex = regEx(\n // oxlint-disable-next-line prefer-named-capture-group -- Only the full match and its position are used.\n /\\$\\{([^${}?]+)(\\?)?\\}/g,\n);\n\nfunction containsEnvironmentVariableReference(value: unknown): boolean {\n if (!isString(value)) {\n return false;\n }\n\n for (const match of value.matchAll(environmentVariableReferenceRegex)) {\n let escapeCount = 0;\n let escapeIndex = match.index - 1;\n while (value[escapeIndex] === '\\\\') {\n escapeCount += 1;\n escapeIndex -= 1;\n }\n\n if (escapeCount % 2 === 0) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction hasEnvironmentVariableReference(line: NpmrcSettingLine): boolean {\n return (\n containsEnvironmentVariableReference(line.key) ||\n containsEnvironmentVariableReference(line.value)\n );\n}\n\nfunction sanitizeRepoNpmrc(\n repoNpmrc: string,\n npmrcFileName: string,\n): SanitizedRepoNpmrc {\n const document = parseNpmrc(repoNpmrc);\n const retainedLines: NpmrcLine[] = [];\n const allowEnvironmentVariableReferences = GlobalConfig.get('exposeAllEnv');\n let removedEnvironmentVariableReferenceLine = false;\n let removedPackageLockSetting = false;\n\n for (const line of document.lines) {\n if (line.type !== 'setting' || line.section !== null) {\n retainedLines.push(line);\n continue;\n }\n\n if (line.key === 'package-lock') {\n removedPackageLockSetting = true;\n continue;\n }\n\n if (\n !allowEnvironmentVariableReferences &&\n hasEnvironmentVariableReference(line)\n ) {\n removedEnvironmentVariableReferenceLine = true;\n continue;\n }\n\n retainedLines.push(line);\n }\n\n if (removedPackageLockSetting) {\n logger.debug('Stripping package-lock setting from .npmrc');\n }\n\n if (removedEnvironmentVariableReferenceLine) {\n logger.debug(\n { npmrcFileName },\n 'Stripping .npmrc file of lines with variables',\n );\n }\n\n return {\n fileName: npmrcFileName,\n content: renderNpmrc(retainedLines),\n detectedLineEnding: document.detectedLineEnding,\n };\n}\n\nfunction mergeNpmrcDocuments(\n configNpmrc: string | undefined,\n sanitizedRepoNpmrc: SanitizedRepoNpmrc,\n): string {\n if (!configNpmrc) {\n return sanitizedRepoNpmrc.content;\n }\n\n const configDocument = parseNpmrc(configNpmrc);\n if (configDocument.trailingLineEnding) {\n return `${configNpmrc}${sanitizedRepoNpmrc.content}`;\n }\n\n const separator: Exclude<NpmrcLineEnding, ''> =\n configDocument.detectedLineEnding ??\n sanitizedRepoNpmrc.detectedLineEnding ??\n '\\n';\n\n return `${configNpmrc}${separator}${sanitizedRepoNpmrc.content}`;\n}\n\n/**\n * Whether the repository `.npmrc` is ignored in favour of a configured `npmrc` without `npmrcMerge`.\n */\nfunction isRepoNpmrcIgnored(config: NpmrcConfig): boolean {\n return isString(config.npmrc) && !config.npmrcMerge;\n}\n\n/**\n * Combines the configured `npmrc` with the sanitized repository `.npmrc`, honouring `npmrcMerge`.\n *\n * @returns the `npmrc` to use for the package file, or `undefined` when there is neither\n */\nexport function applyConfigNpmrc(\n config: NpmrcConfig,\n repoNpmrc: SanitizedRepoNpmrc | undefined,\n): string | undefined {\n if (!repoNpmrc) {\n return isString(config.npmrc) ? config.npmrc : undefined;\n }\n\n if (isRepoNpmrcIgnored(config)) {\n logger.info(\n { npmrcFileName: repoNpmrc.fileName },\n 'Repo .npmrc file is ignored due to config.npmrc with config.npmrcMerge=false',\n );\n\n return config.npmrc;\n }\n\n return mergeNpmrcDocuments(config.npmrc, repoNpmrc);\n}\n\n/**\n * The npm settings holding a secret: the auth settings, and `key` with an inline client key; `username`, `email`, `cert`, `certfile` and `keyfile` are not.\n *\n * @see https://docs.npmjs.com/cli/configuring-npm/npmrc#auth-related-configuration\n */\nconst credentialKeyRegex = regEx(/(?:^|:)(?:_auth|_authToken|_password|key)$/i);\n\nconst singleEnvironmentVariableReferenceRegex = regEx(\n /^\\$\\{[a-z_][a-z\\d_]*\\}$/i,\n);\n\n/**\n * Whether `value` is exactly one `${NAME}` environment variable reference.\n */\nfunction isSingleEnvironmentVariableReference(value: unknown): boolean {\n return isString(value) && singleEnvironmentVariableReferenceRegex.test(value);\n}\n\nfunction hasRegistryUrlCredentials(value: unknown): boolean {\n if (!isString(value)) {\n return false;\n }\n // a protocol-relative registry URL is given a scheme, which `hasUrlCredentials()` looks for\n return hasUrlCredentials(value.startsWith('//') ? `https:${value}` : value);\n}\n\n/**\n * Whether the registry URL of a `//host/:setting` or `https://host/:setting` key, the part before its last `:`, carries credentials.\n */\nfunction hasKeyUrlCredentials(key: string): boolean {\n const separatorIndex = key.lastIndexOf(':');\n if (separatorIndex === -1) {\n return false;\n }\n return hasRegistryUrlCredentials(key.slice(0, separatorIndex));\n}\n\n/**\n * Whether the sanitized repository `.npmrc` carries credentials: an `_auth`, `_authToken`, `_password` or `key` setting other than exactly one `${NAME}` reference, or a URL with credentials in its userinfo, in a setting's key or value.\n */\nexport function hasNpmrcCredentials(repoNpmrc: SanitizedRepoNpmrc): boolean {\n const settings = parseNpmrc(repoNpmrc.content).lines.filter(\n (line): line is NpmrcSettingLine => line.type === 'setting',\n );\n for (const line of settings) {\n if (hasKeyUrlCredentials(line.key)) {\n return true;\n }\n // an environment variable reference is only replaced when the `.npmrc` is used, so the stored value is not a credential\n if (isSingleEnvironmentVariableReference(line.value)) {\n continue;\n }\n if (\n credentialKeyRegex.test(line.key) ||\n hasRegistryUrlCredentials(line.value)\n ) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Matches the characters which start a comment in an `.npmrc`, at the start of a line or inline.\n */\nconst npmrcCommentRegex = regEx(/[#;]/);\n\n/**\n * Whether the repository `.npmrc` has content `hasNpmrcCredentials()` does not read: a `#` or `;` anywhere, which may start a comment, or a non-blank line which is neither a setting nor a section.\n */\nfunction hasUnreadContent(repoNpmrc: SanitizedRepoNpmrc): boolean {\n return (\n npmrcCommentRegex.test(repoNpmrc.content) ||\n parseNpmrc(repoNpmrc.content).lines.some(\n (line) => line.type === 'other' && !!line.raw.trim(),\n )\n );\n}\n\n/**\n * Why a repository `.npmrc` is not cached: it carries credentials, or has content which is not checked for credentials.\n */\ntype UncachedNpmrcReason = 'credentials' | 'unread-content';\n\n/**\n * Returns why `repoNpmrc` is not cached, or `null` when it is cached.\n */\nfunction getUncachedNpmrcReason(\n repoNpmrc: SanitizedRepoNpmrc,\n): UncachedNpmrcReason | null {\n if (hasNpmrcCredentials(repoNpmrc)) {\n return 'credentials';\n }\n if (hasUnreadContent(repoNpmrc)) {\n return 'unread-content';\n }\n return null;\n}\n\n/**\n * Returns shallow copies of the package files without their `npmrc`, as they are put into the repository cache.\n *\n * A repository `.npmrc` carrying credentials, or with a comment or another line which is not checked for credentials, is dropped as well and the copy is marked with its `uncachedNpmrcFileName`. So is a copy of a package file with an `npmrcFileName` but without `npmrc`, whose repository `.npmrc` cannot be read.\n */\nexport function stripNpmrc(\n packageFiles: NpmrcPackageFile<NpmManagerData>[],\n): NpmrcPackageFile<NpmManagerData>[] {\n const result: NpmrcPackageFile<NpmManagerData>[] = [];\n // the workspaces of a monorepo share one `.npmrc`, which is classified once\n const reasonByContent = new Map<string, UncachedNpmrcReason | null>();\n for (const packageFile of packageFiles) {\n const copy = { ...packageFile };\n delete copy.npmrc;\n // read from disk again, so that the configured `npmrc` is not used in its place when the package file is restored\n const npmrcFileName = copy.managerData?.npmrcFileName;\n if (npmrcFileName && !isString(packageFile.npmrc)) {\n copy.managerData = {\n ...copy.managerData,\n uncachedNpmrcFileName: npmrcFileName,\n };\n }\n const repoNpmrc = copy.managerData?.repoNpmrc;\n if (repoNpmrc) {\n let reason = reasonByContent.get(repoNpmrc.content);\n if (reason === undefined) {\n reason = getUncachedNpmrcReason(repoNpmrc);\n reasonByContent.set(repoNpmrc.content, reason);\n }\n if (reason === 'credentials') {\n logger.once.warn(\n { npmrcFileName: repoNpmrc.fileName },\n 'A repository .npmrc contains credentials, which are not cached: configure them through hostRules or the npmrc option instead',\n );\n } else if (reason === 'unread-content') {\n logger.once.debug(\n { npmrcFileName: repoNpmrc.fileName },\n 'A repository .npmrc contains comments or lines which are not settings, so it is not cached',\n );\n }\n if (reason) {\n copy.managerData = {\n ...copy.managerData,\n uncachedNpmrcFileName: repoNpmrc.fileName,\n };\n delete copy.managerData.repoNpmrc;\n }\n }\n result.push(copy);\n }\n return result;\n}\n\n/**\n * Whether `packageFile` was extracted with an `npmrc` from `resolveNpmrc()`, which also sets its `npmrcFileName`, `null` without a repository `.npmrc`.\n */\nfunction hasResolvedNpmrc(\n packageFile: NpmrcPackageFile<NpmManagerData>,\n): boolean {\n return !isUndefined(packageFile.managerData?.npmrcFileName);\n}\n\n/**\n * Returns shallow copies of cached package files with their `npmrc` rebuilt from the cached repository `.npmrc` and the config, or read from disk again for a file with an `uncachedNpmrcFileName`.\n * A package file extracted without `npmrc`, such as a `pnpm-workspace.yaml` or `.yarnrc.yml` catalog, is copied without one.\n */\nexport async function restoreNpmrc(\n packageFiles: NpmrcPackageFile<NpmManagerData>[],\n config: NpmrcConfig,\n): Promise<NpmrcPackageFile<NpmManagerData>[]> {\n const result: NpmrcPackageFile<NpmManagerData>[] = [];\n // the workspaces of a monorepo share one `.npmrc`, which is read once\n const npmrcByFileName = new Map<string, string | undefined>();\n for (const packageFile of packageFiles) {\n if (!hasResolvedNpmrc(packageFile)) {\n result.push({ ...packageFile });\n continue;\n }\n let npmrc: string | undefined;\n const uncachedNpmrcFileName =\n packageFile.managerData?.uncachedNpmrcFileName;\n if (uncachedNpmrcFileName) {\n if (!npmrcByFileName.has(uncachedNpmrcFileName)) {\n const read = await readRepoNpmrc(uncachedNpmrcFileName, config);\n npmrcByFileName.set(uncachedNpmrcFileName, read.npmrc);\n }\n npmrc = npmrcByFileName.get(uncachedNpmrcFileName);\n } else {\n npmrc = applyConfigNpmrc(config, packageFile.managerData?.repoNpmrc);\n }\n result.push({ ...packageFile, npmrc });\n }\n return result;\n}\n\n/**\n * Whether any of the cached package files has an `uncachedNpmrcFileName`.\n */\nexport function hasUncachedNpmrc(\n packageFiles: NpmrcPackageFile<NpmManagerData>[],\n): boolean {\n return packageFiles.some(\n (packageFile) => !!packageFile.managerData?.uncachedNpmrcFileName,\n );\n}\n\n/**\n * Reads and sanitizes the repository `.npmrc` and combines it with the configured `npmrc`.\n *\n * @returns the `npmrc` to use, `undefined` when the repository `.npmrc` cannot be read, and the sanitized repository `.npmrc` when it is readable and not ignored\n */\nasync function readRepoNpmrc(\n npmrcFileName: string,\n config: NpmrcConfig,\n): Promise<Omit<NpmrcResult, 'npmrcFileName'>> {\n const content = await readLocalFile(npmrcFileName, 'utf8');\n if (!isString(content)) {\n return { npmrc: undefined };\n }\n\n const repoNpmrc = sanitizeRepoNpmrc(content, npmrcFileName);\n const npmrc = applyConfigNpmrc(config, repoNpmrc);\n if (isRepoNpmrcIgnored(config)) {\n return { npmrc };\n }\n return { npmrc, repoNpmrc };\n}\n\nexport async function resolveNpmrc(\n packageFile: string,\n config: NpmrcConfig,\n): Promise<NpmrcResult> {\n const npmrcFileName = await findLocalSiblingOrParent(packageFile, '.npmrc');\n if (!npmrcFileName) {\n return {\n npmrc: applyConfigNpmrc(config, undefined),\n npmrcFileName,\n };\n }\n\n return { ...(await readRepoNpmrc(npmrcFileName, config)), npmrcFileName };\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,MAAM,oCAAoC,MAExC,wBACF;AAEA,SAAS,qCAAqC,OAAyB;CACrE,IAAI,CAAC,SAAS,KAAK,GACjB,OAAO;CAGT,KAAK,MAAM,SAAS,MAAM,SAAS,iCAAiC,GAAG;EACrE,IAAI,cAAc;EAClB,IAAI,cAAc,MAAM,QAAQ;EAChC,OAAO,MAAM,iBAAiB,MAAM;GAClC,eAAe;GACf,eAAe;EACjB;EAEA,IAAI,cAAc,MAAM,GACtB,OAAO;CAEX;CAEA,OAAO;AACT;AAEA,SAAS,gCAAgC,MAAiC;CACxE,OACE,qCAAqC,KAAK,GAAG,KAC7C,qCAAqC,KAAK,KAAK;AAEnD;AAEA,SAAS,kBACP,WACA,eACoB;CACpB,MAAM,WAAW,WAAW,SAAS;CACrC,MAAM,gBAA6B,CAAC;CACpC,MAAM,qCAAqC,aAAa,IAAI,cAAc;CAC1E,IAAI,0CAA0C;CAC9C,IAAI,4BAA4B;CAEhC,KAAK,MAAM,QAAQ,SAAS,OAAO;EACjC,IAAI,KAAK,SAAS,aAAa,KAAK,YAAY,MAAM;GACpD,cAAc,KAAK,IAAI;GACvB;EACF;EAEA,IAAI,KAAK,QAAQ,gBAAgB;GAC/B,4BAA4B;GAC5B;EACF;EAEA,IACE,CAAC,sCACD,gCAAgC,IAAI,GACpC;GACA,0CAA0C;GAC1C;EACF;EAEA,cAAc,KAAK,IAAI;CACzB;CAEA,IAAI,2BACF,OAAO,MAAM,4CAA4C;CAG3D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CAEjB,OAAO;EAAE;EAAO;CAAU;AAC5B;AAEA,eAAsB,aACpB,aACA,QACsB;CACtB,MAAM,gBAAgB,MAAM,yBAAyB,aAAa,QAAQ;CAC1E,IAAI,CAAC,eACH,OAAO;EACL,OAAO,iBAAiB,QAAQ,KAAA,CAAS;EACzC;CACF;CAGF,OAAO;EAAE,GAAI,MAAM,cAAc,eAAe,MAAM;EAAI;CAAc;AAC1E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { coerceObject } from "../../util/object.js";
|
|
2
|
+
import { hasUncachedNpmrc, restoreNpmrc, stripNpmrc } from "./npm/npmrc.js";
|
|
3
|
+
import { get } from "./index.js";
|
|
4
|
+
import { getManagerConfig } from "../../config/index.js";
|
|
5
|
+
//#region lib/modules/manager/npmrc.ts
|
|
6
|
+
function asNpmrcPackageFiles(files) {
|
|
7
|
+
return files;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns the package files with those of managers with `supportsNpmrc` replaced by shallow copies without their `npmrc`.
|
|
11
|
+
*/
|
|
12
|
+
function withoutNpmrc(packageFiles) {
|
|
13
|
+
const result = { ...coerceObject(packageFiles) };
|
|
14
|
+
for (const [manager, files] of Object.entries(result)) if (get(manager, "supportsNpmrc")) result[manager] = stripNpmrc(asNpmrcPackageFiles(files));
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns the package files with those of managers with `supportsNpmrc` replaced by shallow copies whose `npmrc` is rebuilt from their repository `.npmrc` and the manager config.
|
|
19
|
+
*/
|
|
20
|
+
async function withNpmrc(packageFiles, config) {
|
|
21
|
+
const result = { ...coerceObject(packageFiles) };
|
|
22
|
+
for (const [manager, files] of Object.entries(result)) if (get(manager, "supportsNpmrc")) result[manager] = await restoreNpmrc(asNpmrcPackageFiles(files), getManagerConfig(config, manager));
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether any package file of a manager with `supportsNpmrc` needs its repository `.npmrc` read from disk again.
|
|
27
|
+
*/
|
|
28
|
+
function needsNpmrcFromDisk(packageFiles) {
|
|
29
|
+
for (const [manager, files] of Object.entries(coerceObject(packageFiles))) if (get(manager, "supportsNpmrc") && hasUncachedNpmrc(asNpmrcPackageFiles(files))) return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { needsNpmrcFromDisk, withNpmrc, withoutNpmrc };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=npmrc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npmrc.js","names":[],"sources":["../../../lib/modules/manager/npmrc.ts"],"sourcesContent":["import { getManagerConfig } from '../../config/index.ts';\nimport type { RenovateConfig } from '../../config/types.ts';\nimport { coerceObject } from '../../util/object.ts';\nimport { get } from './index.ts';\nimport { hasUncachedNpmrc, restoreNpmrc, stripNpmrc } from './npm/npmrc.ts';\nimport type { NpmManagerData } from './npm/types.ts';\nimport type { NpmrcPackageFile, PackageFile } from './types.ts';\n\nfunction asNpmrcPackageFiles(\n files: PackageFile[],\n): NpmrcPackageFile<NpmManagerData>[] {\n // the managers with `supportsNpmrc` (npm and bun) extract their package files with npm manager data\n return files as NpmrcPackageFile<NpmManagerData>[];\n}\n\n/**\n * Returns the package files with those of managers with `supportsNpmrc` replaced by shallow copies without their `npmrc`.\n */\nexport function withoutNpmrc(\n packageFiles: Record<string, PackageFile[]>,\n): Record<string, PackageFile[]> {\n const result = { ...coerceObject(packageFiles) };\n for (const [manager, files] of Object.entries(result)) {\n if (get(manager, 'supportsNpmrc')) {\n result[manager] = stripNpmrc(asNpmrcPackageFiles(files));\n }\n }\n return result;\n}\n\n/**\n * Returns the package files with those of managers with `supportsNpmrc` replaced by shallow copies whose `npmrc` is rebuilt from their repository `.npmrc` and the manager config.\n */\nexport async function withNpmrc(\n packageFiles: Record<string, PackageFile[]>,\n config: RenovateConfig,\n): Promise<Record<string, PackageFile[]>> {\n const result = { ...coerceObject(packageFiles) };\n for (const [manager, files] of Object.entries(result)) {\n if (get(manager, 'supportsNpmrc')) {\n result[manager] = await restoreNpmrc(\n asNpmrcPackageFiles(files),\n getManagerConfig(config, manager),\n );\n }\n }\n return result;\n}\n\n/**\n * Whether any package file of a manager with `supportsNpmrc` needs its repository `.npmrc` read from disk again.\n */\nexport function needsNpmrcFromDisk(\n packageFiles: Record<string, PackageFile[]>,\n): boolean {\n for (const [manager, files] of Object.entries(coerceObject(packageFiles))) {\n if (\n get(manager, 'supportsNpmrc') &&\n hasUncachedNpmrc(asNpmrcPackageFiles(files))\n ) {\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;AAQA,SAAS,oBACP,OACoC;CAEpC,OAAO;AACT;;;;AAKA,SAAgB,aACd,cAC+B;CAC/B,MAAM,SAAS,EAAE,GAAG,aAAa,YAAY,EAAE;CAC/C,KAAK,MAAM,CAAC,SAAS,UAAU,OAAO,QAAQ,MAAM,GAClD,IAAI,IAAI,SAAS,eAAe,GAC9B,OAAO,WAAW,WAAW,oBAAoB,KAAK,CAAC;CAG3D,OAAO;AACT;;;;AAKA,eAAsB,UACpB,cACA,QACwC;CACxC,MAAM,SAAS,EAAE,GAAG,aAAa,YAAY,EAAE;CAC/C,KAAK,MAAM,CAAC,SAAS,UAAU,OAAO,QAAQ,MAAM,GAClD,IAAI,IAAI,SAAS,eAAe,GAC9B,OAAO,WAAW,MAAM,aACtB,oBAAoB,KAAK,GACzB,iBAAiB,QAAQ,OAAO,CAClC;CAGJ,OAAO;AACT;;;;AAKA,SAAgB,mBACd,cACS;CACT,KAAK,MAAM,CAAC,SAAS,UAAU,OAAO,QAAQ,aAAa,YAAY,CAAC,GACtE,IACE,IAAI,SAAS,eAAe,KAC5B,iBAAiB,oBAAoB,KAAK,CAAC,GAE3C,OAAO;CAGX,OAAO;AACT"}
|
|
@@ -2,7 +2,7 @@ import "../../../../constants/error-messages.js";
|
|
|
2
2
|
import { regEx } from "../../../../util/regex.js";
|
|
3
3
|
import { coerceArray } from "../../../../util/array.js";
|
|
4
4
|
import { logger } from "../../../../logger/index.js";
|
|
5
|
-
import { parseUrl } from "../../../../util/url.js";
|
|
5
|
+
import { parseUrl, stripUrlCredentials } from "../../../../util/url.js";
|
|
6
6
|
import { findLocalSiblingOrParent, readLocalFile } from "../../../../util/fs/index.js";
|
|
7
7
|
import { Result } from "../../../../util/result.js";
|
|
8
8
|
import { findPypiIndexCredentials } from "../../../datasource/pypi/host-rules.js";
|
|
@@ -140,14 +140,20 @@ function generateCMD(updatedDeps) {
|
|
|
140
140
|
}
|
|
141
141
|
return `${uvUpdateCMD} ${deps.map((dep) => `--upgrade-package ${quote(dep)}`).join(" ")}`;
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns `url` without its userinfo, placeholders included, or `url` unchanged when it cannot be parsed.
|
|
145
|
+
*/
|
|
146
|
+
function withoutAnyUserinfo(url) {
|
|
147
|
+
return stripUrlCredentials(url) ?? url;
|
|
148
|
+
}
|
|
143
149
|
async function getUvExtraIndexUrl(project, deps) {
|
|
150
|
+
const configuredIndexUrls = new Set(coerceArray(project.tool?.uv?.index).map(({ url }) => withoutAnyUserinfo(url)));
|
|
144
151
|
const pyPiRegistryUrls = deps.filter((dep) => dep.datasource === PypiDatasource.id).filter((dep) => {
|
|
145
152
|
const sources = project.tool?.uv?.sources;
|
|
146
153
|
const packageName = dep.packageName;
|
|
147
154
|
return !sources || !(packageName in sources);
|
|
148
155
|
}).flatMap((dep) => dep.registryUrls).filter(isString).filter((registryUrl) => {
|
|
149
|
-
|
|
150
|
-
return registryUrl !== PypiDatasource.defaultURL && !configuredIndexUrls.includes(registryUrl);
|
|
156
|
+
return registryUrl !== PypiDatasource.defaultURL && !configuredIndexUrls.has(withoutAnyUserinfo(registryUrl));
|
|
151
157
|
});
|
|
152
158
|
const registryUrls = new Set(pyPiRegistryUrls);
|
|
153
159
|
const extraIndexUrls = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uv.js","names":[],"sources":["../../../../../lib/modules/manager/pep621/processors/uv.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../../constants/error-messages.ts';\nimport { logger } from '../../../../logger/index.ts';\nimport { coerceArray } from '../../../../util/array.ts';\nimport type {\n ExecOptions,\n ToolConstraint,\n} from '../../../../util/exec/types.ts';\nimport {\n findLocalSiblingOrParent,\n readLocalFile,\n} from '../../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../../util/git/exec.ts';\nimport { regEx } from '../../../../util/regex.ts';\nimport { Result } from '../../../../util/result.ts';\nimport { parseUrl } from '../../../../util/url.ts';\nimport { findPypiIndexCredentials } from '../../../datasource/pypi/host-rules.ts';\nimport { PypiDatasource } from '../../../datasource/pypi/index.ts';\nimport type {\n PackageDependency,\n UpdateArtifact,\n UpdateArtifactsResult,\n Upgrade,\n} from '../../types.ts';\nimport {\n applyGitSource,\n artifactErrorResult,\n resolveToolConstraint,\n updateLockFile,\n} from '../../util.ts';\nimport { type PyProject, UvLockfile, type UvSource } from '../schema.ts';\nimport { depTypes } from '../utils.ts';\nimport { BasePyProjectProcessor } from './abstract.ts';\n\nconst uvUpdateCMD = 'uv lock';\nconst gitExec = withGitEnvironment(['pep621']);\n\nfunction isUvIndexSource(\n source: UvSource,\n): source is Extract<UvSource, { index: string }> {\n return 'index' in source;\n}\n\nexport class UvProcessor extends BasePyProjectProcessor {\n override lockfileName = 'uv.lock';\n\n process(project: PyProject, deps: PackageDependency[]): PackageDependency[] {\n const uv = project.tool?.uv;\n if (!uv) {\n return deps;\n }\n\n const hasExplicitDefault = uv.index?.some(\n (index) => index.default && index.explicit,\n );\n const defaultIndex = uv.index?.find(\n (index) => index.default && !index.explicit,\n );\n const implicitIndexUrls = uv.index\n ?.filter((index) => !index.explicit && index.name !== defaultIndex?.name)\n ?.map(({ url }) => url);\n\n const devDependencies = uv['dev-dependencies'];\n if (devDependencies) {\n deps.push(...devDependencies);\n }\n\n // https://docs.astral.sh/uv/concepts/dependencies/#dependency-sources\n // Skip sources that do not make sense to handle (e.g. path).\n if (uv.sources || defaultIndex || implicitIndexUrls) {\n for (const dep of deps) {\n /* v8 ignore next -- needs test */\n if (!dep.packageName) {\n continue;\n }\n\n if (dep.depType === 'requires-python') {\n continue;\n }\n\n // Using `packageName` as it applies PEP 508 normalization, which is\n // also applied by uv when matching a source to a dependency.\n const depSources = uv.sources?.[dep.packageName];\n if (depSources) {\n // Dependency is pinned to one or more specific sources.\n dep.depType = depTypes.uvSources;\n if (depSources.every(isUvIndexSource)) {\n // Sources referencing an index, possibly disambiguated by\n // environment markers. Any of the indexes can serve the package,\n // so use all of them as registries.\n const registryUrls: string[] = [];\n for (const depSource of depSources) {\n const index = uv.index?.find(\n ({ name }) => name === depSource.index,\n );\n if (index) {\n registryUrls.push(index.url);\n }\n }\n if (registryUrls.length) {\n dep.registryUrls = [...new Set(registryUrls)];\n }\n } else if (depSources.length === 1) {\n const depSource = depSources[0];\n if ('git' in depSource) {\n applyGitSource(\n dep,\n depSource.git,\n depSource.rev,\n depSource.tag,\n depSource.branch,\n );\n } else if ('url' in depSource) {\n dep.skipReason = 'unsupported-url';\n } else if ('path' in depSource) {\n dep.skipReason = 'path-dependency';\n } else if ('workspace' in depSource) {\n dep.skipReason = 'inherited-dependency';\n } else {\n dep.skipReason = 'unknown-registry';\n }\n } else {\n // Multiple sources that are not all indexes (e.g. a git source\n // per platform) cannot be represented as a single update.\n dep.skipReason = 'unsupported';\n }\n } else {\n // Dependency is not pinned to a specific source, so we need to\n // determine the source based on the index configuration.\n if (hasExplicitDefault) {\n // don't fall back to pypi if there is an explicit default index\n dep.registryUrls = [];\n } else if (defaultIndex) {\n // There is a default index configured, so use it.\n dep.registryUrls = [defaultIndex.url];\n }\n\n if (implicitIndexUrls?.length) {\n // If there are implicit indexes, check them first and fall back\n // to the default.\n dep.registryUrls = implicitIndexUrls.concat(\n dep.registryUrls ?? PypiDatasource.defaultURL,\n );\n }\n }\n }\n }\n\n return deps;\n }\n\n async extractLockedVersions(\n project: PyProject,\n deps: PackageDependency[],\n packageFile: string,\n ): Promise<PackageDependency[]> {\n const lockFileName = await findLocalSiblingOrParent(\n packageFile,\n this.lockfileName,\n );\n if (lockFileName === null) {\n logger.debug({ packageFile }, `No uv lock file found`);\n } else {\n const lockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (lockFileContent) {\n const { val: lockFileMapping, err } = Result.parse(\n lockFileContent,\n UvLockfile,\n ).unwrap();\n\n if (err) {\n logger.debug({ packageFile, err }, `Error parsing uv lock file`);\n } else {\n for (const dep of deps) {\n const packageName = dep.packageName;\n if (packageName && packageName in lockFileMapping) {\n dep.lockedVersion = lockFileMapping[packageName];\n }\n }\n }\n }\n }\n\n return Promise.resolve(deps);\n }\n\n async updateArtifacts(\n updateArtifact: UpdateArtifact,\n project: PyProject,\n ): Promise<UpdateArtifactsResult[] | null> {\n const { config, updatedDeps, packageFileName } = updateArtifact;\n\n const { isLockFileMaintenance } = config;\n\n // abort if no lockfile is defined\n const lockFileName = await findLocalSiblingOrParent(\n packageFileName,\n 'uv.lock',\n );\n if (lockFileName === null) {\n logger.debug({ packageFileName }, `No uv lock file found`);\n return null;\n }\n try {\n const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n logger.debug('No uv.lock found');\n return null;\n }\n\n const pythonConstraint: ToolConstraint = {\n toolName: 'python',\n constraint: await resolveToolConstraint(\n config,\n 'python',\n () => project.project?.['requires-python'],\n ),\n };\n const uvConstraint: ToolConstraint = {\n toolName: 'uv',\n constraint: await resolveToolConstraint(\n config,\n 'uv',\n () => project.tool?.uv?.['required-version'],\n ),\n };\n\n const extraEnv = {\n ...(await getUvExtraIndexUrl(project, updateArtifact.updatedDeps)),\n ...(await getUvIndexCredentials(project)),\n };\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n extraEnv,\n docker: {},\n toolConstraints: [pythonConstraint, uvConstraint],\n };\n\n // on lockFileMaintenance do not specify any packages and update the complete lock file\n // else only update specific packages\n let cmd: string;\n if (isLockFileMaintenance) {\n cmd = `${uvUpdateCMD} --upgrade`;\n } else {\n cmd = generateCMD(updatedDeps);\n }\n return await updateLockFile({\n lockFileName,\n existingLockFileContent,\n run: () => gitExec(cmd, execOptions),\n });\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update uv lock file');\n return artifactErrorResult(lockFileName, err);\n }\n }\n}\n\nfunction generateCMD(updatedDeps: Upgrade[]): string {\n const deps: string[] = [];\n\n for (const dep of updatedDeps) {\n switch (dep.depType) {\n case depTypes.optionalDependencies: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.uvDevDependencies:\n case depTypes.uvSources: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.buildSystemRequires:\n // build requirements are not locked in the lock files, no need to update.\n break;\n default: {\n deps.push(dep.packageName!);\n }\n }\n }\n\n return `${uvUpdateCMD} ${deps.map((dep) => `--upgrade-package ${quote(dep)}`).join(' ')}`;\n}\n\nasync function getUvExtraIndexUrl(\n project: PyProject,\n deps: Upgrade[],\n): Promise<NodeJS.ProcessEnv> {\n const pyPiRegistryUrls = deps\n .filter((dep) => dep.datasource === PypiDatasource.id)\n .filter((dep) => {\n // Remove dependencies that are pinned to a specific index\n const sources = project.tool?.uv?.sources;\n const packageName = dep.packageName!;\n return !sources || !(packageName in sources);\n })\n .flatMap((dep) => dep.registryUrls)\n .filter(isString)\n .filter((registryUrl) => {\n // Check if the registry URL is not the default one and not already configured\n const configuredIndexUrls = coerceArray(\n project.tool?.uv?.index?.map(({ url }) => url),\n );\n return (\n registryUrl !== PypiDatasource.defaultURL &&\n !configuredIndexUrls.includes(registryUrl)\n );\n });\n\n const registryUrls = new Set(pyPiRegistryUrls);\n const extraIndexUrls: string[] = [];\n\n for (const registryUrl of registryUrls) {\n const parsedUrl = parseUrl(registryUrl);\n if (!parsedUrl) {\n continue;\n }\n\n const { username, password } = await findPypiIndexCredentials(\n parsedUrl.toString(),\n );\n if (username || password) {\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (username) {\n parsedUrl.username = username;\n }\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (password) {\n parsedUrl.password = password;\n }\n }\n\n extraIndexUrls.push(parsedUrl.toString());\n }\n\n return {\n UV_EXTRA_INDEX_URL: extraIndexUrls.join(' '),\n };\n}\n\nasync function getUvIndexCredentials(\n project: PyProject,\n): Promise<NodeJS.ProcessEnv> {\n const uv_indexes = project.tool?.uv?.index;\n\n if (!uv_indexes) {\n return {};\n }\n\n const entries = [];\n\n for (const { name, url } of uv_indexes) {\n const parsedUrl = parseUrl(url);\n /* v8 ignore next -- needs test */\n if (!parsedUrl) {\n continue;\n }\n\n // If no name is provided for the index, authentication information must be passed through alternative methods\n if (!name) {\n continue;\n }\n\n const { username, password } = await findPypiIndexCredentials(\n parsedUrl.toString(),\n );\n\n const NAME = name.toUpperCase().replace(regEx(/[^A-Z0-9]/g), '_');\n\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (username) {\n entries.push([`UV_INDEX_${NAME}_USERNAME`, username]);\n }\n\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (password) {\n entries.push([`UV_INDEX_${NAME}_PASSWORD`, password]);\n }\n }\n\n return Object.fromEntries(entries);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmCA,MAAM,cAAc;AACpB,MAAM,UAAU,mBAAmB,CAAC,QAAQ,CAAC;AAE7C,SAAS,gBACP,QACgD;CAChD,OAAO,WAAW;AACpB;AAEA,IAAa,cAAb,cAAiC,uBAAuB;CACtD,eAAwB;CAExB,QAAQ,SAAoB,MAAgD;EAC1E,MAAM,KAAK,QAAQ,MAAM;EACzB,IAAI,CAAC,IACH,OAAO;EAGT,MAAM,qBAAqB,GAAG,OAAO,MAClC,UAAU,MAAM,WAAW,MAAM,QACpC;EACA,MAAM,eAAe,GAAG,OAA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MAAM,iBAA2B,CAAC;CAElC,KAAK,MAAM,eAAe,cAAc;EACtC,MAAM,YAAY,SAAS,WAAW;EACtC,IAAI,CAAC,WACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,yBACnC,UAAU,SAAS,CACrB;EACA,IAAI,YAAY,UAAU;;GAExB,IAAI,UACF,UAAU,WAAW;;GAGvB,IAAI,UACF,UAAU,WAAW;EAEzB;EAEA,eAAe,KAAK,UAAU,SAAS,CAAC;CAC1C;CAEA,OAAO,EACL,oBAAoB,eAAe,KAAK,GAAG,EAC7C;AACF;AAEA,eAAe,sBACb,SAC4B;CAC5B,MAAM,aAAa,QAAQ,MAAM,IAAI;CAErC,IAAI,CAAC,YACH,OAAO,CAAC;CAGV,MAAM,UAAU,CAAC;CAEjB,KAAK,MAAM,EAAE,MAAM,SAAS,YAAY;EACtC,MAAM,YAAY,SAAS,GAAG;;EAE9B,IAAI,CAAC,WACH;EAIF,IAAI,CAAC,MACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,yBACnC,UAAU,SAAS,CACrB;EAEA,MAAM,OAAO,KAAK,YAAY,CAAC,CAAC,QAAQ,MAAM,YAAY,GAAG,GAAG;;EAGhE,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;;EAItD,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;CAExD;CAEA,OAAO,OAAO,YAAY,OAAO;AACnC"}
|
|
1
|
+
{"version":3,"file":"uv.js","names":[],"sources":["../../../../../lib/modules/manager/pep621/processors/uv.ts"],"sourcesContent":["import { isString } from '@sindresorhus/is';\nimport { quote } from 'shlex';\nimport { TEMPORARY_ERROR } from '../../../../constants/error-messages.ts';\nimport { logger } from '../../../../logger/index.ts';\nimport { coerceArray } from '../../../../util/array.ts';\nimport type {\n ExecOptions,\n ToolConstraint,\n} from '../../../../util/exec/types.ts';\nimport {\n findLocalSiblingOrParent,\n readLocalFile,\n} from '../../../../util/fs/index.ts';\nimport { withGitEnvironment } from '../../../../util/git/exec.ts';\nimport { regEx } from '../../../../util/regex.ts';\nimport { Result } from '../../../../util/result.ts';\nimport { parseUrl, stripUrlCredentials } from '../../../../util/url.ts';\nimport { findPypiIndexCredentials } from '../../../datasource/pypi/host-rules.ts';\nimport { PypiDatasource } from '../../../datasource/pypi/index.ts';\nimport type {\n PackageDependency,\n UpdateArtifact,\n UpdateArtifactsResult,\n Upgrade,\n} from '../../types.ts';\nimport {\n applyGitSource,\n artifactErrorResult,\n resolveToolConstraint,\n updateLockFile,\n} from '../../util.ts';\nimport { type PyProject, UvLockfile, type UvSource } from '../schema.ts';\nimport { depTypes } from '../utils.ts';\nimport { BasePyProjectProcessor } from './abstract.ts';\n\nconst uvUpdateCMD = 'uv lock';\nconst gitExec = withGitEnvironment(['pep621']);\n\nfunction isUvIndexSource(\n source: UvSource,\n): source is Extract<UvSource, { index: string }> {\n return 'index' in source;\n}\n\nexport class UvProcessor extends BasePyProjectProcessor {\n override lockfileName = 'uv.lock';\n\n process(project: PyProject, deps: PackageDependency[]): PackageDependency[] {\n const uv = project.tool?.uv;\n if (!uv) {\n return deps;\n }\n\n const hasExplicitDefault = uv.index?.some(\n (index) => index.default && index.explicit,\n );\n const defaultIndex = uv.index?.find(\n (index) => index.default && !index.explicit,\n );\n const implicitIndexUrls = uv.index\n ?.filter((index) => !index.explicit && index.name !== defaultIndex?.name)\n ?.map(({ url }) => url);\n\n const devDependencies = uv['dev-dependencies'];\n if (devDependencies) {\n deps.push(...devDependencies);\n }\n\n // https://docs.astral.sh/uv/concepts/dependencies/#dependency-sources\n // Skip sources that do not make sense to handle (e.g. path).\n if (uv.sources || defaultIndex || implicitIndexUrls) {\n for (const dep of deps) {\n /* v8 ignore next -- needs test */\n if (!dep.packageName) {\n continue;\n }\n\n if (dep.depType === 'requires-python') {\n continue;\n }\n\n // Using `packageName` as it applies PEP 508 normalization, which is\n // also applied by uv when matching a source to a dependency.\n const depSources = uv.sources?.[dep.packageName];\n if (depSources) {\n // Dependency is pinned to one or more specific sources.\n dep.depType = depTypes.uvSources;\n if (depSources.every(isUvIndexSource)) {\n // Sources referencing an index, possibly disambiguated by\n // environment markers. Any of the indexes can serve the package,\n // so use all of them as registries.\n const registryUrls: string[] = [];\n for (const depSource of depSources) {\n const index = uv.index?.find(\n ({ name }) => name === depSource.index,\n );\n if (index) {\n registryUrls.push(index.url);\n }\n }\n if (registryUrls.length) {\n dep.registryUrls = [...new Set(registryUrls)];\n }\n } else if (depSources.length === 1) {\n const depSource = depSources[0];\n if ('git' in depSource) {\n applyGitSource(\n dep,\n depSource.git,\n depSource.rev,\n depSource.tag,\n depSource.branch,\n );\n } else if ('url' in depSource) {\n dep.skipReason = 'unsupported-url';\n } else if ('path' in depSource) {\n dep.skipReason = 'path-dependency';\n } else if ('workspace' in depSource) {\n dep.skipReason = 'inherited-dependency';\n } else {\n dep.skipReason = 'unknown-registry';\n }\n } else {\n // Multiple sources that are not all indexes (e.g. a git source\n // per platform) cannot be represented as a single update.\n dep.skipReason = 'unsupported';\n }\n } else {\n // Dependency is not pinned to a specific source, so we need to\n // determine the source based on the index configuration.\n if (hasExplicitDefault) {\n // don't fall back to pypi if there is an explicit default index\n dep.registryUrls = [];\n } else if (defaultIndex) {\n // There is a default index configured, so use it.\n dep.registryUrls = [defaultIndex.url];\n }\n\n if (implicitIndexUrls?.length) {\n // If there are implicit indexes, check them first and fall back\n // to the default.\n dep.registryUrls = implicitIndexUrls.concat(\n dep.registryUrls ?? PypiDatasource.defaultURL,\n );\n }\n }\n }\n }\n\n return deps;\n }\n\n async extractLockedVersions(\n project: PyProject,\n deps: PackageDependency[],\n packageFile: string,\n ): Promise<PackageDependency[]> {\n const lockFileName = await findLocalSiblingOrParent(\n packageFile,\n this.lockfileName,\n );\n if (lockFileName === null) {\n logger.debug({ packageFile }, `No uv lock file found`);\n } else {\n const lockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (lockFileContent) {\n const { val: lockFileMapping, err } = Result.parse(\n lockFileContent,\n UvLockfile,\n ).unwrap();\n\n if (err) {\n logger.debug({ packageFile, err }, `Error parsing uv lock file`);\n } else {\n for (const dep of deps) {\n const packageName = dep.packageName;\n if (packageName && packageName in lockFileMapping) {\n dep.lockedVersion = lockFileMapping[packageName];\n }\n }\n }\n }\n }\n\n return Promise.resolve(deps);\n }\n\n async updateArtifacts(\n updateArtifact: UpdateArtifact,\n project: PyProject,\n ): Promise<UpdateArtifactsResult[] | null> {\n const { config, updatedDeps, packageFileName } = updateArtifact;\n\n const { isLockFileMaintenance } = config;\n\n // abort if no lockfile is defined\n const lockFileName = await findLocalSiblingOrParent(\n packageFileName,\n 'uv.lock',\n );\n if (lockFileName === null) {\n logger.debug({ packageFileName }, `No uv lock file found`);\n return null;\n }\n try {\n const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');\n if (!existingLockFileContent) {\n logger.debug('No uv.lock found');\n return null;\n }\n\n const pythonConstraint: ToolConstraint = {\n toolName: 'python',\n constraint: await resolveToolConstraint(\n config,\n 'python',\n () => project.project?.['requires-python'],\n ),\n };\n const uvConstraint: ToolConstraint = {\n toolName: 'uv',\n constraint: await resolveToolConstraint(\n config,\n 'uv',\n () => project.tool?.uv?.['required-version'],\n ),\n };\n\n const extraEnv = {\n ...(await getUvExtraIndexUrl(project, updateArtifact.updatedDeps)),\n ...(await getUvIndexCredentials(project)),\n };\n const execOptions: ExecOptions = {\n cwdFile: packageFileName,\n extraEnv,\n docker: {},\n toolConstraints: [pythonConstraint, uvConstraint],\n };\n\n // on lockFileMaintenance do not specify any packages and update the complete lock file\n // else only update specific packages\n let cmd: string;\n if (isLockFileMaintenance) {\n cmd = `${uvUpdateCMD} --upgrade`;\n } else {\n cmd = generateCMD(updatedDeps);\n }\n return await updateLockFile({\n lockFileName,\n existingLockFileContent,\n run: () => gitExec(cmd, execOptions),\n });\n } catch (err) {\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update uv lock file');\n return artifactErrorResult(lockFileName, err);\n }\n }\n}\n\nfunction generateCMD(updatedDeps: Upgrade[]): string {\n const deps: string[] = [];\n\n for (const dep of updatedDeps) {\n switch (dep.depType) {\n case depTypes.optionalDependencies: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.uvDevDependencies:\n case depTypes.uvSources: {\n deps.push(dep.depName!);\n break;\n }\n case depTypes.buildSystemRequires:\n // build requirements are not locked in the lock files, no need to update.\n break;\n default: {\n deps.push(dep.packageName!);\n }\n }\n }\n\n return `${uvUpdateCMD} ${deps.map((dep) => `--upgrade-package ${quote(dep)}`).join(' ')}`;\n}\n\n/**\n * Returns `url` without its userinfo, placeholders included, or `url` unchanged when it cannot be parsed.\n */\nfunction withoutAnyUserinfo(url: string): string {\n return stripUrlCredentials(url) ?? url;\n}\n\nasync function getUvExtraIndexUrl(\n project: PyProject,\n deps: Upgrade[],\n): Promise<NodeJS.ProcessEnv> {\n // compared without any userinfo, which the registry URLs of the deps may no longer carry\n const configuredIndexUrls = new Set(\n coerceArray(project.tool?.uv?.index).map(({ url }) =>\n withoutAnyUserinfo(url),\n ),\n );\n const pyPiRegistryUrls = deps\n .filter((dep) => dep.datasource === PypiDatasource.id)\n .filter((dep) => {\n // Remove dependencies that are pinned to a specific index\n const sources = project.tool?.uv?.sources;\n const packageName = dep.packageName!;\n return !sources || !(packageName in sources);\n })\n .flatMap((dep) => dep.registryUrls)\n .filter(isString)\n .filter((registryUrl) => {\n // Check if the registry URL is not the default one and not already configured\n return (\n registryUrl !== PypiDatasource.defaultURL &&\n !configuredIndexUrls.has(withoutAnyUserinfo(registryUrl))\n );\n });\n\n const registryUrls = new Set(pyPiRegistryUrls);\n const extraIndexUrls: string[] = [];\n\n for (const registryUrl of registryUrls) {\n const parsedUrl = parseUrl(registryUrl);\n if (!parsedUrl) {\n continue;\n }\n\n const { username, password } = await findPypiIndexCredentials(\n parsedUrl.toString(),\n );\n if (username || password) {\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (username) {\n parsedUrl.username = username;\n }\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (password) {\n parsedUrl.password = password;\n }\n }\n\n extraIndexUrls.push(parsedUrl.toString());\n }\n\n return {\n UV_EXTRA_INDEX_URL: extraIndexUrls.join(' '),\n };\n}\n\nasync function getUvIndexCredentials(\n project: PyProject,\n): Promise<NodeJS.ProcessEnv> {\n const uv_indexes = project.tool?.uv?.index;\n\n if (!uv_indexes) {\n return {};\n }\n\n const entries = [];\n\n for (const { name, url } of uv_indexes) {\n const parsedUrl = parseUrl(url);\n /* v8 ignore next -- needs test */\n if (!parsedUrl) {\n continue;\n }\n\n // If no name is provided for the index, authentication information must be passed through alternative methods\n if (!name) {\n continue;\n }\n\n const { username, password } = await findPypiIndexCredentials(\n parsedUrl.toString(),\n );\n\n const NAME = name.toUpperCase().replace(regEx(/[^A-Z0-9]/g), '_');\n\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (username) {\n entries.push([`UV_INDEX_${NAME}_USERNAME`, username]);\n }\n\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (password) {\n entries.push([`UV_INDEX_${NAME}_PASSWORD`, password]);\n }\n }\n\n return Object.fromEntries(entries);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmCA,MAAM,cAAc;AACpB,MAAM,UAAU,mBAAmB,CAAC,QAAQ,CAAC;AAE7C,SAAS,gBACP,QACgD;CAChD,OAAO,WAAW;AACpB;AAEA,IAAa,cAAb,cAAiC,uBAAuB;CACtD,eAAwB;CAExB,QAAQ,SAAoB,MAAgD;EAC1E,MAAM,KAAK,QAAQ,MAAM;EACzB,IAAI,CAAC,IACH,OAAO;EAGT,MAAM,qBAAqB,GAAG,OAAO,MAClC,UAAU,MAAM,WAAW,MAAM,QACpC;EACA,MAAM,eAAe,GAAG,OAAO,MAC5B,UAAU,MAAM,WAAW,CAAC,MAAM,QACrC;EACA,MAAM,oBAAoB,GAAG,OACzB,QAAQ,UAAU,CAAC,MAAM,YAAY,M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AAgB;CAC7C,MAAM,iBAA2B,CAAC;CAElC,KAAK,MAAM,eAAe,cAAc;EACtC,MAAM,YAAY,SAAS,WAAW;EACtC,IAAI,CAAC,WACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,yBACnC,UAAU,SAAS,CACrB;EACA,IAAI,YAAY,UAAU;;GAExB,IAAI,UACF,UAAU,WAAW;;GAGvB,IAAI,UACF,UAAU,WAAW;EAEzB;EAEA,eAAe,KAAK,UAAU,SAAS,CAAC;CAC1C;CAEA,OAAO,EACL,oBAAoB,eAAe,KAAK,GAAG,EAC7C;AACF;AAEA,eAAe,sBACb,SAC4B;CAC5B,MAAM,aAAa,QAAQ,MAAM,IAAI;CAErC,IAAI,CAAC,YACH,OAAO,CAAC;CAGV,MAAM,UAAU,CAAC;CAEjB,KAAK,MAAM,EAAE,MAAM,SAAS,YAAY;EACtC,MAAM,YAAY,SAAS,GAAG;;EAE9B,IAAI,CAAC,WACH;EAIF,IAAI,CAAC,MACH;EAGF,MAAM,EAAE,UAAU,aAAa,MAAM,yBACnC,UAAU,SAAS,CACrB;EAEA,MAAM,OAAO,KAAK,YAAY,CAAC,CAAC,QAAQ,MAAM,YAAY,GAAG,GAAG;;EAGhE,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;;EAItD,IAAI,UACF,QAAQ,KAAK,CAAC,YAAY,KAAK,YAAY,QAAQ,CAAC;CAExD;CAEA,OAAO,OAAO,YAAY,OAAO;AACnC"}
|
|
@@ -2,7 +2,7 @@ import "../../../constants/error-messages.js";
|
|
|
2
2
|
import { regEx } from "../../../util/regex.js";
|
|
3
3
|
import { coerceArray } from "../../../util/array.js";
|
|
4
4
|
import { logger } from "../../../logger/index.js";
|
|
5
|
-
import { parseUrl } from "../../../util/url.js";
|
|
5
|
+
import { decodeUserinfo, parseUrl } from "../../../util/url.js";
|
|
6
6
|
import { ensureLocalPath } from "../../../util/fs/util.js";
|
|
7
7
|
import { deleteLocalFile, ensureCacheDir, getParentDir, localPathExists, readLocalFile, writeLocalFile } from "../../../util/fs/index.js";
|
|
8
8
|
import { exec } from "../../../util/exec/index.js";
|
|
@@ -18,12 +18,23 @@ async function findPipfileSourceUrlsWithCredentials(pipfileContent, pipfileName)
|
|
|
18
18
|
return coerceArray(pipfile?.registryUrls?.map(parseUrl).filter(isUrlInstance).filter((url) => isNonEmptyStringAndNotWhitespace(url.username)));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
+
* Matches a whole `$NAME`, `${NAME}`, `${NAME-default}` or `${NAME:-default}` environment variable reference, the braced forms also in single quotes as pipenv accepts them.
|
|
22
|
+
*/
|
|
23
|
+
const environmentVariableReferenceRegex = regEx(/^(?:'\$\{(?<quoted>[a-z_][a-z\d_]*)(?::?-[^{}]*)?\}'|\$(?:\{(?<braced>[a-z_][a-z\d_]*)(?::?-[^{}]*)?\}|(?<plain>[a-z_][a-z\d_]*)))$/i);
|
|
24
|
+
/**
|
|
21
25
|
* This will extract the actual variable name from an environment-placeholder:
|
|
22
26
|
* ${USERNAME:-defaultvalue} will yield 'USERNAME'
|
|
27
|
+
* @returns the variable name, or `null` when `credential` is not exactly one reference, such as a literal value
|
|
23
28
|
*/
|
|
24
29
|
function extractEnvironmentVariableName(credential) {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
30
|
+
const groups = environmentVariableReferenceRegex.exec(decodeUserinfo(credential))?.groups;
|
|
31
|
+
return groups?.quoted ?? groups?.braced ?? groups?.plain ?? null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether the userinfo of `url` holds a literal value rather than environment variable references as pipenv reads them: its password, or its username when it has no password, is not exactly one reference.
|
|
35
|
+
*/
|
|
36
|
+
function hasLiteralUserinfo(url) {
|
|
37
|
+
return !extractEnvironmentVariableName(url.password || url.username);
|
|
27
38
|
}
|
|
28
39
|
function addExtraEnvVariable(extraEnv, environmentVariableName, environmentValue) {
|
|
29
40
|
logger.trace(`Adding ${environmentVariableName} environment variable for pipenv`);
|
|
@@ -37,8 +48,8 @@ function addExtraEnvVariable(extraEnv, environmentVariableName, environmentValue
|
|
|
37
48
|
*
|
|
38
49
|
*/
|
|
39
50
|
async function addCredentialsForSourceUrls(newPipfileContent, pipfileName, extraEnv) {
|
|
40
|
-
const
|
|
41
|
-
for (const parsedSourceUrl of
|
|
51
|
+
const placeholderSourceUrls = (await findPipfileSourceUrlsWithCredentials(newPipfileContent, pipfileName)).filter((url) => !hasLiteralUserinfo(url));
|
|
52
|
+
for (const parsedSourceUrl of placeholderSourceUrls) {
|
|
42
53
|
logger.trace(`Trying to add credentials for ${parsedSourceUrl.toString()}`);
|
|
43
54
|
const credentials = await findPypiIndexCredentials(parsedSourceUrl.toString());
|
|
44
55
|
const usernameVariableName = extractEnvironmentVariableName(parsedSourceUrl.username);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifacts.js","names":["pipenvDetect"],"sources":["../../../../lib/modules/manager/pipenv/artifacts.ts"],"sourcesContent":["import { pipenv as pipenvDetect } from '@renovatebot/detect-tools';\nimport {\n isNonEmptyStringAndNotWhitespace,\n isUrlInstance,\n} from '@sindresorhus/is';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions, ExtraEnv, Opt } from '../../../util/exec/types.ts';\nimport {\n deleteLocalFile,\n ensureCacheDir,\n getParentDir,\n localPathExists,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { ensureLocalPath } from '../../../util/fs/util.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { parseUrl } from '../../../util/url.ts';\nimport { findPypiIndexCredentials } from '../../datasource/pypi/host-rules.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { resolveToolConstraint } from '../util.ts';\nimport { extractPackageFile } from './extract.ts';\n\nasync function findPipfileSourceUrlsWithCredentials(\n pipfileContent: string,\n pipfileName: string,\n): Promise<URL[]> {\n const pipfile = await extractPackageFile(pipfileContent, pipfileName);\n\n return coerceArray(\n pipfile?.registryUrls\n ?.map(parseUrl)\n .filter(isUrlInstance)\n .filter((url) => isNonEmptyStringAndNotWhitespace(url.username)),\n );\n}\n\n/**\n * This will extract the actual variable name from an environment-placeholder:\n * ${USERNAME:-defaultvalue} will yield 'USERNAME'\n */\nexport function extractEnvironmentVariableName(\n credential: string,\n): string | null {\n
|
|
1
|
+
{"version":3,"file":"artifacts.js","names":["pipenvDetect"],"sources":["../../../../lib/modules/manager/pipenv/artifacts.ts"],"sourcesContent":["import { pipenv as pipenvDetect } from '@renovatebot/detect-tools';\nimport {\n isNonEmptyStringAndNotWhitespace,\n isUrlInstance,\n} from '@sindresorhus/is';\nimport { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';\nimport { logger } from '../../../logger/index.ts';\nimport { coerceArray } from '../../../util/array.ts';\nimport { exec } from '../../../util/exec/index.ts';\nimport type { ExecOptions, ExtraEnv, Opt } from '../../../util/exec/types.ts';\nimport {\n deleteLocalFile,\n ensureCacheDir,\n getParentDir,\n localPathExists,\n readLocalFile,\n writeLocalFile,\n} from '../../../util/fs/index.ts';\nimport { ensureLocalPath } from '../../../util/fs/util.ts';\nimport { getRepoStatus } from '../../../util/git/index.ts';\nimport { regEx } from '../../../util/regex.ts';\nimport { decodeUserinfo, parseUrl } from '../../../util/url.ts';\nimport { findPypiIndexCredentials } from '../../datasource/pypi/host-rules.ts';\nimport type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';\nimport { resolveToolConstraint } from '../util.ts';\nimport { extractPackageFile } from './extract.ts';\n\nasync function findPipfileSourceUrlsWithCredentials(\n pipfileContent: string,\n pipfileName: string,\n): Promise<URL[]> {\n const pipfile = await extractPackageFile(pipfileContent, pipfileName);\n\n return coerceArray(\n pipfile?.registryUrls\n ?.map(parseUrl)\n .filter(isUrlInstance)\n .filter((url) => isNonEmptyStringAndNotWhitespace(url.username)),\n );\n}\n\n/**\n * Matches a whole `$NAME`, `${NAME}`, `${NAME-default}` or `${NAME:-default}` environment variable reference, the braced forms also in single quotes as pipenv accepts them.\n */\nconst environmentVariableReferenceRegex = regEx(\n /^(?:'\\$\\{(?<quoted>[a-z_][a-z\\d_]*)(?::?-[^{}]*)?\\}'|\\$(?:\\{(?<braced>[a-z_][a-z\\d_]*)(?::?-[^{}]*)?\\}|(?<plain>[a-z_][a-z\\d_]*)))$/i,\n);\n\n/**\n * This will extract the actual variable name from an environment-placeholder:\n * ${USERNAME:-defaultvalue} will yield 'USERNAME'\n * @returns the variable name, or `null` when `credential` is not exactly one reference, such as a literal value\n */\nexport function extractEnvironmentVariableName(\n credential: string,\n): string | null {\n // the URL parser percent-encodes the braces, the quotes and the `:` of `${NAME:-default}`\n const groups = environmentVariableReferenceRegex.exec(\n decodeUserinfo(credential),\n )?.groups;\n return groups?.quoted ?? groups?.braced ?? groups?.plain ?? null;\n}\n\n/**\n * Whether the userinfo of `url` holds a literal value rather than environment variable references as pipenv reads them: its password, or its username when it has no password, is not exactly one reference.\n */\nfunction hasLiteralUserinfo(url: URL): boolean {\n return !extractEnvironmentVariableName(url.password || url.username);\n}\n\nexport function addExtraEnvVariable(\n extraEnv: ExtraEnv,\n environmentVariableName: string,\n environmentValue: string,\n): void {\n logger.trace(\n `Adding ${environmentVariableName} environment variable for pipenv`,\n );\n if (\n extraEnv[environmentVariableName] &&\n extraEnv[environmentVariableName] !== environmentValue\n ) {\n logger.warn(\n { envVar: environmentVariableName },\n 'Possible misconfiguration, environment variable already set to a different value',\n );\n }\n extraEnv[environmentVariableName] = environmentValue;\n}\n\n/**\n * Pipenv allows configuring source-urls for remote repositories with placeholders for credentials, i.e. http://$USER:$PASS@myprivate.repo\n * if a matching host rule exists for that repository, we need to set the corresponding variables.\n * Simply substituting them in the URL is not an option as it would impact the hash for the resulting Pipfile.lock\n *\n */\nasync function addCredentialsForSourceUrls(\n newPipfileContent: string,\n pipfileName: string,\n extraEnv: ExtraEnv,\n): Promise<void> {\n const sourceUrls = await findPipfileSourceUrlsWithCredentials(\n newPipfileContent,\n pipfileName,\n );\n // a source URL with literal credentials carries them itself, and the host rule found for it may hold just those\n const placeholderSourceUrls = sourceUrls.filter(\n (url) => !hasLiteralUserinfo(url),\n );\n for (const parsedSourceUrl of placeholderSourceUrls) {\n logger.trace(`Trying to add credentials for ${parsedSourceUrl.toString()}`);\n const credentials = await findPypiIndexCredentials(\n parsedSourceUrl.toString(),\n );\n const usernameVariableName = extractEnvironmentVariableName(\n parsedSourceUrl.username,\n );\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (credentials.username && usernameVariableName) {\n addExtraEnvVariable(extraEnv, usernameVariableName, credentials.username);\n }\n const passwordVariableName = extractEnvironmentVariableName(\n parsedSourceUrl.password,\n );\n // v8 ignore else -- needs a host rule carrying only one of the two\n if (credentials.password && passwordVariableName) {\n addExtraEnvVariable(extraEnv, passwordVariableName, credentials.password);\n }\n }\n}\n\nexport async function updateArtifacts({\n packageFileName: pipfileName,\n newPackageFileContent: newPipfileContent,\n config,\n}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {\n logger.debug(`pipenv.updateArtifacts(${pipfileName})`);\n\n const lockFileName = `${pipfileName}.lock`;\n if (!(await localPathExists(lockFileName))) {\n logger.debug('No Pipfile.lock found');\n return null;\n }\n try {\n await writeLocalFile(pipfileName, newPipfileContent);\n if (config.isLockFileMaintenance) {\n await deleteLocalFile(lockFileName);\n }\n const cmd = 'pipenv lock';\n const pipfileDir = getParentDir(ensureLocalPath(pipfileName));\n const tagConstraint = await resolveToolConstraint(config, 'python', () =>\n pipenvDetect.getPythonConstraint(pipfileDir),\n );\n const pipenvConstraint = await resolveToolConstraint(config, 'pipenv', () =>\n pipenvDetect.getPipenvConstraint(pipfileDir),\n );\n const extraEnv: Opt<ExtraEnv> = {\n PIPENV_CACHE_DIR: await ensureCacheDir('pipenv'),\n PIP_CACHE_DIR: await ensureCacheDir('pip'),\n WORKON_HOME: await ensureCacheDir('virtualenvs'),\n };\n const execOptions: ExecOptions = {\n cwdFile: pipfileName,\n docker: {},\n toolConstraints: [\n {\n toolName: 'python',\n constraint: tagConstraint,\n },\n {\n toolName: 'pipenv',\n constraint: pipenvConstraint,\n },\n ],\n };\n await addCredentialsForSourceUrls(newPipfileContent, pipfileName, extraEnv);\n execOptions.extraEnv = extraEnv;\n\n logger.trace({ cmd }, 'pipenv lock command');\n await exec(cmd, execOptions);\n const status = await getRepoStatus();\n if (!status?.modified.includes(lockFileName)) {\n return null;\n }\n logger.debug('Returning updated Pipfile.lock');\n return [\n {\n file: {\n type: 'addition',\n path: lockFileName,\n contents: await readLocalFile(lockFileName, 'utf8'),\n },\n },\n ];\n } catch (err) {\n // istanbul ignore if\n if (err.message === TEMPORARY_ERROR) {\n throw err;\n }\n logger.debug({ err }, 'Failed to update Pipfile.lock');\n return [\n {\n artifactError: {\n fileName: lockFileName,\n stderr: err.message,\n },\n },\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2BA,eAAe,qCACb,gBACA,aACgB;CAChB,MAAM,UAAU,MAAM,mBAAmB,gBAAgB,WAAW;CAEpE,OAAO,YACL,SAAS,cACL,IAAI,QAAQ,CAAC,CACd,OAAO,aAAa,CAAC,CACrB,QAAQ,QAAQ,iCAAiC,IAAI,QAAQ,CAAC,CACnE;AACF;;;;AAKA,MAAM,oCAAoC,MACxC,sIACF;;;;;;AAOA,SAAgB,+BACd,YACe;CAEf,MAAM,SAAS,kCAAkC,KAC/C,eAAe,UAAU,CAC3B,CAAC,EAAE;CACH,OAAO,QAAQ,UAAU,QAAQ,UAAU,QAAQ,SAAS;AAC9D;;;;AAKA,SAAS,mBAAmB,KAAmB;CAC7C,OAAO,CAAC,+BAA+B,IAAI,YAAY,IAAI,QAAQ;AACrE;AAEA,SAAgB,oBACd,UACA,yBACA,kBACM;CACN,OAAO,MAC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;GAC/C,eAAe,MAAM,eAAe,KAAK;GACzC,aAAa,MAAM,eAAe,aAAa;EACjD;EACA,MAAM,cAA2B;GAC/B,SAAS;GACT,QAAQ,CAAC;GACT,iBAAiB,CACf;IACE,UAAU;IACV,YAAY;GACd,GACA;IACE,UAAU;IACV,YAAY;GACd,CACF;EACF;EACA,MAAM,4BAA4B,mBAAmB,aAAa,QAAQ;EAC1E,YAAY,WAAW;EAEvB,OAAO,MAAM,EAAE,IAAI,GAAG,qBAAqB;EAC3C,MAAM,KAAK,KAAK,WAAW;EAE3B,IAAI,EAAC,MADgB,cAAc,EAAA,EACtB,SAAS,SAAS,YAAY,GACzC,OAAO;EAET,OAAO,MAAM,gCAAgC;EAC7C,OAAO,CACL,EACE,MAAM;GACJ,MAAM;GACN,MAAM;GACN,UAAU,MAAM,cAAc,cAAc,MAAM;EACpD,EACF,CACF;CACF,SAAS,KAAK;;EAEZ,IAAI,IAAI,YAAA,mBACN,MAAM;EAER,OAAO,MAAM,EAAE,IAAI,GAAG,+BAA+B;EACrD,OAAO,CACL,EACE,eAAe;GACb,UAAU;GACV,QAAQ,IAAI;EACd,EACF,CACF;CACF;AACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { get as get$1, set as set$1 } from "../memory/index.js";
|
|
2
2
|
import { getCombinedKey } from "./key.js";
|
|
3
3
|
import { PackageCacheStats } from "../../stats.js";
|
|
4
|
+
import { sanitizeKey } from "../sanitize-key.js";
|
|
4
5
|
import { destroy, get as get$2, getCacheType as getCacheType$1, init as init$1, set as set$2 } from "./backend.js";
|
|
5
6
|
import { getTtlOverride } from "./ttl.js";
|
|
6
7
|
//#region lib/util/cache/package/index.ts
|
|
@@ -9,10 +10,11 @@ function getCacheType() {
|
|
|
9
10
|
}
|
|
10
11
|
async function get(namespace, key) {
|
|
11
12
|
if (!getCacheType$1()) return;
|
|
12
|
-
const
|
|
13
|
+
const sanitizedKey = sanitizeKey(key);
|
|
14
|
+
const combinedKey = getCombinedKey(namespace, sanitizedKey);
|
|
13
15
|
let cachedPromise = get$1(combinedKey);
|
|
14
16
|
if (!cachedPromise) {
|
|
15
|
-
cachedPromise = PackageCacheStats.wrapGet(() => get$2(namespace,
|
|
17
|
+
cachedPromise = PackageCacheStats.wrapGet(() => get$2(namespace, sanitizedKey));
|
|
16
18
|
set$1(combinedKey, cachedPromise);
|
|
17
19
|
}
|
|
18
20
|
return await cachedPromise;
|
|
@@ -29,8 +31,9 @@ async function set(namespace, key, value, hardTtlMinutes) {
|
|
|
29
31
|
*/
|
|
30
32
|
async function setWithRawTtl(namespace, key, value, hardTtlMinutes) {
|
|
31
33
|
if (!getCacheType$1()) return;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
const sanitizedKey = sanitizeKey(key);
|
|
35
|
+
await PackageCacheStats.wrapSet(() => set$2(namespace, sanitizedKey, value, hardTtlMinutes));
|
|
36
|
+
const combinedKey = getCombinedKey(namespace, sanitizedKey);
|
|
34
37
|
const p = Promise.resolve(value);
|
|
35
38
|
set$1(combinedKey, p);
|
|
36
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["backend.getCacheType","memCache.get","backend.get","backend.set","backend.init","backend.destroy"],"sources":["../../../../lib/util/cache/package/index.ts"],"sourcesContent":["import type { AllConfig } from '../../../config/types.ts';\nimport { PackageCacheStats } from '../../stats.ts';\nimport * as memCache from '../memory/index.ts';\nimport * as backend from './backend.ts';\nimport { getCombinedKey } from './key.ts';\nimport { getTtlOverride } from './ttl.ts';\nimport type { PackageCacheNamespace } from './types.ts';\n\nexport function getCacheType(): ReturnType<typeof backend.getCacheType> {\n return backend.getCacheType();\n}\n\nexport async function get<T = any>(\n namespace: PackageCacheNamespace,\n key: string,\n): Promise<T | undefined> {\n if (!backend.getCacheType()) {\n return undefined;\n }\n\n const combinedKey = getCombinedKey(namespace,
|
|
1
|
+
{"version":3,"file":"index.js","names":["backend.getCacheType","memCache.get","backend.get","backend.set","backend.init","backend.destroy"],"sources":["../../../../lib/util/cache/package/index.ts"],"sourcesContent":["import type { AllConfig } from '../../../config/types.ts';\nimport { PackageCacheStats } from '../../stats.ts';\nimport * as memCache from '../memory/index.ts';\nimport { sanitizeKey } from '../sanitize-key.ts';\nimport * as backend from './backend.ts';\nimport { getCombinedKey } from './key.ts';\nimport { getTtlOverride } from './ttl.ts';\nimport type { PackageCacheNamespace } from './types.ts';\n\nexport function getCacheType(): ReturnType<typeof backend.getCacheType> {\n return backend.getCacheType();\n}\n\nexport async function get<T = any>(\n namespace: PackageCacheNamespace,\n key: string,\n): Promise<T | undefined> {\n if (!backend.getCacheType()) {\n return undefined;\n }\n\n const sanitizedKey = sanitizeKey(key);\n const combinedKey = getCombinedKey(namespace, sanitizedKey);\n let cachedPromise = memCache.get(combinedKey);\n if (!cachedPromise) {\n cachedPromise = PackageCacheStats.wrapGet(() =>\n backend.get(namespace, sanitizedKey),\n );\n memCache.set(combinedKey, cachedPromise);\n }\n\n return await cachedPromise;\n}\n\n/**\n * Set cache value with user-defined TTL overrides.\n */\nexport async function set(\n namespace: PackageCacheNamespace,\n key: string,\n value: unknown,\n hardTtlMinutes: number,\n): Promise<void> {\n const rawTtl = getTtlOverride(namespace) ?? hardTtlMinutes;\n await setWithRawTtl(namespace, key, value, rawTtl);\n}\n\n/**\n * Set cache value ignoring user-defined TTL overrides.\n * This MUST NOT be used outside of cache implementation\n */\nexport async function setWithRawTtl(\n namespace: PackageCacheNamespace,\n key: string,\n value: unknown,\n hardTtlMinutes: number,\n): Promise<void> {\n if (!backend.getCacheType()) {\n return;\n }\n\n const sanitizedKey = sanitizeKey(key);\n await PackageCacheStats.wrapSet(() =>\n backend.set(namespace, sanitizedKey, value, hardTtlMinutes),\n );\n\n const combinedKey = getCombinedKey(namespace, sanitizedKey);\n const p = Promise.resolve(value);\n memCache.set(combinedKey, p);\n}\n\nexport async function init(config: AllConfig): Promise<void> {\n await backend.init(config);\n}\n\nexport async function cleanup(_config: AllConfig): Promise<void> {\n await backend.destroy();\n}\n"],"mappings":";;;;;;;AASA,SAAgB,eAAwD;CACtE,OAAOA,eAAqB;AAC9B;AAEA,eAAsB,IACpB,WACA,KACwB;CACxB,IAAI,CAACA,eAAqB,GACxB;CAGF,MAAM,eAAe,YAAY,GAAG;CACpC,MAAM,cAAc,eAAe,WAAW,YAAY;CAC1D,IAAI,gBAAgBC,MAAa,WAAW;CAC5C,IAAI,CAAC,eAAe;EAClB,gBAAgB,kBAAkB,cAChCC,MAAY,WAAW,YAAY,CACrC;EACA,MAAa,aAAa,aAAa;CACzC;CAEA,OAAO,MAAM;AACf;;;;AAKA,eAAsB,IACpB,WACA,KACA,OACA,gBACe;CAEf,MAAM,cAAc,WAAW,KAAK,OADrB,eAAe,SAAS,KAAK,cACK;AACnD;;;;;AAMA,eAAsB,cACpB,WACA,KACA,OACA,gBACe;CACf,IAAI,CAACF,eAAqB,GACxB;CAGF,MAAM,eAAe,YAAY,GAAG;CACpC,MAAM,kBAAkB,cACtBG,MAAY,WAAW,cAAc,OAAO,cAAc,CAC5D;CAEA,MAAM,cAAc,eAAe,WAAW,YAAY;CAC1D,MAAM,IAAI,QAAQ,QAAQ,KAAK;CAC/B,MAAa,aAAa,CAAC;AAC7B;AAEA,eAAsB,KAAK,QAAkC;CAC3D,MAAMC,OAAa,MAAM;AAC3B;AAEA,eAAsB,QAAQ,SAAmC;CAC/D,MAAMC,QAAgB;AACxB"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { GlobalConfig } from "../../../config/global.js";
|
|
2
2
|
import { logger } from "../../../logger/index.js";
|
|
3
|
+
import { hashUserinfoAndQuery } from "../sanitize-key.js";
|
|
4
|
+
import { persistedResponseHeaders, pickHeaders } from "../../http/cache/persisted-headers.js";
|
|
3
5
|
import { HttpCache } from "../../http/cache/schema.js";
|
|
4
6
|
import { isTruthy } from "@sindresorhus/is";
|
|
5
7
|
import { DateTime } from "luxon";
|
|
@@ -23,6 +25,11 @@ function cleanupHttpCache(cacheData) {
|
|
|
23
25
|
item
|
|
24
26
|
})));
|
|
25
27
|
for (const { httpCache, url, item } of entries) {
|
|
28
|
+
if (hashUserinfoAndQuery(url) !== url) {
|
|
29
|
+
logger.debug("http cache: removing an entry with an unsanitized key");
|
|
30
|
+
delete httpCache[url];
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
26
33
|
const parsed = HttpCache.safeParse(item);
|
|
27
34
|
if (!parsed.success || !parsed.data) {
|
|
28
35
|
logger.debug(`http cache: removing invalid cache for ${url}`);
|
|
@@ -32,7 +39,10 @@ function cleanupHttpCache(cacheData) {
|
|
|
32
39
|
if (DateTime.fromISO(parsed.data.timestamp).plus({ days: ttlDays }) < now) {
|
|
33
40
|
logger.debug(`http cache: removing expired cache for ${url}`);
|
|
34
41
|
delete httpCache[url];
|
|
42
|
+
continue;
|
|
35
43
|
}
|
|
44
|
+
const entry = item;
|
|
45
|
+
entry.httpResponse.headers = pickHeaders(entry.httpResponse.headers, persistedResponseHeaders);
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
//#endregion
|