@nx/react-native 16.8.0-beta.4 → 16.8.0-beta.6

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
@@ -27,14 +27,10 @@ describe('react-native:stories for libraries', () => {
27
27
  });
28
28
 
29
29
  expect(
30
- appTree.exists(
31
- 'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx'
32
- )
30
+ appTree.exists('test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx')
33
31
  ).toBeTruthy();
34
32
  expect(
35
- appTree.exists(
36
- 'libs/test-ui-lib/src/lib/another-cmp/another-cmp.stories.tsx'
37
- )
33
+ appTree.exists('test-ui-lib/src/lib/another-cmp/another-cmp.stories.tsx')
38
34
  ).toBeTruthy();
39
35
  });
40
36
 
@@ -49,18 +45,14 @@ describe('react-native:stories for libraries', () => {
49
45
  });
50
46
  await storiesGenerator(appTree, {
51
47
  project: 'test-ui-lib',
52
- ignorePaths: ['libs/test-ui-lib/src/lib/another-cmp/**'],
48
+ ignorePaths: ['test-ui-lib/src/lib/another-cmp/**'],
53
49
  });
54
50
 
55
51
  expect(
56
- appTree.exists(
57
- 'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx'
58
- )
52
+ appTree.exists('test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx')
59
53
  ).toBeTruthy();
60
54
  expect(
61
- appTree.exists(
62
- 'libs/test-ui-lib/src/lib/another-cmp/another-cmp.stories.tsx'
63
- )
55
+ appTree.exists('test-ui-lib/src/lib/another-cmp/another-cmp.stories.tsx')
64
56
  ).toBeFalsy();
65
57
  });
66
58
 
@@ -71,7 +63,7 @@ describe('react-native:stories for libraries', () => {
71
63
  });
72
64
  // create another component
73
65
  appTree.write(
74
- 'libs/test-ui-lib/src/lib/some-command-line-utils.ts',
66
+ 'test-ui-lib/src/lib/some-command-line-utils.ts',
75
67
  `export const add = (a: number, b: number) => a + b;`
76
68
  );
77
69
 
@@ -82,15 +74,13 @@ describe('react-native:stories for libraries', () => {
82
74
  // should just create the story and not error, even though there's a js file
83
75
  // not containing any react component
84
76
  expect(
85
- appTree.exists(
86
- 'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx'
87
- )
77
+ appTree.exists('test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx')
88
78
  ).toBeTruthy();
89
79
  });
90
80
  });
91
81
 
92
82
  export async function createTestUILib(libName: string): Promise<Tree> {
93
- let appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
83
+ let appTree = createTreeWithEmptyWorkspace();
94
84
  appTree.write('.gitignore', '');
95
85
 
96
86
  await libraryGenerator(appTree, {
@@ -99,6 +89,7 @@ export async function createTestUILib(libName: string): Promise<Tree> {
99
89
  skipTsConfig: false,
100
90
  unitTestRunner: 'none',
101
91
  name: libName,
92
+ projectNameAndRootFormat: 'as-provided',
102
93
  });
103
94
 
104
95
  await applicationGenerator(appTree, {
@@ -108,6 +99,7 @@ export async function createTestUILib(libName: string): Promise<Tree> {
108
99
  unitTestRunner: 'none',
109
100
  name: `${libName}-e2e`,
110
101
  install: false,
102
+ projectNameAndRootFormat: 'as-provided',
111
103
  });
112
104
  return appTree;
113
105
  }
@@ -1,61 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.storiesSchematic = exports.storiesGenerator = exports.createAllStories = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const path_1 = require("path");
7
6
  const component_story_1 = require("../component-story/component-story");
8
7
  const stories_1 = require("@nx/react/src/generators/stories/stories");
9
8
  const minimatch = require("minimatch");
10
9
  const versions_1 = require("../../utils/versions");
11
- function createAllStories(tree, projectName, ignorePaths) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
14
- const { isTheFileAStory } = yield Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
15
- const projects = (0, devkit_1.getProjects)(tree);
16
- const projectConfiguration = projects.get(projectName);
17
- const { sourceRoot } = projectConfiguration;
18
- const projectPath = yield (0, stories_1.projectRootPath)(tree, projectConfiguration);
19
- let componentPaths = [];
20
- (0, devkit_1.visitNotIgnoredFiles)(tree, projectPath, (path) => {
21
- if (ignorePaths === null || ignorePaths === void 0 ? void 0 : ignorePaths.some((pattern) => minimatch(path, pattern)))
22
- return;
23
- if ((path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
24
- (path.endsWith('.js') && !path.endsWith('.spec.js')) ||
25
- (path.endsWith('.jsx') && !path.endsWith('.spec.jsx'))) {
26
- // Check if file is NOT a story (either ts/tsx or js/jsx)
27
- if (!isTheFileAStory(tree, path)) {
28
- // Since the file is not a story
29
- // Let's see if the .stories.* file exists
30
- const ext = path.slice(path.lastIndexOf('.'));
31
- const storyPath = `${path.split(ext)[0]}.stories${ext}`;
32
- if (!tree.exists(storyPath)) {
33
- componentPaths.push(path);
34
- }
10
+ async function createAllStories(tree, projectName, ignorePaths) {
11
+ (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
12
+ const { isTheFileAStory } = await Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
13
+ const projects = (0, devkit_1.getProjects)(tree);
14
+ const projectConfiguration = projects.get(projectName);
15
+ const { sourceRoot } = projectConfiguration;
16
+ const projectPath = await (0, stories_1.projectRootPath)(tree, projectConfiguration);
17
+ let componentPaths = [];
18
+ (0, devkit_1.visitNotIgnoredFiles)(tree, projectPath, (path) => {
19
+ if (ignorePaths?.some((pattern) => minimatch(path, pattern)))
20
+ return;
21
+ if ((path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
22
+ (path.endsWith('.js') && !path.endsWith('.spec.js')) ||
23
+ (path.endsWith('.jsx') && !path.endsWith('.spec.jsx'))) {
24
+ // Check if file is NOT a story (either ts/tsx or js/jsx)
25
+ if (!isTheFileAStory(tree, path)) {
26
+ // Since the file is not a story
27
+ // Let's see if the .stories.* file exists
28
+ const ext = path.slice(path.lastIndexOf('.'));
29
+ const storyPath = `${path.split(ext)[0]}.stories${ext}`;
30
+ if (!tree.exists(storyPath)) {
31
+ componentPaths.push(path);
35
32
  }
36
33
  }
37
- });
38
- yield Promise.all(componentPaths.map((componentPath) => tslib_1.__awaiter(this, void 0, void 0, function* () {
39
- const relativeCmpDir = componentPath.replace((0, path_1.join)(sourceRoot, '/'), '');
40
- if (!(0, stories_1.containsComponentDeclaration)(tree, componentPath)) {
41
- return;
42
- }
43
- yield (0, component_story_1.default)(tree, {
44
- componentPath: relativeCmpDir,
45
- project: projectName,
46
- skipFormat: true,
47
- });
48
- })));
34
+ }
49
35
  });
36
+ await Promise.all(componentPaths.map(async (componentPath) => {
37
+ const relativeCmpDir = componentPath.replace((0, path_1.join)(sourceRoot, '/'), '');
38
+ if (!(0, stories_1.containsComponentDeclaration)(tree, componentPath)) {
39
+ return;
40
+ }
41
+ await (0, component_story_1.default)(tree, {
42
+ componentPath: relativeCmpDir,
43
+ project: projectName,
44
+ skipFormat: true,
45
+ });
46
+ }));
50
47
  }
51
48
  exports.createAllStories = createAllStories;
52
- function storiesGenerator(host, schema) {
53
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
54
- yield createAllStories(host, schema.project, schema.ignorePaths);
55
- if (!schema.skipFormat) {
56
- yield (0, devkit_1.formatFiles)(host);
57
- }
58
- });
49
+ async function storiesGenerator(host, schema) {
50
+ await createAllStories(host, schema.project, schema.ignorePaths);
51
+ if (!schema.skipFormat) {
52
+ await (0, devkit_1.formatFiles)(host);
53
+ }
59
54
  }
60
55
  exports.storiesGenerator = storiesGenerator;
61
56
  exports.default = storiesGenerator;
@@ -1,49 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.storybookConfigurationSchematic = exports.storybookConfigurationGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const versions_1 = require("../../utils/versions");
7
6
  const stories_1 = require("../stories/stories");
8
7
  const add_resolver_main_fields_to_metro_config_1 = require("./lib/add-resolver-main-fields-to-metro-config");
9
8
  const create_storybook_files_1 = require("./lib/create-storybook-files");
10
9
  const replace_app_import_with_storybook_toggle_1 = require("./lib/replace-app-import-with-storybook-toggle");
11
- function generateStories(host, schema) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- yield (0, stories_1.default)(host, {
14
- project: schema.name,
15
- ignorePaths: schema.ignorePaths,
16
- skipFormat: true,
17
- });
10
+ async function generateStories(host, schema) {
11
+ await (0, stories_1.default)(host, {
12
+ project: schema.name,
13
+ ignorePaths: schema.ignorePaths,
14
+ skipFormat: true,
18
15
  });
19
16
  }
20
- function storybookConfigurationGenerator(host, schema) {
21
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
22
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
23
- const installTask = yield configurationGenerator(host, {
24
- name: schema.name,
25
- uiFramework: '@storybook/react-native',
26
- configureCypress: false,
27
- js: false,
28
- linter: schema.linter,
29
- standaloneConfig: schema.standaloneConfig,
30
- tsConfiguration: schema.tsConfiguration,
31
- skipFormat: true,
32
- });
33
- const installRequiredPackagesTask = yield (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
34
- '@react-native-async-storage/async-storage': versions_1.reactNativeAsyncStorageVersion,
35
- 'react-native-safe-area-context': versions_1.reactNativeSafeAreaContextVersion,
36
- });
37
- addStorybookTask(host, schema.name);
38
- (0, create_storybook_files_1.createStorybookFiles)(host, schema);
39
- (0, replace_app_import_with_storybook_toggle_1.replaceAppImportWithStorybookToggle)(host, schema);
40
- (0, add_resolver_main_fields_to_metro_config_1.addResolverMainFieldsToMetroConfig)(host, schema);
41
- if (schema.generateStories) {
42
- yield generateStories(host, schema);
43
- }
44
- yield (0, devkit_1.formatFiles)(host);
45
- return (0, devkit_1.runTasksInSerial)(installTask, installRequiredPackagesTask);
17
+ async function storybookConfigurationGenerator(host, schema) {
18
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
19
+ const installTask = await configurationGenerator(host, {
20
+ name: schema.name,
21
+ uiFramework: '@storybook/react-native',
22
+ configureCypress: false,
23
+ js: false,
24
+ linter: schema.linter,
25
+ standaloneConfig: schema.standaloneConfig,
26
+ tsConfiguration: schema.tsConfiguration,
27
+ skipFormat: true,
46
28
  });
29
+ const installRequiredPackagesTask = await (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
30
+ '@react-native-async-storage/async-storage': versions_1.reactNativeAsyncStorageVersion,
31
+ 'react-native-safe-area-context': versions_1.reactNativeSafeAreaContextVersion,
32
+ });
33
+ addStorybookTask(host, schema.name);
34
+ (0, create_storybook_files_1.createStorybookFiles)(host, schema);
35
+ (0, replace_app_import_with_storybook_toggle_1.replaceAppImportWithStorybookToggle)(host, schema);
36
+ (0, add_resolver_main_fields_to_metro_config_1.addResolverMainFieldsToMetroConfig)(host, schema);
37
+ if (schema.generateStories) {
38
+ await generateStories(host, schema);
39
+ }
40
+ await (0, devkit_1.formatFiles)(host);
41
+ return (0, devkit_1.runTasksInSerial)(installTask, installRequiredPackagesTask);
47
42
  }
48
43
  exports.storybookConfigurationGenerator = storybookConfigurationGenerator;
49
44
  function addStorybookTask(host, projectName) {
@@ -36,11 +36,9 @@ describe('react-native:storybook-configuration', () => {
36
36
  name: 'test-ui-lib',
37
37
  });
38
38
 
39
+ expect(appTree.exists('test-ui-lib/.storybook/main.js')).toBeTruthy();
39
40
  expect(
40
- appTree.exists('libs/test-ui-lib/.storybook/main.js')
41
- ).toBeTruthy();
42
- expect(
43
- appTree.exists('libs/test-ui-lib/tsconfig.storybook.json')
41
+ appTree.exists('test-ui-lib/tsconfig.storybook.json')
44
42
  ).toBeTruthy();
45
43
  });
46
44
 
@@ -57,7 +55,7 @@ describe('react-native:storybook-configuration', () => {
57
55
 
58
56
  expect(
59
57
  appTree.exists(
60
- 'libs/test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx'
58
+ 'test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx'
61
59
  )
62
60
  ).toBeTruthy();
63
61
  });
@@ -70,11 +68,9 @@ describe('react-native:storybook-configuration', () => {
70
68
  name: 'test-ui-app',
71
69
  });
72
70
 
71
+ expect(appTree.exists('test-ui-app/.storybook/main.js')).toBeTruthy();
73
72
  expect(
74
- appTree.exists('apps/test-ui-app/.storybook/main.js')
75
- ).toBeTruthy();
76
- expect(
77
- appTree.exists('apps/test-ui-app/tsconfig.storybook.json')
73
+ appTree.exists('test-ui-app/tsconfig.storybook.json')
78
74
  ).toBeTruthy();
79
75
  });
80
76
 
@@ -90,7 +86,7 @@ describe('react-native:storybook-configuration', () => {
90
86
  // under the specified 'lib' directory
91
87
  expect(
92
88
  appTree.exists(
93
- 'apps/test-ui-app/src/app/my-component/my-component.stories.tsx'
89
+ 'test-ui-app/src/app/my-component/my-component.stories.tsx'
94
90
  )
95
91
  ).toBeTruthy();
96
92
  });
@@ -98,7 +94,7 @@ describe('react-native:storybook-configuration', () => {
98
94
  });
99
95
 
100
96
  export async function createTestUILib(libName: string): Promise<Tree> {
101
- let appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
97
+ let appTree = createTreeWithEmptyWorkspace();
102
98
 
103
99
  await libraryGenerator(appTree, {
104
100
  linter: Linter.EsLint,
@@ -106,6 +102,7 @@ export async function createTestUILib(libName: string): Promise<Tree> {
106
102
  skipTsConfig: false,
107
103
  unitTestRunner: 'none',
108
104
  name: libName,
105
+ projectNameAndRootFormat: 'as-provided',
109
106
  });
110
107
  return appTree;
111
108
  }
@@ -114,7 +111,7 @@ export async function createTestAppLib(
114
111
  libName: string,
115
112
  plainJS = false
116
113
  ): Promise<Tree> {
117
- let appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
114
+ let appTree = createTreeWithEmptyWorkspace();
118
115
 
119
116
  await applicationGenerator(appTree, {
120
117
  e2eTestRunner: 'none',
@@ -125,6 +122,7 @@ export async function createTestAppLib(
125
122
  name: libName,
126
123
  js: plainJS,
127
124
  install: false,
125
+ projectNameAndRootFormat: 'as-provided',
128
126
  });
129
127
 
130
128
  await componentGenerator(appTree, {
@@ -18,7 +18,7 @@ function addResolverMainFieldsToMetroConfig(host, schema) {
18
18
  }
19
19
  host.write(metroConfigPath, metroConfigContent.replace(/},\s+resolver: {/, `},resolver: { resolverMainFields: ['sbmodern', 'browser', 'main'],`));
20
20
  }
21
- catch (_a) {
21
+ catch {
22
22
  devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update ${metroConfigPath} for project ${root}.`);
23
23
  }
24
24
  }
@@ -9,17 +9,17 @@ describe('addResolverMainFieldsToMetroConfig', () => {
9
9
  let tree: Tree;
10
10
 
11
11
  beforeEach(() => {
12
- tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
12
+ tree = createTreeWithEmptyWorkspace();
13
13
 
14
14
  addProjectConfiguration(tree, 'products', {
15
- root: 'apps/products',
16
- sourceRoot: 'apps/products/src',
15
+ root: 'products',
16
+ sourceRoot: 'products/src',
17
17
  });
18
18
  });
19
19
 
20
20
  it(`should update metro.config.js and add key projectRoot`, async () => {
21
21
  tree.write(
22
- 'apps/products/metro.config.js',
22
+ 'products/metro.config.js',
23
23
  formatFile`
24
24
  const { withNxMetro } = require('@nx/react-native');
25
25
  const { getDefaultConfig } = require('metro-config');
@@ -55,7 +55,7 @@ module.exports = (async () => {
55
55
  });
56
56
 
57
57
  expect(
58
- formatFile`${tree.read('apps/products/metro.config.js', 'utf-8')}`
58
+ formatFile`${tree.read('products/metro.config.js', 'utf-8')}`
59
59
  ).toEqual(
60
60
  formatFile`
61
61
  const { withNxMetro } = require('@nx/react-native');
@@ -91,7 +91,7 @@ module.exports = (async () => {
91
91
 
92
92
  it(`should not udpate metro.config.js if projectRoot already exists`, async () => {
93
93
  tree.write(
94
- 'apps/products/metro.config.js',
94
+ 'products/metro.config.js',
95
95
  `
96
96
  const { withNxMetro } = require('@nx/react-native');
97
97
  const { getDefaultConfig } = require('metro-config');
@@ -126,7 +126,7 @@ module.exports = (async () => {
126
126
  name: 'products',
127
127
  });
128
128
 
129
- expect(tree.read('apps/products/metro.config.js', 'utf-8')).toEqual(
129
+ expect(tree.read('products/metro.config.js', 'utf-8')).toEqual(
130
130
  `
131
131
  const { withNxMetro } = require('@nx/react-native');
132
132
  const { getDefaultConfig } = require('metro-config');
@@ -1,46 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createStorybookFiles = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const path_1 = require("path");
7
6
  const chalk = require("chalk");
8
7
  /**
9
8
  * This function generate ./storybook under project root.
10
9
  */
11
- function createStorybookFiles(host, schema) {
12
- var _a, _b, _c, _d;
13
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
- const { root, projectType, targets, sourceRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.name);
15
- // do not proceed if not a react native project
16
- if (((_a = targets === null || targets === void 0 ? void 0 : targets.start) === null || _a === void 0 ? void 0 : _a.executor) !== '@nx/react-native:start' &&
17
- ((_b = targets === null || targets === void 0 ? void 0 : targets.start) === null || _b === void 0 ? void 0 : _b.executor) !== '@nx/expo:start' &&
18
- ((_c = targets === null || targets === void 0 ? void 0 : targets.start) === null || _c === void 0 ? void 0 : _c.executor) !== '@nrwl/react-native:start' &&
19
- ((_d = targets === null || targets === void 0 ? void 0 : targets.start) === null || _d === void 0 ? void 0 : _d.executor) !== '@nrwl/expo:start') {
20
- devkit_1.logger.error(`Unable to add storybook to ${schema.name}. It is not a Nx React Native / Expo project.`);
21
- return;
22
- }
23
- const storybookUIFileName = schema.js ? 'storybook.js' : 'storybook.ts';
24
- const storybookUIFilePath = (0, path_1.join)(root, `./${storybookUIFileName}`);
25
- if (host.exists(storybookUIFilePath)) {
26
- devkit_1.logger.warn(`${storybookUIFileName} file already exists for ${projectType} ${schema.name}! Skipping generating this file.`);
27
- return;
28
- }
29
- if (projectType !== 'application') {
30
- devkit_1.logger.info(`${chalk.bold.cyan('info')} To see your Storybook stories on the device, you should start your mobile app for the <platform> of your choice (typically ios or android).`);
31
- }
32
- // copy files to app's .storybook folder
33
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app'), (0, path_1.join)(root, 'src', 'storybook'), {
34
- tmpl: '',
35
- offsetFromRoot: (0, devkit_1.offsetFromRoot)(sourceRoot),
36
- });
37
- // copy files to workspace root's .storybook folder
38
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/root'), (0, path_1.join)(root, (0, devkit_1.offsetFromRoot)(root), '.storybook'), {
39
- tmpl: '',
40
- });
41
- if (schema.js) {
42
- (0, devkit_1.toJS)(host);
43
- }
10
+ async function createStorybookFiles(host, schema) {
11
+ const { root, projectType, targets, sourceRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.name);
12
+ // do not proceed if not a react native project
13
+ if (targets?.start?.executor !== '@nx/react-native:start' &&
14
+ targets?.start?.executor !== '@nx/expo:start' &&
15
+ targets?.start?.executor !== '@nrwl/react-native:start' &&
16
+ targets?.start?.executor !== '@nrwl/expo:start') {
17
+ devkit_1.logger.error(`Unable to add storybook to ${schema.name}. It is not a Nx React Native / Expo project.`);
18
+ return;
19
+ }
20
+ const storybookUIFileName = schema.js ? 'storybook.js' : 'storybook.ts';
21
+ const storybookUIFilePath = (0, path_1.join)(root, `./${storybookUIFileName}`);
22
+ if (host.exists(storybookUIFilePath)) {
23
+ devkit_1.logger.warn(`${storybookUIFileName} file already exists for ${projectType} ${schema.name}! Skipping generating this file.`);
24
+ return;
25
+ }
26
+ if (projectType !== 'application') {
27
+ devkit_1.logger.info(`${chalk.bold.cyan('info')} To see your Storybook stories on the device, you should start your mobile app for the <platform> of your choice (typically ios or android).`);
28
+ }
29
+ // copy files to app's .storybook folder
30
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/app'), (0, path_1.join)(root, 'src', 'storybook'), {
31
+ tmpl: '',
32
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(sourceRoot),
44
33
  });
34
+ // copy files to workspace root's .storybook folder
35
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/root'), (0, path_1.join)(root, (0, devkit_1.offsetFromRoot)(root), '.storybook'), {
36
+ tmpl: '',
37
+ });
38
+ if (schema.js) {
39
+ (0, devkit_1.toJS)(host);
40
+ }
45
41
  }
46
42
  exports.createStorybookFiles = createStorybookFiles;
@@ -22,7 +22,7 @@ function replaceAppImportWithStorybookToggle(host, schema) {
22
22
  }
23
23
  host.write(mainFilePath, contents.replace(appImportImport, storybookeToggleImport));
24
24
  }
25
- catch (_a) {
25
+ catch {
26
26
  devkit_1.logger.warn((0, devkit_1.stripIndents) `Unable to update import in ${mainFilePath} for project ${root}.`);
27
27
  }
28
28
  }
@@ -9,17 +9,17 @@ describe('replaceAppImportWithStorybookToggle', () => {
9
9
  let tree: Tree;
10
10
 
11
11
  beforeEach(() => {
12
- tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
12
+ tree = createTreeWithEmptyWorkspace();
13
13
 
14
14
  addProjectConfiguration(tree, 'products', {
15
- root: 'apps/products',
16
- sourceRoot: 'apps/products/src',
15
+ root: 'products',
16
+ sourceRoot: 'products/src',
17
17
  });
18
18
  });
19
19
 
20
20
  it('should update the main file with import from storybook', async () => {
21
21
  tree.write(
22
- '/apps/products/src/main.tsx',
22
+ 'products/src/main.tsx',
23
23
  formatFile`import { AppRegistry } from 'react-native';
24
24
  import App from './app/App';
25
25
 
@@ -31,7 +31,7 @@ describe('replaceAppImportWithStorybookToggle', () => {
31
31
  js: false,
32
32
  });
33
33
 
34
- const mainFile = tree.read('apps/products/src/main.tsx', 'utf-8');
34
+ const mainFile = tree.read('products/src/main.tsx', 'utf-8');
35
35
  expect(formatFile`${mainFile}`).toEqual(
36
36
  formatFile`import { AppRegistry } from 'react-native';
37
37
  import App from './storybook/toggle-storybook';
@@ -42,7 +42,7 @@ describe('replaceAppImportWithStorybookToggle', () => {
42
42
 
43
43
  it('should not update the main file if import is already updated', async () => {
44
44
  tree.write(
45
- '/apps/products/src/main.tsx',
45
+ 'products/src/main.tsx',
46
46
  formatFile`import { AppRegistry } from 'react-native';
47
47
  import App from './app/App';
48
48
 
@@ -54,7 +54,7 @@ describe('replaceAppImportWithStorybookToggle', () => {
54
54
  js: false,
55
55
  });
56
56
 
57
- const mainFile = tree.read('apps/products/src/main.tsx', 'utf-8');
57
+ const mainFile = tree.read('products/src/main.tsx', 'utf-8');
58
58
  expect(formatFile`${mainFile}`).toEqual(
59
59
  formatFile`import { AppRegistry } from 'react-native';
60
60
  import App from './storybook/toggle-storybook';
@@ -5,27 +5,24 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.reactNativeUpgradeNativeSchematic = exports.reactNativeUpgradeNativeGenerator = void 0;
8
- const tslib_1 = require("tslib");
9
8
  const devkit_1 = require("@nx/devkit");
10
9
  const fs_1 = require("fs");
11
10
  const pod_install_task_1 = require("../../utils/pod-install-task");
12
11
  const chmod_android_gradle_files_1 = require("../../utils/chmod-android-gradle-files");
13
12
  const create_native_files_1 = require("./lib/create-native-files");
14
- function reactNativeUpgradeNativeGenerator(host, schema) {
15
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
- const { projectType, root: appProjectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.name);
17
- const iosProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'ios');
18
- const androidProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'android');
19
- if (projectType !== 'application' ||
20
- !(0, fs_1.existsSync)(iosProjectRoot) ||
21
- !(0, fs_1.existsSync)(androidProjectRoot)) {
22
- throw new Error(`Could not upgrade React Native code for ${schema.name}`);
23
- }
24
- (0, create_native_files_1.createNativeFiles)(host, schema, appProjectRoot);
25
- const podInstallTask = (0, pod_install_task_1.runPodInstall)(iosProjectRoot, schema.install);
26
- const chmodTaskGradlew = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)(androidProjectRoot);
27
- return (0, devkit_1.runTasksInSerial)(podInstallTask, chmodTaskGradlew);
28
- });
13
+ async function reactNativeUpgradeNativeGenerator(host, schema) {
14
+ const { projectType, root: appProjectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.name);
15
+ const iosProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'ios');
16
+ const androidProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'android');
17
+ if (projectType !== 'application' ||
18
+ !(0, fs_1.existsSync)(iosProjectRoot) ||
19
+ !(0, fs_1.existsSync)(androidProjectRoot)) {
20
+ throw new Error(`Could not upgrade React Native code for ${schema.name}`);
21
+ }
22
+ (0, create_native_files_1.createNativeFiles)(host, schema, appProjectRoot);
23
+ const podInstallTask = (0, pod_install_task_1.runPodInstall)(iosProjectRoot, schema.install);
24
+ const chmodTaskGradlew = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)(androidProjectRoot);
25
+ return (0, devkit_1.runTasksInSerial)(podInstallTask, chmodTaskGradlew);
29
26
  }
30
27
  exports.reactNativeUpgradeNativeGenerator = reactNativeUpgradeNativeGenerator;
31
28
  exports.default = reactNativeUpgradeNativeGenerator;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  /**
6
5
  * Add support to display svg in react native:
@@ -8,19 +7,16 @@ const devkit_1 = require("@nx/devkit");
8
7
  * - Add typing to app's tsconfig.json.
9
8
  * - Add react-native-svg to app's package.json.
10
9
  */
11
- function update(tree) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- const projects = (0, devkit_1.getProjects)(tree);
14
- projects.forEach((project) => {
15
- var _a, _b;
16
- if (((_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.executor) !== '@nrwl/react-native:start')
17
- return;
18
- addReactNativeSvgToAppPackageJson(tree, project);
19
- addReactNativeSvgToTsconfig(tree, project);
20
- mockSvgInJestConfig(tree, project);
21
- });
22
- yield (0, devkit_1.formatFiles)(tree);
10
+ async function update(tree) {
11
+ const projects = (0, devkit_1.getProjects)(tree);
12
+ projects.forEach((project) => {
13
+ if (project.targets?.start?.executor !== '@nrwl/react-native:start')
14
+ return;
15
+ addReactNativeSvgToAppPackageJson(tree, project);
16
+ addReactNativeSvgToTsconfig(tree, project);
17
+ mockSvgInJestConfig(tree, project);
23
18
  });
19
+ await (0, devkit_1.formatFiles)(tree);
24
20
  }
25
21
  exports.default = update;
26
22
  function addReactNativeSvgToAppPackageJson(host, project) {
@@ -46,8 +42,7 @@ function addReactNativeSvgToTsconfig(host, project) {
46
42
  });
47
43
  }
48
44
  function mockSvgInJestConfig(host, project) {
49
- var _a, _b, _c;
50
- const jestConfigPath = (_c = (_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.test) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.jestConfig;
45
+ const jestConfigPath = project.targets?.test?.options?.jestConfig;
51
46
  if (!jestConfigPath || !host.exists(jestConfigPath))
52
47
  return;
53
48
  try {
@@ -56,7 +51,7 @@ function mockSvgInJestConfig(host, project) {
56
51
  return;
57
52
  host.write(jestConfigPath, contents.replace(/,([^,]*)$/, `, moduleNameMapper: {'\\.svg': '@nrwl/react-native/plugins/jest/svg-mock'}, $1`));
58
53
  }
59
- catch (_d) {
54
+ catch {
60
55
  devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update ${jestConfigPath} for project ${project.root}.`);
61
56
  }
62
57
  }