mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 14:05:47 -05:00
"Annotate" exported object to fix named / namespace imports of our API in Node ESM (#57133)
This commit is contained in:
@@ -5,31 +5,37 @@ import {
|
||||
__importDefault,
|
||||
__importStar,
|
||||
} from "tslib";
|
||||
import {
|
||||
pathToFileURL,
|
||||
} from "url";
|
||||
|
||||
// This script tests that TypeScript's CJS API is structured
|
||||
// as expected. It calls "require" as though it were in CWD,
|
||||
// so it can be tested on a separate install of TypeScript.
|
||||
|
||||
const require = createRequire(process.cwd() + "/index.js");
|
||||
const typescript = process.argv[2];
|
||||
const resolvedTypeScript = pathToFileURL(require.resolve(typescript)).toString();
|
||||
|
||||
console.log(`Testing ${process.argv[2]}...`);
|
||||
const ts = require(process.argv[2]);
|
||||
console.log(`Testing ${typescript}...`);
|
||||
|
||||
// See: https://github.com/microsoft/TypeScript/pull/51474#issuecomment-1310871623
|
||||
/** @type {[fn: (() => any), shouldSucceed: boolean][]} */
|
||||
/** @type {[fn: (() => Promise<any>), shouldSucceed: boolean][]} */
|
||||
const fns = [
|
||||
[() => ts.version, true],
|
||||
[() => ts.default.version, false],
|
||||
[() => __importDefault(ts).version, false],
|
||||
[() => __importDefault(ts).default.version, true],
|
||||
[() => __importStar(ts).version, true],
|
||||
[() => __importStar(ts).default.version, true],
|
||||
[() => require(typescript).version, true],
|
||||
[() => require(typescript).default.version, false],
|
||||
[() => __importDefault(require(typescript)).version, false],
|
||||
[() => __importDefault(require(typescript)).default.version, true],
|
||||
[() => __importStar(require(typescript)).version, true],
|
||||
[() => __importStar(require(typescript)).default.version, true],
|
||||
[async () => (await import(resolvedTypeScript)).version, true],
|
||||
[async () => (await import(resolvedTypeScript)).default.version, true],
|
||||
];
|
||||
|
||||
for (const [fn, shouldSucceed] of fns) {
|
||||
let success = false;
|
||||
try {
|
||||
success = !!fn();
|
||||
success = !!(await fn());
|
||||
}
|
||||
catch {
|
||||
// Ignore
|
||||
@@ -43,4 +49,10 @@ for (const [fn, shouldSucceed] of fns) {
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
console.log("ok");
|
||||
|
||||
if (process.exitCode) {
|
||||
console.log("fail");
|
||||
}
|
||||
else {
|
||||
console.log("ok");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user