Skip to content

Commit

Permalink
Remove rimraf dependency in favour of Node.js's rm method (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed May 8, 2024
1 parent e532c39 commit 346d53f
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 252 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-rockets-invent.md
@@ -0,0 +1,5 @@
---
'sku': patch
---

Remove `rimraf` dependency in favour of Node.js's `rm`
4 changes: 4 additions & 0 deletions .npmrc
Expand Up @@ -6,3 +6,7 @@ public-hoist-pattern[]="*prettier*"
# This bypasses the .pnpm folder that resolveModules looks for
# See https://github.com/seek-oss/sku/blob/275752bd3066e52885d461ef5bcd953aaac3bfff/config/webpack/resolveModules.js
public-hoist-pattern[]="@babel/*"

# `docsify-cli` depends on `docsify` which depends on `opencollective-postinstall` and calls it during `postinstall`.
# For some reason, this call fails on CI, so we need to hoist it.
public-hoist-pattern[]="opencollective-postinstall"
6 changes: 6 additions & 0 deletions fixtures/sku-init/sku-init.test.js
Expand Up @@ -26,6 +26,12 @@ describe('sku init', () => {
it(
'should create a sku.config.ts',
async () => {
const projectName = 'new-project';
await fs.rm(path.join(fixtureDirectory, projectName), {
recursive: true,
force: true,
});

const { child } = await runSkuScriptInDir('init', fixtureDirectory, [
projectName,
]);
Expand Down
6 changes: 5 additions & 1 deletion jest.config.js
Expand Up @@ -3,7 +3,11 @@ module.exports = {
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
},
maxWorkers: process.env.CI ? 2 : undefined,
...(process.env.CI
? {
maxWorkers: 2,
}
: {}),
preset: 'jest-puppeteer',
setupFilesAfterEnv: ['<rootDir>/test-utils/jestSetup.ts'],
snapshotSerializers: [
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -65,7 +65,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
@@ -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
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
@@ -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
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 346d53f

Please sign in to comment.