monocrate 0.3.0 → 0.5.0

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.
Files changed (123) hide show
  1. package/dist/collect-package-locations.d.ts +12 -0
  2. package/dist/collect-package-locations.d.ts.map +1 -0
  3. package/dist/collect-package-locations.js +53 -0
  4. package/dist/collect-package-locations.js.map +1 -0
  5. package/dist/compute-package-closure.d.ts +4 -0
  6. package/dist/compute-package-closure.d.ts.map +1 -0
  7. package/dist/compute-package-closure.js +64 -0
  8. package/dist/compute-package-closure.js.map +1 -0
  9. package/dist/file-copier.d.ts +9 -0
  10. package/dist/file-copier.d.ts.map +1 -0
  11. package/dist/file-copier.js +37 -0
  12. package/dist/file-copier.js.map +1 -0
  13. package/dist/get-files-to-pack.d.ts +12 -0
  14. package/dist/get-files-to-pack.d.ts.map +1 -0
  15. package/dist/get-files-to-pack.js +20 -0
  16. package/dist/get-files-to-pack.js.map +1 -0
  17. package/dist/import-rewriter.d.ts +4 -4
  18. package/dist/import-rewriter.d.ts.map +1 -1
  19. package/dist/import-rewriter.js +6 -9
  20. package/dist/import-rewriter.js.map +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/mirror-sources.d.ts +11 -0
  25. package/dist/mirror-sources.d.ts.map +1 -0
  26. package/dist/mirror-sources.js +90 -0
  27. package/dist/mirror-sources.js.map +1 -0
  28. package/dist/monocrate-cli.d.ts.map +1 -1
  29. package/dist/monocrate-cli.js +74 -38
  30. package/dist/monocrate-cli.js.map +1 -1
  31. package/dist/monocrate-options.d.ts +67 -0
  32. package/dist/monocrate-options.d.ts.map +1 -0
  33. package/dist/monocrate-options.js +2 -0
  34. package/dist/monocrate-options.js.map +1 -0
  35. package/dist/monocrate-result.d.ts +18 -0
  36. package/dist/monocrate-result.d.ts.map +1 -0
  37. package/dist/monocrate-result.js +2 -0
  38. package/dist/monocrate-result.js.map +1 -0
  39. package/dist/monocrate.d.ts +6 -32
  40. package/dist/monocrate.d.ts.map +1 -1
  41. package/dist/monocrate.js +60 -64
  42. package/dist/monocrate.js.map +1 -1
  43. package/dist/name-mangler.d.ts +2 -0
  44. package/dist/name-mangler.d.ts.map +1 -0
  45. package/dist/name-mangler.js +4 -0
  46. package/dist/name-mangler.js.map +1 -0
  47. package/dist/npm-client.d.ts +29 -0
  48. package/dist/npm-client.d.ts.map +1 -0
  49. package/dist/npm-client.js +83 -0
  50. package/dist/npm-client.js.map +1 -0
  51. package/dist/package-assembler.d.ts +16 -0
  52. package/dist/package-assembler.d.ts.map +1 -0
  53. package/dist/package-assembler.js +52 -0
  54. package/dist/package-assembler.js.map +1 -0
  55. package/dist/package-closure.d.ts +14 -0
  56. package/dist/package-closure.d.ts.map +1 -0
  57. package/dist/package-closure.js +2 -0
  58. package/dist/package-closure.js.map +1 -0
  59. package/dist/package-json.d.ts +1 -0
  60. package/dist/package-json.d.ts.map +1 -1
  61. package/dist/package-json.js +1 -0
  62. package/dist/package-json.js.map +1 -1
  63. package/dist/package-location.d.ts +31 -0
  64. package/dist/package-location.d.ts.map +1 -0
  65. package/dist/package-location.js +2 -0
  66. package/dist/package-location.js.map +1 -0
  67. package/dist/paths.d.ts +37 -0
  68. package/dist/paths.d.ts.map +1 -0
  69. package/dist/paths.js +59 -0
  70. package/dist/paths.js.map +1 -0
  71. package/dist/publish.d.ts +4 -0
  72. package/dist/publish.d.ts.map +1 -0
  73. package/dist/publish.js +4 -0
  74. package/dist/publish.js.map +1 -0
  75. package/dist/repo-explorer.d.ts +23 -0
  76. package/dist/repo-explorer.d.ts.map +1 -0
  77. package/dist/repo-explorer.js +121 -0
  78. package/dist/repo-explorer.js.map +1 -0
  79. package/dist/resolve-version.d.ts +6 -0
  80. package/dist/resolve-version.d.ts.map +1 -0
  81. package/dist/resolve-version.js +38 -0
  82. package/dist/resolve-version.js.map +1 -0
  83. package/dist/rewrite-package-json.d.ts +4 -0
  84. package/dist/rewrite-package-json.d.ts.map +1 -0
  85. package/dist/rewrite-package-json.js +21 -0
  86. package/dist/rewrite-package-json.js.map +1 -0
  87. package/dist/run-npm.d.ts +36 -0
  88. package/dist/run-npm.d.ts.map +1 -0
  89. package/dist/run-npm.js +35 -0
  90. package/dist/run-npm.js.map +1 -0
  91. package/dist/version-specifier.d.ts +8 -0
  92. package/dist/version-specifier.d.ts.map +1 -0
  93. package/dist/version-specifier.js +17 -0
  94. package/dist/version-specifier.js.map +1 -0
  95. package/package.json +11 -3
  96. package/dist/assemble.d.ts +0 -3
  97. package/dist/assemble.d.ts.map +0 -1
  98. package/dist/assemble.js +0 -11
  99. package/dist/assemble.js.map +0 -1
  100. package/dist/build-dependency-graph.d.ts +0 -8
  101. package/dist/build-dependency-graph.d.ts.map +0 -1
  102. package/dist/build-dependency-graph.js +0 -38
  103. package/dist/build-dependency-graph.js.map +0 -1
  104. package/dist/build-package-map.d.ts +0 -4
  105. package/dist/build-package-map.d.ts.map +0 -1
  106. package/dist/build-package-map.js +0 -43
  107. package/dist/build-package-map.js.map +0 -1
  108. package/dist/dist-copier.d.ts +0 -10
  109. package/dist/dist-copier.d.ts.map +0 -1
  110. package/dist/dist-copier.js +0 -44
  111. package/dist/dist-copier.js.map +0 -1
  112. package/dist/monorepo.d.ts +0 -9
  113. package/dist/monorepo.d.ts.map +0 -1
  114. package/dist/monorepo.js +0 -82
  115. package/dist/monorepo.js.map +0 -1
  116. package/dist/package-map.d.ts +0 -8
  117. package/dist/package-map.d.ts.map +0 -1
  118. package/dist/package-map.js +0 -2
  119. package/dist/package-map.js.map +0 -1
  120. package/dist/transform-package-json.d.ts +0 -5
  121. package/dist/transform-package-json.d.ts.map +0 -1
  122. package/dist/transform-package-json.js +0 -19
  123. package/dist/transform-package-json.js.map +0 -1
