@mxpicture/build-api 0.2.9 → 0.2.11
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/dist/changeset/Changeset.d.ts +14 -0
- package/dist/changeset/Changeset.js +84 -0
- package/dist/changeset/index.d.ts +1 -0
- package/dist/changeset/index.js +2 -0
- package/dist/common/common.fs.d.ts +4 -0
- package/dist/common/common.fs.js +13 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +2 -0
- package/dist/npmPublish/NpmPublisher.js +5 -7
- package/dist/osInfo/osInfo.common.js +3 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/types.changeset.d.ts +4 -0
- package/dist/types/types.changeset.js +1 -0
- package/dist/types/types.package.d.ts +1 -0
- package/dist/vscode/vscode.config.js +1 -1
- package/dist/vscode/vscode.profiles.js +2 -2
- package/dist/vscode/vscode.settings.js +1 -1
- package/dist/vscode/vscode.storage.js +2 -2
- package/dist/vscode/vscode.workspace.js +2 -2
- package/dist/workspace/workspace.common.d.ts +1 -0
- package/dist/workspace/workspace.common.js +9 -2
- package/package.json +3 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
|
|
2
|
+
import { ChangesetParams } from "../types/types.changeset.js";
|
|
3
|
+
import { PackageJson } from "../types/types.package.js";
|
|
4
|
+
export declare const runChangeset: (params: ChangesetParams) => Promise<void>;
|
|
5
|
+
export declare class Changeset {
|
|
6
|
+
protected readonly paths: WorkspacePaths;
|
|
7
|
+
constructor(paths: WorkspacePaths);
|
|
8
|
+
run(): Promise<void>;
|
|
9
|
+
protected readPackages(): Promise<PackageJson[]>;
|
|
10
|
+
protected range4Compare(): Promise<string>;
|
|
11
|
+
protected findChangedPackages(range: string, packages: PackageJson[]): Promise<string[]>;
|
|
12
|
+
protected findChangedInPackage(range: string, pkg: PackageJson): Promise<string[]>;
|
|
13
|
+
protected write(changed: string[]): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { readPackageJsons } from "../workspace/workspace.common.js";
|
|
3
|
+
import { WorkspacePaths } from "../workspace/WorkspacePaths.js";
|
|
4
|
+
import { execAsync } from "../common/common.fs.js";
|
|
5
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
|
+
export const runChangeset = async (params) => new Changeset(WorkspacePaths.instance(params.repoRoot, params.workspacesName)).run();
|
|
7
|
+
export class Changeset {
|
|
8
|
+
paths;
|
|
9
|
+
constructor(paths) {
|
|
10
|
+
this.paths = paths;
|
|
11
|
+
}
|
|
12
|
+
async run() {
|
|
13
|
+
const [range, packages] = await Promise.all([
|
|
14
|
+
this.range4Compare(),
|
|
15
|
+
this.readPackages(),
|
|
16
|
+
]);
|
|
17
|
+
const changed = await this.findChangedPackages(range, packages);
|
|
18
|
+
// 4) If nothing changed, exit quietly
|
|
19
|
+
if (changed.length === 0) {
|
|
20
|
+
console.log("No publishable package changes detected.");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return this.write(changed);
|
|
24
|
+
}
|
|
25
|
+
// 1) Discover workspace packages (assuming packages/*)
|
|
26
|
+
async readPackages() {
|
|
27
|
+
return (await readPackageJsons(this.paths.repoRoot)).map((p) => p.content);
|
|
28
|
+
}
|
|
29
|
+
// 2) Determine range to compare: last Changesets tag if available, else initial commit
|
|
30
|
+
async range4Compare() {
|
|
31
|
+
let lastTag = "";
|
|
32
|
+
try {
|
|
33
|
+
// Tags like @your-scope/pkg-a@0.1.1 or pkg-a@0.1.1 are created by Changesets on publish
|
|
34
|
+
lastTag = (await execAsync("git tag --list --sort=-creatordate | head -n 1"))
|
|
35
|
+
.toString()
|
|
36
|
+
.trim();
|
|
37
|
+
}
|
|
38
|
+
catch { }
|
|
39
|
+
return lastTag ? `${lastTag}..HEAD` : "";
|
|
40
|
+
}
|
|
41
|
+
// 3) Find changed packages
|
|
42
|
+
async findChangedPackages(range, packages) {
|
|
43
|
+
const changed = [];
|
|
44
|
+
const results = await Promise.all(packages.map((pkg) => this.findChangedInPackage(range, pkg)));
|
|
45
|
+
for (const result of results)
|
|
46
|
+
changed.push(...result);
|
|
47
|
+
return changed;
|
|
48
|
+
}
|
|
49
|
+
async findChangedInPackage(range, pkg) {
|
|
50
|
+
const changed = [];
|
|
51
|
+
if (pkg.private)
|
|
52
|
+
return []; // ignore private packages
|
|
53
|
+
const cmd = range
|
|
54
|
+
? `git diff --name-only ${range} -- "${pkg.dir}"`
|
|
55
|
+
: `git diff --name-only HEAD^ -- "${pkg.dir}" || true`;
|
|
56
|
+
const diff = (await execAsync(cmd, {
|
|
57
|
+
cwd: this.paths.repoRoot,
|
|
58
|
+
}))
|
|
59
|
+
.toString()
|
|
60
|
+
.split("\n")
|
|
61
|
+
.filter(Boolean)
|
|
62
|
+
// optionally ignore docs/tests-only changes:
|
|
63
|
+
.filter((f) => !/\b(README\.md|CHANGELOG\.md|\.md|\.spec\.(t|j)s|\.test\.(t|j)s)\b/i.test(f));
|
|
64
|
+
if (diff.length > 0)
|
|
65
|
+
changed.push(pkg.name);
|
|
66
|
+
return changed;
|
|
67
|
+
}
|
|
68
|
+
// 5) Write a Changeset file marking every changed package as 'patch'
|
|
69
|
+
async write(changed) {
|
|
70
|
+
const changesetDir = join(this.paths.repoRoot, ".changeset");
|
|
71
|
+
await mkdir(changesetDir, { recursive: true });
|
|
72
|
+
const sha = execAsync("git rev-parse --short HEAD").toString().trim();
|
|
73
|
+
const header = changed.map((name) => `"${name}": patch`).join("\n");
|
|
74
|
+
const body = `---
|
|
75
|
+
${header}
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
Auto-generated patch release for changed packages in ${sha}.
|
|
79
|
+
`;
|
|
80
|
+
const filePath = join(changesetDir, `auto-${sha}.md`);
|
|
81
|
+
await writeFile(filePath, body, "utf8");
|
|
82
|
+
console.log(`Created ${filePath} for packages:\n - ${changed.join("\n - ")}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Changeset.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { exec as execCb } from "node:child_process";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
export const execAsync = promisify(execCb);
|
|
5
|
+
export const existsAsync = async (path) => {
|
|
6
|
+
try {
|
|
7
|
+
const s = await stat(path);
|
|
8
|
+
return s.isFile() || s.isDirectory();
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./common.fs.js";
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { readdir } from "fs/promises";
|
|
2
|
-
import { join } from "path";
|
|
1
|
+
import { readdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
3
|
import { readPackageJson } from "../workspace/workspace.common.js";
|
|
4
|
-
import { exec as execCb } from "node:child_process";
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
4
|
import { logError, logInfo, logSuccess } from "../logger/Logger.js";
|
|
7
|
-
|
|
5
|
+
import { execAsync } from "../common/common.fs.js";
|
|
8
6
|
export const runNpmPublisher = async (params) => new NpmPublisher(params.packagesDir).run();
|
|
9
7
|
export class NpmPublisher {
|
|
10
8
|
packagesDir;
|
|
@@ -33,7 +31,7 @@ export class NpmPublisher {
|
|
|
33
31
|
logInfo(`📦 Publishing ${name}@${version} ... (${new Date().toISOString()})`);
|
|
34
32
|
// Check if this exact version is already published
|
|
35
33
|
try {
|
|
36
|
-
const { stdout } = await
|
|
34
|
+
const { stdout } = await execAsync(`npm view ${name}@${version} version`);
|
|
37
35
|
const published = stdout.trim();
|
|
38
36
|
if (published === version) {
|
|
39
37
|
logInfo(`⏭️ ${name}@${version} already published, skipping.`);
|
|
@@ -44,7 +42,7 @@ export class NpmPublisher {
|
|
|
44
42
|
// npm view exits non-zero if the package/version doesn't exist — means we should publish
|
|
45
43
|
}
|
|
46
44
|
try {
|
|
47
|
-
await
|
|
45
|
+
await execAsync("npm publish --access public", {
|
|
48
46
|
cwd: dir,
|
|
49
47
|
});
|
|
50
48
|
logSuccess(`✅ ${name}@${version} published successfully (${new Date().toISOString()}).`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { join, sep } from "path";
|
|
2
|
-
import * as os from "os";
|
|
3
|
-
import { execSync } from "child_process";
|
|
1
|
+
import { join, sep } from "node:path";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
4
|
let __info = null;
|
|
5
5
|
export const osInfo = () => {
|
|
6
6
|
if (!__info) {
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { join } from "path";
|
|
1
|
+
import { join } from "node:path";
|
|
2
2
|
import { storage } from "./vscode.storage.js";
|
|
3
3
|
import { configUserPath } from "./vscode.config.js";
|
|
4
4
|
import { findWorkspaceRoot } from "../workspace/workspace.common.js";
|
|
5
|
-
import { cwd } from "process";
|
|
5
|
+
import { cwd } from "node:process";
|
|
6
6
|
export const profiles = () => storage().userDataProfiles.map((prof) => ({
|
|
7
7
|
name: prof.name,
|
|
8
8
|
location: prof.location,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import { join } from "path";
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
3
|
import json5 from "json5";
|
|
4
4
|
import { configUserPath } from "./vscode.config.js";
|
|
5
5
|
export const storagePath = () => join(configUserPath(), "globalStorage", "storage.json");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readFile } from "fs/promises";
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
2
|
import json5 from "json5";
|
|
3
|
-
import { dirname } from "path";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
4
|
const __workspaces = {};
|
|
5
5
|
export const vscodeWorkspace = async (workspaceFile) => {
|
|
6
6
|
let found = __workspaces[workspaceFile];
|
|
@@ -6,6 +6,7 @@ export declare const findWorkspaceRoot: (startPath: string) => Promise<Workspace
|
|
|
6
6
|
export declare const readWorkspaceYaml: (repoRoot: string) => Promise<PnpmWorkspace>;
|
|
7
7
|
export declare const readPackageJson: (dirOrFilepath: string) => Promise<PackageJson | null>;
|
|
8
8
|
export declare const readPackageJsonThrow: (dirOrFilepath: string) => Promise<PackageJson>;
|
|
9
|
+
export declare const readPackageJsonSync: (dirOrFilepath: string) => PackageJson;
|
|
9
10
|
export declare const readPackageJsons: (repoRoot: string) => Promise<PackageEntry[]>;
|
|
10
11
|
export declare const writePackageJsons: (entries: PackageEntry[]) => Promise<void[]>;
|
|
11
12
|
export declare const buildMapEntries: (pkgEntries: PackageEntry[]) => MapEntry[];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { readdir, readFile, writeFile } from "fs/promises";
|
|
1
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { WorkspaceFileType, } from "../types/types.workspace.js";
|
|
3
|
-
import { join, relative, resolve } from "path";
|
|
3
|
+
import { join, relative, resolve } from "node:path";
|
|
4
4
|
import { splitVersion, compareVersions, concatVersion, } from "../pkg/pkg.common.js";
|
|
5
5
|
import json5 from "json5";
|
|
6
6
|
import { parse } from "yaml";
|
|
7
7
|
import { logInfo, logSuccess } from "../logger/Logger.js";
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
8
9
|
export const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
|
|
9
10
|
export const getFileType = (filename) => filename.endsWith(DEFAULT_WORKSPACE_FILE_ENDING)
|
|
10
11
|
? WorkspaceFileType.workspace
|
|
@@ -95,6 +96,12 @@ export const readPackageJsonThrow = async (dirOrFilepath) => {
|
|
|
95
96
|
: join(dirOrFilepath, "package.json");
|
|
96
97
|
return json5.parse(await readFile(pkgPath, "utf8"));
|
|
97
98
|
};
|
|
99
|
+
export const readPackageJsonSync = (dirOrFilepath) => {
|
|
100
|
+
const pkgPath = dirOrFilepath.endsWith("/package.json")
|
|
101
|
+
? dirOrFilepath
|
|
102
|
+
: join(dirOrFilepath, "package.json");
|
|
103
|
+
return json5.parse(readFileSync(pkgPath, "utf8"));
|
|
104
|
+
};
|
|
98
105
|
export const readPackageJsons = async (repoRoot) => {
|
|
99
106
|
try {
|
|
100
107
|
const pnpmWS = await readWorkspaceYaml(repoRoot);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/build-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Build utilities API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
"./barrel": "./dist/barrel/index.js",
|
|
14
|
+
"./changeset": "./dist/changeset/index.js",
|
|
14
15
|
"./cleanup": "./dist/cleanup/index.js",
|
|
16
|
+
"./common": "./dist/common/index.js",
|
|
15
17
|
"./deps": "./dist/deps/index.js",
|
|
16
18
|
"./logger": "./dist/logger/index.js",
|
|
17
19
|
"./npmPublish": "./dist/npmPublish/index.js",
|