Skip to content

Commit 69321b0

Browse files
authoredDec 2, 2021
Remove cached lockfile (#11706)
1 parent 3afbbc0 commit 69321b0

File tree

8 files changed

+49
-8809
lines changed

8 files changed

+49
-8809
lines changed
 

‎CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ By default git would use `CRLF` line endings which would cause the scripts to fa
145145
2. Close the milestone and create a new one for the next release.
146146
3. In most releases, only `react-scripts` needs to be released. If you don’t have any changes to the `packages/create-react-app` folder, you don’t need to bump its version or publish it (the publish script will publish only changed packages).
147147
4. Note that files in `packages/create-react-app` should be modified with extreme caution. Since it’s a global CLI, any version of `create-react-app` (global CLI) including very old ones should work with the latest version of `react-scripts`.
148-
5. Pull the latest changes from GitHub, run `npm ci` and then `npm run compile:lockfile`. The command will generate an updated lockfile in `packages/create-react-app` that should be committed.
148+
5. Pull the latest changes from GitHub, run `npm ci`.
149149
6. Create a change log entry for the release:
150150

151151
- You'll need an [access token for the GitHub API](https://help.github.com/articles/creating-an-access-token-for-command-line-use/). Save it to this environment variable: `export GITHUB_AUTH="..."`

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"alex": "alex .",
1818
"test:integration": "jest test/integration",
1919
"test": "cd packages/react-scripts && node bin/react-scripts.js test",
20-
"format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'",
21-
"compile:lockfile": "node tasks/compile-lockfile.js"
20+
"format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'"
2221
},
2322
"devDependencies": {
2423
"@testing-library/jest-dom": "^5.15.1",

‎packages/create-react-app/createReactApp.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,6 @@ function createApp(name, verbose, version, template, useYarn, usePnp) {
325325
}
326326
}
327327

