-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
downlevel in a loop, until stabilised
Workaround for sandersn/downlevel-dts#50
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const childProcess = require("child_process"); | ||
const fs = require("fs"); | ||
|
||
const main = () => { | ||
const tempFolder = `temp/downlevel`; | ||
childProcess.execSync(`rm -rf ${tempFolder}`, { stdio: "inherit" }); | ||
fs.mkdirSync(`${tempFolder}`, { recursive: true }); | ||
childProcess.execSync(`cp -r dist ${tempFolder}/0`, { stdio: "inherit" }); | ||
for (let i = 1; i < 10; i++) { | ||
const [prev, next] = [i - 1, i].map(n => `${tempFolder}/${n}`); | ||
console.log(`downleveling into ${next}`); | ||
childProcess.execSync(`downlevel-dts ${prev} ${next} --to=3.4`, { stdio: "inherit" }); | ||
|
||
const [prevResult, nextResult] = [prev, next].map(folder => | ||
fs.readFileSync(`${folder}/generated/interface.d.ts`).toString() | ||
); | ||
if (prevResult === nextResult) { | ||
if (i <= 2) { | ||
throw new Error( | ||
`downleveling stabilised too quickly, maybe https://github.com/sandersn/downlevel-dts/issues/50 has been fixed?` | ||
); | ||
} | ||
const target = `ts34/dist`; | ||
console.log(`downleveling stabilised after ${i} iterations, copying to ${target}.`); | ||
childProcess.execSync(`rm -rf ${target}`, { stdio: "inherit" }); | ||
fs.mkdirSync("ts34", { recursive: true }); | ||
childProcess.execSync(`cp -r ${next} ${target}`, { stdio: "inherit" }); | ||
console.log(`Replacing push implementation incompatible with typescript < 4`); | ||
childProcess.execSync(`mv ${target}/push.ts34.d.ts ${target}/push.d.ts`, { stdio: "inherit" }); | ||
console.log(`Running old version of typescript on output`); | ||
childProcess.execSync(`npx -p [email protected] tsc ts34/dist/index.d.ts --noEmit`, { stdio: "inherit" }); | ||
console.log(`Removing temporary files`); | ||
childProcess.execSync(`rm -rf ${tempFolder}`, { stdio: "inherit" }); | ||
console.log("Done."); | ||
return; | ||
} | ||
console.log({ prev, next }, "had different outputs, running again"); | ||
} | ||
throw new Error(`Downleveling failed!`); | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters