@nx/expo 17.0.2 → 17.0.4

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 (109) hide show
  1. package/.eslintrc.json +3 -0
  2. package/LICENSE +1 -1
  3. package/README.md +9 -4
  4. package/docs/export-examples.md +112 -0
  5. package/docs/start-examples.md +6 -0
  6. package/executors.json +5 -0
  7. package/generators.json +2 -2
  8. package/migrations.json +114 -6
  9. package/package.json +12 -16
  10. package/plugin.d.ts +1 -0
  11. package/plugin.js +6 -0
  12. package/plugins/metro-resolver.js +4 -1
  13. package/plugins/plugin.d.ts +14 -0
  14. package/plugins/plugin.js +150 -0
  15. package/plugins/with-nx-metro.js +6 -2
  16. package/plugins/with-nx-webpack.d.ts +1 -1
  17. package/plugins/with-nx-webpack.js +8 -4
  18. package/src/executors/build/build.impl.js +2 -1
  19. package/src/executors/build/schema.json +1 -1
  20. package/src/executors/build-list/build-list.impl.js +2 -3
  21. package/src/executors/build-list/schema.json +1 -1
  22. package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
  23. package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
  24. package/src/executors/ensure-symlink/schema.json +1 -1
  25. package/src/executors/export/export.impl.d.ts +1 -0
  26. package/src/executors/export/export.impl.js +25 -15
  27. package/src/executors/export/schema.d.ts +4 -2
  28. package/src/executors/export/schema.json +14 -13
  29. package/src/executors/install/install.impl.js +0 -2
  30. package/src/executors/install/schema.json +1 -1
  31. package/src/executors/prebuild/prebuild.impl.js +11 -5
  32. package/src/executors/prebuild/schema.json +2 -1
  33. package/src/executors/run/schema.json +1 -1
  34. package/src/executors/serve/lib/is-packager-running.d.ts +1 -0
  35. package/src/executors/serve/lib/is-packager-running.js +15 -0
  36. package/src/executors/serve/schema.d.ts +7 -0
  37. package/src/executors/serve/schema.json +35 -0
  38. package/src/executors/serve/serve.impl.d.ts +11 -0
  39. package/src/executors/serve/serve.impl.js +105 -0
  40. package/src/executors/start/schema.json +1 -1
  41. package/src/executors/start/start.impl.js +7 -1
  42. package/src/executors/submit/schema.json +1 -1
  43. package/src/executors/submit/submit.impl.js +2 -1
  44. package/src/executors/sync-deps/schema.d.ts +1 -0
  45. package/src/executors/sync-deps/schema.json +6 -1
  46. package/src/executors/sync-deps/sync-deps.impl.d.ts +4 -3
  47. package/src/executors/sync-deps/sync-deps.impl.js +33 -11
  48. package/src/executors/update/schema.json +1 -1
  49. package/src/executors/update/update.impl.js +7 -4
  50. package/src/generators/application/application.js +27 -7
  51. package/src/generators/application/files/app.json.template +2 -0
  52. package/src/generators/application/files/eas.json.template +0 -3
  53. package/src/generators/application/files/metro.config.js.template +1 -5
  54. package/src/generators/application/files/src/app/App.tsx.template +50 -13
  55. package/src/generators/application/files/webpack.config.js.template +57 -0
  56. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  57. package/src/generators/application/lib/add-e2e.js +86 -0
  58. package/src/generators/application/lib/add-project.js +20 -22
  59. package/src/generators/application/lib/create-application-files.js +0 -2
  60. package/src/generators/application/lib/normalize-options.d.ts +6 -0
  61. package/src/generators/application/lib/normalize-options.js +33 -1
  62. package/src/generators/application/schema.d.ts +2 -1
  63. package/src/generators/application/schema.json +4 -4
  64. package/src/generators/component/files/__fileName__.tsx.template +1 -1
  65. package/src/generators/component/schema.d.ts +3 -3
  66. package/src/generators/component/schema.json +4 -4
  67. package/src/generators/init/init.d.ts +3 -2
  68. package/src/generators/init/init.js +44 -40
  69. package/src/generators/init/schema.d.ts +3 -3
  70. package/src/generators/init/schema.json +11 -16
  71. package/src/generators/library/files/lib/.babelrc.js.template +21 -0
  72. package/src/generators/library/lib/normalize-options.js +5 -0
  73. package/src/generators/library/library.js +52 -38
  74. package/src/generators/library/schema.d.ts +1 -0
  75. package/src/generators/library/schema.json +2 -2
  76. package/src/migrations/update-16-6-0/update-metro-config.js +1 -5
  77. package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
  78. package/src/migrations/update-16-9-0/update-eas-cli-version.js +1 -2
  79. package/src/migrations/{update-16-1-4/add-detox-app-json.d.ts → update-18-0-0/change-outputDir-export-target.d.ts} +1 -1
  80. package/src/migrations/update-18-0-0/change-outputDir-export-target.js +25 -0
  81. package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
  82. package/src/migrations/update-18-0-0/remove-block-list.js +28 -0
  83. package/src/migrations/update-18-0-0/remove-eas-cli.d.ts +12 -0
  84. package/src/migrations/update-18-0-0/remove-eas-cli.js +18 -0
  85. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
  86. package/src/migrations/update-18-0-0/remove-symlink-target.js +29 -0
  87. package/src/utils/add-jest.d.ts +1 -1
  88. package/src/utils/add-jest.js +15 -5
  89. package/src/utils/add-linting.d.ts +1 -0
  90. package/src/utils/add-linting.js +1 -1
  91. package/src/utils/ensure-dependencies.d.ts +2 -0
  92. package/src/utils/ensure-dependencies.js +24 -0
  93. package/src/utils/find-all-npm-dependencies.js +4 -2
  94. package/src/utils/has-expo-plugin.d.ts +2 -0
  95. package/src/utils/has-expo-plugin.js +11 -0
  96. package/src/utils/resolve-eas.d.ts +1 -0
  97. package/src/utils/resolve-eas.js +36 -0
  98. package/src/utils/versions.d.ts +14 -15
  99. package/src/utils/versions.js +15 -16
  100. package/collection.json +0 -0
  101. package/src/generators/application/lib/add-detox.d.ts +0 -3
  102. package/src/generators/application/lib/add-detox.js +0 -24
  103. package/src/generators/library/files/lib/babel.config.json +0 -17
  104. package/src/migrations/update-16-1-4/add-detox-app-json.js +0 -29
  105. package/src/utils/symlink-task.d.ts +0 -2
  106. package/src/utils/symlink-task.js +0 -18
  107. /package/src/generators/application/files/{babel.config.js.template → .babelrc.js.template} +0 -0
  108. /package/src/{generators/init/lib → utils}/init-root-babel-config.d.ts +0 -0
  109. /package/src/{generators/init/lib → utils}/init-root-babel-config.js +0 -0
