@batijs/build 0.0.249 → 0.0.252

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +15 -3
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  import { existsSync } from "node:fs";
3
- import { mkdir, opendir, rm, writeFile } from "node:fs/promises";
3
+ import { mkdir, opendir, rm, rmdir, writeFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import "@batijs/core";
6
6
 
@@ -193,7 +193,7 @@ async function safeWriteFile(destination, content) {
193
193
  });
194
194
  await writeFile(destination, content, { encoding: "utf-8" });
195
195
  }
196
- async function safeRmFile(destination) {
196
+ async function safeRmFile(destination, options) {
197
197
  try {
198
198
  await rm(destination, {
199
199
  force: true,
@@ -201,6 +201,15 @@ async function safeRmFile(destination) {
201
201
  recursive: false,
202
202
  retryDelay: 150
203
203
  });
204
+ if (options?.removeEmptyDir) {
205
+ try {
206
+ await rmdir(path.dirname(destination), {
207
+ maxRetries: 3,
208
+ retryDelay: 150
209
+ });
210
+ } catch {
211
+ }
212
+ }
204
213
  } catch {
205
214
  console.warn(`Failed to remove unecessary file: ${destination}`);
206
215
  }
@@ -299,6 +308,9 @@ Please report this issue to https://github.com/vikejs/bati`
299
308
  if (report.content) {
300
309
  await safeWriteFile(op.destination, report.content.trimStart());
301
310
  }
311
+ if (report.context?.flags.has("include-if-imported")) {
312
+ filesContainingIncludeIfImported.add(op.destinationAbsolute);
313
+ }
302
314
  previousOp = {
303
315
  ...op,
304
316
  ...report
@@ -306,7 +318,7 @@ Please report this issue to https://github.com/vikejs/bati`
306
318
  }
307
319
  for (const target of filesContainingIncludeIfImported) {
308
320
  if (!allImports.has(target)) {
309
- await safeRmFile(target);
321
+ await safeRmFile(target, { removeEmptyDir: true });
310
322
  }
311
323
  }
312
324
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batijs/build",
3
- "version": "0.0.249",
3
+ "version": "0.0.252",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -10,10 +10,10 @@
10
10
  "devDependencies": {
11
11
  "@types/node": "^18.19.14",
12
12
  "tsup": "^8.2.4",
13
- "@batijs/compile": "0.0.249"
13
+ "@batijs/compile": "0.0.252"
14
14
  },
15
15
  "dependencies": {
16
- "@batijs/core": "0.0.249"
16
+ "@batijs/core": "0.0.252"
17
17
  },
18
18
  "main": "./dist/index.js",
19
19
  "module": "./dist/index.js",