monocrate 0.4.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 (95) hide show
  1. package/dist/collect-package-locations.d.ts +7 -43
  2. package/dist/collect-package-locations.d.ts.map +1 -1
  3. package/dist/collect-package-locations.js +23 -19
  4. package/dist/collect-package-locations.js.map +1 -1
  5. package/dist/compute-package-closure.d.ts +2 -1
  6. package/dist/compute-package-closure.d.ts.map +1 -1
  7. package/dist/compute-package-closure.js +37 -12
  8. package/dist/compute-package-closure.js.map +1 -1
  9. package/dist/file-copier.d.ts +4 -4
  10. package/dist/file-copier.d.ts.map +1 -1
  11. package/dist/file-copier.js +5 -6
  12. package/dist/file-copier.js.map +1 -1
  13. package/dist/get-files-to-pack.d.ts +3 -1
  14. package/dist/get-files-to-pack.d.ts.map +1 -1
  15. package/dist/get-files-to-pack.js +7 -33
  16. package/dist/get-files-to-pack.js.map +1 -1
  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 +5 -7
  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 +64 -18
  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 +1 -1
  56. package/dist/package-closure.d.ts.map +1 -1
  57. package/dist/{package-map.d.ts → package-location.d.ts} +9 -10
  58. package/dist/package-location.d.ts.map +1 -0
  59. package/dist/package-location.js +2 -0
  60. package/dist/package-location.js.map +1 -0
  61. package/dist/paths.d.ts +37 -0
  62. package/dist/paths.d.ts.map +1 -0
  63. package/dist/paths.js +59 -0
  64. package/dist/paths.js.map +1 -0
  65. package/dist/publish.d.ts +3 -1
  66. package/dist/publish.d.ts.map +1 -1
  67. package/dist/publish.js +2 -6
  68. package/dist/publish.js.map +1 -1
  69. package/dist/repo-explorer.d.ts +23 -0
  70. package/dist/repo-explorer.d.ts.map +1 -0
  71. package/dist/repo-explorer.js +121 -0
  72. package/dist/repo-explorer.js.map +1 -0
  73. package/dist/resolve-version.d.ts +4 -1
  74. package/dist/resolve-version.d.ts.map +1 -1
  75. package/dist/resolve-version.js +31 -33
  76. package/dist/resolve-version.js.map +1 -1
  77. package/dist/rewrite-package-json.d.ts +2 -1
  78. package/dist/rewrite-package-json.d.ts.map +1 -1
  79. package/dist/rewrite-package-json.js.map +1 -1
  80. package/dist/run-npm.d.ts +36 -0
  81. package/dist/run-npm.d.ts.map +1 -0
  82. package/dist/run-npm.js +35 -0
  83. package/dist/run-npm.js.map +1 -0
  84. package/package.json +10 -3
  85. package/dist/assemble.d.ts +0 -4
  86. package/dist/assemble.d.ts.map +0 -1
  87. package/dist/assemble.js +0 -21
  88. package/dist/assemble.js.map +0 -1
  89. package/dist/monorepo.d.ts +0 -9
  90. package/dist/monorepo.d.ts.map +0 -1
  91. package/dist/monorepo.js +0 -82
  92. package/dist/monorepo.js.map +0 -1
  93. package/dist/package-map.d.ts.map +0 -1
  94. package/dist/package-map.js +0 -2
  95. package/dist/package-map.js.map +0 -1
@@ -1,46 +1,82 @@
1
- import { defineCommand, runMain } from 'citty';
1
+ import { createRequire } from 'node:module';
2
+ import yargs from 'yargs';
3
+ import { hideBin } from 'yargs/helpers';
2
4
  import { monocrate } from './monocrate.js';
3
- const command = defineCommand({
4
- meta: {
5
- name: 'monocrate',
6
- description: 'Assemble and optionally publish a monorepo package to npm',
5
+ const require = createRequire(import.meta.url);
6
+ const pkg = require('../package.json');
7
+ const sharedOptions = {
8
+ bump: {
9
+ alias: 'b',
10
+ type: 'string',
11
+ description: 'Version or increment (patch/minor/major)',
7
12
  },
8
- args: {
9
- source: {
10
- type: 'positional',
11
- description: 'Source package directory',
12
- required: true,
13
- },
14
- output: {
15
- type: 'positional',
16
- description: 'Output directory (creates a dedicated temp directory if not specified)',
17
- required: false,
18
- },
19
- root: {
20
- type: 'string',
21
- description: 'Monorepo root directory (auto-detected if not specified)',
22
- alias: 'r',
23
- },
24
- publish: {
25
- type: 'string',
26
- description: 'Publish to npm with version: x.y.z (explicit) or patch|minor|major (increment)',
27
- alias: 'p',
28
- },
13
+ output: {
14
+ alias: 'o',
15
+ type: 'string',
16
+ description: 'Output directory',
29
17
  },
30
- async run({ args }) {
31
- const outputDir = args.output || undefined;
32
- const actualOutputDir = await monocrate({
33
- pathToSubjectPackage: args.source,
34
- ...(outputDir ? { outputDir } : {}),
35
- monorepoRoot: args.root,
36
- publishToVersion: args.publish,
37
- cwd: process.cwd(),
38
- });
39
- console.log(actualOutputDir);
18
+ root: {
19
+ alias: 'r',
20
+ type: 'string',
21
+ description: 'Monorepo root (auto-detected if omitted)',
40
22
  },
41
- });
23
+ report: {
24
+ type: 'string',
25
+ description: 'Write report to file',
26
+ },
27
+ 'mirror-to': {
28
+ alias: 'm',
29
+ type: 'string',
30
+ description: 'Mirror source files to directory',
31
+ },
32
+ };
33
+ async function runCommand(argv, publish) {
34
+ const packages = argv.packages ?? [];
35
+ if (packages.length === 0) {
36
+ throw new Error('At least one package directory must be specified');
37
+ }
38
+ const options = {
39
+ pathToSubjectPackages: packages,
40
+ outputRoot: argv.output,
41
+ monorepoRoot: argv.root,
42
+ bump: argv.bump,
43
+ publish,
44
+ report: argv.report,
45
+ cwd: process.cwd(),
46
+ mirrorTo: argv['mirror-to'],
47
+ };
48
+ await monocrate(options);
49
+ }
42
50
  export function monocrateCli() {
43
- runMain(command).catch((error) => {
51
+ const parser = yargs(hideBin(process.argv))
52
+ .scriptName('monocrate')
53
+ .version(pkg.version)
54
+ .usage(`From monorepo to npm in one command.
55
+
56
+ Point at your packages. That's it.`)
57
+ .example('$0 publish pkg/foo --bump patch', 'Bump to next patch and publish')
58
+ .example('$0 publish libs/a libs/b', 'Multi-package (defaults to minor bump)')
59
+ .command('publish <packages...>', 'Publish to npm', (yargs) => yargs.options(sharedOptions).positional('packages', {
60
+ describe: 'Package directories to publish',
61
+ type: 'string',
62
+ array: true,
63
+ }), async (argv) => {
64
+ await runCommand(argv, true);
65
+ })
66
+ .command('prepare <packages...>', 'Same as publish, but stop short of publishing', (yargs) => yargs.options(sharedOptions).positional('packages', {
67
+ describe: 'Package directories to prepare',
68
+ type: 'string',
69
+ array: true,
70
+ }), async (argv) => {
71
+ await runCommand(argv, false);
72
+ })
73
+ .demandCommand(1, 'Try: monocrate publish <package-dir>')
74
+ .strict()
75
+ .help()
76
+ .version(pkg.version)
77
+ .option('help', { hidden: true })
78
+ .option('version', { hidden: true });
79
+ void Promise.resolve(parser.parse()).catch((error) => {
44
80
  console.error('Fatal error:', error instanceof Error ? error.stack : error);
45
81
  process.exit(1);
46
82
  });
@@ -1 +1 @@
1
- {"version":3,"file":"monocrate-cli.js","sourceRoot":"","sources":["../src/monocrate-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,MAAM,OAAO,GAAG,aAAa,CAAC;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,2DAA2D;KACzE;IACD,IAAI,EAAE;QACJ,MAAM,EAAE;YACN,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,0BAA0B;YACvC,QAAQ,EAAE,IAAI;SACf;QACD,MAAM,EAAE;YACN,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,wEAAwE;YACrF,QAAQ,EAAE,KAAK;SAChB;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,0DAA0D;YACvE,KAAK,EAAE,GAAG;SACX;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,gFAAgF;YAC7F,KAAK,EAAE,GAAG;SACX;KACF;IACD,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE;QAChB,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,IAAI,SAAS,CAAA;QAC1C,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC;YACtC,oBAAoB,EAAE,IAAI,CAAC,MAAM;YACjC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,YAAY,EAAE,IAAI,CAAC,IAAI;YACvB,gBAAgB,EAAE,IAAI,CAAC,OAAO;YAC9B,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;SACnB,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,eAAe,CAA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AA;IAC9B,CAAC,CACF;SACA,OAAO,CACN,uBAAuB,EACvB,+CAA+C,EAC/C,CAAC,KAAK,EAAE,EAAE,CACR,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,UAAU,CAAC,UAAU,EAAE;QAClD,QAAQ,EAAE,gCAAgC;QAC1C,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;KACZ,CAAC,EACJ,KAAK,EAAE,IAAI,EAAE,EAAE;QACb,MAAM,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC/B,CAAC,CACF;SACA,aAAa,CAAC,CAAC,EAAE,sCAAsC,CAAC;SACxD,MAAM,EAAE;SACR,IAAI,EAAE;SACN,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;SACpB,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;SAChC,MAAM,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAEtC,KAAK,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAC5D,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -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":"AASA,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;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CA6B1E"}
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,20 +1,24 @@
1
1
  import * as fs from 'node:fs/promises';
2
+ import * as fsSync from 'node:fs';
2
3
  import * as os from 'node:os';
3
4
  import * as path from 'node:path';
4
- import { findMonorepoRoot } from './monorepo.js';
5
- import { computePackageClosure } from './compute-package-closure.js';
6
- import { assemble } from './assemble.js';
5
+ import { RepoExplorer } from './repo-explorer.js';
6
+ import { PackageAssembler } from './package-assembler.js';
7
7
  import { publish } from './publish.js';
8
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';
9
13
  /**
10
14
  * Assembles a monorepo package and its in-repo dependencies for npm publishing.
11
15
  * @param options - Configuration options for the assembly process
12
- * @returns The output directory path where the assembly was created
16
+ * @returns The result of the assembly operation
13
17
  * @throws Error if assembly or publishing fails
14
18
  */
15
19
  export async function monocrate(options) {
16
20
  // Resolve and validate cwd first, then use it to resolve all other paths
17
- const cwd = path.resolve(options.cwd);
21
+ const cwd = AbsolutePath(path.resolve(options.cwd));
18
22
  const cwdExists = await fs
19
23
  .stat(cwd)
20
24
  .then(() => true)
@@ -22,18 +26,60 @@ export async function monocrate(options) {
22
26
  if (!cwdExists) {
23
27
  throw new Error(`cwd does not exist: ${cwd}`);
24
28
  }
25
- const sourceDir = path.resolve(cwd, options.pathToSubjectPackage);
26
- const monorepoRoot = options.monorepoRoot ? path.resolve(cwd, options.monorepoRoot) : findMonorepoRoot(sourceDir);
27
- // Validate publish argument before any side effects
28
- const versionSpecifier = parseVersionSpecifier(options.publishToVersion);
29
- const outputDir = options.outputDir
30
- ? path.resolve(cwd, options.outputDir)
31
- : await fs.mkdtemp(path.join(os.tmpdir(), 'monocrate-'));
32
- const closure = await computePackageClosure(sourceDir, monorepoRoot);
33
- await assemble(closure, monorepoRoot, outputDir, versionSpecifier);
34
- if (versionSpecifier) {
35
- publish(outputDir);
36
- }
37
- return outputDir;
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`);
39
+ }
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`);
49
+ }
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');
55
+ }
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);
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);
71
+ }
72
+ if (options.report) {
73
+ const outputFilePath = path.resolve(cwd, options.report);
74
+ fsSync.writeFileSync(outputFilePath, resolvedVersion);
75
+ }
76
+ else {
77
+ console.log(resolvedVersion);
78
+ }
79
+ return {
80
+ outputDir: a0.getOutputDir(),
81
+ resolvedVersion,
82
+ summaries: assemblers.map((at) => ({ outputDir: at.getOutputDir(), packageName: at.pkgName })),
83
+ };
38
84
  }
39
85
  //# sourceMappingURL=monocrate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"monocrate.js","sourceRoot":"","sources":["../src/monocrate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAiC9D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAyB;IACvD,yEAAyE;IACzE,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACrC,MAAM,SAAS,GAAG,MAAM,EAAE;SACvB,IAAI,CAAC,GAAG,CAAC;SACT,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;SAChB,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;IACrB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACjE,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,SAAS,CAAC,C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,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;
81
+ }
82
+ }
83
+ //# sourceMappingURL=npm-client.js.map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F,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