Skip to content

Commit 17a944d

Browse files
committed
Reapply "isolatedDeclarations"
This reverts commit bdef016.
1 parent 6d4d4a0 commit 17a944d

40 files changed

Lines changed: 163 additions & 127 deletions

pnpm-lock.yaml

Lines changed: 24 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ type Constructor<T> = new (ctx: Context) => T;
105105
export async function runCommand<T extends Base>(
106106
CommandClass: Constructor<T>,
107107
config: OverrideConfig,
108-
) {
108+
): Promise<void> {
109109
const ctx = await Config.loadConfig(config);
110110
const instance = new CommandClass(ctx);
111111
process.on("SIGINT", instance.exit.bind(instance));
112112
await instance.run();
113113
}
114114

115-
export default async function mainWithErrorHandler() {
115+
export default async function mainWithErrorHandler(): Promise<void> {
116116
main()
117117
.then(() => {
118118
checkGitIgnore();

src/constant.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
export const BASE_DIR = ".scaffold";
2-
export const CACHE_DIR = `${BASE_DIR}/cache`;
2+
export const CACHE_DIR = `.scaffold/cache`;
33
export const DEFAULT_PROFILE_DIR = "";
44
export const DEFAULT_DATA_DIR = "";
55

66
// Builder
77
export const DEFAULT_DIST_TEMP_DIR = "addon";
88

99
// Testser
10-
export const TESTER_BASE_PATH = `${BASE_DIR}/test`;
11-
export const TESTER_PROFILE_DIR = `${TESTER_BASE_PATH}/profile`;
12-
export const TESTER_DATA_DIR = `${TESTER_BASE_PATH}/data`;
13-
export const TESTER_PLUGIN_DIR = `${TESTER_BASE_PATH}/resource`;
14-
export const TESTER_PLUGIN_TESTS_DIR = `${TESTER_PLUGIN_DIR}/content/units`;
10+
export const TESTER_BASE_PATH = `.scaffold/test`;
11+
export const TESTER_PROFILE_DIR = `.scaffold/test/profile`;
12+
export const TESTER_DATA_DIR = `.scaffold/test/data`;
13+
export const TESTER_PLUGIN_DIR = `.scaffold/test/resource`;
14+
export const TESTER_PLUGIN_TESTS_DIR = `.scaffold/test/resource/content/units`;
1515
export const TESTER_PLUGIN_REF = "zotero-plugin-scaffold-test-runner";
16-
export const TESTER_PLUGIN_ID = "[email protected]";
16+
export const TESTER_PLUGIN_ID = "[email protected]" as const;

src/core/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Context } from "../types/index.js";
2+
import type { Logger } from "../utils/logger.js";
23

34
export abstract class Base {
45
ctx: Context;
@@ -10,7 +11,7 @@ export abstract class Base {
1011

1112
abstract exit(): void;
1213

13-
get logger() {
14+
get logger(): Logger {
1415
return this.ctx.logger;
1516
}
1617
}

src/core/builder/assets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default async function copyAssets(
1111
source: string | string[],
1212
dist: string,
1313
assets: string | string[],
14-
) {
14+
): Promise<void> {
1515
const sourceArr = toArray(source);
1616
const paths = await glob(assets, {
1717
ignore: [...DEFAULT_IGNORE, dist],

src/core/builder/clean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default async function clean() {
1+
export default async function clean(): Promise<void> {
22
//
33
}

src/core/builder/esbuild.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { BuildOptions, BuildResult } from "esbuild";
12
import type { BuildConfig } from "../../types/config.js";
23
import { resolve } from "node:path";
34
import { build as buildAsync } from "esbuild";
45
import { logger } from "../../utils/logger.js";
56

6-
export function resolveConfig(dist: string, esbuildOptions: BuildConfig["esbuildOptions"]) {
7+
export function resolveConfig(dist: string, esbuildOptions: BuildConfig["esbuildOptions"]): BuildOptions[] {
78
const distAbsolute = resolve(dist);
89

910
// ensure outfile and outdir are in dist folder
@@ -20,7 +21,7 @@ export function resolveConfig(dist: string, esbuildOptions: BuildConfig["esbuild
2021
});
2122
}
2223

23-
export default async function esbuild(dist: string, esbuildOptions: BuildConfig["esbuildOptions"]) {
24+
export default async function esbuild(dist: string, esbuildOptions: BuildConfig["esbuildOptions"]): Promise<BuildResult<BuildOptions>[] | undefined> {
2425
if (esbuildOptions.length === 0)
2526
return;
2627

src/core/builder/fluent.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default async function buildLocale(
1313
dist: string,
1414
namespace: string,
1515
options: BuildConfig["fluent"],
16-
) {
16+
): Promise<void> {
1717
const ignores = toArray(options.ignore);
1818
const localeNames = await getLocales(dist);
1919
const messageManager = new MessageManager(ignores);
@@ -81,13 +81,13 @@ export class FluentManager {
8181
constructor() {}
8282

8383
// Parse Fluent source into an AST and extract messages
84-
public parse(source: string) {
84+
public parse(source: string): void {
8585
this.source = source;
8686
this.resource = parse(source, {});
8787
}
8888

8989
// Read a file, parse its content, and extract messages
90-
public async read(path: string) {
90+
public async read(path: string): Promise<void> {
9191
const content = await readFile(path, "utf-8");
9292
this.parse(content);
9393
}
@@ -106,7 +106,7 @@ export class FluentManager {
106106
}
107107

108108
// Apply namespace prefix to message IDs in the resource
109-
public prefixMessages(namespace: string) {
109+
public prefixMessages(namespace: string): void {
110110
if (!this.resource) {
111111
throw new Error("Resource must be parsed before applying prefix.");
112112
}
@@ -122,7 +122,7 @@ export class FluentManager {
122122
}
123123

124124
// Write the serialized resource to a file
125-
public async write(path: string) {
125+
public async write(path: string): Promise<void> {
126126
const result = this.serialize();
127127
if (result !== this.source)
128128
await writeFile(path, this.serialize());
@@ -163,7 +163,7 @@ export class MessageManager {
163163
}
164164

165165
// Add a set of messages (FTL or HTML) for a specific locale or for HTML globally
166-
addMessages(target: string | "html", messages: string[]) {
166+
addMessages(target: string | "html", messages: string[]): void {
167167
if (target === "html") {
168168
messages.forEach(msg => this.htmlMessages.add(msg));
169169
}
@@ -177,7 +177,7 @@ export class MessageManager {
177177
}
178178
}
179179

180-
validateMessages() {
180+
validateMessages(): void {
181181
// Check miss 1: Cross check in diff locale - seems no need
182182
// messagesByLocale.forEach((messageInThisLang, lang) => {
183183
// // Needs Nodejs 22
@@ -223,7 +223,10 @@ export function processHTMLFile(
223223
allMessages: Set<string>,
224224
ignores: string[],
225225
filePath: string,
226-
) {
226+
): {
227+
processedContent: string;
228+
foundMessages: string[];
229+
} {
227230
const foundMessages = new Set<string>();
228231

229232
const L10N_PATTERN = new RegExp(`(data-l10n-id)="((?!${namespace})\\S*)"`, "g");

src/core/builder/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class Build extends Base {
2525
/**
2626
* Default build runner
2727
*/
28-
async run() {
28+
async run(): Promise<void> {
2929
const { dist, version } = this.ctx;
3030
const t = new Date();
3131
this.buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
@@ -71,13 +71,13 @@ export default class Build extends Base {
7171
await buildPrefs(dist, build.prefs);
7272
}
7373

74-
async bundle() {
74+
async bundle(): Promise<void> {
7575
const { dist, build: { esbuildOptions } } = this.ctx;
7676
await esbuild(dist, esbuildOptions);
7777
await this.ctx.hooks.callHook("build:bundle", this.ctx);
7878
}
7979

80-
async buildInProduction() {
80+
async buildInProduction(): Promise<void> {
8181
const { dist, xpiName } = this.ctx;
8282

8383
await pack(dist, xpiName);
@@ -87,5 +87,5 @@ export default class Build extends Base {
8787
await this.ctx.hooks.callHook("build:makeUpdateJSON", this.ctx);
8888
}
8989

90-
exit() {}
90+
exit(): void {}
9191
}

src/core/builder/manifest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { toMerged } from "es-toolkit";
44
import { outputJSON, readJSON } from "fs-extra/esm";
55
import { logger } from "../../utils/logger.js";
66

7-
export default async function buildManifest(ctx: Context) {
7+
export default async function buildManifest(ctx: Context): Promise<void> {
88
if (!ctx.build.makeManifest.enable)
99
return;
1010

@@ -33,6 +33,6 @@ export default async function buildManifest(ctx: Context) {
3333
}
3434

3535
// TODO: process i10n in manifest.json
36-
export function locale() {
36+
export function locale(): void {
3737
//
3838
}

0 commit comments

Comments
 (0)