@doki-land/nifty 0.1.2 → 0.1.4
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/cli/nifty.mjs +1 -1
- package/package.json +8 -7
- package/src/cli/authArgs.ts +3 -3
- package/src/cli/bump-cmd.ts +2 -2
- package/src/cli/bump.ts +122 -33
- package/src/cli/change-logs-cmd.ts +5 -5
- package/src/cli/cli.ts +1 -1
- package/src/cli/commit-cmd.ts +16 -14
- package/src/cli/commit-lint-report.ts +9 -7
- package/src/cli/context.ts +2 -2
- package/src/cli/format-cmd.ts +2 -2
- package/src/cli/format.ts +1 -1
- package/src/cli/install-native-cmd.ts +2 -2
- package/src/cli/install-native.ts +1 -1
- package/src/cli/lint-cmd.ts +2 -2
- package/src/cli/lint.ts +7 -3
- package/src/cli/options.ts +2 -2
- package/src/cli/publish-cmd.ts +9 -3
- package/src/cli/publish.ts +2 -2
- package/src/cli/retime-cmd.ts +4 -4
- package/src/cli/trust-cmd.ts +3 -3
- package/src/cli/trust.ts +1 -1
- package/src/cli/update-cmd.ts +2 -2
- package/src/cli/update.ts +2 -2
- package/src/cli/upload-cmd.ts +2 -2
- package/src/cli/upload.ts +40 -40
- package/src/cli/workspace.ts +13 -13
- package/src/config/authorMap.ts +6 -2
- package/src/config/defineConfig.ts +10 -8
- package/src/config/detectProject.ts +2 -2
- package/src/config/formatPresets.ts +3 -3
- package/src/config/loadConfig.ts +7 -7
- package/src/config/trustPayload.ts +4 -4
- package/src/config/types.ts +3 -3
- package/src/git.ts +2 -2
- package/src/github.ts +20 -20
- package/src/gitmoji.ts +2 -2
- package/src/native.ts +97 -93
- package/src/nifty.ts +10 -8
package/src/cli/publish-cmd.ts
CHANGED
|
@@ -19,10 +19,10 @@ export function registerPublishCommand(cli: Cli): void {
|
|
|
19
19
|
.option("--otp <code>", "cli.opt.otp")
|
|
20
20
|
.option("--totp-secret <secret>", "cli.opt.totp-secret")
|
|
21
21
|
.option("--npm-token <token>", "cli.opt.npm-token")
|
|
22
|
-
.action(async(options) => cmdPublish(options));
|
|
22
|
+
.action(async (options) => cmdPublish(options));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export async function cmdPublish(options: ParsedOptions): Promise
|
|
25
|
+
export async function cmdPublish(options: ParsedOptions): Promise<number> {
|
|
26
26
|
await bootstrapFromOptions(options);
|
|
27
27
|
const { config } = await loadConfig({ cwd: cwdFrom(options), createIfMissing: false });
|
|
28
28
|
const packages = strList(options, "package");
|
|
@@ -35,7 +35,13 @@ export async function cmdPublish(options: ParsedOptions): Promise < number> {
|
|
|
35
35
|
placeholder: flag(options, "placeholder"),
|
|
36
36
|
tag: str(options, "tag"),
|
|
37
37
|
access: str(options, "access") ?? "public",
|
|
38
|
-
...(packages.length === 1
|
|
38
|
+
...(packages.length === 1
|
|
39
|
+
? { only: packages[0] }
|
|
40
|
+
: packages.length > 1
|
|
41
|
+
? { packages }
|
|
42
|
+
: fromConfig.length > 0
|
|
43
|
+
? { packages: fromConfig }
|
|
44
|
+
: {}),
|
|
39
45
|
...trustPayloadFromConfig(config),
|
|
40
46
|
...authPayload(authFromOptions(options)),
|
|
41
47
|
});
|
package/src/cli/publish.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type PublishReport = {
|
|
|
18
18
|
skippedVersions: string[];
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export async function runPublish(argv: string[]): Promise
|
|
21
|
+
export async function runPublish(argv: string[]): Promise<void> {
|
|
22
22
|
const options = parsePublishArgs(argv);
|
|
23
23
|
const native = loadNiftyNative();
|
|
24
24
|
const report = native.publisher["publish-workspace"]({
|
|
@@ -67,7 +67,7 @@ function parsePublishArgs(argv: string[]) {
|
|
|
67
67
|
return { cwd, dryRun, refresh, placeholder, tag, access, auth };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export function printPublishReport(report: PublishReport, dryRun?: boolean)
|
|
70
|
+
export function printPublishReport(report: PublishReport, dryRun?: boolean): void {
|
|
71
71
|
const prefix = dryRun ? "would publish" : "published";
|
|
72
72
|
console.log(`${prefix} workspace ${report.root}`);
|
|
73
73
|
if (report.skipped.length > 0) {
|
package/src/cli/retime-cmd.ts
CHANGED
|
@@ -18,12 +18,12 @@ export function registerRetimeCommand(cli: Cli): void {
|
|
|
18
18
|
.option("-b, --branch <branch>", "cli.opt.branch")
|
|
19
19
|
.option("--tip <ref>", "cli.opt.tip")
|
|
20
20
|
.option("-m, --message <text>", "cli.opt.message")
|
|
21
|
-
.action(async(options) => cmdRetimeRoot(options));
|
|
21
|
+
.action(async (options) => cmdRetimeRoot(options));
|
|
22
22
|
|
|
23
|
-
retime.action(async(options) => cmdRetimeRange(options));
|
|
23
|
+
retime.action(async (options) => cmdRetimeRange(options));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export async function cmdRetimeRange(options: ParsedOptions): Promise
|
|
26
|
+
export async function cmdRetimeRange(options: ParsedOptions): Promise<number> {
|
|
27
27
|
await bootstrapFromOptions(options);
|
|
28
28
|
const commit = options._[0];
|
|
29
29
|
if (!commit) {
|
|
@@ -42,7 +42,7 @@ export async function cmdRetimeRange(options: ParsedOptions): Promise < number>
|
|
|
42
42
|
return 0;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export async function cmdRetimeRoot(options: ParsedOptions): Promise
|
|
45
|
+
export async function cmdRetimeRoot(options: ParsedOptions): Promise<number> {
|
|
46
46
|
await bootstrapFromOptions(options);
|
|
47
47
|
const native = loadNiftyNative();
|
|
48
48
|
const report = native.history["retime-root"]({
|
package/src/cli/trust-cmd.ts
CHANGED
|
@@ -16,10 +16,10 @@ export function registerTrustCommand(cli: Cli): void {
|
|
|
16
16
|
.option("--otp <code>", "cli.opt.otp")
|
|
17
17
|
.option("--totp-secret <secret>", "cli.opt.totp-secret")
|
|
18
18
|
.option("--npm-token <token>", "cli.opt.npm-token")
|
|
19
|
-
.action(async(options) => cmdTrust(options));
|
|
19
|
+
.action(async (options) => cmdTrust(options));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export async function cmdTrust(options: ParsedOptions): Promise
|
|
22
|
+
export async function cmdTrust(options: ParsedOptions): Promise<number> {
|
|
23
23
|
await bootstrapFromOptions(options);
|
|
24
24
|
const { config } = await loadConfig({ cwd: cwdFrom(options), createIfMissing: false });
|
|
25
25
|
const native = loadNiftyNative();
|
|
@@ -29,7 +29,7 @@ export async function cmdTrust(options: ParsedOptions): Promise < number> {
|
|
|
29
29
|
dryRun: flag(options, "dry-run"),
|
|
30
30
|
refresh: flag(options, "refresh"),
|
|
31
31
|
only: str(options, "only"),
|
|
32
|
-
...(fromConfig.length > 0 ? { packages: fromConfig } : {
|
|
32
|
+
...(fromConfig.length > 0 ? { packages: fromConfig } : {}),
|
|
33
33
|
...trustPayloadFromConfig(config),
|
|
34
34
|
...authPayload(authFromOptions(options)),
|
|
35
35
|
});
|
package/src/cli/trust.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type TrustReport = {
|
|
|
8
8
|
failed: string[];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export async function runTrust(argv: string[]): Promise
|
|
11
|
+
export async function runTrust(argv: string[]): Promise<void> {
|
|
12
12
|
const options = parseTrustArgs(argv);
|
|
13
13
|
const native = loadNiftyNative();
|
|
14
14
|
const report = native.publisher["trust-workspace"]({
|
package/src/cli/update-cmd.ts
CHANGED
|
@@ -7,10 +7,10 @@ import { cwdFrom, flag } from "./options.js";
|
|
|
7
7
|
export function registerUpdateCommand(cli: Cli): void {
|
|
8
8
|
cli.command("update", "cli.cmd.update")
|
|
9
9
|
.option("-i, --interactive", "cli.opt.interactive")
|
|
10
|
-
.action(async(options) => cmdUpdate(options));
|
|
10
|
+
.action(async (options) => cmdUpdate(options));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export async function cmdUpdate(options: ParsedOptions): Promise
|
|
13
|
+
export async function cmdUpdate(options: ParsedOptions): Promise<number> {
|
|
14
14
|
await bootstrapFromOptions(options);
|
|
15
15
|
await updateWorkspace({
|
|
16
16
|
interactive: flag(options, "interactive"),
|
package/src/cli/update.ts
CHANGED
|
@@ -5,11 +5,11 @@ export type UpdateOptions = {
|
|
|
5
5
|
cwd?: string;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export async function runUpdate(argv: string[]): Promise
|
|
8
|
+
export async function runUpdate(argv: string[]): Promise<void> {
|
|
9
9
|
await updateWorkspace(parseUpdateArgs(argv));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export async function updateWorkspace(options: UpdateOptions): Promise
|
|
12
|
+
export async function updateWorkspace(options: UpdateOptions): Promise<void> {
|
|
13
13
|
const native = loadNiftyNative();
|
|
14
14
|
native.updater.run({
|
|
15
15
|
cwd: options.cwd,
|
package/src/cli/upload-cmd.ts
CHANGED
|
@@ -19,10 +19,10 @@ export function registerUploadCommand(cli: Cli): void {
|
|
|
19
19
|
.option("--draft", "cli.opt.draft")
|
|
20
20
|
.option("--no-generate-notes", "cli.opt.no-generate-notes")
|
|
21
21
|
.option("--github-action", "cli.opt.github-action")
|
|
22
|
-
.action(async(options) => cmdUpload(options));
|
|
22
|
+
.action(async (options) => cmdUpload(options));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export async function cmdUpload(options: ParsedOptions): Promise
|
|
25
|
+
export async function cmdUpload(options: ParsedOptions): Promise<number> {
|
|
26
26
|
await bootstrapFromOptions(options);
|
|
27
27
|
await uploadFromOptions({
|
|
28
28
|
release: flag(options, "release"),
|
package/src/cli/upload.ts
CHANGED
|
@@ -29,11 +29,11 @@ type GithubRelease = {
|
|
|
29
29
|
id: number;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export async function runUpload(argv: string[]): Promise
|
|
32
|
+
export async function runUpload(argv: string[]): Promise<void> {
|
|
33
33
|
await uploadFromOptions(parseUploadArgs(argv));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export async function uploadFromOptions(options: UploadOptions): Promise
|
|
36
|
+
export async function uploadFromOptions(options: UploadOptions): Promise<void> {
|
|
37
37
|
if (options.githubAction) {
|
|
38
38
|
applyGithubActionDefaults(options);
|
|
39
39
|
}
|
|
@@ -83,52 +83,52 @@ function parseUploadArgs(argv: string[]): UploadOptions {
|
|
|
83
83
|
|
|
84
84
|
for (let i = 0; i < argv.length; i += 1) {
|
|
85
85
|
const arg = argv[i];
|
|
86
|
-
if (arg === "--release")options.release = true;
|
|
87
|
-
else if (arg === "--pages")options.pages = true;
|
|
88
|
-
else if (arg === "--both")options.both = true;
|
|
89
|
-
else if (arg === "-d" || arg === "--dir")options.dir = argv[++i];
|
|
86
|
+
if (arg === "--release") options.release = true;
|
|
87
|
+
else if (arg === "--pages") options.pages = true;
|
|
88
|
+
else if (arg === "--both") options.both = true;
|
|
89
|
+
else if (arg === "-d" || arg === "--dir") options.dir = argv[++i];
|
|
90
90
|
else if (arg === "-h" || arg === "--help") {
|
|
91
91
|
printUploadHelp();
|
|
92
92
|
process.exit(0);
|
|
93
93
|
}
|
|
94
|
-
else if (arg === "-t" || arg === "--tag")options.tag = argv[++i];
|
|
95
|
-
else if (arg === "--repo")options.repo = argv[++i];
|
|
96
|
-
else if (arg === "--token")options.token = argv[++i];
|
|
97
|
-
else if (arg === "--name")options.name = argv[++i];
|
|
98
|
-
else if (arg === "--notes")options.notes = argv[++i];
|
|
99
|
-
else if (arg === "--notes-file")options.notesFile = argv[++i];
|
|
100
|
-
else if (arg === "--draft")options.draft = true;
|
|
101
|
-
else if (arg === "--no-generate-notes")options.generateNotes = false;
|
|
102
|
-
else if (arg === "--github-action")options.githubAction = true;
|
|
103
|
-
else if (arg === "-C" || arg === "--cwd")options.cwd = argv[++i];
|
|
94
|
+
else if (arg === "-t" || arg === "--tag") options.tag = argv[++i];
|
|
95
|
+
else if (arg === "--repo") options.repo = argv[++i];
|
|
96
|
+
else if (arg === "--token") options.token = argv[++i];
|
|
97
|
+
else if (arg === "--name") options.name = argv[++i];
|
|
98
|
+
else if (arg === "--notes") options.notes = argv[++i];
|
|
99
|
+
else if (arg === "--notes-file") options.notesFile = argv[++i];
|
|
100
|
+
else if (arg === "--draft") options.draft = true;
|
|
101
|
+
else if (arg === "--no-generate-notes") options.generateNotes = false;
|
|
102
|
+
else if (arg === "--github-action") options.githubAction = true;
|
|
103
|
+
else if (arg === "-C" || arg === "--cwd") options.cwd = argv[++i];
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
return options;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
function parseTarget(options: UploadOptions): "release" | "pages" | "both" {
|
|
110
|
-
if (options.both)return "both";
|
|
111
|
-
if (options.pages)return "pages";
|
|
112
|
-
if (options.release)return "release";
|
|
110
|
+
if (options.both) return "both";
|
|
111
|
+
if (options.pages) return "pages";
|
|
112
|
+
if (options.release) return "release";
|
|
113
113
|
throw new Error("specify --release, --pages, or --both");
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
function applyGithubActionDefaults(options: UploadOptions): void {
|
|
117
|
-
options.token??= process.env.GITHUB_TOKEN;
|
|
118
|
-
options.repo??= process.env.GITHUB_REPOSITORY;
|
|
119
|
-
options.tag??= process.env.GITHUB_REF_NAME;
|
|
120
|
-
options.cwd??= process.env.GITHUB_WORKSPACE;
|
|
117
|
+
options.token ??= process.env.GITHUB_TOKEN;
|
|
118
|
+
options.repo ??= process.env.GITHUB_REPOSITORY;
|
|
119
|
+
options.tag ??= process.env.GITHUB_REF_NAME;
|
|
120
|
+
options.cwd ??= process.env.GITHUB_WORKSPACE;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
async function resolveNotes(
|
|
124
124
|
options: UploadOptions,
|
|
125
125
|
repoRoot: string,
|
|
126
126
|
tag: string,
|
|
127
|
-
native: ReturnType
|
|
128
|
-
): Promise
|
|
129
|
-
if (options.notes)return options.notes;
|
|
130
|
-
if (options.notesFile)return readFileSync(options.notesFile, "utf8");
|
|
131
|
-
if (!options.generateNotes)return "";
|
|
127
|
+
native: ReturnType<typeof loadNiftyNative>,
|
|
128
|
+
): Promise<string> {
|
|
129
|
+
if (options.notes) return options.notes;
|
|
130
|
+
if (options.notesFile) return readFileSync(options.notesFile, "utf8");
|
|
131
|
+
if (!options.generateNotes) return "";
|
|
132
132
|
try {
|
|
133
133
|
const range = native.git["resolve-range"](repoRoot, tag.replace(/^v/, ""), undefined, tag);
|
|
134
134
|
const commits = native.git["collect-commits"](repoRoot, range["from-ref"], range["to-ref"]);
|
|
@@ -144,8 +144,8 @@ async function uploadReleaseAssets(
|
|
|
144
144
|
tag: string,
|
|
145
145
|
options: UploadOptions,
|
|
146
146
|
notes: string,
|
|
147
|
-
): Promise
|
|
148
|
-
const[owner, name] = splitRepo(repo);
|
|
147
|
+
): Promise<void> {
|
|
148
|
+
const [owner, name] = splitRepo(repo);
|
|
149
149
|
let release = await apiReleaseByTag(owner, name, tag, token);
|
|
150
150
|
if (!release) {
|
|
151
151
|
release = await apiCreateRelease(owner, name, tag, options.name ?? tag, notes, options.draft, token);
|
|
@@ -178,8 +178,8 @@ Options:
|
|
|
178
178
|
`);
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
async function deployGithubPages(repo: string, token: string, dir: string): Promise
|
|
182
|
-
const[owner, name] = splitRepo(repo);
|
|
181
|
+
async function deployGithubPages(repo: string, token: string, dir: string): Promise<void> {
|
|
182
|
+
const [owner, name] = splitRepo(repo);
|
|
183
183
|
const source = resolve(dir);
|
|
184
184
|
const work = mkdtempSync(join(tmpdir(), "nifty-pages-"));
|
|
185
185
|
cpSync(source, work, { recursive: true });
|
|
@@ -226,7 +226,7 @@ function splitRepo(repo: string): [string, string] {
|
|
|
226
226
|
if (parts.length !== 2 || !parts[0] || !parts[1]) {
|
|
227
227
|
throw new Error(`invalid repo ${repo}, expected owner/name`);
|
|
228
228
|
}
|
|
229
|
-
return[parts[0], parts[1]];
|
|
229
|
+
return [parts[0], parts[1]];
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
async function apiReleaseByTag(
|
|
@@ -234,16 +234,16 @@ async function apiReleaseByTag(
|
|
|
234
234
|
name: string,
|
|
235
235
|
tag: string,
|
|
236
236
|
token: string,
|
|
237
|
-
): Promise
|
|
237
|
+
): Promise<GithubRelease | null> {
|
|
238
238
|
const response = await fetch(
|
|
239
239
|
`https://api.github.com/repos/${owner}/${name}/releases/tags/${encodeURIComponent(tag)}`,
|
|
240
240
|
{ headers: githubHeaders(token) },
|
|
241
241
|
);
|
|
242
|
-
if (response.status === 404)return null;
|
|
242
|
+
if (response.status === 404) return null;
|
|
243
243
|
if (!response.ok) {
|
|
244
244
|
throw new Error(`GitHub API ${response.status}: ${await response.text()}`);
|
|
245
245
|
}
|
|
246
|
-
return(await response.json())as GithubRelease;
|
|
246
|
+
return (await response.json()) as GithubRelease;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
async function apiCreateRelease(
|
|
@@ -254,7 +254,7 @@ async function apiCreateRelease(
|
|
|
254
254
|
body: string,
|
|
255
255
|
draft: boolean,
|
|
256
256
|
token: string,
|
|
257
|
-
): Promise
|
|
257
|
+
): Promise<GithubRelease> {
|
|
258
258
|
const response = await fetch(`https://api.github.com/repos/${owner}/${name}/releases`, {
|
|
259
259
|
method: "POST",
|
|
260
260
|
headers: { ...githubHeaders(token), "Content-Type": "application/json" },
|
|
@@ -263,7 +263,7 @@ async function apiCreateRelease(
|
|
|
263
263
|
if (!response.ok) {
|
|
264
264
|
throw new Error(`GitHub API ${response.status}: ${await response.text()}`);
|
|
265
265
|
}
|
|
266
|
-
return(await response.json())as GithubRelease;
|
|
266
|
+
return (await response.json()) as GithubRelease;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
async function apiUploadAsset(
|
|
@@ -273,7 +273,7 @@ async function apiUploadAsset(
|
|
|
273
273
|
assetName: string,
|
|
274
274
|
filePath: string,
|
|
275
275
|
token: string,
|
|
276
|
-
): Promise
|
|
276
|
+
): Promise<void> {
|
|
277
277
|
const url = `https://uploads.github.com/repos/${owner}/${name}/releases/${releaseId}/assets?name=${encodeURIComponent(assetName)}`;
|
|
278
278
|
const body = readFileSync(filePath);
|
|
279
279
|
const response = await fetch(url, {
|
|
@@ -296,7 +296,7 @@ async function apiUploadAsset(
|
|
|
296
296
|
throw new Error(`GitHub upload ${response.status}: ${text}`);
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
function githubHeaders(token: string): Record
|
|
299
|
+
function githubHeaders(token: string): Record<string, string> {
|
|
300
300
|
return {
|
|
301
301
|
Accept: "application/vnd.github+json",
|
|
302
302
|
Authorization: `Bearer ${token}`,
|
package/src/cli/workspace.ts
CHANGED
|
@@ -16,10 +16,10 @@ export type PackageManifest = {
|
|
|
16
16
|
name: string;
|
|
17
17
|
version: string;
|
|
18
18
|
private?: boolean;
|
|
19
|
-
dependencies?: Record
|
|
20
|
-
devDependencies?: Record
|
|
21
|
-
optionalDependencies?: Record
|
|
22
|
-
peerDependencies?: Record
|
|
19
|
+
dependencies?: Record<string, string>;
|
|
20
|
+
devDependencies?: Record<string, string>;
|
|
21
|
+
optionalDependencies?: Record<string, string>;
|
|
22
|
+
peerDependencies?: Record<string, string>;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const DEPENDENCY_FIELDS = [
|
|
@@ -27,7 +27,7 @@ const DEPENDENCY_FIELDS = [
|
|
|
27
27
|
"devDependencies",
|
|
28
28
|
"optionalDependencies",
|
|
29
29
|
"peerDependencies",
|
|
30
|
-
]as const;
|
|
30
|
+
] as const;
|
|
31
31
|
|
|
32
32
|
export function findWorkspaceRoot(cwd: string): string {
|
|
33
33
|
const layout = detectProjectLayout(cwd);
|
|
@@ -45,7 +45,7 @@ export function findWorkspaceRoot(cwd: string): string {
|
|
|
45
45
|
export function listWorkspacePackages(root: string): WorkspacePackage[] {
|
|
46
46
|
const packagesDir = join(root, "projects", "packages");
|
|
47
47
|
if (!existsSync(packagesDir)) {
|
|
48
|
-
return[];
|
|
48
|
+
return [];
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const packages: WorkspacePackage[] = [];
|
|
@@ -57,7 +57,7 @@ export function listWorkspacePackages(root: string): WorkspacePackage[] {
|
|
|
57
57
|
if (!existsSync(manifestPath)) {
|
|
58
58
|
continue;
|
|
59
59
|
}
|
|
60
|
-
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"))as PackageManifest;
|
|
60
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as PackageManifest;
|
|
61
61
|
if (!manifest.name || !manifest.version) {
|
|
62
62
|
throw new Error(`package.json missing name or version: ${manifestPath}`);
|
|
63
63
|
}
|
|
@@ -76,15 +76,15 @@ export function listWorkspacePackages(root: string): WorkspacePackage[] {
|
|
|
76
76
|
|
|
77
77
|
export function collectInternalDependencyNames(
|
|
78
78
|
pkg: WorkspacePackage,
|
|
79
|
-
byName: Map
|
|
80
|
-
): Set
|
|
81
|
-
const deps = new Set
|
|
79
|
+
byName: Map<string, WorkspacePackage>,
|
|
80
|
+
): Set<string> {
|
|
81
|
+
const deps = new Set<string>();
|
|
82
82
|
for (const field of DEPENDENCY_FIELDS) {
|
|
83
83
|
const entries = pkg.manifest[field];
|
|
84
84
|
if (!entries) {
|
|
85
85
|
continue;
|
|
86
86
|
}
|
|
87
|
-
for (const[depName, spec]of Object.entries(entries)) {
|
|
87
|
+
for (const [depName, spec] of Object.entries(entries)) {
|
|
88
88
|
if (byName.has(depName)) {
|
|
89
89
|
deps.add(depName);
|
|
90
90
|
continue;
|
|
@@ -101,7 +101,7 @@ export function collectInternalDependencyNames(
|
|
|
101
101
|
function resolveWorkspaceDependencyName(
|
|
102
102
|
spec: string,
|
|
103
103
|
packageDir: string,
|
|
104
|
-
byName: Map
|
|
104
|
+
byName: Map<string, WorkspacePackage>,
|
|
105
105
|
): string | undefined {
|
|
106
106
|
if (spec.startsWith("workspace:")) {
|
|
107
107
|
return undefined;
|
|
@@ -119,6 +119,6 @@ function resolveWorkspaceDependencyName(
|
|
|
119
119
|
if (!existsSync(manifestPath)) {
|
|
120
120
|
return undefined;
|
|
121
121
|
}
|
|
122
|
-
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"))as PackageManifest;
|
|
122
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as PackageManifest;
|
|
123
123
|
return manifest.name;
|
|
124
124
|
}
|
package/src/config/authorMap.ts
CHANGED
|
@@ -13,8 +13,12 @@ export function resolveAuthorMapPath(config: NiftyConfig, repoRoot: string): str
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/** Load author map file contents for native helpers expecting JSON text. */
|
|
16
|
-
export function loadAuthorMapJson(repoRoot: string, authorMapPath?: string)
|
|
17
|
-
const abs = authorMapPath
|
|
16
|
+
export function loadAuthorMapJson(repoRoot: string, authorMapPath?: string): string {
|
|
17
|
+
const abs = authorMapPath
|
|
18
|
+
? isAbsolute(authorMapPath)
|
|
19
|
+
? authorMapPath
|
|
20
|
+
: join(repoRoot, authorMapPath)
|
|
21
|
+
: resolveAuthorMapPath({}, repoRoot);
|
|
18
22
|
if (!existsSync(abs)) {
|
|
19
23
|
return "{}";
|
|
20
24
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { NiftyConfig, NiftyConfigEnv } from "./types.js";
|
|
1
|
+
import type { NiftyConfig, NiftyConfigEnv, NiftyConfigExport } from "./types.js";
|
|
2
|
+
|
|
3
|
+
type NiftyConfigFactory = (env: NiftyConfigEnv) => NiftyConfig | Promise<NiftyConfig>;
|
|
4
|
+
|
|
5
|
+
type DefineConfigInput<T> = T extends NiftyConfigFactory
|
|
6
|
+
? T
|
|
7
|
+
: T extends NiftyConfig
|
|
8
|
+
? T & Record<Exclude<keyof T, keyof NiftyConfig>, never>
|
|
9
|
+
: never;
|
|
2
10
|
|
|
3
11
|
/** Type-safe helper for `nifty.config.ts` / `nifty.config.js`. */
|
|
4
|
-
export function defineConfig(config:
|
|
5
|
-
export function defineConfig(
|
|
6
|
-
config: (env: NiftyConfigEnv) => NiftyConfig | Promise < NiftyConfig> ,
|
|
7
|
-
): (env: NiftyConfigEnv) => NiftyConfig | Promise < NiftyConfig> ;
|
|
8
|
-
export function defineConfig(
|
|
9
|
-
config: NiftyConfig | ((env: NiftyConfigEnv) => NiftyConfig | Promise < NiftyConfig> ),
|
|
10
|
-
): NiftyConfig | ((env: NiftyConfigEnv) => NiftyConfig | Promise < NiftyConfig> ) {
|
|
12
|
+
export function defineConfig<T extends NiftyConfigExport>(config: DefineConfigInput<T>): T {
|
|
11
13
|
return config;
|
|
12
14
|
}
|
|
@@ -162,7 +162,7 @@ export function detectProjectLayout(cwd = process.cwd()): ProjectLayout {
|
|
|
162
162
|
|
|
163
163
|
/** Discover npm package directories for hybrid monorepos. */
|
|
164
164
|
export function discoverPackageDirs(layout: ProjectLayout): string[] {
|
|
165
|
-
const roots = new Set
|
|
165
|
+
const roots = new Set<string>();
|
|
166
166
|
|
|
167
167
|
if (layout.npmWorkspaceRoot) {
|
|
168
168
|
roots.add(layout.npmWorkspaceRoot);
|
|
@@ -185,5 +185,5 @@ export function discoverPackageDirs(layout: ProjectLayout): string[] {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
return[...roots];
|
|
188
|
+
return [...roots];
|
|
189
189
|
}
|
|
@@ -23,7 +23,7 @@ const NIFTY_PRESET_INCLUDES = [
|
|
|
23
23
|
"projects/dashboard/**",
|
|
24
24
|
"package.json",
|
|
25
25
|
"nifty.config.ts",
|
|
26
|
-
]as const;
|
|
26
|
+
] as const;
|
|
27
27
|
|
|
28
28
|
/** VMZ hybrid monorepo — JS/TS surfaces only, never whole-repo walk. */
|
|
29
29
|
const VMZ_INCLUDES = [
|
|
@@ -37,9 +37,9 @@ const VMZ_INCLUDES = [
|
|
|
37
37
|
"packages/homepage/**",
|
|
38
38
|
"package.json",
|
|
39
39
|
"nifty.config.ts",
|
|
40
|
-
]as const;
|
|
40
|
+
] as const;
|
|
41
41
|
|
|
42
|
-
const PRESET_INCLUDES: Record
|
|
42
|
+
const PRESET_INCLUDES: Record<NiftyFormatPreset, readonly string[] | undefined> = {
|
|
43
43
|
default: undefined,
|
|
44
44
|
nifty: NIFTY_PRESET_INCLUDES,
|
|
45
45
|
"npm-tools": NIFTY_PRESET_INCLUDES,
|
package/src/config/loadConfig.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type LoadConfigOptions = {
|
|
|
12
12
|
/** When set, skip searching and load this file directly. */
|
|
13
13
|
configFile?: string;
|
|
14
14
|
/** Passed to functional configs: `export default defineConfig(({ mode }) => ...)`. */
|
|
15
|
-
env?: Partial
|
|
15
|
+
env?: Partial<NiftyConfigEnv>;
|
|
16
16
|
/**
|
|
17
17
|
* When true (default), write `nifty.config.ts` at the detected project root if missing.
|
|
18
18
|
* Set false for `--dry-run` so commands only report what would happen.
|
|
@@ -63,7 +63,7 @@ export function defaultConfigPath(cwd = process.cwd()): string {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/** Warn and optionally create a default config when none exists. */
|
|
66
|
-
export function ensureConfigFile(options: { cwd?: string; create?: boolean } = {
|
|
66
|
+
export function ensureConfigFile(options: { cwd?: string; create?: boolean } = {}): string | undefined {
|
|
67
67
|
const cwd = options.cwd ?? process.cwd();
|
|
68
68
|
const existing = findConfigFile(cwd);
|
|
69
69
|
if (existing) {
|
|
@@ -83,12 +83,12 @@ export function ensureConfigFile(options: { cwd?: string; create?: boolean } = {
|
|
|
83
83
|
|
|
84
84
|
function normalizeExport(raw: unknown): NiftyConfigExport {
|
|
85
85
|
if (raw && typeof raw === "object" && "default" in raw) {
|
|
86
|
-
return(raw as { default: NiftyConfigExport }).default;
|
|
86
|
+
return (raw as { default: NiftyConfigExport }).default;
|
|
87
87
|
}
|
|
88
88
|
return raw as NiftyConfigExport;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
async function resolveExport(exported: NiftyConfigExport, env: NiftyConfigEnv): Promise
|
|
91
|
+
async function resolveExport(exported: NiftyConfigExport, env: NiftyConfigEnv): Promise<NiftyConfig> {
|
|
92
92
|
if (typeof exported === "function") {
|
|
93
93
|
return await exported(env);
|
|
94
94
|
}
|
|
@@ -96,7 +96,7 @@ async function resolveExport(exported: NiftyConfigExport, env: NiftyConfigEnv):
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/** Load `nifty.config.ts/js`, creating a default file at the project root when missing. */
|
|
99
|
-
export async function loadConfig(options: LoadConfigOptions = {
|
|
99
|
+
export async function loadConfig(options: LoadConfigOptions = {}): Promise<LoadedNiftyConfig> {
|
|
100
100
|
const cwd = options.cwd ?? process.cwd();
|
|
101
101
|
let configFile = options.configFile ?? findConfigFile(cwd);
|
|
102
102
|
let created = false;
|
|
@@ -106,11 +106,11 @@ export async function loadConfig(options: LoadConfigOptions = { }): Promise < Lo
|
|
|
106
106
|
created = Boolean(configFile);
|
|
107
107
|
} else if (!configFile) {
|
|
108
108
|
ensureConfigFile({ cwd, create: false });
|
|
109
|
-
return { config: {
|
|
109
|
+
return { config: {} };
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
if (!configFile) {
|
|
113
|
-
return { config: {
|
|
113
|
+
return { config: {} };
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
const env: NiftyConfigEnv = { ...DEFAULT_ENV(cwd), ...options.env };
|
|
@@ -4,11 +4,11 @@ import type { NiftyConfig } from "./types.js";
|
|
|
4
4
|
export function trustPayloadFromConfig(config: NiftyConfig) {
|
|
5
5
|
const npm = config.trust?.npm;
|
|
6
6
|
if (!npm) {
|
|
7
|
-
return {
|
|
7
|
+
return {};
|
|
8
8
|
}
|
|
9
9
|
return {
|
|
10
|
-
...(npm.repo ? { trustRepo: npm.repo } : {
|
|
11
|
-
...(npm.file ? { trustFile: npm.file } : {
|
|
12
|
-
...(npm.environment ? { trustEnvironment: npm.environment } : {
|
|
10
|
+
...(npm.repo ? { trustRepo: npm.repo } : {}),
|
|
11
|
+
...(npm.file ? { trustFile: npm.file } : {}),
|
|
12
|
+
...(npm.environment ? { trustEnvironment: npm.environment } : {}),
|
|
13
13
|
};
|
|
14
14
|
}
|
package/src/config/types.ts
CHANGED
|
@@ -84,7 +84,7 @@ export type NiftyConfig = {
|
|
|
84
84
|
};
|
|
85
85
|
/** Rule-based lint configuration. */
|
|
86
86
|
lint?: {
|
|
87
|
-
rules?: Array
|
|
87
|
+
rules?: Array<{
|
|
88
88
|
id: string;
|
|
89
89
|
enabled?: boolean;
|
|
90
90
|
severity?: "error" | "warning" | "info";
|
|
@@ -94,7 +94,7 @@ export type NiftyConfig = {
|
|
|
94
94
|
format?: NiftyFormatConfig;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
export type NiftyConfigExport = NiftyConfig | ((env: NiftyConfigEnv) => NiftyConfig | Promise
|
|
97
|
+
export type NiftyConfigExport = NiftyConfig | ((env: NiftyConfigEnv) => NiftyConfig | Promise<NiftyConfig>);
|
|
98
98
|
|
|
99
99
|
export type NiftyConfigEnv = {
|
|
100
100
|
mode: string;
|
|
@@ -108,4 +108,4 @@ export const CONFIG_FILE_NAMES = [
|
|
|
108
108
|
"nifty.config.js",
|
|
109
109
|
"nifty.config.mjs",
|
|
110
110
|
"nifty.config.cjs",
|
|
111
|
-
]as const;
|
|
111
|
+
] as const;
|
package/src/git.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type ResolveRangeOptions = {
|
|
|
11
11
|
* Read-only git repository helpers (gix via Node-API, no `git` subprocess).
|
|
12
12
|
*/
|
|
13
13
|
export class Git {
|
|
14
|
-
constructor(private readonly wasm: GitExports) {
|
|
14
|
+
constructor(private readonly wasm: GitExports) {}
|
|
15
15
|
|
|
16
16
|
static open(): Git {
|
|
17
17
|
const native = loadNiftyNative();
|
|
@@ -36,7 +36,7 @@ export class Git {
|
|
|
36
36
|
return this.wasm["format-tag-list"](repoRoot);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
resolveRange(repoRoot: string, options: ResolveRangeOptions = {
|
|
39
|
+
resolveRange(repoRoot: string, options: ResolveRangeOptions = {}): RangeInfo {
|
|
40
40
|
return mapRangeInfo(
|
|
41
41
|
this.wasm["resolve-range"](repoRoot, options.version, options.fromRef, options.toRef),
|
|
42
42
|
);
|