@intlayer/chokidar 8.4.1 → 8.4.2
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/listDictionariesPath.cjs +1 -1
- package/dist/cjs/listDictionariesPath.cjs.map +1 -1
- package/dist/cjs/utils/buildComponentFilesList.cjs +1 -1
- package/dist/cjs/utils/buildComponentFilesList.cjs.map +1 -1
- package/dist/cjs/watcher.cjs +1 -1
- package/dist/cjs/watcher.cjs.map +1 -1
- package/dist/esm/listDictionariesPath.mjs +1 -1
- package/dist/esm/listDictionariesPath.mjs.map +1 -1
- package/dist/esm/utils/buildComponentFilesList.mjs +1 -1
- package/dist/esm/utils/buildComponentFilesList.mjs.map +1 -1
- package/dist/esm/watcher.mjs +1 -1
- package/dist/esm/watcher.mjs.map +1 -1
- package/dist/types/listDictionariesPath.d.ts.map +1 -1
- package/dist/types/watcher.d.ts.map +1 -1
- package/package.json +16 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`node:fs/promises`),n=require(`fast-glob`);n=e.t(n);
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`node:fs/promises`),n=require(`fast-glob`);n=e.t(n);let r=require(`@intlayer/config/utils`);const i=async e=>{let{fileExtensions:t,contentDir:i,excludedPath:a}=e.content,o=t.flatMap(e=>i.map(t=>`${(0,r.normalizePath)(t)}/**/*${e}`.replace(`//`,`/`))).map(async e=>{let t=e.search(/[*?{}(]/),r=t>-1?e.slice(0,t):e;return(0,n.default)(e,{ignore:a.filter(e=>{let t=e.replace(/\*\*/g,``).replace(/\//g,``);return!(t&&r.includes(`/${t}/`))}),absolute:!0,dot:!0})}),s=await Promise.all(o);return Array.from(new Set(s.flat()))},a=async e=>{let n=await i(e);return Promise.all(n.map(async e=>({path:e,stats:await(0,t.stat)(e)})))};exports.listDictionaries=i,exports.listDictionariesWithStats=a;
|
|
2
2
|
//# sourceMappingURL=listDictionariesPath.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listDictionariesPath.cjs","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":["import { stat } from 'node:fs/promises';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * List all dictionaries absolute paths in the project\n * @param configuration - The configuration object\n * @returns An array of dictionary paths\n */\nexport const listDictionaries = async (\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const {
|
|
1
|
+
{"version":3,"file":"listDictionariesPath.cjs","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":["import { stat } from 'node:fs/promises';\nimport { normalizePath } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * List all dictionaries absolute paths in the project\n * @param configuration - The configuration object\n * @returns An array of dictionary paths\n */\nexport const listDictionaries = async (\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const { fileExtensions, contentDir, excludedPath } = configuration.content;\n\n const watchedFilesPatternWithPath = fileExtensions.flatMap((ext) =>\n contentDir.map((dir) =>\n `${normalizePath(dir)}/**/*${ext}`.replace('//', '/')\n )\n );\n\n const filePromises = watchedFilesPatternWithPath.map(async (pattern) => {\n // Identify the static part of the path (before any wildcards like *)\n // e.g. \"/Users/.../design-system/dist/esm/**/*.content.ts\" -> \"/Users/.../design-system/dist/esm/\"\n const magicIndex = pattern.search(/[*?{}(]/);\n const basePattern =\n magicIndex > -1 ? pattern.slice(0, magicIndex) : pattern;\n\n // Filter the global ignored list for this specific pattern\n const applicableIgnore = excludedPath.filter((excludePattern) => {\n // Heuristic: Extract the key directory name from the glob\n // e.g. \"**/dist/**\" -> \"dist\", \"**/node_modules/**\" -> \"node_modules\"\n const cleanName = excludePattern.replace(/\\*\\*/g, '').replace(/\\//g, '');\n\n // If the explicit base path contains the excluded directory (e.g. \".../dist/...\"),\n // we assume you explicitly want it, so we REMOVE it from the ignore list.\n // We check for `/${cleanName}/` to ensure we match whole folder names.\n if (cleanName && basePattern.includes(`/${cleanName}/`)) {\n return false; // Drop this exclude rule\n }\n\n return true; // Keep this exclude rule\n });\n\n // Run fast-glob with the customized ignore list\n return fg(pattern, {\n ignore: applicableIgnore,\n absolute: true,\n dot: true,\n });\n });\n\n const filesArrays = await Promise.all(filePromises);\n\n // Flatten and deduplicate\n const uniqueFiles = Array.from(new Set(filesArrays.flat()));\n\n return uniqueFiles;\n};\n\nexport const listDictionariesWithStats = async (\n configuration: IntlayerConfig\n) => {\n const files = await listDictionaries(configuration);\n\n return Promise.all(\n files.map(async (file) => ({ path: file, stats: await stat(file) }))\n );\n};\n"],"mappings":"qNAUA,MAAa,EAAmB,KAC9B,IACsB,CACtB,GAAM,CAAE,iBAAgB,aAAY,gBAAiB,EAAc,QAQ7D,EAN8B,EAAe,QAAS,GAC1D,EAAW,IAAK,GACd,IAAA,EAAA,EAAA,eAAiB,EAAI,CAAC,OAAO,IAAM,QAAQ,KAAM,IAAI,CACtD,CACF,CAEgD,IAAI,KAAO,IAAY,CAGtE,IAAM,EAAa,EAAQ,OAAO,UAAU,CACtC,EACJ,EAAa,GAAK,EAAQ,MAAM,EAAG,EAAW,CAAG,EAmBnD,OAAA,EAAA,EAAA,SAAU,EAAS,CACjB,OAjBuB,EAAa,OAAQ,GAAmB,CAG/D,IAAM,EAAY,EAAe,QAAQ,QAAS,GAAG,CAAC,QAAQ,MAAO,GAAG,CASxE,MAJA,EAAI,GAAa,EAAY,SAAS,IAAI,EAAU,GAAG,GAKvD,CAKA,SAAU,GACV,IAAK,GACN,CAAC,EACF,CAEI,EAAc,MAAM,QAAQ,IAAI,EAAa,CAKnD,OAFoB,MAAM,KAAK,IAAI,IAAI,EAAY,MAAM,CAAC,CAAC,EAKhD,EAA4B,KACvC,IACG,CACH,IAAM,EAAQ,MAAM,EAAiB,EAAc,CAEnD,OAAO,QAAQ,IACb,EAAM,IAAI,KAAO,KAAU,CAAE,KAAM,EAAM,MAAO,MAAA,EAAA,EAAA,MAAW,EAAK,CAAE,EAAE,CACrE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`node:path`),n=require(`fast-glob`);n=e.t(n);const r=e=>Array.isArray(e)?e:[e],i=e=>{let n=Array.from(new Set(e.map(e=>(0,t.resolve)(e))));return n.sort((e,t)=>e.length-t.length),n.reduce((e,n)=>(e.some(e=>{let r=(0,t.relative)(e,n);return!r.startsWith(`..`)&&!(0,t.isAbsolute)(r)&&r!==``})||e.push(n),e),[])},a=(e,a)=>{let o=e.build.traversePattern,s=e.compiler.transformPattern,c=e.content.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`node:path`),n=require(`fast-glob`);n=e.t(n);const r=e=>Array.isArray(e)?e:[e],i=e=>{let n=Array.from(new Set(e.map(e=>(0,t.resolve)(e))));return n.sort((e,t)=>e.length-t.length),n.reduce((e,n)=>(e.some(e=>{let r=(0,t.relative)(e,n);return!r.startsWith(`..`)&&!(0,t.isAbsolute)(r)&&r!==``})||e.push(n),e),[])},a=(e,a)=>{let o=e.build.traversePattern,s=e.compiler.transformPattern,c=e.content.fileExtensions.map(e=>`/**/*${e}`),l=[...o,...r(s)].filter(e=>typeof e==`string`).filter(e=>!e.startsWith(`!`)).map(e=>(0,t.normalize)(e)),u=[...a??[],...c,...o.filter(e=>typeof e==`string`&&e.startsWith(`!`)).map(e=>e.slice(1))].filter(e=>typeof e==`string`).map(e=>(0,t.normalize)(e)),d=i([e.system.baseDir,...e.content.codeDir]).flatMap(e=>n.default.sync(l,{cwd:e,ignore:u,absolute:!0,dot:!0}));return Array.from(new Set(d))};exports.buildComponentFilesList=a;
|
|
2
2
|
//# sourceMappingURL=buildComponentFilesList.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildComponentFilesList.cjs","names":["fg"],"sources":["../../../src/utils/buildComponentFilesList.ts"],"sourcesContent":["import { isAbsolute, normalize, relative, resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] =>\n Array.isArray(value) ? value : [value];\n\n/**\n * Remove directories that are subdirectories of others in the list so files\n * are never scanned twice.\n * Example: ['/root', '/root/src'] → ['/root']\n */\nconst getDistinctRootDirs = (dirs: string[]): string[] => {\n const uniqueDirs = Array.from(new Set(dirs.map((dir) => resolve(dir))));\n uniqueDirs.sort((a, b) => a.length - b.length);\n\n return uniqueDirs.reduce((acc: string[], dir) => {\n const isNested = acc.some((parent) => {\n const rel = relative(parent, dir);\n\n return !rel.startsWith('..') && !isAbsolute(rel) && rel !== '';\n });\n if (!isNested) acc.push(dir);\n\n return acc;\n }, []);\n};\n\n/**\n * Builds a deduplicated list of absolute file paths matching the given patterns.\n *\n * Handles multiple root directories (deduplicates overlapping roots), exclude\n * patterns, negation patterns embedded in `transformPattern`, and optional\n * dot-file inclusion.\n *\n * @example\n * // Single root with excludes\n * const files = buildComponentFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // Multiple roots (e.g. baseDir + codeDir), dot files included\n * const files = buildComponentFilesList(config, ['**\\/node_modules\\/**']);\n */\nexport const buildComponentFilesList = (\n config: IntlayerConfig,\n excludePattern?: string[]\n): string[] => {\n const transformPattern = config.build.traversePattern;\n const compilerTransformPattern = config.compiler.transformPattern;\n const contentDeclarationPattern = config.content.
|
|
1
|
+
{"version":3,"file":"buildComponentFilesList.cjs","names":["fg"],"sources":["../../../src/utils/buildComponentFilesList.ts"],"sourcesContent":["import { isAbsolute, normalize, relative, resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] =>\n Array.isArray(value) ? value : [value];\n\n/**\n * Remove directories that are subdirectories of others in the list so files\n * are never scanned twice.\n * Example: ['/root', '/root/src'] → ['/root']\n */\nconst getDistinctRootDirs = (dirs: string[]): string[] => {\n const uniqueDirs = Array.from(new Set(dirs.map((dir) => resolve(dir))));\n uniqueDirs.sort((a, b) => a.length - b.length);\n\n return uniqueDirs.reduce((acc: string[], dir) => {\n const isNested = acc.some((parent) => {\n const rel = relative(parent, dir);\n\n return !rel.startsWith('..') && !isAbsolute(rel) && rel !== '';\n });\n if (!isNested) acc.push(dir);\n\n return acc;\n }, []);\n};\n\n/**\n * Builds a deduplicated list of absolute file paths matching the given patterns.\n *\n * Handles multiple root directories (deduplicates overlapping roots), exclude\n * patterns, negation patterns embedded in `transformPattern`, and optional\n * dot-file inclusion.\n *\n * @example\n * // Single root with excludes\n * const files = buildComponentFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // Multiple roots (e.g. baseDir + codeDir), dot files included\n * const files = buildComponentFilesList(config, ['**\\/node_modules\\/**']);\n */\nexport const buildComponentFilesList = (\n config: IntlayerConfig,\n excludePattern?: string[]\n): string[] => {\n const transformPattern = config.build.traversePattern;\n const compilerTransformPattern = config.compiler.transformPattern;\n const contentDeclarationPattern = config.content.fileExtensions.map(\n (ext) => `/**/*${ext}`\n );\n\n const patterns = [\n ...transformPattern,\n ...normalizeToArray(compilerTransformPattern),\n ]\n .filter((pattern) => typeof pattern === 'string')\n .filter((pattern) => !pattern.startsWith('!'))\n .map((pattern) => normalize(pattern)); // Ensure it works with Windows\n\n const excludePatterns = [\n ...(excludePattern ?? []),\n ...contentDeclarationPattern,\n // Treat negation entries in transformPattern as additional excludes\n ...transformPattern\n .filter(\n (pattern) => typeof pattern === 'string' && pattern.startsWith('!')\n )\n .map((pattern) => pattern.slice(1)),\n ]\n .filter((pattern) => typeof pattern === 'string')\n .map((pattern) => normalize(pattern)); // Ensure it works with Windows\n\n const roots = getDistinctRootDirs([\n config.system.baseDir,\n ...config.content.codeDir,\n ]);\n\n const fileList = roots.flatMap((root) =>\n fg.sync(patterns, {\n cwd: root,\n ignore: excludePatterns,\n absolute: true,\n dot: true, // include dot files like .next / .intlayer\n })\n );\n\n return Array.from(new Set(fileList));\n};\n"],"mappings":"uKAOA,MAAM,EAAuB,GAC3B,MAAM,QAAQ,EAAM,CAAG,EAAQ,CAAC,EAAM,CAOlC,EAAuB,GAA6B,CACxD,IAAM,EAAa,MAAM,KAAK,IAAI,IAAI,EAAK,IAAK,IAAA,EAAA,EAAA,SAAgB,EAAI,CAAC,CAAC,CAAC,CAGvE,OAFA,EAAW,MAAM,EAAG,IAAM,EAAE,OAAS,EAAE,OAAO,CAEvC,EAAW,QAAQ,EAAe,KACtB,EAAI,KAAM,GAAW,CACpC,IAAM,GAAA,EAAA,EAAA,UAAe,EAAQ,EAAI,CAEjC,MAAO,CAAC,EAAI,WAAW,KAAK,EAAI,EAAA,EAAA,EAAA,YAAY,EAAI,EAAI,IAAQ,IAC5D,EACa,EAAI,KAAK,EAAI,CAErB,GACN,EAAE,CAAC,EAsBK,GACX,EACA,IACa,CACb,IAAM,EAAmB,EAAO,MAAM,gBAChC,EAA2B,EAAO,SAAS,iBAC3C,EAA4B,EAAO,QAAQ,eAAe,IAC7D,GAAQ,QAAQ,IAClB,CAEK,EAAW,CACf,GAAG,EACH,GAAG,EAAiB,EAAyB,CAC9C,CACE,OAAQ,GAAY,OAAO,GAAY,SAAS,CAChD,OAAQ,GAAY,CAAC,EAAQ,WAAW,IAAI,CAAC,CAC7C,IAAK,IAAA,EAAA,EAAA,WAAsB,EAAQ,CAAC,CAEjC,EAAkB,CACtB,GAAI,GAAkB,EAAE,CACxB,GAAG,EAEH,GAAG,EACA,OACE,GAAY,OAAO,GAAY,UAAY,EAAQ,WAAW,IAAI,CACpE,CACA,IAAK,GAAY,EAAQ,MAAM,EAAE,CAAC,CACtC,CACE,OAAQ,GAAY,OAAO,GAAY,SAAS,CAChD,IAAK,IAAA,EAAA,EAAA,WAAsB,EAAQ,CAAC,CAOjC,EALQ,EAAoB,CAChC,EAAO,OAAO,QACd,GAAG,EAAO,QAAQ,QACnB,CAAC,CAEqB,QAAS,GAC9BA,EAAAA,QAAG,KAAK,EAAU,CAChB,IAAK,EACL,OAAQ,EACR,SAAU,GACV,IAAK,GACN,CAAC,CACH,CAED,OAAO,MAAM,KAAK,IAAI,IAAI,EAAS,CAAC"}
|
package/dist/cjs/watcher.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);const e=require(`./handleContentDeclarationFileChange.cjs`),t=require(`./handleContentDeclarationFileMoved.cjs`),n=require(`./handleAdditionalContentDeclarationFile.cjs`),r=require(`./handleUnlinkedContentDeclarationFile.cjs`),i=require(`./prepareIntlayer.cjs`),a=require(`./writeContentDeclaration/writeContentDeclaration.cjs`);require(`./writeContentDeclaration/index.cjs`);let o=require(`node:fs/promises`),s=require(`node:path`),c=require(`@intlayer/config/logger`),l=require(`@intlayer/config/node`),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,l.getConfigurationAndFilePath)(p?.configOptions),g=h.configurationFilePath,_=p?.configuration??h.configuration,v=(0,c.getAppLogger)(_),{watch:y,
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./chunk-Bmb41Sf3.cjs`);const e=require(`./handleContentDeclarationFileChange.cjs`),t=require(`./handleContentDeclarationFileMoved.cjs`),n=require(`./handleAdditionalContentDeclarationFile.cjs`),r=require(`./handleUnlinkedContentDeclarationFile.cjs`),i=require(`./prepareIntlayer.cjs`),a=require(`./writeContentDeclaration/writeContentDeclaration.cjs`);require(`./writeContentDeclaration/index.cjs`);let o=require(`node:fs/promises`),s=require(`node:path`),c=require(`@intlayer/config/logger`),l=require(`@intlayer/config/node`),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,l.getConfigurationAndFilePath)(p?.configOptions),g=h.configurationFilePath,_=p?.configuration??h.configuration,v=(0,c.getAppLogger)(_),{watch:y,fileExtensions:b,contentDir:x}=_.content,S=[...b.flatMap(e=>x.map(t=>`${(0,u.normalizePath)(t)}/**/*${e}`.replace(`//`,`/`))),...g?[g]:[]];if(_.content.watch)return v(`Watching Intlayer content declarations`),(0,d.watch)(S,{persistent:y,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:1e3,pollInterval:100},ignored:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.intlayer/**`],...p}).on(`add`,async e=>{let r=(0,s.basename)(e),i=!1,c;for(let[e]of f)if((0,s.basename)(e)===r){c=e;break}if(!c&&f.size===1&&(c=f.keys().next().value),c){let t=f.get(c);t&&(clearTimeout(t.timer),f.delete(c)),i=!0,v(`File moved from ${c} to ${e}`)}m(async()=>{if(i&&c)await t.handleContentDeclarationFileMoved(c,e,_);else{if(await(0,o.readFile)(e,`utf-8`)===``){let t=b.map(e=>e.replace(/\./g,`\\.`)).join(`|`);await a.writeContentDeclaration({key:r.replace(RegExp(`(${t})$`),``),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:e}=(0,l.getConfigurationAndFilePath)(p?.configOptions);_=p?.configuration??e,await i.prepareIntlayer(_,{clean:!1})}else await e.handleContentDeclarationFileChange(t,_)})).on(`unlink`,async e=>{let t=setTimeout(async()=>{f.delete(e),m(async()=>r.handleUnlinkedContentDeclarationFile(e,_))},200);f.set(e,{timer:t,oldPath:e})}).on(`error`,async e=>{v(`Watcher error: ${e}`,{level:`error`}),v(`Restarting watcher`),await i.prepareIntlayer(_)})},g=async e=>{let{skipPrepare:t,...n}=e??{},r=e?.configuration??(0,l.getConfiguration)(e?.configOptions);t||await i.prepareIntlayer(r,{forceRun:!0}),(r.content.watch||e?.persistent)&&h({...n,configuration:r})};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 {
|
|
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 {\n clearAllCache,\n clearModuleCache,\n normalizePath,\n} from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\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 fileExtensions,\n contentDir,\n } = configuration.content;\n\n const watchedFilesPatternWithPath = fileExtensions.flatMap((ext) =>\n contentDir.map((dir) =>\n `${normalizePath(dir)}/**/*${ext}`.replace('//', '/')\n )\n );\n\n const pathsToWatch = [\n ...watchedFilesPatternWithPath,\n ...(configurationFilePath ? [configurationFilePath] : []),\n ];\n\n if (!configuration.content.watch) return;\n\n appLogger('Watching Intlayer content declarations');\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 watch({ ...rest, configuration });\n }\n};\n"],"mappings":"spBAwBA,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,GAAA,EAAA,EAAA,6BAA2C,GAAS,cAAc,CAClE,EAAwB,EAAa,sBACvC,EACF,GAAS,eAAiB,EAAa,cACnC,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEvC,CACJ,MAAO,EACP,iBACA,cACE,EAAc,QAQZ,EAAe,CACnB,GAPkC,EAAe,QAAS,GAC1D,EAAW,IAAK,GACd,IAAA,EAAA,EAAA,eAAiB,EAAI,CAAC,OAAO,IAAM,QAAQ,KAAM,IAAI,CACtD,CACF,CAIC,GAAI,EAAw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A,gBAAe,CAEf,GAAM,CAAE,cAAe,IAAA,EAAA,EAAA,6BACO,GAAS,cAAc,CAErD,EAAgB,GAAS,eAAiB,EAE1C,MAAMC,EAAAA,gBAAgB,EAAe,CAAE,MAAO,GAAO,CAAC,MAEtD,MAAMC,EAAAA,mCAAmC,EAAU,EAAc,EAEnE,CACH,CACA,GAAG,SAAU,KAAO,IAAa,CAEhC,IAAM,EAAQ,WAAW,SAAY,CAEnC,EAAe,OAAO,EAAS,CAC/B,EAAa,SACXC,EAAAA,qCAAqC,EAAU,EAAc,CAC9D,EACA,IAAI,CAEP,EAAe,IAAI,EAAU,CAAE,QAAO,QAAS,EAAU,CAAC,EAC1D,CACD,GAAG,QAAS,KAAO,IAAU,CAC5B,EAAU,kBAAkB,IAAS,CACnC,MAAO,QACR,CAAC,CAEF,EAAU,qBAAqB,CAE/B,MAAMF,EAAAA,gBAAgB,EAAc,EACpC,EAGO,EAAwB,KAAO,IAA2B,CACrE,GAAM,CAAE,cAAa,GAAG,GAAS,GAAW,EAAE,CACxC,EACJ,GAAS,gBAAA,EAAA,EAAA,kBAAkC,GAAS,cAAc,CAE/D,GACH,MAAMA,EAAAA,gBAAgB,EAAe,CAAE,SAAU,GAAM,CAAC,EAGtD,EAAc,QAAQ,OAAS,GAAS,aAC1C,EAAM,CAAE,GAAG,EAAM,gBAAe,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{stat as e}from"node:fs/promises";import t from"fast-glob";const
|
|
1
|
+
import{stat as e}from"node:fs/promises";import t from"fast-glob";import{normalizePath as n}from"@intlayer/config/utils";const r=async e=>{let{fileExtensions:r,contentDir:i,excludedPath:a}=e.content,o=r.flatMap(e=>i.map(t=>`${n(t)}/**/*${e}`.replace(`//`,`/`))).map(async e=>{let n=e.search(/[*?{}(]/),r=n>-1?e.slice(0,n):e;return t(e,{ignore:a.filter(e=>{let t=e.replace(/\*\*/g,``).replace(/\//g,``);return!(t&&r.includes(`/${t}/`))}),absolute:!0,dot:!0})}),s=await Promise.all(o);return Array.from(new Set(s.flat()))},i=async t=>{let n=await r(t);return Promise.all(n.map(async t=>({path:t,stats:await e(t)})))};export{r as listDictionaries,i as listDictionariesWithStats};
|
|
2
2
|
//# sourceMappingURL=listDictionariesPath.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listDictionariesPath.mjs","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":["import { stat } from 'node:fs/promises';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * List all dictionaries absolute paths in the project\n * @param configuration - The configuration object\n * @returns An array of dictionary paths\n */\nexport const listDictionaries = async (\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const {
|
|
1
|
+
{"version":3,"file":"listDictionariesPath.mjs","names":[],"sources":["../../src/listDictionariesPath.ts"],"sourcesContent":["import { stat } from 'node:fs/promises';\nimport { normalizePath } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * List all dictionaries absolute paths in the project\n * @param configuration - The configuration object\n * @returns An array of dictionary paths\n */\nexport const listDictionaries = async (\n configuration: IntlayerConfig\n): Promise<string[]> => {\n const { fileExtensions, contentDir, excludedPath } = configuration.content;\n\n const watchedFilesPatternWithPath = fileExtensions.flatMap((ext) =>\n contentDir.map((dir) =>\n `${normalizePath(dir)}/**/*${ext}`.replace('//', '/')\n )\n );\n\n const filePromises = watchedFilesPatternWithPath.map(async (pattern) => {\n // Identify the static part of the path (before any wildcards like *)\n // e.g. \"/Users/.../design-system/dist/esm/**/*.content.ts\" -> \"/Users/.../design-system/dist/esm/\"\n const magicIndex = pattern.search(/[*?{}(]/);\n const basePattern =\n magicIndex > -1 ? pattern.slice(0, magicIndex) : pattern;\n\n // Filter the global ignored list for this specific pattern\n const applicableIgnore = excludedPath.filter((excludePattern) => {\n // Heuristic: Extract the key directory name from the glob\n // e.g. \"**/dist/**\" -> \"dist\", \"**/node_modules/**\" -> \"node_modules\"\n const cleanName = excludePattern.replace(/\\*\\*/g, '').replace(/\\//g, '');\n\n // If the explicit base path contains the excluded directory (e.g. \".../dist/...\"),\n // we assume you explicitly want it, so we REMOVE it from the ignore list.\n // We check for `/${cleanName}/` to ensure we match whole folder names.\n if (cleanName && basePattern.includes(`/${cleanName}/`)) {\n return false; // Drop this exclude rule\n }\n\n return true; // Keep this exclude rule\n });\n\n // Run fast-glob with the customized ignore list\n return fg(pattern, {\n ignore: applicableIgnore,\n absolute: true,\n dot: true,\n });\n });\n\n const filesArrays = await Promise.all(filePromises);\n\n // Flatten and deduplicate\n const uniqueFiles = Array.from(new Set(filesArrays.flat()));\n\n return uniqueFiles;\n};\n\nexport const listDictionariesWithStats = async (\n configuration: IntlayerConfig\n) => {\n const files = await listDictionaries(configuration);\n\n return Promise.all(\n files.map(async (file) => ({ path: file, stats: await stat(file) }))\n );\n};\n"],"mappings":"wHAUA,MAAa,EAAmB,KAC9B,IACsB,CACtB,GAAM,CAAE,iBAAgB,aAAY,gBAAiB,EAAc,QAQ7D,EAN8B,EAAe,QAAS,GAC1D,EAAW,IAAK,GACd,GAAG,EAAc,EAAI,CAAC,OAAO,IAAM,QAAQ,KAAM,IAAI,CACtD,CACF,CAEgD,IAAI,KAAO,IAAY,CAGtE,IAAM,EAAa,EAAQ,OAAO,UAAU,CACtC,EACJ,EAAa,GAAK,EAAQ,MAAM,EAAG,EAAW,CAAG,EAmBnD,OAAO,EAAG,EAAS,CACjB,OAjBuB,EAAa,OAAQ,GAAmB,CAG/D,IAAM,EAAY,EAAe,QAAQ,QAAS,GAAG,CAAC,QAAQ,MAAO,GAAG,CASxE,MAJA,EAAI,GAAa,EAAY,SAAS,IAAI,EAAU,GAAG,GAKvD,CAKA,SAAU,GACV,IAAK,GACN,CAAC,EACF,CAEI,EAAc,MAAM,QAAQ,IAAI,EAAa,CAKnD,OAFoB,MAAM,KAAK,IAAI,IAAI,EAAY,MAAM,CAAC,CAAC,EAKhD,EAA4B,KACvC,IACG,CACH,IAAM,EAAQ,MAAM,EAAiB,EAAc,CAEnD,OAAO,QAAQ,IACb,EAAM,IAAI,KAAO,KAAU,CAAE,KAAM,EAAM,MAAO,MAAM,EAAK,EAAK,CAAE,EAAE,CACrE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{isAbsolute as e,normalize as t,relative as n,resolve as r}from"node:path";import i from"fast-glob";const a=e=>Array.isArray(e)?e:[e],o=t=>{let i=Array.from(new Set(t.map(e=>r(e))));return i.sort((e,t)=>e.length-t.length),i.reduce((t,r)=>(t.some(t=>{let i=n(t,r);return!i.startsWith(`..`)&&!e(i)&&i!==``})||t.push(r),t),[])},s=(e,n)=>{let r=e.build.traversePattern,s=e.compiler.transformPattern,c=e.content.
|
|
1
|
+
import{isAbsolute as e,normalize as t,relative as n,resolve as r}from"node:path";import i from"fast-glob";const a=e=>Array.isArray(e)?e:[e],o=t=>{let i=Array.from(new Set(t.map(e=>r(e))));return i.sort((e,t)=>e.length-t.length),i.reduce((t,r)=>(t.some(t=>{let i=n(t,r);return!i.startsWith(`..`)&&!e(i)&&i!==``})||t.push(r),t),[])},s=(e,n)=>{let r=e.build.traversePattern,s=e.compiler.transformPattern,c=e.content.fileExtensions.map(e=>`/**/*${e}`),l=[...r,...a(s)].filter(e=>typeof e==`string`).filter(e=>!e.startsWith(`!`)).map(e=>t(e)),u=[...n??[],...c,...r.filter(e=>typeof e==`string`&&e.startsWith(`!`)).map(e=>e.slice(1))].filter(e=>typeof e==`string`).map(e=>t(e)),d=o([e.system.baseDir,...e.content.codeDir]).flatMap(e=>i.sync(l,{cwd:e,ignore:u,absolute:!0,dot:!0}));return Array.from(new Set(d))};export{s as buildComponentFilesList};
|
|
2
2
|
//# sourceMappingURL=buildComponentFilesList.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildComponentFilesList.mjs","names":[],"sources":["../../../src/utils/buildComponentFilesList.ts"],"sourcesContent":["import { isAbsolute, normalize, relative, resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] =>\n Array.isArray(value) ? value : [value];\n\n/**\n * Remove directories that are subdirectories of others in the list so files\n * are never scanned twice.\n * Example: ['/root', '/root/src'] → ['/root']\n */\nconst getDistinctRootDirs = (dirs: string[]): string[] => {\n const uniqueDirs = Array.from(new Set(dirs.map((dir) => resolve(dir))));\n uniqueDirs.sort((a, b) => a.length - b.length);\n\n return uniqueDirs.reduce((acc: string[], dir) => {\n const isNested = acc.some((parent) => {\n const rel = relative(parent, dir);\n\n return !rel.startsWith('..') && !isAbsolute(rel) && rel !== '';\n });\n if (!isNested) acc.push(dir);\n\n return acc;\n }, []);\n};\n\n/**\n * Builds a deduplicated list of absolute file paths matching the given patterns.\n *\n * Handles multiple root directories (deduplicates overlapping roots), exclude\n * patterns, negation patterns embedded in `transformPattern`, and optional\n * dot-file inclusion.\n *\n * @example\n * // Single root with excludes\n * const files = buildComponentFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // Multiple roots (e.g. baseDir + codeDir), dot files included\n * const files = buildComponentFilesList(config, ['**\\/node_modules\\/**']);\n */\nexport const buildComponentFilesList = (\n config: IntlayerConfig,\n excludePattern?: string[]\n): string[] => {\n const transformPattern = config.build.traversePattern;\n const compilerTransformPattern = config.compiler.transformPattern;\n const contentDeclarationPattern = config.content.
|
|
1
|
+
{"version":3,"file":"buildComponentFilesList.mjs","names":[],"sources":["../../../src/utils/buildComponentFilesList.ts"],"sourcesContent":["import { isAbsolute, normalize, relative, resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] =>\n Array.isArray(value) ? value : [value];\n\n/**\n * Remove directories that are subdirectories of others in the list so files\n * are never scanned twice.\n * Example: ['/root', '/root/src'] → ['/root']\n */\nconst getDistinctRootDirs = (dirs: string[]): string[] => {\n const uniqueDirs = Array.from(new Set(dirs.map((dir) => resolve(dir))));\n uniqueDirs.sort((a, b) => a.length - b.length);\n\n return uniqueDirs.reduce((acc: string[], dir) => {\n const isNested = acc.some((parent) => {\n const rel = relative(parent, dir);\n\n return !rel.startsWith('..') && !isAbsolute(rel) && rel !== '';\n });\n if (!isNested) acc.push(dir);\n\n return acc;\n }, []);\n};\n\n/**\n * Builds a deduplicated list of absolute file paths matching the given patterns.\n *\n * Handles multiple root directories (deduplicates overlapping roots), exclude\n * patterns, negation patterns embedded in `transformPattern`, and optional\n * dot-file inclusion.\n *\n * @example\n * // Single root with excludes\n * const files = buildComponentFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // Multiple roots (e.g. baseDir + codeDir), dot files included\n * const files = buildComponentFilesList(config, ['**\\/node_modules\\/**']);\n */\nexport const buildComponentFilesList = (\n config: IntlayerConfig,\n excludePattern?: string[]\n): string[] => {\n const transformPattern = config.build.traversePattern;\n const compilerTransformPattern = config.compiler.transformPattern;\n const contentDeclarationPattern = config.content.fileExtensions.map(\n (ext) => `/**/*${ext}`\n );\n\n const patterns = [\n ...transformPattern,\n ...normalizeToArray(compilerTransformPattern),\n ]\n .filter((pattern) => typeof pattern === 'string')\n .filter((pattern) => !pattern.startsWith('!'))\n .map((pattern) => normalize(pattern)); // Ensure it works with Windows\n\n const excludePatterns = [\n ...(excludePattern ?? []),\n ...contentDeclarationPattern,\n // Treat negation entries in transformPattern as additional excludes\n ...transformPattern\n .filter(\n (pattern) => typeof pattern === 'string' && pattern.startsWith('!')\n )\n .map((pattern) => pattern.slice(1)),\n ]\n .filter((pattern) => typeof pattern === 'string')\n .map((pattern) => normalize(pattern)); // Ensure it works with Windows\n\n const roots = getDistinctRootDirs([\n config.system.baseDir,\n ...config.content.codeDir,\n ]);\n\n const fileList = roots.flatMap((root) =>\n fg.sync(patterns, {\n cwd: root,\n ignore: excludePatterns,\n absolute: true,\n dot: true, // include dot files like .next / .intlayer\n })\n );\n\n return Array.from(new Set(fileList));\n};\n"],"mappings":"0GAOA,MAAM,EAAuB,GAC3B,MAAM,QAAQ,EAAM,CAAG,EAAQ,CAAC,EAAM,CAOlC,EAAuB,GAA6B,CACxD,IAAM,EAAa,MAAM,KAAK,IAAI,IAAI,EAAK,IAAK,GAAQ,EAAQ,EAAI,CAAC,CAAC,CAAC,CAGvE,OAFA,EAAW,MAAM,EAAG,IAAM,EAAE,OAAS,EAAE,OAAO,CAEvC,EAAW,QAAQ,EAAe,KACtB,EAAI,KAAM,GAAW,CACpC,IAAM,EAAM,EAAS,EAAQ,EAAI,CAEjC,MAAO,CAAC,EAAI,WAAW,KAAK,EAAI,CAAC,EAAW,EAAI,EAAI,IAAQ,IAC5D,EACa,EAAI,KAAK,EAAI,CAErB,GACN,EAAE,CAAC,EAsBK,GACX,EACA,IACa,CACb,IAAM,EAAmB,EAAO,MAAM,gBAChC,EAA2B,EAAO,SAAS,iBAC3C,EAA4B,EAAO,QAAQ,eAAe,IAC7D,GAAQ,QAAQ,IAClB,CAEK,EAAW,CACf,GAAG,EACH,GAAG,EAAiB,EAAyB,CAC9C,CACE,OAAQ,GAAY,OAAO,GAAY,SAAS,CAChD,OAAQ,GAAY,CAAC,EAAQ,WAAW,IAAI,CAAC,CAC7C,IAAK,GAAY,EAAU,EAAQ,CAAC,CAEjC,EAAkB,CACtB,GAAI,GAAkB,EAAE,CACxB,GAAG,EAEH,GAAG,EACA,OACE,GAAY,OAAO,GAAY,UAAY,EAAQ,WAAW,IAAI,CACpE,CACA,IAAK,GAAY,EAAQ,MAAM,EAAE,CAAC,CACtC,CACE,OAAQ,GAAY,OAAO,GAAY,SAAS,CAChD,IAAK,GAAY,EAAU,EAAQ,CAAC,CAOjC,EALQ,EAAoB,CAChC,EAAO,OAAO,QACd,GAAG,EAAO,QAAQ,QACnB,CAAC,CAEqB,QAAS,GAC9B,EAAG,KAAK,EAAU,CAChB,IAAK,EACL,OAAQ,EACR,SAAU,GACV,IAAK,GACN,CAAC,CACH,CAED,OAAO,MAAM,KAAK,IAAI,IAAI,EAAS,CAAC"}
|
package/dist/esm/watcher.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{handleContentDeclarationFileChange as e}from"./handleContentDeclarationFileChange.mjs";import{handleContentDeclarationFileMoved as t}from"./handleContentDeclarationFileMoved.mjs";import{handleAdditionalContentDeclarationFile as n}from"./handleAdditionalContentDeclarationFile.mjs";import{handleUnlinkedContentDeclarationFile as r}from"./handleUnlinkedContentDeclarationFile.mjs";import{prepareIntlayer as i}from"./prepareIntlayer.mjs";import{writeContentDeclaration as a}from"./writeContentDeclaration/writeContentDeclaration.mjs";import"./writeContentDeclaration/index.mjs";import{readFile as o}from"node:fs/promises";import{basename as s}from"node:path";import{getAppLogger as c}from"@intlayer/config/logger";import{getConfiguration as l,getConfigurationAndFilePath as u}from"@intlayer/config/node";import{clearAllCache as d,clearModuleCache as f}from"@intlayer/config/utils";import{watch as
|
|
1
|
+
import{handleContentDeclarationFileChange as e}from"./handleContentDeclarationFileChange.mjs";import{handleContentDeclarationFileMoved as t}from"./handleContentDeclarationFileMoved.mjs";import{handleAdditionalContentDeclarationFile as n}from"./handleAdditionalContentDeclarationFile.mjs";import{handleUnlinkedContentDeclarationFile as r}from"./handleUnlinkedContentDeclarationFile.mjs";import{prepareIntlayer as i}from"./prepareIntlayer.mjs";import{writeContentDeclaration as a}from"./writeContentDeclaration/writeContentDeclaration.mjs";import"./writeContentDeclaration/index.mjs";import{readFile as o}from"node:fs/promises";import{basename as s}from"node:path";import{getAppLogger as c}from"@intlayer/config/logger";import{getConfiguration as l,getConfigurationAndFilePath as u}from"@intlayer/config/node";import{clearAllCache as d,clearModuleCache as f,normalizePath as p}from"@intlayer/config/utils";import{watch as m}from"chokidar";const h=new Map;let g=Promise.resolve();const _=e=>{g=g.then(async()=>{try{await e()}catch(e){console.error(e)}})},v=l=>{let g=u(l?.configOptions),v=g.configurationFilePath,y=l?.configuration??g.configuration,b=c(y),{watch:x,fileExtensions:S,contentDir:C}=y.content,w=[...S.flatMap(e=>C.map(t=>`${p(t)}/**/*${e}`.replace(`//`,`/`))),...v?[v]:[]];if(y.content.watch)return b(`Watching Intlayer content declarations`),m(w,{persistent:x,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:1e3,pollInterval:100},ignored:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.intlayer/**`],...l}).on(`add`,async e=>{let r=s(e),i=!1,c;for(let[e]of h)if(s(e)===r){c=e;break}if(!c&&h.size===1&&(c=h.keys().next().value),c){let t=h.get(c);t&&(clearTimeout(t.timer),h.delete(c)),i=!0,b(`File moved from ${c} to ${e}`)}_(async()=>{if(i&&c)await t(c,e,y);else{if(await o(e,`utf-8`)===``){let t=S.map(e=>e.replace(/\./g,`\\.`)).join(`|`);await a({key:r.replace(RegExp(`(${t})$`),``),content:{},filePath:e},y)}await n(e,y)}})}).on(`change`,async t=>_(async()=>{if(v&&t===v){b(`Configuration file changed, repreparing Intlayer`),f(v),d();let{configuration:e}=u(l?.configOptions);y=l?.configuration??e,await i(y,{clean:!1})}else await e(t,y)})).on(`unlink`,async e=>{let t=setTimeout(async()=>{h.delete(e),_(async()=>r(e,y))},200);h.set(e,{timer:t,oldPath:e})}).on(`error`,async e=>{b(`Watcher error: ${e}`,{level:`error`}),b(`Restarting watcher`),await i(y)})},y=async e=>{let{skipPrepare:t,...n}=e??{},r=e?.configuration??l(e?.configOptions);t||await i(r,{forceRun:!0}),(r.content.watch||e?.persistent)&&v({...n,configuration:r})};export{y as buildAndWatchIntlayer,v 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 {
|
|
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 {\n clearAllCache,\n clearModuleCache,\n normalizePath,\n} from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\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 fileExtensions,\n contentDir,\n } = configuration.content;\n\n const watchedFilesPatternWithPath = fileExtensions.flatMap((ext) =>\n contentDir.map((dir) =>\n `${normalizePath(dir)}/**/*${ext}`.replace('//', '/')\n )\n );\n\n const pathsToWatch = [\n ...watchedFilesPatternWithPath,\n ...(configurationFilePath ? [configurationFilePath] : []),\n ];\n\n if (!configuration.content.watch) return;\n\n appLogger('Watching Intlayer content declarations');\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 watch({ ...rest, configuration });\n }\n};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":"listDictionariesPath.d.ts","names":[],"sources":["../../src/listDictionariesPath.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"listDictionariesPath.d.ts","names":[],"sources":["../../src/listDictionariesPath.ts"],"mappings":";;;;;;;AAUA;;cAAa,gBAAA,GACX,aAAA,EAAe,cAAA,KACd,OAAA;AAAA,cAgDU,yBAAA,GACX,aAAA,EAAe,cAAA,KAAc,OAAA;;SAAA,QAAA,CAAA,KAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","names":[],"sources":["../../src/watcher.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","names":[],"sources":["../../src/watcher.ts"],"mappings":";;;;;;KAyCK,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,cA2J/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.4.
|
|
3
|
+
"version": "8.4.2",
|
|
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": [
|
|
@@ -55,6 +55,11 @@
|
|
|
55
55
|
"require": "./dist/cjs/utils/index.cjs",
|
|
56
56
|
"import": "./dist/esm/utils/index.mjs"
|
|
57
57
|
},
|
|
58
|
+
"./listDictionaries": {
|
|
59
|
+
"types": "./dist/types/listDictionariesPath.d.ts",
|
|
60
|
+
"require": "./dist/cjs/listDictionariesPath.cjs",
|
|
61
|
+
"import": "./dist/esm/listDictionariesPath.mjs"
|
|
62
|
+
},
|
|
58
63
|
"./package.json": "./package.json"
|
|
59
64
|
},
|
|
60
65
|
"main": "dist/cjs/index.cjs",
|
|
@@ -74,6 +79,9 @@
|
|
|
74
79
|
"utils": [
|
|
75
80
|
"./dist/types/utils/index.d.ts"
|
|
76
81
|
],
|
|
82
|
+
"listDictionaries": [
|
|
83
|
+
"./dist/types/listDictionariesPath.d.ts"
|
|
84
|
+
],
|
|
77
85
|
"package.json": [
|
|
78
86
|
"./package.json"
|
|
79
87
|
]
|
|
@@ -102,13 +110,13 @@
|
|
|
102
110
|
},
|
|
103
111
|
"dependencies": {
|
|
104
112
|
"@babel/parser": "7.29.0",
|
|
105
|
-
"@intlayer/api": "8.4.
|
|
106
|
-
"@intlayer/config": "8.4.
|
|
107
|
-
"@intlayer/core": "8.4.
|
|
108
|
-
"@intlayer/dictionaries-entry": "8.4.
|
|
109
|
-
"@intlayer/remote-dictionaries-entry": "8.4.
|
|
110
|
-
"@intlayer/types": "8.4.
|
|
111
|
-
"@intlayer/unmerged-dictionaries-entry": "8.4.
|
|
113
|
+
"@intlayer/api": "8.4.2",
|
|
114
|
+
"@intlayer/config": "8.4.2",
|
|
115
|
+
"@intlayer/core": "8.4.2",
|
|
116
|
+
"@intlayer/dictionaries-entry": "8.4.2",
|
|
117
|
+
"@intlayer/remote-dictionaries-entry": "8.4.2",
|
|
118
|
+
"@intlayer/types": "8.4.2",
|
|
119
|
+
"@intlayer/unmerged-dictionaries-entry": "8.4.2",
|
|
112
120
|
"chokidar": "3.6.0",
|
|
113
121
|
"defu": "6.1.4",
|
|
114
122
|
"fast-glob": "3.3.3",
|