@react-native/babel-preset 0.73.2 → 0.73.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.babelrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "plugins": [
3
+ "@babel/plugin-proposal-object-rest-spread",
4
+ "@babel/plugin-transform-async-to-generator",
5
+ "@babel/plugin-transform-destructuring",
6
+ "@babel/plugin-transform-flow-strip-types",
7
+ "@babel/plugin-syntax-dynamic-import",
8
+ "@babel/plugin-proposal-class-properties",
9
+ "@babel/plugin-proposal-nullish-coalescing-operator",
10
+ "@babel/plugin-proposal-optional-chaining"
11
+ ]
12
+ }
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "arrowParens": "avoid",
3
+ "bracketSameLine": true,
4
+ "bracketSpacing": false,
5
+ "requirePragma": true,
6
+ "singleQuote": true,
7
+ "trailingComma": "all"
8
+ }
package/BUCK ADDED
@@ -0,0 +1,23 @@
1
+ load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace")
2
+
3
+ oncall("react_native")
4
+
5
+ yarn_workspace(
6
+ name = "yarn-workspace",
7
+ srcs = glob(
8
+ ["src/**/*.js"],
9
+ exclude = [
10
+ "**/__fixtures__/**",
11
+ "**/__flowtests__/**",
12
+ "**/__mocks__/**",
13
+ "**/__server_snapshot_tests__/**",
14
+ "**/__tests__/**",
15
+ "**/.*",
16
+ "**/.*/**",
17
+ "**/.*/.*",
18
+ "**/*.xcodeproj/**",
19
+ "**/*.xcworkspace/**",
20
+ ],
21
+ ),
22
+ visibility = ["PUBLIC"],
23
+ )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/babel-preset",
3
- "version": "0.73.2",
3
+ "version": "0.73.3",
4
4
  "description": "Babel preset for React Native applications",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -8,13 +8,13 @@
8
8
  "url": "git@github.com:facebook/react-native.git"
9
9
  },
10
10
  "scripts": {
11
- "build": "yarn clean && node scripts/build.js --verbose",
12
- "clean": "rimraf lib",
13
- "prepare": "yarn run build"
11
+ "prepare-release": "test -d lib && mv src src.real && mv lib src",
12
+ "cleanup-release": "test ! -e lib && mv src lib && mv src.real src && rimraf lib",
13
+ "build-clean": "rimraf build && rimraf src.real",
14
+ "build": " node scripts/build.js --verbose",
15
+ "prepare": "yarn run build-clean && yarn run build && yarn run prepare-release",
16
+ "postpublish": "yarn run cleanup-release"
14
17
  },
