@kanso-labs/unplugin-style-dictionary 0.2.0 → 0.2.1

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/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("node:fs");c=s(c,1);let l=require("node:path");l=s(l,1);let u=require("node:url"),d=require("node:zlib");d=s(d,1);let f=require("style-dictionary");f=s(f,1);let p=require("unplugin");var m=(e={})=>{let{silent:t=!1}=e,n=process.cwd(),r=(e,n=`info`)=>{if(t)return;let r=`[unplugin-style-dictionary]`;n===`error`?console.error(`\x1b[31m${r} ${e}\x1b[0m`):console.log(n===`success`?`\x1b[32m${r} ${e}\x1b[0m`:`\x1b[36m${r} ${e}\x1b[0m`)},i=async()=>{let t=e.config;if(!t)for(let e of[`sd.config.json`,`config.json`,`sd.config.js`,`sd.config.mjs`]){let r=l.default.resolve(n,e);if(c.default.existsSync(r)){t=e;break}}return t?(typeof t==`function`&&(t=await t()),(Array.isArray(t)?t:[t]).map(e=>{if(typeof e==`string`){let t=l.default.resolve(n,e);return{config:t,dir:l.default.dirname(t),file:t}}else return{config:e,dir:n}})):(r(`No configuration specified and no default config file found. Style Dictionary will not compile.`,`error`),[])},a=async t=>{let i=new Set;for(let e of t){e.file&&i.add(e.file.replace(/\\/g,`/`));let t=null;if(typeof e.config==`string`)try{if(e.config.endsWith(`.json`)){let n=c.default.readFileSync(e.config,`utf-8`);t=JSON.parse(n)}else{let n=await import(`${(0,u.pathToFileURL)(e.config).href}?t=${Date.now()}`);t=n.default||n}}catch(t){r(`Failed to parse config file: ${e.config}. Error: ${t.message}`,`error`)}else t=e.config;if(t){let n=t=>{if(typeof t==`string`){let n=(l.default.isAbsolute(t)?t:l.default.resolve(e.dir,t)).replace(/\\/g,`/`);i.add(n)}};t.source&&(Array.isArray(t.source)?t.source.forEach(n):n(t.source)),t.include&&(Array.isArray(t.include)?t.include.forEach(n):n(t.include))}}if(e.watch){let t=Array.isArray(e.watch)?e.watch:[e.watch];for(let e of t){let t=l.default.isAbsolute(e)?e:l.default.resolve(n,e);i.add(t.replace(/\\/g,`/`))}}return Array.from(i)},o=async(e,i)=>{let a=Date.now();try{i||r(`Compiling design tokens...`,`info`);let o=new Set;for(let r of e){let e=new f.default(r.config);await e.hasInitialized;let a=await e.extend({log:{verbosity:`silent`}});if(await a.buildAllPlatforms(),!i&&!t&&a.platforms)for(let e of Object.keys(a.platforms)){let t=a.platforms[e];if(t&&t.files){let e=t.buildPath||``;for(let r of t.files)if(r&&r.destination){let t=l.default.isAbsolute(e)?e:l.default.resolve(n,e),i=l.default.isAbsolute(r.destination)?r.destination:l.default.resolve(t,r.destination);o.add(i)}}}}let s=Date.now()-a;if(i)r(`Rebuilt design tokens due to change in ${i} (${s}ms)`,`success`);else{if(!t&&o.size>0){let e=[];for(let t of o)if(c.default.existsSync(t)){let r=l.default.relative(n,t).replace(/\\/g,`/`),i=l.default.dirname(r),a=l.default.basename(r),o=i===`.`?`\x1b[32m${a}\x1b[0m`:`\x1b[90m${i}/\x1b[0m\x1b[32m${a}\x1b[0m`;try{let n=`${(c.default.statSync(t).size/1024).toFixed(2)} kB`,i=c.default.readFileSync(t),a=`${(d.default.gzipSync(i).length/1024).toFixed(2)} kB`;e.push({coloredPath:o,gzipSizeStr:a,relativeDisplayPath:r,sizeStr:n})}catch{}}if(e.length>0){let t=Math.max(...e.map(e=>e.relativeDisplayPath.length),0),n=Math.max(...e.map(e=>e.sizeStr.length),0);for(let r of e){let e=` `.repeat(Math.max(2,t-r.relativeDisplayPath.length+2)),i=r.sizeStr.padStart(n);console.log(`${r.coloredPath}${e}\x1b[90m${i} │ gzip: ${r.gzipSizeStr}\x1b[0m`)}}}r(`Compiled successfully! (${s}ms)`,`success`)}}catch(e){let t=Date.now()-a;r(`Compilation failed after ${t}ms: ${e.message}`,`error`)}};return{async buildStart(){let e=await i();if(e.length===0)return;let t=await a(e);for(let e of t)this.addWatchFile(e);await o(e)},name:`unplugin-style-dictionary`,vite:{configResolved(e){n=e.root||process.cwd()},async configureServer(e){let t=await i();if(t.length===0)return;let n=await a(t);e.watcher.add(n),e.watcher.on(`all`,async(t,r)=>{let s=r.replace(/\\/g,`/`);if(n.some(e=>e===s||s.startsWith(e.replace(/\/\*\*/g,``))||e.includes(`*`)&&new RegExp(e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)).test(s))){let t=await i();await o(t,l.default.basename(s));let n=await a(t);e.watcher.add(n)}})}},async watchChange(e){let t=await i();if(t.length===0)return;await o(t,l.default.basename(e));let n=await a(t);for(let e of n)this.addWatchFile(e)}}},h=(0,p.createUnplugin)(m);exports.default=h,exports.unplugin=h,exports.unpluginFactory=m;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("node:fs");c=s(c,1);let l=require("node:path");l=s(l,1);let u=require("node:url"),d=require("node:zlib");d=s(d,1);let f=require("style-dictionary");f=s(f,1);let p=require("unplugin");function m(e,t){let n=e.replace(/\\/g,`/`);return t.some(e=>e===n||n.startsWith(e.replace(/\/\*\*/g,``))||e.includes(`*`)&&new RegExp(e.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`.*`)).test(n))}var h=(e={})=>{let{silent:t=!1}=e,n=process.cwd(),r=(e,n=`info`)=>{if(t)return;let r=`[unplugin-style-dictionary]`;n===`error`?console.error(`\x1b[31m${r} ${e}\x1b[0m`):console.log(n===`success`?`\x1b[32m${r} ${e}\x1b[0m`:`\x1b[36m${r} ${e}\x1b[0m`)},i=async()=>{let t=e.config;if(!t)for(let e of[`sd.config.json`,`config.json`,`sd.config.js`,`sd.config.mjs`]){let r=l.default.resolve(n,e);if(c.default.existsSync(r)){t=e;break}}return t?(typeof t==`function`&&(t=await t()),(Array.isArray(t)?t:[t]).map(e=>{if(typeof e==`string`){let t=l.default.resolve(n,e);return{config:t,dir:l.default.dirname(t),file:t}}else return{config:e,dir:n}})):(r(`No configuration specified and no default config file found. Style Dictionary will not compile.`,`error`),[])},a=async t=>{let i=new Set;for(let e of t){e.file&&i.add(e.file.replace(/\\/g,`/`));let t=null;if(typeof e.config==`string`)try{if(e.config.endsWith(`.json`)){let n=c.default.readFileSync(e.config,`utf-8`);t=JSON.parse(n)}else{let n=await import(`${(0,u.pathToFileURL)(e.config).href}?t=${Date.now()}`);t=n.default||n}}catch(t){r(`Failed to parse config file: ${e.config}. Error: ${t.message}`,`error`)}else t=e.config;if(t){let n=t=>{if(typeof t==`string`){let n=(l.default.isAbsolute(t)?t:l.default.resolve(e.dir,t)).replace(/\\/g,`/`);i.add(n)}};t.source&&(Array.isArray(t.source)?t.source.forEach(n):n(t.source)),t.include&&(Array.isArray(t.include)?t.include.forEach(n):n(t.include))}}if(e.watch){let t=Array.isArray(e.watch)?e.watch:[e.watch];for(let e of t){let t=l.default.isAbsolute(e)?e:l.default.resolve(n,e);i.add(t.replace(/\\/g,`/`))}}return Array.from(i)},o=async(e,i)=>{let a=Date.now();try{i||r(`Compiling design tokens...`,`info`);let o=new Set;for(let r of e){let e=new f.default(r.config);await e.hasInitialized;let a=await e.extend({log:{verbosity:`silent`}});if(await a.buildAllPlatforms(),!i&&!t&&a.platforms)for(let e of Object.keys(a.platforms)){let t=a.platforms[e];if(t&&t.files){let e=t.buildPath||``;for(let r of t.files)if(r&&r.destination){let t=l.default.isAbsolute(e)?e:l.default.resolve(n,e),i=l.default.isAbsolute(r.destination)?r.destination:l.default.resolve(t,r.destination);o.add(i)}}}}let s=Date.now()-a;if(i)r(`Rebuilt design tokens due to change in ${i} (${s}ms)`,`success`);else{if(!t&&o.size>0){let e=[];for(let t of o)if(c.default.existsSync(t)){let r=l.default.relative(n,t).replace(/\\/g,`/`),i=l.default.dirname(r),a=l.default.basename(r),o=i===`.`?`\x1b[32m${a}\x1b[0m`:`\x1b[90m${i}/\x1b[0m\x1b[32m${a}\x1b[0m`;try{let n=`${(c.default.statSync(t).size/1024).toFixed(2)} kB`,i=c.default.readFileSync(t),a=`${(d.default.gzipSync(i).length/1024).toFixed(2)} kB`;e.push({coloredPath:o,gzipSizeStr:a,relativeDisplayPath:r,sizeStr:n})}catch{}}if(e.length>0){let t=Math.max(...e.map(e=>e.relativeDisplayPath.length),0),n=Math.max(...e.map(e=>e.sizeStr.length),0);for(let r of e){let e=` `.repeat(Math.max(2,t-r.relativeDisplayPath.length+2)),i=r.sizeStr.padStart(n);console.log(`${r.coloredPath}${e}\x1b[90m${i} │ gzip: ${r.gzipSizeStr}\x1b[0m`)}}}r(`Compiled successfully! (${s}ms)`,`success`)}}catch(e){let t=Date.now()-a;r(`Compilation failed after ${t}ms: ${e.message}`,`error`)}};return{async buildStart(){let e=await i();if(e.length===0)return;let t=await a(e);for(let e of t)this.addWatchFile(e);await o(e)},name:`unplugin-style-dictionary`,vite:{configResolved(e){n=e.root||process.cwd()},async configureServer(e){let t=await i();if(t.length===0)return;let n=await a(t);e.watcher.add(n),e.watcher.on(`all`,async(t,r)=>{if(!m(r,n))return;let s=await i();await o(s,l.default.basename(r));let c=await a(s);e.watcher.add(c)})}},async watchChange(e){let t=await i();if(t.length===0)return;let n=await a(t);if(m(e,n)){await o(t,l.default.basename(e));for(let e of n)this.addWatchFile(e)}}}},g=(0,p.createUnplugin)(h);exports.default=g,exports.unplugin=g,exports.matchesWatchedFile=m,exports.unpluginFactory=h;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'style-dictionary'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { ViteDevServer } from 'vite'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport zlib from 'node:zlib'\nimport StyleDictionary from 'style-dictionary'\nimport { createUnplugin } from 'unplugin'\n\nimport type { UnpluginStyleDictionaryOptions } from './types.js'\n\nexport * from './types.js'\n\nexport const unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}) => {\n const { silent = false } = options\n let root = process.cwd()\n\n // Helper to log if not silent\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n if (silent) return\n const prefix = '[unplugin-style-dictionary]'\n if (type === 'error') {\n console.error(`\\x1b[31m${prefix} ${message}\\x1b[0m`)\n } else if (type === 'success') {\n console.log(`\\x1b[32m${prefix} ${message}\\x1b[0m`)\n } else {\n console.log(`\\x1b[36m${prefix} ${message}\\x1b[0m`)\n }\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<\n Array<{ config: Config | string; dir: string; file?: string }>\n > => {\n let rawConfig = options.config\n\n // If config is not defined, look for default configuration files\n if (!rawConfig) {\n const defaults = [\n 'sd.config.json',\n 'config.json',\n 'sd.config.js',\n 'sd.config.mjs',\n ]\n for (const file of defaults) {\n const fullPath = path.resolve(root, file)\n if (fs.existsSync(fullPath)) {\n rawConfig = file\n break\n }\n }\n }\n\n if (!rawConfig) {\n log(\n 'No configuration specified and no default config file found. Style Dictionary will not compile.',\n 'error',\n )\n return []\n }\n\n // Evaluate function if provided\n if (typeof rawConfig === 'function') {\n rawConfig = await rawConfig()\n }\n\n const configs = Array.isArray(rawConfig) ? rawConfig : [rawConfig]\n\n return configs.map((conf) => {\n if (typeof conf === 'string') {\n const fullPath = path.resolve(root, conf)\n return {\n config: fullPath,\n dir: path.dirname(fullPath),\n file: fullPath,\n }\n } else {\n return {\n config: conf,\n dir: root,\n }\n }\n })\n }\n\n // Parse token files to watch\n const getWatchFiles = async (\n resolvedConfigs: Array<{\n config: Config | string\n dir: string\n file?: string\n }>,\n ): Promise<string[]> => {\n const filesToWatch = new Set<string>()\n\n for (const item of resolvedConfigs) {\n if (item.file) {\n filesToWatch.add(item.file.replace(/\\\\/g, '/'))\n }\n\n let configObj: Config | null = null\n\n if (typeof item.config === 'string') {\n try {\n if (item.config.endsWith('.json')) {\n const content = fs.readFileSync(item.config, 'utf-8')\n configObj = JSON.parse(content)\n } else {\n const fileUrl = pathToFileURL(item.config).href\n const module = await import(`${fileUrl}?t=${Date.now()}`)\n configObj = module.default || module\n }\n } catch (err) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${(err as Error).message}`,\n 'error',\n )\n }\n } else {\n configObj = item.config\n }\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(item.dir, pattern)\n const normalized = absolutePattern.replace(/\\\\/g, '/')\n filesToWatch.add(normalized)\n }\n }\n\n if (configObj.source) {\n if (Array.isArray(configObj.source)) {\n configObj.source.forEach(addPattern)\n } else {\n addPattern(configObj.source)\n }\n }\n\n if (configObj.include) {\n if (Array.isArray(configObj.include)) {\n configObj.include.forEach(addPattern)\n } else {\n addPattern(configObj.include)\n }\n }\n }\n }\n\n // Add manually configured watch files\n if (options.watch) {\n const extraWatches = Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n for (const pattern of extraWatches) {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n filesToWatch.add(absolutePattern.replace(/\\\\/g, '/'))\n }\n }\n\n return Array.from(filesToWatch)\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: Array<{ config: Config | string; dir: string }>,\n context?: string,\n ) => {\n const startTime = Date.now()\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n const generatedFiles = new Set<string>()\n\n for (const item of resolvedConfigs) {\n const sd = new StyleDictionary(item.config)\n await sd.hasInitialized\n const silentSD = await sd.extend({\n log: {\n verbosity: 'silent',\n },\n })\n await silentSD.buildAllPlatforms()\n\n if (!context && !silent && silentSD.platforms) {\n for (const platformName of Object.keys(silentSD.platforms)) {\n const platform = silentSD.platforms[platformName]\n if (platform && platform.files) {\n const buildPath = platform.buildPath || ''\n for (const file of platform.files) {\n if (file && file.destination) {\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n const absoluteDestination = path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination)\n generatedFiles.add(absoluteDestination)\n }\n }\n }\n }\n }\n }\n\n const duration = Date.now() - startTime\n\n if (context) {\n log(\n `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n } else {\n if (!silent && generatedFiles.size > 0) {\n const fileInfos: Array<{\n coloredPath: string\n gzipSizeStr: string\n relativeDisplayPath: string\n sizeStr: string\n }> = []\n\n for (const filePath of generatedFiles) {\n if (fs.existsSync(filePath)) {\n const displayPath = path\n .relative(root, filePath)\n .replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n const coloredPath =\n dir === '.'\n ? `\\x1b[32m${base}\\x1b[0m`\n : `\\x1b[90m${dir}/\\x1b[0m\\x1b[32m${base}\\x1b[0m`\n\n try {\n const stats = fs.statSync(filePath)\n const bytes = stats.size\n const sizeStr = `${(bytes / 1024).toFixed(2)} kB`\n\n const content = fs.readFileSync(filePath)\n const gzipBytes = zlib.gzipSync(content).length\n const gzipSizeStr = `${(gzipBytes / 1024).toFixed(2)} kB`\n\n fileInfos.push({\n coloredPath,\n gzipSizeStr,\n relativeDisplayPath: displayPath,\n sizeStr,\n })\n } catch {\n // Ignore errors reading individual files\n }\n }\n }\n\n if (fileInfos.length > 0) {\n const longestPathLength = Math.max(\n ...fileInfos.map((f) => f.relativeDisplayPath.length),\n 0,\n )\n const longestSizeLength = Math.max(\n ...fileInfos.map((f) => f.sizeStr.length),\n 0,\n )\n\n for (const info of fileInfos) {\n const pathPadding = ' '.repeat(\n Math.max(\n 2,\n longestPathLength - info.relativeDisplayPath.length + 2,\n ),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n `${info.coloredPath}${pathPadding}\\x1b[90m${sizePadded} │ gzip: ${info.gzipSizeStr}\\x1b[0m`,\n )\n }\n }\n }\n\n log(`Compiled successfully! (${duration}ms)`, 'success')\n }\n } catch (err) {\n const duration = Date.now() - startTime\n log(\n `Compilation failed after ${duration}ms: ${(err as Error).message}`,\n 'error',\n )\n }\n }\n\n return {\n async buildStart() {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Register token/config files with the host bundler's watch mode.\n // Works out of the box wherever the host runs a persistent watcher\n // (e.g. `rollup --watch`); Vite's dev server is additionally handled\n // below via the `vite.configureServer` escape hatch, since token\n // sources are plain JSON/JS files outside the module graph and\n // `watchChange` is not reliably invoked by Vite while serving.\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n\n await runBuilds(resolved)\n },\n\n name: 'unplugin-style-dictionary',\n\n vite: {\n configResolved(config) {\n root = config.root || process.cwd()\n },\n\n async configureServer(server: ViteDevServer) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const filesToWatch = await getWatchFiles(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(filesToWatch)\n\n server.watcher.on('all', async (_event, file) => {\n const normalizedFile = file.replace(/\\\\/g, '/')\n\n // Check if the modified file matches our watched config or token patterns\n const isConfigOrToken = filesToWatch.some((pattern) => {\n // If the pattern is an exact file path\n if (pattern === normalizedFile) return true\n\n // If the pattern is a glob, we check if the file matches it.\n // Note: A simple string match or simple glob matcher can be used here.\n // For simplicity and correctness, since token source paths are usually globs,\n // we can match based on path directory containment or general matching.\n // Let's implement a robust matchesGlob check or check if it's one of the token files.\n // Chokidar triggers on actual files, so we want to check if the changed file matches\n // any of the config files or token files/globs.\n return (\n normalizedFile.startsWith(pattern.replace(/\\/\\*\\*/g, '')) ||\n (pattern.includes('*') &&\n new RegExp(\n pattern\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\*/g, '.*'),\n ).test(normalizedFile))\n )\n })\n\n if (isConfigOrToken) {\n // Re-resolve configs to handle added/removed configs or changes to config itself\n const currentResolved = await resolveConfigs()\n await runBuilds(currentResolved, path.basename(normalizedFile))\n\n // Dynamically update the watch list in case the configurations changed\n const newWatches = await getWatchFiles(currentResolved)\n server.watcher.add(newWatches)\n }\n })\n },\n },\n\n async watchChange(id) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n await runBuilds(resolved, path.basename(id))\n\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n },\n }\n}\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n"],"mappings":"kwBAeA,IAAa,GAGR,EAAU,CAAC,IAAM,CACpB,GAAM,CAAE,SAAS,IAAU,EACvB,EAAO,QAAQ,IAAI,EAGjB,GACJ,EACA,EAAqC,SAClC,CACH,GAAI,EAAQ,OACZ,I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B9C,GAtBwB,EAAa,KAAM,GAErC,IAAY,GAUd,EAAe,WAAW,EAAQ,QAAQ,UAAW,EAAE,CAAC,GACvD,EAAQ,SAAS,GAAG,GACnB,IAAI,OACF,EACG,QAAQ,oBAAqB,MAAM,CAAC,CACpC,QAAQ,MAAO,IAAI,CACxB,CAAC,CAAC,KAAK,CAAc,CAIvB,EAAiB,CAEnB,IAAM,EAAkB,MAAM,EAAe,EAC7C,MAAM,EAAU,EAAiB,EAAA,QAAK,SAAS,CAAc,CAAC,EAG9D,IAAM,EAAa,MAAM,EAAc,CAAe,EACtD,EAAO,QAAQ,IAAI,CAAU,CAC/B,CACF,CAAC,CACH,CACF,EAEA,MAAM,YAAY,EAAI,CACpB,IAAM,EAAW,MAAM,EAAe,EACtC,GAAI,EAAS,SAAW,EAAG,OAE3B,MAAM,EAAU,EAAU,EAAA,QAAK,SAAS,CAAE,CAAC,EAE3C,IAAM,EAAa,MAAM,EAAc,CAAQ,EAC/C,IAAK,IAAM,KAAQ,EACjB,KAAK,aAAa,CAAI,CAE1B,CACF,CACF,EAEa,GAA2B,EAAA,EAAA,eAAA,CAAe,CAAe"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'style-dictionary'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { ViteDevServer } from 'vite'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport zlib from 'node:zlib'\nimport StyleDictionary from 'style-dictionary'\nimport { createUnplugin } from 'unplugin'\n\nimport type { UnpluginStyleDictionaryOptions } from './types.js'\n\nexport * from './types.js'\n\n// Whether `file` matches one of the resolved config/token watch patterns.\n// Shared by the Vite-specific `configureServer` watcher and the universal\n// `watchChange` hook — both need it, and both must skip files that don't\n// match: without this filter, `watchChange` reacts to *any* changed\n// module-graph file, including this plugin's own generated output (since\n// consuming code imports it). Every regenerate is itself a \"change\", which\n// without filtering re-triggers a rebuild forever.\nexport function matchesWatchedFile(file: string, patterns: string[]): boolean {\n const normalizedFile = file.replace(/\\\\/g, '/')\n\n return patterns.some((pattern) => {\n // If the pattern is an exact file path\n if (pattern === normalizedFile) return true\n\n // If the pattern is a glob, we check if the file matches it.\n // Note: A simple string match or simple glob matcher can be used here.\n // For simplicity and correctness, since token source paths are usually globs,\n // we can match based on path directory containment or general matching.\n // Let's implement a robust matchesGlob check or check if it's one of the token files.\n // Chokidar triggers on actual files, so we want to check if the changed file matches\n // any of the config files or token files/globs.\n return (\n normalizedFile.startsWith(pattern.replace(/\\/\\*\\*/g, '')) ||\n (pattern.includes('*') &&\n new RegExp(\n pattern.replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*/g, '.*'),\n ).test(normalizedFile))\n )\n })\n}\n\nexport const unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}) => {\n const { silent = false } = options\n let root = process.cwd()\n\n // Helper to log if not silent\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n if (silent) return\n const prefix = '[unplugin-style-dictionary]'\n if (type === 'error') {\n console.error(`\\x1b[31m${prefix} ${message}\\x1b[0m`)\n } else if (type === 'success') {\n console.log(`\\x1b[32m${prefix} ${message}\\x1b[0m`)\n } else {\n console.log(`\\x1b[36m${prefix} ${message}\\x1b[0m`)\n }\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<\n Array<{ config: Config | string; dir: string; file?: string }>\n > => {\n let rawConfig = options.config\n\n // If config is not defined, look for default configuration files\n if (!rawConfig) {\n const defaults = [\n 'sd.config.json',\n 'config.json',\n 'sd.config.js',\n 'sd.config.mjs',\n ]\n for (const file of defaults) {\n const fullPath = path.resolve(root, file)\n if (fs.existsSync(fullPath)) {\n rawConfig = file\n break\n }\n }\n }\n\n if (!rawConfig) {\n log(\n 'No configuration specified and no default config file found. Style Dictionary will not compile.',\n 'error',\n )\n return []\n }\n\n // Evaluate function if provided\n if (typeof rawConfig === 'function') {\n rawConfig = await rawConfig()\n }\n\n const configs = Array.isArray(rawConfig) ? rawConfig : [rawConfig]\n\n return configs.map((conf) => {\n if (typeof conf === 'string') {\n const fullPath = path.resolve(root, conf)\n return {\n config: fullPath,\n dir: path.dirname(fullPath),\n file: fullPath,\n }\n } else {\n return {\n config: conf,\n dir: root,\n }\n }\n })\n }\n\n // Parse token files to watch\n const getWatchFiles = async (\n resolvedConfigs: Array<{\n config: Config | string\n dir: string\n file?: string\n }>,\n ): Promise<string[]> => {\n const filesToWatch = new Set<string>()\n\n for (const item of resolvedConfigs) {\n if (item.file) {\n filesToWatch.add(item.file.replace(/\\\\/g, '/'))\n }\n\n let configObj: Config | null = null\n\n if (typeof item.config === 'string') {\n try {\n if (item.config.endsWith('.json')) {\n const content = fs.readFileSync(item.config, 'utf-8')\n configObj = JSON.parse(content)\n } else {\n const fileUrl = pathToFileURL(item.config).href\n const module = await import(`${fileUrl}?t=${Date.now()}`)\n configObj = module.default || module\n }\n } catch (err) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${(err as Error).message}`,\n 'error',\n )\n }\n } else {\n configObj = item.config\n }\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(item.dir, pattern)\n const normalized = absolutePattern.replace(/\\\\/g, '/')\n filesToWatch.add(normalized)\n }\n }\n\n if (configObj.source) {\n if (Array.isArray(configObj.source)) {\n configObj.source.forEach(addPattern)\n } else {\n addPattern(configObj.source)\n }\n }\n\n if (configObj.include) {\n if (Array.isArray(configObj.include)) {\n configObj.include.forEach(addPattern)\n } else {\n addPattern(configObj.include)\n }\n }\n }\n }\n\n // Add manually configured watch files\n if (options.watch) {\n const extraWatches = Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n for (const pattern of extraWatches) {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n filesToWatch.add(absolutePattern.replace(/\\\\/g, '/'))\n }\n }\n\n return Array.from(filesToWatch)\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: Array<{ config: Config | string; dir: string }>,\n context?: string,\n ) => {\n const startTime = Date.now()\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n const generatedFiles = new Set<string>()\n\n for (const item of resolvedConfigs) {\n const sd = new StyleDictionary(item.config)\n await sd.hasInitialized\n const silentSD = await sd.extend({\n log: {\n verbosity: 'silent',\n },\n })\n await silentSD.buildAllPlatforms()\n\n if (!context && !silent && silentSD.platforms) {\n for (const platformName of Object.keys(silentSD.platforms)) {\n const platform = silentSD.platforms[platformName]\n if (platform && platform.files) {\n const buildPath = platform.buildPath || ''\n for (const file of platform.files) {\n if (file && file.destination) {\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n const absoluteDestination = path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination)\n generatedFiles.add(absoluteDestination)\n }\n }\n }\n }\n }\n }\n\n const duration = Date.now() - startTime\n\n if (context) {\n log(\n `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n } else {\n if (!silent && generatedFiles.size > 0) {\n const fileInfos: Array<{\n coloredPath: string\n gzipSizeStr: string\n relativeDisplayPath: string\n sizeStr: string\n }> = []\n\n for (const filePath of generatedFiles) {\n if (fs.existsSync(filePath)) {\n const displayPath = path\n .relative(root, filePath)\n .replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n const coloredPath =\n dir === '.'\n ? `\\x1b[32m${base}\\x1b[0m`\n : `\\x1b[90m${dir}/\\x1b[0m\\x1b[32m${base}\\x1b[0m`\n\n try {\n const stats = fs.statSync(filePath)\n const bytes = stats.size\n const sizeStr = `${(bytes / 1024).toFixed(2)} kB`\n\n const content = fs.readFileSync(filePath)\n const gzipBytes = zlib.gzipSync(content).length\n const gzipSizeStr = `${(gzipBytes / 1024).toFixed(2)} kB`\n\n fileInfos.push({\n coloredPath,\n gzipSizeStr,\n relativeDisplayPath: displayPath,\n sizeStr,\n })\n } catch {\n // Ignore errors reading individual files\n }\n }\n }\n\n if (fileInfos.length > 0) {\n const longestPathLength = Math.max(\n ...fileInfos.map((f) => f.relativeDisplayPath.length),\n 0,\n )\n const longestSizeLength = Math.max(\n ...fileInfos.map((f) => f.sizeStr.length),\n 0,\n )\n\n for (const info of fileInfos) {\n const pathPadding = ' '.repeat(\n Math.max(\n 2,\n longestPathLength - info.relativeDisplayPath.length + 2,\n ),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n `${info.coloredPath}${pathPadding}\\x1b[90m${sizePadded} │ gzip: ${info.gzipSizeStr}\\x1b[0m`,\n )\n }\n }\n }\n\n log(`Compiled successfully! (${duration}ms)`, 'success')\n }\n } catch (err) {\n const duration = Date.now() - startTime\n log(\n `Compilation failed after ${duration}ms: ${(err as Error).message}`,\n 'error',\n )\n }\n }\n\n return {\n async buildStart() {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Register token/config files with the host bundler's watch mode.\n // Works out of the box wherever the host runs a persistent watcher\n // (e.g. `rollup --watch`); Vite's dev server is additionally handled\n // below via the `vite.configureServer` escape hatch, since token\n // sources are plain JSON/JS files outside the module graph and\n // `watchChange` is not reliably invoked by Vite while serving.\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n\n await runBuilds(resolved)\n },\n\n name: 'unplugin-style-dictionary',\n\n vite: {\n configResolved(config) {\n root = config.root || process.cwd()\n },\n\n async configureServer(server: ViteDevServer) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const filesToWatch = await getWatchFiles(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(filesToWatch)\n\n server.watcher.on('all', async (_event, file) => {\n if (!matchesWatchedFile(file, filesToWatch)) return\n\n // Re-resolve configs to handle added/removed configs or changes to config itself\n const currentResolved = await resolveConfigs()\n await runBuilds(currentResolved, path.basename(file))\n\n // Dynamically update the watch list in case the configurations changed\n const newWatches = await getWatchFiles(currentResolved)\n server.watcher.add(newWatches)\n })\n },\n },\n\n async watchChange(id) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const watchFiles = await getWatchFiles(resolved)\n // Without this check, watchChange fires for *any* changed file in the\n // host bundler's module graph — including our own generated output,\n // since consuming code imports it. Every regenerate is itself a\n // \"change\", so skipping non-matching files here is what keeps this\n // from rebuilding forever.\n if (!matchesWatchedFile(id, watchFiles)) return\n\n await runBuilds(resolved, path.basename(id))\n\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n },\n }\n}\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n"],"mappings":"kwBAsBA,SAAgB,EAAmB,EAAc,EAA6B,CAC5E,IAAM,EAAiB,EAAK,QAAQ,MAAO,GAAG,EAE9C,OAAO,EAAS,KAAM,GAEhB,IAAY,GAUd,EAAe,WAAW,EAAQ,QAAQ,UAAW,EAAE,CAAC,GACvD,EAAQ,SAAS,GAAG,GACnB,IAAI,OACF,EAAQ,QAAQ,oBAAqB,MAAM,CAAC,CAAC,QAAQ,MAAO,IAAI,CAClE,CAAC,CAAC,KAAK,CAAc,CAE1B,CACH,CAEA,IAAa,GAGR,EAAU,CAAC,IAAM,CACpB,GAAM,CAAE,SAAS,IAAU,EACvB,EAAO,QAAQ,IAAI,EAGjB,GACJ,EACA,EAAqC,SAClC,CACH,GAAI,EAAQ,OACZ,IAAM,EAAS,8BACX,IAAS,QACX,QAAQ,MAAM,WAAW,EAAO,GAAG,EAAQ,QAAQ,EAEnD,QAAQ,IADC,IAAS,UACN,WAAW,EAAO,GAAG,EAAQ,SAE7B,WAAW,EAAO,GAAG,EAAQ,QAAQ,CAErD,EAGM,EAAiB,SAElB,CACH,IAAI,EAAY,EAAQ,OAGxB,GAAI,CAAC,EAOH,IAAK,IAAM,IAAQ,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E3B,IAAM,EAAa,MAAM,EAAc,CAAQ,EAM1C,KAAmB,EAAI,CAAU,EAEtC,OAAM,EAAU,EAAU,EAAA,QAAK,SAAS,CAAE,CAAC,EAE3C,IAAK,IAAM,KAAQ,EACjB,KAAK,aAAa,CAAI,CAHmB,CAK7C,CACF,CACF,EAEa,GAA2B,EAAA,EAAA,eAAA,CAAe,CAAe"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { UnpluginFactory } from 'unplugin';
2
2
  import { UnpluginStyleDictionaryOptions } from './types.js';
3
3
  export * from './types.js';
4
+ export declare function matchesWatchedFile(file: string, patterns: string[]): boolean;
4
5
  export declare const unpluginFactory: UnpluginFactory<undefined | UnpluginStyleDictionaryOptions, false>;
5
6
  export declare const unplugin: import('unplugin').UnpluginInstance<UnpluginStyleDictionaryOptions | undefined, false>;
6
7
  export default unplugin;
package/dist/index.js CHANGED
@@ -5,12 +5,16 @@ import r from "node:zlib";
5
5
  import i from "style-dictionary";
6
6
  import { createUnplugin as a } from "unplugin";
7
7
  //#region src/index.ts
8
- var o = (a = {}) => {
9
- let { silent: o = !1 } = a, s = process.cwd(), c = (e, t = "info") => {
10
- if (o) return;
8
+ function o(e, t) {
9
+ let n = e.replace(/\\/g, "/");
10
+ return t.some((e) => e === n || n.startsWith(e.replace(/\/\*\*/g, "")) || e.includes("*") && new RegExp(e.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")).test(n));
11
+ }
12
+ var s = (a = {}) => {
13
+ let { silent: s = !1 } = a, c = process.cwd(), l = (e, t = "info") => {
14
+ if (s) return;
11
15
  let n = "[unplugin-style-dictionary]";
12
16
  t === "error" ? console.error(`\x1b[31m${n} ${e}\x1b[0m`) : console.log(t === "success" ? `\x1b[32m${n} ${e}\x1b[0m` : `\x1b[36m${n} ${e}\x1b[0m`);
13
- }, l = async () => {
17
+ }, u = async () => {
14
18
  let n = a.config;
15
19
  if (!n) for (let r of [
16
20
  "sd.config.json",
@@ -18,7 +22,7 @@ var o = (a = {}) => {
18
22
  "sd.config.js",
19
23
  "sd.config.mjs"
20
24
  ]) {
21
- let i = t.resolve(s, r);
25
+ let i = t.resolve(c, r);
22
26
  if (e.existsSync(i)) {
23
27
  n = r;
24
28
  break;
@@ -26,7 +30,7 @@ var o = (a = {}) => {
26
30
  }
27
31
  return n ? (typeof n == "function" && (n = await n()), (Array.isArray(n) ? n : [n]).map((e) => {
28
32
  if (typeof e == "string") {
29
- let n = t.resolve(s, e);
33
+ let n = t.resolve(c, e);
30
34
  return {
31
35
  config: n,
32
36
  dir: t.dirname(n),
@@ -34,10 +38,10 @@ var o = (a = {}) => {
34
38
  };
35
39
  } else return {
36
40
  config: e,
37
- dir: s
41
+ dir: c
38
42
  };
39
- })) : (c("No configuration specified and no default config file found. Style Dictionary will not compile.", "error"), []);
40
- }, u = async (r) => {
43
+ })) : (l("No configuration specified and no default config file found. Style Dictionary will not compile.", "error"), []);
44
+ }, d = async (r) => {
41
45
  let i = /* @__PURE__ */ new Set();
42
46
  for (let a of r) {
43
47
  a.file && i.add(a.file.replace(/\\/g, "/"));
@@ -51,7 +55,7 @@ var o = (a = {}) => {
51
55
  r = e.default || e;
52
56
  }
53
57
  } catch (e) {
54
- c(`Failed to parse config file: ${a.config}. Error: ${e.message}`, "error");
58
+ l(`Failed to parse config file: ${a.config}. Error: ${e.message}`, "error");
55
59
  }
56
60
  else r = a.config;
57
61
  if (r) {
@@ -67,38 +71,38 @@ var o = (a = {}) => {
67
71
  if (a.watch) {
68
72
  let e = Array.isArray(a.watch) ? a.watch : [a.watch];
69
73
  for (let n of e) {
70
- let e = t.isAbsolute(n) ? n : t.resolve(s, n);
74
+ let e = t.isAbsolute(n) ? n : t.resolve(c, n);
71
75
  i.add(e.replace(/\\/g, "/"));
72
76
  }
73
77
  }
74
78
  return Array.from(i);
75
- }, d = async (n, a) => {
76
- let l = Date.now();
79
+ }, f = async (n, a) => {
80
+ let o = Date.now();
77
81
  try {
78
- a || c("Compiling design tokens...", "info");
82
+ a || l("Compiling design tokens...", "info");
79
83
  let u = /* @__PURE__ */ new Set();
80
84
  for (let e of n) {
81
85
  let n = new i(e.config);
82
86
  await n.hasInitialized;
83
87
  let r = await n.extend({ log: { verbosity: "silent" } });
84
- if (await r.buildAllPlatforms(), !a && !o && r.platforms) for (let e of Object.keys(r.platforms)) {
88
+ if (await r.buildAllPlatforms(), !a && !s && r.platforms) for (let e of Object.keys(r.platforms)) {
85
89
  let n = r.platforms[e];
86
90
  if (n && n.files) {
87
91
  let e = n.buildPath || "";
88
92
  for (let r of n.files) if (r && r.destination) {
89
- let n = t.isAbsolute(e) ? e : t.resolve(s, e), i = t.isAbsolute(r.destination) ? r.destination : t.resolve(n, r.destination);
93
+ let n = t.isAbsolute(e) ? e : t.resolve(c, e), i = t.isAbsolute(r.destination) ? r.destination : t.resolve(n, r.destination);
90
94
  u.add(i);
91
95
  }
92
96
  }
93
97
  }
94
98
  }
95
- let d = Date.now() - l;
96
- if (a) c(`Rebuilt design tokens due to change in ${a} (${d}ms)`, "success");
99
+ let d = Date.now() - o;
100
+ if (a) l(`Rebuilt design tokens due to change in ${a} (${d}ms)`, "success");
97
101
  else {
98
- if (!o && u.size > 0) {
102
+ if (!s && u.size > 0) {
99
103
  let n = [];
100
104
  for (let i of u) if (e.existsSync(i)) {
101
- let a = t.relative(s, i).replace(/\\/g, "/"), o = t.dirname(a), c = t.basename(a), l = o === "." ? `\x1b[32m${c}\x1b[0m` : `\x1b[90m${o}/\x1b[0m\x1b[32m${c}\x1b[0m`;
105
+ let a = t.relative(c, i).replace(/\\/g, "/"), o = t.dirname(a), s = t.basename(a), l = o === "." ? `\x1b[32m${s}\x1b[0m` : `\x1b[90m${o}/\x1b[0m\x1b[32m${s}\x1b[0m`;
102
106
  try {
103
107
  let t = `${(e.statSync(i).size / 1024).toFixed(2)} kB`, o = e.readFileSync(i), s = `${(r.gzipSync(o).length / 1024).toFixed(2)} kB`;
104
108
  n.push({
@@ -117,51 +121,51 @@ var o = (a = {}) => {
117
121
  }
118
122
  }
119
123
  }
120
- c(`Compiled successfully! (${d}ms)`, "success");
124
+ l(`Compiled successfully! (${d}ms)`, "success");
121
125
  }
122
126
  } catch (e) {
123
- let t = Date.now() - l;
124
- c(`Compilation failed after ${t}ms: ${e.message}`, "error");
127
+ let t = Date.now() - o;
128
+ l(`Compilation failed after ${t}ms: ${e.message}`, "error");
125
129
  }
126
130
  };
127
131
  return {
128
132
  async buildStart() {
129
- let e = await l();
133
+ let e = await u();
130
134
  if (e.length === 0) return;
131
- let t = await u(e);
135
+ let t = await d(e);
132
136
  for (let e of t) this.addWatchFile(e);
133
- await d(e);
137
+ await f(e);
134
138
  },
135
139
  name: "unplugin-style-dictionary",
136
140
  vite: {
137
141
  configResolved(e) {
138
- s = e.root || process.cwd();
142
+ c = e.root || process.cwd();
139
143
  },
140
144
  async configureServer(e) {
141
- let n = await l();
145
+ let n = await u();
142
146
  if (n.length === 0) return;
143
- let r = await u(n);
147
+ let r = await d(n);
144
148
  e.watcher.add(r), e.watcher.on("all", async (n, i) => {
145
- let a = i.replace(/\\/g, "/");
146
- if (r.some((e) => e === a || a.startsWith(e.replace(/\/\*\*/g, "")) || e.includes("*") && new RegExp(e.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")).test(a))) {
147
- let n = await l();
148
- await d(n, t.basename(a));
149
- let r = await u(n);
150
- e.watcher.add(r);
151
- }
149
+ if (!o(i, r)) return;
150
+ let a = await u();
151
+ await f(a, t.basename(i));
152
+ let s = await d(a);
153
+ e.watcher.add(s);
152
154
  });
153
155
  }
154
156
  },
155
157
  async watchChange(e) {
156
- let n = await l();
158
+ let n = await u();
157
159
  if (n.length === 0) return;
158
- await d(n, t.basename(e));
159
- let r = await u(n);
160
- for (let e of r) this.addWatchFile(e);
160
+ let r = await d(n);
161
+ if (o(e, r)) {
162
+ await f(n, t.basename(e));
163
+ for (let e of r) this.addWatchFile(e);
164
+ }
161
165
  }
162
166
  };
163
- }, s = /* #__PURE__ */ a(o);
167
+ }, c = /* #__PURE__ */ a(s);
164
168
  //#endregion
165
- export { s as default, s as unplugin, o as unpluginFactory };
169
+ export { c as default, c as unplugin, o as matchesWatchedFile, s as unpluginFactory };
166
170
 
167
171
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'style-dictionary'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { ViteDevServer } from 'vite'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport zlib from 'node:zlib'\nimport StyleDictionary from 'style-dictionary'\nimport { createUnplugin } from 'unplugin'\n\nimport type { UnpluginStyleDictionaryOptions } from './types.js'\n\nexport * from './types.js'\n\nexport const unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}) => {\n const { silent = false } = options\n let root = process.cwd()\n\n // Helper to log if not silent\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n if (silent) return\n const prefix = '[unplugin-style-dictionary]'\n if (type === 'error') {\n console.error(`\\x1b[31m${prefix} ${message}\\x1b[0m`)\n } else if (type === 'success') {\n console.log(`\\x1b[32m${prefix} ${message}\\x1b[0m`)\n } else {\n console.log(`\\x1b[36m${prefix} ${message}\\x1b[0m`)\n }\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<\n Array<{ config: Config | string; dir: string; file?: string }>\n > => {\n let rawConfig = options.config\n\n // If config is not defined, look for default configuration files\n if (!rawConfig) {\n const defaults = [\n 'sd.config.json',\n 'config.json',\n 'sd.config.js',\n 'sd.config.mjs',\n ]\n for (const file of defaults) {\n const fullPath = path.resolve(root, file)\n if (fs.existsSync(fullPath)) {\n rawConfig = file\n break\n }\n }\n }\n\n if (!rawConfig) {\n log(\n 'No configuration specified and no default config file found. Style Dictionary will not compile.',\n 'error',\n )\n return []\n }\n\n // Evaluate function if provided\n if (typeof rawConfig === 'function') {\n rawConfig = await rawConfig()\n }\n\n const configs = Array.isArray(rawConfig) ? rawConfig : [rawConfig]\n\n return configs.map((conf) => {\n if (typeof conf === 'string') {\n const fullPath = path.resolve(root, conf)\n return {\n config: fullPath,\n dir: path.dirname(fullPath),\n file: fullPath,\n }\n } else {\n return {\n config: conf,\n dir: root,\n }\n }\n })\n }\n\n // Parse token files to watch\n const getWatchFiles = async (\n resolvedConfigs: Array<{\n config: Config | string\n dir: string\n file?: string\n }>,\n ): Promise<string[]> => {\n const filesToWatch = new Set<string>()\n\n for (const item of resolvedConfigs) {\n if (item.file) {\n filesToWatch.add(item.file.replace(/\\\\/g, '/'))\n }\n\n let configObj: Config | null = null\n\n if (typeof item.config === 'string') {\n try {\n if (item.config.endsWith('.json')) {\n const content = fs.readFileSync(item.config, 'utf-8')\n configObj = JSON.parse(content)\n } else {\n const fileUrl = pathToFileURL(item.config).href\n const module = await import(`${fileUrl}?t=${Date.now()}`)\n configObj = module.default || module\n }\n } catch (err) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${(err as Error).message}`,\n 'error',\n )\n }\n } else {\n configObj = item.config\n }\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(item.dir, pattern)\n const normalized = absolutePattern.replace(/\\\\/g, '/')\n filesToWatch.add(normalized)\n }\n }\n\n if (configObj.source) {\n if (Array.isArray(configObj.source)) {\n configObj.source.forEach(addPattern)\n } else {\n addPattern(configObj.source)\n }\n }\n\n if (configObj.include) {\n if (Array.isArray(configObj.include)) {\n configObj.include.forEach(addPattern)\n } else {\n addPattern(configObj.include)\n }\n }\n }\n }\n\n // Add manually configured watch files\n if (options.watch) {\n const extraWatches = Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n for (const pattern of extraWatches) {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n filesToWatch.add(absolutePattern.replace(/\\\\/g, '/'))\n }\n }\n\n return Array.from(filesToWatch)\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: Array<{ config: Config | string; dir: string }>,\n context?: string,\n ) => {\n const startTime = Date.now()\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n const generatedFiles = new Set<string>()\n\n for (const item of resolvedConfigs) {\n const sd = new StyleDictionary(item.config)\n await sd.hasInitialized\n const silentSD = await sd.extend({\n log: {\n verbosity: 'silent',\n },\n })\n await silentSD.buildAllPlatforms()\n\n if (!context && !silent && silentSD.platforms) {\n for (const platformName of Object.keys(silentSD.platforms)) {\n const platform = silentSD.platforms[platformName]\n if (platform && platform.files) {\n const buildPath = platform.buildPath || ''\n for (const file of platform.files) {\n if (file && file.destination) {\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n const absoluteDestination = path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination)\n generatedFiles.add(absoluteDestination)\n }\n }\n }\n }\n }\n }\n\n const duration = Date.now() - startTime\n\n if (context) {\n log(\n `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n } else {\n if (!silent && generatedFiles.size > 0) {\n const fileInfos: Array<{\n coloredPath: string\n gzipSizeStr: string\n relativeDisplayPath: string\n sizeStr: string\n }> = []\n\n for (const filePath of generatedFiles) {\n if (fs.existsSync(filePath)) {\n const displayPath = path\n .relative(root, filePath)\n .replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n const coloredPath =\n dir === '.'\n ? `\\x1b[32m${base}\\x1b[0m`\n : `\\x1b[90m${dir}/\\x1b[0m\\x1b[32m${base}\\x1b[0m`\n\n try {\n const stats = fs.statSync(filePath)\n const bytes = stats.size\n const sizeStr = `${(bytes / 1024).toFixed(2)} kB`\n\n const content = fs.readFileSync(filePath)\n const gzipBytes = zlib.gzipSync(content).length\n const gzipSizeStr = `${(gzipBytes / 1024).toFixed(2)} kB`\n\n fileInfos.push({\n coloredPath,\n gzipSizeStr,\n relativeDisplayPath: displayPath,\n sizeStr,\n })\n } catch {\n // Ignore errors reading individual files\n }\n }\n }\n\n if (fileInfos.length > 0) {\n const longestPathLength = Math.max(\n ...fileInfos.map((f) => f.relativeDisplayPath.length),\n 0,\n )\n const longestSizeLength = Math.max(\n ...fileInfos.map((f) => f.sizeStr.length),\n 0,\n )\n\n for (const info of fileInfos) {\n const pathPadding = ' '.repeat(\n Math.max(\n 2,\n longestPathLength - info.relativeDisplayPath.length + 2,\n ),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n `${info.coloredPath}${pathPadding}\\x1b[90m${sizePadded} │ gzip: ${info.gzipSizeStr}\\x1b[0m`,\n )\n }\n }\n }\n\n log(`Compiled successfully! (${duration}ms)`, 'success')\n }\n } catch (err) {\n const duration = Date.now() - startTime\n log(\n `Compilation failed after ${duration}ms: ${(err as Error).message}`,\n 'error',\n )\n }\n }\n\n return {\n async buildStart() {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Register token/config files with the host bundler's watch mode.\n // Works out of the box wherever the host runs a persistent watcher\n // (e.g. `rollup --watch`); Vite's dev server is additionally handled\n // below via the `vite.configureServer` escape hatch, since token\n // sources are plain JSON/JS files outside the module graph and\n // `watchChange` is not reliably invoked by Vite while serving.\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n\n await runBuilds(resolved)\n },\n\n name: 'unplugin-style-dictionary',\n\n vite: {\n configResolved(config) {\n root = config.root || process.cwd()\n },\n\n async configureServer(server: ViteDevServer) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const filesToWatch = await getWatchFiles(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(filesToWatch)\n\n server.watcher.on('all', async (_event, file) => {\n const normalizedFile = file.replace(/\\\\/g, '/')\n\n // Check if the modified file matches our watched config or token patterns\n const isConfigOrToken = filesToWatch.some((pattern) => {\n // If the pattern is an exact file path\n if (pattern === normalizedFile) return true\n\n // If the pattern is a glob, we check if the file matches it.\n // Note: A simple string match or simple glob matcher can be used here.\n // For simplicity and correctness, since token source paths are usually globs,\n // we can match based on path directory containment or general matching.\n // Let's implement a robust matchesGlob check or check if it's one of the token files.\n // Chokidar triggers on actual files, so we want to check if the changed file matches\n // any of the config files or token files/globs.\n return (\n normalizedFile.startsWith(pattern.replace(/\\/\\*\\*/g, '')) ||\n (pattern.includes('*') &&\n new RegExp(\n pattern\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\n .replace(/\\*/g, '.*'),\n ).test(normalizedFile))\n )\n })\n\n if (isConfigOrToken) {\n // Re-resolve configs to handle added/removed configs or changes to config itself\n const currentResolved = await resolveConfigs()\n await runBuilds(currentResolved, path.basename(normalizedFile))\n\n // Dynamically update the watch list in case the configurations changed\n const newWatches = await getWatchFiles(currentResolved)\n server.watcher.add(newWatches)\n }\n })\n },\n },\n\n async watchChange(id) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n await runBuilds(resolved, path.basename(id))\n\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n },\n }\n}\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n"],"mappings":";;;;;;;AAeA,IAAa,KAGR,IAAU,CAAC,MAAM;CACpB,IAAM,EAAE,YAAS,OAAU,GACvB,IAAO,QAAQ,IAAI,GAGjB,KACJ,GACA,IAAqC,WAClC;EACH,IAAI,GAAQ;EACZ,IAAM,IAAS;EACf,AAAI,MAAS,UACX,QAAQ,MAAM,WAAW,EAAO,GAAG,EAAQ,QAAQ,IAEnD,QAAQ,IADC,MAAS,YACN,WAAW,EAAO,GAAG,EAAQ,WAE7B,WAAW,EAAO,GAAG,EAAQ,QAAQ;CAErD,GAGM,IAAiB,YAEl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,CAAc,CAAC;MAG9D,IAAM,IAAa,MAAM,EAAc,CAAe;MACtD,EAAO,QAAQ,IAAI,CAAU;KAC/B;IACF,CAAC;GACH;EACF;EAEA,MAAM,YAAY,GAAI;GACpB,IAAM,IAAW,MAAM,EAAe;GACtC,IAAI,EAAS,WAAW,GAAG;GAE3B,MAAM,EAAU,GAAU,EAAK,SAAS,CAAE,CAAC;GAE3C,IAAM,IAAa,MAAM,EAAc,CAAQ;GAC/C,KAAK,IAAM,KAAQ,GACjB,KAAK,aAAa,CAAI;EAE1B;CACF;AACF,GAEa,IAA2B,kBAAe,CAAe"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'style-dictionary'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { ViteDevServer } from 'vite'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport zlib from 'node:zlib'\nimport StyleDictionary from 'style-dictionary'\nimport { createUnplugin } from 'unplugin'\n\nimport type { UnpluginStyleDictionaryOptions } from './types.js'\n\nexport * from './types.js'\n\n// Whether `file` matches one of the resolved config/token watch patterns.\n// Shared by the Vite-specific `configureServer` watcher and the universal\n// `watchChange` hook — both need it, and both must skip files that don't\n// match: without this filter, `watchChange` reacts to *any* changed\n// module-graph file, including this plugin's own generated output (since\n// consuming code imports it). Every regenerate is itself a \"change\", which\n// without filtering re-triggers a rebuild forever.\nexport function matchesWatchedFile(file: string, patterns: string[]): boolean {\n const normalizedFile = file.replace(/\\\\/g, '/')\n\n return patterns.some((pattern) => {\n // If the pattern is an exact file path\n if (pattern === normalizedFile) return true\n\n // If the pattern is a glob, we check if the file matches it.\n // Note: A simple string match or simple glob matcher can be used here.\n // For simplicity and correctness, since token source paths are usually globs,\n // we can match based on path directory containment or general matching.\n // Let's implement a robust matchesGlob check or check if it's one of the token files.\n // Chokidar triggers on actual files, so we want to check if the changed file matches\n // any of the config files or token files/globs.\n return (\n normalizedFile.startsWith(pattern.replace(/\\/\\*\\*/g, '')) ||\n (pattern.includes('*') &&\n new RegExp(\n pattern.replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\*/g, '.*'),\n ).test(normalizedFile))\n )\n })\n}\n\nexport const unpluginFactory: UnpluginFactory<\n undefined | UnpluginStyleDictionaryOptions,\n false\n> = (options = {}) => {\n const { silent = false } = options\n let root = process.cwd()\n\n // Helper to log if not silent\n const log = (\n message: string,\n type: 'error' | 'info' | 'success' = 'info',\n ) => {\n if (silent) return\n const prefix = '[unplugin-style-dictionary]'\n if (type === 'error') {\n console.error(`\\x1b[31m${prefix} ${message}\\x1b[0m`)\n } else if (type === 'success') {\n console.log(`\\x1b[32m${prefix} ${message}\\x1b[0m`)\n } else {\n console.log(`\\x1b[36m${prefix} ${message}\\x1b[0m`)\n }\n }\n\n // Resolve config file paths / objects\n const resolveConfigs = async (): Promise<\n Array<{ config: Config | string; dir: string; file?: string }>\n > => {\n let rawConfig = options.config\n\n // If config is not defined, look for default configuration files\n if (!rawConfig) {\n const defaults = [\n 'sd.config.json',\n 'config.json',\n 'sd.config.js',\n 'sd.config.mjs',\n ]\n for (const file of defaults) {\n const fullPath = path.resolve(root, file)\n if (fs.existsSync(fullPath)) {\n rawConfig = file\n break\n }\n }\n }\n\n if (!rawConfig) {\n log(\n 'No configuration specified and no default config file found. Style Dictionary will not compile.',\n 'error',\n )\n return []\n }\n\n // Evaluate function if provided\n if (typeof rawConfig === 'function') {\n rawConfig = await rawConfig()\n }\n\n const configs = Array.isArray(rawConfig) ? rawConfig : [rawConfig]\n\n return configs.map((conf) => {\n if (typeof conf === 'string') {\n const fullPath = path.resolve(root, conf)\n return {\n config: fullPath,\n dir: path.dirname(fullPath),\n file: fullPath,\n }\n } else {\n return {\n config: conf,\n dir: root,\n }\n }\n })\n }\n\n // Parse token files to watch\n const getWatchFiles = async (\n resolvedConfigs: Array<{\n config: Config | string\n dir: string\n file?: string\n }>,\n ): Promise<string[]> => {\n const filesToWatch = new Set<string>()\n\n for (const item of resolvedConfigs) {\n if (item.file) {\n filesToWatch.add(item.file.replace(/\\\\/g, '/'))\n }\n\n let configObj: Config | null = null\n\n if (typeof item.config === 'string') {\n try {\n if (item.config.endsWith('.json')) {\n const content = fs.readFileSync(item.config, 'utf-8')\n configObj = JSON.parse(content)\n } else {\n const fileUrl = pathToFileURL(item.config).href\n const module = await import(`${fileUrl}?t=${Date.now()}`)\n configObj = module.default || module\n }\n } catch (err) {\n log(\n `Failed to parse config file: ${item.config}. Error: ${(err as Error).message}`,\n 'error',\n )\n }\n } else {\n configObj = item.config\n }\n\n if (configObj) {\n const addPattern = (pattern: unknown) => {\n if (typeof pattern === 'string') {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(item.dir, pattern)\n const normalized = absolutePattern.replace(/\\\\/g, '/')\n filesToWatch.add(normalized)\n }\n }\n\n if (configObj.source) {\n if (Array.isArray(configObj.source)) {\n configObj.source.forEach(addPattern)\n } else {\n addPattern(configObj.source)\n }\n }\n\n if (configObj.include) {\n if (Array.isArray(configObj.include)) {\n configObj.include.forEach(addPattern)\n } else {\n addPattern(configObj.include)\n }\n }\n }\n }\n\n // Add manually configured watch files\n if (options.watch) {\n const extraWatches = Array.isArray(options.watch)\n ? options.watch\n : [options.watch]\n for (const pattern of extraWatches) {\n const absolutePattern = path.isAbsolute(pattern)\n ? pattern\n : path.resolve(root, pattern)\n filesToWatch.add(absolutePattern.replace(/\\\\/g, '/'))\n }\n }\n\n return Array.from(filesToWatch)\n }\n\n // Compile design tokens\n const runBuilds = async (\n resolvedConfigs: Array<{ config: Config | string; dir: string }>,\n context?: string,\n ) => {\n const startTime = Date.now()\n try {\n if (!context) {\n log('Compiling design tokens...', 'info')\n }\n\n const generatedFiles = new Set<string>()\n\n for (const item of resolvedConfigs) {\n const sd = new StyleDictionary(item.config)\n await sd.hasInitialized\n const silentSD = await sd.extend({\n log: {\n verbosity: 'silent',\n },\n })\n await silentSD.buildAllPlatforms()\n\n if (!context && !silent && silentSD.platforms) {\n for (const platformName of Object.keys(silentSD.platforms)) {\n const platform = silentSD.platforms[platformName]\n if (platform && platform.files) {\n const buildPath = platform.buildPath || ''\n for (const file of platform.files) {\n if (file && file.destination) {\n const absoluteBuildPath = path.isAbsolute(buildPath)\n ? buildPath\n : path.resolve(root, buildPath)\n const absoluteDestination = path.isAbsolute(file.destination)\n ? file.destination\n : path.resolve(absoluteBuildPath, file.destination)\n generatedFiles.add(absoluteDestination)\n }\n }\n }\n }\n }\n }\n\n const duration = Date.now() - startTime\n\n if (context) {\n log(\n `Rebuilt design tokens due to change in ${context} (${duration}ms)`,\n 'success',\n )\n } else {\n if (!silent && generatedFiles.size > 0) {\n const fileInfos: Array<{\n coloredPath: string\n gzipSizeStr: string\n relativeDisplayPath: string\n sizeStr: string\n }> = []\n\n for (const filePath of generatedFiles) {\n if (fs.existsSync(filePath)) {\n const displayPath = path\n .relative(root, filePath)\n .replace(/\\\\/g, '/')\n const dir = path.dirname(displayPath)\n const base = path.basename(displayPath)\n const coloredPath =\n dir === '.'\n ? `\\x1b[32m${base}\\x1b[0m`\n : `\\x1b[90m${dir}/\\x1b[0m\\x1b[32m${base}\\x1b[0m`\n\n try {\n const stats = fs.statSync(filePath)\n const bytes = stats.size\n const sizeStr = `${(bytes / 1024).toFixed(2)} kB`\n\n const content = fs.readFileSync(filePath)\n const gzipBytes = zlib.gzipSync(content).length\n const gzipSizeStr = `${(gzipBytes / 1024).toFixed(2)} kB`\n\n fileInfos.push({\n coloredPath,\n gzipSizeStr,\n relativeDisplayPath: displayPath,\n sizeStr,\n })\n } catch {\n // Ignore errors reading individual files\n }\n }\n }\n\n if (fileInfos.length > 0) {\n const longestPathLength = Math.max(\n ...fileInfos.map((f) => f.relativeDisplayPath.length),\n 0,\n )\n const longestSizeLength = Math.max(\n ...fileInfos.map((f) => f.sizeStr.length),\n 0,\n )\n\n for (const info of fileInfos) {\n const pathPadding = ' '.repeat(\n Math.max(\n 2,\n longestPathLength - info.relativeDisplayPath.length + 2,\n ),\n )\n const sizePadded = info.sizeStr.padStart(longestSizeLength)\n console.log(\n `${info.coloredPath}${pathPadding}\\x1b[90m${sizePadded} │ gzip: ${info.gzipSizeStr}\\x1b[0m`,\n )\n }\n }\n }\n\n log(`Compiled successfully! (${duration}ms)`, 'success')\n }\n } catch (err) {\n const duration = Date.now() - startTime\n log(\n `Compilation failed after ${duration}ms: ${(err as Error).message}`,\n 'error',\n )\n }\n }\n\n return {\n async buildStart() {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n // Register token/config files with the host bundler's watch mode.\n // Works out of the box wherever the host runs a persistent watcher\n // (e.g. `rollup --watch`); Vite's dev server is additionally handled\n // below via the `vite.configureServer` escape hatch, since token\n // sources are plain JSON/JS files outside the module graph and\n // `watchChange` is not reliably invoked by Vite while serving.\n const watchFiles = await getWatchFiles(resolved)\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n\n await runBuilds(resolved)\n },\n\n name: 'unplugin-style-dictionary',\n\n vite: {\n configResolved(config) {\n root = config.root || process.cwd()\n },\n\n async configureServer(server: ViteDevServer) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const filesToWatch = await getWatchFiles(resolved)\n\n // Watch configuration files and token files\n server.watcher.add(filesToWatch)\n\n server.watcher.on('all', async (_event, file) => {\n if (!matchesWatchedFile(file, filesToWatch)) return\n\n // Re-resolve configs to handle added/removed configs or changes to config itself\n const currentResolved = await resolveConfigs()\n await runBuilds(currentResolved, path.basename(file))\n\n // Dynamically update the watch list in case the configurations changed\n const newWatches = await getWatchFiles(currentResolved)\n server.watcher.add(newWatches)\n })\n },\n },\n\n async watchChange(id) {\n const resolved = await resolveConfigs()\n if (resolved.length === 0) return\n\n const watchFiles = await getWatchFiles(resolved)\n // Without this check, watchChange fires for *any* changed file in the\n // host bundler's module graph — including our own generated output,\n // since consuming code imports it. Every regenerate is itself a\n // \"change\", so skipping non-matching files here is what keeps this\n // from rebuilding forever.\n if (!matchesWatchedFile(id, watchFiles)) return\n\n await runBuilds(resolved, path.basename(id))\n\n for (const file of watchFiles) {\n this.addWatchFile(file)\n }\n },\n }\n}\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n"],"mappings":";;;;;;;AAsBA,SAAgB,EAAmB,GAAc,GAA6B;CAC5E,IAAM,IAAiB,EAAK,QAAQ,OAAO,GAAG;CAE9C,OAAO,EAAS,MAAM,MAEhB,MAAY,KAUd,EAAe,WAAW,EAAQ,QAAQ,WAAW,EAAE,CAAC,KACvD,EAAQ,SAAS,GAAG,KACnB,IAAI,OACF,EAAQ,QAAQ,qBAAqB,MAAM,CAAC,CAAC,QAAQ,OAAO,IAAI,CAClE,CAAC,CAAC,KAAK,CAAc,CAE1B;AACH;AAEA,IAAa,KAGR,IAAU,CAAC,MAAM;CACpB,IAAM,EAAE,YAAS,OAAU,GACvB,IAAO,QAAQ,IAAI,GAGjB,KACJ,GACA,IAAqC,WAClC;EACH,IAAI,GAAQ;EACZ,IAAM,IAAS;EACf,AAAI,MAAS,UACX,QAAQ,MAAM,WAAW,EAAO,GAAG,EAAQ,QAAQ,IAEnD,QAAQ,IADC,MAAS,YACN,WAAW,EAAO,GAAG,EAAQ,WAE7B,WAAW,EAAO,GAAG,EAAQ,QAAQ;CAErD,GAGM,IAAiB,YAElB;EACH,IAAI,IAAY,EAAQ;EAGxB,IAAI,CAAC,GAOH,KAAK,IAAM,KAAQ;GALjB;GACA;GACA;GACA;EAEiB,GAAU;GAC3B,IAAM,IAAW,EAAK,QAAQ,GAAM,CAAI;GACxC,IAAI,EAAG,WAAW,CAAQ,GAAG;IAC3B,IAAY;IACZ;GACF;EACF;EAkBF,OAfK,KASD,OAAO,KAAc,eACvB,IAAY,MAAM,EAAU,KAGd,MAAM,QAAQ,CAAS,IAAI,IAAY,CAAC,CAAS,EAAA,CAElD,KAAK,MAAS;GAC3B,IAAI,OAAO,KAAS,UAAU;IAC5B,IAAM,IAAW,E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B,IAAM,IAAW,MAAM,EAAe;GACtC,IAAI,EAAS,WAAW,GAAG;GAQ3B,IAAM,IAAa,MAAM,EAAc,CAAQ;GAC/C,KAAK,IAAM,KAAQ,GACjB,KAAK,aAAa,CAAI;GAGxB,MAAM,EAAU,CAAQ;EAC1B;EAEA,MAAM;EAEN,MAAM;GACJ,eAAe,GAAQ;IACrB,IAAO,EAAO,QAAQ,QAAQ,IAAI;GACpC;GAEA,MAAM,gBAAgB,GAAuB;IAC3C,IAAM,IAAW,MAAM,EAAe;IACtC,IAAI,EAAS,WAAW,GAAG;IAE3B,IAAM,IAAe,MAAM,EAAc,CAAQ;IAKjD,AAFA,EAAO,QAAQ,IAAI,CAAY,GAE/B,EAAO,QAAQ,GAAG,OAAO,OAAO,GAAQ,MAAS;KAC/C,IAAI,CAAC,EAAmB,GAAM,CAAY,GAAG;KAG7C,IAAM,IAAkB,MAAM,EAAe;KAC7C,MAAM,EAAU,GAAiB,EAAK,SAAS,CAAI,CAAC;KAGpD,IAAM,IAAa,MAAM,EAAc,CAAe;KACtD,EAAO,QAAQ,IAAI,CAAU;IAC/B,CAAC;GACH;EACF;EAEA,MAAM,YAAY,GAAI;GACpB,IAAM,IAAW,MAAM,EAAe;GACtC,IAAI,EAAS,WAAW,GAAG;GAE3B,IAAM,IAAa,MAAM,EAAc,CAAQ;GAM1C,MAAmB,GAAI,CAAU,GAEtC;UAAM,EAAU,GAAU,EAAK,SAAS,CAAE,CAAC;IAE3C,KAAK,IAAM,KAAQ,GACjB,KAAK,aAAa,CAAI;GAHmB;EAK7C;CACF;AACF,GAEa,IAA2B,kBAAe,CAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanso-labs/unplugin-style-dictionary",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Compile Style Dictionary design tokens ahead of your bundler (Vite, Rolldown, Rollup, or Webpack) from a single unplugin-based plugin, with automatic watching and rebuilding under Vite",
5
5
  "keywords": [
6
6
  "unplugin",
@@ -48,6 +48,10 @@
48
48
  "module": "./dist/index.js",
49
49
  "types": "./dist/index.d.ts",
50
50
  "type": "module",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/kanso-labs/unplugin-style-dictionary.git"
54
+ },
51
55
  "scripts": {
52
56
  "build": "tsc -b && vite build",
53
57
  "clean": "rimraf dist",
@@ -80,17 +84,17 @@
80
84
  "@commitlint/cli": "21.2.1",
81
85
  "@commitlint/config-conventional": "21.2.0",
82
86
  "@eslint/js": "10.0.1",
83
- "@types/node": "25.9.1",
87
+ "@types/node": "26.1.1",
84
88
  "eslint": "10.5.0",
85
89
  "eslint-config-prettier": "10.1.8",
86
90
  "eslint-plugin-perfectionist": "5.9.1",
87
91
  "eslint-plugin-prettier": "5.5.6",
88
- "globals": "17.6.0",
92
+ "globals": "17.7.0",
89
93
  "husky": "9.1.7",
90
94
  "prettier": "3.8.3",
91
95
  "rimraf": "6.1.3",
92
96
  "rollup": "^4.62.2",
93
- "style-dictionary": "5.4.1",
97
+ "style-dictionary": "5.5.0",
94
98
  "typescript": "6.0.3",
95
99
  "typescript-eslint": "8.61.1",
96
100
  "vite": "8.1.5",