Skip to content

Commit bf9119e

Browse files
authored
fix(ci): override @astrojs/language-server with an older version (#145)
1 parent 9673322 commit bf9119e

File tree

9 files changed

+362
-437
lines changed

9 files changed

+362
-437
lines changed

docs/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@unocss/reset": "^0.59.4",
2626
"astro": "^4.10.3",
2727
"fast-glob": "^3.3.2",
28-
"prettier-plugin-astro": "^0.14.0",
28+
"prettier-plugin-astro": "^0.14.1",
2929
"typescript": "^5.4.5",
3030
"unocss": "^0.59.4"
3131
}

docs/tutorialkit.dev/src/components/Layout/Head.astro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ import Default from '@astrojs/starlight/components/Head.astro';
99
<script is:inline async src="https://www.googletagmanager.com/gtag/js?id=G-64MFE82HG5"></script>
1010

1111
<script is:inline>
12+
// @ts-ignore
1213
window.dataLayer = window.dataLayer || [];
14+
1315
function gtag() {
16+
// @ts-ignore
1417
dataLayer.push(arguments);
1518
}
19+
// @ts-ignore
1620
gtag('js', new Date());
21+
// @ts-ignore
1722
gtag('config', 'G-64MFE82HG5');
1823
</script>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"husky": "^9.0.11",
2929
"is-ci": "^3.0.1",
3030
"prettier": "^3.3.2",
31-
"prettier-plugin-astro": "^0.13.0",
31+
"prettier-plugin-astro": "^0.14.1",
3232
"tempfile": "^5.0.0"
3333
},
3434
"lint-staged": {},

packages/cli/src/commands/eject/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface PackageJson {
1818
}
1919

2020
const TUTORIALKIT_VERSION = pkg.version;
21-
const REQUIRED_DEPENDENCIES = ['@tutorialkit/runtime', '@webcontainer/api', 'nanostores', '@nanostores/react'];
21+
const REQUIRED_DEPENDENCIES = ['@tutorialkit/runtime', '@webcontainer/api', 'nanostores', '@nanostores/react', 'kleur'];
2222

2323
export function ejectRoutes(flags: Arguments) {
2424
if (flags._[1] === 'help' || flags.help || flags.h) {

packages/cli/src/utils/workspace-version.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ export function updateWorkspaceVersions(
77
const depVersion = dependencies[dependency];
88

99
if (depVersion === 'workspace:*' && filterDependency(dependency)) {
10-
if (process.env.TK_DIRECTORY) {
11-
const name = dependency.split('/')[1];
12-
13-
dependencies[dependency] = `file:${process.env.TK_DIRECTORY}/packages/${name.replace('-', '/')}`;
14-
} else {
15-
dependencies[dependency] = version;
16-
}
10+
dependencies[dependency] = version;
1711
}
1812
}
1913
}

packages/cli/tests/__snapshots__/create-tutorial.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ exports[`create and eject a project 1`] = `
139139
"icons/languages/markdown.svg",
140140
"icons/languages/sass.svg",
141141
"icons/languages/ts.svg",
142-
"package-lock.json",
143142
"package.json",
143+
"pnpm-lock.yaml",
144144
"public",
145145
"public/favicon.svg",
146146
"public/logo-dark.svg",

packages/cli/tests/create-tutorial.test.ts

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import path from 'node:path';
1+
import { execa } from 'execa';
22
import fs from 'node:fs/promises';
3+
import { tmpdir } from 'node:os';
4+
import path from 'node:path';
35
import { afterAll, beforeAll, expect, test } from 'vitest';
4-
import { execa } from 'execa';
56

6-
const tmpDir = path.join(__dirname, '.tmp');
7+
// on CI on windows we want to make sure to use the same drive, so we use a custom logic
8+
const tmpDir =
9+
process.platform === 'win32'
10+
? path.join(path.resolve(__dirname, '../../../..'), '.tmp')
11+
: await fs.mkdtemp(path.join(tmpdir(), 'tk-test-'));
712
const baseDir = path.resolve(__dirname, '../../..');
813

914
const cli = path.join(baseDir, 'packages/cli/dist/index.js');
@@ -14,7 +19,9 @@ beforeAll(async () => {
1419
});
1520

1621
afterAll(async () => {
17-
await fs.rm(tmpDir, { force: true, recursive: true });
22+
if (process.platform !== 'win32' || !process.env.CI) {
23+
await fs.rm(tmpDir, { force: true, recursive: true });
24+
}
1825
});
1926

2027
test('cannot create project without installing but with starting', async (context) => {
@@ -23,9 +30,6 @@ test('cannot create project without installing but with starting', async (contex
2330
await expect(
2431
execa('node', [cli, 'create', name, '--no-install', '--start'], {
2532
cwd: tmpDir,
26-
env: {
27-
TK_DIRECTORY: baseDir,
28-
},
2933
}),
3034
).rejects.toThrow('Cannot start project without installing dependencies.');
3135
});
@@ -36,9 +40,6 @@ test('create a project', async (context) => {
3640

3741
await execa('node', [cli, 'create', name, '--no-install', '--no-git', '--defaults'], {
3842
cwd: tmpDir,
39-
env: {
40-
TK_DIRECTORY: baseDir,
41-
},
4243
});
4344

4445
const projectFiles = await fs.readdir(dest, { recursive: true });
@@ -50,14 +51,13 @@ test('create and build a project', async (context) => {
5051
const name = context.task.id;
5152
const dest = path.join(tmpDir, name);
5253

53-
await execa('node', [cli, 'create', name, '--no-git', '--no-start', '--defaults'], {
54+
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--defaults'], {
5455
cwd: tmpDir,
55-
env: {
56-
TK_DIRECTORY: baseDir,
57-
},
5856
});
5957

60-
await execa('npm', ['run', 'build'], {
58+
await runPnpmInstall(dest, baseDir);
59+
60+
await execa('pnpm', ['run', 'build'], {
6161
cwd: dest,
6262
});
6363

@@ -73,24 +73,25 @@ test('create and eject a project', async (context) => {
7373
const name = context.task.id;
7474
const dest = path.join(tmpDir, name);
7575

76-
await execa('node', [cli, 'create', name, '--no-git', '--no-start', '--defaults'], {
76+
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--defaults'], {
7777
cwd: tmpDir,
78-
env: {
79-
TK_DIRECTORY: baseDir,
80-
},
8178
});
8279

80+
await runPnpmInstall(dest, baseDir);
81+
8382
await execa('node', [cli, 'eject', name, '--force', '--defaults'], {
8483
cwd: tmpDir,
85-
env: {
86-
TK_DIRECTORY: baseDir,
87-
},
8884
});
8985

90-
// remove `node_modules` before taking the snapshot
91-
await fs.rm(path.join(dest, 'node_modules'), { force: true, recursive: true });
86+
if (process.platform !== 'win32') {
87+
await fs.rm(path.join(dest, 'node_modules'), { force: true, recursive: true, maxRetries: 5 });
88+
}
9289

93-
const projectFiles = await fs.readdir(dest, { recursive: true });
90+
let projectFiles = await fs.readdir(dest, { recursive: true });
91+
92+
if (process.platform === 'win32') {
93+
projectFiles = projectFiles.filter((filePath) => !filePath.startsWith('node_modules'));
94+
}
9495

9596
expect(projectFiles.map(normaliseSlash).sort()).toMatchSnapshot();
9697
expect(await fs.readFile(path.join(dest, 'astro.config.ts'), 'utf-8')).toMatchSnapshot();
@@ -100,25 +101,21 @@ test('create, eject and build a project', async (context) => {
100101
const name = context.task.id;
101102
const dest = path.join(tmpDir, name);
102103

103-
await execa('node', [cli, 'create', name, '--no-git', '--no-start', '--defaults'], {
104+
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--defaults'], {
104105
cwd: tmpDir,
105-
env: {
106-
TK_DIRECTORY: baseDir,
107-
},
108106
});
109107

108+
await runPnpmInstall(dest, baseDir);
109+
110110
await execa('node', [cli, 'eject', name, '--force', '--defaults'], {
111111
cwd: tmpDir,
112-
env: {
113-
TK_DIRECTORY: baseDir,
114-
},
115112
});
116113

117-
await execa('npm', ['install'], {
114+
await execa('pnpm', ['install', '--no-frozen-lockfile'], {
118115
cwd: dest,
119116
});
120117

121-
await execa('npm', ['run', 'build'], {
118+
await execa('pnpm', ['run', 'build'], {
122119
cwd: dest,
123120
});
124121

@@ -139,9 +136,6 @@ test('cannot eject on an empty folder', async (context) => {
139136
await expect(
140137
execa('node', [cli, 'eject', name, '--force', '--defaults'], {
141138
cwd: tmpDir,
142-
env: {
143-
TK_DIRECTORY: baseDir,
144-
},
145139
}),
146140
).rejects.toThrow('package.json does not exists!');
147141
});
@@ -157,9 +151,6 @@ test('cannot eject on a node project that is not an Astro project', async (conte
157151
await expect(
158152
execa('node', [cli, 'eject', name, '--force', '--defaults'], {
159153
cwd: tmpDir,
160-
env: {
161-
TK_DIRECTORY: baseDir,
162-
},
163154
}),
164155
).rejects.toThrow('astro.config.ts does not exists!');
165156
});
@@ -188,9 +179,6 @@ test('cannot eject on an astro project that is not using TutorialKit', async (co
188179
await expect(
189180
execa('node', [cli, 'eject', name, '--force', '--defaults'], {
190181
cwd: tmpDir,
191-
env: {
192-
TK_DIRECTORY: baseDir,
193-
},
194182
}),
195183
).rejects.toThrow(`@tutorialkit${path.sep}astro does not exists!`);
196184
});
@@ -216,20 +204,39 @@ test('cannot eject on an astro project that is not using TutorialKit 2', async (
216204
`,
217205
);
218206

