Skip to content

Commit

Permalink
tests: updated env tests for TypeScript 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Oct 11, 2023
1 parent 3a73c56 commit 4772915
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions testcases/test-env/test-tsc/prepare.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ function replace(filename, key, value) {
fs.writeFileSync(filename, data);
}

// moduleResolution: node, node16, nodenext
replace("tsconfig.json", "${TS_MODULE_RESOLUTION}", process.argv[2]);
// TypeScript moduleResolution: node, node16, nodenext
const tsModuleResolution = process.argv[2];

// module: commonjs, es2020
replace("tsconfig.json", "${TS_MODULE}", process.argv[3]);
// Package module: commonjs, es2020
const pModule = process.argv[3];

// type: commonjs, module
const type = (process.argv[3] === "commonjs") ? "commonjs": "module";
replace("package.json", "${PKG_TYPE}", type);
// TypeScript module: node=pModule, otherwise=pModuleResolution
const tsModule = ({
node16: "node16",
nodenext: "nodenext"
})[pModuleResolution] || pModule;

// Package type: commonjs, module
const pType = (pModule === "commonjs") ? "commonjs": "module";


// Replace necessary properties in tsconfig.json and package.json
replace("tsconfig.json", "${TS_MODULE_RESOLUTION}", tsModuleResolution);
replace("tsconfig.json", "${TS_MODULE}", tsModule);
replace("package.json", "${PKG_TYPE}", pType);

// JavaScript
fs.writeFileSync("index.ts", fs.readFileSync("js-" + type + ".ts"));
fs.writeFileSync("index.ts", fs.readFileSync("js-" + pType + ".ts"));

0 comments on commit 4772915

Please sign in to comment.