@intlayer/chokidar 8.1.9 → 8.1.10
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/watcher.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./prepareIntlayer.cjs`),t=require(`./writeContentDeclaration/writeContentDeclaration.cjs`),n=require(`./handleAdditionalContentDeclarationFile.cjs`),r=require(`./handleContentDeclarationFileChange.cjs`),i=require(`./handleContentDeclarationFileMoved.cjs`),a=require(`./handleUnlinkedContentDeclarationFile.cjs`);let o=require(`@intlayer/config/node`),s=require(`node:fs/promises`),c=require(`node:path`),l=require(`@intlayer/config/logger`),u=require(`@intlayer/config/utils`),d=require(`chokidar`);const f=new Map;let p=Promise.resolve();const m=e=>{p=p.then(async()=>{try{await e()}catch(e){console.error(e)}})},h=p=>{let h=(0,o.getConfigurationAndFilePath)(p?.configOptions),g=h.configurationFilePath,_=p?.configuration??h.configuration,v=(0,l.getAppLogger)(_)
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./prepareIntlayer.cjs`),t=require(`./writeContentDeclaration/writeContentDeclaration.cjs`),n=require(`./handleAdditionalContentDeclarationFile.cjs`),r=require(`./handleContentDeclarationFileChange.cjs`),i=require(`./handleContentDeclarationFileMoved.cjs`),a=require(`./handleUnlinkedContentDeclarationFile.cjs`);let o=require(`@intlayer/config/node`),s=require(`node:fs/promises`),c=require(`node:path`),l=require(`@intlayer/config/logger`),u=require(`@intlayer/config/utils`),d=require(`chokidar`);const f=new Map;let p=Promise.resolve();const m=e=>{p=p.then(async()=>{try{await e()}catch(e){console.error(e)}})},h=p=>{let h=(0,o.getConfigurationAndFilePath)(p?.configOptions),g=h.configurationFilePath,_=p?.configuration??h.configuration,v=(0,l.getAppLogger)(_),{watch:y,watchedFilesPatternWithPath:b,fileExtensions:x}=_.content;return(0,d.watch)([...Array.isArray(b)?b:[b],...g?[g]:[]],{persistent:y,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:1e3,pollInterval:100},ignored:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.intlayer/**`],...p}).on(`add`,async e=>{let r=(0,c.basename)(e),a=!1,o;for(let[e]of f)if((0,c.basename)(e)===r){o=e;break}if(!o&&f.size===1&&(o=f.keys().next().value),o){let t=f.get(o);t&&(clearTimeout(t.timer),f.delete(o)),a=!0,v(`File moved from ${o} to ${e}`)}m(async()=>{if(a&&o)await i.handleContentDeclarationFileMoved(o,e,_);else{if(await(0,s.readFile)(e,`utf-8`)===``){let n=x.map(e=>e.replace(/\./g,`\\.`)).join(`|`);await t.writeContentDeclaration({key:r.replace(RegExp(`(${n})$`),``),content:{},filePath:e},_)}await n.handleAdditionalContentDeclarationFile(e,_)}})}).on(`change`,async t=>m(async()=>{if(g&&t===g){v(`Configuration file changed, repreparing Intlayer`),(0,u.clearModuleCache)(g),(0,u.clearAllCache)();let{configuration:t}=(0,o.getConfigurationAndFilePath)(p?.configOptions);_=p?.configuration??t,await e.prepareIntlayer(_,{clean:!1})}else await r.handleContentDeclarationFileChange(t,_)})).on(`unlink`,async e=>{let t=setTimeout(async()=>{f.delete(e),m(async()=>a.handleUnlinkedContentDeclarationFile(e,_))},200);f.set(e,{timer:t,oldPath:e})}).on(`error`,async t=>{v(`Watcher error: ${t}`,{level:`error`}),v(`Restarting watcher`),await e.prepareIntlayer(_)})},g=async t=>{let{skipPrepare:n,...r}=t??{},i=t?.configuration??(0,o.getConfiguration)(t?.configOptions);n||await e.prepareIntlayer(i,{forceRun:!0}),(i.content.watch||t?.persistent)&&((0,l.getAppLogger)(i)(`Watching Intlayer content declarations`),h({...r,configuration:i}))};exports.buildAndWatchIntlayer=g,exports.watch=h;
|
|
2
2
|
//# sourceMappingURL=watcher.cjs.map
|
package/dist/cjs/watcher.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.cjs","names":["handleContentDeclarationFileMoved","writeContentDeclaration","handleAdditionalContentDeclarationFile","prepareIntlayer","handleContentDeclarationFileChange","handleUnlinkedContentDeclarationFile"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n getConfigurationAndFilePath,\n} from '@intlayer/config/node';\nimport { clearAllCache, clearModuleCache } from '@intlayer/config/utils';\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\n// Task queue to ensure sequential processing of file events\nlet processingQueue = Promise.resolve();\nconst processEvent = (task: () => Promise<void>) => {\n processingQueue = processingQueue.then(async () => {\n try {\n await task();\n } catch (error) {\n console.error(error);\n }\n });\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 configResult = getConfigurationAndFilePath(options?.configOptions);\n const configurationFilePath = configResult.configurationFilePath;\n let configuration: IntlayerConfig =\n options?.configuration ?? configResult.configuration;\n const appLogger = getAppLogger(configuration);\n\n
|
|
1
|
+
{"version":3,"file":"watcher.cjs","names":["handleContentDeclarationFileMoved","writeContentDeclaration","handleAdditionalContentDeclarationFile","prepareIntlayer","handleContentDeclarationFileChange","handleUnlinkedContentDeclarationFile"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n getConfigurationAndFilePath,\n} from '@intlayer/config/node';\nimport { clearAllCache, clearModuleCache } from '@intlayer/config/utils';\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\n// Task queue to ensure sequential processing of file events\nlet processingQueue = Promise.resolve();\nconst processEvent = (task: () => Promise<void>) => {\n processingQueue = processingQueue.then(async () => {\n try {\n await task();\n } catch (error) {\n console.error(error);\n }\n });\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 configResult = getConfigurationAndFilePath(options?.configOptions);\n const configurationFilePath = configResult.configurationFilePath;\n let configuration: IntlayerConfig =\n options?.configuration ?? configResult.configuration;\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n const pathsToWatch = [\n ...(Array.isArray(watchedFilesPatternWithPath)\n ? watchedFilesPatternWithPath\n : [watchedFilesPatternWithPath]),\n ...(configurationFilePath ? [configurationFilePath] : []),\n ];\n\n return chokidarWatch(pathsToWatch, {\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\n processEvent(async () => {\n if (isMove && matchedOldPath) {\n await handleContentDeclarationFileMoved(\n matchedOldPath,\n filePath,\n configuration\n );\n } else {\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 await handleAdditionalContentDeclarationFile(filePath, configuration);\n }\n });\n })\n .on('change', async (filePath) =>\n processEvent(async () => {\n if (configurationFilePath && filePath === configurationFilePath) {\n appLogger('Configuration file changed, repreparing Intlayer');\n\n clearModuleCache(configurationFilePath);\n clearAllCache();\n\n const { configuration: newConfiguration } =\n getConfigurationAndFilePath(options?.configOptions);\n\n configuration = options?.configuration ?? newConfiguration;\n\n await prepareIntlayer(configuration, { clean: false });\n } else {\n await handleContentDeclarationFileChange(filePath, configuration);\n }\n })\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 processEvent(async () =>\n handleUnlinkedContentDeclarationFile(filePath, configuration)\n );\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":"mnBAoBA,MAAM,EAAiB,IAAI,IAM3B,IAAI,EAAkB,QAAQ,SAAS,CACvC,MAAM,EAAgB,GAA8B,CAClD,EAAkB,EAAgB,KAAK,SAAY,CACjD,GAAI,CACF,MAAM,GAAM,OACL,EAAO,CACd,Q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./prepareIntlayer.mjs";import{writeContentDeclaration as t}from"./writeContentDeclaration/writeContentDeclaration.mjs";import{handleAdditionalContentDeclarationFile as n}from"./handleAdditionalContentDeclarationFile.mjs";import{handleContentDeclarationFileChange as r}from"./handleContentDeclarationFileChange.mjs";import{handleContentDeclarationFileMoved as i}from"./handleContentDeclarationFileMoved.mjs";import{handleUnlinkedContentDeclarationFile as a}from"./handleUnlinkedContentDeclarationFile.mjs";import{getConfiguration as o,getConfigurationAndFilePath as s}from"@intlayer/config/node";import{readFile as c}from"node:fs/promises";import{basename as l}from"node:path";import{getAppLogger as u}from"@intlayer/config/logger";import{clearAllCache as d,clearModuleCache as f}from"@intlayer/config/utils";import{watch as p}from"chokidar";const m=new Map;let h=Promise.resolve();const g=e=>{h=h.then(async()=>{try{await e()}catch(e){console.error(e)}})},_=o=>{let h=s(o?.configOptions),_=h.configurationFilePath,v=o?.configuration??h.configuration,y=u(v)
|
|
1
|
+
import{prepareIntlayer as e}from"./prepareIntlayer.mjs";import{writeContentDeclaration as t}from"./writeContentDeclaration/writeContentDeclaration.mjs";import{handleAdditionalContentDeclarationFile as n}from"./handleAdditionalContentDeclarationFile.mjs";import{handleContentDeclarationFileChange as r}from"./handleContentDeclarationFileChange.mjs";import{handleContentDeclarationFileMoved as i}from"./handleContentDeclarationFileMoved.mjs";import{handleUnlinkedContentDeclarationFile as a}from"./handleUnlinkedContentDeclarationFile.mjs";import{getConfiguration as o,getConfigurationAndFilePath as s}from"@intlayer/config/node";import{readFile as c}from"node:fs/promises";import{basename as l}from"node:path";import{getAppLogger as u}from"@intlayer/config/logger";import{clearAllCache as d,clearModuleCache as f}from"@intlayer/config/utils";import{watch as p}from"chokidar";const m=new Map;let h=Promise.resolve();const g=e=>{h=h.then(async()=>{try{await e()}catch(e){console.error(e)}})},_=o=>{let h=s(o?.configOptions),_=h.configurationFilePath,v=o?.configuration??h.configuration,y=u(v),{watch:b,watchedFilesPatternWithPath:x,fileExtensions:S}=v.content;return p([...Array.isArray(x)?x:[x],..._?[_]:[]],{persistent:b,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:1e3,pollInterval:100},ignored:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.intlayer/**`],...o}).on(`add`,async e=>{let r=l(e),a=!1,o;for(let[e]of m)if(l(e)===r){o=e;break}if(!o&&m.size===1&&(o=m.keys().next().value),o){let t=m.get(o);t&&(clearTimeout(t.timer),m.delete(o)),a=!0,y(`File moved from ${o} to ${e}`)}g(async()=>{if(a&&o)await i(o,e,v);else{if(await c(e,`utf-8`)===``){let n=S.map(e=>e.replace(/\./g,`\\.`)).join(`|`);await t({key:r.replace(RegExp(`(${n})$`),``),content:{},filePath:e},v)}await n(e,v)}})}).on(`change`,async t=>g(async()=>{if(_&&t===_){y(`Configuration file changed, repreparing Intlayer`),f(_),d();let{configuration:t}=s(o?.configOptions);v=o?.configuration??t,await e(v,{clean:!1})}else await r(t,v)})).on(`unlink`,async e=>{let t=setTimeout(async()=>{m.delete(e),g(async()=>a(e,v))},200);m.set(e,{timer:t,oldPath:e})}).on(`error`,async t=>{y(`Watcher error: ${t}`,{level:`error`}),y(`Restarting watcher`),await e(v)})},v=async t=>{let{skipPrepare:n,...r}=t??{},i=t?.configuration??o(t?.configOptions);n||await e(i,{forceRun:!0}),(i.content.watch||t?.persistent)&&(u(i)(`Watching Intlayer content declarations`),_({...r,configuration:i}))};export{v as buildAndWatchIntlayer,_ as watch};
|
|
2
2
|
//# sourceMappingURL=watcher.mjs.map
|
package/dist/esm/watcher.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n getConfigurationAndFilePath,\n} from '@intlayer/config/node';\nimport { clearAllCache, clearModuleCache } from '@intlayer/config/utils';\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\n// Task queue to ensure sequential processing of file events\nlet processingQueue = Promise.resolve();\nconst processEvent = (task: () => Promise<void>) => {\n processingQueue = processingQueue.then(async () => {\n try {\n await task();\n } catch (error) {\n console.error(error);\n }\n });\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 configResult = getConfigurationAndFilePath(options?.configOptions);\n const configurationFilePath = configResult.configurationFilePath;\n let configuration: IntlayerConfig =\n options?.configuration ?? configResult.configuration;\n const appLogger = getAppLogger(configuration);\n\n
|
|
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 { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n getConfigurationAndFilePath,\n} from '@intlayer/config/node';\nimport { clearAllCache, clearModuleCache } from '@intlayer/config/utils';\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\n// Task queue to ensure sequential processing of file events\nlet processingQueue = Promise.resolve();\nconst processEvent = (task: () => Promise<void>) => {\n processingQueue = processingQueue.then(async () => {\n try {\n await task();\n } catch (error) {\n console.error(error);\n }\n });\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 configResult = getConfigurationAndFilePath(options?.configOptions);\n const configurationFilePath = configResult.configurationFilePath;\n let configuration: IntlayerConfig =\n options?.configuration ?? configResult.configuration;\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n const pathsToWatch = [\n ...(Array.isArray(watchedFilesPatternWithPath)\n ? watchedFilesPatternWithPath\n : [watchedFilesPatternWithPath]),\n ...(configurationFilePath ? [configurationFilePath] : []),\n ];\n\n return chokidarWatch(pathsToWatch, {\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\n processEvent(async () => {\n if (isMove && matchedOldPath) {\n await handleContentDeclarationFileMoved(\n matchedOldPath,\n filePath,\n configuration\n );\n } else {\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 await handleAdditionalContentDeclarationFile(filePath, configuration);\n }\n });\n })\n .on('change', async (filePath) =>\n processEvent(async () => {\n if (configurationFilePath && filePath === configurationFilePath) {\n appLogger('Configuration file changed, repreparing Intlayer');\n\n clearModuleCache(configurationFilePath);\n clearAllCache();\n\n const { configuration: newConfiguration } =\n getConfigurationAndFilePath(options?.configOptions);\n\n configuration = options?.configuration ?? newConfiguration;\n\n await prepareIntlayer(configuration, { clean: false });\n } else {\n await handleContentDeclarationFileChange(filePath, configuration);\n }\n })\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 processEvent(async () =>\n handleUnlinkedContentDeclarationFile(filePath, configuration)\n );\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":"02BAoBA,MAAM,EAAiB,IAAI,IAM3B,IAAI,EAAkB,QAAQ,SAAS,CACvC,MAAM,EAAgB,GAA8B,CAClD,EAAkB,EAAgB,KAAK,SAAY,CACjD,GAAI,CACF,MAAM,GAAM,OACL,EAAO,CACd,QAAQ,MAAM,EAAM,GAEtB,EAUS,EAAS,GAA2B,CAC/C,IAAM,EAAe,EAA4B,GAAS,cAAc,CAClE,EAAwB,EAAa,sBACvC,EACF,GAAS,eAAiB,EAAa,cACnC,EAAY,EAAa,EAAc,CAEvC,CACJ,MAAO,EACP,8BACA,kBACE,EAAc,QASlB,OAAOA,EAPc,CACnB,GAAI,MAAM,QAAQ,EAA4B,CAC1C,EACA,CAAC,EAA4B,CACjC,GAAI,EAAwB,CAAC,EAAsB,CAAG,EAAE,CACzD,CAEkC,CACjC,WAAY,EACZ,cAAe,GACf,iBAAkB,CAChB,mBAAoB,IACpB,aAAc,IACf,CACD,QAAS,CACP,qBACA,aACA,cACA,kBACD,CACD,GAAG,EACJ,CAAC,CACC,GAAG,MAAO,KA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AAO,QAAS,EAAU,CAAC,EAC1D,CACD,GAAG,QAAS,KAAO,IAAU,CAC5B,EAAU,kBAAkB,IAAS,CACnC,MAAO,QACR,CAAC,CAEF,EAAU,qBAAqB,CAE/B,MAAM,EAAgB,EAAc,EACpC,EAGO,EAAwB,KAAO,IAA2B,CACrE,GAAM,CAAE,cAAa,GAAG,GAAS,GAAW,EAAE,CACxC,EACJ,GAAS,eAAiB,EAAiB,GAAS,cAAc,CAE/D,GACH,MAAM,EAAgB,EAAe,CAAE,SAAU,GAAM,CAAC,EAGtD,EAAc,QAAQ,OAAS,GAAS,cACxB,EAAa,EAAc,CAEnC,yCAAyC,CACnD,EAAM,CAAE,GAAG,EAAM,gBAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","names":[],"sources":["../../src/watcher.ts"],"mappings":";;;;;;KAqCK,YAAA,GAAe,eAAA;EAClB,aAAA,GAAgB,cAAA;EAChB,aAAA,GAAgB,uBAAA;EAChB,WAAA;AAAA;AAAA,cAIW,KAAA,GAAS,OAAA,GAAU,YAAA,KAAY,QAAA,CAAA,SAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","names":[],"sources":["../../src/watcher.ts"],"mappings":";;;;;;KAqCK,YAAA,GAAe,eAAA;EAClB,aAAA,GAAgB,cAAA;EAChB,aAAA,GAAgB,uBAAA;EAChB,WAAA;AAAA;AAAA,cAIW,KAAA,GAAS,OAAA,GAAU,YAAA,KAAY,QAAA,CAAA,SAAA;AAAA,cAmJ/B,qBAAA,GAA+B,OAAA,GAAU,YAAA,KAAY,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/chokidar",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.",
|
|
6
6
|
"keywords": [
|
|
@@ -101,24 +101,24 @@
|
|
|
101
101
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@intlayer/api": "8.1.
|
|
105
|
-
"@intlayer/config": "8.1.
|
|
106
|
-
"@intlayer/core": "8.1.
|
|
107
|
-
"@intlayer/dictionaries-entry": "8.1.
|
|
108
|
-
"@intlayer/remote-dictionaries-entry": "8.1.
|
|
109
|
-
"@intlayer/types": "8.1.
|
|
110
|
-
"@intlayer/unmerged-dictionaries-entry": "8.1.
|
|
104
|
+
"@intlayer/api": "8.1.10",
|
|
105
|
+
"@intlayer/config": "8.1.10",
|
|
106
|
+
"@intlayer/core": "8.1.10",
|
|
107
|
+
"@intlayer/dictionaries-entry": "8.1.10",
|
|
108
|
+
"@intlayer/remote-dictionaries-entry": "8.1.10",
|
|
109
|
+
"@intlayer/types": "8.1.10",
|
|
110
|
+
"@intlayer/unmerged-dictionaries-entry": "8.1.10",
|
|
111
111
|
"chokidar": "3.6.0",
|
|
112
112
|
"crypto-js": "4.2.0",
|
|
113
113
|
"defu": "6.1.4",
|
|
114
114
|
"fast-glob": "3.3.3",
|
|
115
|
-
"simple-git": "3.
|
|
115
|
+
"simple-git": "3.32.3",
|
|
116
116
|
"ts-morph": "27.0.2",
|
|
117
117
|
"zod-to-ts": "2.0.0"
|
|
118
118
|
},
|
|
119
119
|
"devDependencies": {
|
|
120
120
|
"@types/crypto-js": "4.2.2",
|
|
121
|
-
"@types/node": "25.3.
|
|
121
|
+
"@types/node": "25.3.3",
|
|
122
122
|
"@utils/ts-config": "1.0.4",
|
|
123
123
|
"@utils/ts-config-types": "1.0.4",
|
|
124
124
|
"@utils/tsdown-config": "1.0.4",
|
|
@@ -129,8 +129,8 @@
|
|
|
129
129
|
"zod": "4.3.6"
|
|
130
130
|
},
|
|
131
131
|
"peerDependencies": {
|
|
132
|
-
"@intlayer/svelte-transformer": "8.1.
|
|
133
|
-
"@intlayer/vue-transformer": "8.1.
|
|
132
|
+
"@intlayer/svelte-transformer": "8.1.10",
|
|
133
|
+
"@intlayer/vue-transformer": "8.1.10"
|
|
134
134
|
},
|
|
135
135
|
"peerDependenciesMeta": {
|
|
136
136
|
"@intlayer/svelte-transformer": {
|