Skip to content

Commit

Permalink
Remove empty-dir dependency and add our own implementation (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Mar 21, 2024
1 parent ba918f5 commit cc5750f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-hats-live.md
@@ -0,0 +1,5 @@
---
'sku': patch
---

Remove `empty-dir` dependency
20 changes: 20 additions & 0 deletions packages/sku/lib/isEmptyDir.js
@@ -0,0 +1,20 @@
const { statSync, readdirSync } = require('node:fs');

/**
* Returns whether the given directory is empty, throwing if the path is not a directory
* @typedef {import('fs').PathLike} PathLike
* @param {PathLike} path A path to a directory
*/
const isEmptyDir = (path) => {
const isDirectory = statSync(path).isDirectory();

if (!isDirectory) {
throw new Error(`${path} is not a directory`);
}

const files = readdirSync(path);

return files.length === 0;
};

module.exports = { isEmptyDir };
1 change: 0 additions & 1 deletion packages/sku/package.json
Expand Up @@ -77,7 +77,6 @@
"dedent": "^1.5.1",
"didyoumean2": "^6.0.1",
"ejs": "^3.1.8",
"empty-dir": "^3.0.0",
"ensure-gitignore": "^1.1.2",
"env-ci": "^7.0.0",
"esbuild": "^0.19.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/sku/scripts/init.js
Expand Up @@ -10,7 +10,7 @@ const {
const chalk = require('chalk');
const fs = require('node:fs/promises');
const { posix: path } = require('node:path');
const emptyDir = require('empty-dir');
const { isEmptyDir } = require('../lib/isEmptyDir');
const validatePackageName = require('validate-npm-package-name');
const dedent = require('dedent');
const { setCwd } = require('../lib/cwd');
Expand Down Expand Up @@ -125,7 +125,7 @@ const getTemplateFileDestinationFromRoot =

await fs.mkdir(projectName, { recursive: true });

if (!emptyDir.sync(root)) {
if (!isEmptyDir(root)) {
console.log(`The directory ${chalk.green(projectName)} is not empty.`);
process.exit(1);
}
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc5750f

Please sign in to comment.