Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bds-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"scripts": {
"build": "node ../scripts/esbuild-transpile.mjs --dts",
"dev": "tsx src/bds-manager.ts",
"typecheck": "node ../tools/tsc7.mjs --noEmit",
"typecheck": "tsc7 --noEmit",
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
"test": "node --test is-main.test.mjs pack-manager-lifecycle.test.mjs server-properties.test.mjs world-packs.test.mjs zipx.test.mjs",
"update": "node dist/check-update.js",
Expand Down
2 changes: 1 addition & 1 deletion db-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"start": "node dist/index.js",
"dev": "tsx src/index.ts",
"build": "node ../scripts/esbuild-transpile.mjs --dts",
"typecheck": "node ../tools/tsc7.mjs --noEmit",
"typecheck": "tsc7 --noEmit",
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
"test": "npm run build && node --test dist/*.test.js",
"format": "prettier --write \"src/**/*.{ts,tsx,js,json}\"",
Expand Down
2 changes: 1 addition & 1 deletion modules/packages/afk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "SAPI module: AFK - 玩家挂机检测与状态管理。",
"main": "sapi/src/index.ts",
"scripts": {
"typecheck": "node ../../../tools/tsc7.mjs --noEmit -p sapi/tsconfig.json"
"typecheck": "tsc7 --noEmit -p sapi/tsconfig.json"
},
"dependencies": {
"@sfmc-bds/sdk": "*"
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk/@sfmc-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"README.md"
],
"scripts": {
"build": "node ../../../tools/tsc7.mjs -p tsconfig.json",
"typecheck": "node ../../../tools/tsc7.mjs --noEmit -p tsconfig.json",
"build": "tsc7 -p tsconfig.json",
"typecheck": "tsc7 --noEmit -p tsconfig.json",
"test": "npm run build && node --test dist/**/*.test.js",
"prepublishOnly": "npm run build"
},
Expand Down
9 changes: 5 additions & 4 deletions modules/sdk/@sfmc-sdk/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* 2) tsc 发 .d.ts → dist/types/<subpath>/index.d.ts
*/
import { build } from "esbuild";
import { execSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import { runTsc7 } from "../../../tools/tsc7.mjs";

const SUBPATHS = [
{ sub: "contracts", platform: "neutral" },
Expand Down Expand Up @@ -74,9 +74,10 @@ for (const { sub, platform } of SUBPATHS) {
});
}

// 2) .d.ts — tsc --emitDeclarationOnly 产 dist/types
console.log("[sdk] emitting .d.ts via tsc...");
execSync("npx tsc -p tsconfig.types.json", { stdio: "inherit" });
// 2) .d.ts — 经 tsc7(TS7 native)产 dist/types
console.log("[sdk] emitting .d.ts via tsc7...");
const dtsCode = runTsc7(["-p", "tsconfig.types.json"]);
if (dtsCode !== 0) process.exit(dtsCode);

console.log("@sfmc-bds/sdk build done:", SUBPATHS.length, "subpaths");