15
- "files": [
16
- "lib"
17
- ],
18
18
  "keywords": [
19
19
  "babel",
20
20
  "preset",
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ */
9
+
10
+ /**
11
+ * script to build (transpile) files.
12
+ *
13
+ * Based off of the build script from Metro, and tweaked to run in just one
14
+ * package instead of in a monorepo. Just run `build.js` and the JS files in
15
+ * `src/` will be built in `lib/`, and the original source files will be copied
16
+ * over as `Example.js.flow`, so consumers of this module can still make use of
17
+ * type checking.
18
+ *
19
+ * Call this script with the `--verbose` flag to show the full output of this
20
+ * script.
21
+ */
22
+
23
+ 'use strict';
24
+
25
+ const babel = require('@babel/core');
26
+ const chalk = require('chalk');
27
+ const fs = require('fs');
28
+ const glob = require('glob');
29
+ const micromatch = require('micromatch');
30
+ const mkdirp = require('mkdirp');
31
+ const path = require('path');
32
+ const prettier = require('prettier');
33
+ const prettierConfig = JSON.parse(
34
+ fs.readFileSync(path.resolve(__dirname, '..', '.prettierrc'), 'utf8'),
35
+ );
36
+
37
+ const SRC_DIR = 'src';
38
+ const BUILD_DIR = 'lib';
39
+ const JS_FILES_PATTERN = '**/*.js';
40
+ const IGNORE_PATTERN = '**/__tests__/**';
41
+ const PACKAGE_DIR = path.resolve(__dirname, '../');
42
+
43
+ const fixedWidth = str => {
44
+ const WIDTH = 80;
45
+ const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g')) || [str];
46
+ let lastString = strs[strs.length - 1];
47
+ if (lastString.length < WIDTH) {
48
+ lastString += Array(WIDTH - lastString.length).join(chalk.dim('.'));
49
+ }
50
+ return strs.slice(0, -1).concat(lastString).join('\n');
51
+ };
52
+
53
+ function getBuildPath(file, buildFolder) {
54
+ const pkgSrcPath = path.resolve(PACKAGE_DIR, SRC_DIR);
55
+ const pkgBuildPath = path.resolve(PACKAGE_DIR, BUILD_DIR);
56
+ const relativeToSrcPath = path.relative(pkgSrcPath, file);
57
+ return path.resolve(pkgBuildPath, relativeToSrcPath);
58
+ }
59
+
60
+ function buildFile(file, silent) {
61
+ const destPath = getBuildPath(file, BUILD_DIR);
62
+
63
+ mkdirp.sync(path.dirname(destPath));
64
+ if (micromatch.isMatch(file, IGNORE_PATTERN)) {
65
+ silent ||
66
+ process.stdout.write(
67
+ chalk.dim(' \u2022 ') +
68
+ path.relative(PACKAGE_DIR, file) +
69
+ ' (ignore)\n',
70
+ );
71
+ } else if (!micromatch.isMatch(file, JS_FILES_PATTERN)) {
72
+ fs.createReadStream(file).pipe(fs.createWriteStream(destPath));
73
+ silent ||
74
+ process.stdout.write(
75
+ chalk.red(' \u2022 ') +
76
+ path.relative(PACKAGE_DIR, file) +
77
+ chalk.red(' \u21D2 ') +
78
+ path.relative(PACKAGE_DIR, destPath) +
79
+ ' (copy)' +
80
+ '\n',
81
+ );
82
+ } else {
83
+ const transformed = prettier.format(
84
+ babel.transformFileSync(file, {}).code,
85
+ {
86
+ ...prettierConfig,
87
+ parser: 'babel',
88
+ },
89
+ );
90
+ fs.writeFileSync(destPath, transformed);
91
+ const source = fs.readFileSync(file).toString('utf-8');
92
+ if (/@flow/.test(source)) {
93
+ fs.createReadStream(file).pipe(fs.createWriteStream(destPath + '.flow'));
94
+ }
95
+ silent ||
96
+ process.stdout.write(
97
+ chalk.green(' \u2022 ') +
98
+ path.relative(PACKAGE_DIR, file) +
99
+ chalk.green(' \u21D2 ') +
100
+ path.relative(PACKAGE_DIR, destPath) +
101
+ '\n',
102
+ );
103
+ }
104
+ }
105
+
106
+ const srcDir = path.resolve(__dirname, '..', SRC_DIR);
107
+ const pattern = path.resolve(srcDir, '**/*');
108
+ const files = glob.sync(pattern, {nodir: true});
109
+
110
+ process.stdout.write(fixedWidth(`${path.basename(PACKAGE_DIR)}\n`));
111
+
112
+ files.forEach(file => buildFile(file, !process.argv.includes('--verbose')));
113
+
114
+ process.stdout.write(`[ ${chalk.green('OK')} ]\n`);
package/src/index.js CHANGED
@@ -11,10 +11,8 @@
11
11
  'use strict';
12
12
 
13
13
  const main = require('./configs/main');
14
-
15
14
  module.exports = function (babel, options) {
16
15
  return main(options);
17
16
  };
18
-
19
17
  module.exports.getPreset = main.getPreset;
20
18
  module.exports.passthroughSyntaxPlugins = require('./passthrough-syntax-plugins');
package/lib/index.js DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @oncall react_native
9
- */
10
-
11
- 'use strict';
12
-
13
- const main = require('./configs/main');
14
- module.exports = function (babel, options) {
15
- return main(options);
16
- };
17
- module.exports.getPreset = main.getPreset;
18
- module.exports.passthroughSyntaxPlugins = require('./passthrough-syntax-plugins');
File without changes
File without changes
File without changes
File without changes