@@ -19,8 +19,8 @@ afterAll(() => {
19
19
process . env . RWJS_CWD = RWJS_CWD
20
20
} )
21
21
22
- function getPluginTransform ( ) {
23
- const plugin = rscTransformUseServerPlugin ( )
22
+ function getPluginTransform ( serverEntryFiles : Record < string , string > ) {
23
+ const plugin = rscTransformUseServerPlugin ( 'some/dist/path' , serverEntryFiles )
24
24
25
25
if ( typeof plugin . transform !== 'function' ) {
26
26
throw new Error ( 'Plugin does not have a transform function' )
@@ -33,12 +33,14 @@ function getPluginTransform() {
33
33
return plugin . transform . bind ( { } as TransformPluginContext )
34
34
}
35
35
36
- const pluginTransform = getPluginTransform ( )
36
+ const id = 'rw-app/web/src/some/path/to/actions.ts'
37
+ const pluginTransform = getPluginTransform ( {
38
+ 'rsa-actions.ts-0' : id ,
39
+ } )
37
40
38
41
describe ( 'rscTransformUseServerPlugin function scoped "use server"' , ( ) => {
39
42
describe ( 'top-level exports' , ( ) => {
40
43
it ( 'should handle named function' , async ( ) => {
41
- const id = 'some/path/to/actions.ts'
42
44
const input = `
43
45
import fs from 'node:fs'
44
46
@@ -65,12 +67,11 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
65
67
await fs.promises.writeFile('settings.json', \`{ "delay": \${formData.get('delay')} }\`);
66
68
}
67
69
import { registerServerReference } from "react-server-dom-webpack/server";
68
- registerServerReference(formAction, "some/path/to/ actions.ts", "formAction");"
70
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "formAction");"
69
71
` )
70
72
} )
71
73
72
74
it ( 'should handle arrow function' , async ( ) => {
73
- const id = 'some/path/to/actions.ts'
74
75
const input = `
75
76
import fs from 'node:fs'
76
77
@@ -97,12 +98,11 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
97
98
await fs.promises.writeFile('settings.json', \`{ "delay": \${formData.get('delay')} }\`);
98
99
};
99
100
import { registerServerReference } from "react-server-dom-webpack/server";
100
- registerServerReference(formAction, "some/path/to/ actions.ts", "formAction");"
101
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "formAction");"
101
102
` )
102
103
} )
103
104
104
105
it ( 'should handle default exported named function' , async ( ) => {
105
- const id = 'some/path/to/actions.ts'
106
106
const input = `
107
107
import fs from 'node:fs'
108
108
@@ -129,12 +129,11 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
129
129
await fs.promises.writeFile('settings.json', \`{ "delay": \${formData.get('delay')} }\`);
130
130
}
131
131
import { registerServerReference } from "react-server-dom-webpack/server";
132
- registerServerReference(formAction, "some/path/to/ actions.ts", "default");"
132
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "default");"
133
133
` )
134
134
} )
135
135
136
136
it ( 'should handle exports with two consts' , async ( ) => {
137
- const id = 'some/path/to/actions.ts'
138
137
const input = `
139
138
import fs from 'node:fs'
140
139
@@ -162,13 +161,12 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
162
161
await fs.promises.writeFile('settings.json', \`{ "delay": \${formData.get('delay')} }\`);
163
162
};
164
163
import { registerServerReference } from "react-server-dom-webpack/server";
165
- registerServerReference(fortyTwo, "some/path/to/ actions.ts", "fortyTwo");
166
- registerServerReference(formAction, "some/path/to/ actions.ts", "formAction");"
164
+ registerServerReference(fortyTwo, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "fortyTwo");
165
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "formAction");"
167
166
` )
168
167
} )
169
168
170
169
it ( 'should handle named function and arrow function with separate export' , async ( ) => {
171
- const id = 'some/path/to/actions.ts'
172
170
const input = `
173
171
import fs from 'node:fs'
174
172
@@ -213,15 +211,14 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
213
211
await fs.promises.writeFile('settings.json', \`{ "delay": \${formData.get('delay')} }\`);
214
212
};
215
213
import { registerServerReference } from "react-server-dom-webpack/server";
216
- registerServerReference(formAction, "some/path/to/ actions.ts", "formAction");
217
- registerServerReference(arrowAction, "some/path/to/ actions.ts", "arrowAction");"
214
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "formAction");
215
+ registerServerReference(arrowAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "arrowAction");"
218
216
` )
219
217
} )
220
218
221
219
it . todo (
222
220
"should handle named function and 'let' arrow function with separate export" ,
223
221
async ( ) => {
224
- const id = 'some/path/to/actions.ts'
225
222
const input = `
226
223
import fs from 'node:fs'
227
224
@@ -280,14 +277,13 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
280
277
// Not 'use server' anymore
281
278
};
282
279
import { registerServerReference } from "react-server-dom-webpack/server";
283
- registerServerReference(formAction, "some/path/to/ actions.ts", "formAction");
284
- if (typeof letArrowFunction === "function") registerServerReference(letArrowAction, "some/path/to/ actions.ts", "letArrowAction");"
280
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "formAction");
281
+ if (typeof letArrowFunction === "function") registerServerReference(letArrowAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "letArrowAction");"
285
282
` )
286
283
} ,
287
284
)
288
285
289
286
it ( 'should handle separate renamed export' , async ( ) => {
290
- const id = 'some/path/to/actions.ts'
291
287
const input = `
292
288
import fs from 'node:fs'
293
289
@@ -327,13 +323,12 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
327
323
};
328
324
export { formAction as fA, arrowAction };
329
325
import { registerServerReference } from "react-server-dom-webpack/server";
330
- registerServerReference(formAction, "some/path/to/ actions.ts", "fA");
331
- registerServerReference(arrowAction, "some/path/to/ actions.ts", "arrowAction");"
326
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "fA");
327
+ registerServerReference(arrowAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "arrowAction");"
332
328
` )
333
329
} )
334
330
335
331
it . todo ( 'should handle default exported arrow function' , async ( ) => {
336
- const id = 'some/path/to/actions.ts'
337
332
const input = `
338
333
import fs from 'node:fs'
339
334
@@ -365,14 +360,13 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
365
360
}
366
361
367
362
import {registerServerReference} from "react-server-dom-webpack/server";
368
- if (typeof formAction === "function") registerServerReference(formAction,"some/path/to/ actions.ts","formAction");
363
+ if (typeof formAction === "function") registerServerReference(formAction,"some/dist/ path/assets/rsa- actions.ts-0.mjs ","formAction");
369
364
"
370
365
` )
371
366
} )
372
367
373
368
describe ( 'without "use server"' , ( ) => {
374
369
it ( 'should not register named function' , async ( ) => {
375
- const id = 'some/path/to/actions.ts'
376
370
const input = `
377
371
import fs from 'node:fs'
378
372
@@ -401,7 +395,6 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
401
395
} )
402
396
403
397
it ( 'should not register arrow function' , async ( ) => {
404
- const id = 'some/path/to/actions.ts'
405
398
const input = `
406
399
import fs from 'node:fs'
407
400
@@ -430,7 +423,6 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
430
423
} )
431
424
432
425
it ( 'should not register default exported named function' , async ( ) => {
433
- const id = 'some/path/to/actions.ts'
434
426
const input = `
435
427
import fs from 'node:fs'
436
428
@@ -459,7 +451,6 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
459
451
} )
460
452
461
453
it ( 'should not register exports with two consts' , async ( ) => {
462
- const id = 'some/path/to/actions.ts'
463
454
const input = `
464
455
import fs from 'node:fs'
465
456
@@ -483,12 +474,11 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
483
474
await fs.promises.writeFile('settings.json', \`{ "delay": \${formData.get('delay')} }\`);
484
475
};
485
476
import { registerServerReference } from "react-server-dom-webpack/server";
486
- registerServerReference(formAction, "some/path/to/ actions.ts", "formAction");"
477
+ registerServerReference(formAction, "some/dist/ path/assets/rsa- actions.ts-0.mjs ", "formAction");"
487
478
` )
488
479
} )
489
480
490
481
it ( 'should not register named function and arrow function with separate export' , async ( ) => {
491
- const id = 'some/path/to/actions.ts'
492
482
const input = `
493
483
import fs from 'node:fs'
494
484
@@ -525,7 +515,6 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
525
515
} )
526
516
527
517
it ( 'should not register separate renamed export' , async ( ) => {
528
- const id = 'some/path/to/actions.ts'
529
518
const input = `
530
519
import fs from 'node:fs'
531
520
@@ -564,7 +553,6 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
564
553
} )
565
554
566
555
it ( 'should not register default exported arrow function' , async ( ) => {
567
- const id = 'some/path/to/actions.ts'
568
556
const input = `
569
557
import fs from 'node:fs'
570
558
@@ -597,7 +585,11 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
597
585
598
586
describe ( 'actions inside components' , async ( ) => {
599
587
it ( 'should handle self-contained named function inside default exported component' , async ( ) => {
600
- const id = 'some/path/to/Component.tsx'
588
+ const id = 'rw-app/web/src/some/path/to/Component.tsx'
589
+ const pluginTransform = getPluginTransform ( {
590
+ 'rsa-Component.tsx-0' : id ,
591
+ } )
592
+
601
593
const input = `
602
594
import fs from 'node:fs'
603
595
@@ -640,7 +632,7 @@ describe('rscTransformUseServerPlugin function scoped "use server"', () => {
640
632
641
633
await fs.promises.writeFile('settings.json', \`{ "delay": \${formData.get('delay')} }\`);
642
634
}
643
- registerServerReference(__rwjs__rsa0_formAction, "some/path/to/ Component.tsx", "__rwjs__rsa0_formAction");"
635
+ registerServerReference(__rwjs__rsa0_formAction, "some/dist/ path/assets/rsa- Component.tsx-0.mjs ", "__rwjs__rsa0_formAction");"
644
636
` )
645
637
} )
646
638
0 commit comments