Skip to content

Commit

Permalink
Remove cached lockfile (facebook#11706)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored and abhiisheek committed May 24, 2023
1 parent 3982c97 commit 7550420
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8,809 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ By default git would use `CRLF` line endings which would cause the scripts to fa
2. Close the milestone and create a new one for the next release.
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).
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`.
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.
5. Pull the latest changes from GitHub, run `npm ci`.
6. Create a change log entry for the release:

- 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="..."`
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"alex": "alex .",
"test:integration": "jest test/integration",
"test": "cd packages/react-scripts && node bin/react-scripts.js test",
"format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'",
"compile:lockfile": "node tasks/compile-lockfile.js"
"format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.15.1",
Expand Down
23 changes: 1 addition & 22 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,6 @@ function createApp(name, verbose, version, template, useYarn, usePnp) {
}
}

if (useYarn) {
let yarnUsesDefaultRegistry = true;
try {
yarnUsesDefaultRegistry =
execSync('yarnpkg config get registry').toString().trim() ===
'https://registry.yarnpkg.com';
} catch (e) {
// ignore
}
if (yarnUsesDefaultRegistry) {
fs.copySync(
require.resolve('./yarn.lock.cached'),
path.join(root, 'yarn.lock')
);
}
}

run(
root,
appName,
Expand Down Expand Up @@ -540,11 +523,7 @@ function run(
console.log();

// On 'exit' we will delete these files from target directory.
const knownGeneratedFiles = [
'package.json',
'yarn.lock',
'node_modules',
];
const knownGeneratedFiles = ['package.json', 'node_modules'];
const currentFiles = fs.readdirSync(path.join(root));
currentFiles.forEach(file => {
knownGeneratedFiles.forEach(fileToMatch => {
Expand Down
3 changes: 1 addition & 2 deletions packages/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
},
"files": [
"index.js",
"createReactApp.js",
"yarn.lock.cached"
"createReactApp.js"
],
"bin": {
"create-react-app": "./index.js"
Expand Down
8,692 changes: 0 additions & 8,692 deletions packages/create-react-app/yarn.lock.cached

This file was deleted.

49 changes: 0 additions & 49 deletions tasks/compile-lockfile.js

This file was deleted.

4 changes: 0 additions & 4 deletions tasks/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ set -x
cd ..
root_path=$PWD

if [ -z $CI ]; then
npm run compile:lockfile
fi

if [ -n "$(git status --porcelain)" ]; then
echo "Your git status is not clean. Aborting.";
exit 1;
Expand Down
82 changes: 45 additions & 37 deletions test/integration/create-react-app/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const execa = require('execa');
const { mkdirp, writeFileSync, existsSync } = require('fs-extra');
const { mkdirp, writeFileSync, existsSync, readdirSync } = require('fs-extra');
const { join } = require('path');
const { rmSync } = require('fs');

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

const generatedFiles = [
'.gitignore',
'README.md',
'node_modules',
'package.json',
'public',
'src',
'package-lock.json',
];
Expand Down Expand Up @@ -47,10 +50,17 @@ const run = async (args, options) => {
const childProcessResult = await result;
process.stdout.write(`ExitCode: ${childProcessResult.exitCode}\n`);
process.stdout.write('::endgroup::\n');
return childProcessResult;
const files = existsSync(genPath)
? readdirSync(genPath).filter(f => existsSync(join(genPath, f)))
: null;
return {
...childProcessResult,
files,
};
};

const genFileExists = f => existsSync(join(genPath, f));
const expectAllFiles = (arr1, arr2) =>
expect([...arr1].sort()).toEqual([...arr2].sort());

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

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

// Assertions
expect(exitCode).toBe(1);
expect(stderr).toContain('Please specify the project directory');
expect(files).toBe(null);
});

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

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

// Assert for the generated files
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
expectAllFiles(files, generatedFiles);
});

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

const { exitCode, stdout } = await run([projectName], {
const { exitCode, stdout, files } = await run([projectName], {
cwd: __dirname,
reject: false,
});
Expand All @@ -98,57 +109,54 @@ describe('create-react-app', () => {
expect(stdout).toContain(
`The directory ${projectName} contains files that could conflict`
);

// Existing file is still there
expectAllFiles(files, ['package.json']);
});

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

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

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

// Assert for the generated files
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
expectAllFiles(files, generatedFiles);
});

it(
'uses yarn as the package manager',
async () => {
const { exitCode } = await run([projectName], {
cwd: __dirname,
env: { npm_config_user_agent: 'yarn' },
});

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

// Assert for the generated files
const generatedFilesWithYarn = [
...generatedFiles.filter(file => file !== 'package-lock.json'),
'yarn.lock',
];

generatedFilesWithYarn.forEach(file =>
expect(genFileExists(file)).toBeTruthy()
);
},
1000 * 60 * 10
);

it('creates a project based on the typescript template', async () => {
const { exitCode } = await run([projectName, '--template', 'typescript'], {
it('uses yarn as the package manager', async () => {
const { exitCode, files } = await run([projectName], {
cwd: __dirname,
env: { npm_config_user_agent: 'yarn' },
});

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

// Assert for the generated files
[...generatedFiles, 'tsconfig.json'].forEach(file =>
expect(genFileExists(file)).toBeTruthy()
const generatedFilesWithYarn = generatedFiles.map(file =>
file === 'package-lock.json' ? 'yarn.lock' : file
);

expectAllFiles(files, generatedFilesWithYarn);
});

it('creates a project based on the typescript template', async () => {
const { exitCode, files } = await run(
[projectName, '--template', 'typescript'],
{
cwd: __dirname,
}
);

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

// Assert for the generated files
expectAllFiles(files, [...generatedFiles, 'tsconfig.json']);
});
});

0 comments on commit 7550420

Please sign in to comment.