Skip to content

Commit

Permalink
chore: Update tools
Browse files Browse the repository at this point in the history
  • Loading branch information
nuintun committed Dec 18, 2024
1 parent 90f87c5 commit 884c1ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tools/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

import { rimraf } from 'rimraf';

await rimraf(['cjs', 'esm', 'types']);
await rimraf(['cjs', 'esm']);
18 changes: 9 additions & 9 deletions tools/fix-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ import { readdir, rename } from 'node:fs/promises';

/**
* @function renameDts
* @description Rename `.d.ts` files in a directory to a specified extension
* @param {string} dir The target directory to process
* @param {string} ext The new extension to replace `.d.ts`
* @description Rename `.d.ts` files in a directory to a specified extension.
* @param {string} dir The target directory to process.
* @param {string} ext The new extension to replace `.d.ts`.
* @returns {Promise<void>}
*/
async function renameDts(dir, ext) {
// Stack to manage directories
// Stack to manage directories.
const stack = [dir];

while (stack.length > 0) {
const currentDir = stack.pop();

// Read items in the current directory
// Read items in the current directory.
const items = await readdir(currentDir, { withFileTypes: true });

// Collect all tasks for the current directory
// Collect all tasks for the current directory.
const tasks = items.map(async item => {
const sourcePath = join(currentDir, item.name);

if (item.isDirectory()) {
// If it's a directory, push it onto the stack
// If it's a directory, push it onto the stack.
stack.push(sourcePath);
} else if (item.isFile()) {
const re = /\.d\.ts$/i;

// If the file matches `.d.ts`, rename it
// If the file matches `.d.ts`, rename it.
if (re.test(sourcePath)) {
const targetPath = sourcePath.replace(re, ext);

Expand All @@ -42,7 +42,7 @@ async function renameDts(dir, ext) {
}
});

// Process all tasks concurrently for the current directory
// Process all tasks concurrently for the current directory.
await Promise.all(tasks);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/plugins/tree-shake.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MagicString from 'magic-string';

/***
* @function treeShake
* @description Fixed tree shaking for typescript and rollup preserve modules
* @description Fixed tree shaking for typescript and rollup preserve modules.
* @return {import('rollup').Plugin}
*/
export default function treeShake() {
Expand Down
6 changes: 3 additions & 3 deletions tools/rollup.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { createRequire, isBuiltin } from 'node:module';
const pkg = createRequire(import.meta.url)('../package.json');

const externals = [
// Dependencies
// Dependencies.
...Object.keys(pkg.dependencies || {}),
// Peer dependencies
// Peer dependencies.
...Object.keys(pkg.peerDependencies || {})
];

Expand Down Expand Up @@ -41,7 +41,7 @@ function env() {

/**
* @function rollup
* @param {boolean} [esnext]
* @param {boolean} [esnext] Is esnext.
* @return {import('rollup').RollupOptions}
*/
export default function rollup(esnext) {
Expand Down

0 comments on commit 884c1ca

Please sign in to comment.