@ms-cloudpack/package-hashes 0.8.0 → 0.8.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findProjectRoot } from '@ms-cloudpack/path-utilities';
|
|
2
2
|
import fsPromises from 'fs/promises';
|
|
3
|
-
import glob from '
|
|
3
|
+
import { glob } from 'tinyglobby';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { parsePatchFilePath } from './parsePatchFilePath.js';
|
|
6
6
|
/** Default `patch-package` patches path. (yarn v2+ patches are handled separately.) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePatchesCache.js","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"PackagePatchesCache.js","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,uFAAuF;AACvF,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAkB7C;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAYD;IAX7B;;;;;;OAMG;IACK,QAAQ,CAA8C;IACtD,OAAO,GAAG,KAAK,CAAC;IAChB,SAAS,CAAqB;IAEtC,YAA6B,QAAgC;QAAhC,aAAQ,GAAR,QAAQ,CAAwB;QAC3D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,IAAI,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ises from 'fs/promises';\nimport { glob } from 'tinyglobby';\nimport path from 'path';\nimport { parsePatchFilePath } from './parsePatchFilePath.js';\nimport type { PackageJson } from '@ms-cloudpack/common-types';\n\n/** Default `patch-package` patches path. (yarn v2+ patches are handled separately.) */\nconst defaultGlobPattern = 'patches/*.patch';\n\nexport interface PackagePatchesSettings {\n /** Working directory, used to determine the project root where patches are stored. */\n cwd: string;\n\n /** Custom glob pattern for patch files (from `AppConfig.patchFilesGlobPattern`). */\n globPattern?: string;\n\n /** Patches to use instead of reading from disk (for testing). */\n patches?: Record<`${string}@${string}`, PackagePatch>;\n}\n\ninterface PackagePatch {\n path: string;\n contents?: string;\n}\n\n/**\n * PackagePatchesCache manages a cache of information about patch files, which are usually stored in the\n * `patches` folder at the root of the repo (also handles yarn v2+ patches).\n */\nexport class PackagePatchesCache {\n /**\n * Mapping from package key (see `getKey`) to patch file path and contents.\n *\n * The paths from `globPattern` (or `defaultGlobPattern`) are saved in an initial pass, but the\n * contents are only read on first request (in case of very large patches for packages that\n * cloudpack doesn't process). Yarn v2+ patches are also lazy loaded.\n */\n private _patches: Record<`${string}@${string}`, PackagePatch>;\n private _loaded = false;\n private _rootPath: string | undefined;\n\n constructor(private readonly settings: PackagePatchesSettings) {\n this._patches = settings.patches || {};\n }\n\n private getKey(packageName: string, version: string): `${string}@${string}` {\n return `${packageName}@${version}`;\n }\n\n /**\n * Loads the list of patched packages from the `patches` folder.\n */\n private async loadPatchedPackages(): Promise<void> {\n if (this._loaded) {\n return;\n }\n\n this._loaded = true;\n\n // get the repo root\n this._rootPath = findProjectRoot(this.settings.cwd) || this.settings.cwd;\n\n // get the files with .patch extension\n const patchFiles = await glob(this.settings.globPattern || defaultGlobPattern, {\n cwd: this._rootPath,\n absolute: true,\n });\n\n for (const absoluteFilePath of patchFiles) {\n try {\n const normalizedPath = path.normalize(absoluteFilePath);\n\n const { packageName, version } = parsePatchFilePath(normalizedPath);\n\n console.debug(`Found patch file for package: ${packageName}@${version}`);\n\n this._patches[this.getKey(packageName, version)] = { path: normalizedPath };\n } catch (e) {\n console.warn(`Invalid patch file \"${absoluteFilePath}\": ${e}`);\n }\n }\n }\n\n private async readPatchFile(patchFilePath: string): Promise<string> {\n try {\n return await fsPromises.readFile(patchFilePath, 'utf-8');\n } catch (e) {\n console.warn(`Error reading patch file \"${patchFilePath}\": ${e}`);\n return '';\n }\n }\n\n /**\n * Gets info about the patch file for the specified package.\n * @returns Patch file path and contents if the package has been patched, undefined otherwise.\n */\n public async getPackagePatch(definition: PackageJson): Promise<PackagePatch | undefined> {\n if (!this._loaded) {\n await this.loadPatchedPackages();\n }\n\n const key = this.getKey(definition.name, definition.version);\n\n let patchInfo = this._patches[key];\n\n if (!patchInfo && definition.cloudpack?.patchFilePath && this._rootPath) {\n // Yarn v2+ patch files don't use a parseable name, so we handle them separately.\n // The file paths are like .yarn/patches/@foo-bar-baz-npm-4.3.0-e85334d38f.patch\n // without a way to distinguish where the scope ends.\n console.debug(`Found yarn patch file for package: ${key}`);\n patchInfo = { path: path.join(this._rootPath, definition.cloudpack.patchFilePath) };\n this._patches[key] = patchInfo;\n }\n\n if (patchInfo) {\n // The contents are lazy loaded\n patchInfo.contents ??= await this.readPatchFile(patchInfo.path);\n return patchInfo;\n }\n\n return undefined;\n }\n}\n"]}
|
package/lib/getSourceHash.js
CHANGED
package/lib/getSourceHash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceHash.js","sourceRoot":"","sources":["../src/getSourceHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"getSourceHash.js","sourceRoot":"","sources":["../src/getSourceHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAIhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAInC;IACC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAEhC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC5C,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAEpE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE;QACjC,GAAG,EAAE,WAAW;QAChB,4GAA4G;QAC5G,wFAAwF;QACxF,qFAAqF;QACrF,MAAM,EAAE,CAAC,iBAAiB,EAAE,uBAAuB,CAAC;KACrD,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC,CAAC;IAEnD,OAAO,CAAC,KAAK,CAAC,0BAA0B,WAAW,OAAO,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC;IAEzF,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { appConfigFileName, generatedConfigFileName } from '@ms-cloudpack/config';\nimport { glob } from 'tinyglobby';\nimport { hash } from 'glob-hasher';\nimport { sourceFilesGlobs } from '@ms-cloudpack/path-utilities';\n\nexport type FilesHash = ReturnType<typeof hash>;\n\n/**\n * Get the hash of the source files in a package.\n * - If there is an `src` folder, hash the files in that folder, the `*.json` files and the `inputPaths`.\n * - If there are `inputPaths`, hash only those files.\n * - Otherwise, hash all files except `node_modules`.\n */\nexport async function getSourceHash(options: {\n packagePath: string;\n /** Input paths from the package settings */\n inputPaths: string[] | undefined;\n}): Promise<FilesHash> {\n const start = performance.now();\n\n const { packagePath, inputPaths } = options;\n // Use the inputPaths if they are defined, otherwise use the default patterns\n const patterns = inputPaths?.length ? inputPaths : sourceFilesGlobs;\n\n const files = await glob(patterns, {\n cwd: packagePath,\n // We want to ignore the app config and generated config files because they are not part of the source code.\n // Ignoring the generated config is especially important because it changes during init,\n // and it would invalidate the cache for the entry package with the generated config.\n ignore: [appConfigFileName, generatedConfigFileName],\n });\n\n const globHash = hash(files, { cwd: packagePath });\n\n console.debug(`Hashed source files in ${packagePath} in ${performance.now() - start}ms`);\n\n return globHash;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-hashes",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "Utilities for hashing packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
18
|
-
"@ms-cloudpack/config": "^0.35.
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^12.3.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.24.17",
|
|
18
|
+
"@ms-cloudpack/config": "^0.35.2",
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^12.3.5",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
21
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
22
|
-
"fast-glob": "^3.2.12",
|
|
21
|
+
"@ms-cloudpack/path-utilities": "^3.1.2",
|
|
23
22
|
"glob-hasher": "^1.4.2",
|
|
24
|
-
"object-hash": "^3.0.0"
|
|
23
|
+
"object-hash": "^3.0.0",
|
|
24
|
+
"tinyglobby": "^0.2.13"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|