328-
if (useYarn) {
329-
let yarnUsesDefaultRegistry = true;
330-
try {
331-
yarnUsesDefaultRegistry =
332-
execSync('yarnpkg config get registry').toString().trim() ===
333-
'https://registry.yarnpkg.com';
334-
} catch (e) {
335-
// ignore
336-
}
337-
if (yarnUsesDefaultRegistry) {
338-
fs.copySync(
339-
require.resolve('./yarn.lock.cached'),
340-
path.join(root, 'yarn.lock')
341-
);
342-
}
343-
}
344-
345328
run(
346329
root,
347330
appName,
@@ -540,11 +523,7 @@ function run(
540523
console.log();
541524

542525
// On 'exit' we will delete these files from target directory.
543-
const knownGeneratedFiles = [
544-
'package.json',
545-
'yarn.lock',
546-
'node_modules',
547-
];
526+
const knownGeneratedFiles = ['package.json', 'node_modules'];
548527
const currentFiles = fs.readdirSync(path.join(root));
549528
currentFiles.forEach(file => {
550529
knownGeneratedFiles.forEach(fileToMatch => {

‎packages/create-react-app/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
},
2020
"files": [
2121
"index.js",
22-
"createReactApp.js",
23-
"yarn.lock.cached"
22+
"createReactApp.js"
2423
],
2524
"bin": {
2625
"create-react-app": "./index.js"

‎packages/create-react-app/yarn.lock.cached

-8,692
This file was deleted.

‎tasks/compile-lockfile.js

-49
This file was deleted.

‎tasks/publish.sh

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ set -x
2626
cd ..
2727
root_path=$PWD
2828

29-
if [ -z $CI ]; then
30-
npm run compile:lockfile
31-
fi
32-
3329
if [ -n "$(git status --porcelain)" ]; then
3430
echo "Your git status is not clean. Aborting.";
3531
exit 1;

‎test/integration/create-react-app/index.test.js

+45-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const execa = require('execa');
4-
const { mkdirp, writeFileSync, existsSync } = require('fs-extra');
4+
const { mkdirp, writeFileSync, existsSync, readdirSync } = require('fs-extra');
55
const { join } = require('path');
66
const { rmSync } = require('fs');
77

@@ -15,7 +15,10 @@ const genPath = join(__dirname, projectName);
1515

1616
const generatedFiles = [
1717
'.gitignore',
18+
'README.md',
19+
'node_modules',
1820
'package.json',
21+
'public',
1922
'src',
2023
'package-lock.json',
2124
];
@@ -47,10 +50,17 @@ const run = async (args, options) => {
4750
const childProcessResult = await result;
4851
process.stdout.write(`ExitCode: ${childProcessResult.exitCode}\n`);
4952
process.stdout.write('::endgroup::\n');
50-
return childProcessResult;
53+
const files = existsSync(genPath)
54+
? readdirSync(genPath).filter(f => existsSync(join(genPath, f)))
55+
: null;
56+
return {
57+
...childProcessResult,
58+
files,
59+
};
5160
};
5261

53-
const genFileExists = f => existsSync(join(genPath, f));
62+
const expectAllFiles = (arr1, arr2) =>
63+
expect([...arr1].sort()).toEqual([...arr2].sort());
5464

5565
describe('create-react-app', () => {
5666
it('check yarn installation', async () => {
@@ -61,21 +71,22 @@ describe('create-react-app', () => {
6171
});
6272

6373
it('asks to supply an argument if none supplied', async () => {
64-
const { exitCode, stderr } = await run([], { reject: false });
74+
const { exitCode, stderr, files } = await run([], { reject: false });
6575

6676
// Assertions
6777
expect(exitCode).toBe(1);
6878
expect(stderr).toContain('Please specify the project directory');
79+
expect(files).toBe(null);
6980
});
7081

7182
it('creates a project on supplying a name as the argument', async () => {
72-
const { exitCode } = await run([projectName], { cwd: __dirname });
83+
const { exitCode, files } = await run([projectName], { cwd: __dirname });
7384

7485
// Assert for exit code
7586
expect(exitCode).toBe(0);
7687

7788
// Assert for the generated files
78-
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
89+
expectAllFiles(files, generatedFiles);
7990
});
8091

8192
it('warns about conflicting files in path', async () => {
@@ -86,7 +97,7 @@ describe('create-react-app', () => {
8697
const pkgJson = join(genPath, 'package.json');
8798
writeFileSync(pkgJson, '{ "foo": "bar" }');
8899

89-
const { exitCode, stdout } = await run([projectName], {
100+
const { exitCode, stdout, files } = await run([projectName], {
90101
cwd: __dirname,
91102
reject: false,
92103
});
@@ -98,57 +109,54 @@ describe('create-react-app', () => {
98109
expect(stdout).toContain(
99110
`The directory ${projectName} contains files that could conflict`
100111
);
112+
113+
// Existing file is still there
114+
expectAllFiles(files, ['package.json']);
101115
});
102116

103117
it('creates a project in the current directory', async () => {
104118
// Create temporary directory
105119
await mkdirp(genPath);
106120

107121
// Create a project in the current directory
108-
const { exitCode } = await run(['.'], { cwd: genPath });
122+
const { exitCode, files } = await run(['.'], { cwd: genPath });
109123

110124
// Assert for exit code
111125
expect(exitCode).toBe(0);
112126

113127
// Assert for the generated files
114-
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
128+
expectAllFiles(files, generatedFiles);
115129
});
116130

117-
it(
118-
'uses yarn as the package manager',
119-
async () => {
120-
const { exitCode } = await run([projectName], {
121-
cwd: __dirname,
122-
env: { npm_config_user_agent: 'yarn' },
123-
});
124-
125-
// Assert for exit code
126-
expect(exitCode).toBe(0);
127-
128-
// Assert for the generated files
129-
const generatedFilesWithYarn = [
130-
...generatedFiles.filter(file => file !== 'package-lock.json'),
131-
'yarn.lock',
132-
];
133-
134-
generatedFilesWithYarn.forEach(file =>
135-
expect(genFileExists(file)).toBeTruthy()
136-
);
137-
},
138-
1000 * 60 * 10
139-
);
140-
141-
it('creates a project based on the typescript template', async () => {
142-
const { exitCode } = await run([projectName, '--template', 'typescript'], {
131+
it('uses yarn as the package manager', async () => {
132+
const { exitCode, files } = await run([projectName], {
143133
cwd: __dirname,
134+
env: { npm_config_user_agent: 'yarn' },
144135
});
145136

146137
// Assert for exit code
147138
expect(exitCode).toBe(0);
148139

149140
// Assert for the generated files
150-
[...generatedFiles, 'tsconfig.json'].forEach(file =>
151-
expect(genFileExists(file)).toBeTruthy()
141+
const generatedFilesWithYarn = generatedFiles.map(file =>
142+
file === 'package-lock.json' ? 'yarn.lock' : file
143+
);
144+
145+
expectAllFiles(files, generatedFilesWithYarn);
146+
});
147+
148+
it('creates a project based on the typescript template', async () => {
149+
const { exitCode, files } = await run(
150+
[projectName, '--template', 'typescript'],
151+
{
152+
cwd: __dirname,
153+
}
152154
);
155+
156+
// Assert for exit code
157+
expect(exitCode).toBe(0);
158+
159+
// Assert for the generated files
160+
expectAllFiles(files, [...generatedFiles, 'tsconfig.json']);
153161
});
154162
});

0 commit comments

Comments
 (0)
Please sign in to comment.