Skip to content

fix(theme): apply fast-glob Windows work-around for all \@ matches #383

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

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions .github/workflows/integration-test-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@ jobs:
cli-integration-test:
name: CLI Integration Tests
# Note: `prepare-release.yaml` sets this commit message
if: ${{ contains(github.event.pull_request.title, 'release CLI') || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.title, 'release CLI') || github.event_name == 'workflow_dispatch' || github.ref_name == 'main' }}

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node-version: [18, 20, 22]
include:
- os: macos-latest
node_version: 20
- os: windows-latest
node_version: 20.13.1

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-and-build
with:
node-version: ${{ matrix.node-version }}

- name: Update template's versions
working-directory: ./packages/cli
Expand Down
20 changes: 11 additions & 9 deletions integration/cli/create-tutorial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import { execa } from 'execa';
import { temporaryDirectory } from 'tempy';
import { describe, beforeEach, afterAll, expect, it } from 'vitest';

const isWindows = process.platform === 'win32';
const baseDir = path.resolve(__dirname, '../..');

const cli = path.join(baseDir, 'packages/cli/dist/index.js');
const tmp = temporaryDirectory();

interface TestContext {
projectName: string;
dest: string;
}

const tmp = temporaryDirectory();

beforeEach<TestContext>(async (context) => {
context.projectName = Math.random().toString(36).substring(7);
context.dest = path.join(tmp, context.projectName);
Expand All @@ -35,7 +34,7 @@ describe.each(['npm', 'pnpm', 'yarn'])('%s', (packageManager) => {
expect(filesToJSON(projectFiles)).toMatchFileSnapshot(`${snapshotPrefix}-created.json`);
});

it<TestContext>('should create and build a project', async ({ projectName, dest }) => {
it.skipIf(isWindows)<TestContext>('should create and build a project', async ({ projectName, dest }) => {
await createProject(projectName, packageManager, { cwd: tmp, install: true });

await execa(packageManager, ['run', 'build'], {
Expand All @@ -50,19 +49,22 @@ describe.each(['npm', 'pnpm', 'yarn'])('%s', (packageManager) => {
expect(filesToJSON(distFiles)).toMatchFileSnapshot(`${snapshotPrefix}-built.json`);
});

it<TestContext>('created project contains overwritten UnoCSS config', async ({ projectName, dest }) => {
await createProject(projectName, packageManager, { cwd: tmp });
it.skipIf(isWindows)<TestContext>(
'created project contains overwritten UnoCSS config',
async ({ projectName, dest }) => {
await createProject(projectName, packageManager, { cwd: tmp });

const unoConfig = await fs.readFile(`${dest}/uno.config.ts`, 'utf8');
const unoConfig = await fs.readFile(`${dest}/uno.config.ts`, 'utf8');

expect(unoConfig).toBe(`\
expect(unoConfig).toBe(`\
import { defineConfig } from '@tutorialkit/theme';

export default defineConfig({
// add your UnoCSS config here: https://unocss.dev/guide/config-file
});
`);
});
},
);
});

async function createProject(name: string, packageManager: string, options: { cwd: string; install?: boolean }) {
Expand Down
1 change: 1 addition & 0 deletions integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"test": "vitest --testTimeout=300000"
},
"dependencies": {
"@tutorialkit/theme": "workspace:*",
"execa": "^9.2.0",
"tempy": "^3.1.0",
"vitest": "^2.1.1"
Expand Down
30 changes: 30 additions & 0 deletions integration/theme-resolving/inline-content.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { getInlineContentForPackage } from '@tutorialkit/theme';
import { execa } from 'execa';
import { temporaryDirectory } from 'tempy';
import { afterAll, expect, test } from 'vitest';

const baseDir = path.resolve(__dirname, '../..');
const cli = path.join(baseDir, 'packages/cli/dist/index.js');
const tmp = temporaryDirectory();

afterAll(async () => {
await fs.rm(tmp, { force: true, recursive: true });
});

test('getInlineContentForPackage finds files from @tutorialkit/astro', async () => {
await execa(
'node',
[cli, 'create', 'theme-test', '--install', '--no-git', '--no-start', '--package-manager', 'pnpm', '--defaults'],
{ cwd: tmp },
);

const content = getInlineContentForPackage({
name: '@tutorialkit/astro',
pattern: '/dist/default/**/*.astro',
root: `${tmp}/theme-test`,
});

expect(content.length).toBeGreaterThan(0);
});
6 changes: 4 additions & 2 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
],
"scripts": {
"build": "tsc -b",
"dev": "pnpm run build --watch --preserveWatchOutput"
"dev": "pnpm run build --watch --preserveWatchOutput",
"test": "vitest"
},
"dependencies": {
"@iconify-json/ph": "^1.1.13",
Expand All @@ -38,6 +39,7 @@
},
"devDependencies": {
"@types/node": "^22.4.1",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"vitest": "^2.1.1"
}
}
15 changes: 15 additions & 0 deletions packages/theme/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fileURLToPath, URL } from 'node:url';
import { expect, test } from 'vitest';
import { getInlineContentForPackage } from './index.js';

const root = fileURLToPath(new URL('../../template', import.meta.url));

test('getInlineContentForPackage finds files from @tutorialkit/astro', () => {
const content = getInlineContentForPackage({
name: '@tutorialkit/astro',
pattern: '/dist/default/**/*.astro',
root,
});

expect(content.length).toBeGreaterThan(0);
});
2 changes: 1 addition & 1 deletion packages/theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getInlineContentForPackage({ name, pattern, root }: { name: stri
const packageRoot = resolve(require.resolve(`${name}/package.json`, { paths: [root] }), '..');

// work-around for https://github.com/mrmlnc/fast-glob/issues/452
const packagePattern = convertPathToPattern(packageRoot.replace('\\@', '/@'));
const packagePattern = convertPathToPattern(packageRoot.replaceAll('\\@', '/@'));

return globSync(`${packagePattern}${pattern}`).map((filePath) => () => fs.readFile(filePath, { encoding: 'utf8' }));
} catch {
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.