@@ -0,0 +1,67 @@
1
+ export interface MonocrateOptions {
2
+ /**
3
+ * Paths to the directories of the various package to assemble. If a string, it is transformed to a single element array.
4
+ * Can be absolute or relative. Relative paths are resolved from the cwd option.
5
+ */
6
+ pathToSubjectPackages: string[] | string;
7
+ /**
8
+ * Path to the output root directory where the assembly will be written.
9
+ * The actual output will be placed in a subdirectory named after the package.
10
+ * Can be absolute or relative. Relative paths are resolved from the cwd option.
11
+ * If not specified, a dedicated temp directory is created under the system temp directory.
12
+ */
13
+ outputRoot?: string;
14
+ /**
15
+ * Path to the monorepo root directory.
16
+ * Can be absolute or relative. Relative paths are resolved from the cwd option.
17
+ * If not specified, auto-detected by searching for a root package.json with workspaces.
18
+ */
19
+ monorepoRoot?: string;
20
+ /**
21
+ * Version specifier for the assembly.
22
+ * Accepts either an explicit semver version (e.g., "1.2.3") or an increment keyword ("patch", "minor", "major").
23
+ * The resolved version is either this value (if it is an explicit semver value) or is obtained by finding the
24
+ * current version of all the packages to publish, finding the highest version of these, and then applying
25
+ * the increment depicted by this value.
26
+ *
27
+ * Defaults to "minor".
28
+ */
29
+ bump?: string;
30
+ /**
31
+ * Whether to publish the assemblies to npm after building.
32
+ * When false, the assembly is prepared with the resolved version but not published
33
+ * (useful for inspection or manual publishing).
34
+ */
35
+ publish: boolean;
36
+ /**
37
+ * Path to write the report (resolved version) to a file instead of stdout.
38
+ * Can be absolute or relative. Relative paths are resolved from the cwd option.
39
+ * If not specified, output is written to stdout.
40
+ */
41
+ report?: string;
42
+ /**
43
+ * Base directory for resolving relative paths. Must be a valid, existing directory.
44
+ */
45
+ cwd: string;
46
+ /**
47
+ * Path to an .npmrc file to use in npm commands as "userconfig". Settings from this file are merged with any
48
+ * package-specific .npmrc file, with the package-specific file's settings winning on conflicts (see
49
+ * https://docs.npmjs.com/cli/v11/configuring-npm/npmrc#files).
50
+ */
51
+ npmrcPath?: string;
52
+ /**
53
+ * Path to a directory where source files should be mirrored.
54
+ *
55
+ * Primary use case: copying exact source code from a private monorepo to a public mirror
56
+ * repository for published, open-sourced, packages.
57
+ *
58
+ * Mirrors all assembled packages (the main package and its in-repo dependencies).
59
+ * Only committed files (from HEAD) are copied, preserving their path structure relative
60
+ * to the monorepo root. Fails if any package has untracked files.
61
+ * Each package's target directory is wiped before copying.
62
+ *
63
+ * Can be absolute or relative. Relative paths are resolved from the cwd option.
64
+ */
65
+ mirrorTo?: string;
66
+ }
67
+ //# sourceMappingURL=monocrate-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monocrate-options.d.ts","sourceRoot":"","sources":["../src/monocrate-options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,qBAAqB,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACxC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=monocrate-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monocrate-options.js","sourceRoot":"","sources":["../src/monocrate-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ export interface MonocrateResult {
2
+ /**
3
+ * The output directory path where the assembly of the first package was created.
4
+ */
5
+ outputDir: string;
6
+ /**
7
+ * The new version (AKA: 'resolved version') for the package (or packages).
8
+ */
9
+ resolvedVersion: string;
10
+ /**
11
+ * Details about each individual package that was assembled/published.
12
+ */
13
+ summaries: {
14
+ packageName: string;
15
+ outputDir: string;
16
+ }[];
17
+ }
18
+ //# sourceMappingURL=monocrate-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monocrate-result.d.ts","sourceRoot":"","sources":["../src/monocrate-result.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,SAAS,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CACxD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=monocrate-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monocrate-result.js","sourceRoot":"","sources":["../src/monocrate-result.ts"],"names":[],"mappings":""}
@@ -1,38 +1,12 @@
1
- export interface MonocrateOptions {
2
- /**
3
- * Path to the package directory to assemble.
4
- * Can be absolute or relative. Relative paths are resolved from the cwd option.
5
- */
6
- pathToSubjectPackage: string;
7
- /**
8
- * Path to the output directory where the assembly will be written.
9
- * Can be absolute or relative. Relative paths are resolved from the cwd option.
10
- * If not specified, a dedicated temp directory is created under the system temp directory.
11
- */
12
- outputDir?: string;
13
- /**
14
- * Path to the monorepo root directory.
15
- * Can be absolute or relative. Relative paths are resolved from the cwd option.
16
- * If not specified, auto-detected by searching for a root package.json with workspaces.
17
- */
18
- monorepoRoot?: string;
19
- /**
20
- * Publish the assembly to npm after building.
21
- * Accepts either an explicit semver version (e.g., "1.2.3") or an increment keyword ("patch", "minor", "major").
22
- * When specified, the assembly is published to npm with the resolved version.
23
- * If not specified, no publishing occurs.
24
- */
25
- publishToVersion?: string;
26
- /**
27
- * Base directory for resolving relative paths. Must be a valid, existing directory.
28
- */
29
- cwd: string;
30
- }
1
+ import type { MonocrateResult } from './monocrate-result.js';
2
+ import type { MonocrateOptions } from './monocrate-options.js';
3
+ export type { MonocrateOptions } from './monocrate-options.js';
4
+ export type { MonocrateResult } from './monocrate-result.js';
31
5
  /**
32
6
  * Assembles a monorepo package and its in-repo dependencies for npm publishing.
33
7
  * @param options - Configuration options for the assembly process
34
- * @returns The output directory path where the assembly was created
8
+ * @returns The result of the assembly operation
35
9
  * @throws Error if assembly or publishing fails
36
10
  */
