Skip to content

Commit d3e9724

Browse files
JiansenGeorge Czabania
authored and
George Czabania
committed
tagging dev-only code (@remove-on-publish-begin/end) and pre-eject-only code (@remove-on-eject-begin/end) facebook#257 (facebook#257)
1 parent 7529238 commit d3e9724

23 files changed

+203
-71
lines changed

config/babel.dev.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
var path = require('path');
1113

config/babel.prod.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
var path = require('path');
1113

config/env.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
1113
// injected into the application via DefinePlugin in Webpack configuration.

config/eslint.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
// Inspired by https://github.com/airbnb/javascript but less opinionated.
1113

config/jest/CSSStub.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
34
*
@@ -7,5 +8,6 @@
78
*
89
* @flow
910
*/
11+
// @remove-on-eject-end
1012

1113
module.exports = {};

config/jest/FileStub.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
34
*
@@ -7,5 +8,6 @@
78
*
89
* @flow
910
*/
11+
// @remove-on-eject-end
1012

1113
module.exports = "test-file-stub";

config/jest/transform.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
34
*
45
* This source code is licensed under the BSD-style license found in the
56
* LICENSE file in the root directory of this source tree. An additional grant
67
* of patent rights can be found in the PATENTS file in the same directory.
78
*/
9+
// @remove-on-eject-end
810

911
const babelDev = require('../babel.dev');
1012
const babelJest = require('babel-jest');

config/paths.js

+36-51
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,63 +7,47 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
9-
10-
// TODO: we can split this file into several files (pre-eject, post-eject, test)
11-
// and use those instead. This way we don't need to branch here.
10+
// @remove-on-eject-end
1211

1312
var path = require('path');
1413

15-
// True after ejecting, false when used as a dependency
16-
var isEjected = (
17-
path.resolve(path.join(__dirname, '..')) ===
18-
path.resolve(process.cwd())
19-
);
14+
function resolveApp(relativePath) {
15+
return path.resolve(relativePath);
16+
}
2017

21-
// Are we developing create-react-app locally?
22-
var isInCreateReactAppSource = (
23-
process.argv.some(arg => arg.indexOf('--debug-template') > -1)
24-
);
18+
// config after eject: we're in ./config/
19+
module.exports = {
20+
appBuild: resolveApp('build'),
21+
appHtml: resolveApp('index.html'),
22+
appPackageJson: resolveApp('package.json'),
23+
appSrc: resolveApp('src'),
24+
appNodeModules: resolveApp('node_modules'),
25+
ownNodeModules: resolveApp('node_modules')
26+
};
2527

28+
// @remove-on-eject-begin
2629
function resolveOwn(relativePath) {
2730
return path.resolve(__dirname, relativePath);
2831
}
32+
// config before eject: we're in ./node_modules/react-scripts/config/
33+
module.exports = {
34+
appBuild: resolveApp('build'),
35+
appHtml: resolveApp('index.html'),
36+
appPackageJson: resolveApp('package.json'),
37+
appSrc: resolveApp('src'),
38+
appNodeModules: resolveApp('node_modules'),
39+
// this is empty with npm3 but node resolution searches higher anyway:
40+
ownNodeModules: resolveOwn('../node_modules')
41+
};
42+
// @remove-on-eject-end
2943

30-
function resolveApp(relativePath) {
31-
return path.resolve(relativePath);
32-
}
33-
34-
if (isInCreateReactAppSource) {
35-
// create-react-app development: we're in ./config/
36-
module.exports = {
37-
appBuild: resolveOwn('../build'),
38-
appHtml: resolveOwn('../template/index.html'),
39-
appPackageJson: resolveOwn('../package.json'),
40-
appStatic: resolveOwn('../template/static'),
41-
appSrc: resolveOwn('../template/src'),
42-
appNodeModules: resolveOwn('../node_modules'),
43-
ownNodeModules: resolveOwn('../node_modules')
44-
};
45-
} else if (!isEjected) {
46-
// before eject: we're in ./node_modules/react-scripts/config/
47-
module.exports = {
48-
appBuild: resolveApp('build'),
49-
appHtml: resolveApp('index.html'),
50-
appPackageJson: resolveApp('package.json'),
51-
appStatic: resolveApp('static'),
52-
appSrc: resolveApp('src'),
53-
appNodeModules: resolveApp('node_modules'),
54-
// this is empty with npm3 but node resolution searches higher anyway:
55-
ownNodeModules: resolveOwn('../node_modules')
56-
};
57-
} else {
58-
// after eject: we're in ./config/
59-
module.exports = {
60-
appBuild: resolveApp('build'),
61-
appHtml: resolveApp('index.html'),
62-
appPackageJson: resolveApp('package.json'),
63-
appStatic: resolveApp('static'),
64-
appSrc: resolveApp('src'),
65-
appNodeModules: resolveApp('node_modules'),
66-
ownNodeModules: resolveApp('node_modules')
67-
};
68-
}
44+
// @remove-on-publish-begin
45+
module.exports = {
46+
appBuild: resolveOwn('../build'),
47+
appHtml: resolveOwn('../template/index.html'),
48+
appPackageJson: resolveOwn('../package.json'),
49+
appSrc: resolveOwn('../template/src'),
50+
appNodeModules: resolveOwn('../node_modules'),
51+
ownNodeModules: resolveOwn('../node_modules')
52+
};
53+
// @remove-on-publish-end

