Skip to content

Commit

Permalink
Remove rimraf dependency in favour of Node.js's rm
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed May 7, 2024
1 parent 111c591 commit 3a0569f
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 206 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-rockets-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sku': patch
---

Remove `rimraf` dependency in favour of Node.js's `rm`
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"prettier": "^2.8.8",
"puppeteer": "^21.6.0",
"renovate-config-seek": "^0.4.0",
"rimraf": "^5.0.0",
"typescript": "*"
},
"volta": {
Expand Down
21 changes: 15 additions & 6 deletions packages/sku/lib/buildFileUtils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// @ts-check
const path = require('node:path');
const fs = require('node:fs/promises');
const { rimraf } = require('rimraf');
const { fdir: Fdir } = require('fdir');

const { paths } = require('../context');
const exists = require('./exists');
const copyDirContents = require('./copyDirContents');

const cleanTargetDirectory = () => rimraf(`${paths.target}/*`, { glob: true });
const cleanTargetDirectory = async () => {
fs.rm(paths.target, { recursive: true, force: true });
};

const copyPublicFiles = async () => {
if (await exists(paths.public)) {
Expand All @@ -19,14 +21,21 @@ const ensureTargetDirectory = async () => {
await fs.mkdir(paths.target, { recursive: true });
};

const cleanRenderJs = async () => {
const renderFileGlob = path.join(paths.target, '*render.js');
await rimraf(renderFileGlob, { glob: true });
const cleanStaticRenderEntry = async () => {
const files = await new Fdir()
.withBasePath()
.filter((file) => file.endsWith('render.js'))
.crawl(paths.target)
.withPromise();

for (const file of files) {
await fs.rm(file);
}
};

module.exports = {
cleanTargetDirectory,
copyPublicFiles,
ensureTargetDirectory,
cleanRenderJs,
cleanStaticRenderEntry,
};
1 change: 0 additions & 1 deletion packages/sku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"prettier": "^2.8.8",
"pretty-ms": "^7.0.1",
"react-refresh": "^0.14.0",
"rimraf": "^5.0.0",
"selfsigned": "^2.1.1",
"semver": "^7.3.4",
"serialize-javascript": "^6.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/sku/scripts/build-storybook.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// First, ensure the build is running in production mode
process.env.NODE_ENV = 'production';

const { rimraf } = require('rimraf');
const { rm } = require('node:fs/promises');
const { argv, config } = require('../config/args');
const gracefulSpawn = require('../lib/gracefulSpawn');
const { storybookTarget } = require('../context');
Expand All @@ -11,7 +11,7 @@ const { setUpStorybookConfigDirectory } = require('../lib/storybook');

(async () => {
await runVocabCompile();
await rimraf(storybookTarget);
await rm(storybookTarget, { recursive: true, force: true });
await setUpStorybookConfigDirectory();

argv.push('build');
Expand Down
4 changes: 2 additions & 2 deletions packages/sku/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
copyPublicFiles,
cleanTargetDirectory,
ensureTargetDirectory,
cleanRenderJs,
cleanStaticRenderEntry,
} = require('../lib/buildFileUtils');
const { run } = require('../lib/runWebpack');
const createHtmlRenderPlugin = require('../config/webpack/plugins/createHtmlRenderPlugin');
Expand All @@ -31,7 +31,7 @@ const { runVocabCompile } = require('../lib/runVocab');
}),
),
);
await cleanRenderJs();
await cleanStaticRenderEntry();
await copyPublicFiles();

const timeTaken = performance.now();
Expand Down

0 comments on commit 3a0569f

Please sign in to comment.