@@ -12,14 +12,40 @@ async function normalizeOptions(host, options) {
12
12
  callingGenerator: '@nx/expo:application',
13
13
  });
14
14
  options.projectNameAndRootFormat = projectNameAndRootFormat;
15
+ const nxJson = (0, devkit_1.readNxJson)(host);
16
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
+ nxJson.useInferencePlugins !== false;
18
+ options.addPlugin ??= addPluginDefault;
15
19
  const { className } = (0, devkit_1.names)(options.name);
16
20
  const parsedTags = options.tags
17
21
  ? options.tags.split(',').map((s) => s.trim())
18
22
  : [];
23
+ const rootProject = appProjectRoot === '.';
24
+ let e2eWebServerTarget = 'serve';
25
+ if (options.addPlugin) {
26
+ if (nxJson.plugins) {
27
+ for (const plugin of nxJson.plugins) {
28
+ if (typeof plugin === 'object' &&
29
+ plugin.plugin === '@nx/expo/plugin' &&
30
+ plugin.options.serveTargetName) {
31
+ e2eWebServerTarget = plugin.options
32
+ .serveTargetName;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ let e2ePort = options.addPlugin ? 8081 : 4200;
38
+ if (nxJson.targetDefaults?.[e2eWebServerTarget] &&
39
+ nxJson.targetDefaults?.[e2eWebServerTarget].options?.port) {
40
+ e2ePort = nxJson.targetDefaults?.[e2eWebServerTarget].options.port;
41
+ }
42
+ const e2eProjectName = rootProject ? 'e2e' : `${appProjectName}-e2e`;
43
+ const e2eProjectRoot = rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
44
+ const e2eWebServerAddress = `http://localhost:${e2ePort}`;
19
45
  return {
20
46
  ...options,
21
47
  unitTestRunner: options.unitTestRunner || 'jest',
22
- e2eTestRunner: options.e2eTestRunner || 'detox',
48
+ e2eTestRunner: options.e2eTestRunner,
23
49
  name: projectNames.projectSimpleName,
24
50
  className,
25
51
  lowerCaseName: className.toLowerCase(),
@@ -27,6 +53,12 @@ async function normalizeOptions(host, options) {
27
53
  projectName: appProjectName,
28
54
  appProjectRoot,
29
55
  parsedTags,
56
+ rootProject,
57
+ e2eProjectName,
58
+ e2eProjectRoot,
59
+ e2eWebServerAddress,
60
+ e2eWebServerTarget,
61
+ e2ePort,
30
62
  };
31
63
  }
32
64
  exports.normalizeOptions = normalizeOptions;
@@ -15,7 +15,8 @@ export interface Schema {
15
15
  js: boolean; // default is false
16
16
  linter: Linter; // default is eslint
17
17
  setParserOptionsProject?: boolean; // default is false
18
- e2eTestRunner: 'detox' | 'none'; // default is detox
18
+ e2eTestRunner: 'cypress' | 'playwright' | 'detox' | 'none'; // default is cypress
19
19
  standaloneConfig?: boolean;
20
20
  skipPackageJson?: boolean; // default is false
21
+ addPlugin?: boolean;
21
22
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxExpoApplication",
4
- "$schema": "http://json-schema.org/schema",
4
+ "$schema": "https://json-schema.org/schema",
5
5
  "description": "Create an Expo Application for Nx.",
6
6
  "examples": [
7
7
  {
@@ -48,7 +48,7 @@
48
48
  "linter": {
49
49
  "description": "The tool to use for running lint checks.",
50
50
  "type": "string",
51
- "enum": ["eslint"],
51
+ "enum": ["eslint", "none"],
52
52
  "default": "eslint"
53
53
  },
54
54
  "unitTestRunner": {
@@ -75,8 +75,8 @@
75
75
  "e2eTestRunner": {
76
76
  "description": "Adds the specified e2e test runner",
77
77
  "type": "string",
78
- "enum": ["detox", "none"],
79
- "default": "detox"
78
+ "enum": ["cypress", "playwright", "detox", "none"],
79
+ "default": "cypress"
80
80
  },
81
81
  "standaloneConfig": {
82
82
  "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
@@ -26,7 +26,7 @@ export function <%= className %>(props: <%= className %>Props) {
26
26
  <Text>Welcome to <%= name %>!</Text>
27
27
  </View>
28
28
  );
29
- };
29
+ }
30
30
  <% } %>
31
31
 
32
32
  export default <%= className %>;
@@ -4,21 +4,21 @@
4
4
  export interface Schema {
5
5
  name: string;
6
6
  /**
7
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18.
7
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19.
8
8
  */
9
9
  project: string;
10
10
  directory?: string;
11
11
  skipFormat: boolean; // default is false
12
12
  skipTests: boolean; // default is false
13
13
  /**
14
- * @deprecated Provide the name in pascal-case and use the `as-provided` format. This option will be removed in Nx v18.
14
+ * @deprecated Provide the name in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
15
15
  */
16
16
  export: boolean; // default is false
17
17
  pascalCaseFiles: boolean; // default is false
18
18
  classComponent: boolean; // default is false
19
19
  js: boolean; // default is false
20
20
  /**
21
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18.
21
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
22
22
  */
23
23
  flat: boolean; // default is false
24
24
  nameAndDirectoryFormat?: 'as-provided' | 'derived';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxExpoComponent",
4
- "$schema": "http://json-schema.org/schema",
4
+ "$schema": "https://json-schema.org/schema",
5
5
  "description": "Create a Expo Component for Nx.",
6
6
  "type": "object",
7
7
  "examples": [
@@ -22,7 +22,7 @@
22
22
  "$default": {
23
23
  "$source": "projectName"
24
24
  },
25
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
25
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19."
26
26
  },
27
27
  "name": {
28
28
  "type": "string",
@@ -63,7 +63,7 @@
63
63
  "type": "boolean",
64
64
  "description": "Create component at the source root rather than its own directory.",
65
65
  "default": false,
66
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18."
66
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
67
67
  },
68
68
  "export": {
69
69
  "type": "boolean",
@@ -77,7 +77,7 @@
77
77
  "description": "Use pascal case component file name (e.g. App.tsx).",
78
78
  "alias": "P",
79
79
  "default": false,
80
- "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v18."
80
+ "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
81
81
  },
82
82
  "classComponent": {
83
83
  "type": "boolean",
@@ -1,5 +1,6 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
- export declare function expoInitGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
- export declare function updateDependencies(host: Tree): GeneratorCallback;
3
+ export declare function expoInitGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export declare function expoInitGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
+ export declare function updateDependencies(host: Tree, schema: Schema): GeneratorCallback;
5
6
  export default expoInitGenerator;
@@ -1,70 +1,74 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateDependencies = exports.expoInitGenerator = void 0;
3
+ exports.updateDependencies = exports.expoInitGeneratorInternal = exports.expoInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
+ const plugin_1 = require("../../../plugins/plugin");
5
7
  const versions_1 = require("../../utils/versions");
6
- const jest_1 = require("@nx/jest");
7
- const detox_1 = require("@nx/detox");
8
- const js_1 = require("@nx/js");
8
+ const has_expo_plugin_1 = require("../../utils/has-expo-plugin");
9
9
  const add_git_ignore_entry_1 = require("./lib/add-git-ignore-entry");
10
- const init_root_babel_config_1 = require("./lib/init-root-babel-config");
11
- async function expoInitGenerator(host, schema) {
10
+ function expoInitGenerator(tree, schema) {
11
+ return expoInitGeneratorInternal(tree, { addPlugin: false, ...schema });
12
+ }
13
+ exports.expoInitGenerator = expoInitGenerator;
14
+ async function expoInitGeneratorInternal(host, schema) {
15
+ const nxJson = (0, devkit_1.readNxJson)(host);
16
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
+ nxJson.useInferencePlugins !== false;
18
+ schema.addPlugin ??= addPluginDefault;
12
19
  (0, add_git_ignore_entry_1.addGitIgnoreEntry)(host);
13
- (0, init_root_babel_config_1.initRootBabelConfig)(host);
20
+ if (schema.addPlugin) {
21
+ addPlugin(host);
22
+ }
14
23
  const tasks = [];
15
- tasks.push(await (0, js_1.initGenerator)(host, {
16
- ...schema,
17
- skipFormat: true,
18
- }));
19
24
  if (!schema.skipPackageJson) {
20
25
  tasks.push(moveDependency(host));
21
- tasks.push(updateDependencies(host));
26
+ tasks.push(updateDependencies(host, schema));
22
27
  }
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);
28
+ if (schema.updatePackageScripts) {
29
+ await (0, update_package_scripts_1.updatePackageScripts)(host, plugin_1.createNodes);
33
30
  }
34
31
  if (!schema.skipFormat) {
35
32
  await (0, devkit_1.formatFiles)(host);
36
33
  }
37
34
  return (0, devkit_1.runTasksInSerial)(...tasks);
38
35
  }
39
- exports.expoInitGenerator = expoInitGenerator;
40
- function updateDependencies(host) {
36
+ exports.expoInitGeneratorInternal = expoInitGeneratorInternal;
37
+ function updateDependencies(host, schema) {
41
38
  return (0, devkit_1.addDependenciesToPackageJson)(host, {
42
39
  react: versions_1.reactVersion,
43
40
  'react-dom': versions_1.reactDomVersion,
44
41
  'react-native': versions_1.reactNativeVersion,
45
42
  expo: versions_1.expoVersion,
46
- 'expo-splash-screen': versions_1.expoSplashScreenVersion,
47
- 'expo-status-bar': versions_1.expoStatusBarVersion,
48
- 'react-native-web': versions_1.reactNativeWebVersion,
49
- '@expo/metro-config': versions_1.expoMetroConfigVersion,
50
- 'react-native-svg-transformer': versions_1.reactNativeSvgTransformerVersion,
51
- 'react-native-svg': versions_1.reactNativeSvgVersion,
52
43
  }, {
53
44
  '@nx/expo': versions_1.nxVersion,
54
- '@types/react': versions_1.typesReactVersion,
55
- metro: versions_1.metroVersion,
56
- 'metro-resolver': versions_1.metroVersion,
57
- 'react-test-renderer': versions_1.reactTestRendererVersion,
58
- '@testing-library/react-native': versions_1.testingLibraryReactNativeVersion,
59
- '@testing-library/jest-native': versions_1.testingLibraryJestNativeVersion,
60
- 'jest-expo': versions_1.jestExpoVersion,
61
45
  '@expo/cli': versions_1.expoCliVersion,
62
- 'eas-cli': versions_1.easCliVersion,
63
- 'babel-preset-expo': versions_1.babelPresetExpoVersion,
64
- });
46
+ }, undefined, schema.keepExistingVersions);
65
47
  }
66
48
  exports.updateDependencies = updateDependencies;
67
49
  function moveDependency(host) {
68
50
  return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react-native'], []);
69
51
  }
52
+ function addPlugin(host) {
53
+ const nxJson = (0, devkit_1.readNxJson)(host);
54
+ if ((0, has_expo_plugin_1.hasExpoPlugin)(host)) {
55
+ return;
56
+ }
57
+ nxJson.plugins ??= [];
58
+ nxJson.plugins.push({
59
+ plugin: '@nx/expo/plugin',
60
+ options: {
61
+ startTargetName: 'start',
62
+ serveTargetName: 'serve',
63
+ runIosTargetName: 'run-ios',
64
+ runAndroidTargetName: 'run-android',
65
+ exportTargetName: 'export',
66
+ prebuildTargetName: 'prebuild',
67
+ installTargetName: 'install',
68
+ buildTargetName: 'build',
69
+ submitTargetName: 'submit',
70
+ },
71
+ });
72
+ (0, devkit_1.updateNxJson)(host, nxJson);
73
+ }
70
74
  exports.default = expoInitGenerator;
@@ -1,7 +1,7 @@
1
1
  export interface Schema {
2
- unitTestRunner?: 'jest' | 'none';
3
2
  skipFormat?: boolean;
4
- e2eTestRunner?: 'detox' | 'none';
5
3
  skipPackageJson?: boolean; // default is false
6
- js?: boolean;
4
+ keepExistingVersions?: boolean; // default is false
5
+ updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
7
7
  }
@@ -1,37 +1,32 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxExpoInit",
4
- "$schema": "http://json-schema.org/schema",
4
+ "$schema": "https://json-schema.org/schema",
5
5
  "description": "Add Nx Expo Schematics.",
6
6
  "type": "object",
7
7
  "properties": {
8
- "unitTestRunner": {
9
- "description": "Adds the specified unit test runner",
10
- "type": "string",
11
- "enum": ["jest", "none"],
12
- "default": "jest"
13
- },
14
8
  "skipFormat": {
15
9
  "description": "Skip formatting files",
16
10
  "type": "boolean",
17
11
  "default": false,
18
12
  "x-priority": "internal"
19
13
  },
20
- "e2eTestRunner": {
21
- "description": "Adds the specified e2e test runner",
22
- "type": "string",
23
- "enum": ["detox", "none"],
24
- "default": "detox"
25
- },
26
14
  "skipPackageJson": {
27
15
  "type": "boolean",
28
16
  "default": false,
29
17
  "description": "Do not add dependencies to `package.json`."
30
18
  },
31
- "js": {
19
+ "keepExistingVersions": {
32
20
  "type": "boolean",
33
- "default": false,
34
- "description": "Use JavaScript instead of TypeScript"
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
+ },
25
+ "updatePackageScripts": {
26
+ "type": "boolean",
27
+ "x-priority": "internal",
28
+ "description": "Update `package.json` scripts with inferred targets",
29
+ "default": false
35
30
  }
36
31
  },
37
32
  "required": []
@@ -0,0 +1,21 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+
4
+ return {
5
+ presets: [
6
+ [
7
+ '@nx/react/babel',
8
+ {
9
+ runtime: 'automatic',
10
+ useBuiltIns: 'usage',
11
+ },
12
+ ],
13
+ ],
14
+ plugins: [],
15
+ env: {
16
+ test: {
17
+ presets: ['babel-preset-expo'],
18
+ },
19
+ },
20
+ };
21
+ };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
4
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
5
6
  async function normalizeOptions(host, options) {
6
7
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
@@ -11,6 +12,10 @@ async function normalizeOptions(host, options) {
11
12
  projectNameAndRootFormat: options.projectNameAndRootFormat,
12
13
  callingGenerator: '@nx/expo:library',
13
14
  });
15
+ const nxJson = (0, devkit_1.readNxJson)(host);
16
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
+ nxJson.useInferencePlugins !== false;
18
+ options.addPlugin ??= addPluginDefault;
14
19
  const parsedTags = options.tags
15
20
  ? options.tags.split(',').map((s) => s.trim())
16
21
  : [];
@@ -8,8 +8,13 @@ const add_linting_1 = require("../../utils/add-linting");
8
8
  const add_jest_1 = require("../../utils/add-jest");
9
9
  const versions_1 = require("../../utils/versions");
10
10
  const normalize_options_1 = require("./lib/normalize-options");
11
+ const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
12
+ const init_root_babel_config_1 = require("../../utils/init-root-babel-config");
13
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
14
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
11
15
  async function expoLibraryGenerator(host, schema) {
12
16
  return await expoLibraryGeneratorInternal(host, {
17
+ addPlugin: false,
13
18
  projectNameAndRootFormat: 'derived',
14
19
  ...schema,
15
20
  });
@@ -21,12 +26,17 @@ async function expoLibraryGeneratorInternal(host, schema) {
21
26
  throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
22
27
  }
23
28
  const tasks = [];
24
- const initTask = await (0, init_1.default)(host, {
25
- ...options,
29
+ const jsInitTask = await (0, js_1.initGenerator)(host, {
30
+ ...schema,
26
31
  skipFormat: true,
27
- e2eTestRunner: 'none',
28
32
  });
33
+ tasks.push(jsInitTask);
34
+ const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
29
35
  tasks.push(initTask);
36
+ if (!options.skipPackageJson) {
37
+ tasks.push((0, ensure_dependencies_1.ensureDependencies)(host));
38
+ }
39
+ (0, init_root_babel_config_1.initRootBabelConfig)(host);
30
40
  const addProjectTask = await addProject(host, options);
31
41
  if (addProjectTask) {
32
42
  tasks.push(addProjectTask);
@@ -40,7 +50,7 @@ async function expoLibraryGeneratorInternal(host, schema) {
40
50
  ],
41
51
  });
42
52
  tasks.push(lintTask);
43
- const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson);
53
+ const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin);
44
54
  tasks.push(jestTask);
45
55
  if (options.publishable || options.buildable) {
46
56
  updateLibPackageNpmScope(host, options);
@@ -53,49 +63,53 @@ async function expoLibraryGeneratorInternal(host, schema) {
53
63
  if (!options.skipFormat) {
54
64
  await (0, devkit_1.formatFiles)(host);
55
65
  }
66
+ tasks.push(() => {
67
+ (0, log_show_project_command_1.logShowProjectCommand)(options.name);
68
+ });
56
69
  return (0, devkit_1.runTasksInSerial)(...tasks);
57
70
  }
58
71
  exports.expoLibraryGeneratorInternal = expoLibraryGeneratorInternal;
59
72
  async function addProject(host, options) {
60
- const targets = {};
61
- let task;
62
- if (options.publishable || options.buildable) {
63
- const { rollupInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
64
- const external = [
65
- 'react/jsx-runtime',
66
- 'react-native',
67
- 'react',
68
- 'react-dom',
69
- ];
70
- targets.build = {
71
- executor: '@nx/rollup:rollup',
72
- outputs: ['{options.outputPath}'],
73
- options: {
74
- outputPath: `dist/${options.projectRoot}`,
75
- tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
76
- project: `${options.projectRoot}/package.json`,
77
- entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
78
- external,
79
- rollupConfig: `@nx/react/plugins/bundle-rollup`,
80
- assets: [
81
- {
82
- glob: `${options.projectRoot}/README.md`,
83
- input: '.',
84
- output: '.',
85
- },
86
- ],
87
- },
88
- };
89
- task = await rollupInitGenerator(host, { ...options, skipFormat: true });
90
- }
91
- (0, devkit_1.addProjectConfiguration)(host, options.name, {
73
+ const project = {
92
74
  root: options.projectRoot,
93
75
  sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
94
76
  projectType: 'library',
95
77
  tags: options.parsedTags,
96
- targets,
78
+ targets: {},
79
+ };
80
+ (0, devkit_1.addProjectConfiguration)(host, options.name, project);
81
+ if (!options.publishable && !options.buildable) {
82
+ return () => { };
83
+ }
84
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
85
+ const rollupConfigTask = await configurationGenerator(host, {
86
+ ...options,
87
+ project: options.name,
88
+ skipFormat: true,
97
89
  });
98
- return task;
90
+ const external = ['react/jsx-runtime', 'react-native', 'react', 'react-dom'];
91
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(host, '@nx/rollup:rollup');
92
+ project.targets.build = {
93
+ executor: '@nx/rollup:rollup',
94
+ outputs: ['{options.outputPath}'],
95
+ options: {
96
+ outputPath: `dist/${options.projectRoot}`,
97
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
98
+ project: `${options.projectRoot}/package.json`,
99
+ entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
100
+ external,
101
+ rollupConfig: `@nx/react/plugins/bundle-rollup`,
102
+ assets: [
103
+ {
104
+ glob: `${options.projectRoot}/README.md`,
105
+ input: '.',
106
+ output: '.',
107
+ },
108
+ ],
109
+ },
110
+ };
111
+ (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
112
+ return rollupConfigTask;
99
113
  }
100
114
  function updateTsConfig(tree, options) {
101
115
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
@@ -21,4 +21,5 @@ export interface Schema {
21
21
  strict: boolean; // default is true
22
22
  setParserOptionsProject?: boolean;
23
23
  skipPackageJson?: boolean; // default is false
24
+ addPlugin?: boolean;
24
25
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxExpoLibrary",
4
- "$schema": "http://json-schema.org/schema",
4
+ "$schema": "https://json-schema.org/schema",
5
5
  "description": "Create a Expo Library for Nx.",
6
6
  "type": "object",
7
7
  "examples": [
@@ -34,7 +34,7 @@
34
34
  "linter": {
35
35
  "description": "The tool to use for running lint checks.",
36
36
  "type": "string",
37
- "enum": ["eslint"],
37
+ "enum": ["eslint", "none"],
38
38
  "default": "eslint"
39
39
  },
40
40
  "unitTestRunner": {
@@ -32,7 +32,6 @@ const content = `
32
32
  const { withNxMetro } = require('@nx/expo');
33
33
  const { getDefaultConfig } = require('@expo/metro-config');
34
34
  const { mergeConfig } = require('metro-config');
35
- const exclusionList = require('metro-config/src/defaults/exclusionList');
36
35
 
37
36
  const defaultConfig = getDefaultConfig(__dirname);
38
37
  const { assetExts, sourceExts } = defaultConfig.resolver;
@@ -49,10 +48,7 @@ const customConfig = {
49
48
  },
50
49
  resolver: {
51
50
  assetExts: assetExts.filter((ext) => ext !== 'svg'),
52
- sourceExts: [...sourceExts, 'svg'],
53
- blockList: exclusionList([/^(?!.*node_modules).*\\/dist\\/.*/]),
54
- unstable_enableSymlinks: true,
55
- unstable_enablePackageExports: true,
51
+ sourceExts: [...sourceExts, 'cjs', 'mjs', 'svg'],
56
52
  },
57
53
  };
58
54
 
@@ -7,14 +7,7 @@ const devkit_1 = require("@nx/devkit");
7
7
  * @returns
8
8
  */
9
9
  async function update(tree) {
10
- const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
11
- if (!packageJson.devDependencies['@types/react-native'] ||
12
- !packageJson.dependencies['react-native']) {
13
- return;
14
- }
15
- (0, devkit_1.updateJson)(tree, 'package.json', (packageJson) => {
16
- delete packageJson.devDependencies['@types/react-native'];
17
- return packageJson;
18
- });
10
+ (0, devkit_1.removeDependenciesFromPackageJson)(tree, [], ['@types/react-native']);
11
+ await (0, devkit_1.formatFiles)(tree);
19
12
  }
20
13
  exports.default = update;
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const devkit_1 = require("@nx/devkit");
4
- const versions_1 = require("../../utils/versions");
5
4
  async function update(tree) {
6
5
  const projects = (0, devkit_1.getProjects)(tree);
7
6
  for (const [name, config] of projects.entries()) {
8
7
  if (config.targets?.['start']?.executor === '@nx/expo:start') {
9
8
  (0, devkit_1.updateJson)(tree, `${config.root}/eas.json`, (easJson) => {
10
9
  if (easJson?.cli?.version) {
11
- easJson.cli.version = `>= ${versions_1.easCliVersion.replace('~', '')}`;
10
+ easJson.cli.version = `>= 5`;
12
11
  }
13
12
  return easJson;
14
13
  });
@@ -1,5 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  /**
3
- * Add detox plugin to app.json for expo
3
+ * Remove the offset from the outputDir of the export target
4
4
  */
5
5
  export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ /**
5
+ * Remove the offset from the outputDir of the export target
6
+ */
7
+ async function update(tree) {
8
+ const projects = (0, devkit_1.getProjects)(tree);
9
+ for (const [projectName, config] of projects.entries()) {
10
+ if (config.targets?.['export']?.executor === '@nx/expo:export') {
11
+ const target = config.targets['export'];
12
+ if (target.options?.outputDir) {
13
+ const offset = (0, devkit_1.offsetFromRoot)(config.root);
14
+ target.options.outputDir = target.options.outputDir.replace(offset, '');
15
+ target.outputs = ['{options.outputDir}'];
16
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, config);
17
+ }
18
+ }
19
+ if (config.targets?.['export-web']?.executor === '@nx/expo:export') {
20
+ delete config.targets['export-web'];
21
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, config);
22
+ }
23
+ }
24
+ }
25
+ exports.default = update;
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ /**
3
+ * This migration remove blockList in metro.config.js.
4
+ * It is now excluding dist folder in watchFolders in withNxMetro.
5
+ */
6
+ export default function update(tree: Tree): Promise<void>;