Skip to content

Commit ec7de7c

Browse files
authoredJul 24, 2023
[core] Fix rsc-builder removing the first line (#38134)
1 parent eabb988 commit ec7de7c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎packages/rsc-builder/buildRsc.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import * as yargs from 'yargs';
22
import * as fse from 'fs-extra';
3-
import os from 'os';
43
import path from 'path';
54
import findComponents from '../api-docs-builder/utils/findComponents';
65
import findHooks from '../api-docs-builder/utils/findHooks';
76

87
type CommandOptions = { grep?: string };
98

10-
const { EOL } = os;
11-
129
const PROJECTS = [
1310
{
1411
name: 'base',
@@ -44,14 +41,17 @@ async function processFile(
4441
filename: string,
4542
options: {
4643
lineToPrepend?: string;
47-
truncate?: boolean;
4844
} = {},
4945
) {
50-
const { lineToPrepend = `'use client';${EOL}`, truncate = true } = options;
46+
const { lineToPrepend = `'use client';` } = options;
5147
const contents = await fse.readFile(filename, 'utf8');
5248

53-
const truncatedContents = truncate ? contents.split(/\r?\n/).slice(1).join('\n') : contents;
54-
const newContents = `${lineToPrepend}${truncatedContents}`;
49+
const lines = contents.split(/\r?\n/);
50+
if (lines[0] === lineToPrepend) {
51+
return;
52+
}
53+
54+
const newContents = `${lineToPrepend}\n${contents}`;
5555

5656
await fse.writeFile(filename, newContents);
5757
}

0 commit comments

Comments
 (0)
Please sign in to comment.