@nx/react-native 16.8.0-beta.3 → 16.8.0-beta.5

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.
Files changed (65) hide show
  1. package/package.json +10 -10
  2. package/plugins/metro-resolver.js +4 -5
  3. package/plugins/with-nx-metro.js +23 -27
  4. package/src/executors/build-android/build-android.impl.js +6 -9
  5. package/src/executors/build-ios/build-ios.impl.js +8 -11
  6. package/src/executors/bundle/bundle.impl.js +6 -9
  7. package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -7
  8. package/src/executors/pod-install/pod-install.impl.js +5 -8
  9. package/src/executors/run-android/run-android.impl.js +23 -39
  10. package/src/executors/run-ios/run-ios.impl.js +25 -41
  11. package/src/executors/start/lib/is-packager-running.js +9 -12
  12. package/src/executors/start/start.impl.js +38 -43
  13. package/src/executors/storybook/storybook.impl.js +17 -20
  14. package/src/executors/sync-deps/sync-deps.impl.js +32 -37
  15. package/src/generators/application/application.js +23 -21
  16. package/src/generators/application/application.spec.ts +41 -38
  17. package/src/generators/application/lib/add-detox.js +15 -7
  18. package/src/generators/application/lib/add-project.js +4 -2
  19. package/src/generators/application/lib/create-application-files.js +6 -1
  20. package/src/generators/application/lib/nomalize-options.spec.ts +30 -25
  21. package/src/generators/application/lib/normalize-options.js +30 -23
  22. package/src/generators/component/component.js +9 -9
  23. package/src/generators/component/component.spec.ts +14 -22
  24. package/src/generators/component/lib/normalize-options.js +36 -37
  25. package/src/generators/component-story/component-story.js +6 -9
  26. package/src/generators/component-story/component-story.spec.ts +7 -7
  27. package/src/generators/init/init.js +56 -29
  28. package/src/generators/init/init.spec.ts +1 -1
  29. package/src/generators/library/lib/normalize-options.js +21 -18
  30. package/src/generators/library/library.js +94 -79
  31. package/src/generators/library/library.spec.ts +47 -57
  32. package/src/generators/stories/stories-app.spec.ts +20 -37
  33. package/src/generators/stories/stories-lib.spec.ts +10 -18
  34. package/src/generators/stories/stories.js +39 -44
  35. package/src/generators/storybook-configuration/configuration.js +29 -34
  36. package/src/generators/storybook-configuration/configuration.spec.ts +10 -12
  37. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +1 -1
  38. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +7 -7
  39. package/src/generators/storybook-configuration/lib/create-storybook-files.js +30 -34
  40. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +1 -1
  41. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +7 -7
  42. package/src/generators/upgrade-native/upgrade-native.js +13 -16
  43. package/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.js +11 -16
  44. package/src/migrations/update-12-5-0/update-jest-for-react-native.js +5 -8
  45. package/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.js +12 -15
  46. package/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.js +7 -11
  47. package/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.js +16 -20
  48. package/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.js +23 -28
  49. package/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.js +26 -30
  50. package/src/migrations/update-14-2-1/rename-blockList-metro-config.js +16 -20
  51. package/src/migrations/update-14-5-5/add-exclude-sync-deps.js +12 -16
  52. package/src/migrations/update-14-5-8/change-searchDir-storybook.js +12 -16
  53. package/src/migrations/update-14-6-0/remove-jest-transform.js +13 -17
  54. package/src/migrations/update-15-0-0/add-babel-inputs.js +3 -6
  55. package/src/migrations/update-15-9-1/add-build-ios-target.js +19 -23
  56. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  57. package/src/migrations/update-16-1-0/upgrade-storybook-6-5.js +2 -3
  58. package/src/migrations/update-16-6-0/add-depends-on.js +29 -33
  59. package/src/migrations/update-16-6-0/update-metro-config.js +11 -15
  60. package/src/utils/add-jest.js +19 -22
  61. package/src/utils/add-linting.js +26 -29
  62. package/src/utils/chmod-android-gradle-files.js +1 -1
  63. package/src/utils/find-all-npm-dependencies.js +1 -2
  64. package/src/utils/symlink-task.js +1 -1
  65. package/src/utils/testing-generators.js +19 -23
