@reliverse/dler 1.7.8 → 1.7.9
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.
|
@@ -186,6 +186,8 @@ export async function writeFileSafe(filePath, content, reason) {
|
|
|
186
186
|
export async function copyInsteadOfBuild(rootDir, outDir, patterns) {
|
|
187
187
|
if (!patterns.length) return;
|
|
188
188
|
relinka("info", "Copying files/folders that should not be built...");
|
|
189
|
+
const normalizedRootDir = path.normalize(rootDir);
|
|
190
|
+
const normalizedOutDir = path.normalize(outDir);
|
|
189
191
|
const SENSITIVE_PATTERNS = [
|
|
190
192
|
"node_modules",
|
|
191
193
|
".git",
|
|
@@ -209,29 +211,64 @@ export async function copyInsteadOfBuild(rootDir, outDir, patterns) {
|
|
|
209
211
|
const RETRY_DELAY = 1e3;
|
|
210
212
|
async function copyWithRetry(source, dest, relativePath, retryCount = 0) {
|
|
211
213
|
try {
|
|
212
|
-
|
|
214
|
+
const normalizedSource = path.normalize(source);
|
|
215
|
+
const normalizedDest = path.normalize(dest);
|
|
216
|
+
if (!normalizedSource || !normalizedDest) {
|
|
217
|
+
throw new Error(`Invalid paths: source=${normalizedSource}, dest=${normalizedDest}`);
|
|
218
|
+
}
|
|
219
|
+
const destDir = path.dirname(normalizedDest);
|
|
220
|
+
try {
|
|
221
|
+
await fs.mkdir(destDir, { recursive: true });
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (error.code !== "EEXIST") {
|
|
224
|
+
throw new Error(`Failed to create directory ${destDir}: ${error.message}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
213
227
|
try {
|
|
214
|
-
await fs.access(
|
|
215
|
-
} catch {
|
|
216
|
-
relinka("warn", `Source not accessible: ${relativePath}`);
|
|
228
|
+
await fs.access(normalizedSource);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
relinka("warn", `Source not accessible: ${relativePath} (${error.message})`);
|
|
217
231
|
return;
|
|
218
232
|
}
|
|
219
|
-
if (await fs.pathExists(
|
|
220
|
-
|
|
221
|
-
|
|
233
|
+
if (await fs.pathExists(normalizedDest)) {
|
|
234
|
+
try {
|
|
235
|
+
relinka("verbose", `Removing existing destination: ${normalizedDest}`);
|
|
236
|
+
await fs.remove(normalizedDest);
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (error.code === "EBUSY" && retryCount < MAX_RETRIES) {
|
|
239
|
+
relinka("warn", `Destination ${normalizedDest} is busy, retrying in ${RETRY_DELAY}ms`);
|
|
240
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
|
241
|
+
return copyWithRetry(normalizedSource, normalizedDest, relativePath, retryCount + 1);
|
|
242
|
+
}
|
|
243
|
+
throw new Error(
|
|
244
|
+
`Failed to remove existing destination ${normalizedDest}: ${error.message}`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
await fs.cp(normalizedSource, normalizedDest, {
|
|
250
|
+
recursive: true,
|
|
251
|
+
dereference: true,
|
|
252
|
+
force: true,
|
|
253
|
+
errorOnExist: false
|
|
254
|
+
});
|
|
255
|
+
relinka("verbose", `Copied instead of building: ${relativePath}`);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (error.code === "EBUSY" && retryCount < MAX_RETRIES) {
|
|
258
|
+
relinka(
|
|
259
|
+
"warn",
|
|
260
|
+
`File ${relativePath} is busy, retrying in ${RETRY_DELAY}ms (attempt ${retryCount + 1}/${MAX_RETRIES})`
|
|
261
|
+
);
|
|
262
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
|
263
|
+
return copyWithRetry(normalizedSource, normalizedDest, relativePath, retryCount + 1);
|
|
264
|
+
}
|
|
265
|
+
throw new Error(`Failed to copy ${relativePath}: ${error.message}`);
|
|
222
266
|
}
|
|
223
|
-
await fs.cp(source, dest, {
|
|
224
|
-
recursive: true,
|
|
225
|
-
dereference: true,
|
|
226
|
-
force: true,
|
|
227
|
-
errorOnExist: false
|
|
228
|
-
});
|
|
229
|
-
relinka("verbose", `Copied instead of building: ${relativePath}`);
|
|
230
267
|
} catch (error) {
|
|
231
|
-
if (
|
|
268
|
+
if (retryCount < MAX_RETRIES) {
|
|
232
269
|
relinka(
|
|
233
270
|
"warn",
|
|
234
|
-
`
|
|
271
|
+
`Error copying ${relativePath}, retrying in ${RETRY_DELAY}ms (attempt ${retryCount + 1}/${MAX_RETRIES}): ${error.message}`
|
|
235
272
|
);
|
|
236
273
|
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
|
237
274
|
return copyWithRetry(source, dest, relativePath, retryCount + 1);
|
|
@@ -245,21 +282,29 @@ export async function copyInsteadOfBuild(rootDir, outDir, patterns) {
|
|
|
245
282
|
const batchPatterns = filteredPatterns.slice(i, i + BATCH_SIZE);
|
|
246
283
|
const batchCopyTasks = [];
|
|
247
284
|
for (const pattern of batchPatterns) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
285
|
+
try {
|
|
286
|
+
const matches = await glob(pattern, {
|
|
287
|
+
cwd: normalizedRootDir,
|
|
288
|
+
dot: true,
|
|
289
|
+
absolute: true,
|
|
290
|
+
onlyFiles: false,
|
|
291
|
+
followSymbolicLinks: false
|
|
292
|
+
});
|
|
293
|
+
for (const match of matches) {
|
|
294
|
+
const relativePath = path.relative(normalizedRootDir, match);
|
|
295
|
+
const destPath = path.resolve(normalizedOutDir, relativePath);
|
|
296
|
+
batchCopyTasks.push(copyWithRetry(match, destPath, relativePath));
|
|
297
|
+
}
|
|
298
|
+
} catch (error) {
|
|
299
|
+
relinka("error", `Failed to process pattern ${pattern}: ${error.message}`);
|
|
259
300
|
}
|
|
260
301
|
}
|
|
261
302
|
if (batchCopyTasks.length > 0) {
|
|
262
|
-
|
|
303
|
+
try {
|
|
304
|
+
await Promise.all(batchCopyTasks);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
relinka("error", `Batch processing failed: ${error.message}`);
|
|
307
|
+
}
|
|
263
308
|
if (i + BATCH_SIZE < filteredPatterns.length) {
|
|
264
309
|
await new Promise((resolve) => setTimeout(resolve, BATCH_DELAY));
|
|
265
310
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"@reliverse/pathkit": "^1.2.1",
|
|
5
5
|
"@reliverse/reglob": "^1.0.0",
|
|
6
6
|
"@reliverse/relico": "^1.1.2",
|
|
7
|
-
"@reliverse/relifso": "^1.4.
|
|
7
|
+
"@reliverse/relifso": "^1.4.5",
|
|
8
8
|
"@reliverse/relinka": "^1.4.7",
|
|
9
9
|
"@reliverse/rempts": "^1.7.17",
|
|
10
10
|
"@rollup/plugin-alias": "^5.1.1",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"name": "@reliverse/dler",
|
|
46
46
|
"type": "module",
|
|
47
|
-
"version": "1.7.
|
|
47
|
+
"version": "1.7.9",
|
|
48
48
|
"keywords": [
|
|
49
49
|
"reliverse",
|
|
50
50
|
"cli",
|