219-
await execa('npm', ['install'], {
207+
await execa('pnpm', ['install'], {
220208
cwd: dest,
221209
});
222210

223211
await expect(
224212
execa('node', [cli, 'eject', name, '--force', '--defaults'], {
225213
cwd: tmpDir,
226-
env: {
227-
TK_DIRECTORY: baseDir,
228-
},
229214
}),
230215
).rejects.toThrow(`Could not find import to '@tutorialkit/astro'`);
231216
});
232217

233218
function normaliseSlash(filePath: string) {
234219
return filePath.replace(/\\/g, '/');
235220
}
221+
222+
async function runPnpmInstall(dest: string, baseDir: string) {
223+
const packageJsonPath = path.join(dest, 'package.json');
224+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
225+
226+
packageJson.pnpm = {
227+
overrides: {
228+
'@astrojs/language-server': '2.11.1',
229+
'@tutorialkit/astro': `file:${baseDir}/packages/astro`,
230+
'@tutorialkit/components-react': `file:${baseDir}/packages/components/react`,
231+
'@tutorialkit/runtime': `file:${baseDir}/packages/runtime`,
232+
'@tutorialkit/theme': `file:${baseDir}/packages/theme`,
233+
'@tutorialkit/types': `file:${baseDir}/packages/types`,
234+
},
235+
};
236+
237+
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, undefined, 2), 'utf8');
238+
239+
await execa('pnpm', ['install'], {
240+
cwd: dest,
241+
});
242+
}

packages/template/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@unocss/reset": "^0.59.4",
2828
"astro": "4.10.3",
2929
"fast-glob": "^3.3.2",
30-
"prettier-plugin-astro": "^0.13.0",
30+
"prettier-plugin-astro": "^0.14.1",
3131
"typescript": "^5.4.5",
3232
"unocss": "^0.59.4"
3333
}

0 commit comments

Comments
 (0)