@salty-css/core 0.1.0-refactor-add-additional-paths-to-config-cache.1 → 0.1.0

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.
Files changed (60) hide show
  1. package/README.md +355 -374
  2. package/bin/main.cjs +57 -58
  3. package/bin/main.js +1 -2
  4. package/{class-name-generator-CMWY5KTJ.js → class-name-generator-CUEoPowv.js} +18 -4
  5. package/{class-name-generator-DB5aQwC_.cjs → class-name-generator-MtPkBfM_.cjs} +19 -5
  6. package/compiler/helpers.cjs +10 -2
  7. package/compiler/helpers.d.ts +3 -2
  8. package/compiler/helpers.js +11 -3
  9. package/compiler/resolve-import.d.ts +17 -0
  10. package/compiler/salty-compiler.cjs +144 -33
  11. package/compiler/salty-compiler.d.ts +2 -5
  12. package/compiler/salty-compiler.js +149 -38
  13. package/config/index.cjs +4 -0
  14. package/config/index.js +5 -1
  15. package/css/index.cjs +0 -4
  16. package/css/index.d.ts +0 -1
  17. package/css/index.js +0 -4
  18. package/css/keyframes.cjs +2 -2
  19. package/css/keyframes.js +2 -2
  20. package/factories/define-font.d.ts +28 -0
  21. package/factories/define-import.d.ts +14 -0
  22. package/factories/index.cjs +140 -0
  23. package/factories/index.d.ts +2 -0
  24. package/factories/index.js +140 -0
  25. package/generators/index.cjs +3 -3
  26. package/generators/index.js +3 -3
  27. package/helpers/color.d.ts +6 -0
  28. package/instances/classname-instance.cjs +1 -1
  29. package/instances/classname-instance.js +1 -1
  30. package/package.json +1 -13
  31. package/{parse-styles-C54MOrPg.cjs → parse-styles-BbI-2wdn.cjs} +196 -11
  32. package/{parse-styles-CLMTHo2H.js → parse-styles-BgVqQAni.js} +196 -11
  33. package/parsers/index.cjs +93 -5
  34. package/parsers/index.js +97 -9
  35. package/parsers/parse-templates.d.ts +10 -0
  36. package/parsers/parser-regexes.d.ts +1 -0
  37. package/parsers/resolve-template-variants.d.ts +21 -0
  38. package/runtime/index.cjs +16 -3
  39. package/runtime/index.d.ts +7 -0
  40. package/runtime/index.js +16 -3
  41. package/{to-hash-DAN2LcHK.js → to-hash-DSoCPs8D.js} +8 -0
  42. package/{to-hash-C05Y906F.cjs → to-hash-DT2ImSPA.cjs} +8 -0
  43. package/types/config-types.d.ts +33 -2
  44. package/types/font-types.d.ts +53 -0
  45. package/util/index.cjs +3 -4
  46. package/util/index.js +1 -2
  47. package/util/module-type.d.ts +1 -1
  48. package/cache/resolve-dynamic-config-cache.cjs +0 -64
  49. package/cache/resolve-dynamic-config-cache.d.ts +0 -20
  50. package/cache/resolve-dynamic-config-cache.js +0 -64
  51. package/compiler/copy-config-cache.cjs +0 -39
  52. package/compiler/copy-config-cache.d.ts +0 -17
  53. package/compiler/copy-config-cache.js +0 -39
  54. package/css/dynamic-styles.cjs +0 -28
  55. package/css/dynamic-styles.d.ts +0 -49
  56. package/css/dynamic-styles.js +0 -28
  57. package/dash-case-DIwKaYgE.cjs +0 -9
  58. package/dash-case-DblXvymC.js +0 -10
  59. package/logger-7xz0pyAz.cjs +0 -12
  60. package/logger-hHmCwThj.js +0 -13
package/bin/main.cjs CHANGED
@@ -9,7 +9,6 @@ const path = require("path");
9
9
  const promises = require("fs/promises");
10
10
  const child_process = require("child_process");
11
11
  const ora = require("ora");
12
- const logger = require("../logger-7xz0pyAz.cjs");
13
12
  const pascalCase = require("../pascal-case-By_l58S-.cjs");
14
13
  const ejs = require("ejs");
15
14
  const promises$1 = require("readline/promises");
@@ -66,9 +65,9 @@ async function formatWithPrettier(filePath) {
66
65
  const hasPrettier = hasPrettierInstalled();
67
66
  if (!hasPrettier) return;
68
67
  await execAsync(`./node_modules/.bin/prettier --write "${filePath}"`);
69
- logger.logger.info(`Formatted ${filePath} with Prettier`);
68
+ compiler_saltyCompiler.logger.info(`Formatted ${filePath} with Prettier`);
70
69
  } catch (error) {
71
- logger.logger.error(`Error formatting ${filePath} with Prettier:`, error);
70
+ compiler_saltyCompiler.logger.error(`Error formatting ${filePath} with Prettier:`, error);
72
71
  }