@@ -1,31 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
- function normalizeOptions(host, options) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- const { projectName: appProjectName, names: projectNames, projectRoot: appProjectRoot, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
- name: options.name,
11
- projectType: 'application',
12
- directory: options.directory,
13
- projectNameAndRootFormat: options.projectNameAndRootFormat,
14
- callingGenerator: '@nx/react-native:application',
15
- });
16
- options.projectNameAndRootFormat = projectNameAndRootFormat;
17
- const { className } = (0, devkit_1.names)(options.name);
18
- const iosProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'ios');
19
- const androidProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'android');
20
- const parsedTags = options.tags
21
- ? options.tags.split(',').map((s) => s.trim())
22
- : [];
23
- const entryFile = options.js ? 'src/main.js' : 'src/main.tsx';
24
- return Object.assign(Object.assign({}, options), { unitTestRunner: options.unitTestRunner || 'jest', e2eTestRunner: options.e2eTestRunner || 'detox', name: projectNames.projectSimpleName, className, lowerCaseName: className.toLowerCase(), displayName: options.displayName || className, projectName: appProjectName, appProjectRoot,
25
- iosProjectRoot,
26
- androidProjectRoot,
27
- parsedTags,
28
- entryFile });
6
+ async function normalizeOptions(host, options) {
7
+ const { projectName: appProjectName, names: projectNames, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
+ name: options.name,
9
+ projectType: 'application',
10
+ directory: options.directory,
11
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
12
+ callingGenerator: '@nx/react-native:application',
29
13
  });
14
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
15
+ const { className } = (0, devkit_1.names)(options.name);
16
+ const iosProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'ios');
17
+ const androidProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'android');
18
+ const parsedTags = options.tags
19
+ ? options.tags.split(',').map((s) => s.trim())
20
+ : [];
21
+ const entryFile = options.js ? 'src/main.js' : 'src/main.tsx';
22
+ return {
23
+ ...options,
24
+ unitTestRunner: options.unitTestRunner || 'jest',
25
+ e2eTestRunner: options.e2eTestRunner || 'detox',
26
+ name: projectNames.projectSimpleName,
27
+ className,
28
+ lowerCaseName: className.toLowerCase(),
29
+ displayName: options.displayName || className,
30
+ projectName: appProjectName,
31
+ appProjectRoot,
32
+ iosProjectRoot,
33
+ androidProjectRoot,
34
+ parsedTags,
35
+ entryFile,
36
+ };
30
37
  }
31
38
  exports.normalizeOptions = normalizeOptions;
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeComponentSchematic = exports.reactNativeComponentGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const normalize_options_1 = require("./lib/normalize-options");
7
6
  const add_import_1 = require("./lib/add-import");
8
7
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
9
8
  const path_1 = require("path");
10
- function reactNativeComponentGenerator(host, schema) {
11
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- const options = yield (0, normalize_options_1.normalizeOptions)(host, schema);
13
- createComponentFiles(host, options);
14
- addExportsToBarrel(host, options);
15
- yield (0, devkit_1.formatFiles)(host);
16
- });
9
+ async function reactNativeComponentGenerator(host, schema) {
10
+ const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
11
+ createComponentFiles(host, options);
12
+ addExportsToBarrel(host, options);
13
+ await (0, devkit_1.formatFiles)(host);
17
14
  }
18
15
  exports.reactNativeComponentGenerator = reactNativeComponentGenerator;
19
16
  function createComponentFiles(host, options) {
20
17
  const componentDir = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.directory);
