@fuman/build 0.0.1
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.
- package/LICENSE +8 -0
- package/README.md +108 -0
- package/ci/github-actions.d.ts +3 -0
- package/ci/github-actions.js +28 -0
- package/ci/index.d.ts +1 -0
- package/cli/commands/_utils.d.ts +8 -0
- package/cli/commands/_utils.js +18 -0
- package/cli/commands/build.d.ts +20 -0
- package/cli/commands/build.js +45 -0
- package/cli/commands/bump-version.d.ts +18 -0
- package/cli/commands/bump-version.js +72 -0
- package/cli/commands/cr.d.ts +17 -0
- package/cli/commands/cr.js +76 -0
- package/cli/commands/find-changed-packages.d.ts +12 -0
- package/cli/commands/find-changed-packages.js +44 -0
- package/cli/commands/gen-changelog.d.ts +12 -0
- package/cli/commands/gen-changelog.js +49 -0
- package/cli/commands/gen-deps-graph.d.ts +15 -0
- package/cli/commands/gen-deps-graph.js +78 -0
- package/cli/commands/jsr.d.ts +6 -0
- package/cli/commands/jsr.js +79 -0
- package/cli/commands/publish.d.ts +48 -0
- package/cli/commands/publish.js +197 -0
- package/cli/commands/release.d.ts +34 -0
- package/cli/commands/release.js +226 -0
- package/cli/commands/validate-workspace-deps.d.ts +38 -0
- package/cli/commands/validate-workspace-deps.js +68 -0
- package/cli/index.d.ts +3 -0
- package/cli/main.d.ts +2 -0
- package/config.d.ts +32 -0
- package/fuman-build.d.ts +1 -0
- package/fuman-build.js +33 -0
- package/git/github.d.ts +14 -0
- package/git/github.js +48 -0
- package/git/index.d.ts +1 -0
- package/git/utils.d.ts +38 -0
- package/git/utils.js +110 -0
- package/index.d.ts +7 -0
- package/index.js +46 -0
- package/jsr/build-jsr.d.ts +7 -0
- package/jsr/build-jsr.js +145 -0
- package/jsr/config.d.ts +48 -0
- package/jsr/create-packages.d.ts +8 -0
- package/jsr/create-packages.js +46 -0
- package/jsr/deno-json.d.ts +19 -0
- package/jsr/deno-json.js +80 -0
- package/jsr/generate-workspace.d.ts +9 -0
- package/jsr/generate-workspace.js +174 -0
- package/jsr/index.d.ts +5 -0
- package/jsr/populate.d.ts +45 -0
- package/jsr/populate.js +132 -0
- package/jsr/utils/external-libs.d.ts +8 -0
- package/jsr/utils/external-libs.js +46 -0
- package/jsr/utils/index.d.ts +4 -0
- package/jsr/utils/jsr-api.d.ts +23 -0
- package/jsr/utils/jsr-api.js +115 -0
- package/jsr/utils/jsr-json.d.ts +10 -0
- package/jsr/utils/jsr-json.js +80 -0
- package/jsr/utils/jsr.d.ts +11 -0
- package/jsr/utils/jsr.js +74 -0
- package/jsr.d.ts +1 -0
- package/jsr.js +23 -0
- package/misc/_config.d.ts +1 -0
- package/misc/_config.js +18 -0
- package/misc/exec.d.ts +9 -0
- package/misc/exec.js +40 -0
- package/misc/fs.d.ts +4 -0
- package/misc/fs.js +32 -0
- package/misc/index.d.ts +4 -0
- package/misc/path.d.ts +1 -0
- package/misc/path.js +12 -0
- package/misc/publish-order.d.ts +3 -0
- package/misc/publish-order.js +56 -0
- package/misc/tsconfig.d.ts +2 -0
- package/misc/tsconfig.js +28 -0
- package/npm/index.d.ts +1 -0
- package/npm/npm-api.d.ts +7 -0
- package/npm/npm-api.js +18 -0
- package/package-json/collect-package-jsons.d.ts +8 -0
- package/package-json/collect-package-jsons.js +61 -0
- package/package-json/find-package-json.d.ts +7 -0
- package/package-json/find-package-json.js +28 -0
- package/package-json/index.d.ts +5 -0
- package/package-json/parse.d.ts +4 -0
- package/package-json/parse.js +40 -0
- package/package-json/process-package-json.d.ts +13 -0
- package/package-json/process-package-json.js +132 -0
- package/package-json/types.d.ts +56 -0
- package/package-json/types.js +57 -0
- package/package-json/utils.d.ts +4 -0
- package/package-json/utils.js +27 -0
- package/package.json +67 -0
- package/versioning/bump-version.d.ts +48 -0
- package/versioning/bump-version.js +129 -0
- package/versioning/collect-files.d.ts +22 -0
- package/versioning/collect-files.js +66 -0
- package/versioning/generate-changelog.d.ts +13 -0
- package/versioning/generate-changelog.js +81 -0
- package/versioning/types.d.ts +32 -0
- package/vite/build-plugin.d.ts +73 -0
- package/vite/build-plugin.js +170 -0
- package/vite/config.d.ts +34 -0
- package/vite/index.d.ts +2 -0
- package/vite.d.ts +1 -0
- package/vite.js +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2024 alina sireneva
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
## @fuman/build
|
|
2
|
+
|
|
3
|
+
this package contains utilities for building packages and managing monorepos.
|
|
4
|
+
|
|
5
|
+
existing similar tools try to do too much and accomodate for every possible use case,
|
|
6
|
+
which makes them quite hard to use and don't provide enough consistency.
|
|
7
|
+
unlike them, this package is *very* opinionated and might not be for you.
|
|
8
|
+
|
|
9
|
+
this package works on some assumptions, allowing to abstract some of the complexity away:
|
|
10
|
+
- for workspaces, it assumes that the workspace is managed with pnpm
|
|
11
|
+
- packages within the workspace are linked using [`workspace:` protocol](https://pnpm.io/workspaces#workspace-protocol-workspace),
|
|
12
|
+
and versions are replaced with the actual version at build time
|
|
13
|
+
- packages are built using vite (i.e. rollup). i might support some other bundler down the line, though
|
|
14
|
+
- tsc is explicitly **not** supported, because using `tsc` to build is such a pain that it's just not worth it.
|
|
15
|
+
- all packages must be `type: module`, because commonjs sucks (you can still build into commonjs, tho)
|
|
16
|
+
- `.exports` and `.bin` fields in package.json are build entrypoints, e.g.:
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./src/index.ts"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"fuman-build": "./src/cli.ts"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
- `.main`, `.module`, `.types`, `.browser` are explicitly **not** supported. for browser-specific code, you should make a secondary entrypoint/package instead of relying on bundle-time magic
|
|
27
|
+
- package versioning is continous and semver-compliant (except "fixed version" releases, which all share the same version)
|
|
28
|
+
- this package currently focuses on non-frontend libraries
|
|
29
|
+
|
|
30
|
+
it *might* work with other setups, but that is not supported.
|
|
31
|
+
|
|
32
|
+
### why exactly?
|
|
33
|
+
|
|
34
|
+
because node sucks. `package.json` is an absolute mess – it's not standardized properly, and it's a pain to work with.
|
|
35
|
+
when it was invented, typescript wasn't even a thing, and as such it's a pain to set it up correctly for libraries.
|
|
36
|
+
and npm is also a pain due to similar reasons. everything is so fragile and inconsistent that it's very easy to make mistakes.
|
|
37
|
+
|
|
38
|
+
deno and jsr fix some of the issues, but i just generally don't like deno because it feels very limiting and vendor-locking,
|
|
39
|
+
and there isn't any tool to write cross-runtime code under deno anyway.
|
|
40
|
+
|
|
41
|
+
additionally there's quite some pain writing release ci/cd flows for libraries.
|
|
42
|
+
especially for monorepos, especially when you want to cross-publish to npm and jsr.
|
|
43
|
+
|
|
44
|
+
### package.json pre-processing features
|
|
45
|
+
|
|
46
|
+
...provided by `processPackageJson` function
|
|
47
|
+
- copying common fields from root package.json
|
|
48
|
+
- replacing `workspace:` dependencies with the actual version from the workspace
|
|
49
|
+
- removing `scripts` (except ones listed in `keepScripts`)
|
|
50
|
+
- removing `devDependencies`, `typedoc`/`prettier`/etc
|
|
51
|
+
- collecting entrypoints from `exports` and `bin`
|
|
52
|
+
- running hooks declared in `build.config.js` files
|
|
53
|
+
|
|
54
|
+
this allows to:
|
|
55
|
+
- simplify the inner package.jsons and keep them in sync with the root package.json
|
|
56
|
+
- simplify the release flow by not having to manually update dependency versions in each package
|
|
57
|
+
- (i know that pnpm/yarn basically fix this with `workspace:` protocol, but i don't like the idea of using something other than npm cli to publish to npm)
|
|
58
|
+
- ensures you don't accidentally publish unwanted `prepare`/`install`/etc. scripts to npm (and also reduces install size by a bit)
|
|
59
|
+
- reduces install size a bit
|
|
60
|
+
- improve dx by *a lot*
|
|
61
|
+
- you no longer need to build the packages before you can import them, nor do you need to repeat yourself by manually providing `.types` field for development
|
|
62
|
+
- you no longer need to sync vite build entrypoints with `package.json` across all packages (and accidentally publish them broken)
|
|
63
|
+
- since we generate a new package.json, you can do pretty much any modifications to the production package.json
|
|
64
|
+
(despite the above, there might still be cases that we don't cover and you want a bit more control.
|
|
65
|
+
feel free to open an issue if you feel like this should be in the package tho!)
|
|
66
|
+
|
|
67
|
+
## usage with vite
|
|
68
|
+
|
|
69
|
+
just put this in your `vite.config.js`:
|
|
70
|
+
```ts
|
|
71
|
+
import { fumanBuild } from '@fuman/build/vite'
|
|
72
|
+
|
|
73
|
+
export default {
|
|
74
|
+
plugins: [
|
|
75
|
+
fumanBuild({
|
|
76
|
+
root: __dirname,
|
|
77
|
+
// if you're using `vite-plugin-dts`, make sure to add this option,
|
|
78
|
+
// otherwise additional entrypoints will not have proper types
|
|
79
|
+
// (and DO NOT add this option to the dts plugin itself)
|
|
80
|
+
insertTypesEntry: true,
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## usage with jsr
|
|
87
|
+
|
|
88
|
+
fuman-build also supports jsr by being able to convert a pnpm workspace into a deno workspace,
|
|
89
|
+
which can then be published via simple `deno publish` command.
|
|
90
|
+
|
|
91
|
+
to generate a deno workspace, run `fuman-build jsr gen-deno-workspace`.
|
|
92
|
+
|
|
93
|
+
## cli
|
|
94
|
+
|
|
95
|
+
fuman-build has a pretty cool cli, check it out via `fuman-build --help`
|
|
96
|
+
|
|
97
|
+
## ci/cd
|
|
98
|
+
|
|
99
|
+
fuman-build also makes it *very* easy to use in CI/CD pipelines.
|
|
100
|
+
a very simple release flow powered by fuman build and github actions
|
|
101
|
+
can be found [here](https://github.com/teidesu/fuman/blob/main/.github/workflows/release.yaml).
|
|
102
|
+
|
|
103
|
+
the `release` command basically combines a bunch of other commands
|
|
104
|
+
(namely, `bump-version`, `gen-changelog`, `publish` and `jsr` subcommands)
|
|
105
|
+
into one and adds some additional release-specific features (like git tagging and github release generation), and is the recommended way to use fuman-build in CI/CD pipelines.
|
|
106
|
+
|
|
107
|
+
though it is definitely possible to use the other commands directly, in case
|
|
108
|
+
you need to do something that is not supported out of the box.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { appendFileSync } from "node:fs";
|
|
3
|
+
import { EOL } from "node:os";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
function isRunningInGithubActions() {
|
|
6
|
+
return Boolean(process.env.GITHUB_ACTIONS);
|
|
7
|
+
}
|
|
8
|
+
function getGithubActionsInput(name) {
|
|
9
|
+
const input = process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`];
|
|
10
|
+
if (input === void 0) return void 0;
|
|
11
|
+
return input.trim();
|
|
12
|
+
}
|
|
13
|
+
function writeGithubActionsOutput(name, value) {
|
|
14
|
+
if (process.env.GITHUB_OUTPUT === void 0) {
|
|
15
|
+
throw new Error("GITHUB_OUTPUT is not set");
|
|
16
|
+
}
|
|
17
|
+
if (!value.includes(EOL)) {
|
|
18
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `${name}=${value}${EOL}`, "utf8");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const delim = `---${randomUUID()}---${EOL}`;
|
|
22
|
+
appendFileSync(process.env.GITHUB_OUTPUT, `${name}<<${delim}${value}${delim}`, "utf8");
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
getGithubActionsInput,
|
|
26
|
+
isRunningInGithubActions,
|
|
27
|
+
writeGithubActionsOutput
|
|
28
|
+
};
|
package/ci/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './github-actions.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RootConfigObject } from '../../config.js';
|
|
2
|
+
import * as bc from '@drizzle-team/brocli';
|
|
3
|
+
export { bc };
|
|
4
|
+
export declare function loadConfig(params: {
|
|
5
|
+
workspaceRoot: string;
|
|
6
|
+
configPath?: string;
|
|
7
|
+
require?: boolean;
|
|
8
|
+
}): Promise<RootConfigObject | null>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as bc from "@drizzle-team/brocli";
|
|
2
|
+
import { loadBuildConfig } from "../../misc/_config.js";
|
|
3
|
+
async function loadConfig(params) {
|
|
4
|
+
const {
|
|
5
|
+
workspaceRoot,
|
|
6
|
+
configPath = "build.config.js",
|
|
7
|
+
require: require2 = true
|
|
8
|
+
} = params;
|
|
9
|
+
const config = await loadBuildConfig(workspaceRoot, configPath);
|
|
10
|
+
if (!config && require2) {
|
|
11
|
+
throw new Error(`Config not found: ${configPath}`);
|
|
12
|
+
}
|
|
13
|
+
return config ?? null;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
bc,
|
|
17
|
+
loadConfig
|
|
18
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WorkspacePackage } from '../../package-json/collect-package-jsons.js';
|
|
2
|
+
import { bc } from './_utils.js';
|
|
3
|
+
export declare function buildPackage(params: {
|
|
4
|
+
workspaceRoot: string;
|
|
5
|
+
workspace?: WorkspacePackage[];
|
|
6
|
+
packageName: string;
|
|
7
|
+
configPath?: string;
|
|
8
|
+
fixedVersion?: string;
|
|
9
|
+
}): Promise<void>;
|
|
10
|
+
export declare const buildPackageCli: bc.Command<{
|
|
11
|
+
config: string | undefined;
|
|
12
|
+
root: string | undefined;
|
|
13
|
+
packageName: string;
|
|
14
|
+
fixedVersion: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
config: string | undefined;
|
|
17
|
+
root: string | undefined;
|
|
18
|
+
packageName: string;
|
|
19
|
+
fixedVersion: string | undefined;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { exec } from "../../misc/exec.js";
|
|
4
|
+
import { collectPackageJsons } from "../../package-json/collect-package-jsons.js";
|
|
5
|
+
import { findPackageByName } from "../../package-json/utils.js";
|
|
6
|
+
import { loadConfig } from "./_utils.js";
|
|
7
|
+
import * as bc from "@drizzle-team/brocli";
|
|
8
|
+
async function buildPackage(params) {
|
|
9
|
+
const config = await loadConfig(params);
|
|
10
|
+
const workspacePackages = params.workspace ?? await collectPackageJsons(params.workspaceRoot, true);
|
|
11
|
+
const viteConfig = config?.viteConfig ?? "vite.config.js";
|
|
12
|
+
const packageRoot = findPackageByName(workspacePackages, params.packageName).path;
|
|
13
|
+
await exec(["npx", "vite", "build", "--config", join(params.workspaceRoot, viteConfig)], {
|
|
14
|
+
env: {
|
|
15
|
+
...process.env,
|
|
16
|
+
__FUMAN_INTERNAL_PACKAGES_LIST: JSON.stringify(workspacePackages),
|
|
17
|
+
__FUMAN_INTERNAL_FIXED_VERSION: params.fixedVersion
|
|
18
|
+
},
|
|
19
|
+
cwd: packageRoot,
|
|
20
|
+
stdio: "inherit",
|
|
21
|
+
throwOnError: true
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const buildPackageCli = bc.command({
|
|
25
|
+
name: "build",
|
|
26
|
+
desc: "build a package",
|
|
27
|
+
options: {
|
|
28
|
+
config: bc.string("config").desc("path to the build.config.js file"),
|
|
29
|
+
root: bc.string().desc("path to the root of the workspace (default: cwd)"),
|
|
30
|
+
packageName: bc.positional("package-name").desc("name of the package to build").required(),
|
|
31
|
+
fixedVersion: bc.string("fixed-version").desc("version to publish the package to (overrides the version in every package.json, useful for pre-releases)")
|
|
32
|
+
},
|
|
33
|
+
handler: async (args) => {
|
|
34
|
+
await buildPackage({
|
|
35
|
+
workspaceRoot: args.root ?? process.cwd(),
|
|
36
|
+
packageName: args.packageName,
|
|
37
|
+
configPath: args.config,
|
|
38
|
+
fixedVersion: args.fixedVersion
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
export {
|
|
43
|
+
buildPackage,
|
|
44
|
+
buildPackageCli
|
|
45
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BumpVersionResult } from '../../versioning/bump-version.js';
|
|
2
|
+
import { bc } from './_utils.js';
|
|
3
|
+
export declare function formatBumpVersionResult(result: BumpVersionResult, withReleaseType: boolean): string;
|
|
4
|
+
export declare const bumpVersionCli: bc.Command<{
|
|
5
|
+
root: string | undefined;
|
|
6
|
+
config: string | undefined;
|
|
7
|
+
type: "auto" | "major" | "minor" | "patch";
|
|
8
|
+
since: string | undefined;
|
|
9
|
+
dryRun: boolean | undefined;
|
|
10
|
+
quiet: boolean | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
root: string | undefined;
|
|
13
|
+
config: string | undefined;
|
|
14
|
+
type: "auto" | "major" | "minor" | "patch";
|
|
15
|
+
since: string | undefined;
|
|
16
|
+
dryRun: boolean | undefined;
|
|
17
|
+
quiet: boolean | undefined;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { isRunningInGithubActions, writeGithubActionsOutput } from "../../ci/github-actions.js";
|
|
3
|
+
import { getLatestTag } from "../../git/utils.js";
|
|
4
|
+
import { collectPackageJsons } from "../../package-json/collect-package-jsons.js";
|
|
5
|
+
import { bumpVersion } from "../../versioning/bump-version.js";
|
|
6
|
+
import { loadConfig } from "./_utils.js";
|
|
7
|
+
import * as bc from "@drizzle-team/brocli";
|
|
8
|
+
function formatBumpVersionResult(result, withReleaseType) {
|
|
9
|
+
const lines = [];
|
|
10
|
+
if (withReleaseType) {
|
|
11
|
+
lines.push(`detected release type: ${result.releaseType}`);
|
|
12
|
+
lines.push(` has breaking changes: ${result.hasBreakingChanges}`);
|
|
13
|
+
lines.push(` has new features: ${result.hasFeatures}`);
|
|
14
|
+
lines.push("");
|
|
15
|
+
}
|
|
16
|
+
lines.push(`next version: ${result.nextVersion}`);
|
|
17
|
+
lines.push("");
|
|
18
|
+
lines.push("list of changed packages:");
|
|
19
|
+
for (const { package: pkg, because } of result.changedPackages) {
|
|
20
|
+
lines.push(` ${pkg.json.name}${because ? ` (because of ${because.join(", ")})` : ""}: ${pkg.json.version} → ${result.nextVersion}`);
|
|
21
|
+
}
|
|
22
|
+
return lines.join("\n");
|
|
23
|
+
}
|
|
24
|
+
const bumpVersionCli = bc.command({
|
|
25
|
+
name: "bump-version",
|
|
26
|
+
desc: "bump the version of changed packages",
|
|
27
|
+
options: {
|
|
28
|
+
root: bc.string().desc("path to the root of the workspace (default: process.cwd())"),
|
|
29
|
+
config: bc.string().desc("path to the build.config.js file"),
|
|
30
|
+
type: bc.string().desc("override type of release (major, minor, patch) (default: auto-detect)").enum("major", "minor", "patch", "auto").default("auto"),
|
|
31
|
+
since: bc.string().desc("starting point for the changelog (default: latest tag)"),
|
|
32
|
+
dryRun: bc.boolean("dry-run").desc("whether to only print the detected changes without actually modifying anything"),
|
|
33
|
+
quiet: bc.boolean().desc("whether to only print the new version number").alias("q")
|
|
34
|
+
},
|
|
35
|
+
handler: async (args) => {
|
|
36
|
+
const root = args.root ?? process.cwd();
|
|
37
|
+
const releaseType = args.type === "auto" ? void 0 : args.type;
|
|
38
|
+
const workspace = await collectPackageJsons(root);
|
|
39
|
+
const config = await loadConfig({
|
|
40
|
+
workspaceRoot: root,
|
|
41
|
+
configPath: args.config,
|
|
42
|
+
require: false
|
|
43
|
+
});
|
|
44
|
+
const since = args.since ?? await getLatestTag(root);
|
|
45
|
+
if (since == null) {
|
|
46
|
+
throw new Error("no previous tag found, cannot determine changeset");
|
|
47
|
+
}
|
|
48
|
+
const result = await bumpVersion({
|
|
49
|
+
workspace,
|
|
50
|
+
type: releaseType,
|
|
51
|
+
cwd: root,
|
|
52
|
+
since,
|
|
53
|
+
params: config?.versioning,
|
|
54
|
+
dryRun: args.dryRun
|
|
55
|
+
});
|
|
56
|
+
if (args.quiet) {
|
|
57
|
+
console.log(result.nextVersion);
|
|
58
|
+
} else {
|
|
59
|
+
console.log(formatBumpVersionResult(result, releaseType == null));
|
|
60
|
+
}
|
|
61
|
+
if (isRunningInGithubActions()) {
|
|
62
|
+
writeGithubActionsOutput("version", result.nextVersion);
|
|
63
|
+
writeGithubActionsOutput("hasBreakingChanges", String(result.hasBreakingChanges));
|
|
64
|
+
writeGithubActionsOutput("hasFeatures", String(result.hasFeatures));
|
|
65
|
+
writeGithubActionsOutput("changedPackages", result.changedPackages.map((it) => it.package.json.name).join(","));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
export {
|
|
70
|
+
bumpVersionCli,
|
|
71
|
+
formatBumpVersionResult
|
|
72
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WorkspacePackage } from '../../package-json/collect-package-jsons.js';
|
|
2
|
+
import { bc } from './_utils.js';
|
|
3
|
+
export declare function runContinuousRelease(params: {
|
|
4
|
+
workspaceRoot?: string;
|
|
5
|
+
workspace?: WorkspacePackage[];
|
|
6
|
+
distDir?: string;
|
|
7
|
+
extraArgs?: string[];
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare const runContinuousReleaseCli: bc.Command<{
|
|
10
|
+
root: string | undefined;
|
|
11
|
+
distDir: string | undefined;
|
|
12
|
+
extraArgs: string | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
extraArgs: string[] | undefined;
|
|
15
|
+
root: string | undefined;
|
|
16
|
+
distDir: string | undefined;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { asNonNull } from "@fuman/utils";
|
|
4
|
+
import { isRunningInGithubActions } from "../../ci/github-actions.js";
|
|
5
|
+
import { exec } from "../../misc/exec.js";
|
|
6
|
+
import { collectPackageJsons, filterPackageJsonsForPublish } from "../../package-json/collect-package-jsons.js";
|
|
7
|
+
import * as bc from "@drizzle-team/brocli";
|
|
8
|
+
import { buildPackage } from "./build.js";
|
|
9
|
+
async function runContinuousRelease(params) {
|
|
10
|
+
const {
|
|
11
|
+
workspaceRoot = process.cwd(),
|
|
12
|
+
workspace = await collectPackageJsons(workspaceRoot, true),
|
|
13
|
+
distDir = "dist",
|
|
14
|
+
extraArgs = []
|
|
15
|
+
} = params;
|
|
16
|
+
const workspaceWithoutRoot = workspace.filter((pkg) => !pkg.root);
|
|
17
|
+
const ordered = filterPackageJsonsForPublish(workspaceWithoutRoot, "npm");
|
|
18
|
+
if (!isRunningInGithubActions()) {
|
|
19
|
+
throw new Error("cr command is only supported in github actions");
|
|
20
|
+
}
|
|
21
|
+
const distPaths = [];
|
|
22
|
+
for (const pkg of ordered) {
|
|
23
|
+
if (pkg.json.scripts?.build !== void 0) {
|
|
24
|
+
await exec([
|
|
25
|
+
"npm",
|
|
26
|
+
"run",
|
|
27
|
+
"build"
|
|
28
|
+
], {
|
|
29
|
+
cwd: join(pkg.path),
|
|
30
|
+
stdio: "inherit",
|
|
31
|
+
throwOnError: true
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
await buildPackage({
|
|
35
|
+
workspaceRoot,
|
|
36
|
+
workspace,
|
|
37
|
+
packageName: asNonNull(pkg.json.name)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
distPaths.push(join(pkg.path, distDir));
|
|
41
|
+
}
|
|
42
|
+
if (extraArgs.some((it) => it.startsWith("--pnpm"))) {
|
|
43
|
+
console.warn("`--pnpm` flag is not supported and may cause issues, please avoid using it");
|
|
44
|
+
}
|
|
45
|
+
await exec([
|
|
46
|
+
"npx",
|
|
47
|
+
"pkg-pr-new",
|
|
48
|
+
"publish",
|
|
49
|
+
...extraArgs,
|
|
50
|
+
...distPaths
|
|
51
|
+
], {
|
|
52
|
+
cwd: workspaceRoot,
|
|
53
|
+
throwOnError: true,
|
|
54
|
+
stdio: "inherit"
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const runContinuousReleaseCli = bc.command({
|
|
58
|
+
name: "cr",
|
|
59
|
+
desc: "publish the workspace to pkg.pr.new",
|
|
60
|
+
options: {
|
|
61
|
+
root: bc.string().desc("path to the root of the workspace (default: cwd)"),
|
|
62
|
+
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")
|
|
64
|
+
},
|
|
65
|
+
transform: (args) => {
|
|
66
|
+
return {
|
|
67
|
+
...args,
|
|
68
|
+
extraArgs: args.extraArgs?.split(" ")
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
handler: runContinuousRelease
|
|
72
|
+
});
|
|
73
|
+
export {
|
|
74
|
+
runContinuousRelease,
|
|
75
|
+
runContinuousReleaseCli
|
|
76
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { bc } from './_utils.js';
|
|
2
|
+
export declare const findChangedPackagesCli: bc.Command<{
|
|
3
|
+
root: string | undefined;
|
|
4
|
+
config: string | undefined;
|
|
5
|
+
since: string | undefined;
|
|
6
|
+
until: string | undefined;
|
|
7
|
+
}, {
|
|
8
|
+
root: string | undefined;
|
|
9
|
+
config: string | undefined;
|
|
10
|
+
since: string | undefined;
|
|
11
|
+
until: string | undefined;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { isRunningInGithubActions, writeGithubActionsOutput } from "../../ci/github-actions.js";
|
|
3
|
+
import { getLatestTag } from "../../git/utils.js";
|
|
4
|
+
import { findProjectChangedPackages } from "../../versioning/collect-files.js";
|
|
5
|
+
import { loadConfig } from "./_utils.js";
|
|
6
|
+
import * as bc from "@drizzle-team/brocli";
|
|
7
|
+
const findChangedPackagesCli = bc.command({
|
|
8
|
+
name: "find-changed-packages",
|
|
9
|
+
desc: "find changed packages between two commits, and output a comma-separated list of package names",
|
|
10
|
+
options: {
|
|
11
|
+
root: bc.string().desc("path to the root of the workspace (default: process.cwd())"),
|
|
12
|
+
config: bc.string("config").desc("path to the build.config.js file"),
|
|
13
|
+
since: bc.string().desc("starting point for the changelog (default: latest tag)"),
|
|
14
|
+
until: bc.string().desc("ending point for the changelog (default: HEAD)")
|
|
15
|
+
},
|
|
16
|
+
handler: async (args) => {
|
|
17
|
+
const root = args.root ?? process.cwd();
|
|
18
|
+
const config = await loadConfig({
|
|
19
|
+
workspaceRoot: root,
|
|
20
|
+
configPath: args.config,
|
|
21
|
+
require: false
|
|
22
|
+
});
|
|
23
|
+
const since = args.since ?? await getLatestTag(root);
|
|
24
|
+
if (since == null) {
|
|
25
|
+
throw new Error("no previous tag found, cannot determine changeset");
|
|
26
|
+
}
|
|
27
|
+
const list = await findProjectChangedPackages({
|
|
28
|
+
params: config?.versioning,
|
|
29
|
+
root,
|
|
30
|
+
since,
|
|
31
|
+
until: args.until
|
|
32
|
+
});
|
|
33
|
+
const result = list.map((pkg) => pkg.json.name).join(",");
|
|
34
|
+
if (isRunningInGithubActions()) {
|
|
35
|
+
writeGithubActionsOutput("packages", result);
|
|
36
|
+
console.log("Written packages to `packages` output");
|
|
37
|
+
} else {
|
|
38
|
+
console.log(result);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
export {
|
|
43
|
+
findChangedPackagesCli
|
|
44
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { bc } from './_utils.js';
|
|
2
|
+
export declare const generateChangelogCli: bc.Command<{
|
|
3
|
+
only: string | undefined;
|
|
4
|
+
root: string | undefined;
|
|
5
|
+
config: string | undefined;
|
|
6
|
+
since: string | undefined;
|
|
7
|
+
}, {
|
|
8
|
+
only: string | undefined;
|
|
9
|
+
root: string | undefined;
|
|
10
|
+
config: string | undefined;
|
|
11
|
+
since: string | undefined;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { isRunningInGithubActions, writeGithubActionsOutput } from "../../ci/github-actions.js";
|
|
3
|
+
import { getLatestTag } from "../../git/utils.js";
|
|
4
|
+
import { collectPackageJsons } from "../../package-json/collect-package-jsons.js";
|
|
5
|
+
import { generateChangelog } from "../../versioning/generate-changelog.js";
|
|
6
|
+
import { loadConfig } from "./_utils.js";
|
|
7
|
+
import * as bc from "@drizzle-team/brocli";
|
|
8
|
+
const generateChangelogCli = bc.command({
|
|
9
|
+
name: "gen-changelog",
|
|
10
|
+
desc: "generate a changelog for the workspace",
|
|
11
|
+
options: {
|
|
12
|
+
only: bc.string().desc("comma-separated list of packages to include"),
|
|
13
|
+
root: bc.string().desc("path to the root of the workspace (default: process.cwd())"),
|
|
14
|
+
config: bc.string("config").desc("path to the build.config.js file"),
|
|
15
|
+
since: bc.string().desc("starting point for the changelog (default: latest tag)")
|
|
16
|
+
},
|
|
17
|
+
handler: async (args) => {
|
|
18
|
+
const root = args.root ?? process.cwd();
|
|
19
|
+
const config = await loadConfig({
|
|
20
|
+
workspaceRoot: root,
|
|
21
|
+
configPath: args.config,
|
|
22
|
+
require: false
|
|
23
|
+
});
|
|
24
|
+
let workspacePackages = await collectPackageJsons(root, false);
|
|
25
|
+
if (args.only !== void 0) {
|
|
26
|
+
const only = new Set(args.only.split(",").map((s) => s.trim()));
|
|
27
|
+
workspacePackages = workspacePackages.filter((pkg) => only.has(pkg.json.name));
|
|
28
|
+
}
|
|
29
|
+
const since = args.since ?? await getLatestTag(root);
|
|
30
|
+
if (since == null) {
|
|
31
|
+
throw new Error("no previous tag found, cannot determine changeset");
|
|
32
|
+
}
|
|
33
|
+
const changelog = await generateChangelog({
|
|
34
|
+
workspace: workspacePackages,
|
|
35
|
+
cwd: root,
|
|
36
|
+
since,
|
|
37
|
+
params: config?.versioning
|
|
38
|
+
});
|
|
39
|
+
if (isRunningInGithubActions()) {
|
|
40
|
+
writeGithubActionsOutput("changelog", changelog);
|
|
41
|
+
console.log("Written changelog to `changelog` output");
|
|
42
|
+
} else {
|
|
43
|
+
console.log(changelog);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
export {
|
|
48
|
+
generateChangelogCli
|
|
49
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bc } from './_utils.js';
|
|
2
|
+
export declare function generateDepsGraph(params: {
|
|
3
|
+
workspaceRoot: string | URL;
|
|
4
|
+
includeRoot?: boolean;
|
|
5
|
+
includeExternal?: boolean;
|
|
6
|
+
}): Promise<string>;
|
|
7
|
+
export declare const generateDepsGraphCli: bc.Command<{
|
|
8
|
+
includeRoot: boolean | undefined;
|
|
9
|
+
includeExternal: boolean | undefined;
|
|
10
|
+
root: string | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
includeRoot: boolean | undefined;
|
|
13
|
+
includeExternal: boolean | undefined;
|
|
14
|
+
root: string | undefined;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { collectPackageJsons } from "../../package-json/collect-package-jsons.js";
|
|
3
|
+
import * as bc from "@drizzle-team/brocli";
|
|
4
|
+
async function generateDepsGraph(params) {
|
|
5
|
+
const {
|
|
6
|
+
workspaceRoot,
|
|
7
|
+
includeRoot = false,
|
|
8
|
+
includeExternal = false
|
|
9
|
+
} = params;
|
|
10
|
+
const pjs = await collectPackageJsons(workspaceRoot, includeRoot);
|
|
11
|
+
const workspacePackages = /* @__PURE__ */ new Set();
|
|
12
|
+
let commonPrefix;
|
|
13
|
+
for (const { json: pj } of pjs) {
|
|
14
|
+
if (pj.name === void 0) continue;
|
|
15
|
+
workspacePackages.add(pj.name);
|
|
16
|
+
const [org, name] = pj.name.split("/");
|
|
17
|
+
if (!name) {
|
|
18
|
+
if (commonPrefix !== void 0) {
|
|
19
|
+
commonPrefix = void 0;
|
|
20
|
+
}
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (commonPrefix === void 0) {
|
|
24
|
+
commonPrefix = org;
|
|
25
|
+
} else if (commonPrefix !== org) {
|
|
26
|
+
commonPrefix = void 0;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const getName = (name) => {
|
|
31
|
+
if (commonPrefix !== void 0) {
|
|
32
|
+
const [org, pkg] = name.split("/");
|
|
33
|
+
if (org === commonPrefix) {
|
|
34
|
+
return pkg;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return name;
|
|
38
|
+
};
|
|
39
|
+
const lines = [];
|
|
40
|
+
for (const { json: pj } of pjs) {
|
|
41
|
+
if (pj.name === void 0) continue;
|
|
42
|
+
const name = getName(pj.name);
|
|
43
|
+
for (const dep of Object.keys(pj.dependencies || {})) {
|
|
44
|
+
if (!workspacePackages.has(dep) && !includeExternal) continue;
|
|
45
|
+
const depName = getName(dep);
|
|
46
|
+
lines.push(`"${name}" -> "${depName}"`);
|
|
47
|
+
}
|
|
48
|
+
for (const dep of Object.keys(pj.devDependencies || {})) {
|
|
49
|
+
if (!workspacePackages.has(dep) && !includeExternal) continue;
|
|
50
|
+
const depName = getName(dep);
|
|
51
|
+
lines.push(`"${name}" -> "${depName}" [style=dashed,color=grey]`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return `digraph {
|
|
55
|
+
${lines.join("\n")}
|
|
56
|
+
}`;
|
|
57
|
+
}
|
|
58
|
+
const generateDepsGraphCli = bc.command({
|
|
59
|
+
name: "gen-deps-graph",
|
|
60
|
+
desc: "generate a graphviz dot file of the workspace dependencies",
|
|
61
|
+
options: {
|
|
62
|
+
includeRoot: bc.boolean("include-root").desc("whether to include the root package.json in the graph"),
|
|
63
|
+
includeExternal: bc.boolean("include-external").desc("whether to include external dependencies in the graph"),
|
|
64
|
+
root: bc.string().desc("path to the root of the workspace (default: cwd)")
|
|
65
|
+
},
|
|
66
|
+
handler: async (args) => {
|
|
67
|
+
const dot = await generateDepsGraph({
|
|
68
|
+
workspaceRoot: args.root ?? process.cwd(),
|
|
69
|
+
includeRoot: args.includeRoot,
|
|
70
|
+
includeExternal: args.includeExternal
|
|
71
|
+
});
|
|
72
|
+
console.log(dot);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
export {
|
|
76
|
+
generateDepsGraph,
|
|
77
|
+
generateDepsGraphCli
|
|
78
|
+
};
|