Skip to content

Commit

Permalink
increase JSON module usage
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 3, 2024
1 parent 8bbe561 commit 1812537
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
5 changes: 1 addition & 4 deletions scripts/generators/archived-libs-typings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import fs from "fs";

const archivedSyntaxPkgs = JSON.parse(
fs.readFileSync(new URL("./archived-syntax-pkgs.json", import.meta.url))
);
import archivedSyntaxPkgs from "./archived-syntax-pkgs.json" with { "type": "json" };
const root = new URL("../..", import.meta.url);

let output = `/* This file is automatically generated by scripts/generators/archived-libs-typings.js */
Expand Down
5 changes: 1 addition & 4 deletions scripts/generators/tsconfig.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import fs from "fs";
import archivedSyntaxPkgs from "./archived-syntax-pkgs.json" with { "type": "json" };

function importJSON(path) {
return JSON.parse(fs.readFileSync(path));
}

const archivedSyntaxPkgs = importJSON(
new URL("./archived-syntax-pkgs.json", import.meta.url)
);

const thirdPartyBabelPlugins = [
"@babel/preset-modules/lib/plugins/transform-async-arrows-in-class",
"@babel/preset-modules/lib/plugins/transform-edge-default-parameters",
Expand Down
11 changes: 3 additions & 8 deletions scripts/integration-tests/utils/bump-babel-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const packageJSONPath = path.resolve(process.cwd(), "./package.json");
const content = JSON.parse(fs.readFileSync(packageJSONPath));
import content from "../../../package.json" with { type: "json" };

function bumpBabelDependency(type, version) {
const dependencies = content[type];
Expand All @@ -20,7 +14,7 @@ function bumpBabelDependency(type, version) {
if (process.argv[2] === "resolutions") {
const resolutions = content.resolutions || {};
for (const name of fs.readdirSync(
path.join(__dirname, "../../../packages")
new URL("../../../packages", import.meta.url)
)) {
if (!name.startsWith("babel-")) continue;
resolutions[name.replace("babel-", "@babel/")] = "*";
Expand All @@ -38,4 +32,5 @@ if (process.argv[2] === "resolutions") {
}
}

const packageJSONPath = new URL("../../../package.json", import.meta.url);
fs.writeFileSync(packageJSONPath, JSON.stringify(content, undefined, 2));
3 changes: 2 additions & 1 deletion scripts/rename-proposal-to-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const oldPackageJSONPath = path.join(oldPackageFolder, "package.json");

console.info("Updating package.json...");
{
const pkgJSON = JSON.parse(fs.readFileSync(oldPackageJSONPath, "utf8"));
const pkgJSON = (await import(oldPackageJSONPath, { with: { type: "json" } }))
.default;
pkgJSON.name = pkgJSON.name.replace(oldName, newName);
pkgJSON.description = pkgJSON.description.replace(
/the ([a-z-]+?)s? proposal/gi,
Expand Down
6 changes: 2 additions & 4 deletions scripts/rollup-plugin-standalone-internals.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import fs from "fs";
import { fileURLToPath } from "url";
import pluginConfig from "../packages/babel-standalone/scripts/pluginConfig.json" with { "type": "json" };

const standaloneURL = new URL("../packages/babel-standalone/", import.meta.url);
const inStandalone = path =>
fileURLToPath(new URL(path, standaloneURL)).replace(/\\/g, "/");
const { noopPlugins, unexposedNoopPlugins } = JSON.parse(
fs.readFileSync(new URL("./scripts/pluginConfig.json", standaloneURL), "utf8")
);
const { noopPlugins, unexposedNoopPlugins } = pluginConfig;

const pluginUtilsID = "@babel/helper-plugin-utils";

Expand Down

0 comments on commit 1812537

Please sign in to comment.