21
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), componentDir, Object.assign(Object.assign({}, options), { tmpl: '' }));
18
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), componentDir, {
19
+ ...options,
20
+ tmpl: '',
21
+ });
22
22
  for (const c of host.listChanges()) {
23
23
  let deleteFile = false;
24
24
  if (options.skipTests && /.*spec.tsx/.test(c.path)) {
@@ -9,7 +9,7 @@ describe('component', () => {
9
9
 
10
10
  beforeEach(async () => {
11
11
  projectName = 'my-lib';
12
- appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
12
+ appTree = createTreeWithEmptyWorkspace();
13
13
  appTree.write('.gitignore', '');
14
14
  await createApp(appTree, 'my-app');
15
15
  await createLib(appTree, projectName);
@@ -21,16 +21,14 @@ describe('component', () => {
21
21
  jest.restoreAllMocks();
22
22
  });
23
23
 
24
- it('should generate files', async () => {
24
+ it('should generate component files', async () => {
25
25
  await reactNativeComponentGenerator(appTree, {
26
26
  name: 'hello',
27
27
  project: projectName,
28
28
  });
29
29
 
30
- expect(appTree.exists('libs/my-lib/src/lib/hello/hello.tsx')).toBeTruthy();
31
- expect(
32
- appTree.exists('libs/my-lib/src/lib/hello/hello.spec.tsx')
33
- ).toBeTruthy();
30
+ expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy();
31
+ expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy();
34
32
  });
35
33
 
36
34
  it('should generate files for an app', async () => {
@@ -39,10 +37,8 @@ describe('component', () => {
39
37
  project: 'my-app',
40
38
  });
41
39
 
42
- expect(appTree.exists('apps/my-app/src/app/hello/hello.tsx')).toBeTruthy();
43
- expect(
44
- appTree.exists('apps/my-app/src/app/hello/hello.spec.tsx')
45
- ).toBeTruthy();
40
+ expect(appTree.exists('my-app/src/app/hello/hello.tsx')).toBeTruthy();
41
+ expect(appTree.exists('my-app/src/app/hello/hello.spec.tsx')).toBeTruthy();
46
42
  });
47
43
 
48
44
  describe('--export', () => {
@@ -53,7 +49,7 @@ describe('component', () => {
53
49
  export: true,
54
50
  });
55
51
 
56
- const indexContent = appTree.read('libs/my-lib/src/index.ts', 'utf-8');
52
+ const indexContent = appTree.read('my-lib/src/index.ts', 'utf-8');
57
53
 
58
54
  expect(indexContent).toMatch(/lib\/hello/);
59
55
  });
@@ -65,7 +61,7 @@ describe('component', () => {
65
61
  export: true,
66
62
  });
67
63
 
68
- const indexContent = appTree.read('libs/my-lib/src/index.ts', 'utf-8');
64
+ const indexContent = appTree.read('my-lib/src/index.ts', 'utf-8');
69
65
 
70
66
  expect(indexContent).not.toMatch(/lib\/hello/);
71
67
  });
@@ -78,11 +74,9 @@ describe('component', () => {
78
74
  project: projectName,
79
75
  pascalCaseFiles: true,
80
76
  });
77
+ expect(appTree.exists('my-lib/src/lib/hello/Hello.tsx')).toBeTruthy();
81
78
  expect(
82
- appTree.exists('libs/my-lib/src/lib/hello/Hello.tsx')
83
- ).toBeTruthy();
84
- expect(
85
- appTree.exists('libs/my-lib/src/lib/hello/Hello.spec.tsx')
79
+ appTree.exists('my-lib/src/lib/hello/Hello.spec.tsx')
86
80
  ).toBeTruthy();
87
81
  });
88
82
  });
@@ -95,7 +89,7 @@ describe('component', () => {
95
89
  directory: 'components',
96
90
  });
97
91
 
98
- expect(appTree.exists('/libs/my-lib/src/components/hello/hello.tsx'));
92
+ expect(appTree.exists('my-lib/src/components/hello/hello.tsx'));
99
93
  });
100
94
 
101
95
  it('should create with nested directories', async () => {
@@ -105,9 +99,7 @@ describe('component', () => {
105
99
  directory: 'lib/foo',
106
100
  });
107
101
 
108
- expect(
109
- appTree.exists('/libs/my-lib/src/lib/foo/hello-world/hello-world.tsx')
110
- );
102
+ expect(appTree.exists('my-lib/src/lib/foo/hello-world/hello-world.tsx'));
111
103
  });
112
104
  });
113
105
 
@@ -119,7 +111,7 @@ describe('component', () => {
119
111
  flat: true,
120
112
  });
121
113
 
122
- expect(appTree.exists('/libs/my-lib/src/lib/hello.tsx'));
114
+ expect(appTree.exists('my-lib/src/lib/hello.tsx'));
123
115
  });
124
116
  it('should work with custom directory path', async () => {
125
117
  await reactNativeComponentGenerator(appTree, {
@@ -129,7 +121,7 @@ describe('component', () => {
129
121
  directory: 'components',
130
122
  });
131
123
 
132
- expect(appTree.exists('/libs/my-lib/src/components/hello.tsx'));
124
+ expect(appTree.exists('my-lib/src/components/hello.tsx'));
133
125
  });
134
126
  });
135
127
  });
@@ -1,46 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
- function normalizeOptions(host, options) {
7
- var _a;
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- assertValidOptions(options);
10
- const { className, fileName } = (0, devkit_1.names)(options.name);
11
- const componentFileName = options.pascalCaseFiles ? className : fileName;
12
- const project = (0, devkit_1.getProjects)(host).get(options.project);
13
- if (!project) {
14
- devkit_1.logger.error(`Cannot find the ${options.project} project. Please double check the project name.`);
15
- throw new Error();
16
- }
17
- const { sourceRoot: projectSourceRoot, projectType } = project;
18
- const directory = yield getDirectory(host, options);
19
- if (options.export && projectType === 'application') {
20
- devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
21
- }
22
- options.classComponent = (_a = options.classComponent) !== null && _a !== void 0 ? _a : false;
23
- return Object.assign(Object.assign({}, options), { directory,
24
- className, fileName: componentFileName, projectSourceRoot });
25
- });
5
+ async function normalizeOptions(host, options) {
6
+ assertValidOptions(options);
7
+ const { className, fileName } = (0, devkit_1.names)(options.name);
8
+ const componentFileName = options.pascalCaseFiles ? className : fileName;
9
+ const project = (0, devkit_1.getProjects)(host).get(options.project);
10
+ if (!project) {
11
+ devkit_1.logger.error(`Cannot find the ${options.project} project. Please double check the project name.`);
12
+ throw new Error();
13
+ }
14
+ const { sourceRoot: projectSourceRoot, projectType } = project;
15
+ const directory = await getDirectory(host, options);
16
+ if (options.export && projectType === 'application') {
17
+ devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
18
+ }
19
+ options.classComponent = options.classComponent ?? false;
20
+ return {
21
+ ...options,
22
+ directory,
23
+ className,
24
+ fileName: componentFileName,
25
+ projectSourceRoot,
26
+ };
26
27
  }
27
28
  exports.normalizeOptions = normalizeOptions;
28
- function getDirectory(host, options) {
29
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
- const fileName = (0, devkit_1.names)(options.name).fileName;
31
- const workspace = (0, devkit_1.getProjects)(host);
32
- let baseDir;
33
- if (options.directory) {
34
- baseDir = options.directory;
35
- }
36
- else {
37
- baseDir =
38
- workspace.get(options.project).projectType === 'application'
39
- ? 'app'
40
- : 'lib';
41
- }
42
- return options.flat ? baseDir : (0, devkit_1.joinPathFragments)(baseDir, fileName);
43
- });
29
+ async function getDirectory(host, options) {
30
+ const fileName = (0, devkit_1.names)(options.name).fileName;
31
+ const workspace = (0, devkit_1.getProjects)(host);
32
+ let baseDir;
33
+ if (options.directory) {
34
+ baseDir = options.directory;
35
+ }
36
+ else {
37
+ baseDir =
38
+ workspace.get(options.project).projectType === 'application'
39
+ ? 'app'
40
+ : 'lib';
41
+ }
42
+ return options.flat ? baseDir : (0, devkit_1.joinPathFragments)(baseDir, fileName);
44
43
  }
45
44
  function assertValidOptions(options) {
46
45
  const slashes = ['/', '\\'];
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentStorySchematic = exports.componentStoryGenerator = exports.findPropsAndGenerateFile = exports.createComponentStoriesFile = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const ast_utils_1 = require("@nx/react/src/utils/ast-utils");
7
6
  const component_props_1 = require("@nx/react/src/utils/component-props");
@@ -37,7 +36,7 @@ function createComponentStoriesFile(host, { project, componentPath }) {
37
36
  const cmpDeclaration = (0, ast_utils_1.getComponentNode)(sourceFile);
38
37
  if (!cmpDeclaration) {
39
38
  const componentNodes = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile);
40
- if (componentNodes === null || componentNodes === void 0 ? void 0 : componentNodes.length) {
39
+ if (componentNodes?.length) {
41
40
  componentNodes.forEach((declaration) => {
42
41
  findPropsAndGenerateFile(host, sourceFile, declaration, componentDirectory, name, isPlainJs, fileExt, componentNodes.length > 1);
43
42
  });
@@ -67,13 +66,11 @@ function findPropsAndGenerateFile(host, sourceFile, cmpDeclaration, componentDir
67
66
  });
68
67
  }
69
68
  exports.findPropsAndGenerateFile = findPropsAndGenerateFile;
70
- function componentStoryGenerator(host, schema) {
71
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
72
- createComponentStoriesFile(host, schema);
73
- if (!schema.skipFormat) {
74
- yield (0, devkit_1.formatFiles)(host);
75
- }
76
- });
69
+ async function componentStoryGenerator(host, schema) {
70
+ createComponentStoriesFile(host, schema);
71
+ if (!schema.skipFormat) {
72
+ await (0, devkit_1.formatFiles)(host);
73
+ }
77
74
  }
78
75
  exports.componentStoryGenerator = componentStoryGenerator;
79
76
  exports.default = componentStoryGenerator;
@@ -9,9 +9,8 @@ import componentGenerator from '../component/component';
9
9
 
10
10
  describe('react-native:component-story', () => {
11
11
  let appTree: Tree;
12
- let cmpPath = 'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx';
13
- let storyFilePath =
14
- 'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx';
12
+ let cmpPath = 'test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx';
13
+ let storyFilePath = 'test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx';
15
14
 
16
15
  describe('default setup', () => {
17
16
  beforeEach(async () => {
@@ -34,7 +33,7 @@ describe('react-native:component-story', () => {
34
33
  });
35
34
  } catch (e) {
36
35
  expect(e.message).toContain(
37
- 'Could not find any React Native component in file libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx'
36
+ 'Could not find any React Native component in file test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx'
38
37
  );
39
38
  }
40
39
  });
@@ -70,11 +69,11 @@ describe('react-native:component-story', () => {
70
69
 
71
70
  describe('when using plain JS components', () => {
72
71
  let storyFilePathPlain =
73
- 'libs/test-ui-lib/src/lib/test-ui-libplain.stories.jsx';
72
+ 'test-ui-lib/src/lib/test-ui-libplain.stories.jsx';
74
73
 
75
74
  beforeEach(async () => {
76
75
  appTree.write(
77
- 'libs/test-ui-lib/src/lib/test-ui-libplain.jsx',
76
+ 'test-ui-lib/src/lib/test-ui-libplain.jsx',
78
77
  `import React from 'react';
79
78
 
80
79
  import './test.scss';
@@ -400,7 +399,7 @@ describe('react-native:component-story', () => {
400
399
  });
401
400
 
402
401
  export async function createTestUILib(libName: string): Promise<Tree> {
403
- let appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
402
+ let appTree = createTreeWithEmptyWorkspace();
404
403
  appTree.write('.gitignore', '');
405
404
 
406
405
  await libraryGenerator(appTree, {
@@ -409,6 +408,7 @@ export async function createTestUILib(libName: string): Promise<Tree> {
409
408
  skipFormat: true,
410
409
  skipTsConfig: false,
411
410
  unitTestRunner: 'jest',
411
+ projectNameAndRootFormat: 'as-provided',
412
412
  });
413
413
 
414
414
  await componentGenerator(appTree, {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeInitSchematic = exports.updateDependencies = exports.reactNativeInitGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const jest_1 = require("@nx/jest");
7
6
  const detox_1 = require("@nx/detox");
@@ -9,29 +8,33 @@ const versions_1 = require("@nx/react/src/utils/versions");
9
8
  const js_1 = require("@nx/js");
10
9
  const versions_2 = require("../../utils/versions");
11
10
  const add_git_ignore_entry_1 = require("./lib/add-git-ignore-entry");
12
- function reactNativeInitGenerator(host, schema) {
13
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
- (0, add_git_ignore_entry_1.addGitIgnoreEntry)(host);
15
- const tasks = [];
16
- tasks.push(yield (0, js_1.initGenerator)(host, Object.assign(Object.assign({}, schema), { skipFormat: true })));
17
- if (!schema.skipPackageJson) {
18
- const installTask = updateDependencies(host);
19
- tasks.push(moveDependency(host));
20
- tasks.push(installTask);
21
- }
22
- if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
23
- const jestTask = yield (0, jest_1.jestInitGenerator)(host, schema);
24
- tasks.push(jestTask);
25
- }
26
- if (!schema.e2eTestRunner || schema.e2eTestRunner === 'detox') {
27
- const detoxTask = yield (0, detox_1.detoxInitGenerator)(host, Object.assign(Object.assign({}, schema), { skipFormat: true }));
28
- tasks.push(detoxTask);
29
- }
30
- if (!schema.skipFormat) {
31
- yield (0, devkit_1.formatFiles)(host);
32
- }
33
- return (0, devkit_1.runTasksInSerial)(...tasks);
34
- });
11
+ async function reactNativeInitGenerator(host, schema) {
12
+ (0, add_git_ignore_entry_1.addGitIgnoreEntry)(host);
13
+ const tasks = [];
14
+ tasks.push(await (0, js_1.initGenerator)(host, {
15
+ ...schema,
16
+ skipFormat: true,
17
+ }));
18
+ if (!schema.skipPackageJson) {
19
+ const installTask = updateDependencies(host);
20
+ tasks.push(moveDependency(host));
21
+ tasks.push(installTask);
22
+ }
23
+ if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
24
+ const jestTask = await (0, jest_1.jestInitGenerator)(host, schema);
25
+ tasks.push(jestTask);
26
+ }
27
+ if (!schema.e2eTestRunner || schema.e2eTestRunner === 'detox') {
28
+ const detoxTask = await (0, detox_1.detoxInitGenerator)(host, {
29
+ ...schema,
30
+ skipFormat: true,
31
+ });
32
+ tasks.push(detoxTask);
33
+ }
34
+ if (!schema.skipFormat) {
35
+ await (0, devkit_1.formatFiles)(host);
36
+ }
37
+ return (0, devkit_1.runTasksInSerial)(...tasks);
35
38
  }
36
39
  exports.reactNativeInitGenerator = reactNativeInitGenerator;
37
40
  function updateDependencies(host) {
@@ -40,11 +43,35 @@ function updateDependencies(host) {
40
43
  react: versions_2.reactVersion,
41
44
  'react-dom': versions_2.reactDomVersion,
42
45
  'react-native': versions_2.reactNativeVersion,
43
- }, Object.assign({ '@nx/react-native': versions_2.nxVersion, '@types/node': versions_2.typesNodeVersion, '@types/react': versions_2.typesReactVersion, '@types/react-native': versions_2.typesReactNativeVersion, '@react-native/metro-config': versions_2.reactNativeMetroConfigVersion, '@react-native-community/cli': versions_2.reactNativeCommunityCli, '@react-native-community/cli-platform-android': versions_2.reactNativeCommunityCliAndroid, '@react-native-community/cli-platform-ios': versions_2.reactNativeCommunityCliIos, '@testing-library/react-native': versions_2.testingLibraryReactNativeVersion, '@testing-library/jest-native': versions_2.testingLibraryJestNativeVersion, 'jest-react-native': versions_2.jestReactNativeVersion, metro: versions_2.metroVersion, 'metro-config': versions_2.metroVersion, 'metro-resolver': versions_2.metroVersion, 'metro-babel-register': versions_2.metroVersion, 'metro-react-native-babel-preset': versions_2.metroVersion, 'metro-react-native-babel-transformer': versions_2.metroVersion, 'react-test-renderer': versions_2.reactTestRendererVersion, 'react-native-svg-transformer': versions_2.reactNativeSvgTransformerVersion, 'react-native-svg': versions_2.reactNativeSvgVersion, '@babel/preset-react': versions_1.babelPresetReactVersion, '@babel/core': versions_1.babelCoreVersion }, (isPnpm
44
- ? {
45
- '@babel/runtime': versions_2.babelRuntimeVersion, // @babel/runtime is used by react-native-svg
46
- }
47
- : {})));
46
+ }, {
47
+ '@nx/react-native': versions_2.nxVersion,
48
+ '@types/node': versions_2.typesNodeVersion,
49
+ '@types/react': versions_2.typesReactVersion,
50
+ '@types/react-native': versions_2.typesReactNativeVersion,
51
+ '@react-native/metro-config': versions_2.reactNativeMetroConfigVersion,
52
+ '@react-native-community/cli': versions_2.reactNativeCommunityCli,
53
+ '@react-native-community/cli-platform-android': versions_2.reactNativeCommunityCliAndroid,
54
+ '@react-native-community/cli-platform-ios': versions_2.reactNativeCommunityCliIos,
55
+ '@testing-library/react-native': versions_2.testingLibraryReactNativeVersion,
56
+ '@testing-library/jest-native': versions_2.testingLibraryJestNativeVersion,
57
+ 'jest-react-native': versions_2.jestReactNativeVersion,
58
+ metro: versions_2.metroVersion,
59
+ 'metro-config': versions_2.metroVersion,
60
+ 'metro-resolver': versions_2.metroVersion,
61
+ 'metro-babel-register': versions_2.metroVersion,
62
+ 'metro-react-native-babel-preset': versions_2.metroVersion,
63
+ 'metro-react-native-babel-transformer': versions_2.metroVersion,
64
+ 'react-test-renderer': versions_2.reactTestRendererVersion,
65
+ 'react-native-svg-transformer': versions_2.reactNativeSvgTransformerVersion,
66
+ 'react-native-svg': versions_2.reactNativeSvgVersion,
67
+ '@babel/preset-react': versions_1.babelPresetReactVersion,
68
+ '@babel/core': versions_1.babelCoreVersion,
69
+ ...(isPnpm
70
+ ? {
71
+ '@babel/runtime': versions_2.babelRuntimeVersion, // @babel/runtime is used by react-native-svg
72
+ }
73
+ : {}),
74
+ });
48
75
  }
49
76
  exports.updateDependencies = updateDependencies;
50
77
  function moveDependency(host) {
@@ -7,7 +7,7 @@ describe('init', () => {
7
7
  let tree: Tree;
8
8
 
9
9
  beforeEach(() => {
10
- tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
10
+ tree = createTreeWithEmptyWorkspace();
11
11
  tree.write('.gitignore', '');
12
12
  });
13
13
 
@@ -1,25 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
- function normalizeOptions(host, options) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- const { projectName, names: projectNames, projectRoot, importPath, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
9
- name: options.name,
10
- projectType: 'library',
11
- directory: options.directory,
12
- importPath: options.importPath,
13
- projectNameAndRootFormat: options.projectNameAndRootFormat,
14
- callingGenerator: '@nx/react-native:library',
15
- });
16
- const parsedTags = options.tags
17
- ? options.tags.split(',').map((s) => s.trim())
18
- : [];
19
- const normalized = Object.assign(Object.assign({}, options), { fileName: projectName, routePath: `/${projectNames.projectSimpleName}`, name: projectName, projectRoot,
20
- parsedTags,
21
- importPath });
22
- return normalized;
5
+ async function normalizeOptions(host, options) {
6
+ const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
7
+ name: options.name,
8
+ projectType: 'library',
9
+ directory: options.directory,
10
+ importPath: options.importPath,
11
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
12
+ callingGenerator: '@nx/react-native:library',
23
13
  });
14
+ const parsedTags = options.tags
15
+ ? options.tags.split(',').map((s) => s.trim())
16
+ : [];
17
+ const normalized = {
18
+ ...options,
19
+ fileName: projectName,
20
+ routePath: `/${projectNames.projectSimpleName}`,
21
+ name: projectName,
22
+ projectRoot,
23
+ parsedTags,
24
+ importPath,
25
+ };
26
+ return normalized;
24
27
  }
25
28
  exports.normalizeOptions = normalizeOptions;