Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Normalize globby path for cli build command #44

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync } from 'node:fs';
import { mkdir, realpath, writeFile } from 'node:fs/promises';
import os from 'node:os';
import { basename, extname, join, resolve } from 'path';
import { basename, extname, join, resolve, win32, posix } from 'path';

import { render } from '@jsx-email/render';
import chalk from 'chalk';
Expand Down Expand Up @@ -61,6 +61,9 @@ const pretty = (html: string) => {
return beautify.html(html, defaults);
};

// Credit: https://github.com/rollup/plugins/blob/master/packages/pluginutils/src/normalizePath.ts#L5
const normalizePath = (filename: string) => filename.split(win32.sep).join(posix.sep);

const stripHtml = (html: string) => {
const $ = load(html);

Expand Down Expand Up @@ -108,7 +111,7 @@ const compile = async (files: string[], outDir: string) => {
write: true
});

return globby([join(outDir, '*.js')]);
return globby([normalizePath(join(outDir, '*.js'))]);
};

export const command: CommandFn = async (argv: BuildOptions, input) => {
Expand All @@ -129,7 +132,7 @@ export const command: CommandFn = async (argv: BuildOptions, input) => {
const isFile = target.endsWith('.tsx') || target.endsWith('.jsx');
const { out = '.rendered' } = argv;
const glob = isFile ? target : join(target, '*.{jsx,tsx}');
const targetFiles = await globby([glob]);
const targetFiles = await globby([normalizePath(glob)]);
const outputPath = resolve(out);

log('Found', targetFiles.length, 'files:');
Expand Down
Loading