@fuman/build 0.0.3 → 0.0.5

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.
@@ -5,13 +5,19 @@ export declare function runContinuousRelease(params: {
5
5
  workspace?: WorkspacePackage[];
6
6
  distDir?: string;
7
7
  extraArgs?: string[];
8
+ onlyChanged?: boolean;
9
+ onlyChangedSince?: string;
8
10
  }): Promise<void>;
9
11
  export declare const runContinuousReleaseCli: bc.Command<{
10
12
  root: string | undefined;
11
13
  distDir: string | undefined;
12
14
  extraArgs: string | undefined;
15
+ onlyChanged: boolean;
16
+ onlyChangedSince: string | undefined;
13
17
  }, {
14
18
  extraArgs: string[] | undefined;
15
19
  root: string | undefined;
16
20
  distDir: string | undefined;
21
+ onlyChanged: boolean;
22
+ onlyChangedSince: string | undefined;
17
23
  }>;
@@ -2,24 +2,77 @@ import { join } from "node:path";
2
2
  import process from "node:process";
3
3
  import { asNonNull } from "@fuman/utils";
4
4
  import { isRunningInGithubActions } from "../../ci/github-actions.js";
5
+ import { getLatestTag } from "../../git/utils.js";
5
6
  import { exec } from "../../misc/exec.js";
6
7
  import { collectPackageJsons, filterPackageJsonsForPublish } from "../../package-json/collect-package-jsons.js";
7
- import * as bc from "@drizzle-team/brocli";
8
+ import { findProjectChangedPackages } from "../../versioning/collect-files.js";
9
+ import { loadConfig } from "./_utils.js";
8
10
  import { buildPackage } from "./build.js";
