diff --git a/.github/workflows/test-smoke.yml b/.github/workflows/test-smoke.yml deleted file mode 100644 index 2546e485..00000000 --- a/.github/workflows/test-smoke.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Smoke Test - -on: - workflow_dispatch: - pull_request: - types: - - edited - - opened - - synchronize - push: - branches: - - '*' - - '!main' - -jobs: - validate: - runs-on: ubuntu-latest - name: Smoke Test - - steps: - - name: Checkout Commit - uses: actions/checkout@v4 - with: - fetch-depth: 10 - - - name: Checkout Main - run: | - git fetch origin - git branch -f main origin/main - - - name: Setup - uses: ./.github/actions/setup - - - name: Build Projects - run: | - moon jsx-email:build - moon create-mail:build - moon run :build --query "project~plugin-*" - - - name: Smoke Test - # Note: We're running `pnpm i` again so that pnpm places the `email` bin in root node_modules - # We'll need that for the preview tests below - run: | - pnpm i - moon test-smoke:run.ci diff --git a/packages/jsx-email/src/cli/commands/build.ts b/packages/jsx-email/src/cli/commands/build.ts index 277782ca..4ef535de 100644 --- a/packages/jsx-email/src/cli/commands/build.ts +++ b/packages/jsx-email/src/cli/commands/build.ts @@ -5,7 +5,7 @@ import os from 'node:os'; import chalkTmpl from 'chalk-template'; import { globby } from 'globby'; import micromatch from 'micromatch'; -import { basename, dirname, extname, join, posix, resolve, win32 } from 'path'; +import { basename, dirname, extname, join, posix, relative, resolve, win32 } from 'path'; import { isWindows } from 'std-env'; import { pathToFileURL } from 'url'; import type { InferOutput as Infer } from 'valibot'; @@ -121,8 +121,9 @@ export const build = async (options: BuildOptions): Promise => { const templateName = basename(path, fileExt).replace(/-[^-]{8}$/, ''); const component = componentExport(renderProps); const baseDir = dirname(path); + const relativeBaseDir = outputBasePath ? relative(outputBasePath, baseDir) : ''; const writePath = outputBasePath - ? join(out!, baseDir.replace(outputBasePath, ''), templateName) + ? join(out!, relativeBaseDir, templateName) : join(out!, templateName); // const writePath = outputBasePath // ? join(out!, baseDir.replace(outputBasePath, ''), templateName + extension) diff --git a/packages/jsx-email/src/renderer/compile.ts b/packages/jsx-email/src/renderer/compile.ts index 10b2b35e..2aaa5814 100644 --- a/packages/jsx-email/src/renderer/compile.ts +++ b/packages/jsx-email/src/renderer/compile.ts @@ -78,7 +78,7 @@ export const compile = async (options: CompileOptions): Promise if (!entryPoint) return null; return { entryPoint, - path: resolve('/', path) + path: resolve(originalCwd, path) }; }) .filter(Boolean as any); diff --git a/packages/jsx-email/test/render/compile-path.test.ts b/packages/jsx-email/test/render/compile-path.test.ts new file mode 100644 index 00000000..2f4c1c9f --- /dev/null +++ b/packages/jsx-email/test/render/compile-path.test.ts @@ -0,0 +1,38 @@ +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; +import { join } from 'node:path'; +import { pathToFileURL } from 'node:url'; + +import { isWindows } from 'std-env'; + +import { compile } from '../../src/renderer/compile.js'; + +describe('compile', () => { + it('returns an importable path for nested entrypoints', async () => { + const tmpRoot = await mkdtemp(join(process.cwd(), '.tmp-jsx-email-compile-')); + + try { + const entryDir = join(tmpRoot, 'templates', 'nested'); + await mkdir(entryDir, { recursive: true }); + + const entryPoint = join(entryDir, 'template.tsx'); + await writeFile( + entryPoint, + `export const Template = ({ name }: { name: string }) =>

Hello {name}

;\n`, + 'utf8' + ); + + const outDir = join(tmpRoot, 'out'); + const results = await compile({ files: [entryPoint], outDir }); + const result = results[0]; + + if (!result) throw new Error('Expected compile to return at least one output'); + + const compiledImportPath = isWindows ? pathToFileURL(result.path).toString() : result.path; + + const mod = await import(compiledImportPath); + expect(typeof mod.Template).toBe('function'); + } finally { + await rm(tmpRoot, { recursive: true, force: true }); + } + }); +});