convert @babel/standalone to typescript (#13212)

* babel-standalone flowts rename

* babel-standalone flowts convert

* babel-standalone - update rollup plugin to support ts files

* babel-standalone code generation update

* babel-standalone

* babel-standalone eslint fixes

* babel-standalone tsconfig.json

* babel-standalone

* babel-standalone tsconfig related fix

* make generate-tsconfig

* yarn install

* babel-standalone use fs.existsSync

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
Bogdan Savluk
2021-05-14 15:54:09 +02:00
committed by GitHub
parent bb70ea47f5
commit b670c11070
12 changed files with 36 additions and 31 deletions

View File

@@ -29,13 +29,24 @@ export default function () {
typeof packageJson["browser"] === "object"
) {
for (const nodeFile in packageJson["browser"]) {
const browserFile = packageJson["browser"][nodeFile].replace(
const browserFileAsJs = packageJson["browser"][nodeFile].replace(
/^(\.\/)?lib\//,
"src/"
);
const nodeFileSrc = path.normalize(
const browserFileAsTs = browserFileAsJs.replace(/.js$/, ".ts");
const browserFile = fs.existsSync(browserFileAsTs)
? browserFileAsTs
: browserFileAsJs;
const nodeFileSrcAsJs = path.normalize(
nodeFile.replace(/^(\.\/)?lib\//, "src/")
);
const nodeFileSrcAsTs = nodeFileSrcAsJs.replace(/.js$/, ".ts");
const nodeFileSrc = fs.existsSync(nodeFileSrcAsTs)
? nodeFileSrcAsTs
: nodeFileSrcAsJs;
if (id.endsWith(nodeFileSrc)) {
if (browserFile === false) {
return "";
@@ -98,12 +109,7 @@ export default function () {
if (!/\.[a-z]+$/.test(asJS)) asJS += ".js";
const asTS = asJS.replace(/\.js$/, ".ts");
try {
fs.statSync(asTS);
return asTS;
} catch {
return asJS;
}
return fs.existsSync(asTS) ? asTS : asJS;
},
};
}