Compare commits
6
Commits
82381a5e93
...
4a6bc42635
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a6bc42635 | ||
|
|
b86c661af5 | ||
|
|
71c068966e | ||
|
|
784b9cbac8 | ||
|
|
2325214078 | ||
|
|
e194e605f9 |
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
|
"scope": "模板完成证据登记,保留命令、日志与产物哈希",
|
||||||
"generatedAt": "2026-10-20T13:23:08.179Z",
|
"generatedAt": "2026-10-21T04:17:12.186Z",
|
||||||
"templates": {
|
"templates": {
|
||||||
"acheng-campus-food": {
|
"acheng-campus-food": {
|
||||||
"real-manifest-interaction": {
|
"real-manifest-interaction": {
|
||||||
@@ -256,5 +256,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sourceTreeHash": "7db7647772c54d29bcff2211b59bc3a1c261988b543046ba3b078d5945d3a599"
|
"sourceTreeHash": "4331e0ff7919e4cc1d44de321c1c1d47e7f1858098d575dea7b21553aaeba284"
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -p tsconfig.json",
|
"build": "tsc -p tsconfig.json",
|
||||||
|
"postinstall": "prisma generate",
|
||||||
"dev": "pnpm build && node --env-file=.env --watch dist/main.js",
|
"dev": "pnpm build && node --env-file=.env --watch dist/main.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ function validateManifestOutput(manifest, output, otherComponentNames) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasNpm = fs.existsSync(path.join(output, "miniprogram_npm"));
|
||||||
for (const file of listFiles(output)) {
|
for (const file of listFiles(output)) {
|
||||||
if (!/\.(js|json|wxml)$/.test(file)) continue;
|
if (!/\.(js|json|wxml)$/.test(file)) continue;
|
||||||
const source = fs.readFileSync(path.join(output, file), "utf8");
|
const source = fs.readFileSync(path.join(output, file), "utf8");
|
||||||
@@ -106,11 +107,11 @@ function validateManifestOutput(manifest, output, otherComponentNames) {
|
|||||||
}
|
}
|
||||||
for (const [name, reference] of Object.entries(definition.usingComponents || {})) {
|
for (const [name, reference] of Object.entries(definition.usingComponents || {})) {
|
||||||
if (reference.startsWith("plugin://")) continue;
|
if (reference.startsWith("plugin://")) continue;
|
||||||
if (
|
// miniprogram_npm 由微信开发者工具生成且不入库;缺失时跳过 npm 组件解析检查。
|
||||||
reference.startsWith("/miniprogram_npm/") &&
|
const needsNpm =
|
||||||
!fs.existsSync(path.join(output, "miniprogram_npm"))
|
reference.startsWith("/miniprogram_npm/") ||
|
||||||
)
|
(!reference.startsWith("/") && !reference.startsWith("."));
|
||||||
continue;
|
if (needsNpm && !hasNpm) continue;
|
||||||
if (!resolveComponent(output, file, reference))
|
if (!resolveComponent(output, file, reference))
|
||||||
failures.push(`${file}: component ${name} cannot be resolved (${reference})`);
|
failures.push(`${file}: component ${name} cannot be resolved (${reference})`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ function resolveRequire(output, fromFile, reference) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 校验产物可以被微信开发者工具直接打开:页面、组件、require、图标和模板隔离。 */
|
/** 校验产物可以被微信开发者工具直接打开:页面、组件、require、图标和模板隔离。 */
|
||||||
function validateOutput(output, appJson, packageKey) {
|
export function validateOutput(output, appJson, packageKey) {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
const warnings = [];
|
const warnings = [];
|
||||||
for (const page of appJson.pages) {
|
for (const page of appJson.pages) {
|
||||||
@@ -325,11 +325,15 @@ function validateOutput(output, appJson, packageKey) {
|
|||||||
if (file.endsWith(".json") && (file.startsWith("pages/") || file.startsWith("components/"))) {
|
if (file.endsWith(".json") && (file.startsWith("pages/") || file.startsWith("components/"))) {
|
||||||
const usingComponents = JSON.parse(source).usingComponents || {};
|
const usingComponents = JSON.parse(source).usingComponents || {};
|
||||||
for (const [name, reference] of Object.entries(usingComponents)) {
|
for (const [name, reference] of Object.entries(usingComponents)) {
|
||||||
if (reference.startsWith("/miniprogram_npm/") && !hasNpm) {
|
if (reference.startsWith("plugin://")) continue;
|
||||||
|
// miniprogram_npm 由微信开发者工具生成且不入库;缺失时只能提示,不能把干净检出判为失败。
|
||||||
|
const needsNpm =
|
||||||
|
reference.startsWith("/miniprogram_npm/") ||
|
||||||
|
(!reference.startsWith("/") && !reference.startsWith("."));
|
||||||
|
if (needsNpm && !hasNpm) {
|
||||||
warnings.push(`${file}: ${name} needs miniprogram_npm (build npm in apps/miniapp first)`);
|
warnings.push(`${file}: ${name} needs miniprogram_npm (build npm in apps/miniapp first)`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (reference.startsWith("plugin://")) continue;
|
|
||||||
if (!resolveComponent(output, file, reference))
|
if (!resolveComponent(output, file, reference))
|
||||||
errors.push(`${file}: component ${name} cannot be resolved (${reference})`);
|
errors.push(`${file}: component ${name} cannot be resolved (${reference})`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import path from "node:path";
|
|||||||
import { execFileSync } from "node:child_process";
|
import { execFileSync } from "node:child_process";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
|
import { validateOutput } from "../src/cli.mjs";
|
||||||
|
|
||||||
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
const workspaceRoot = path.resolve(packageRoot, "../..");
|
const workspaceRoot = path.resolve(packageRoot, "../..");
|
||||||
@@ -59,6 +60,43 @@ test("compiler generates an isolated Acheng runtime manifest", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("干净检出缺少 miniprogram_npm 时 npm 组件引用只提示不报错", () => {
|
||||||
|
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-npm-"));
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(path.join(output, "pages/index"), { recursive: true });
|
||||||
|
fs.mkdirSync(path.join(output, "components/ui/brand-button"), { recursive: true });
|
||||||
|
for (const extension of [".js", ".json", ".wxml", ".wxss"]) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(output, "pages/index/index" + extension),
|
||||||
|
extension === ".json" ? "{}" : "",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(output, "components/ui/brand-button/brand-button.json"),
|
||||||
|
JSON.stringify({ usingComponents: { "t-button": "tdesign-miniprogram/button/button" } }),
|
||||||
|
);
|
||||||
|
const app = {
|
||||||
|
pages: ["pages/index/index"],
|
||||||
|
tabBar: { list: [{ pagePath: "pages/index/index" }] },
|
||||||
|
};
|
||||||
|
|
||||||
|
const withoutNpm = validateOutput(output, app, "fixture-template");
|
||||||
|
assert.deepEqual(withoutNpm.errors, []);
|
||||||
|
assert.ok(
|
||||||
|
withoutNpm.warnings.some((warning) => warning.includes("t-button needs miniprogram_npm")),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 微信开发者工具构建出 miniprogram_npm 后,仍必须严格校验组件是否真实存在。
|
||||||
|
fs.mkdirSync(path.join(output, "miniprogram_npm/tdesign-miniprogram/button"), {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
const withNpm = validateOutput(output, app, "fixture-template");
|
||||||
|
assert.ok(withNpm.errors.some((error) => error.includes("tdesign-miniprogram/button/button")));
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(output, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("compiler generates the Linjing navigation contract", () => {
|
test("compiler generates the Linjing navigation contract", () => {
|
||||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||||
execFileSync(process.execPath, [compiler, "--template", "linjing-editorial", "--out", output], {
|
execFileSync(process.execPath, [compiler, "--template", "linjing-editorial", "--out", output], {
|
||||||
|
|||||||
+2
-2
@@ -3,8 +3,8 @@
|
|||||||
"tasks": {
|
"tasks": {
|
||||||
"build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**"] },
|
"build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**"] },
|
||||||
"dev": { "cache": false, "persistent": true },
|
"dev": { "cache": false, "persistent": true },
|
||||||
"lint": { "dependsOn": ["^lint"], "outputs": [] },
|
"lint": { "dependsOn": ["^build"], "outputs": [] },
|
||||||
"typecheck": { "dependsOn": ["^typecheck"], "outputs": [] },
|
"typecheck": { "dependsOn": ["^build"], "outputs": [] },
|
||||||
"clean": { "cache": false }
|
"clean": { "cache": false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user