forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile-lockfile.js
49 lines (41 loc) · 1.35 KB
/
compile-lockfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
const cprocess = require('child_process');
const fse = require('fs-extra');
const os = require('os');
const path = require('path');
const temp = path.join(os.tmpdir(), `cra-compile-lockfile`);
try {
// Ensures that we start from a clean state
fse.removeSync(temp);
fse.mkdirSync(temp);
// Create an empty package.json that we'll populate
fse.writeFileSync(path.join(temp, 'package.json'), '{}');
// Extract the dependencies from react-scripts (which is a workspace)
const dependencies = require('react-scripts/package.json').dependencies;
const descriptors = Object.keys(dependencies).map(
dep => `${dep}@${dependencies[dep]}`
);
// Run "yarn add" with all the dependencies of react-scripts
cprocess.execFileSync('yarn', ['add', ...descriptors], { cwd: temp });
// Store the generated lockfile in create-react-app
// We can't store it inside react-scripts, because we need it even before react-scripts is installed
fse.copySync(
path.join(temp, 'yarn.lock'),
path.join(
__dirname,
'..',
'packages',
'create-react-app',
'yarn.lock.cached'
)
);
} finally {
fse.removeSync(temp);
}