Skip to content

Commit 9f4bd13

Browse files
authored
fix(theme): apply fast-glob Windows work-around for all \@ matches (#383)
1 parent b57a764 commit 9f4bd13

File tree

8 files changed

+84
-14
lines changed

8 files changed

+84
-14
lines changed

.github/workflows/integration-test-cli.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,29 @@ jobs:
88
cli-integration-test:
99
name: CLI Integration Tests
1010
# Note: `prepare-release.yaml` sets this commit message
11-
if: ${{ contains(github.event.pull_request.title, 'release CLI') || github.event_name == 'workflow_dispatch' }}
12-
runs-on: ubuntu-latest
11+
if: ${{ contains(github.event.pull_request.title, 'release CLI') || github.event_name == 'workflow_dispatch' || github.ref_name == 'main' }}
12+
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest]
18+
node-version: [18, 20, 22]
19+
include:
20+
- os: macos-latest
21+
node_version: 20
22+
- os: windows-latest
23+
node_version: 20.13.1
24+
1325
steps:
1426
- name: Checkout
1527
uses: actions/checkout@v4
1628
with:
1729
fetch-depth: 0
1830

1931
- uses: ./.github/actions/setup-and-build
32+
with:
33+
node-version: ${{ matrix.node-version }}
2034

2135
- name: Update template's versions
2236
working-directory: ./packages/cli

integration/cli/create-tutorial.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import { execa } from 'execa';
44
import { temporaryDirectory } from 'tempy';
55
import { describe, beforeEach, afterAll, expect, it } from 'vitest';
66

7+
const isWindows = process.platform === 'win32';
78
const baseDir = path.resolve(__dirname, '../..');
8-
99
const cli = path.join(baseDir, 'packages/cli/dist/index.js');
10+
const tmp = temporaryDirectory();
1011

1112
interface TestContext {
1213
projectName: string;
1314
dest: string;
1415
}
1516

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

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

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

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

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

58-
expect(unoConfig).toBe(`\
59+
expect(unoConfig).toBe(`\
5960
import { defineConfig } from '@tutorialkit/theme';
6061
6162
export default defineConfig({
6263
// add your UnoCSS config here: https://unocss.dev/guide/config-file
6364
});
6465
`);
65-
});
66+
},
67+
);
6668
});
6769

6870
async function createProject(name: string, packageManager: string, options: { cwd: string; install?: boolean }) {

integration/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"test": "vitest --testTimeout=300000"
77
},
88
"dependencies": {
9+
"@tutorialkit/theme": "workspace:*",
910
"execa": "^9.2.0",
1011
"tempy": "^3.1.0",
1112
"vitest": "^2.1.1"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fs from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { getInlineContentForPackage } from '@tutorialkit/theme';
4+
import { execa } from 'execa';
5+
import { temporaryDirectory } from 'tempy';
6+
import { afterAll, expect, test } from 'vitest';
7+
8+
const baseDir = path.resolve(__dirname, '../..');
9+
const cli = path.join(baseDir, 'packages/cli/dist/index.js');
10+
const tmp = temporaryDirectory();
11+
12+
afterAll(async () => {
13+
await fs.rm(tmp, { force: true, recursive: true });
14+
});
15+
16+
test('getInlineContentForPackage finds files from @tutorialkit/astro', async () => {
17+
await execa(
18+
'node',
19+
[cli, 'create', 'theme-test', '--install', '--no-git', '--no-start', '--package-manager', 'pnpm', '--defaults'],
20+
{ cwd: tmp },
21+
);
22+
23+
const content = getInlineContentForPackage({
24+
name: '@tutorialkit/astro',
25+
pattern: '/dist/default/**/*.astro',
26+
root: `${tmp}/theme-test`,
27+
});
28+
29+
expect(content.length).toBeGreaterThan(0);
30+
});

packages/theme/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
],
2929
"scripts": {
3030
"build": "tsc -b",
31-
"dev": "pnpm run build --watch --preserveWatchOutput"
31+
"dev": "pnpm run build --watch --preserveWatchOutput",
32+
"test": "vitest"
3233
},
3334
"dependencies": {
3435
"@iconify-json/ph": "^1.1.13",
@@ -38,6 +39,7 @@
3839
},
3940
"devDependencies": {
4041
"@types/node": "^22.4.1",
41-
"typescript": "^5.4.5"
42+
"typescript": "^5.4.5",
43+
"vitest": "^2.1.1"
4244
}
4345
}

packages/theme/src/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { fileURLToPath, URL } from 'node:url';
2+
import { expect, test } from 'vitest';
3+
import { getInlineContentForPackage } from './index.js';
4+
5+
const root = fileURLToPath(new URL('../../template', import.meta.url));
6+
7+
test('getInlineContentForPackage finds files from @tutorialkit/astro', () => {
8+
const content = getInlineContentForPackage({
9+
name: '@tutorialkit/astro',
10+
pattern: '/dist/default/**/*.astro',
11+
root,
12+
});
13+
14+
expect(content.length).toBeGreaterThan(0);
15+
});

packages/theme/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function getInlineContentForPackage({ name, pattern, root }: { name: stri
4949
const packageRoot = resolve(require.resolve(`${name}/package.json`, { paths: [root] }), '..');
5050

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

5454
return globSync(`${packagePattern}${pattern}`).map((filePath) => () => fs.readFile(filePath, { encoding: 'utf8' }));
5555
} catch {

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)