37
- export declare function monocrate(options: MonocrateOptions): Promise<string>;
11
+ export declare function monocrate(options: MonocrateOptions): Promise<MonocrateResult>;
38
12
  //# sourceMappingURL=monocrate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"monocrate.d.ts","sourceRoot":"","sources":["../src/monocrate.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAA;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;CACZ;AA2BD;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkE1E"}
1
+ {"version":3,"file":"monocrate.d.ts","sourceRoot":"","sources":["../src/monocrate.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAgFnF"}
package/dist/monocrate.js CHANGED
@@ -1,40 +1,24 @@
1
- import { spawnSync } from 'node:child_process';
2
1
  import * as fs from 'node:fs/promises';
2
+ import * as fsSync from 'node:fs';
3
3
  import * as os from 'node:os';
4
4
  import * as path from 'node:path';
5
- import { z } from 'zod';
6
- import { findMonorepoRoot } from './monorepo.js';
7
- import { buildDependencyGraph } from './build-dependency-graph.js';
8
- import { assemble } from './assemble.js';
9
- import { transformPackageJson, writePackageJson } from './transform-package-json.js';
10
- const explicitVersionRegex = /^\d+\.\d+\.\d+$/;
11
- const VersionSpecifier = z.union([
12
- z.literal('patch'),
13
- z.literal('minor'),
14
- z.literal('major'),
15
- z.string().regex(explicitVersionRegex, 'Must be x.y.z format'),
16
- ]);
17
- function isExplicitVersion(value) {
18
- return explicitVersionRegex.test(value);
19
- }
20
- function getCurrentPublishedVersion(packageName) {
21
- const result = spawnSync('npm', ['view', packageName, 'version'], {
22
- encoding: 'utf-8',
23
- });
24
- if (result.status !== 0 || !result.stdout.trim()) {
25
- return '0.0.0';
26
- }
27
- return result.stdout.trim();
28
- }
5
+ import { RepoExplorer } from './repo-explorer.js';
6
+ import { PackageAssembler } from './package-assembler.js';
7
+ import { publish } from './publish.js';
8
+ import { parseVersionSpecifier } from './version-specifier.js';
9
+ import { AbsolutePath } from './paths.js';
10
+ import { maxVersion } from './resolve-version.js';
11
+ import { NpmClient } from './npm-client.js';
12
+ import { mirrorSources } from './mirror-sources.js';
29
13
  /**
30
14
  * Assembles a monorepo package and its in-repo dependencies for npm publishing.
31
15
  * @param options - Configuration options for the assembly process
32
- * @returns The output directory path where the assembly was created
16
+ * @returns The result of the assembly operation
33
17
  * @throws Error if assembly or publishing fails
34
18
  */
35
19
  export async function monocrate(options) {
36
20
  // Resolve and validate cwd first, then use it to resolve all other paths
37
- const cwd = path.resolve(options.cwd);
21
+ const cwd = AbsolutePath(path.resolve(options.cwd));
38
22
  const cwdExists = await fs
39
23
  .stat(cwd)
40
24
  .then(() => true)
@@ -42,48 +26,60 @@ export async function monocrate(options) {
42
26
  if (!cwdExists) {
43
27
  throw new Error(`cwd does not exist: ${cwd}`);
44
28
  }
45
- const sourceDir = path.resolve(cwd, options.pathToSubjectPackage);
46
- const monorepoRoot = options.monorepoRoot ? path.resolve(cwd, options.monorepoRoot) : findMonorepoRoot(sourceDir);
47
- // Validate publish argument before any side effects
48
- let versionSpecifier;
49
- if (options.publishToVersion !== undefined) {
50
- const parseResult = VersionSpecifier.safeParse(options.publishToVersion);
51
- if (!parseResult.success) {
52
- throw new Error(`Invalid publish value: "${options.publishToVersion}". Expected "patch", "minor", "major" or an explicit version such as "1.2.3"`);
53
- }
54
- versionSpecifier = parseResult.data;
29
+ const outputRoot = AbsolutePath(options.outputRoot ? path.resolve(cwd, options.outputRoot) : await fs.mkdtemp(path.join(os.tmpdir(), 'monocrate-')));
30
+ // Validate bump argument before any side effects (defaults to 'minor')
31
+ const versionSpecifier = parseVersionSpecifier(options.bump ?? 'minor');
32
+ const sources = Array.isArray(options.pathToSubjectPackages)
33
+ ? options.pathToSubjectPackages
34
+ : [options.pathToSubjectPackages];
35
+ const sourceDirs = sources.map((at) => AbsolutePath(path.resolve(cwd, at)));
36
+ const sourceDir0 = sourceDirs.at(0);
37
+ if (!sourceDir0) {
38
+ throw new Error(`At least one package must be specified`);
55
39
  }
56
- const outputDir = options.outputDir
57
- ? path.resolve(cwd, options.outputDir)
58
- : await fs.mkdtemp(path.join(os.tmpdir(), 'monocrate-'));
59
- const graph = await buildDependencyGraph(sourceDir, monorepoRoot);
60
- await assemble(graph, monorepoRoot, outputDir);
61
- const packageJson = transformPackageJson(graph);
62
- if (!versionSpecifier) {
63
- await writePackageJson(packageJson, outputDir);
64
- return outputDir;
40
+ const monorepoRoot = options.monorepoRoot
41
+ ? AbsolutePath(path.resolve(cwd, options.monorepoRoot))
42
+ : RepoExplorer.findMonorepoRoot(sourceDir0);
43
+ const explorer = await RepoExplorer.create(monorepoRoot);
44
+ const npmClient = new NpmClient({ userconfig: options.npmrcPath });
45
+ const assemblers = sourceDirs.map((at) => new PackageAssembler(npmClient, explorer, at, outputRoot));
46
+ const a0 = assemblers.at(0);
47
+ if (!a0) {
48
+ throw new Error(`Incosistency - could not find an assembler for the first package`);
65
49
  }
66
- // Publishing flow
67
- const packageName = graph.subjectPackage.packageJson.name;
68
- if (isExplicitVersion(versionSpecifier)) {
69
- await writePackageJson({ ...packageJson, version: versionSpecifier }, outputDir);
50
+ // versionSpecifier is always defined (defaults to 'minor'), so computeNewVersion always returns a string
51
+ const versions = (await Promise.all(assemblers.map((a) => a.computeNewVersion(versionSpecifier)))).flatMap((v) => v ? [v] : []);
52
+ const v = versions.at(0);
53
+ if (!v) {
54
+ throw new Error('Inconsistency - no versions computed');
70
55
  }
71
- else {
72
- const currentVersion = getCurrentPublishedVersion(packageName);
73
- await writePackageJson({ ...packageJson, version: currentVersion }, outputDir);
74
- // --no-git-tag-version: bump version in package.json only, without creating a git tag (we're in a temp directory, not a git repo)
75
- const npmVersionResult = spawnSync('npm', ['version', versionSpecifier, '--no-git-tag-version'], {
76
- cwd: outputDir,
77
- stdio: 'inherit',
78
- });
79
- if (npmVersionResult.status !== 0) {
80
- throw new Error(`npm version failed with exit code ${String(npmVersionResult.status ?? 1)}`);
56
+ const resolvedVersion = versions.reduce((soFar, curr) => maxVersion(soFar, curr), v);
57
+ const allPackages = new Map();
58
+ for (const assembler of assemblers) {
59
+ const members = await assembler.assemble(resolvedVersion);
60
+ for (const pkg of members) {
61
+ allPackages.set(pkg.name, pkg);
81
62
  }
63
+ if (options.publish) {
64
+ await publish(npmClient, assembler.getOutputDir());
65
+ }
66
+ }
67
+ // Mirror source files if mirrorTo is specified
68
+ if (options.mirrorTo) {
69
+ const mirrorDir = AbsolutePath(path.resolve(cwd, options.mirrorTo));
70
+ await mirrorSources([...allPackages.values()], mirrorDir);
82
71
  }
83
- const npmPublishResult = spawnSync('npm', ['publish'], { cwd: outputDir, stdio: 'inherit' });
84
- if (npmPublishResult.status !== 0) {
85
- throw new Error(`npm publish failed with exit code ${String(npmPublishResult.status ?? 1)}`);
72
+ if (options.report) {
73
+ const outputFilePath = path.resolve(cwd, options.report);
74
+ fsSync.writeFileSync(outputFilePath, resolvedVersion);
75
+ }
76
+ else {
77
+ console.log(resolvedVersion);
86
78
  }
87
- return outputDir;
79
+ return {
80
+ outputDir: a0.getOutputDir(),
81
+ resolvedVersion,
82
+ summaries: assemblers.map((at) => ({ outputDir: at.getOutputDir(), packageName: at.pkgName })),
83
+ };
88
84
  }
89
85
  //# sourceMappingURL=monocrate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"monocrate.js","sourceRoot":"","sources":["../src/monocrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAiCpF,MAAM,oBAAoB,GAAG,iBAAiB,CAAA;AAE9C,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAClB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAClB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAClB,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,oBAAoB,EAAE,sBAAsB,CAAC;CAC/D,CAAC,CAAA;AAIF,SAAS,iBAAiB,CAAC,KAAa;IACtC,OAAO,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACzC,CAAC;AAED,SAAS,0BAA0B,CAAC,WAAmB;IACrD,MAAM,MAAM,G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AAC;IAED,OAAO;QACL,SAAS,EAAE,EAAE,CAAC,YAAY,EAAE;QAC5B,eAAe;QACf,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,YAAY,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;KAC/F,CAAA;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function manglePackageName(name: string): string;
2
+ //# sourceMappingURL=name-mangler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name-mangler.d.ts","sourceRoot":"","sources":["../src/name-mangler.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD"}
@@ -0,0 +1,4 @@
1
+ export function manglePackageName(name) {
2
+ return name.replace(/[@/]/g, '__');
3
+ }
4
+ //# sourceMappingURL=name-mangler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"name-mangler.js","sourceRoot":"","sources":["../src/name-mangler.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { AbsolutePath } from './paths.js';
2
+ import type { NpmOptionsBase } from './run-npm.js';
3
+ export declare class NpmClient {
4
+ private readonly npmOptions?;
5
+ constructor(npmOptions?: NpmOptionsBase | undefined);
6
+ publish(dir: AbsolutePath): Promise<void>;
7
+ /**
8
+ * @param packageName
9
+ * @param cwd
10
+ * @returns the version of `packageName` or undefined (if not found)
11
+ */
12
+ viewVersion(packageName: string, cwd: AbsolutePath): Promise<string | undefined>;
13
+ pack(dir: AbsolutePath, options?: {
14
+ dryRun?: boolean;
15
+ }): Promise<{
16
+ id: string;
17
+ name: string;
18
+ version: string;
19
+ size: number;
20
+ unpackedSize: number;
21
+ shasum: string;
22
+ integrity: string;
23
+ filename: string;
24
+ files: {
25
+ path: string;
26
+ }[];
27
+ }[]>;
28
+ }
29
+ //# sourceMappingURL=npm-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-client.d.ts","sourceRoot":"","sources":["../src/npm-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AAWlD,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAAX,UAAU,CAAC,EAAE,cAAc,YAAA;IAElD,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C;;;;OAIG;IACG,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA4BhF,IAAI,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE;;;;;;;;;;;;;CA2C7D"}
@@ -0,0 +1,83 @@
1
+ import { z } from 'zod';
2
+ import { runNpm } from './run-npm.js';
3
+ const NpmErrorResponse = z.object({
4
+ error: z.object({
5
+ code: z.string().optional(),
6
+ summary: z.string().optional(),
7
+ detail: z.string().optional(),
8
+ }),
9
+ });
10
+ export class NpmClient {
11
+ npmOptions;
12
+ constructor(npmOptions) {
13
+ this.npmOptions = npmOptions;
14
+ }
15
+ async publish(dir) {
16
+ await runNpm('publish', [], dir, { ...this.npmOptions, stdio: 'inherit' });
17
+ }
18
+ /**
19
+ * @param packageName
20
+ * @param cwd
21
+ * @returns the version of `packageName` or undefined (if not found)
22
+ */
23
+ async viewVersion(packageName, cwd) {
24
+ const { ok, stdout } = await runNpm('view', ['-s', '--json', packageName, 'version'], cwd, {
25
+ ...this.npmOptions,
26
+ stdio: 'pipe',
27
+ nonZeroExitCodePolicy: 'return',
28
+ });
29
+ if (!ok) {
30
+ const parsed = NpmErrorResponse.safeParse(JSON.parse(stdout));
31
+ if (!parsed.success) {
32
+ throw new Error(`Error response of 'npm view' could not be parsed: ${stdout}`);
33
+ }
34
+ const code = parsed.data.error.code ?? 'UNKNOWN';
35
+ if (code !== 'E404') {
36
+ const detail = parsed.data.error.detail ?? parsed.data.error.summary ?? '<No Further Details>';
37
+ throw new Error(`npm view failed (${code}): ${detail}`);
38
+ }
39
+ return undefined;
40
+ }
41
+ const parsed = z.string().safeParse(JSON.parse(stdout));
42
+ if (!parsed.success) {
43
+ throw new Error(`Response of 'npm view' could not be parsed: ${stdout}`);
44
+ }
45
+ return parsed.data;
46
+ }
47
+ async pack(dir, options) {
48
+ const { stdout, ok } = await runNpm('pack', ['--json', ...(options?.dryRun ? ['--dry-run'] : [])], dir, {
49
+ ...this.npmOptions,
50
+ stdio: 'pipe',
51
+ nonZeroExitCodePolicy: 'return',
52
+ });
53
+ if (!ok) {
54
+ const parsed = NpmErrorResponse.safeParse(JSON.parse(stdout));
55
+ if (!parsed.success) {
56
+ throw new Error(`Error response of 'npm pack' could not be parsed: ${stdout}`);
57
+ }
58
+ const code = parsed.data.error.code ?? 'UNKNOWN';
59
+ const detail = parsed.data.error.detail ?? parsed.data.error.summary ?? '<No Further Details>';
60
+ throw new Error(`The 'npm view' command failed (code: ${code}): ${detail}`);
61
+ }
62
+ const parsed = z
63
+ .array(z.object({
64
+ id: z.string(),
65
+ name: z.string(),
66
+ version: z.string(),
67
+ size: z.number(),
68
+ unpackedSize: z.number(),
69
+ shasum: z.string(),
70
+ integrity: z.string(),
71
+ filename: z.string(),
72
+ files: z.array(z.object({
73
+ path: z.string(),
74
+ })),
75
+ }))
76
+ .safeParse(JSON.parse(stdout));
77
+ if (!parsed.success) {
78
+ throw new Error(`Response of 'npm pack' could not be parsed: ${parsed.error.message}`);
79
+ }
80
+ return parsed.data;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AC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;QACxF,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAA;IACpB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { VersionSpecifier } from './version-specifier.js';
2
+ import { AbsolutePath } from './paths.js';
3
+ import type { RepoExplorer, MonorepoPackage } from './repo-explorer.js';
4
+ import type { NpmClient } from './npm-client.js';
5
+ export declare class PackageAssembler {
6
+ private readonly npmClient;
7
+ private readonly explorer;
8
+ private readonly fromDir;
9
+ private readonly outputRoot;
10
+ readonly pkgName: string;
11
+ constructor(npmClient: NpmClient, explorer: RepoExplorer, fromDir: AbsolutePath, outputRoot: AbsolutePath);
12
+ getOutputDir(): AbsolutePath;
13
+ computeNewVersion(versionSpecifier: VersionSpecifier | undefined): Promise<string | undefined>;
14
+ assemble(newVersion: string | undefined): Promise<MonorepoPackage[]>;
15
+ }
16
+ //# sourceMappingURL=package-assembler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-assembler.d.ts","sourceRoot":"","sources":["../src/package-assembler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,qBAAa,gBAAgB;IAGzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAL7B,QAAQ,CAAC,OAAO,SAAA;gBAEG,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,YAAY;IAS3C,YAAY;IAIN,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,SAAS;IAMhE,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CAoB3E"}
@@ -0,0 +1,52 @@
1
+ import * as fsPromises from 'node:fs/promises';
2
+ import { collectPackageLocations } from './collect-package-locations.js';
3
+ import { FileCopier } from './file-copier.js';
4
+ import { ImportRewriter } from './import-rewriter.js';
5
+ import { resolveVersion } from './resolve-version.js';
6
+ import { rewritePackageJson } from './rewrite-package-json.js';
7
+ import { AbsolutePath, RelativePath } from './paths.js';
8
+ import { computePackageClosure } from './compute-package-closure.js';
9
+ import { manglePackageName } from './name-mangler.js';
10
+ export class PackageAssembler {
11
+ npmClient;
12
+ explorer;
13
+ fromDir;
14
+ outputRoot;
15
+ pkgName;
16
+ constructor(npmClient, explorer, fromDir, outputRoot) {
17
+ this.npmClient = npmClient;
18
+ this.explorer = explorer;
19
+ this.fromDir = fromDir;
20
+ this.outputRoot = outputRoot;
21
+ const found = this.explorer.listPackages().find((at) => at.fromDir === fromDir);
22
+ if (!found) {
23
+ throw new Error(`Unrecognized package source dir: "${this.fromDir}"`);
24
+ }
25
+ this.pkgName = found.name;
26
+ }
27
+ getOutputDir() {
28
+ return AbsolutePath.join(this.outputRoot, RelativePath(manglePackageName(this.pkgName)));
29
+ }
30
+ async computeNewVersion(versionSpecifier) {
31
+ return versionSpecifier
32
+ ? await resolveVersion(this.npmClient, this.fromDir, this.pkgName, versionSpecifier)
33
+ : Promise.resolve(undefined);
34
+ }
35
+ async assemble(newVersion) {
36
+ const closure = computePackageClosure(this.pkgName, this.explorer);
37
+ const outputDir = this.getOutputDir();
38
+ const locations = await collectPackageLocations(this.npmClient, closure, outputDir);
39
+ const packageMap = new Map(locations.map((at) => [at.name, at]));
40
+ const subject = packageMap.get(closure.subjectPackageName);
41
+ if (!subject) {
42
+ throw new Error(`Internal mismatch: could not find location data of "${closure.subjectPackageName}"`);
43
+ }
44
+ await fsPromises.mkdir(outputDir, { recursive: true });
45
+ const copiedFiles = await new FileCopier(packageMap).copy();
46
+ await new ImportRewriter(packageMap).rewriteAll(copiedFiles);
47
+ // This must happen after file copying completes (otherwise the rewritten package.json could be overwritten)
48
+ rewritePackageJson(closure, newVersion, outputDir);
49
+ return closure.members;
50
+ }
51
+ }
52
+ //# sourceMappingURL=package-assembler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-assembler.js","sourceRoot":"","sources":["../src/package-assembler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAGrD,MAAM,OAAO,gBAAgB;IAGR;IACA;IACA;IACA;IALV,OAAO,CAAA;IAChB,YACmB,SAAoB,EACpB,QAAsB,EACtB,OAAqB,EACrB,UAAwB;QAHxB,cAAS,GAAT,SAAS,CAAW;QACpB,aAAQ,GAAR,QAAQ,CAAc;QACtB,YAAO,GAAP,OAAO,CAAc;QACrB,eAAU,GAAV,UAAU,CAAc;QAEzC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,KAAK,OAAO,CAAC,CAAA;QAC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G,CAAC;QAED,MAAM,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACtD,MAAM,WAAW,GAAG,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAA;QAC3D,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;QAE5D,4GAA4G;QAC5G,kBAAkB,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;QAElD,OAAO,OAAO,CAAC,OAAO,CAAA;IACxB,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import type { MonorepoPackage } from './repo-explorer.js';
2
+ /**
3
+ * The transitive closure of packages needed to publish a monorepo package. Computed by traversing dependencies
4
+ * starting from a subject package.
5
+ */
6
+ export interface PackageClosure {
7
+ /** The name of package we care about (the root of the closure). */
8
+ subjectPackageName: string;
9
+ /** The subject package all in-repo dependencies (direct or indirect dependencies). */
10
+ members: MonorepoPackage[];
11
+ /** Merged third-party dependencies from all packages in the closure. */
12
+ allThirdPartyDeps: Partial<Record<string, string>>;
13
+ }
14
+ //# sourceMappingURL=package-closure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-closure.d.ts","sourceRoot":"","sources":["../src/package-closure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEzD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,kBAAkB,EAAE,MAAM,CAAA;IAC1B,sFAAsF;IACtF,OAAO,EAAE,eAAe,EAAE,CAAA;IAC1B,wEAAwE;IACxE,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACnD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=package-closure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-closure.js","sourceRoot":"","sources":["../src/package-closure.ts"],"names":[],"mappings":""}
@@ -33,6 +33,7 @@ export declare const PackageJson: z.ZodObject<{
33
33
  workspaces: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodObject<{
34
34
  packages: z.ZodArray<z.ZodString>;
35
35
  }, z.core.$strip>]>>;
36
+ files: z.ZodOptional<z.ZodArray<z.ZodString>>;
36
37
  }, z.core.$loose>;
37
38
  export type PackageJson = z.infer<typeof PackageJson>;
38
39
  //# sourceMappingURL=package-json.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../src/package-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsBd,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA"}
1
+ {"version":3,"file":"package-json.d.ts","sourceRoot":"","sources":["../src/package-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuBd,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA"}
@@ -20,6 +20,7 @@ export const PackageJson = z
20
20
  bin: z.union([z.string(), z.partialRecord(z.string(), z.string())]).optional(),
21
21
  type: z.enum(['module', 'commonjs']).optional(),
22
22
  workspaces: z.union([z.array(z.string()), z.object({ packages: z.array(z.string()) })]).optional(),
23
+ files: z.array(z.string()).optional(),
23
24
  })
24
25
  .loose();
25
26
  //# sourceMappingURL=package-json.js.map