@akanjs/devkit 3.2.0-rc.3 → 3.2.0-rc.6
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/CHANGELOG.md +80 -11
- package/akanApp/akanApp.host.test.ts +51 -0
- package/akanApp/akanApp.host.ts +3 -3
- package/akanContext.ts +2 -3
- package/apiReport/apiDeclarationPrinter.ts +120 -0
- package/apiReport/apiReport.test.ts +483 -0
- package/apiReport/apiReport.ts +232 -0
- package/apiReport/apiReportDiff.ts +126 -0
- package/apiReport/apiReportPolicy.ts +64 -0
- package/apiReport/apiTargets.ts +311 -0
- package/apiReport/changesetBump.ts +19 -0
- package/applicationBuildReporter.test.ts +21 -0
- package/applicationBuildReporter.ts +8 -0
- package/applicationBuildRunner.test.ts +67 -0
- package/applicationBuildRunner.ts +6 -1
- package/artifact/implicitRootLayout.ts +12 -1
- package/codeAgent/skills/akan-debug/SKILL.md +6 -2
- package/codeAgent/skills/akan-transport/SKILL.md +2 -0
- package/commandDecorators/argMeta.ts +4 -0
- package/commandDecorators/command.ts +51 -33
- package/commandDecorators/commandDecorators.test.ts +74 -9
- package/frontendBuild/allRoutesBuilder.test.ts +16 -4
- package/frontendBuild/allRoutesBuilder.ts +24 -6
- package/frontendBuild/bundleDefine.ts +2 -0
- package/frontendBuild/clientBuildTypes.ts +5 -2
- package/frontendBuild/clientEntryDiscovery.test.ts +28 -0
- package/frontendBuild/clientEntryDiscovery.ts +25 -6
- package/frontendBuild/nativeCore.test.ts +148 -0
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +26 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +23 -19
- package/frontendBuild/vendorImportScanner.test.ts +24 -3
- package/frontendBuild/vendorImportScanner.ts +25 -10
- package/incrementalBuilder/incrementalBuilder.host.test.ts +5 -1
- package/incrementalBuilder/incrementalBuilder.host.ts +2 -1
- package/lint/no-web-only-api-outside-webkit.grit +3 -3
- package/{constantFieldNames.test.ts → moduleFieldNames.test.ts} +24 -2
- package/moduleFieldNames.ts +25 -0
- package/package.json +3 -3
- package/preview/PreviewView.ts +32 -13
- package/preview/previewView.test.ts +33 -3
- package/routeJsBudget.test.ts +47 -11
- package/routeJsBudget.ts +88 -25
- package/workflow/plainName.ts +16 -3
- package/constantFieldNames.ts +0 -18
package/routeJsBudget.test.ts
CHANGED
|
@@ -96,30 +96,50 @@ describe("RouteJsBudget", () => {
|
|
|
96
96
|
const setup = async (text?: string) => {
|
|
97
97
|
const budgetPath = path.join(await makeTempRoot(), "akan.budget.json");
|
|
98
98
|
if (text !== undefined) await write(budgetPath, text);
|
|
99
|
-
return { budgetPath, source: "apps/shop/akan.budget.json", environment: "local" };
|
|
99
|
+
return { app: "shop", budgetPath, source: "apps/shop/akan.budget.json", environment: "local" };
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
test("enforce fails a route over its limit
|
|
102
|
+
test("enforce fails a route over its limit, a route with no entry, a file it cannot read, and an app with no file", async () => {
|
|
103
103
|
const over = await setup(JSON.stringify({ env: "main", routeJsBrotliKB: { "/:lang/memo": 120 } }));
|
|
104
104
|
await expect(RouteJsBudget.check(sizes, { ...over, mode: "enforce" })).rejects.toThrow(
|
|
105
105
|
"1 route over the JS budget in apps/shop/akan.budget.json (recorded for main, built for local):",
|
|
106
106
|
);
|
|
107
|
+
await expect(RouteJsBudget.check(sizes, { ...over, mode: "enforce" })).rejects.toThrow(
|
|
108
|
+
"in apps/shop/akan.budget.json by hand.\n1 route with no entry in apps/shop/akan.budget.json",
|
|
109
|
+
);
|
|
110
|
+
const missing = await setup(JSON.stringify({ routeJsBrotliKB: { "/:lang/memo": 130 } }));
|
|
111
|
+
await expect(RouteJsBudget.check(sizes, { ...missing, mode: "enforce" })).rejects.toThrow(
|
|
112
|
+
[
|
|
113
|
+
"1 route with no entry in apps/shop/akan.budget.json, which --check-budget checks every route against:",
|
|
114
|
+
" /:lang/new",
|
|
115
|
+
"Record it in the same change: `akan build shop --update-budget` adds each new route at its measured size.",
|
|
116
|
+
].join("\n"),
|
|
117
|
+
);
|
|
107
118
|
const broken = await setup("{");
|
|
108
119
|
await expect(RouteJsBudget.check(sizes, { ...broken, mode: "enforce" })).rejects.toThrow("is not valid JSON");
|
|
120
|
+
await expect(RouteJsBudget.check(sizes, { ...(await setup()), mode: "enforce" })).rejects.toThrow(
|
|
121
|
+
"--check-budget found no apps/shop/akan.budget.json: record one with `akan build shop --update-budget`.",
|
|
122
|
+
);
|
|
109
123
|
});
|
|
110
124
|
|
|
111
|
-
test("report warns of an overage and a file it cannot read, and fails
|
|
125
|
+
test("report warns of an overage, a route with no entry and a file it cannot read, and fails none", async () => {
|
|
126
|
+
const unbudgetedWarning = {
|
|
127
|
+
file: "apps/shop/akan.budget.json",
|
|
128
|
+
message: "/:lang/new has no entry; akan build --check-budget fails on it",
|
|
129
|
+
fix: "record it with akan build shop --update-budget",
|
|
130
|
+
};
|
|
112
131
|
const over = await setup(JSON.stringify({ env: "main", routeJsBrotliKB: { "/:lang/memo": 120 } }));
|
|
113
132
|
expect(await RouteJsBudget.check(sizes, { ...over, mode: "report" })).toEqual({
|
|
114
133
|
summary:
|
|
115
|
-
"1 route(s) over apps/shop/akan.budget.json (recorded for main, built for local), reported only: /:lang/memo",
|
|
134
|
+
"1 route(s) over apps/shop/akan.budget.json (recorded for main, built for local), reported only: /:lang/memo; 1 route(s) without an entry",
|
|
116
135
|
warnings: [
|
|
117
136
|
{
|
|
118
137
|
file: "apps/shop/akan.budget.json",
|
|
119
138
|
message:
|
|
120
|
-
"/:lang/memo loads 133,120 bytes brotli, over its limit of 126,976 (recorded for main, built for local); akan build fails on it",
|
|
121
|
-
fix: "shrink what the route loads, or raise its entry
|
|
139
|
+
"/:lang/memo loads 133,120 bytes brotli, over its limit of 126,976 (recorded for main, built for local); akan build --check-budget fails on it",
|
|
140
|
+
fix: "shrink what the route loads, or raise its entry with akan build shop --raise-budget",
|
|
122
141
|
},
|
|
142
|
+
unbudgetedWarning,
|
|
123
143
|
],
|
|
124
144
|
});
|
|
125
145
|
const broken = await setup("{");
|
|
@@ -128,8 +148,8 @@ describe("RouteJsBudget", () => {
|
|
|
128
148
|
warnings: [
|
|
129
149
|
{
|
|
130
150
|
file: "apps/shop/akan.budget.json",
|
|
131
|
-
message: "apps/shop/akan.budget.json is not valid JSON; akan build fails on it",
|
|
132
|
-
fix: "correct it, or rewrite it with akan build
|
|
151
|
+
message: "apps/shop/akan.budget.json is not valid JSON; akan build --check-budget fails on it",
|
|
152
|
+
fix: "correct it, or rewrite it with akan build shop --update-budget",
|
|
133
153
|
},
|
|
134
154
|
],
|
|
135
155
|
});
|
|
@@ -138,7 +158,8 @@ describe("RouteJsBudget", () => {
|
|
|
138
158
|
});
|
|
139
159
|
const within = await setup(JSON.stringify({ routeJsBrotliKB: { "/:lang/memo": 130 } }));
|
|
140
160
|
expect(await RouteJsBudget.check(sizes, { ...within, mode: "report" })).toEqual({
|
|
141
|
-
summary: "within apps/shop/akan.budget.json
|
|
161
|
+
summary: "within apps/shop/akan.budget.json; 1 route(s) without an entry",
|
|
162
|
+
warnings: [unbudgetedWarning],
|
|
142
163
|
});
|
|
143
164
|
});
|
|
144
165
|
|
|
@@ -157,20 +178,35 @@ describe("RouteJsBudget", () => {
|
|
|
157
178
|
await expect(RouteJsBudget.check(sizes, { ...over, mode: "update" })).rejects.toThrow("/:lang/memo");
|
|
158
179
|
expect(RouteJsBudget.parse(await Bun.file(over.budgetPath).text()).kbByRoute.get("/:lang/memo")).toBe(120);
|
|
159
180
|
});
|
|
181
|
+
|
|
182
|
+
test("raise re-records every route at its measured size and names the entries it raised", async () => {
|
|
183
|
+
const over = await setup(
|
|
184
|
+
JSON.stringify({ env: "main", routeJsBrotliKB: { "/:lang/memo": 120, "/:lang/new": 90 } }),
|
|
185
|
+
);
|
|
186
|
+
expect(await RouteJsBudget.check(sizes, { ...over, mode: "raise" })).toEqual({
|
|
187
|
+
summary: "apps/shop/akan.budget.json re-recorded at each route's measured size, raised: /:lang/memo",
|
|
188
|
+
});
|
|
189
|
+
const written = RouteJsBudget.parse(await Bun.file(over.budgetPath).text());
|
|
190
|
+
expect(written.env).toBe("local");
|
|
191
|
+
expect(Object.fromEntries(written.kbByRoute)).toEqual({ "/:lang/memo": 130, "/:lang/new": 70 });
|
|
192
|
+
expect(await RouteJsBudget.check(sizes, { ...over, mode: "enforce" })).toEqual({
|
|
193
|
+
summary: "within apps/shop/akan.budget.json",
|
|
194
|
+
});
|
|
195
|
+
});
|
|
160
196
|
});
|
|
161
197
|
|
|
162
198
|
test("names each route over budget, its limit, and how to resolve it", () => {
|
|
163
199
|
expect(
|
|
164
200
|
RouteJsBudget.formatOverages(
|
|
165
201
|
[{ routeId: "/:lang/memo", brotliBytes: 128_000, budgetKB: 120, limitBytes: 126_976 }],
|
|
166
|
-
"apps/shop/akan.budget.json",
|
|
202
|
+
{ app: "shop", source: "apps/shop/akan.budget.json" },
|
|
167
203
|
" (recorded for main, built for local)",
|
|
168
204
|
),
|
|
169
205
|
).toBe(
|
|
170
206
|
[
|
|
171
207
|
"1 route over the JS budget in apps/shop/akan.budget.json (recorded for main, built for local):",
|
|
172
208
|
" /:lang/memo: 128,000 bytes brotli, over its limit of 126,976 (120KB + the larger of 1% and 4KB)",
|
|
173
|
-
|
|
209
|
+
'Shrink what the route loads. If the growth is intended, record it in the same change: `akan build shop --raise-budget` re-records every route at its measured size, or raise the route\'s entry under "routeJsBrotliKB" in apps/shop/akan.budget.json by hand.',
|
|
174
210
|
].join("\n"),
|
|
175
211
|
);
|
|
176
212
|
});
|
package/routeJsBudget.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface RouteJsOverage {
|
|
|
17
17
|
limitBytes: number;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export type RouteJsBudgetMode = "enforce" | "update" | "report" | "off";
|
|
20
|
+
export type RouteJsBudgetMode = "enforce" | "update" | "raise" | "report" | "off";
|
|
21
21
|
|
|
22
22
|
export interface RouteJsBudgetWarning {
|
|
23
23
|
file: string;
|
|
@@ -30,8 +30,20 @@ export interface RouteJsBudgetStatus {
|
|
|
30
30
|
warnings?: RouteJsBudgetWarning[];
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export interface RouteJsBudgetFlags {
|
|
34
|
+
checkBudget?: boolean;
|
|
35
|
+
updateBudget?: boolean;
|
|
36
|
+
raiseBudget?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface BudgetTarget {
|
|
40
|
+
app: string;
|
|
41
|
+
source: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
export interface RouteJsBudgetCheck {
|
|
34
45
|
mode: Exclude<RouteJsBudgetMode, "off">;
|
|
46
|
+
app: string;
|
|
35
47
|
budgetPath: string;
|
|
36
48
|
source: string;
|
|
37
49
|
environment: string;
|
|
@@ -65,47 +77,85 @@ export class RouteJsBudget {
|
|
|
65
77
|
.sort((a, b) => b.brotliBytes - a.brotliBytes || RouteJsBudget.#byCodeUnit(a.routeId, b.routeId));
|
|
66
78
|
}
|
|
67
79
|
|
|
80
|
+
static modeOf({ checkBudget = false, updateBudget = false, raiseBudget = false }: RouteJsBudgetFlags) {
|
|
81
|
+
if ([checkBudget, updateBudget, raiseBudget].filter(Boolean).length > 1)
|
|
82
|
+
throw new Error("Pass at most one of --check-budget, --update-budget and --raise-budget.");
|
|
83
|
+
return checkBudget ? "enforce" : updateBudget ? "update" : raiseBudget ? "raise" : "report";
|
|
84
|
+
}
|
|
85
|
+
|
|
68
86
|
static async load(filePath: string, source = filePath): Promise<RouteJsBudget | null> {
|
|
69
87
|
const file = Bun.file(filePath);
|
|
70
88
|
if (!(await file.exists())) return null;
|
|
71
89
|
return RouteJsBudget.parse(await file.text(), source);
|
|
72
90
|
}
|
|
73
91
|
|
|
74
|
-
//?
|
|
75
|
-
static async check(
|
|
76
|
-
|
|
77
|
-
{ mode, budgetPath, source, environment }: RouteJsBudgetCheck,
|
|
78
|
-
): Promise<RouteJsBudgetStatus> {
|
|
92
|
+
//? A deploy build and `akan verify`'s edit loop only report: `enforce` (`--check-budget`, run by CI) is the gate.
|
|
93
|
+
static async check(sizes: RouteJsSize[], check: RouteJsBudgetCheck): Promise<RouteJsBudgetStatus> {
|
|
94
|
+
const { mode, app, budgetPath, source, environment } = check;
|
|
79
95
|
const { committed, unreadable } = await RouteJsBudget.#loadFor(mode, budgetPath, source);
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
if (mode === "enforce" && !committed)
|
|
97
|
+
throw new Error(`--check-budget found no ${source}: record one with \`akan build ${app} --update-budget\`.`);
|
|
98
|
+
const budget =
|
|
99
|
+
mode === "raise"
|
|
100
|
+
? new RouteJsBudget().tightenedBy(sizes, environment)
|
|
101
|
+
: mode === "update"
|
|
102
|
+
? (committed ?? new RouteJsBudget()).tightenedBy(sizes, environment)
|
|
103
|
+
: committed;
|
|
104
|
+
if ((mode === "update" || mode === "raise") && budget) await Bun.write(budgetPath, budget.stringify());
|
|
82
105
|
const overages = budget?.overages(sizes) ?? [];
|
|
106
|
+
const unbudgeted = budget?.unbudgeted(sizes) ?? [];
|
|
83
107
|
const envNote = committed?.envNote(environment) ?? "";
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
108
|
+
const target = { app, source };
|
|
109
|
+
const failures = [
|
|
110
|
+
...(overages.length && mode !== "report" ? [RouteJsBudget.formatOverages(overages, target, envNote)] : []),
|
|
111
|
+
...(unbudgeted.length && mode === "enforce" ? [RouteJsBudget.formatUnbudgeted(unbudgeted, target)] : []),
|
|
112
|
+
];
|
|
113
|
+
if (failures.length) throw new Error(failures.join("\n"));
|
|
114
|
+
if (mode === "update" || mode === "raise")
|
|
115
|
+
return { summary: RouteJsBudget.#writtenSummary(check, unreadable, committed, budget) };
|
|
87
116
|
if (unreadable)
|
|
88
117
|
return {
|
|
89
118
|
summary: `${unreadable}, not checked`,
|
|
90
119
|
warnings: [
|
|
91
120
|
{
|
|
92
121
|
file: source,
|
|
93
|
-
message: `${unreadable}; akan build fails on it`,
|
|
94
|
-
fix:
|
|
122
|
+
message: `${unreadable}; akan build --check-budget fails on it`,
|
|
123
|
+
fix: `correct it, or rewrite it with akan build ${app} --update-budget`,
|
|
95
124
|
},
|
|
96
125
|
],
|
|
97
126
|
};
|
|
98
127
|
if (!budget) return { summary: `no ${RouteJsBudget.fileName}` };
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
128
|
+
const warnings = [
|
|
129
|
+
...overages.map(({ routeId, brotliBytes, limitBytes }) => ({
|
|
130
|
+
file: source,
|
|
131
|
+
message: `${routeId} loads ${RouteJsBudget.#bytes(brotliBytes)} bytes brotli, over its limit of ${RouteJsBudget.#bytes(limitBytes)}${envNote}; akan build --check-budget fails on it`,
|
|
132
|
+
fix: `shrink what the route loads, or raise its entry with akan build ${app} --raise-budget`,
|
|
133
|
+
})),
|
|
134
|
+
...unbudgeted.map((routeId) => ({
|
|
135
|
+
file: source,
|
|
136
|
+
message: `${routeId} has no entry; akan build --check-budget fails on it`,
|
|
137
|
+
fix: `record it with akan build ${app} --update-budget`,
|
|
138
|
+
})),
|
|
139
|
+
];
|
|
140
|
+
const verdict = overages.length
|
|
141
|
+
? `${overages.length} route(s) over ${source}${envNote}, reported only: ${overages.map(({ routeId }) => routeId).join(", ")}`
|
|
142
|
+
: `within ${source}${envNote}`;
|
|
143
|
+
const unbudgetedNote = unbudgeted.length ? `; ${unbudgeted.length} route(s) without an entry` : "";
|
|
144
|
+
return { summary: `${verdict}${unbudgetedNote}`, ...(warnings.length ? { warnings } : {}) };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static #writtenSummary(
|
|
148
|
+
{ mode, source }: RouteJsBudgetCheck,
|
|
149
|
+
unreadable: string | null,
|
|
150
|
+
committed: RouteJsBudget | null,
|
|
151
|
+
written: RouteJsBudget | null,
|
|
152
|
+
) {
|
|
153
|
+
if (unreadable) return `${source} rewritten (${unreadable})`;
|
|
154
|
+
if (mode === "update") return `${source} updated`;
|
|
155
|
+
const raised = [...(written?.kbByRoute ?? [])].filter(
|
|
156
|
+
([routeId, kb]) => kb > (committed?.kbByRoute.get(routeId) ?? kb),
|
|
157
|
+
);
|
|
158
|
+
return `${source} re-recorded at each route's measured size${raised.length ? `, raised: ${raised.map(([routeId]) => routeId).join(", ")}` : ""}`;
|
|
109
159
|
}
|
|
110
160
|
|
|
111
161
|
static async #loadFor(mode: RouteJsBudgetCheck["mode"], budgetPath: string, source: string) {
|
|
@@ -158,18 +208,31 @@ export class RouteJsBudget {
|
|
|
158
208
|
];
|
|
159
209
|
}
|
|
160
210
|
|
|
161
|
-
static formatOverages(overages: RouteJsOverage[],
|
|
211
|
+
static formatOverages(overages: RouteJsOverage[], target: BudgetTarget, envNote = ""): string {
|
|
162
212
|
const bytes = RouteJsBudget.#bytes;
|
|
213
|
+
const { source } = target;
|
|
163
214
|
return [
|
|
164
215
|
`${overages.length} route${overages.length === 1 ? "" : "s"} over the JS budget in ${source}${envNote}:`,
|
|
165
216
|
...overages.map(
|
|
166
217
|
({ routeId, brotliBytes, budgetKB, limitBytes }) =>
|
|
167
218
|
` ${routeId}: ${bytes(brotliBytes)} bytes brotli, over its limit of ${bytes(limitBytes)} (${budgetKB}KB + the larger of 1% and 4KB)`,
|
|
168
219
|
),
|
|
169
|
-
|
|
220
|
+
RouteJsBudget.#overageFix(target),
|
|
221
|
+
].join("\n");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static formatUnbudgeted(routeIds: string[], { app, source }: BudgetTarget): string {
|
|
225
|
+
return [
|
|
226
|
+
`${routeIds.length} route${routeIds.length === 1 ? "" : "s"} with no entry in ${source}, which --check-budget checks every route against:`,
|
|
227
|
+
...routeIds.map((routeId) => ` ${routeId}`),
|
|
228
|
+
`Record ${routeIds.length === 1 ? "it" : "them"} in the same change: \`akan build ${app} --update-budget\` adds each new route at its measured size.`,
|
|
170
229
|
].join("\n");
|
|
171
230
|
}
|
|
172
231
|
|
|
232
|
+
static #overageFix({ app, source }: BudgetTarget) {
|
|
233
|
+
return `Shrink what the route loads. If the growth is intended, record it in the same change: \`akan build ${app} --raise-budget\` re-records every route at its measured size, or raise the route's entry under "${RouteJsBudget.section}" in ${source} by hand.`;
|
|
234
|
+
}
|
|
235
|
+
|
|
173
236
|
static #bytes(value: number) {
|
|
174
237
|
return value.toLocaleString("en-US");
|
|
175
238
|
}
|
package/workflow/plainName.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
export const sysNamePattern = /^[a-z0-9][a-zA-Z0-9_-]*$/;
|
|
2
2
|
export const identifierPattern = /^_{0,2}[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
3
|
+
const packageNamePattern = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
|
4
|
+
|
|
5
|
+
export type PlainNameKind = "app" | "lib" | "module" | "service" | "scalar";
|
|
3
6
|
|
|
4
7
|
export const isWorkflowSysName = (value: unknown): value is string =>
|
|
5
8
|
typeof value === "string" && sysNamePattern.test(value);
|
|
6
9
|
export const isWorkflowModuleName = (value: unknown): value is string =>
|
|
7
10
|
typeof value === "string" && identifierPattern.test(value);
|
|
8
11
|
|
|
9
|
-
export const
|
|
12
|
+
export const plainNameProblem = (kind: PlainNameKind, name: string) => {
|
|
10
13
|
const isSys = kind === "app" || kind === "lib";
|
|
11
|
-
if (isSys ? isWorkflowSysName(name) : isWorkflowModuleName(name)) return;
|
|
14
|
+
if (isSys ? isWorkflowSysName(name) : isWorkflowModuleName(name)) return null;
|
|
15
|
+
return `${JSON.stringify(name)} is no ${kind} name; use letters, digits, - and _, starting with ${isSys ? "a lowercase letter or digit" : "a letter"}`;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const assertPlainName = (kind: PlainNameKind, name: string) => {
|
|
19
|
+
const problem = plainNameProblem(kind, name);
|
|
20
|
+
if (problem) throw new Error(problem);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const assertPackageName = (name: string) => {
|
|
24
|
+
if (packageNamePattern.test(name)) return;
|
|
12
25
|
throw new Error(
|
|
13
|
-
`${JSON.stringify(name)} is no
|
|
26
|
+
`${JSON.stringify(name)} is no package name; use name or @scope/name, each of lowercase letters, digits, -, . and _, starting with a letter or digit`,
|
|
14
27
|
);
|
|
15
28
|
};
|
package/constantFieldNames.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
const isFieldCall = (node: ts.Expression): boolean =>
|
|
4
|
-
ts.isCallExpression(node) &&
|
|
5
|
-
(ts.isIdentifier(node.expression)
|
|
6
|
-
? node.expression.text === "field"
|
|
7
|
-
: ts.isPropertyAccessExpression(node.expression) && isFieldCall(node.expression.expression));
|
|
8
|
-
|
|
9
|
-
export const constantFieldNames = (content: string) => {
|
|
10
|
-
const names: string[] = [];
|
|
11
|
-
const visit = (node: ts.Node) => {
|
|
12
|
-
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && isFieldCall(node.initializer))
|
|
13
|
-
names.push(node.name.text);
|
|
14
|
-
ts.forEachChild(node, visit);
|
|
15
|
-
};
|
|
16
|
-
visit(ts.createSourceFile("constant.ts", content, ts.ScriptTarget.Latest));
|
|
17
|
-
return names;
|
|
18
|
-
};
|