11
+ import * as bc from "@drizzle-team/brocli";
9
12
  async function runContinuousRelease(params) {
10
13
  const {
11
14
  workspaceRoot = process.cwd(),
12
15
  workspace = await collectPackageJsons(workspaceRoot, true),
13
16
  distDir = "dist",
14
- extraArgs = []
17
+ extraArgs = [],
18
+ onlyChanged = false,
19
+ onlyChangedSince
15
20
  } = params;
16
21
  const workspaceWithoutRoot = workspace.filter((pkg) => !pkg.root);
17
- const ordered = filterPackageJsonsForPublish(workspaceWithoutRoot, "npm");
22
+ let packages = filterPackageJsonsForPublish(workspaceWithoutRoot, "npm");
23
+ if (onlyChanged) {
24
+ const config = await loadConfig({
25
+ workspaceRoot,
26
+ require: false
27
+ });
28
+ const since = onlyChangedSince ?? await getLatestTag(workspaceRoot);
29
+ if (since == null) {
30
+ throw new Error("no previous tag found, cannot determine changeset");
31
+ }
32
+ const changedPackages = await findProjectChangedPackages({
33
+ params: config?.versioning,
34
+ workspace: workspaceWithoutRoot,
35
+ root: workspaceRoot,
36
+ since
37
+ });
38
+ if (!changedPackages.length) {
39
+ console.log(`🤔 no packages changed since ${since}, nothing to do`);
40
+ return;
41
+ }
42
+ const changedPackagesNames = /* @__PURE__ */ new Set();
43
+ for (const pkg of changedPackages) {
44
+ changedPackagesNames.add(asNonNull(pkg.json.name));
45
+ }
46
+ let hadChanges = true;
47
+ while (hadChanges) {
48
+ hadChanges = false;
49
+ for (const pkg of packages) {
50
+ const pkgName = asNonNull(pkg.json.name);
51
+ for (const field of ["dependencies", "peerDependencies"]) {
52
+ const deps = pkg.json[field];
53
+ if (deps == null) continue;
54
+ for (const name of Object.keys(deps)) {
55
+ if (changedPackagesNames.has(name) && !changedPackagesNames.has(pkgName)) {
56
+ hadChanges = true;
57
+ changedPackages.push(pkg);
58
+ changedPackagesNames.add(pkgName);
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ }
64
+ }
65
+ packages = changedPackages;
66
+ console.log(`📝 only publishing changed packages since ${since}:`);
67
+ for (const pkg of packages) {
68
+ console.log(` - ${pkg.json.name}`);
69
+ }
70
+ }
18
71
  if (!isRunningInGithubActions()) {
19
72
  throw new Error("cr command is only supported in github actions");
20
73
  }
21
74
  const distPaths = [];
22
- for (const pkg of ordered) {
75
+ for (const pkg of packages) {
23
76
  if (pkg.json.scripts?.build !== void 0) {
24
77
  await exec([
25
78
  "npm",
@@ -60,7 +113,9 @@ const runContinuousReleaseCli = bc.command({
60
113
  options: {
61
114
  root: bc.string().desc("path to the root of the workspace (default: cwd)"),
62
115
  distDir: bc.string("dist-dir").desc("directory to publish from, relative to package root (default: dist)"),
63
- extraArgs: bc.string("extra-args").desc("extra arguments to pass to pkg-pr-new")
116
+ extraArgs: bc.string("extra-args").desc("extra arguments to pass to pkg-pr-new"),
117
+ onlyChanged: bc.boolean("only-changed").desc("whether to only publish packages changed since the last release.").default(false),
118
+ onlyChangedSince: bc.string("only-changed-since").desc("starting point for the changelog (defaults to latest tag)")
64
119
  },
65
120
  transform: (args) => {
66
121
  return {
@@ -138,7 +138,7 @@ async function publishPackages(params) {
138
138
  if (tar.exitCode !== 0) {
139
139
  console.error(tar.stderr);
140
140
  } else {
141
- tarballs.push(tar.stdout.trim());
141
+ tarballs.push(join(fullDistDir, tar.stdout.trim()));
142
142
  }
143
143
  }
144
144
  }
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@fuman/build",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "description": "utils for building packages and managing monorepos",
6
6
  "license": "MIT",
7
7
  "scripts": {},
8
8
  "dependencies": {
9
9
  "@drizzle-team/brocli": "^0.10.2",
10
- "@fuman/fetch": "^0.0.3",
11
- "@fuman/io": "^0.0.3",
12
- "@fuman/node": "^0.0.3",
13
- "@fuman/utils": "^0.0.3",
10
+ "@fuman/fetch": "^0.0.4",
11
+ "@fuman/io": "^0.0.4",
12
+ "@fuman/node": "^0.0.4",
13
+ "@fuman/utils": "^0.0.4",
14
14
  "cross-spawn": "^7.0.5",
15
15
  "detect-indent": "^7.0.1",
16
16
  "js-yaml": "^4.1.0",
@@ -10,12 +10,14 @@ export interface ProjectChangedFile {
10
10
  }
11
11
  export declare function findProjectChangedFiles(params: {
12
12
  params?: VersioningOptions;
13
+ workspace?: WorkspacePackage[];
13
14
  root?: string | URL;
14
15
  since: string;
15
16
  until?: string;
16
17
  }): Promise<ProjectChangedFile[]>;
17
18
  export declare function findProjectChangedPackages(params: {
18
19
  params?: VersioningOptions;
20
+ workspace?: WorkspacePackage[];
19
21
  root?: string | URL;
20
22
  since: string;
21
23
  until?: string;
@@ -29,10 +29,7 @@ async function findProjectChangedFiles(params) {
29
29
  cwd: root
30
30
  });
31
31
  if (!changed.length) return [];
32
- const packages = await collectPackageJsons(root);
33
- for (const pkg of packages) {
34
- pkg.path = relative(root, pkg.path);
35
- }
32
+ const packages = (params.workspace ?? await collectPackageJsons(root)).map((pkg) => ({ ...pkg, path: relative(root, pkg.path) }));
36
33
  const files = [];
37
34
  const includeGlobs = include == null ? null : picomatch(include);
38
35
  const excludeGlobs = exclude == null ? null : picomatch(exclude);
@@ -1,7 +1,8 @@
1
1
  import * as fsp from "node:fs/promises";
2
2
  import { join, relative } from "node:path";
3
3
  import process from "node:process";
4
- import { asNonNull, deepMerge, assertStartsWith } from "@fuman/utils";
4
+ import { asNonNull, deepMerge, assertStartsWith, parallelMap } from "@fuman/utils";
5
+ import { glob } from "tinyglobby";
5
6
  import { loadBuildConfig } from "../misc/_config.js";
6
7
  import { tryCopy, fileExists, directoryExists } from "../misc/fs.js";
7
8
  import { normalizeFilePath } from "../misc/path.js";
@@ -148,16 +149,15 @@ async function fumanBuild(params) {
148
149
  await fsp.writeFile(dTsFile, `export * from ${JSON.stringify(entrypointFile)}`);
149
150
  }
150
151
  }
151
- if (buildCjs && await directoryExists(join(buildDir, "chunks/cjs"))) {
152
- const cjsFile = join(buildDir, "chunks/cjs/package.json");
153
- await fsp.writeFile(cjsFile, JSON.stringify({ type: "commonjs" }));
154
- for (const name of Object.keys(entrypoints)) {
155
- const dTsFile = join(buildDir, `${name}.d.ts`);
156
- if (!await fileExists(dTsFile)) {
157
- continue;
158
- }
159
- await fsp.cp(dTsFile, dTsFile.replace(/\.d\.ts$/, ".d.cts"));
152
+ if (buildCjs) {
153
+ if (await directoryExists(join(buildDir, "chunks/cjs"))) {
154
+ const cjsFile = join(buildDir, "chunks/cjs/package.json");
155
+ await fsp.writeFile(cjsFile, JSON.stringify({ type: "commonjs" }));
160
156
  }
157
+ await parallelMap(await glob("**/*.d.ts", { cwd: buildDir }), async (file) => {
158
+ const fullPath = join(buildDir, file);
159
+ await fsp.cp(fullPath, fullPath.replace(/\.d\.ts$/, ".d.cts"));
160
+ });
161
161
  }
162
162
  await params.finalize?.(hookContext);
163
163
  await packageConfig?.finalize?.(hookContext);