Skip to content

The plugin-tailwind template path resolves inconsistently (existence check vs file read) #718

Description

@burkeshartsis

Versions

  • @terrazzo/cli: 2.0.1
  • @terrazzo/plugin-css: 2.0.1
  • @terrazzo/plugin-tailwind: 2.0.1

Node.js version

24.7.0

OS + version

26.0.1

Description

The @terrazzo/plugin-tailwind resolves the template path against two different bases, causing ENOENT errors when outDir in terrazzo.config.ts is anything other than ./.

In https://github.com/terrazzoapp/terrazzo/blob/main/packages/plugin-tailwind/dist/index.js, the existence check resolves relative to outDir:

cwd = new URL("./", config.outDir);                                                                                                                           
  if (!fsSync.existsSync(new URL(options.template, cwd))) // relative to outDir

But the file read uses the raw path, which resolves relative to the process cwd:

template = await fs.readFile(options.template, "utf8"); // relative to process.cwd()

When outDir differs from the process cwd (e.g. outDir: "./src/tokens/"), no single template value satisfies both checks.

Reproduction

my-project/                                                                                                                                                   
    terrazzo.config.ts
    tokens.json                                                                                                                                                 
    src/tokens/   
      tailwind-theme-template.css
                                                                                                                                                                
  // terrazzo.config.ts
  export default defineConfig({                                                                                                                                 
    outDir: "./src/tokens/",
    plugins: [
      pluginTailwind({                                                                                                                                          
        template: "./tailwind-theme-template.css",
        // ...                                                                                                                                                  
      }),         
    ],
  });
  1. template: ./tailwind-theme-template.css existence check looks for ./src/tokens/tailwind-theme-template.css (found), but fs.readFile looks for ./tailwind-theme-template.css from process cwd (not found) → ENOENT
  2. template: ../tailwind-theme-template.css existence check looks for ./src/tailwind-theme-template.css (not found) → "Could not locate template"

Workaround: Place the template file at both locations (or use a symlink from the project root to the file in outDir).

Expected result

The template path should be resolved consistently. Either always relative to outDir, always relative to process cwd, or always relative to the config file. The same path should be used for both the existence check and the file read.

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions