Skip to content

Commit b2d8587

Browse files
committed
fix: delete output files before building
1 parent 917f8f1 commit b2d8587

File tree

6 files changed

+62
-11
lines changed

6 files changed

+62
-11
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @react-native-community/bob
22

3-
Simple CLI to build React Native libraries for different targets.
3+
👷‍♂️ Simple CLI to build React Native libraries for different targets.
44

55
## Features
66

@@ -9,7 +9,6 @@ The CLI can build code for following targets:
99
- Generic CommonJS build
1010
- ES modules build for bundlers such as webpack
1111
- Flow definitions (copies .js files to .flow files)
12-
- TypeScript definitions (uses tsc to generate declaration files)
1312

1413
## Why?
1514

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@babel/core": "^7.4.0",
2929
"chalk": "^2.4.2",
3030
"cosmiconfig": "^5.2.0",
31+
"del": "^4.1.0",
3132
"fs-extra": "^7.0.1",
3233
"glob": "^7.1.3",
3334
"inquirer": "^6.2.2",
@@ -44,6 +45,7 @@
4445
"@types/babel__core": "^7.1.0",
4546
"@types/chalk": "^2.2.0",
4647
"@types/cosmiconfig": "^5.0.3",
48+
"@types/del": "^4.0.0",
4749
"@types/fs-extra": "^5.0.5",
4850
"@types/glob": "^7.1.1",
4951
"@types/inquirer": "^6.0.0",

src/targets/commonjs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Input } from '../types';
1+
import del from 'del'
22
import compile from '../utils/compile';
33
import * as logger from '../utils/logger';
4+
import { Input } from '../types';
45

