@postxl/generator 1.0.11 → 1.1.1

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.
@@ -123,7 +123,7 @@ async function sync({ vfs, lockFilePath, diskFilePath, force }) {
123
123
  const files = await getFilesStates({ vfs, lockFilePath, diskFilePath });
124
124
  // Check for unresolved merge conflicts before writing any files
125
125
  const filesWithConflicts = findFilesWithMergeConflicts(files);
126
- if (filesWithConflicts.length > 0) {
126
+ if (filesWithConflicts.length > 0 && !force) {
127
127
  return {
128
128
  success: false,
129
129
  error: {
@@ -34,8 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.VirtualFileSystem = void 0;
37
- const fs = __importStar(require("fs/promises"));
38
37
  const minimatch_1 = require("minimatch");
38
+ const fs = __importStar(require("node:fs/promises"));
39
39
  const utils_1 = require("@postxl/utils");
40
40
  const fs_utils_1 = require("./fs-utils");
41
41
  const Path = __importStar(require("./path"));
@@ -186,33 +186,54 @@ class VirtualFileSystem {
186
186
  this.#files.set(basePath, content.unwrap());
187
187
  }
188
188
  async #readDirectory({ diskPath, targetPath, filter, recursive, }) {
189
- const entries = await utils_1.Result.fromPromise(() => fs.readdir(diskPath, { withFileTypes: true }), () => `Folder "${diskPath}" does not exist`);
190
- if (entries.isErr()) {
191
- throw new Error(entries.unwrapErr());
192
- }
193
- for (const entry of entries.unwrap()) {
189
+ const entries = await this.#readDirEntries(diskPath);
190
+ for (const entry of entries) {
194
191
  const entryName = Path.normalize(entry.name);
195
192
  const entryPath = Path.join(diskPath, entryName);
196
193
  const relativePath = Path.join(targetPath, entryName);
197
- if (filter && !filter(relativePath)) {
194
+ if (this.#shouldSkipEntry(relativePath, filter)) {
198
195
  continue;
199
196
  }
200
197
  if (recursive && entry.isDirectory()) {
201
- await this.#readDirectory({ diskPath: entryPath, targetPath: relativePath, filter, recursive });
198
+ await this.#processDirectory(entryPath, relativePath, filter, recursive);
202
199
  }
203
200
  else if (entry.isFile()) {
204
- // Skip files that don't match the pattern
205
- if (!this.matchesPattern(relativePath)) {
206
- continue;
207
- }
208
- const content = await (0, fs_utils_1.readFile)(entryPath);
209
- if (content.isErr()) {
210
- throw content.unwrapErr();
211
- }
212
- this.#files.set(relativePath, content.unwrap());
201
+ await this.#processFile(entryPath, relativePath);
213
202
  }
214
203
  }
215
204
  }
205
+ async #readDirEntries(diskPath) {
206
+ const entries = await utils_1.Result.fromPromise(() => fs.readdir(diskPath, { withFileTypes: true }), () => `Folder "${diskPath}" does not exist`);
207
+ if (entries.isErr()) {
208
+ throw new Error(entries.unwrapErr());
209
+ }
210
+ return entries.unwrap();
211
+ }
212
+ #shouldSkipEntry(relativePath, filter) {
213
+ return filter ? !filter(relativePath) : false;
214
+ }
215
+ async #processDirectory(diskPath, relativePath, filter, recursive) {
216
+ await this.#readDirectory({ diskPath, targetPath: relativePath, filter, recursive });
217
+ }
218
+ async #processFile(entryPath, relativePath) {
219
+ if (!this.matchesPattern(relativePath)) {
220
+ return;
221
+ }
222
+ const content = await (0, fs_utils_1.readFile)(entryPath);
223
+ if (content.isErr()) {
224
+ throw content.unwrapErr();
225
+ }
226
+ const finalPath = this.#resolveFinalPath(relativePath);
227
+ this.#files.set(finalPath, content.unwrap());
228
+ }
229
+ #resolveFinalPath(relativePath) {
230
+ // Handle .gitignore.template files: rename them to .gitignore
231
+ // This is necessary because npm/pnpm exclude .gitignore files from published packages
232
+ if (relativePath.endsWith('.gitignore.template')) {
233
+ return relativePath.replace(/\.gitignore\.template$/, '.gitignore');
234
+ }
235
+ return relativePath;
236
+ }
216
237
  /**
217
238
  * Transforms the content of all files using the provided function.
218
239
  * An optional filter function can be provided to select specific files.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "1.0.11",
3
+ "version": "1.1.1",
4
4
  "description": "Core package that orchestrates the code generation of a PXL project",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -46,8 +46,8 @@
46
46
  "jszip": "3.10.1",
47
47
  "minimatch": "^10.1.1",
48
48
  "p-limit": "3.1.0",
49
- "@postxl/schema": "^1.0.3",
50
- "@postxl/utils": "^1.0.1"
49
+ "@postxl/schema": "^1.1.1",
50
+ "@postxl/utils": "^1.1.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/diff": "8.0.0"