@intlayer/chokidar 7.5.12 → 7.5.14
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.
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -1
- package/dist/cjs/cleanOutputDir.cjs.map +1 -1
- package/dist/cjs/cleanRemovedContentDeclaration.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
- package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/createType/createType.cjs.map +1 -1
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +2 -0
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileMoved.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/init/index.cjs +1 -1
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/listGitFiles.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -1
- package/dist/cjs/transformFiles/transformFiles.cjs.map +1 -1
- package/dist/cjs/utils/chunkJSON.cjs.map +1 -1
- package/dist/cjs/utils/getFormatFromExtension.cjs +3 -0
- package/dist/cjs/utils/getFormatFromExtension.cjs.map +1 -1
- package/dist/cjs/utils/pLimit.cjs.map +1 -1
- package/dist/cjs/utils/parallelizeGlobal.cjs.map +1 -1
- package/dist/cjs/utils/reduceObjectFormat.cjs.map +1 -1
- package/dist/cjs/utils/resolveObjectPromises.cjs.map +1 -1
- package/dist/cjs/utils/runOnce.cjs +13 -6
- package/dist/cjs/utils/runOnce.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/bin.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/index.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/pidTree.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/ps.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/runTask.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/wmic.cjs.map +1 -1
- package/dist/cjs/watcher.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs +21 -17
- package/dist/cjs/writeContentDeclaration/detectFormatCommand.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/index.cjs +2 -0
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs +77 -0
- package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs.map +1 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +10 -0
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +1 -1
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs.map +1 -1
- package/dist/esm/cleanRemovedContentDeclaration.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -1
- package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/createType/createType.mjs.map +1 -1
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +2 -0
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileMoved.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/init/index.mjs +1 -1
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/listGitFiles.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/log.mjs.map +1 -1
- package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -1
- package/dist/esm/transformFiles/transformFiles.mjs.map +1 -1
- package/dist/esm/utils/chunkJSON.mjs.map +1 -1
- package/dist/esm/utils/getFormatFromExtension.mjs +3 -0
- package/dist/esm/utils/getFormatFromExtension.mjs.map +1 -1
- package/dist/esm/utils/pLimit.mjs.map +1 -1
- package/dist/esm/utils/parallelizeGlobal.mjs.map +1 -1
- package/dist/esm/utils/reduceObjectFormat.mjs.map +1 -1
- package/dist/esm/utils/resolveObjectPromises.mjs.map +1 -1
- package/dist/esm/utils/runOnce.mjs +13 -6
- package/dist/esm/utils/runOnce.mjs.map +1 -1
- package/dist/esm/utils/runParallel/bin.mjs.map +1 -1
- package/dist/esm/utils/runParallel/index.mjs.map +1 -1
- package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -1
- package/dist/esm/utils/runParallel/ps.mjs.map +1 -1
- package/dist/esm/utils/runParallel/runTask.mjs.map +1 -1
- package/dist/esm/utils/runParallel/wmic.mjs.map +1 -1
- package/dist/esm/watcher.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs +21 -17
- package/dist/esm/writeContentDeclaration/detectFormatCommand.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/index.mjs +2 -1
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/transformJSONFile.mjs +76 -0
- package/dist/esm/writeContentDeclaration/transformJSONFile.mjs.map +1 -0
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +11 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +1 -1
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
- package/dist/types/formatDictionary.d.ts +15 -15
- package/dist/types/index.d.ts +1 -1
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
- package/dist/types/utils/getFormatFromExtension.d.ts +2 -2
- package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
- package/dist/types/utils/runOnce.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/detectFormatCommand.d.ts +1 -1
- package/dist/types/writeContentDeclaration/detectFormatCommand.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/index.d.ts +2 -1
- package/dist/types/writeContentDeclaration/transformJSONFile.d.ts +7 -0
- package/dist/types/writeContentDeclaration/transformJSONFile.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reduceObjectFormat.mjs","names":[
|
|
1
|
+
{"version":3,"file":"reduceObjectFormat.mjs","names":[],"sources":["../../../src/utils/reduceObjectFormat.ts"],"sourcesContent":["type Primitive = string | number | boolean | null | undefined;\n\ntype Recursive = Primitive | { [key: string]: Recursive } | Array<Recursive>;\n\n/**\n * Reduce an object to only the shape provided by a format object.\n * Values are always taken from the source object; the format is used only for structure.\n *\n * Examples:\n * reduceObjectFormat({ a: 1, b: 2 }, { a: 0 }) => { a: 1 }\n * reduceObjectFormat({ a: { x: 1, y: 2 } }, { a: { x: 0 } }) => { a: { x: 1 } }\n */\nexport const reduceObjectFormat = (\n source: Recursive,\n format: Recursive\n): Recursive => {\n // If the format is an array, reduce each element by its counterpart in source\n if (Array.isArray(format)) {\n const sourceArray = Array.isArray(source) ? source : [];\n return format.map((formatItem, index) =>\n reduceObjectFormat(sourceArray[index], formatItem)\n );\n }\n\n // If the format is an object (and not null), pick matching keys and recurse\n if (typeof format === 'object' && format !== null) {\n const result: Record<string, Recursive> = {};\n const sourceObject =\n typeof source === 'object' && source !== null && !Array.isArray(source)\n ? (source as Record<string, Recursive>)\n : ({} as Record<string, Recursive>);\n\n for (const key of Object.keys(format)) {\n const nextSource = sourceObject[key];\n const nextFormat = (format as Record<string, Recursive>)[key];\n result[key] = reduceObjectFormat(nextSource, nextFormat);\n }\n return result;\n }\n\n // For primitives in the format, simply return the source value (can be undefined)\n return source as Primitive;\n};\n"],"mappings":";;;;;;;;;AAYA,MAAa,sBACX,QACA,WACc;AAEd,KAAI,MAAM,QAAQ,OAAO,EAAE;EACzB,MAAM,cAAc,MAAM,QAAQ,OAAO,GAAG,SAAS,EAAE;AACvD,SAAO,OAAO,KAAK,YAAY,UAC7B,mBAAmB,YAAY,QAAQ,WAAW,CACnD;;AAIH,KAAI,OAAO,WAAW,YAAY,WAAW,MAAM;EACjD,MAAM,SAAoC,EAAE;EAC5C,MAAM,eACJ,OAAO,WAAW,YAAY,WAAW,QAAQ,CAAC,MAAM,QAAQ,OAAO,GAClE,SACA,EAAE;AAET,OAAK,MAAM,OAAO,OAAO,KAAK,OAAO,EAAE;GACrC,MAAM,aAAa,aAAa;GAChC,MAAM,aAAc,OAAqC;AACzD,UAAO,OAAO,mBAAmB,YAAY,WAAW;;AAE1D,SAAO;;AAIT,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveObjectPromises.mjs","names":[
|
|
1
|
+
{"version":3,"file":"resolveObjectPromises.mjs","names":[],"sources":["../../../src/utils/resolveObjectPromises.ts"],"sourcesContent":["/**\n * A more \"unified\" approach where each type (function, array, object, primitive)\n * is handled inside the main recursive body.\n */\nexport const resolveObjectPromises = async <T = unknown>(\n entry: any\n): Promise<T> => {\n // Check if entry is a Promise (Thenable)\n if (entry && typeof entry.then === 'function') {\n const awaited = await entry;\n return resolveObjectPromises(awaited);\n }\n\n // If entry is a function, invoke it and process the result\n if (typeof entry === 'function') {\n const result = entry();\n return resolveObjectPromises(result);\n }\n\n if (Array.isArray(entry)) {\n return Promise.all(\n entry.map(async (item) => resolveObjectPromises(item))\n ) as unknown as T;\n }\n\n // Handle plain objects (but not arrays)\n if (entry && typeof entry === 'object') {\n // Arrays are handled in the `Array.isArray` branch above, so we know `entry` is a plain object here.\n\n const result: Record<string, any> = {};\n\n // Iterate over keys **sequentially** to make sure the insertion order of the\n // resulting object matches the original key order. Using `Promise.all` here\n // could lead to out-of-order insertions when asynchronous resolutions\n // finish at different times.\n for (const key of Object.keys(entry)) {\n result[key] = await resolveObjectPromises(entry[key]);\n }\n\n return result as T;\n }\n\n return entry as T;\n};\n"],"mappings":";;;;;AAIA,MAAa,wBAAwB,OACnC,UACe;AAEf,KAAI,SAAS,OAAO,MAAM,SAAS,WAEjC,QAAO,sBADS,MAAM,MACe;AAIvC,KAAI,OAAO,UAAU,WAEnB,QAAO,sBADQ,OAAO,CACc;AAGtC,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,QAAQ,IACb,MAAM,IAAI,OAAO,SAAS,sBAAsB,KAAK,CAAC,CACvD;AAIH,KAAI,SAAS,OAAO,UAAU,UAAU;EAGtC,MAAM,SAA8B,EAAE;AAMtC,OAAK,MAAM,OAAO,OAAO,KAAK,MAAM,CAClC,QAAO,OAAO,MAAM,sBAAsB,MAAM,KAAK;AAGvD,SAAO;;AAGT,QAAO"}
|
|
@@ -5,15 +5,22 @@ import packageJson from "@intlayer/core/package.json" with { type: "json" };
|
|
|
5
5
|
//#region src/utils/runOnce.ts
|
|
6
6
|
const DEFAULT_RUN_ONCE_OPTIONS = { cacheTimeoutMs: 60 * 1e3 };
|
|
7
7
|
const writeSentinelFile = async (sentinelFilePath, currentTimestamp) => {
|
|
8
|
+
const data = {
|
|
9
|
+
version: packageJson.version,
|
|
10
|
+
timestamp: currentTimestamp
|
|
11
|
+
};
|
|
8
12
|
try {
|
|
9
13
|
await mkdir(dirname(sentinelFilePath), { recursive: true });
|
|
10
|
-
const data = {
|
|
11
|
-
version: packageJson.version,
|
|
12
|
-
timestamp: currentTimestamp
|
|
13
|
-
};
|
|
14
14
|
await writeFile(sentinelFilePath, JSON.stringify(data), { flag: "wx" });
|
|
15
15
|
} catch (err) {
|
|
16
16
|
if (err.code === "EEXIST") return;
|
|
17
|
+
if (err.code === "ENOENT") try {
|
|
18
|
+
await mkdir(dirname(sentinelFilePath), { recursive: true });
|
|
19
|
+
await writeFile(sentinelFilePath, JSON.stringify(data), { flag: "wx" });
|
|
20
|
+
return;
|
|
21
|
+
} catch (retryErr) {
|
|
22
|
+
if (retryErr.code === "EEXIST") return;
|
|
23
|
+
}
|
|
17
24
|
throw err;
|
|
18
25
|
}
|
|
19
26
|
};
|
|
@@ -70,10 +77,10 @@ const runOnce = async (sentinelFilePath, callback, options) => {
|
|
|
70
77
|
} catch (err) {
|
|
71
78
|
if (err.code === "ENOENT") {} else throw err;
|
|
72
79
|
}
|
|
73
|
-
writeSentinelFile(sentinelFilePath, currentTimestamp);
|
|
80
|
+
await writeSentinelFile(sentinelFilePath, currentTimestamp);
|
|
74
81
|
try {
|
|
75
82
|
await callback();
|
|
76
|
-
writeSentinelFile(sentinelFilePath, currentTimestamp);
|
|
83
|
+
await writeSentinelFile(sentinelFilePath, currentTimestamp);
|
|
77
84
|
} catch {
|
|
78
85
|
try {
|
|
79
86
|
await unlink(sentinelFilePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runOnce.mjs","names":[
|
|
1
|
+
{"version":3,"file":"runOnce.mjs","names":[],"sources":["../../../src/utils/runOnce.ts"],"sourcesContent":["import { mkdir, readFile, stat, unlink, writeFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport packageJson from '@intlayer/core/package.json' with { type: 'json' };\n\ntype RunOnceOptions = {\n /**\n * The function to execute when the sentinel is not found or is older than the cache timeout.\n */\n onIsCached?: () => void | Promise<void>;\n /**\n * The time window in milliseconds during which the sentinel is considered valid.\n *\n * @default 60000 = 1 minute\n */\n cacheTimeoutMs?: number;\n /**\n * If true, the callback will always run. If undefined, the callback will run only if the sentinel is older than the cache timeout.\n *\n * @default false\n */\n forceRun?: boolean;\n};\n\nconst DEFAULT_RUN_ONCE_OPTIONS = {\n cacheTimeoutMs: 60 * 1000, // 1 minute in milliseconds,\n} satisfies RunOnceOptions;\n\ntype SentinelData = {\n version: string;\n timestamp: number;\n};\n\nconst writeSentinelFile = async (\n sentinelFilePath: string,\n currentTimestamp: number\n) => {\n // O_EXCL ensures only the *first* process can create the file\n const data: SentinelData = {\n version: packageJson.version,\n timestamp: currentTimestamp,\n };\n\n try {\n // Ensure the directory exists before writing the file\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n\n await writeFile(sentinelFilePath, JSON.stringify(data), { flag: 'wx' });\n } catch (err: any) {\n if (err.code === 'EEXIST') {\n // Another process already created it → we're done\n return;\n }\n // Optimization: If ENOENT occurs on write despite mkdir (race condition with external deletion), retry once.\n if (err.code === 'ENOENT') {\n try {\n await mkdir(dirname(sentinelFilePath), { recursive: true });\n await writeFile(sentinelFilePath, JSON.stringify(data), { flag: 'wx' });\n return;\n } catch (retryErr: any) {\n if (retryErr.code === 'EEXIST') return;\n }\n }\n throw err; // unexpected FS error\n }\n};\n\n/**\n * Ensures a callback function runs only once within a specified time window across multiple processes.\n * Uses a sentinel file to coordinate execution and prevent duplicate work.\n *\n * @param sentinelFilePath - Path to the sentinel file used for coordination\n * @param callback - The function to execute (should be async)\n * @param options - The options for the runOnce function\n *\n * @example\n * ```typescript\n * await runPrepareIntlayerOnce(\n * '/tmp/intlayer-sentinel',\n * async () => {\n * // Your initialization logic here\n * await prepareIntlayer();\n * },\n * 30 * 1000 // 30 seconds cache\n * );\n * ```\n *\n * @throws {Error} When there are unexpected filesystem errors\n */\nexport const runOnce = async (\n sentinelFilePath: string,\n callback: () => void | Promise<void>,\n options?: RunOnceOptions\n) => {\n const { onIsCached, cacheTimeoutMs, forceRun } = {\n ...DEFAULT_RUN_ONCE_OPTIONS,\n ...(options ?? {}),\n };\n const currentTimestamp = Date.now();\n\n try {\n // Check if sentinel file exists and get its stats\n const sentinelStats = await stat(sentinelFilePath);\n const sentinelAge = currentTimestamp - sentinelStats.mtime.getTime();\n\n // Determine if we should rebuild based on cache age, force flag, or version mismatch\n let shouldRebuild = Boolean(forceRun) || sentinelAge > cacheTimeoutMs!;\n\n if (!shouldRebuild) {\n try {\n const raw = await readFile(sentinelFilePath, 'utf8');\n let cachedVersion: string | undefined;\n try {\n const parsed = JSON.parse(raw) as Partial<SentinelData>;\n cachedVersion = parsed.version;\n } catch {\n // Legacy format (timestamp only). Force a rebuild once to write versioned sentinel.\n cachedVersion = undefined;\n }\n\n if (!cachedVersion || cachedVersion !== packageJson.version) {\n shouldRebuild = true;\n }\n } catch {\n // If we cannot read the file, err on the safe side and rebuild\n shouldRebuild = true;\n }\n }\n\n if (shouldRebuild) {\n try {\n await unlink(sentinelFilePath);\n } catch {}\n // Fall through to create new sentinel and rebuild\n } else {\n await onIsCached?.();\n // Sentinel is recent and versions match, no need to rebuild\n return;\n }\n } catch (err: any) {\n if (err.code === 'ENOENT') {\n // File doesn't exist, continue to create it\n } else {\n throw err; // unexpected FS error\n }\n }\n\n // Write sentinel file before to block parallel processes\n // Added await here\n await writeSentinelFile(sentinelFilePath, currentTimestamp);\n\n try {\n await callback();\n\n // Write sentinel file after to ensure the first one has not been removed with cleanOutputDir\n // Added await here\n await writeSentinelFile(sentinelFilePath, currentTimestamp);\n } catch {\n try {\n await unlink(sentinelFilePath); // Remove sentinel file if an error occurs\n } catch {}\n }\n};\n"],"mappings":";;;;;AAuBA,MAAM,2BAA2B,EAC/B,gBAAgB,KAAK,KACtB;AAOD,MAAM,oBAAoB,OACxB,kBACA,qBACG;CAEH,MAAM,OAAqB;EACzB,SAAS,YAAY;EACrB,WAAW;EACZ;AAED,KAAI;AAEF,QAAM,MAAM,QAAQ,iBAAiB,EAAE,EAAE,WAAW,MAAM,CAAC;AAE3D,QAAM,UAAU,kBAAkB,KAAK,UAAU,KAAK,EAAE,EAAE,MAAM,MAAM,CAAC;UAChE,KAAU;AACjB,MAAI,IAAI,SAAS,SAEf;AAGF,MAAI,IAAI,SAAS,SACf,KAAI;AACF,SAAM,MAAM,QAAQ,iBAAiB,EAAE,EAAE,WAAW,MAAM,CAAC;AAC3D,SAAM,UAAU,kBAAkB,KAAK,UAAU,KAAK,EAAE,EAAE,MAAM,MAAM,CAAC;AACvE;WACO,UAAe;AACtB,OAAI,SAAS,SAAS,SAAU;;AAGpC,QAAM;;;;;;;;;;;;;;;;;;;;;;;;;AA0BV,MAAa,UAAU,OACrB,kBACA,UACA,YACG;CACH,MAAM,EAAE,YAAY,gBAAgB,aAAa;EAC/C,GAAG;EACH,GAAI,WAAW,EAAE;EAClB;CACD,MAAM,mBAAmB,KAAK,KAAK;AAEnC,KAAI;EAGF,MAAM,cAAc,oBADE,MAAM,KAAK,iBAAiB,EACG,MAAM,SAAS;EAGpE,IAAI,gBAAgB,QAAQ,SAAS,IAAI,cAAc;AAEvD,MAAI,CAAC,cACH,KAAI;GACF,MAAM,MAAM,MAAM,SAAS,kBAAkB,OAAO;GACpD,IAAI;AACJ,OAAI;AAEF,oBADe,KAAK,MAAM,IAAI,CACP;WACjB;AAEN,oBAAgB;;AAGlB,OAAI,CAAC,iBAAiB,kBAAkB,YAAY,QAClD,iBAAgB;UAEZ;AAEN,mBAAgB;;AAIpB,MAAI,cACF,KAAI;AACF,SAAM,OAAO,iBAAiB;UACxB;OAEH;AACL,SAAM,cAAc;AAEpB;;UAEK,KAAU;AACjB,MAAI,IAAI,SAAS,UAAU,OAGzB,OAAM;;AAMV,OAAM,kBAAkB,kBAAkB,iBAAiB;AAE3D,KAAI;AACF,QAAM,UAAU;AAIhB,QAAM,kBAAkB,kBAAkB,iBAAiB;SACrD;AACN,MAAI;AACF,SAAM,OAAO,iBAAiB;UACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.mjs","names":[
|
|
1
|
+
{"version":3,"file":"bin.mjs","names":[],"sources":["../../../../src/utils/runParallel/bin.ts"],"sourcesContent":["import type { ChildProcess } from 'node:child_process';\nimport { type SpawnOptions, spawn } from 'node:child_process';\n\ntype BinCallback = (err: Error | null, stdout?: string, code?: number) => void;\n\nconst stripStderr = (stderr: string | undefined): string | undefined => {\n if (!stderr) return;\n let cleaned = stderr.trim();\n // Strip bogus screen size error.\n // See https://github.com/microsoft/vscode/issues/98590\n const regex = /your \\d+x\\d+ screen size is bogus\\. expect trouble/gi;\n cleaned = cleaned.replace(regex, '');\n\n return cleaned.trim() || undefined;\n};\n\n/**\n * Spawn a binary and read its stdout.\n * @param cmd The name of the binary to spawn.\n * @param args The arguments for the binary.\n * @param options Optional option for the spawn function.\n * @param done Callback function.\n */\nexport const run = (\n cmd: string,\n args: string[],\n options: SpawnOptions | BinCallback | undefined,\n done?: BinCallback\n): void => {\n let normalizedOptions: SpawnOptions | undefined;\n let normalizedDone: BinCallback;\n\n if (typeof options === 'function') {\n normalizedDone = options;\n normalizedOptions = undefined;\n } else {\n normalizedDone = done!;\n normalizedOptions = options;\n }\n\n let executed = false;\n const ch: ChildProcess = spawn(cmd, args, normalizedOptions ?? {});\n let stdout = '';\n let stderr = '';\n\n if (ch.stdout) {\n ch.stdout.on('data', (d: Buffer) => {\n stdout += d.toString();\n });\n }\n\n if (ch.stderr) {\n ch.stderr.on('data', (d: Buffer) => {\n stderr += d.toString();\n });\n }\n\n ch.on('error', (err: Error) => {\n if (executed) return;\n executed = true;\n normalizedDone(new Error(String(err)));\n });\n\n ch.on('close', (code: number | null) => {\n if (executed) return;\n executed = true;\n\n const cleanedStderr = stripStderr(stderr);\n if (cleanedStderr) {\n return normalizedDone(new Error(cleanedStderr));\n }\n\n normalizedDone(null, stdout, code ?? undefined);\n });\n};\n"],"mappings":";;;AAKA,MAAM,eAAe,WAAmD;AACtE,KAAI,CAAC,OAAQ;CACb,IAAI,UAAU,OAAO,MAAM;AAI3B,WAAU,QAAQ,QADJ,wDACmB,GAAG;AAEpC,QAAO,QAAQ,MAAM,IAAI;;;;;;;;;AAU3B,MAAa,OACX,KACA,MACA,SACA,SACS;CACT,IAAI;CACJ,IAAI;AAEJ,KAAI,OAAO,YAAY,YAAY;AACjC,mBAAiB;AACjB,sBAAoB;QACf;AACL,mBAAiB;AACjB,sBAAoB;;CAGtB,IAAI,WAAW;CACf,MAAM,KAAmB,MAAM,KAAK,MAAM,qBAAqB,EAAE,CAAC;CAClE,IAAI,SAAS;CACb,IAAI,SAAS;AAEb,KAAI,GAAG,OACL,IAAG,OAAO,GAAG,SAAS,MAAc;AAClC,YAAU,EAAE,UAAU;GACtB;AAGJ,KAAI,GAAG,OACL,IAAG,OAAO,GAAG,SAAS,MAAc;AAClC,YAAU,EAAE,UAAU;GACtB;AAGJ,IAAG,GAAG,UAAU,QAAe;AAC7B,MAAI,SAAU;AACd,aAAW;AACX,iBAAe,IAAI,MAAM,OAAO,IAAI,CAAC,CAAC;GACtC;AAEF,IAAG,GAAG,UAAU,SAAwB;AACtC,MAAI,SAAU;AACd,aAAW;EAEX,MAAM,gBAAgB,YAAY,OAAO;AACzC,MAAI,cACF,QAAO,eAAe,IAAI,MAAM,cAAc,CAAC;AAGjD,iBAAe,MAAM,QAAQ,QAAQ,OAAU;GAC/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/utils/runParallel/index.ts"],"sourcesContent":["import { delimiter, join } from 'node:path';\nimport { spawnPosix } from './spawnPosix';\nimport { spawnWin32 } from './spawnWin32';\n\nexport type ParallelHandle = {\n kill: () => void;\n result: Promise<any>;\n commandText: string;\n};\n\n/**\n * Start a cross-platform parallel process using npm-run-all approach.\n * Accepts either a single string (e.g., 'next start') or an array of tokens (e.g., ['next', 'start']).\n */\nexport const runParallel = (proc?: string | string[]): ParallelHandle => {\n if (!proc || (Array.isArray(proc) && proc.length === 0))\n throw new Error('Invalid command');\n\n const commandText = Array.isArray(proc) ? proc.join(' ') : proc;\n\n const isArray = Array.isArray(proc);\n const command = isArray ? (proc as string[])[0] : commandText;\n const args = isArray ? (proc as string[]).slice(1) : [];\n\n // Ensure local binaries (node_modules/.bin) are resolvable\n const cwdBin = join(process.cwd(), 'node_modules', '.bin');\n const PATH_KEY =\n Object.keys(process.env).find((key) => key.toLowerCase() === 'path') ??\n 'PATH';\n\n const extendedPath = [cwdBin, process.env[PATH_KEY] ?? '']\n .filter(Boolean)\n .join(delimiter);\n\n const childEnv = {\n ...process.env,\n [PATH_KEY]: extendedPath,\n } as NodeJS.ProcessEnv;\n\n const isWin = process.platform === 'win32';\n const spawnFunc = isWin ? spawnWin32 : spawnPosix;\n\n // Spawn options\n const spawnOptions = {\n cwd: process.cwd(),\n stdio: 'inherit' as const,\n env: childEnv,\n shell: isWin,\n };\n\n // Spawn the child process\n const child = isArray\n ? // If provided as a single string element that includes spaces, treat it like a shell command\n args.length === 0 && /\\s/.test(command)\n ? isWin\n ? spawnFunc(\n process.env.ComSpec ?? 'cmd.exe',\n ['/d', '/s', '/c', command],\n spawnOptions\n )\n : spawnFunc(\n process.env.SHELL ?? '/bin/sh',\n ['-c', command],\n spawnOptions\n )\n : spawnFunc(command, args, spawnOptions)\n : isWin\n ? spawnFunc(\n process.env.ComSpec ?? 'cmd.exe',\n ['/d', '/s', '/c', commandText],\n spawnOptions\n )\n : spawnFunc(\n process.env.SHELL ?? '/bin/sh',\n ['-c', commandText],\n spawnOptions\n );\n\n const result = new Promise<void>((resolve, reject) => {\n child.on('error', (err) => {\n try {\n console.error(\n `[runParallel] Failed to start: ${err?.message ?? String(err)}`\n );\n } catch {}\n cleanupHandlers();\n reject(err);\n });\n\n child.on('exit', (code, signal) => {\n cleanupHandlers();\n\n // Treat common termination signals as graceful exits, not failures\n const gracefulSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP'];\n if (code === 0 || (signal && gracefulSignals.includes(signal))) {\n resolve();\n } else {\n reject(\n Object.assign(new Error('Parallel process failed'), { code, signal })\n );\n }\n });\n });\n\n const cleanup = () => {\n try {\n child.kill('SIGTERM');\n } catch {\n // Best effort\n }\n };\n\n const signalHandlers: { event: string; handler: (...args: any[]) => void }[] =\n [\n { event: 'SIGINT', handler: cleanup },\n { event: 'SIGTERM', handler: cleanup },\n { event: 'SIGQUIT', handler: cleanup },\n { event: 'SIGHUP', handler: cleanup },\n ];\n\n // Register signal handlers\n signalHandlers.forEach(({ event, handler }) => {\n process.on(event as any, handler as any);\n });\n\n const cleanupHandlers = () => {\n signalHandlers.forEach(({ event, handler }) => {\n process.off(event as any, handler as any);\n });\n };\n\n const kill = () => {\n try {\n child.kill('SIGTERM');\n } catch {\n // Best effort\n }\n };\n\n return { kill, result, commandText };\n};\n"],"mappings":";;;;;;;;;AAcA,MAAa,eAAe,SAA6C;AACvE,KAAI,CAAC,QAAS,MAAM,QAAQ,KAAK,IAAI,KAAK,WAAW,EACnD,OAAM,IAAI,MAAM,kBAAkB;CAEpC,MAAM,cAAc,MAAM,QAAQ,KAAK,GAAG,KAAK,KAAK,IAAI,GAAG;CAE3D,MAAM,UAAU,MAAM,QAAQ,KAAK;CACnC,MAAM,UAAU,UAAW,KAAkB,KAAK;CAClD,MAAM,OAAO,UAAW,KAAkB,MAAM,EAAE,GAAG,EAAE;CAGvD,MAAM,SAAS,KAAK,QAAQ,KAAK,EAAE,gBAAgB,OAAO;CAC1D,MAAM,WACJ,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,QAAQ,IAAI,aAAa,KAAK,OAAO,IACpE;CAEF,MAAM,eAAe,CAAC,QAAQ,QAAQ,IAAI,aAAa,GAAG,CACvD,OAAO,QAAQ,CACf,KAAK,UAAU;CAElB,MAAM,WAAW;EACf,GAAG,QAAQ;GACV,WAAW;EACb;CAED,MAAM,QAAQ,QAAQ,aAAa;CACnC,MAAM,YAAY,QAAQ,aAAa;CAGvC,MAAM,eAAe;EACnB,KAAK,QAAQ,KAAK;EAClB,OAAO;EACP,KAAK;EACL,OAAO;EACR;CAGD,MAAM,QAAQ,UAEV,KAAK,WAAW,KAAK,KAAK,KAAK,QAAQ,GACrC,QACE,UACE,QAAQ,IAAI,WAAW,WACvB;EAAC;EAAM;EAAM;EAAM;EAAQ,EAC3B,aACD,GACD,UACE,QAAQ,IAAI,SAAS,WACrB,CAAC,MAAM,QAAQ,EACf,aACD,GACH,UAAU,SAAS,MAAM,aAAa,GACxC,QACE,UACE,QAAQ,IAAI,WAAW,WACvB;EAAC;EAAM;EAAM;EAAM;EAAY,EAC/B,aACD,GACD,UACE,QAAQ,IAAI,SAAS,WACrB,CAAC,MAAM,YAAY,EACnB,aACD;CAEP,MAAM,SAAS,IAAI,SAAe,WAAS,WAAW;AACpD,QAAM,GAAG,UAAU,QAAQ;AACzB,OAAI;AACF,YAAQ,MACN,kCAAkC,KAAK,WAAW,OAAO,IAAI,GAC9D;WACK;AACR,oBAAiB;AACjB,UAAO,IAAI;IACX;AAEF,QAAM,GAAG,SAAS,MAAM,WAAW;AACjC,oBAAiB;AAIjB,OAAI,SAAS,KAAM,UADK;IAAC;IAAU;IAAW;IAAW;IAAS,CACrB,SAAS,OAAO,CAC3D,YAAS;OAET,QACE,OAAO,uBAAO,IAAI,MAAM,0BAA0B,EAAE;IAAE;IAAM;IAAQ,CAAC,CACtE;IAEH;GACF;CAEF,MAAM,gBAAgB;AACpB,MAAI;AACF,SAAM,KAAK,UAAU;UACf;;CAKV,MAAM,iBACJ;EACE;GAAE,OAAO;GAAU,SAAS;GAAS;EACrC;GAAE,OAAO;GAAW,SAAS;GAAS;EACtC;GAAE,OAAO;GAAW,SAAS;GAAS;EACtC;GAAE,OAAO;GAAU,SAAS;GAAS;EACtC;AAGH,gBAAe,SAAS,EAAE,OAAO,cAAc;AAC7C,UAAQ,GAAG,OAAc,QAAe;GACxC;CAEF,MAAM,wBAAwB;AAC5B,iBAAe,SAAS,EAAE,OAAO,cAAc;AAC7C,WAAQ,IAAI,OAAc,QAAe;IACzC;;CAGJ,MAAM,aAAa;AACjB,MAAI;AACF,SAAM,KAAK,UAAU;UACf;;AAKV,QAAO;EAAE;EAAM;EAAQ;EAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pidTree.mjs","names":[
|
|
1
|
+
{"version":3,"file":"pidTree.mjs","names":[],"sources":["../../../../src/utils/runParallel/pidTree.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { ps } from './ps';\nimport { wmic } from './wmic';\n\ntype Platform =\n | 'darwin'\n | 'sunos'\n | 'freebsd'\n | 'netbsd'\n | 'win'\n | 'linux'\n | 'aix';\ntype Method = 'ps' | 'wmic';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\n\ninterface ListOptions {\n root?: boolean;\n advanced?: boolean;\n}\n\ntype ProcessInfo = { pid: number; ppid?: number };\ntype ResultType<T extends ListOptions | undefined> = T extends {\n advanced: true;\n}\n ? ProcessInfo[]\n : number[];\n\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\ntype ListCallback<T extends ListOptions | undefined> = (\n err: Error | null,\n list?: ResultType<T>\n) => void;\n\ntype ProcessListFn = (callback: ProcessListCallback) => void;\n\nconst platformToMethod: Record<Platform, Method> = {\n darwin: 'ps',\n sunos: 'ps',\n freebsd: 'ps',\n netbsd: 'ps',\n win: 'wmic',\n linux: 'ps',\n aix: 'ps',\n};\n\nconst methodToFn: Record<Method, ProcessListFn> = {\n ps,\n wmic,\n};\n\nlet platform: string = os.platform();\nif (platform.startsWith('win')) {\n platform = 'win';\n}\n\nconst method: Method | undefined = platformToMethod[platform as Platform];\n\n/**\n * Gets the list of all the pids of the system.\n */\nconst getAll = (callback: ProcessListCallback): void => {\n if (method === undefined) {\n callback(\n new Error(\n os.platform() +\n ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'\n ),\n undefined\n );\n return;\n }\n\n const listFn = methodToFn[method];\n listFn(callback);\n};\n\n/**\n * Get the list of children and grandchildren pids of the given PID.\n * @param PID A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready.\n */\nconst pidtree = <T extends ListOptions | undefined>(\n PID: number | string,\n options: T | ListCallback<T> | undefined,\n callback?: ListCallback<T>\n): void => {\n let normalizedOptions: ListOptions;\n let normalizedCallback: ListCallback<T>;\n\n if (typeof options === 'function') {\n normalizedCallback = options;\n normalizedOptions = {};\n } else {\n normalizedCallback = callback!;\n normalizedOptions = typeof options === 'object' ? options : {};\n }\n\n const parsedPID = parseInt(String(PID), 10);\n if (Number.isNaN(parsedPID) || parsedPID < -1) {\n normalizedCallback(\n new TypeError('The pid provided is invalid') as Error,\n undefined\n );\n return;\n }\n\n getAll((err, processList) => {\n if (err) {\n normalizedCallback(err, undefined);\n return;\n }\n\n if (!processList) {\n normalizedCallback(new Error('Failed to get process list'), undefined);\n return;\n }\n\n // If the user wants the whole list just return it\n if (parsedPID === -1) {\n const result = processList.map(([ppid, pid]) =>\n normalizedOptions.advanced ? { ppid, pid } : pid\n ) as ResultType<T>;\n\n normalizedCallback(null, result);\n return;\n }\n\n let root: ProcessInfo | number | undefined;\n for (let l = 0; l < processList.length; l++) {\n if (processList[l][1] === parsedPID) {\n root = normalizedOptions.advanced\n ? { ppid: processList[l][0], pid: parsedPID }\n : parsedPID;\n break;\n }\n\n if (processList[l][0] === parsedPID) {\n root = normalizedOptions.advanced ? { pid: parsedPID } : parsedPID; // Special pids like 0 on *nix\n }\n }\n\n if (root === undefined) {\n normalizedCallback(new Error('No matching pid found'), undefined);\n return;\n }\n\n // Build the adjacency Hash Map (pid -> [children of pid])\n const tree: Record<number, number[]> = {};\n const listCopy = [...processList];\n while (listCopy.length > 0) {\n const element = listCopy.pop()!;\n if (tree[element[0]]) {\n tree[element[0]].push(element[1]);\n } else {\n tree[element[0]] = [element[1]];\n }\n }\n\n // Starting by the PID provided by the user, traverse the tree using the\n // adjacency Hash Map until the whole subtree is visited.\n // Each pid encountered while visiting is added to the pids array.\n let idx = 0;\n const pids: (ProcessInfo | number)[] = [root];\n while (idx < pids.length) {\n const curpid = normalizedOptions.advanced\n ? (pids[idx++] as ProcessInfo).pid\n : (pids[idx++] as number);\n if (!tree[curpid]) continue;\n const length = tree[curpid].length;\n for (let j = 0; j < length; j++) {\n pids.push(\n normalizedOptions.advanced\n ? { ppid: curpid, pid: tree[curpid][j] }\n : tree[curpid][j]\n );\n }\n\n delete tree[curpid];\n }\n\n if (!normalizedOptions.root) {\n pids.shift(); // Remove root\n }\n\n normalizedCallback(null, pids as ResultType<T>);\n });\n};\n\nconst pify = <T extends ListOptions | undefined>(\n fn: typeof pidtree,\n arg1: number | string,\n arg2: T | undefined\n): Promise<ResultType<T>> => {\n return new Promise((resolve, reject) => {\n fn(arg1, arg2, (err, data) => {\n if (err) return reject(err);\n if (data === undefined) {\n return reject(new Error('No data returned'));\n }\n resolve(data);\n });\n });\n};\n\n// Node versions prior to 4.0.0 do not define have `startsWith`.\n/* istanbul ignore if */\nif (!String.prototype.startsWith) {\n String.prototype.startsWith = function (suffix: string): boolean {\n return this.substring(0, suffix.length) === suffix;\n };\n}\n\n/**\n * Get the list of children pids of the given pid.\n * @param pid A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready. If not provided a promise is returned instead.\n * @returns Only when the callback is not provided.\n */\nexport const list = <T extends ListOptions | undefined>(\n pid: number | string,\n options?: T | ListCallback<T>,\n callback?: ListCallback<T>\n): Promise<ResultType<T>> | undefined => {\n if (typeof options === 'function') {\n pidtree(pid, undefined, options);\n return;\n }\n\n if (typeof callback === 'function') {\n pidtree(pid, options, callback);\n return;\n }\n\n return pify(pidtree, pid, options);\n};\n"],"mappings":";;;;;AAoCA,MAAM,mBAA6C;CACjD,QAAQ;CACR,OAAO;CACP,SAAS;CACT,QAAQ;CACR,KAAK;CACL,OAAO;CACP,KAAK;CACN;AAED,MAAM,aAA4C;CAChD;CACA;CACD;AAED,IAAI,WAAmB,GAAG,UAAU;AACpC,IAAI,SAAS,WAAW,MAAM,CAC5B,YAAW;AAGb,MAAM,SAA6B,iBAAiB;;;;AAKpD,MAAM,UAAU,aAAwC;AACtD,KAAI,WAAW,QAAW;AACxB,2BACE,IAAI,MACF,GAAG,UAAU,GACX,qFACH,EACD,OACD;AACD;;CAGF,MAAM,SAAS,WAAW;AAC1B,QAAO,SAAS;;;;;;;;AASlB,MAAM,WACJ,KACA,SACA,aACS;CACT,IAAI;CACJ,IAAI;AAEJ,KAAI,OAAO,YAAY,YAAY;AACjC,uB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SAAS,kBAAkB,WAC5B,KAAK,OAAuB,MAC5B,KAAK;AACV,OAAI,CAAC,KAAK,QAAS;GACnB,MAAM,SAAS,KAAK,QAAQ;AAC5B,QAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,IAC1B,MAAK,KACH,kBAAkB,WACd;IAAE,MAAM;IAAQ,KAAK,KAAK,QAAQ;IAAI,GACtC,KAAK,QAAQ,GAClB;AAGH,UAAO,KAAK;;AAGd,MAAI,CAAC,kBAAkB,KACrB,MAAK,OAAO;AAGd,qBAAmB,MAAM,KAAsB;GAC/C;;AAGJ,MAAM,QACJ,IACA,MACA,SAC2B;AAC3B,QAAO,IAAI,SAAS,SAAS,WAAW;AACtC,KAAG,MAAM,OAAO,KAAK,SAAS;AAC5B,OAAI,IAAK,QAAO,OAAO,IAAI;AAC3B,OAAI,SAAS,OACX,QAAO,uBAAO,IAAI,MAAM,mBAAmB,CAAC;AAE9C,WAAQ,KAAK;IACb;GACF;;;AAKJ,IAAI,CAAC,OAAO,UAAU,WACpB,QAAO,UAAU,aAAa,SAAU,QAAyB;AAC/D,QAAO,KAAK,UAAU,GAAG,OAAO,OAAO,KAAK;;;;;;;;;AAWhD,MAAa,QACX,KACA,SACA,aACuC;AACvC,KAAI,OAAO,YAAY,YAAY;AACjC,UAAQ,KAAK,QAAW,QAAQ;AAChC;;AAGF,KAAI,OAAO,aAAa,YAAY;AAClC,UAAQ,KAAK,SAAS,SAAS;AAC/B;;AAGF,QAAO,KAAK,SAAS,KAAK,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ps.mjs","names":[
|
|
1
|
+
{"version":3,"file":"ps.mjs","names":[],"sources":["../../../../src/utils/runParallel/ps.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { run } from './bin';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\n\n/**\n * Gets the list of all the pids of the system through the ps command.\n * @param callback Callback function with error and process list.\n */\nexport const ps = (callback: ProcessListCallback): void => {\n const args = ['-A', '-o', 'ppid,pid'];\n\n run('ps', args, (err, stdout, code) => {\n if (err) {\n callback(err);\n return;\n }\n if (code !== 0) {\n callback(new Error(`pidtree ps command exited with code ${code}`));\n return;\n }\n\n // Example of stdout\n //\n // PPID PID\n // 1 430\n // 430 432\n // 1 727\n // 1 7166\n\n if (!stdout) {\n callback(new Error('No stdout received from ps command'));\n return;\n }\n\n try {\n const lines = stdout.split(os.EOL);\n\n const list: ProcessList = [];\n for (let i = 1; i < lines.length; i++) {\n const trimmed = lines[i].trim();\n if (!trimmed) continue;\n const parts = trimmed.split(/\\s+/);\n const ppid = parseInt(parts[0], 10); // PPID\n const pid = parseInt(parts[1], 10); // PID\n if (!Number.isNaN(ppid) && !Number.isNaN(pid)) {\n list.push([ppid, pid]);\n }\n }\n\n callback(null, list);\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n });\n};\n"],"mappings":";;;;;;;;AAUA,MAAa,MAAM,aAAwC;AAGzD,KAAI,MAFS;EAAC;EAAM;EAAM;EAAW,GAEpB,KAAK,QAAQ,SAAS;AACrC,MAAI,KAAK;AACP,YAAS,IAAI;AACb;;AAEF,MAAI,SAAS,GAAG;AACd,4BAAS,IAAI,MAAM,uCAAuC,OAAO,CAAC;AAClE;;AAWF,MAAI,CAAC,QAAQ;AACX,4BAAS,IAAI,MAAM,qCAAqC,CAAC;AACzD;;AAGF,MAAI;GACF,MAAM,QAAQ,OAAO,MAAM,GAAG,IAAI;GAElC,MAAM,OAAoB,EAAE;AAC5B,QAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;IACrC,MAAM,UAAU,MAAM,GAAG,MAAM;AAC/B,QAAI,CAAC,QAAS;IACd,MAAM,QAAQ,QAAQ,MAAM,MAAM;IAClC,MAAM,OAAO,SAAS,MAAM,IAAI,GAAG;IACnC,MAAM,MAAM,SAAS,MAAM,IAAI,GAAG;AAClC,QAAI,CAAC,OAAO,MAAM,KAAK,IAAI,CAAC,OAAO,MAAM,IAAI,CAC3C,MAAK,KAAK,CAAC,MAAM,IAAI,CAAC;;AAI1B,YAAS,MAAM,KAAK;WACb,OAAO;AACd,YAAS,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAAC;;GAErE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runTask.mjs","names":[
|
|
1
|
+
{"version":3,"file":"runTask.mjs","names":[],"sources":["../../../../src/utils/runParallel/runTask.ts"],"sourcesContent":["//------------------------------------------------------------------------------\n// Requirements\n//------------------------------------------------------------------------------\n\nimport { Writable } from 'node:stream';\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * Remove the given value from the array.\n */\nconst remove = <T>(array: T[], x: T): void => {\n const index = array.indexOf(x);\n if (index !== -1) {\n array.splice(index, 1);\n }\n};\n\nconst signals: Record<string, number> = {\n // Signal name mappings to their respective standard numeric codes.\n // See: https://man7.org/linux/man-pages/man7/signal.7.html\n\n SIGABRT: 6, // Abort signal from abort(3)\n SIGALRM: 14, // Timer signal from alarm(2)\n SIGBUS: 10, // Bus error (bad memory access)\n SIGCHLD: 20, // Child stopped or terminated\n SIGCONT: 19, // Continue if stopped\n SIGFPE: 8, // Floating point exception\n SIGHUP: 1, // Hangup detected on controlling terminal or death of controlling process\n SIGILL: 4, // Illegal Instruction\n SIGINT: 2, // Interrupt from keyboard (Ctrl+C)\n SIGKILL: 9, // Kill signal (cannot be caught or ignored)\n SIGPIPE: 13, // Broken pipe: write to pipe with no readers\n SIGQUIT: 3, // Quit from keyboard (Ctrl+\\)\n SIGSEGV: 11, // Invalid memory reference (segmentation fault)\n SIGSTOP: 17, // Stop process (cannot be caught or ignored)\n SIGTERM: 15, // Termination signal\n SIGTRAP: 5, // Trace/breakpoint trap\n SIGTSTP: 18, // Stop typed at tty (Ctrl+Z)\n SIGTTIN: 21, // tty input for background process\n SIGTTOU: 22, // tty output for background process\n SIGUSR1: 30, // User-defined signal 1\n SIGUSR2: 31, // User-defined signal 2\n};\n\n/**\n * Converts a signal name to a number.\n */\nconst convert = (signal: string): number => {\n return signals[signal] || 0;\n};\n\n/**\n * Simple in-memory writable stream\n */\nclass MemoryStream extends Writable {\n private chunks: Buffer[] = [];\n\n _write(\n chunk: Buffer,\n _encoding: string,\n callback: (error?: Error | null) => void\n ): void {\n this.chunks.push(chunk);\n callback();\n }\n\n toString(): string {\n return Buffer.concat(this.chunks).toString('utf8');\n }\n}\n\n//------------------------------------------------------------------------------\n// Types\n//------------------------------------------------------------------------------\n\ninterface TaskResult {\n name: string;\n code: number | null;\n signal?: string | null;\n}\n\ninterface TaskQueueItem {\n name: string;\n index: number;\n}\n\ninterface RunTaskOptions {\n stdout: NodeJS.WritableStream;\n stderr?: NodeJS.WritableStream;\n aggregateOutput?: boolean;\n continueOnError?: boolean;\n race?: boolean;\n maxParallel?: number;\n}\n\ninterface TaskPromise extends Promise<TaskResult> {\n abort?: () => void;\n}\n\n//------------------------------------------------------------------------------\n// Public Interface\n//------------------------------------------------------------------------------\n\n/**\n * Run npm-scripts of given names in parallel.\n *\n * If a npm-script exited with a non-zero code, this aborts other all npm-scripts.\n *\n * Note: This is a simplified version for our use case.\n * The full implementation would require the actual runTask function from npm-run-all.\n */\nexport const runTasks = (\n tasks: string[],\n options: RunTaskOptions\n): Promise<TaskResult[]> => {\n return new Promise((resolve, reject) => {\n if (tasks.length === 0) {\n resolve([]);\n return;\n }\n\n const results: TaskResult[] = tasks.map((task) => ({\n name: task,\n code: undefined as any,\n }));\n const queue: TaskQueueItem[] = tasks.map((task, index) => ({\n name: task,\n index,\n }));\n const promises: TaskPromise[] = [];\n let error: Error | null = null;\n let aborted = false;\n\n /**\n * Done.\n */\n const done = (): void => {\n if (error == null) {\n resolve(results);\n } else {\n reject(error);\n }\n };\n\n /**\n * Aborts all tasks.\n */\n const abort = (): void => {\n if (aborted) {\n return;\n }\n aborted = true;\n\n if (promises.length === 0) {\n done();\n } else {\n for (const p of promises) {\n p.abort?.();\n }\n Promise.all(promises).then(done, reject);\n }\n };\n\n /**\n * Runs a next task.\n */\n const next = (): void => {\n if (aborted) {\n return;\n }\n if (queue.length === 0) {\n if (promises.length === 0) {\n done();\n }\n return;\n }\n\n const originalOutputStream = options.stdout;\n const optionsClone = { ...options };\n const writer = new MemoryStream();\n\n if (options.aggregateOutput) {\n optionsClone.stdout = writer as any;\n }\n\n const task = queue.shift()!;\n\n // Note: This requires the actual runTask implementation from npm-run-all\n // For now, this is a placeholder that would need to be implemented\n const promise = Promise.resolve({\n name: task.name,\n code: 0,\n signal: null,\n }) as TaskPromise;\n\n promises.push(promise);\n promise.then(\n (result) => {\n remove(promises, promise);\n if (aborted) {\n return;\n }\n\n if (options.aggregateOutput) {\n originalOutputStream.write(writer.toString());\n }\n\n // Check if the task failed as a result of a signal, and\n // amend the exit code as a result.\n if (\n result.code === null &&\n result.signal !== null &&\n result.signal !== undefined\n ) {\n // An exit caused by a signal must return a status code\n // of 128 plus the value of the signal code.\n // Ref: https://nodejs.org/api/process.html#process_exit_codes\n result.code = 128 + convert(result.signal);\n }\n\n // Save the result.\n results[task.index].code = result.code;\n\n // Aborts all tasks if it's an error.\n if (result.code) {\n error = new Error(\n `Task ${result.name} failed with code ${result.code}`\n );\n if (!options.continueOnError) {\n abort();\n return;\n }\n }\n\n // Aborts all tasks if options.race is true.\n if (options.race && !result.code) {\n abort();\n return;\n }\n\n // Call the next task.\n next();\n },\n (thisError: Error) => {\n remove(promises, promise);\n if (!options.continueOnError || options.race) {\n error = thisError;\n abort();\n return;\n }\n next();\n }\n );\n };\n\n const max = options.maxParallel;\n const end =\n typeof max === 'number' && max > 0\n ? Math.min(tasks.length, max)\n : tasks.length;\n for (let i = 0; i < end; ++i) {\n next();\n }\n });\n};\n"],"mappings":";;;;;;AAaA,MAAM,UAAa,OAAY,MAAe;CAC5C,MAAM,QAAQ,MAAM,QAAQ,EAAE;AAC9B,KAAI,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../../../../src/utils/runParallel/wmic.ts"],"sourcesContent":["import type { SpawnOptions } from 'node:child_process';\nimport * as os from 'node:os';\nimport { run } from './bin';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\n\n/**\n * Gets the list of all the pids of the system through the wmic command.\n * @param callback Callback function with error and process list.\n */\nexport const wmic = (callback: ProcessListCallback): void => {\n const args = ['PROCESS', 'get', 'ParentProcessId,ProcessId'];\n const options: SpawnOptions = {\n windowsHide: true,\n windowsVerbatimArguments: true,\n };\n run('wmic', args, options, (err, stdout, code) => {\n if (err) {\n callback(err);\n return;\n }\n\n if (code !== 0) {\n callback(new Error(`pidtree wmic command exited with code ${code}`));\n return;\n }\n\n // Example of stdout\n //\n // ParentProcessId ProcessId\n // 0 777\n\n if (!stdout) {\n callback(new Error('No stdout received from wmic command'));\n return;\n }\n\n try {\n const lines = stdout.split(os.EOL);\n\n const list: ProcessList = [];\n for (let i = 1; i < lines.length; i++) {\n const trimmed = lines[i].trim();\n if (!trimmed) continue;\n const parts = trimmed.split(/\\s+/);\n const ppid = parseInt(parts[0], 10); // PPID\n const pid = parseInt(parts[1], 10); // PID\n if (!Number.isNaN(ppid) && !Number.isNaN(pid)) {\n list.push([ppid, pid]);\n }\n }\n\n callback(null, list);\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n });\n};\n"],"mappings":";;;;;;;;AAWA,MAAa,QAAQ,aAAwC;AAM3D,KAAI,QALS;EAAC;EAAW;EAAO;EAA4B,EAC9B;EAC5B,aAAa;EACb,0BAA0B;EAC3B,GAC2B,KAAK,QAAQ,SAAS;AAChD,MAAI,KAAK;AACP,YAAS,IAAI;AACb;;AAGF,MAAI,SAAS,GAAG;AACd,4BAAS,IAAI,MAAM,yCAAyC,OAAO,CAAC;AACpE;;AAQF,MAAI,CAAC,QAAQ;AACX,4BAAS,IAAI,MAAM,uCAAuC,CAAC;AAC3D;;AAGF,MAAI;GACF,MAAM,QAAQ,OAAO,MAAM,GAAG,IAAI;GAElC,MAAM,OAAoB,EAAE;AAC5B,QAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;IACrC,MAAM,UAAU,MAAM,GAAG,MAAM;AAC/B,QAAI,CAAC,QAAS;IACd,MAAM,QAAQ,QAAQ,MAAM,MAAM;IAClC,MAAM,OAAO,SAAS,MAAM,IAAI,GAAG;IACnC,MAAM,MAAM,SAAS,MAAM,IAAI,GAAG;AAClC,QAAI,CAAC,OAAO,MAAM,KAAK,IAAI,CAAC,OAAO,MAAM,IAAI,CAC3C,MAAK,KAAK,CAAC,MAAM,IAAI,CAAC;;AAI1B,YAAS,MAAM,KAAK;WACb,OAAO;AACd,YAAS,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAAC;;GAErE"}
|
package/dist/esm/watcher.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.mjs","names":["
|
|
1
|
+
{"version":3,"file":"watcher.mjs","names":["chokidarWatch"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport {\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { handleContentDeclarationFileMoved } from './handleContentDeclarationFileMoved';\nimport { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';\nimport { prepareIntlayer } from './prepareIntlayer';\nimport { writeContentDeclaration } from './writeContentDeclaration';\n\n// Map to track files that were recently unlinked: oldPath -> { timer, timestamp }\nconst pendingUnlinks = new Map<\n string,\n { timer: NodeJS.Timeout; oldPath: string }\n>();\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n skipPrepare?: boolean;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configuration: IntlayerConfig =\n options?.configuration ?? getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n return chokidarWatch(watchedFilesPatternWithPath, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n awaitWriteFinish: {\n stabilityThreshold: 1000,\n pollInterval: 100,\n },\n ignored: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n let isMove = false;\n\n // Check if this Add corresponds to a pending Unlink (Move/Rename detection)\n // Heuristic:\n // - Priority A: Exact basename match (Moved to different folder)\n // - Priority B: Single entry in pendingUnlinks (Renamed file)\n let matchedOldPath: string | undefined;\n\n // Search for basename match\n for (const [oldPath] of pendingUnlinks) {\n if (basename(oldPath) === fileName) {\n matchedOldPath = oldPath;\n break;\n }\n }\n\n // If no basename match, but exactly one file was recently unlinked, assume it's a rename\n if (!matchedOldPath && pendingUnlinks.size === 1) {\n matchedOldPath = pendingUnlinks.keys().next().value;\n }\n\n if (matchedOldPath) {\n // It is a move! Cancel the unlink handler\n const pending = pendingUnlinks.get(matchedOldPath);\n if (pending) {\n clearTimeout(pending.timer);\n pendingUnlinks.delete(matchedOldPath);\n }\n\n isMove = true;\n appLogger(`File moved from ${matchedOldPath} to ${filePath}`);\n\n await handleContentDeclarationFileMoved(\n matchedOldPath,\n filePath,\n configuration\n );\n }\n\n // If it's NOT a move, perform standard \"New File\" logic\n if (!isMove) {\n const fileContent = await readFile(filePath, 'utf-8');\n const isEmpty = fileContent === '';\n\n // Fill template content declaration file if it is empty\n if (isEmpty) {\n const extensionPattern = fileExtensions\n .map((ext) => ext.replace(/\\./g, '\\\\.'))\n .join('|');\n const name = fileName.replace(\n new RegExp(`(${extensionPattern})$`),\n ''\n );\n\n await writeContentDeclaration(\n {\n key: name,\n content: {},\n filePath,\n },\n configuration\n );\n }\n }\n\n // Always ensure the file is processed (both for moves and adds)\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n })\n .on(\n 'change',\n async (filePath) =>\n await handleContentDeclarationFileChange(filePath, configuration)\n )\n .on('unlink', async (filePath) => {\n // Delay unlink processing to see if an 'add' event occurs (indicating a move)\n const timer = setTimeout(async () => {\n // If timer fires, the file was genuinely removed\n pendingUnlinks.delete(filePath);\n await handleUnlinkedContentDeclarationFile(filePath, configuration);\n }, 200); // 200ms window to catch the 'add' event\n\n pendingUnlinks.set(filePath, { timer, oldPath: filePath });\n })\n .on('error', async (error) => {\n appLogger(`Watcher error: ${error}`, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const { skipPrepare, ...rest } = options ?? {};\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n if (!skipPrepare) {\n await prepareIntlayer(configuration, { forceRun: true });\n }\n\n if (configuration.content.watch || options?.persistent) {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Watching Intlayer content declarations');\n watch({ ...rest, configuration });\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAM,iCAAiB,IAAI,KAGxB;AASH,MAAa,SAAS,YAA2B;CAC/C,MAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,cAAc;CACpE,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,EACJ,OAAO,aACP,6BACA,mBACE,cAAc;AAElB,QAAOA,QAAc,6BAA6B;EAChD,YAAY;EACZ,eAAe;EACf,kBAAkB;GAChB,oBAAoB;GACpB,cAAc;GACf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gBAAgB,cAAc;GACpC;;AAGN,MAAa,wBAAwB,OAAO,YAA2B;CACrE,MAAM,EAAE,aAAa,GAAG,SAAS,WAAW,EAAE;CAC9C,MAAM,gBACJ,SAAS,iBAAiB,iBAAiB,SAAS,cAAc;AAEpE,KAAI,CAAC,YACH,OAAM,gBAAgB,eAAe,EAAE,UAAU,MAAM,CAAC;AAG1D,KAAI,cAAc,QAAQ,SAAS,SAAS,YAAY;AAGtD,EAFkB,aAAa,cAAc,CAEnC,yCAAyC;AACnD,QAAM;GAAE,GAAG;GAAM;GAAe,CAAC"}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { getProjectRequire } from "@intlayer/config";
|
|
2
2
|
|
|
3
3
|
//#region src/writeContentDeclaration/detectFormatCommand.ts
|
|
4
|
-
|
|
4
|
+
let cachedFormatCommand = null;
|
|
5
|
+
const detectFormatCommand = (configuration, projectRequireProp) => {
|
|
6
|
+
const { formatCommand, baseDir } = configuration.content;
|
|
7
|
+
const projectRequire = projectRequireProp ?? getProjectRequire(baseDir);
|
|
8
|
+
if (formatCommand) return formatCommand;
|
|
9
|
+
if (cachedFormatCommand !== null) return cachedFormatCommand;
|
|
5
10
|
try {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} catch {}
|
|
11
|
+
projectRequire.resolve("prettier");
|
|
12
|
+
cachedFormatCommand = "prettier --write \"{{file}}\" --log-level silent";
|
|
13
|
+
return cachedFormatCommand;
|
|
14
|
+
} catch (_error) {}
|
|
15
|
+
try {
|
|
16
|
+
projectRequire.resolve("biome");
|
|
17
|
+
cachedFormatCommand = "biome format \"{{file}}\" --write --log-level none";
|
|
18
|
+
return cachedFormatCommand;
|
|
19
|
+
} catch (_error) {}
|
|
20
|
+
try {
|
|
21
|
+
projectRequire.resolve("eslint");
|
|
22
|
+
cachedFormatCommand = "eslint --fix \"{{file}}\" --quiet";
|
|
23
|
+
return cachedFormatCommand;
|
|
24
|
+
} catch (_error) {}
|
|
25
|
+
cachedFormatCommand = void 0;
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectFormatCommand.mjs","names":[],"sources":["../../../src/writeContentDeclaration/detectFormatCommand.ts"],"sourcesContent":["import { getProjectRequire } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nexport const detectFormatCommand = (configuration: IntlayerConfig) => {\n
|
|
1
|
+
{"version":3,"file":"detectFormatCommand.mjs","names":[],"sources":["../../../src/writeContentDeclaration/detectFormatCommand.ts"],"sourcesContent":["import { getProjectRequire } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nlet cachedFormatCommand: string | undefined | null = null;\n\nexport const detectFormatCommand = (\n configuration: IntlayerConfig,\n projectRequireProp?: NodeJS.Require\n) => {\n const { formatCommand, baseDir } = configuration.content;\n const projectRequire = projectRequireProp ?? getProjectRequire(baseDir);\n\n // Priority: Explicit configuration\n // We do not cache this because the user might change their config file active-session.\n if (formatCommand) {\n return formatCommand;\n }\n\n // Priority: Cached detection\n // If not null, we have already performed the expensive checks.\n if (cachedFormatCommand !== null) {\n return cachedFormatCommand;\n }\n\n // Perform Detection\n\n // Try Prettier\n try {\n projectRequire.resolve('prettier');\n cachedFormatCommand = 'prettier --write \"{{file}}\" --log-level silent';\n return cachedFormatCommand;\n } catch (_error) {\n // Prettier not found, continue\n }\n\n // Try Biome\n try {\n projectRequire.resolve('biome');\n cachedFormatCommand = 'biome format \"{{file}}\" --write --log-level none';\n return cachedFormatCommand;\n } catch (_error) {\n // Biome not found, continue\n }\n\n // Try ESLint\n try {\n projectRequire.resolve('eslint');\n cachedFormatCommand = 'eslint --fix \"{{file}}\" --quiet';\n return cachedFormatCommand;\n } catch (_error) {\n // ESLint not found\n }\n\n // No formatter found\n // Set to undefined (not null) so we know we checked and found nothing.\n cachedFormatCommand = undefined;\n return undefined;\n};\n"],"mappings":";;;AAGA,IAAI,sBAAiD;AAErD,MAAa,uBACX,eACA,uBACG;CACH,MAAM,EAAE,eAAe,YAAY,cAAc;CACjD,MAAM,iBAAiB,sBAAsB,kBAAkB,QAAQ;AAIvE,KAAI,cACF,QAAO;AAKT,KAAI,wBAAwB,KAC1B,QAAO;AAMT,KAAI;AACF,iBAAe,QAAQ,WAAW;AAClC,wBAAsB;AACtB,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,iBAAe,QAAQ,QAAQ;AAC/B,wBAAsB;AACtB,SAAO;UACA,QAAQ;AAKjB,KAAI;AACF,iBAAe,QAAQ,SAAS;AAChC,wBAAsB;AACtB,SAAO;UACA,QAAQ;AAMjB,uBAAsB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { detectExportedComponentName } from "./detectExportedComponentName.mjs";
|
|
2
|
+
import { detectFormatCommand } from "./detectFormatCommand.mjs";
|
|
2
3
|
import { transformJSFile } from "./transformJSFile.mjs";
|
|
3
4
|
import { writeJSFile } from "./writeJSFile.mjs";
|
|
4
5
|
import { writeContentDeclaration } from "./writeContentDeclaration.mjs";
|
|
5
6
|
|
|
6
|
-
export { detectExportedComponentName, transformJSFile, writeContentDeclaration, writeJSFile };
|
|
7
|
+
export { detectExportedComponentName, detectFormatCommand, transformJSFile, writeContentDeclaration, writeJSFile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processContentDeclarationContent.mjs","names":["
|
|
1
|
+
{"version":3,"file":"processContentDeclarationContent.mjs","names":["deepTransformNode"],"sources":["../../../src/writeContentDeclaration/processContentDeclarationContent.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { colorizePath, x } from '@intlayer/config';\nimport {\n deepTransformNode,\n type FileContent,\n type FileContentConstructor,\n type InsertionContent,\n type InsertionContentConstructor,\n type MarkdownContent,\n type MarkdownContentConstructor,\n type Plugins,\n} from '@intlayer/core';\nimport { type Dictionary, NodeType } from '@intlayer/types';\n\n/**\n * Write file plugin\n */\n\nconst writeFilePlugin: Plugins = {\n id: 'write-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent) => {\n const fileContent = node.content;\n const filePath = node.fixedPath;\n\n if (typeof fileContent !== 'string') {\n throw new Error('File content must be a string');\n }\n\n if (typeof filePath !== 'string') {\n throw new Error('File path must be a string');\n }\n\n // Write the file to the file system\n try {\n const absoluteFilePath = join(process.cwd(), filePath);\n\n // Create the file directory if it doesn't exist\n const fileDirectory = dirname(absoluteFilePath);\n\n if (!existsSync(fileDirectory)) {\n mkdirSync(fileDirectory, { recursive: true });\n }\n\n // Write the file\n writeFileSync(absoluteFilePath, fileContent);\n } catch (error) {\n throw new Error(\n `${x} Error writing file to ${colorizePath(filePath)}: ${error}`\n );\n }\n\n const transformedFileContent: FileContentConstructor = {\n nodeType: NodeType.File,\n [NodeType.File]: node.file,\n };\n\n return transformedFileContent;\n },\n};\n\n/**\n * Markdown file plugin\n */\n\nconst markdownFilePlugin: Plugins = {\n id: 'markdown-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Markdown,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const simplifiedMarkdownNode: MarkdownContentConstructor = {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: deepTransformNode(node.markdown, props),\n };\n\n return simplifiedMarkdownNode;\n },\n};\n\n/**\n * Insertion file plugin\n */\n\nconst insertionFilePlugin: Plugins = {\n id: 'insertion-file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const simplifiedInsertionNode: InsertionContentConstructor = {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: deepTransformNode(node.insertion, props),\n };\n\n return simplifiedInsertionNode;\n },\n};\n\nexport const processContentDeclarationContent = async (\n dictionary: Dictionary\n) =>\n deepTransformNode(dictionary, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [writeFilePlugin, markdownFilePlugin, insertionFilePlugin],\n });\n"],"mappings":";;;;;;;;;;AAmBA,MAAM,kBAA2B;CAC/B,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;CAC1D,YAAY,SAAsB;EAChC,MAAM,cAAc,KAAK;EACzB,MAAM,WAAW,KAAK;AAEtB,MAAI,OAAO,gBAAgB,SACzB,OAAM,IAAI,MAAM,gCAAgC;AAGlD,MAAI,OAAO,aAAa,SACtB,OAAM,IAAI,MAAM,6BAA6B;AAI/C,MAAI;GACF,MAAM,mBAAmB,KAAK,QAAQ,KAAK,EAAE,SAAS;GAGtD,MAAM,gBAAgB,QAAQ,iBAAiB;AAE/C,OAAI,CAAC,WAAW,cAAc,CAC5B,WAAU,eAAe,EAAE,WAAW,MAAM,CAAC;AAI/C,iBAAc,kBAAkB,YAAY;WACrC,OAAO;AACd,SAAM,IAAI,MACR,GAAG,EAAE,yBAAyB,aAAa,SAAS,CAAC,IAAI,QAC1D;;AAQH,SALuD;GACrD,UAAU,SAAS;IAClB,SAAS,OAAO,KAAK;GACvB;;CAIJ;;;;AAMD,MAAM,qBAA8B;CAClC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;CAC1D,YAAY,MAAuB,OAAO,wBAAsB;AAM9D,SAL2D;GACzD,UAAU,SAAS;IAClB,SAAS,WAAWA,oBAAkB,KAAK,UAAU,MAAM;GAC7D;;CAIJ;;;;AAMD,MAAM,sBAA+B;CACnC,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;CAC1D,YAAY,MAAwB,OAAO,wBAAsB;AAM/D,SAL6D;GAC3D,UAAU,SAAS;I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