config/polyfills.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
* All rights reserved.
5+
*
6+
* This source code is licensed under the BSD-style license found in the
7+
* LICENSE file in the root directory of this source tree. An additional grant
8+
* of patent rights can be found in the PATENTS file in the same directory.
9+
*/
10+
// @remove-on-eject-end
11+
112
if (typeof Promise === 'undefined') {
213
// Rejection tracking prevents a common issue where React gets into an
314
// inconsistent state due to an error, but it gets swallowed by a Promise,

config/webpack.config.dev.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
var path = require('path');
1113
var autoprefixer = require('autoprefixer');

config/webpack.config.prod.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
var path = require('path');
1113
var autoprefixer = require('autoprefixer');

global-cli/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var pathExists = require('path-exists');
5151
* Example of valid values:
5252
* - a specific npm version: "0.22.0-rc1"
5353
* - a .tgz archive from any npm repo: "https://registry.npmjs.org/react-scripts/-/react-scripts-0.20.0.tgz"
54-
* - a package prepared with `npm pack`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz"
54+
* - a package prepared with `tasks/clean_pack.sh`: "/Users/home/vjeux/create-react-app/react-scripts-0.22.0.tgz"
5555
*/
5656
var commands = argv._;
5757
if (commands.length === 0) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"scripts": {
1414
"build": "node scripts/build.js --debug-template",
15-
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`npm pack`\"",
15+
"create-react-app": "node global-cli/index.js --scripts-version \"$PWD/`tasks/clean_pack.sh`\"",
1616
"e2e": "tasks/e2e.sh",
1717
"start": "node scripts/start.js --debug-template",
1818
"test": "node scripts/test.js --debug-template --env=jsdom"

scripts/build.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
// Do this as the first thing so that any code reading it knows the right env.
1113
process.env.NODE_ENV = 'production';

scripts/eject.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ prompt(
7373
console.log('Copying ' + file + ' to ' + appPath);
7474
var content = fs
7575
.readFileSync(path.join(ownPath, file), 'utf8')
76-
// Remove license header from JS
77-
.replace(/^\/\*\*(\*(?!\/)|[^*])*\*\//, '')
78-
// Remove license header from AppleScript
79-
.replace(/^--.*\n/gm, '')
76+
// Remove dead code from .js files on eject
77+
.replace(/\/\/ @remove-on-eject-begin([\s\S]*?)\/\/ @remove-on-eject-end/mg, '')
78+
// Remove dead code from .applescript files on eject
79+
.replace(/-- @remove-on-eject-begin([\s\S]*?)-- @remove-on-eject-end/mg, '')
8080
.trim() + '\n';
8181
fs.writeFileSync(path.join(appPath, file), content);
8282
});

scripts/start.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
process.env.NODE_ENV = 'development';
1113

scripts/utils/WatchMissingNodeModulesPlugin.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
// This Webpack plugin ensures `npm install <library>` forces a project rebuild.
1113
// We’re not sure why this isn't Webpack's default behavior.

scripts/utils/chrome.applescript

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
-- Copyright (c) 2015-present, Facebook, Inc.
2-
-- All rights reserved.
3-
--
4-
-- This source code is licensed under the BSD-style license found in the
1+
-- @remove-on-eject-begin
2+
(*
3+
Copyright (c) 2015-present, Facebook, Inc.
4+
All rights reserved.
5+
6+
This source code is licensed under the BSD-style license found in the
57
-- LICENSE file in the root directory of this source tree. An additional grant
6-
-- of patent rights can be found in the PATENTS file in the same directory.
8+
of patent rights can be found in the PATENTS file in the same directory.
9+
*)
10+
-- @remove-on-eject-end
11+
712
on run argv
813
set theURL to item 1 of argv
914

scripts/utils/createJestConfig.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
module.exports = (resolve, rootDir) => {
1113
const config = {

scripts/utils/prompt.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @remove-on-eject-begin
12
/**
23
* Copyright (c) 2015-present, Facebook, Inc.
34
* All rights reserved.
@@ -6,6 +7,7 @@
67
* LICENSE file in the root directory of this source tree. An additional grant
78
* of patent rights can be found in the PATENTS file in the same directory.
89
*/
10+
// @remove-on-eject-end
911

1012
var rl = require('readline');
1113

0 commit comments

Comments
 (0)