Skip to content

Commit

Permalink
use regexp to extract import sources instead of parsing the code
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbodya committed Mar 2, 2021
1 parent c5ef5d6 commit afd5c7a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@babel/preset-typescript": "^7.13.0",
"@babel/register": "^7.13.0",
"@babel/runtime": "^7.13.7",
"@babel/traverse": "^7.13.0",
"@rollup/plugin-babel": "^5.2.0",
"@rollup/plugin-commonjs": "patch:@rollup/plugin-commonjs@^17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch",
"@rollup/plugin-json": "^4.1.0",
Expand Down
21 changes: 5 additions & 16 deletions scripts/generators/tsconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import fs from "fs";
import { createRequire } from "module";
import { fileURLToPath } from "url";
import globby from "globby";
import * as babel from "@babel/core";
import traverseModule from "@babel/traverse";
const traverse = traverseModule.default;

const require = createRequire(import.meta.url);

Expand Down Expand Up @@ -50,19 +47,11 @@ function sourceDeps(packageDir) {
const filename = path.join(packageDir, file);
const source = fs.readFileSync(filename, { encoding: "utf8" });

const ast = babel.parseSync(source, {
ast: true,
filename,
});

traverse(ast, {
ImportDeclaration(path) {
const importSource = path.node.source.value;
if (importSource.startsWith("@babel/")) {
result.add(importSource);
}
},
});
for (const [importSource] of source.matchAll(
/(?<=from\s*")@babel\/[^"/]+/g
)) {
result.add(importSource);
}
}
return result;
}
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5480,7 +5480,6 @@ __metadata:
"@babel/preset-typescript": ^7.13.0
"@babel/register": ^7.13.0
"@babel/runtime": ^7.13.7
"@babel/traverse": ^7.13.0
"@rollup/plugin-babel": ^5.2.0
"@rollup/plugin-commonjs": "patch:@rollup/plugin-commonjs@^17.1.0#./.yarn/patches/@rollup__plugin-commonjs.patch"
"@rollup/plugin-json": ^4.1.0
Expand Down

0 comments on commit afd5c7a

Please sign in to comment.