Skip to content

Commit

Permalink
chore(build): update build scripts to resolve side-effects in modules (
Browse files Browse the repository at this point in the history
…#267)

* remove module packages

* update build scripts
  • Loading branch information
mimshins authored Nov 18, 2024
1 parent d495856 commit d9af291
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 159 deletions.
5 changes: 2 additions & 3 deletions packages/icons/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as fs from "node:fs/promises";
import * as path from "node:path";
import { promisify } from "node:util";
import {
createModulePackages,
ensureDirExists,
getFileMeta,
toPascalCase,
Expand Down Expand Up @@ -84,7 +83,9 @@ const extractPathsInfo = (svgData: string) => {
const generatePaths = async () => {
console.log("🧩 generating paths...");

await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await ensureDirExists(distDir);

await fs.writeFile(pathsJSONFile, "{", { encoding: "utf-8" });

const svgs = await globAsync(path.join(iconsDir, "**/*.svg"));
Expand Down Expand Up @@ -134,9 +135,7 @@ const generatePaths = async () => {

void (async () => {
console.time("build");
await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await generatePaths();
await createModulePackages(distDir);
console.timeEnd("build");
})();
/* eslint-enable no-console */
5 changes: 3 additions & 2 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
}
},
"scripts": {
"clear": "shx rm -rf dist",
"generate": "tsx ./scripts/generate.ts",
"prebuild": "pnpm generate",
"build": "tsx ./scripts/build.ts",
"prebuild": "run-p clear generate",
"build": "tsc --project ./tsconfig.build.json",
"prerelease": "pnpm build",
"release": "pnpm publish . --tag latest --access public"
},
Expand Down
37 changes: 0 additions & 37 deletions packages/react-components/scripts/build.ts

This file was deleted.

9 changes: 2 additions & 7 deletions packages/react-icons/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { exec } from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { promisify } from "node:util";
import {
createModulePackages,
ensureDirExists,
getFileMeta,
} from "../../../scripts/utils";
import { ensureDirExists, getFileMeta } from "../../../scripts/utils";

const execCmd = promisify(exec);

Expand All @@ -26,6 +22,7 @@ const baseIconFile = path.join(packageDir, "src/base-icon.tsx");
const generateComponents = async () => {
console.log("🧩 generating react icons...");

await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await ensureDirExists(distDir);

const iconTemplateStr = await fs.readFile(iconTemplate, {
Expand Down Expand Up @@ -89,9 +86,7 @@ const generateComponents = async () => {

void (async () => {
console.time("build");
await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await generateComponents();
await createModulePackages(distDir);
console.timeEnd("build");
})();
/* eslint-enable no-console */
7 changes: 5 additions & 2 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
}
},
"scripts": {
"build": "tsx ./scripts/build.ts",
"dev": "tsx ./scripts/dev.ts",
"clear": "shx rm -rf dist",
"prebuild": "pnpm run clear",
"build": "tsc --project ./tsconfig.build.json",
"predev": "pnpm run clear",
"dev": "tsc --watch --project ./tsconfig.dev.json",
"release": "pnpm publish . --tag latest --access public"
},
"dependencies": {
Expand Down
24 changes: 0 additions & 24 deletions packages/web-components/scripts/build.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/web-components/scripts/dev.ts

This file was deleted.

29 changes: 0 additions & 29 deletions packages/web-components/scripts/transpile.ts

This file was deleted.

9 changes: 2 additions & 7 deletions packages/web-icons/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { exec } from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { promisify } from "node:util";
import {
createModulePackages,
ensureDirExists,
getFileMeta,
} from "../../../scripts/utils";
import { ensureDirExists, getFileMeta } from "../../../scripts/utils";

const execCmd = promisify(exec);

Expand All @@ -26,6 +22,7 @@ const baseIconFile = path.join(packageDir, "src/base-icon.ts");
const generateComponents = async () => {
console.log("🧩 generating web icons...");

await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await ensureDirExists(distDir);

const iconTemplateStr = await fs.readFile(iconTemplate, {
Expand Down Expand Up @@ -90,9 +87,7 @@ const generateComponents = async () => {

void (async () => {
console.time("build");
await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await generateComponents();
await createModulePackages(distDir);
console.timeEnd("build");
})();
/* eslint-enable no-console */
32 changes: 0 additions & 32 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */
import glob from "fast-glob";
import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
Expand Down Expand Up @@ -31,40 +29,10 @@ export const getFileMeta = (fileURL: string | URL) => {
return { filename: __filename, dirname: __dirname };
};

export const createModulePackages = async (distDir: string) => {
console.log("🔧 creating module packages...");

const moduleDirs = glob
.sync(path.join(distDir, "**/index.js"))
.map(p => path.dirname(p));

const promises = moduleDirs.map(async moduleDir => {
const typesPath = path.join(moduleDir, "index.d.ts");
const packageJSONPath = path.join(moduleDir, "package.json");

return fs.promises.writeFile(
packageJSONPath,
JSON.stringify(
{
sideEffects: false,
types: fileExists(typesPath) ? "./index.d.ts" : undefined,
main: "./index.js",
},
null,
2,
),
);
});

await Promise.all(promises);
console.log("✅ module packages created.");
};

export const toPascalCase = (str: string, splitRegex: RegExp | string) => {
const baseCase = str.split(splitRegex);

return baseCase
.map(part => part.charAt(0).toUpperCase() + part.substring(1))
.join("");
};
/* eslint-enable no-console */

0 comments on commit d9af291

Please sign in to comment.