This repository was archived by the owner on Jan 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 7
7
],
8
8
"scripts" : {
9
9
"build" : " turbo run build" ,
10
+ "build:packages" : " turbo run build --filter='./packages/*'" ,
10
11
"changeset" : " changeset" ,
11
12
"clean" : " turbo run clean" ,
12
13
"dev" : " turbo run dev" ,
Original file line number Diff line number Diff line change
1
+ import * as fs from 'node:fs/promises' ;
2
+ import * as path from 'node:path' ;
1
3
import type { Options } from 'tsup' ;
2
4
import { defineConfig } from 'tsup' ;
3
5
6
+ const DIST_PATH = './dist' ;
7
+
8
+ async function addDirectivesToChunkFiles ( distPath = DIST_PATH ) : Promise < void > {
9
+ try {
10
+ const files = await fs . readdir ( distPath ) ;
11
+
12
+ for ( const file of files ) {
13
+ if (
14
+ file . startsWith ( 'chunk-' ) &&
15
+ ( file . endsWith ( '.mjs' ) || file . endsWith ( '.js' ) )
16
+ ) {
17
+ const filePath = path . join ( distPath , file ) ;
18
+
19
+ // eslint-disable-next-line no-await-in-loop -- We need to wait for each file to be read
20
+ const data = await fs . readFile ( filePath , 'utf8' ) ;
21
+
22
+ const updatedContent = `'use client';\n${ data } ` ;
23
+
24
+ // eslint-disable-next-line no-await-in-loop -- We need to wait for each file to be written
25
+ await fs . writeFile ( filePath , updatedContent , 'utf8' ) ;
26
+
27
+ // eslint-disable-next-line no-console -- We need to log the result
28
+ console . log ( `Directive has been added to ${ file } ` ) ;
29
+ }
30
+ }
31
+ } catch ( err ) {
32
+ // eslint-disable-next-line no-console -- We need to log the error
33
+ console . error ( 'Error:' , err ) ;
34
+ }
35
+ }
36
+
4
37
export default defineConfig ( ( options : Options ) => ( {
5
38
clean : ! options . watch ,
6
39
dts : true ,
7
40
entry : [ 'src/**/*.tsx' ] ,
8
41
external : [ 'react' ] ,
9
42
format : [ 'esm' , 'cjs' ] ,
43
+ async onSuccess ( ) {
44
+ await addDirectivesToChunkFiles ( ) ;
45
+ } ,
46
+ outDir : DIST_PATH ,
10
47
sourcemap : true ,
11
48
splitting : true ,
12
49
target : 'esnext' ,
You can’t perform that action at this time.
0 commit comments