Skip to content

Commit dd10f82

Browse files
committed
Migrate cache-testing app to module type
1 parent 9144fc5 commit dd10f82

24 files changed

+817
-766
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: Replace Path with Sed
6969
run: |
7070
if [ "${{ matrix.handler }}" == "redis-strings" ]; then
71-
sed -i 's/cache-handler-redis-stack/cache-handler-redis-strings/g' apps/cache-testing/next.config.mjs
71+
sed -i 's/cache-handler-redis-stack/cache-handler-redis-strings/g' apps/cache-testing/next.config.js
7272
sed -i 's/cache-handler-redis-stack/cache-handler-redis-strings/g' apps/cache-testing/src/instrumentation.ts
7373
fi
7474

apps/cache-testing/cache-handler-redis-stack.mjs renamed to apps/cache-testing/cache-handler-redis-stack.cjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @ts-check
22

3-
import { CacheHandler } from '@neshca/cache-handler';
4-
import createLruHandler from '@neshca/cache-handler/local-lru';
5-
import createRedisHandler from '@neshca/cache-handler/redis-stack';
6-
import { createClient } from 'redis';
3+
const { CacheHandler } = require('@neshca/cache-handler');
4+
const createLruHandler = require('@neshca/cache-handler/local-lru').default;
5+
const createRedisHandler = require('@neshca/cache-handler/redis-stack').default;
6+
const { createClient } = require('redis');
77

88
CacheHandler.onCreation(async () => {
99
if (!process.env.REDIS_URL) {
@@ -86,4 +86,4 @@ CacheHandler.onCreation(async () => {
8686
};
8787
});
8888

89-
export default CacheHandler;
89+
module.exports = CacheHandler;

apps/cache-testing/cache-handler-redis-stack.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @ts-check
22

3-
const { CacheHandler } = require('@neshca/cache-handler');
4-
const createLruHandler = require('@neshca/cache-handler/local-lru').default;
5-
const createRedisHandler = require('@neshca/cache-handler/redis-stack').default;
6-
const { createClient } = require('redis');
3+
import { CacheHandler } from '@neshca/cache-handler';
4+
import createLruHandler from '@neshca/cache-handler/local-lru';
5+
import createRedisHandler from '@neshca/cache-handler/redis-stack';
6+
import { createClient } from 'redis';
77

88
CacheHandler.onCreation(async () => {
99
if (!process.env.REDIS_URL) {
@@ -86,4 +86,4 @@ CacheHandler.onCreation(async () => {
8686
};
8787
});
8888

89-
module.exports = CacheHandler;
89+
export default CacheHandler;

apps/cache-testing/cluster.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
apps: [
33
{
44
name: 'app',

apps/cache-testing/create-instances.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { cp, mkdir, readdir } from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
5+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
6+
7+
// Set common paths
8+
const STANDALONE_DIR = path.join(currentDir, '.next/standalone');
9+
const APP_DIR = path.join(STANDALONE_DIR, 'apps/cache-testing');
10+
const PUBLIC_DIR = path.join(currentDir, 'public');
11+
const STATIC_DIR = path.join(currentDir, '.next/static');
12+
const FETCH_CACHE_DIR = path.join(currentDir, '.next/cache/fetch-cache');
13+
const INSTANCES_DIR = path.join(currentDir, '.next/__instances');
14+
15+
async function copyDir(src: string, dest: string) {
16+
try {
17+
await cp(src, dest, { recursive: true });
18+
} catch (error) {
19+
console.error(`Failed to copy from ${src} to ${dest}:`, error);
20+
process.exit(1);
21+
}
22+
}
23+
24+
async function createInstanceDir(port: string) {
25+
try {
26+
await mkdir(path.join(INSTANCES_DIR, port), { recursive: true });
27+
} catch (error) {
28+
console.error(
29+
`Failed to create ${path.join(INSTANCES_DIR, port)} directory:`,
30+
error,
31+
);
32+
process.exit(1);
33+
}
34+
}
35+
36+
// Copy public directory to standalone app directory
37+
await copyDir(PUBLIC_DIR, path.join(APP_DIR, 'public'));
38+
39+
// Copy static directory to standalone app/.next directory
40+
await copyDir(STATIC_DIR, path.join(APP_DIR, '.next/static'));
41+
42+
try {
43+
// Copy fetch cache directory to standalone app/.next directory
44+
await mkdir(path.join(APP_DIR, '.next/cache/fetch-cache'), {
45+
recursive: true,
46+
});
47+
48+
const files = await readdir(FETCH_CACHE_DIR);
49+
50+
if (files.length > 0) {
51+
await copyDir(
52+
FETCH_CACHE_DIR,
53+
path.join(APP_DIR, '.next/cache/fetch-cache'),
54+
);
55+
}
56+
} catch (_error) {
57+
// Ignore errors - directory might not exist or be empty
58+
console.error('No fetch cache files to copy');
59+
}
60+
61+
// Create instance directories
62+
await createInstanceDir('3000');
63+
await createInstanceDir('3001');
64+
65+
// Copy files from standalone directory to instance directories
66+
await copyDir(path.join(STANDALONE_DIR, '.'), path.join(INSTANCES_DIR, '3000'));
67+
await copyDir(path.join(STANDALONE_DIR, '.'), path.join(INSTANCES_DIR, '3001'));

apps/cache-testing/next.config.mjs renamed to apps/cache-testing/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import path from 'node:path';
44

5-
const cacheHandler = path.resolve('./cache-handler-redis-stack.mjs');
5+
const cacheHandler = path.resolve('./cache-handler-redis-stack.js');
66

77
/** @type {import('next').NextConfig} */
88
const nextConfig = {

0 commit comments

Comments
 (0)