4 changes: 2 additions & 2 deletions modules/sdk/@sfmc-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
"scripts": {
"build": "node build.mjs",
"build:js": "node build.mjs",
"build:types": "node ../../../tools/tsc7.mjs -p tsconfig.types.json",
"typecheck": "node ../../../tools/tsc7.mjs --noEmit -p tsconfig.types.json",
"build:types": "tsc7 -p tsconfig.types.json",
"typecheck": "tsc7 --noEmit -p tsconfig.types.json",
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
"prepublishOnly": "npm run clean && npm run build:types && node build.mjs"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"check-ootb": "node tools/check-ootb.mjs",
"check-minecraft-versions": "node tools/check-minecraft-versions.mjs",
"smoke-modules": "node tools/smoke-modules.mjs",
"typecheck": "node ./tools/tsc7.mjs --noEmit -p sfmc/tsconfig.json && node ./tools/tsc7.mjs --noEmit -p db-server/tsconfig.json && node ./tools/tsc7.mjs --noEmit -p bds-tools/tsconfig.json && node ./tools/tsc7.mjs --noEmit -p qq-bridge/tsconfig.json && node ./tools/tsc7.mjs --noEmit -p modules/sdk/@sfmc-sdk/tsconfig.types.json && node ./tools/tsc7.mjs --noEmit -p modules/sdk/@sfmc-eslint-plugin/tsconfig.json && node ./tools/tsc7.mjs --noEmit -p remote-controller/tsconfig.json",
"typecheck": "npm run typecheck --workspaces --if-present",
"lint": "npm run eslint-plugin:build && eslint .",
"bundle": "node build-sea.mjs",
"sea": "node --build-sea sea-config.json"
Expand Down
2 changes: 1 addition & 1 deletion qq-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"start": "node dist/index.js",
"dev": "tsx src/index.ts",
"build": "node ../scripts/esbuild-transpile.mjs",
"typecheck": "node ../tools/tsc7.mjs --noEmit",
"typecheck": "tsc7 --noEmit",
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
"format": "prettier --write \"src/**/*.{ts,tsx,js,json}\"",
"prepublishOnly": "npm run build"
Expand Down
2 changes: 1 addition & 1 deletion remote-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"build": "node ../scripts/esbuild-transpile.mjs",
"typecheck": "node ../tools/tsc7.mjs --noEmit",
"typecheck": "tsc7 --noEmit",
"start": "node dist/index.js"
},
"dependencies": {
Expand Down
15 changes: 10 additions & 5 deletions scripts/esbuild-transpile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*/

import { build } from "esbuild";
import { execSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import { runTsc7 } from "../tools/tsc7.mjs";

const emitDts = process.argv.includes("--dts");
const srcDir = path.resolve("src");
Expand Down Expand Up @@ -60,8 +60,13 @@ await build({
console.log(`[esbuild-transpile] emitted ${entryPoints.length} files → dist/`);

if (emitDts) {
console.log("[esbuild-transpile] emitting .d.ts via tsc --emitDeclarationOnly...");
execSync("npx tsc -p tsconfig.json --emitDeclarationOnly --declaration --declarationMap", {
stdio: "inherit",
});
console.log("[esbuild-transpile] emitting .d.ts via tsc7 --emitDeclarationOnly...");
const code = runTsc7([
"-p",
"tsconfig.json",
"--emitDeclarationOnly",
"--declaration",
"--declarationMap",
]);
if (code !== 0) process.exit(code);
}
2 changes: 1 addition & 1 deletion sfmc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"scripts": {
"start": "node ./dist/main.js",
"build": "node ../scripts/esbuild-transpile.mjs --dts",
"typecheck": "node ../tools/tsc7.mjs --noEmit -p tsconfig.json",
"typecheck": "tsc7 --noEmit -p tsconfig.json",
"dev": "tsx src/main.ts",
"prepublishOnly": "npm run build"
},
Expand Down
2 changes: 1 addition & 1 deletion tools/new-module.mjs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function buildPackageJson(folderId) {
description: `SAPI module: ${folderId}`,
main: "sapi/src/index.ts",
scripts: {
typecheck: "tsc --noEmit -p sapi/tsconfig.json",
typecheck: "tsc7 --noEmit -p sapi/tsconfig.json",
},
dependencies: {
"@sfmc-bds/sdk": "^0.1.0",
Expand Down
3 changes: 2 additions & 1 deletion tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"sfmc-fetch-module": "./fetch-module.mjs",
"sfmc-new-module": "./new-module.mjs",
"sfmc-smoke-modules": "./smoke-modules.mjs",
"sfmc-sim-new-user": "./sim-new-user.mjs"
"sfmc-sim-new-user": "./sim-new-user.mjs",
"tsc7": "./tsc7.mjs"
},
"files": [
"*.mjs",
Expand Down
2 changes: 1 addition & 1 deletion tools/smoke-remote-controller.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DIST = path.join(ROOT, "remote-controller", "dist", "index.js");
const ENTRY = path.join(ROOT, "tools", "smoke-remote-controller-agent.mjs");

if (!fs.existsSync(DIST)) {
console.error(`FAIL: missing build artifact ${DIST} (run: cd remote-controller && npx tsc)`);
console.error(`FAIL: missing build artifact ${DIST} (run: npm run build -w remote-controller)`);
process.exit(1);
}

Expand Down
65 changes: 56 additions & 9 deletions tools/tsc7.mjs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,64 @@
#!/usr/bin/env node
/**
* 调用 TypeScript 7 原生 tsc。
* 双轨安装下 `typescript` 解析为 @typescript/typescript6(ESLint API),
* 其依赖 @typescript/old 会占用 node_modules/.bin/tsc,故 typecheck/emit 需显式走本入口。
* 调用 TypeScript 7 原生 tsc(权威入口)。
*
* 双轨安装:
* - `typescript` → `@typescript/typescript6`(供 ESLint / typescript-eslint API,bin 为 tsc6)
* - `@typescript/native` → `typescript@7`(类型检查 / emit)
*
* 各包 typecheck、.d.ts emit 应走本入口(或 bin `tsc7`),不要依赖 `.bin/tsc` 的链接胜出方。
*/
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";

const require = createRequire(import.meta.url);
const pkgDir = path.dirname(require.resolve("@typescript/native/package.json"));
const tscPath = path.join(pkgDir, "bin", "tsc");
const result = spawnSync(process.execPath, [tscPath, ...process.argv.slice(2)], {
stdio: "inherit",
});
process.exit(result.status === null ? 1 : result.status);

function tryRealpath(filePath) {
try {
return fs.realpathSync.native(filePath);
} catch {
return filePath;
}
}

/** 解析 @typescript/native 包内 tsc 脚本路径 */
export function resolveNativeTsc() {
let pkgJson;
try {
pkgJson = require.resolve("@typescript/native/package.json");
} catch {
throw new Error("未找到 @typescript/native(TypeScript 7)。请在仓库根目录执行 npm install。");
}
return path.join(path.dirname(pkgJson), "bin", "tsc");
}

/**
* 以当前 Node 进程调用 TS7 tsc。
* @param {string[]} args tsc CLI 参数
* @param {{ stdio?: import("node:child_process").StdioOptions }} [opts]
* @returns {number} 进程退出码
*/
export function runTsc7(args, opts = {}) {
const tscPath = resolveNativeTsc();
const result = spawnSync(process.execPath, [tscPath, ...args], {
stdio: opts.stdio ?? "inherit",
});
if (result.error) throw result.error;
return result.status === null ? 1 : result.status;
}

/** 经 node_modules/.bin/tsc7 符号链接调用时也须识别为主入口 */
function isMainModule() {
const entry = process.argv[1];
if (!entry) return false;
const entryReal = tryRealpath(path.resolve(entry));
const selfReal = tryRealpath(fileURLToPath(import.meta.url));
return entryReal === selfReal;
}

if (isMainModule()) {
process.exit(runTsc7(process.argv.slice(2)));
}