73
72
  }
74
73
  const SALTYRC_FILENAME = ".saltyrc.json";
@@ -111,8 +110,8 @@ const writeProjectToRc = async (cwd, relativeProjectPath, framework) => {
111
110
  const existing = await readRawRc(cwd);
112
111
  const { content, changed, created } = upsertProjectInRc(existing, relativeProjectPath, framework);
113
112
  if (!changed) return false;
114
- if (created) logger.logger.info("Creating file: " + path2);
115
- else logger.logger.info("Edit file: " + path2);
113
+ if (created) compiler_saltyCompiler.logger.info("Creating file: " + path2);
114
+ else compiler_saltyCompiler.logger.info("Edit file: " + path2);
116
115
  await promises.writeFile(path2, content);
117
116
  await formatWithPrettier(path2);
118
117
  return true;
@@ -149,18 +148,18 @@ const buildContext = async (opts) => {
149
148
  };
150
149
  const registerBuildCommand = (program, defaultProject) => {
151
150
  program.command("build [directory]").alias("b").description("Build the Salty-CSS project.").option("-d, --dir <dir>", "Project directory to build the project in.").option("--watch", "Watch for changes and rebuild the project.").option("--mode <mode>", 'Build mode: "production" or "development". Defaults to NODE_ENV-based detection.').action(async function(_dir = defaultProject) {
152
- logger.logger.info("Building the Salty-CSS project...");
151
+ compiler_saltyCompiler.logger.info("Building the Salty-CSS project...");
153
152
  const { dir = _dir, watch, mode } = this.opts();
154
153
  if (mode !== void 0 && mode !== "production" && mode !== "development") {
155
- return logger.logError(`Invalid --mode "${mode}". Expected "production" or "development".`);
154
+ return compiler_saltyCompiler.logError(`Invalid --mode "${mode}". Expected "production" or "development".`);
156
155
  }
157
156
  const resolved = dir ?? await getDefaultProject();
158
- if (!resolved) return logger.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
157
+ if (!resolved) return compiler_saltyCompiler.logError("Project directory must be provided. Add it as the first argument after build command or use the --dir option.");
159
158
  const projectDir = resolveProjectDir(resolved);
160
159
  const compiler = new compiler_saltyCompiler.SaltyCompiler(projectDir, { mode });
161
160
  await compiler.generateCss();
162
161
  if (watch) {
163
- logger.logger.info("Watching for changes in the project directory...");
162
+ compiler_saltyCompiler.logger.info("Watching for changes in the project directory...");
164
163
  fs.watch(projectDir, { recursive: true }, async (_event, filePath) => {
165
164
  const shouldRestart$1 = await shouldRestart.checkShouldRestart(filePath);
166
165
  if (shouldRestart$1) {
@@ -246,13 +245,13 @@ const readTemplate = async (key, options) => {
246
245
  const registerGenerateCommand = (program, defaultProject) => {
247
246
  program.command("generate [file] [directory]").alias("g").description("Generate a new component file.").option("-f, --file <file>", "File to generate.").option("-d, --dir <dir>", "Project directory to generate the file in.").option("-t, --tag <tag>", "HTML tag of the component.", "div").option("-n, --name <name>", "Name of the component.").option("-c, --className <className>", "CSS class of the component.").option("-r, --reactComponent", "Generate a wrapper component file alongside the styled definition.").action(async function(_file, _dir = defaultProject) {
248
247
  const { file = _file, dir = _dir, tag, name, className, reactComponent = false } = this.opts();
249
- if (!file) return logger.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
250
- if (!dir) return logger.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
248
+ if (!file) return compiler_saltyCompiler.logError("File to generate must be provided. Add it as the first argument after generate command or use the --file option.");
249
+ if (!dir) return compiler_saltyCompiler.logError("Project directory must be provided. Add it as the second argument after generate command or use the --dir option.");
251
250
  let ctx;
252
251
  try {
253
252
  ctx = await buildContext({ dir, requirePackageJson: false });
254
253
  } catch (err) {
255
- return logger.logError(err instanceof Error ? err.message : String(err));
254
+ return compiler_saltyCompiler.logError(err instanceof Error ? err.message : String(err));
256
255
  }
257
256
  const rcFramework = getFramework(getProjectFramework(ctx.rcFile, ctx.relativeProjectPath));
258
257
  const framework = rcFramework ?? await detectFramework(ctx);
@@ -266,13 +265,13 @@ const registerGenerateCommand = (program, defaultProject) => {
266
265
  const formattedStyledFilePath = path.format(parsedFilePath);
267
266
  const alreadyExists = await promises.readFile(formattedStyledFilePath, "utf-8").catch(() => void 0);
268
267
  if (alreadyExists !== void 0) {
269
- logger.logger.error("File already exists: " + formattedStyledFilePath);
268
+ compiler_saltyCompiler.logger.error("File already exists: " + formattedStyledFilePath);
270
269
  return;
271
270
  }
272
271
  let styledComponentName = pascalCase.pascalCase(name || parsedFilePath.base.replace(/\.css\.\w+$/, ""));
273
272
  if (reactComponent) {
274
273
  if (!framework.templates.component) {
275
- return logger.logError(`--reactComponent is not supported for the ${framework.name} framework.`);
274
+ return compiler_saltyCompiler.logError(`--reactComponent is not supported for the ${framework.name} framework.`);
276
275
  }
277
276
  const componentName = styledComponentName + "Component";
278
277
  styledComponentName = styledComponentName + "Wrapper";
@@ -288,13 +287,13 @@ const registerGenerateCommand = (program, defaultProject) => {
288
287
  parsedFilePath.ext = framework.templates.component.wrapperExt;
289
288
  parsedFilePath.base = parsedFilePath.name + parsedFilePath.ext;
290
289
  const formattedWrapperPath = path.format(parsedFilePath);
291
- logger.logger.info("Generating a new file: " + formattedWrapperPath);
290
+ compiler_saltyCompiler.logger.info("Generating a new file: " + formattedWrapperPath);
292
291
  await promises.writeFile(formattedWrapperPath, wrapperContent);
293
292
  await formatWithPrettier(formattedWrapperPath);
294
293
  }
295
294
  const styledKey = reactComponent && framework.templates.component ? framework.templates.component.styled : framework.templates.styled;
296
295
  const { content } = await readTemplate(styledKey, { tag, name: styledComponentName, className });
297
- logger.logger.info("Generating a new file: " + formattedStyledFilePath);
296
+ compiler_saltyCompiler.logger.info("Generating a new file: " + formattedStyledFilePath);
298
297
  await promises.writeFile(formattedStyledFilePath, content);
299
298
  await formatWithPrettier(formattedStyledFilePath);
300
299
  });
@@ -395,13 +394,13 @@ const astroIntegration = {
395
394
  const existing = await promises.readFile(configPath, "utf-8").catch(() => void 0);
396
395
  if (existing === void 0) return null;
397
396
  const result = editAstroConfig(existing);
398
- if (result.warning) logger.logger.warn(result.warning);
397
+ if (result.warning) compiler_saltyCompiler.logger.warn(result.warning);
399
398
  if (result.content === null) return null;
400
399
  const newContent = result.content;
401
400
  return {
402
401
  packages: [`-D ${astroPackage(ctx.cliVersion)}`],
403
402
  execute: async () => {
404
- logger.logger.info("Adding Salty-CSS integration to Astro config: " + configPath);
403
+ compiler_saltyCompiler.logger.info("Adding Salty-CSS integration to Astro config: " + configPath);
405
404
  await promises.writeFile(configPath, newContent);
406
405
  await formatWithPrettier(configPath);
407
406
  return { changed: true };
@@ -468,17 +467,17 @@ const eslintIntegration = {
468
467
  plan: async (ctx, configPath) => {
469
468
  const existing = await promises.readFile(configPath, "utf-8").catch(() => void 0);
470
469
  if (existing === void 0) {
471
- logger.logger.error("Could not read ESLint config file.");
470
+ compiler_saltyCompiler.logger.error("Could not read ESLint config file.");
472
471
  return null;
473
472
  }
474
473
  const result = editEslintConfig(existing, configPath.endsWith("js"));
475
- if (result.warning) logger.logger.warn(result.warning);
474
+ if (result.warning) compiler_saltyCompiler.logger.warn(result.warning);
476
475
  if (result.content === null) return null;
477
476
  const newContent = result.content;
478
477
  return {
479
478
  packages: [corePackages.eslintConfigCore(ctx.cliVersion)],
480
479
  execute: async () => {
481
- logger.logger.info("Edit file: " + configPath);
480
+ compiler_saltyCompiler.logger.info("Edit file: " + configPath);
482
481
  await promises.writeFile(configPath, newContent);
483
482
  await formatWithPrettier(configPath);
484
483
  return { changed: true };
@@ -521,7 +520,7 @@ const nextIntegration = {
521
520
  return {
522
521
  packages: [`-D ${nextPackage(ctx.cliVersion)}`],
523
522
  execute: async () => {
524
- logger.logger.info("Adding Salty-CSS plugin to Next.js config...");
523
+ compiler_saltyCompiler.logger.info("Adding Salty-CSS plugin to Next.js config...");
525
524
  await promises.writeFile(configPath, content);
526
525
  await formatWithPrettier(configPath);
527
526
  return { changed: true };
@@ -552,8 +551,8 @@ const viteIntegration = {
552
551
  return {
553
552
  packages: [`-D ${vitePackage(ctx.cliVersion)}`],
554
553
  execute: async () => {
555
- logger.logger.info("Edit file: " + configPath);
556
- logger.logger.info("Adding Salty-CSS plugin to Vite config...");
554
+ compiler_saltyCompiler.logger.info("Edit file: " + configPath);
555
+ compiler_saltyCompiler.logger.info("Adding Salty-CSS plugin to Vite config...");
557
556
  await promises.writeFile(configPath, content);
558
557
  await formatWithPrettier(configPath);
559
558
  return { changed: true };
@@ -584,12 +583,12 @@ const applyIntegrationPlans = async (planned) => {
584
583
  const writeProjectFile = async (projectDir, fileName, content) => {
585
584
  const filePath = path.join(projectDir, fileName);
586
585
  if (fs.existsSync(filePath)) {
587
- logger.logger.debug("File already exists: " + filePath);
586
+ compiler_saltyCompiler.logger.debug("File already exists: " + filePath);
588
587
  return;
589
588
  }
590
589
  const additionalFolders = fileName.split("/").slice(0, -1).join("/");
591
590
  if (additionalFolders) await promises.mkdir(path.join(projectDir, additionalFolders), { recursive: true });
592
- logger.logger.info("Creating file: " + filePath);
591
+ compiler_saltyCompiler.logger.info("Creating file: " + filePath);
593
592
  await promises.writeFile(filePath, content);
594
593
  await formatWithPrettier(filePath);
595
594
  };
@@ -598,13 +597,13 @@ const ensureGitignoreSaltygen = async (rootDir) => {
598
597
  const existing = await promises.readFile(path$1, "utf-8").catch(() => void 0);
599
598
  if (existing === void 0) return;
600
599
  if (existing.includes("saltygen")) return;
601
- logger.logger.info("Edit file: " + path$1);
600
+ compiler_saltyCompiler.logger.info("Edit file: " + path$1);
602
601
  await promises.writeFile(path$1, existing + "\n\n# Salty-CSS\nsaltygen\n");
603
602
  };
604
603
  const importSaltygenIntoCss = async (projectDir, explicitCssFile) => {
605
604
  const target = explicitCssFile ?? await findGlobalCssFile(projectDir);
606
605
  if (!target) {
607
- logger.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
606
+ compiler_saltyCompiler.logger.warn("Could not find a CSS file to import the generated CSS. Please add it manually.");
608
607
  return;
609
608
  }
610
609
  const cssFilePath = path.join(projectDir, target);
@@ -613,14 +612,14 @@ const importSaltygenIntoCss = async (projectDir, explicitCssFile) => {
613
612
  if (cssFileContent.includes("saltygen")) return;
614
613
  const cssFileFolder = path.join(cssFilePath, "..");
615
614
  const relPath = path.relative(cssFileFolder, path.join(projectDir, "saltygen/index.css"));
616
- logger.logger.info("Adding global import statement to CSS file: " + cssFilePath);
615
+ compiler_saltyCompiler.logger.info("Adding global import statement to CSS file: " + cssFilePath);
617
616
  await promises.writeFile(cssFilePath, `@import '${relPath}';
618
617
  ` + cssFileContent);
619
618
  await formatWithPrettier(cssFilePath);
620
619
  };
621
620
  const wirePrepareScript = async () => {
622
621
  const pkg = await readPackageJson().catch(() => {
623
- logger.logError("Could not read package.json file.");
622
+ compiler_saltyCompiler.logError("Could not read package.json file.");
624
623
  return void 0;
625
624
  });
626
625
  if (!pkg) return;
@@ -632,11 +631,11 @@ const registerInitCommand = (program) => {
632
631
  try {
633
632
  const opts = this.opts();
634
633
  const dir = opts.dir ?? _dir;
635
- if (!dir) return logger.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
634
+ if (!dir) return compiler_saltyCompiler.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");
636
635
  const ctx = await buildContext({ dir, skipInstall: opts.skipInstall, yes: opts.yes });
637
- logger.logger.info("Initializing a new Salty-CSS project!");
636
+ compiler_saltyCompiler.logger.info("Initializing a new Salty-CSS project!");
638
637
  const framework = await detectFramework(ctx);
639
- logger.logger.info(`Detected framework: ${framework.name}`);
638
+ compiler_saltyCompiler.logger.info(`Detected framework: ${framework.name}`);
640
639
  const plannedIntegrations = await planIntegrations(ctx);
641
640
  if (!ctx.skipInstall) {
642
641
  const packages = [
@@ -655,29 +654,29 @@ const registerInitCommand = (program) => {
655
654
  await importSaltygenIntoCss(ctx.projectDir, opts.cssFile);
656
655
  await applyIntegrationPlans(plannedIntegrations);
657
656
  await wirePrepareScript();
658
- logger.logger.info("Running the build to generate initial CSS...");
657
+ compiler_saltyCompiler.logger.info("Running the build to generate initial CSS...");
659
658
  const compiler = new compiler_saltyCompiler.SaltyCompiler(ctx.projectDir);
660
659
  await compiler.generateCss();
661
- logger.logger.info("🎉 Salty CSS project initialized successfully!");
662
- logger.logger.info("Next steps:");
663
- logger.logger.info("1. Configure variables and templates in `salty.config.ts`");
664
- logger.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
665
- logger.logger.info("3. Run `npx salty-css build` to generate the CSS");
666
- logger.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
667
- logger.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
660
+ compiler_saltyCompiler.logger.info("🎉 Salty CSS project initialized successfully!");
661
+ compiler_saltyCompiler.logger.info("Next steps:");
662
+ compiler_saltyCompiler.logger.info("1. Configure variables and templates in `salty.config.ts`");
663
+ compiler_saltyCompiler.logger.info("2. Create a new component with `npx salty-css generate [component-name]`");
664
+ compiler_saltyCompiler.logger.info("3. Run `npx salty-css build` to generate the CSS");
665
+ compiler_saltyCompiler.logger.info("4. Read about the features in the documentation: https://salty-css.dev");
666
+ compiler_saltyCompiler.logger.info("5. Star the project on GitHub: https://github.com/margarita-form/salty-css ⭐");
668
667
  } catch (err) {
669
- return logger.logError(err instanceof Error ? err.message : String(err));
668
+ return compiler_saltyCompiler.logError(err instanceof Error ? err.message : String(err));
670
669
  }
671
670
  });
672
671
  };
673
672
  const getSaltyCssPackages = async () => {
674
673
  const packageJSONPath = path.join(process.cwd(), "package.json");
675
- const packageJson = await readPackageJson(packageJSONPath).catch((err) => logger.logError(err));
676
- if (!packageJson) return logger.logError("Could not read package.json file.");
674
+ const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_saltyCompiler.logError(err));
675
+ if (!packageJson) return compiler_saltyCompiler.logError("Could not read package.json file.");
677
676
  const allDependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
678
677
  const saltyCssPackages = Object.entries(allDependencies).filter(([name]) => name === "salty-css" || name.startsWith("@salty-css/"));
679
678
  if (!saltyCssPackages.length) {
680
- return logger.logError(
679
+ return compiler_saltyCompiler.logError(
681
680
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + packageJSONPath
682
681
  );
683
682
  }
@@ -687,7 +686,7 @@ const registerUpdateCommand = (program) => {
687
686
  program.command("update [version]").alias("up").description("Update Salty-CSS packages to the latest or specified version.").option("-v, --version <version>", "Version to update to.").option("--legacy-peer-deps <legacyPeerDeps>", "Use legacy peer dependencies (not recommended).", false).option("-y, --yes", "Skip confirmation prompts (install and rebuild).").option("-d, --dir <dir>", "Project directory to rebuild after updating.").action(async function(_version = "latest") {
688
687
  const { legacyPeerDeps, version = _version, yes = false, dir } = this.opts();
689
688
  const saltyCssPackages = await getSaltyCssPackages();
690
- if (!saltyCssPackages) return logger.logError("Could not update Salty-CSS packages as any were found in package.json.");
689
+ if (!saltyCssPackages) return compiler_saltyCompiler.logError("Could not update Salty-CSS packages as any were found in package.json.");
691
690
  const cli = await readThisPackageJson();
692
691
  const packagesToUpdate = saltyCssPackages.map(([name]) => {
693
692
  if (version === "@") return `${name}@${cli.version}`;
@@ -696,16 +695,16 @@ const registerUpdateCommand = (program) => {
696
695
  try {
697
696
  await confirmInstall(packagesToUpdate, yes);
698
697
  } catch (err) {
699
- return logger.logError(err instanceof Error ? err.message : String(err));
698
+ return compiler_saltyCompiler.logError(err instanceof Error ? err.message : String(err));
700
699
  }
701
700
  if (legacyPeerDeps) {
702
- logger.logger.warn("Using legacy peer dependencies to update packages.");
701
+ compiler_saltyCompiler.logger.warn("Using legacy peer dependencies to update packages.");
703
702
  await npmInstall(...packagesToUpdate, "--legacy-peer-deps");
704
703
  } else {
705
704
  await npmInstall(...packagesToUpdate);
706
705
  }
707
706
  const updatedPackages = await getSaltyCssPackages();
708
- if (!updatedPackages) return logger.logError("Something went wrong while reading the updated packages.");
707
+ if (!updatedPackages) return compiler_saltyCompiler.logError("Something went wrong while reading the updated packages.");
709
708
  const mappedByVersions = updatedPackages.reduce((acc, [name, version2]) => {
710
709
  if (!acc[version2]) acc[version2] = [];
711
710
  acc[version2].push(name);
@@ -714,41 +713,41 @@ const registerUpdateCommand = (program) => {
714
713
  const versionsCount = Object.keys(mappedByVersions).length;
715
714
  if (versionsCount === 1) {
716
715
  const v = Object.keys(mappedByVersions)[0];
717
- logger.logger.info(`Updated to all Salty CSS packages successfully to ${v.replace(/^\^/, "")}`);
716
+ compiler_saltyCompiler.logger.info(`Updated to all Salty CSS packages successfully to ${v.replace(/^\^/, "")}`);
718
717
  } else {
719
718
  for (const [v, names] of Object.entries(mappedByVersions)) {
720
- logger.logger.info(`Updated to ${v.replace(/^\^/, "")}: ${names.join(", ")}`);
719
+ compiler_saltyCompiler.logger.info(`Updated to ${v.replace(/^\^/, "")}: ${names.join(", ")}`);
721
720
  }
722
721
  }
723
722
  const project = dir ?? await getDefaultProject();
724
723
  if (!project) {
725
- logger.logger.warn("Skipping rebuild: no project directory configured. Run `salty-css build [dir]` manually.");
724
+ compiler_saltyCompiler.logger.warn("Skipping rebuild: no project directory configured. Run `salty-css build [dir]` manually.");
726
725
  return;
727
726
  }
728
727
  const shouldRebuild = await confirmYesNo("Rebuild Salty CSS now?", { yes });
729
728
  if (!shouldRebuild) return;
730
729
  const projectDir = resolveProjectDir(project);
731
- logger.logger.info("Rebuilding Salty-CSS project...");
730
+ compiler_saltyCompiler.logger.info("Rebuilding Salty-CSS project...");
732
731
  await new compiler_saltyCompiler.SaltyCompiler(projectDir).generateCss();
733
- logger.logger.info("Rebuild complete.");
732
+ compiler_saltyCompiler.logger.info("Rebuild complete.");
734
733
  });
735
734
  };
736
735
  const registerVersionOption = (program) => {
737
736
  program.option("-v, --version", "Show the current version of Salty-CSS.").action(async function() {
738
737
  const cli = await readThisPackageJson();
739
- logger.logger.info("CLI is running: " + cli.version);
738
+ compiler_saltyCompiler.logger.info("CLI is running: " + cli.version);
740
739
  const packageJSONPath = path.join(process.cwd(), "package.json");
741
- const packageJson = await readPackageJson(packageJSONPath).catch((err) => logger.logError(err));
740
+ const packageJson = await readPackageJson(packageJSONPath).catch((err) => compiler_saltyCompiler.logError(err));
742
741
  if (!packageJson) return;
743
742
  const allDependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
744
743
  const saltyCssPackages = Object.keys(allDependencies).filter((dep) => dep === "salty-css" || dep.startsWith("@salty-css/"));
745
744
  if (!saltyCssPackages.length) {
746
- return logger.logError(
745
+ return compiler_saltyCompiler.logError(
747
746
  "No Salty-CSS packages found in package.json. Make sure you are running update command in the same directory! Used package.json path: " + packageJSONPath
748
747
  );
749
748
  }
750
749
  for (const dep of saltyCssPackages) {
751
- logger.logger.info(`${dep}: ${allDependencies[dep]}`);
750
+ compiler_saltyCompiler.logger.info(`${dep}: ${allDependencies[dep]}`);
752
751
  }
753
752
  });
754
753
  };
package/bin/main.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import { Command } from "commander";
2
2
  import { existsSync, watch } from "fs";
3
- import { SaltyCompiler } from "../compiler/salty-compiler.js";
3
+ import { l as logger, a as logError, SaltyCompiler } from "../compiler/salty-compiler.js";
4
4
  import { isSaltyFile } from "../compiler/helpers.js";
5
5
  import { c as checkShouldRestart } from "../should-restart-CXIO0jxY.js";
6
6
  import { join, relative, parse, format } from "path";
7
7
  import { readFile, writeFile, mkdir } from "fs/promises";
8
8
  import { exec } from "child_process";
9
9
  import ora from "ora";
10
- import { l as logger, a as logError } from "../logger-hHmCwThj.js";
11
10
  import { p as pascalCase } from "../pascal-case-F3Usi5Wf.js";
12
11
  import ejs from "ejs";
13
12
  import { createInterface } from "readline/promises";
@@ -1,9 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { p as parseAndJoinStyles } from "./parse-styles-CLMTHo2H.js";
5
- import { d as dashCase } from "./dash-case-DblXvymC.js";
6
- import { t as toHash } from "./to-hash-DAN2LcHK.js";
4
+ import { p as parseAndJoinStyles, b as parseTemplateCallSite } from "./parse-styles-BgVqQAni.js";
5
+ import { t as toHash, d as dashCase } from "./to-hash-DSoCPs8D.js";
7
6
  class StylesGenerator {
8
7
  constructor(params) {
9
8
  __publicField(this, "buildContext", {});
@@ -50,7 +49,22 @@ class StylesGenerator {
50
49
  if (!(config == null ? void 0 : config.templates) || !this.params.base || this.priority > 0) return [];
51
50
  const templateKeys = Object.keys(config.templates);
52
51
  return Object.entries(this.params.base).reduce((acc, [key, value]) => {
53
- if (templateKeys.includes(key)) acc.push("t_" + toHash(dashCase(`${key}-${value}`), 4));
52
+ if (!templateKeys.includes(key)) return acc;
53
+ const callSite = parseTemplateCallSite(value);
54
+ if (!callSite || callSite.path.length === 0) return acc;
55
+ const { path, variants } = callSite;
56
+ const cumulative = [];
57
+ for (const part of path) {
58
+ cumulative.push(part);
59
+ const baseClassName = dashCase(`${key}-${cumulative.join(".")}`);
60
+ acc.push("t_" + toHash(baseClassName, 4));
61
+ for (const [axis, axisValue] of Object.entries(variants)) {
62
+ if (axisValue === false || axisValue === void 0) continue;
63
+ const valueSuffix = axisValue === true ? "" : `-${dashCase(String(axisValue))}`;
64
+ const variantClassName = `${baseClassName}-${dashCase(axis)}${valueSuffix}`;
65
+ acc.push("tv_" + toHash(variantClassName, 4));
66
+ }
67
+ }
54
68
  return acc;
55
69
  }, []);
56
70
  }
@@ -2,9 +2,8 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- const parseStyles = require("./parse-styles-C54MOrPg.cjs");
6
- const dashCase = require("./dash-case-DIwKaYgE.cjs");
7
- const toHash = require("./to-hash-C05Y906F.cjs");
5
+ const parseStyles = require("./parse-styles-BbI-2wdn.cjs");
6
+ const toHash = require("./to-hash-DT2ImSPA.cjs");
8
7
  class StylesGenerator {
9
8
  constructor(params) {
10
9
  __publicField(this, "buildContext", {});
@@ -35,7 +34,7 @@ class StylesGenerator {
35
34
  get cssFileName() {
36
35
  const { callerName } = this.buildContext;
37
36
  if (callerName) {
38
- const dasherized = dashCase.dashCase(callerName);
37
+ const dasherized = toHash.dashCase(callerName);
39
38
  return `cl_${dasherized}-${this.hash}.css`;
40
39
  }
41
40
  return `${this.hash}.css`;
@@ -51,7 +50,22 @@ class StylesGenerator {
51
50
  if (!(config == null ? void 0 : config.templates) || !this.params.base || this.priority > 0) return [];
52
51
  const templateKeys = Object.keys(config.templates);
53
52
  return Object.entries(this.params.base).reduce((acc, [key, value]) => {
54
- if (templateKeys.includes(key)) acc.push("t_" + toHash.toHash(dashCase.dashCase(`${key}-${value}`), 4));
53
+ if (!templateKeys.includes(key)) return acc;
54
+ const callSite = parseStyles.parseTemplateCallSite(value);
55
+ if (!callSite || callSite.path.length === 0) return acc;
56
+ const { path, variants } = callSite;
57
+ const cumulative = [];
58
+ for (const part of path) {
59
+ cumulative.push(part);
60
+ const baseClassName = toHash.dashCase(`${key}-${cumulative.join(".")}`);
61
+ acc.push("t_" + toHash.toHash(baseClassName, 4));
62
+ for (const [axis, axisValue] of Object.entries(variants)) {
63
+ if (axisValue === false || axisValue === void 0) continue;
64
+ const valueSuffix = axisValue === true ? "" : `-${toHash.dashCase(String(axisValue))}`;
65
+ const variantClassName = `${baseClassName}-${toHash.dashCase(axis)}${valueSuffix}`;
66
+ acc.push("tv_" + toHash.toHash(variantClassName, 4));
67
+ }
68
+ }
55
69
  return acc;
56
70
  }, []);
57
71
  }
@@ -16,11 +16,19 @@ const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
16
16
  return value;
17
17
  };
18
18
  const saltyFileExtensions = ["salty", "css", "styles", "styled"];
19
+ const tsFileExtensions = ["ts", "tsx", "js", "jsx", "mjs", "cjs"];
19
20
  const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20
- const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].map(escapeRegExp).join("|")})\\.`);
21
- const isSaltyFile = (file, additional = []) => saltyFileRegExp(additional).test(file);
21
+ const saltyFileRegExp = (additional = [], testExtension = true) => {
22
+ const extensions = [...saltyFileExtensions, ...additional].map(escapeRegExp).join("|");
23
+ if (testExtension) {
24
+ return new RegExp(`\\.(${extensions})\\.(${tsFileExtensions.map(escapeRegExp).join("|")})$`);
25
+ }
26
+ return new RegExp(`\\.(${extensions})\\.`);
27
+ };
28
+ const isSaltyFile = (file, additional = [], testExtension = true) => saltyFileRegExp(additional, testExtension).test(file);
22
29
  exports.getCorePackageRoot = getCorePackageRoot;
23
30
  exports.isSaltyFile = isSaltyFile;
24
31
  exports.resolveExportValue = resolveExportValue;
25
32
  exports.saltyFileExtensions = saltyFileExtensions;
26
33
  exports.saltyFileRegExp = saltyFileRegExp;
34
+ exports.tsFileExtensions = tsFileExtensions;
@@ -1,5 +1,6 @@
1
1
  export declare const getCorePackageRoot: () => string;
2
2
  export declare const resolveExportValue: <T>(value: unknown, maxLevel?: number, _level?: number) => Promise<T>;
3
3
  export declare const saltyFileExtensions: string[];
4
- export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
5
- export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
4
+ export declare const tsFileExtensions: string[];
5
+ export declare const saltyFileRegExp: (additional?: string[], testExtension?: boolean) => RegExp;
6
+ export declare const isSaltyFile: (file: string, additional?: string[], testExtension?: boolean) => boolean;
@@ -13,13 +13,21 @@ const resolveExportValue = async (value, maxLevel = 10, _level = 0) => {
13
13
  return value;
14
14
  };
15
15
  const saltyFileExtensions = ["salty", "css", "styles", "styled"];
16
+ const tsFileExtensions = ["ts", "tsx", "js", "jsx", "mjs", "cjs"];
16
17
  const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
17
- const saltyFileRegExp = (additional = []) => new RegExp(`\\.(${[...saltyFileExtensions, ...additional].map(escapeRegExp).join("|")})\\.`);
18
- const isSaltyFile = (file, additional = []) => saltyFileRegExp(additional).test(file);
18
+ const saltyFileRegExp = (additional = [], testExtension = true) => {
19
+ const extensions = [...saltyFileExtensions, ...additional].map(escapeRegExp).join("|");
20
+ if (testExtension) {
21
+ return new RegExp(`\\.(${extensions})\\.(${tsFileExtensions.map(escapeRegExp).join("|")})$`);
22
+ }
23
+ return new RegExp(`\\.(${extensions})\\.`);
24
+ };
25
+ const isSaltyFile = (file, additional = [], testExtension = true) => saltyFileRegExp(additional, testExtension).test(file);
19
26
  export {
20
27
  getCorePackageRoot,
21
28
  isSaltyFile,
22
29
  resolveExportValue,
23
30
  saltyFileExtensions,
24
- saltyFileRegExp
31
+ saltyFileRegExp,
32
+ tsFileExtensions
25
33
  };
@@ -0,0 +1,17 @@
1
+ import { ImportSpec } from '../factories/define-import';
2
+ export interface ResolveImportOptions {
3
+ /**
4
+ * Override for node_modules resolution. Receives the bare specifier (with any leading `~` already
5
+ * stripped) and the source file path of the salty file that called `defineImport`. Must return the
6
+ * absolute filesystem path of the resolved CSS file. Defaults to `createRequire(sourceFile).resolve`.
7
+ */
8
+ resolveModule?: (specifier: string, sourceFile: string) => string;
9
+ /**
10
+ * Override for copying resolved node_modules CSS into `<destDir>/imports/`. Receives the absolute
11
+ * source and destination paths. Defaults to `copyFileSync`.
12
+ */
13
+ copyAsset?: (from: string, to: string) => void;
14
+ }
15
+ export declare const resolveImport: (spec: ImportSpec, sourceFile: string, destDir: string, options?: ResolveImportOptions) => {
16
+ rule: string;
17
+ };