56
type Options = Input & {
67
options?: { flow?: boolean };
@@ -9,6 +10,7 @@ type Options = Input & {
910
export default async function build({ root, source, output, options }: Options) {
1011
logger.info('building files for commonjs target');
1112

13+
await del([output]);
1214
await compile({
1315
root,
1416
source,

src/targets/module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Input } from '../types';
1+
import del from 'del'
22
import compile from '../utils/compile';
33
import * as logger from '../utils/logger';
4+
import { Input } from '../types';
45

56
type Options = Input & {
67
options?: { flow?: boolean };
@@ -14,6 +15,7 @@ export default async function build({
1415
}: Options) {
1516
logger.info('building files for module target');
1617

18+
await del([output]);
1719
await compile({
1820
root,
1921
source,

src/utils/compile.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default async function compile({
3333

3434
if (!/\.(js|tsx?)/.test(filepath)) {
3535
// Copy files which aren't source code
36-
fs.copy(filepath, outputFilename, { overwrite: true });
36+
fs.copy(filepath, outputFilename);
3737
}
3838

3939
const content = await fs.readFile(filepath, 'utf-8');
@@ -59,9 +59,8 @@ export default async function compile({
5959

6060
await fs.writeFile(outputFilename, code);
6161

62-
// If the code has flow comment, also copy the file for flow
63-
if (flow && content.includes('@flow')) {
64-
fs.copy(filepath, outputFilename + '.flow', { overwrite: true });
62+
if (flow) {
63+
fs.copy(filepath, outputFilename + '.flow');
6564
}
6665
})
6766
);

yarn.lock

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,13 @@
10281028
dependencies:
10291029
"@types/node" "*"
10301030

1031+
"@types/del@^4.0.0":
1032+
version "4.0.0"
1033+
resolved "https://registry.yarnpkg.com/@types/del/-/del-4.0.0.tgz#0d0b5a02e66a96d410d19241557ab25cded9eb16"
1034+
integrity sha512-LDE5atstX5kKnTobWknpmGHC52DH/tp8pIVsD2SSxaOFqW3AQr0EpdzYIfkZ331xe7l9Vn9NlJsBG6viU3mjBA==
1035+
dependencies:
1036+
del "*"
1037+
10311038
"@types/events@*":
10321039
version "3.0.0"
10331040
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
@@ -1191,7 +1198,7 @@ array-ify@^1.0.0:
11911198
resolved "https://registry.yarnpkg.com/array-ify/-/array-ify-1.0.0.tgz#9e528762b4a9066ad163a6962a364418e9626ece"
11921199
integrity sha1-nlKHYrSpBmrRY6aWKjZEGOlibs4=
11931200

1194-
array-union@^1.0.2:
1201+
array-union@^1.0.1, array-union@^1.0.2:
11951202
version "1.0.2"
11961203
resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39"
11971204
integrity sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=
@@ -2047,6 +2054,18 @@ define-property@^2.0.2:
20472054
is-descriptor "^1.0.2"
20482055
isobject "^3.0.1"
20492056

2057+
del@*, del@^4.1.0:
2058+
version "4.1.0"
2059+
resolved "https://registry.yarnpkg.com/del/-/del-4.1.0.tgz#049543b8290e1a9293e2bd150ab3a06f637322b8"
2060+
integrity sha512-C4kvKNlYrwXhKxz97BuohF8YoGgQ23Xm9lvoHmgT7JaPGprSEjk3+XFled74Yt/x0ZABUHg2D67covzAPUKx5Q==
2061+
dependencies:
2062+
globby "^6.1.0"
2063+
is-path-cwd "^2.0.0"
2064+
is-path-in-cwd "^2.0.0"
2065+
p-map "^2.0.0"
2066+
pify "^4.0.1"
2067+
rimraf "^2.6.3"
2068+
20502069
delayed-stream@~1.0.0:
20512070
version "1.0.0"
20522071
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
@@ -2501,7 +2520,7 @@ glob-to-regexp@^0.3.0:
25012520
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
25022521
integrity sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=
25032522

2504-
glob@^7.0.0, glob@^7.1.3:
2523+
glob@^7.0.0, glob@^7.0.3, glob@^7.1.3:
25052524
version "7.1.3"
25062525
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1"
25072526
integrity sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==
@@ -2547,6 +2566,17 @@ globby@9.2.0:
25472566
pify "^4.0.1"
25482567
slash "^2.0.0"
25492568

2569+
globby@^6.1.0:
2570+
version "6.1.0"
2571+
resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
2572+
integrity sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=
2573+
dependencies:
2574+
array-union "^1.0.1"
2575+
glob "^7.0.3"
2576+
object-assign "^4.0.1"
2577+
pify "^2.0.0"
2578+
pinkie-promise "^2.0.0"
2579+
25502580
globby@^9.1.0:
25512581
version "9.1.0"
25522582
resolved "https://registry.yarnpkg.com/globby/-/globby-9.1.0.tgz#e90f4d5134109e6d855abdd31bdb1b085428592e"
@@ -2967,6 +2997,18 @@ is-obj@^1.0.0:
29672997
resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f"
29682998
integrity sha1-PkcprB9f3gJc19g6iW2rn09n2w8=
29692999

3000+
is-path-cwd@^2.0.0:
3001+
version "2.0.0"
3002+
resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-2.0.0.tgz#d4777a8e227a00096a31f030db3770f84b116c02"
3003+
integrity sha512-m5dHHzpOXEiv18JEORttBO64UgTEypx99vCxQLjbBvGhOJxnTNglYoFXxwo6AbsQb79sqqycQEHv2hWkHZAijA==
3004+
3005+
is-path-in-cwd@^2.0.0:
3006+
version "2.0.0"
3007+
resolved "https://registry.yarnpkg.com/is-path-in-cwd/-/is-path-in-cwd-2.0.0.tgz#68e452a6eec260500cec21e029c0a44cc0dcd2ea"
3008+
integrity sha512-6Vz5Gc9s/sDA3JBVu0FzWufm8xaBsqy1zn8Q6gmvGP6nSDMw78aS4poBNeatWjaRpTpxxLn1WOndAiOlk+qY8A==
3009+
dependencies:
3010+
is-path-inside "^1.0.0"
3011+
29703012
is-path-inside@^1.0.0:
29713013
version "1.0.1"
29723014
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-1.0.1.tgz#8ef5b7de50437a3fdca6b4e865ef7aa55cb48036"
@@ -3882,6 +3924,11 @@ p-locate@^3.0.0:
38823924
dependencies:
38833925
p-limit "^2.0.0"
38843926

3927+
p-map@^2.0.0:
3928+
version "2.0.0"
3929+
resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.0.0.tgz#be18c5a5adeb8e156460651421aceca56c213a50"
3930+
integrity sha512-GO107XdrSUmtHxVoi60qc9tUl/KkNKm+X2CF4P9amalpGxv5YqVPJNfSb0wcA+syCopkZvYYIzW8OVTQW59x/w==
3931+
38853932
p-try@^1.0.0:
38863933
version "1.0.0"
38873934
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
@@ -4440,7 +4487,7 @@ retry@0.12.0:
44404487
resolved "https://registry.yarnpkg.com/retry/-/retry-0.12.0.tgz#1b42a6266a21f07421d1b0b54b7dc167b01c013b"
44414488
integrity sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=
44424489

4443-
rimraf@^2.5.2, rimraf@^2.6.1:
4490+
rimraf@^2.5.2, rimraf@^2.6.1, rimraf@^2.6.3:
44444491
version "2.6.3"
44454492
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
44464493
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==

0 commit comments

Comments
 (0)