@ms-cloudpack/package-utilities 12.0.2 → 12.0.3

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 +1 @@
1
- {"version":3,"file":"getNonSemverTransform.d.ts","sourceRoot":"","sources":["../../src/packageDefinitions/getNonSemverTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAM7E;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,0BAA0B,CAoFlE"}
1
+ {"version":3,"file":"getNonSemverTransform.d.ts","sourceRoot":"","sources":["../../src/packageDefinitions/getNonSemverTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAA4B,MAAM,4BAA4B,CAAC;AAiBvG;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,0BAA0B,CAgHlE"}
@@ -1,6 +1,16 @@
1
1
  import semver from 'semver';
2
2
  import { generateVersionFromNonSemver } from './generateVersionFromNonSemver.js';
3
3
  const depTypes = ['dependencies', 'peerDependencies', 'devDependencies', 'optionalDependencies'];
4
+ /**
5
+ * Match yarn berry (v2+) patch versions:
6
+ * `patch:@foo/bar@npm%3A7.18.0#~/.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`
7
+ *
8
+ * - `[1]` is the part of the version before the `#`
9
+ * - `[2]` is the patch path relative to root: `.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`
10
+ */
11
+ // Be strict about matching yarn's generated path in case of other patching-related cases that
12
+ // might need different handling (those could be explicitly supported later if needed).
13
+ const yarnBerryPatchRegex = /^(patch:.*?)#~\/(\.yarn\/patches\/.*\.patch)$/;
4
14
  /**
5
15
  * Get a transform which handles non-semver dependencies:
6
16
  * - In a parent package, if a dependency is specified with a non-semver version, change the dep
@@ -14,6 +24,18 @@ export function getNonSemverTransform() {
14
24
  * Map from parent name/version => dep type => non-semver dependency names
15
25
  */
16
26
  const nonSemverDeps = {};
27
+ /**
28
+ * Map from transformed yarn berry patch versions to relative patch file paths.
29
+ * (This is necessary to save because the original path is only available in the parent's deps,
30
+ * but it needs to be added to the child's cloudpack metadata.)
31
+ *
32
+ * Example:
33
+ * - Original version: `patch:@foo/bar@npm%3A7.18.0#~/.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`
34
+ * - the part after `#~/` is the patch file path
35
+ * - Transformed version: `0.0.0-patch--foo-bar-npm-3A7-18-0`
36
+ * - This map: `0.0.0-patch--foo-bar-npm-3A7-18-0` to `.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`
37
+ */
38
+ const yarnPatchVersionsToFiles = {};
17
39
  return ({ definition, packagePath, importerContext }) => {
18
40
  // Check for non-semver dependencies
19
41
  for (const depType of depTypes) {
@@ -31,9 +53,18 @@ export function getNonSemverTransform() {
31
53
  `(in ${definition.name}@${definition.version} at ${packagePath}). ` +
32
54
  "Cloudpack will attempt to handle this, but it's recommended to use semantic versions only if possible.");
33
55
  }
56
+ const patchFileMatch = depVersion.match(yarnBerryPatchRegex);
34
57
  // Update the version in the returned dependencies:
35
58
  // "bar": "npm:@custom/bar@^1" => "0.0.0-npm--custom-bar--1"
36
- deps[depName] = generateVersionFromNonSemver(depVersion);
59
+ // (For the yarn berry patch files, remove the path from the end to make the version shorter;
60
+ // this will probably still be a unique version/not collide with anything else.)
61
+ const updatedVersion = generateVersionFromNonSemver(patchFileMatch?.[1] || depVersion);
62
+ deps[depName] = updatedVersion;
63
+ if (patchFileMatch) {
64
+ // This version corresponds to a yarn berry patch file.
65
+ // Save the patch file path for reference when we're updating the child package.
66
+ yarnPatchVersionsToFiles[updatedVersion] = patchFileMatch[2];
67
+ }
37
68
  // Save that this was a non-semver dep
38
69
  const record = (nonSemverDeps[`${definition.name}@${definition.version}`] ??= {});
39
70
  (record[depType] ??= []).push(depName);
@@ -64,6 +95,13 @@ export function getNonSemverTransform() {
64
95
  const origSpec = `${definition.name}@${definition.version}`;
65
96
  definition.name = importedName;
66
97
  definition.version = versionRequirement;
98
+ if (yarnPatchVersionsToFiles[versionRequirement]) {
99
+ // This version corresponds to a yarn berry patch file.
100
+ // Save the patch file path for reference in PackagePatchesCache.
101
+ // (technically `cloudpack.mode` is required, but it's set in another transform)
102
+ definition.cloudpack ??= {};
103
+ definition.cloudpack.patchFilePath = yarnPatchVersionsToFiles[versionRequirement];
104
+ }
67
105
  // We have changed the definition, so link the entry in nonSemverDeps to the new name/version.
68
106
  if (nonSemverDeps[origSpec]) {
69
107
  nonSemverDeps[`${importedName}@${versionRequirement}`] = nonSemverDeps[origSpec];
@@ -1 +1 @@
1
- {"version":3,"file":"getNonSemverTransform.js","sourceRoot":"","sources":["../../src/packageDefinitions/getNonSemverTransform.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,CAAU,CAAC;AAE1G;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB;IACnC;;;OAGG;IACH,MAAM,aAAa,GAGf,EAAE,CAAC;IAEP,OAAO,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,EAAE;QACtD,oCAAoC;QACpC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAEvC,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzD,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oBACjD,SAAS;gBACX,CAAC;gBAED,0EAA0E;gBAC1E,0FAA0F;gBAC1F,wFAAwF;g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M,QAAQ,GAAG,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAW,CAAC;gBACrE,UAAU,CAAC,IAAI,GAAG,YAAY,CAAC;gBAC/B,UAAU,CAAC,OAAO,GAAG,kBAAkB,CAAC;gBAExC,8FAA8F;gBAC9F,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC5B,aAAa,CAAC,GAAG,YAAY,IAAI,kBAAkB,EAAE,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;gBACnF,CAAC;gBAED,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageDefinitionTransform } from '@ms-cloudpack/common-types';\nimport semver from 'semver';\nimport { generateVersionFromNonSemver } from './generateVersionFromNonSemver.js';\n\nconst depTypes = ['dependencies', 'peerDependencies', 'devDependencies', 'optionalDependencies'] as const;\n\n/**\n * Get a transform which handles non-semver dependencies:\n * - In a parent package, if a dependency is specified with a non-semver version, change the dep\n * to a special `0.0.0-<original-version>` prerelease version.\n * - In a child package, if the package was pulled in as a non-semver dependency by a parent\n * (per the `importerContext`), change its version to the special prerelease version as above.\n */\nexport function getNonSemverTransform(): PackageDefinitionTransform {\n /**\n * Cached info about parent packages with non-semver dependencies:\n * Map from parent name/version => dep type => non-semver dependency names\n */\n const nonSemverDeps: Record<\n `${string}@${string}`,\n Partial<Record<'dependencies' | 'peerDependencies' | 'devDependencies' | 'optionalDependencies', string[]>>\n > = {};\n\n return ({ definition, packagePath, importerContext }) => {\n // Check for non-semver dependencies\n for (const depType of depTypes) {\n const deps = definition[depType] || {};\n\n for (const [depName, depVersion] of Object.entries(deps)) {\n if (!depVersion || semver.validRange(depVersion)) {\n continue;\n }\n\n // Don't warn about workspace: deps, but still process them as non-semver.\n // (Alternatively, we could change the version of all workspace deps to * in dependencies,\n // but that's risky since there could theoretically be an additional version of that dep\n // from the registry nested somewhere in the tree.)\n if (!depVersion.startsWith('workspace:')) {\n console.debug(\n `Non-semver dependency found: ${depName}@${depVersion} ` +\n `(in ${definition.name}@${definition.version} at ${packagePath}). ` +\n \"Cloudpack will attempt to handle this, but it's recommended to use semantic versions only if possible.\",\n );\n }\n\n // Update the version in the returned dependencies:\n // \"bar\": \"npm:@custom/bar@^1\" => \"0.0.0-npm--custom-bar--1\"\n deps[depName] = generateVersionFromNonSemver(depVersion);\n\n // Save that this was a non-semver dep\n const record = (nonSemverDeps[`${definition.name}@${definition.version}`] ??= {});\n (record[depType] ??= []).push(depName);\n }\n }\n\n // Check if this package's parent pulled it in with a non-semver dependency, and if so,\n // update the returned name and version.\n const nonSemverParentInfo =\n importerContext && nonSemverDeps[`${importerContext.parentName}@${importerContext.parentVersion}`];\n\n // TODO: maybe this could also be used for resolutions if we have problems there:\n // adding a check for !semver.satisfies(requiredAs, definition.version) and forcing the package version?\n\n if (nonSemverParentInfo) {\n // The parent has at least one non-semver dependency (which might not be this package).\n // Check in each dependency type to see if this package is listed as non-semver.\n const { importedName, versionRequirement } = importerContext;\n\n for (const depType of depTypes) {\n if (!nonSemverParentInfo[depType]?.includes(importedName)) {\n continue;\n }\n\n // This package's parent pulled it in with a non-semver dependency.\n // Example: the parent depended on this package as \"bar\": \"npm:@custom/bar@^1\"\n // importedName = bar\n // versionRequirement = 0.0.0-npm--custom-bar--1 (was modified when this transform ran on the parent definition)\n //\n // To ensure other code handles this package properly, change its name and version to\n // the ones used by the parent (after transforms). This ensures it works properly with\n // the resolve map and isn't accidentally used by other packages which depend on this\n // package under its real name.\n const origSpec = `${definition.name}@${definition.version}` as const;\n definition.name = importedName;\n definition.version = versionRequirement;\n\n // We have changed the definition, so link the entry in nonSemverDeps to the new name/version.\n if (nonSemverDeps[origSpec]) {\n nonSemverDeps[`${importedName}@${versionRequirement}`] = nonSemverDeps[origSpec];\n }\n\n break;\n }\n }\n\n return definition;\n };\n}\n"]}
1
+ {"version":3,"file":"getNonSemverTransform.js","sourceR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F,qFAAqF;gBACrF,+BAA+B;gBAC/B,MAAM,QAAQ,GAAG,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAW,CAAC;gBACrE,UAAU,CAAC,IAAI,GAAG,YAAY,CAAC;gBAC/B,UAAU,CAAC,OAAO,GAAG,kBAAkB,CAAC;gBAExC,IAAI,wBAAwB,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBACjD,uDAAuD;oBACvD,iEAAiE;oBACjE,gFAAgF;oBAChF,UAAU,CAAC,SAAS,KAAK,EAA8B,CAAC;oBACxD,UAAU,CAAC,SAAS,CAAC,aAAa,GAAG,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;gBACpF,CAAC;gBAED,8FAA8F;gBAC9F,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC5B,aAAa,CAAC,GAAG,YAAY,IAAI,kBAAkB,EAAE,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;gBACnF,CAAC;gBAED,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageDefinitionTransform, PackageJsonCloudpackMeta } from '@ms-cloudpack/common-types';\nimport semver from 'semver';\nimport { generateVersionFromNonSemver } from './generateVersionFromNonSemver.js';\n\nconst depTypes = ['dependencies', 'peerDependencies', 'devDependencies', 'optionalDependencies'] as const;\n\n/**\n * Match yarn berry (v2+) patch versions:\n * `patch:@foo/bar@npm%3A7.18.0#~/.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`\n *\n * - `[1]` is the part of the version before the `#`\n * - `[2]` is the patch path relative to root: `.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`\n */\n// Be strict about matching yarn's generated path in case of other patching-related cases that\n// might need different handling (those could be explicitly supported later if needed).\nconst yarnBerryPatchRegex = /^(patch:.*?)#~\\/(\\.yarn\\/patches\\/.*\\.patch)$/;\n\n/**\n * Get a transform which handles non-semver dependencies:\n * - In a parent package, if a dependency is specified with a non-semver version, change the dep\n * to a special `0.0.0-<original-version>` prerelease version.\n * - In a child package, if the package was pulled in as a non-semver dependency by a parent\n * (per the `importerContext`), change its version to the special prerelease version as above.\n */\nexport function getNonSemverTransform(): PackageDefinitionTransform {\n /**\n * Cached info about parent packages with non-semver dependencies:\n * Map from parent name/version => dep type => non-semver dependency names\n */\n const nonSemverDeps: Record<`${string}@${string}`, Partial<Record<(typeof depTypes)[number], string[]>>> = {};\n /**\n * Map from transformed yarn berry patch versions to relative patch file paths.\n * (This is necessary to save because the original path is only available in the parent's deps,\n * but it needs to be added to the child's cloudpack metadata.)\n *\n * Example:\n * - Original version: `patch:@foo/bar@npm%3A7.18.0#~/.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`\n * - the part after `#~/` is the patch file path\n * - Transformed version: `0.0.0-patch--foo-bar-npm-3A7-18-0`\n * - This map: `0.0.0-patch--foo-bar-npm-3A7-18-0` to `.yarn/patches/@foo-bar-npm-7.18.0-f1d556a934.patch`\n */\n const yarnPatchVersionsToFiles: Record<string, string> = {};\n\n return ({ definition, packagePath, importerContext }) => {\n // Check for non-semver dependencies\n for (const depType of depTypes) {\n const deps = definition[depType] || {};\n\n for (const [depName, depVersion] of Object.entries(deps)) {\n if (!depVersion || semver.validRange(depVersion)) {\n continue;\n }\n\n // Don't warn about workspace: deps, but still process them as non-semver.\n // (Alternatively, we could change the version of all workspace deps to * in dependencies,\n // but that's risky since there could theoretically be an additional version of that dep\n // from the registry nested somewhere in the tree.)\n if (!depVersion.startsWith('workspace:')) {\n console.debug(\n `Non-semver dependency found: ${depName}@${depVersion} ` +\n `(in ${definition.name}@${definition.version} at ${packagePath}). ` +\n \"Cloudpack will attempt to handle this, but it's recommended to use semantic versions only if possible.\",\n );\n }\n\n const patchFileMatch = depVersion.match(yarnBerryPatchRegex);\n\n // Update the version in the returned dependencies:\n // \"bar\": \"npm:@custom/bar@^1\" => \"0.0.0-npm--custom-bar--1\"\n // (For the yarn berry patch files, remove the path from the end to make the version shorter;\n // this will probably still be a unique version/not collide with anything else.)\n const updatedVersion = generateVersionFromNonSemver(patchFileMatch?.[1] || depVersion);\n deps[depName] = updatedVersion;\n\n if (patchFileMatch) {\n // This version corresponds to a yarn berry patch file.\n // Save the patch file path for reference when we're updating the child package.\n yarnPatchVersionsToFiles[updatedVersion] = patchFileMatch[2];\n }\n\n // Save that this was a non-semver dep\n const record = (nonSemverDeps[`${definition.name}@${definition.version}`] ??= {});\n (record[depType] ??= []).push(depName);\n }\n }\n\n // Check if this package's parent pulled it in with a non-semver dependency, and if so,\n // update the returned name and version.\n const nonSemverParentInfo =\n importerContext && nonSemverDeps[`${importerContext.parentName}@${importerContext.parentVersion}`];\n\n // TODO: maybe this could also be used for resolutions if we have problems there:\n // adding a check for !semver.satisfies(requiredAs, definition.version) and forcing the package version?\n\n if (nonSemverParentInfo) {\n // The parent has at least one non-semver dependency (which might not be this package).\n // Check in each dependency type to see if this package is listed as non-semver.\n const { importedName, versionRequirement } = importerContext;\n\n for (const depType of depTypes) {\n if (!nonSemverParentInfo[depType]?.includes(importedName)) {\n continue;\n }\n\n // This package's parent pulled it in with a non-semver dependency.\n // Example: the parent depended on this package as \"bar\": \"npm:@custom/bar@^1\"\n // importedName = bar\n // versionRequirement = 0.0.0-npm--custom-bar--1 (was modified when this transform ran on the parent definition)\n //\n // To ensure other code handles this package properly, change its name and version to\n // the ones used by the parent (after transforms). This ensures it works properly with\n // the resolve map and isn't accidentally used by other packages which depend on this\n // package under its real name.\n const origSpec = `${definition.name}@${definition.version}` as const;\n definition.name = importedName;\n definition.version = versionRequirement;\n\n if (yarnPatchVersionsToFiles[versionRequirement]) {\n // This version corresponds to a yarn berry patch file.\n // Save the patch file path for reference in PackagePatchesCache.\n // (technically `cloudpack.mode` is required, but it's set in another transform)\n definition.cloudpack ??= {} as PackageJsonCloudpackMeta;\n definition.cloudpack.patchFilePath = yarnPatchVersionsToFiles[versionRequirement];\n }\n\n // We have changed the definition, so link the entry in nonSemverDeps to the new name/version.\n if (nonSemverDeps[origSpec]) {\n nonSemverDeps[`${importedName}@${versionRequirement}`] = nonSemverDeps[origSpec];\n }\n\n break;\n }\n }\n\n return definition;\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "12.0.2",
3
+ "version": "12.0.3",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,10 +14,10 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.24.11",
17
+ "@ms-cloudpack/common-types": "^0.24.12",
18
18
  "@ms-cloudpack/json-utilities": "^0.1.10",
19
19
  "@ms-cloudpack/path-string-parsing": "^1.2.6",
20
- "@ms-cloudpack/path-utilities": "^3.0.8",
20
+ "@ms-cloudpack/path-utilities": "^3.0.9",
21
21
  "@ms-cloudpack/task-reporter": "^0.16.0",
22
22
  "acorn": "^8.11.2",
23
23
  "acorn-walk": "^8.2.1",