@nx/expo 0.0.0-pr-30418-4e2b721 → 0.0.0-pr-3-ec41644

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/expo",
3
- "version": "0.0.0-pr-30418-4e2b721",
3
+ "version": "0.0.0-pr-3-ec41644",
4
4
  "private": false,
5
5
  "description": "The Expo Plugin for Nx contains executors and generators for managing and developing an expo application within your workspace. For example, you can directly build for different target platforms as well as generate projects and publish your code.",
6
6
  "keywords": [
@@ -28,13 +28,13 @@
28
28
  "main": "./index",
29
29
  "types": "index.d.ts",
30
30
  "dependencies": {
31
- "@nx/devkit": "0.0.0-pr-30418-4e2b721",
32
- "@nx/eslint": "0.0.0-pr-30418-4e2b721",
33
- "@nx/jest": "0.0.0-pr-30418-4e2b721",
34
- "@nx/js": "0.0.0-pr-30418-4e2b721",
35
- "@nx/react": "0.0.0-pr-30418-4e2b721",
36
- "@nx/web": "0.0.0-pr-30418-4e2b721",
37
- "@nx/webpack": "0.0.0-pr-30418-4e2b721",
31
+ "@nx/devkit": "0.0.0-pr-3-ec41644",
32
+ "@nx/eslint": "0.0.0-pr-3-ec41644",
33
+ "@nx/jest": "0.0.0-pr-3-ec41644",
34
+ "@nx/js": "0.0.0-pr-3-ec41644",
35
+ "@nx/react": "0.0.0-pr-3-ec41644",
36
+ "@nx/web": "0.0.0-pr-3-ec41644",
37
+ "@nx/webpack": "0.0.0-pr-3-ec41644",
38
38
  "enhanced-resolve": "^5.8.3",
39
39
  "metro-config": "~0.80.4",
40
40
  "metro-resolver": "~0.80.4",
@@ -20,7 +20,6 @@ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
20
20
  async function expoApplicationGenerator(host, schema) {
21
21
  return await expoApplicationGeneratorInternal(host, {
22
22
  addPlugin: false,
23
- useProjectJson: true,
24
23
  ...schema,
25
24
  });
26
25
  }
@@ -43,11 +42,6 @@ async function expoApplicationGeneratorInternal(host, schema) {
43
42
  (0, init_root_babel_config_1.initRootBabelConfig)(host);
44
43
  await (0, create_application_files_1.createApplicationFiles)(host, options);
45
44
  (0, add_project_1.addProject)(host, options);
46
- // If we are using the new TS solution
47
- // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
48
- if (options.isTsSolutionSetup) {
49
- await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot);
50
- }
51
45
  const lintTask = await (0, add_linting_1.addLinting)(host, {
52
46
  ...options,
53
47
  projectRoot: options.appProjectRoot,
@@ -69,6 +63,11 @@ async function expoApplicationGeneratorInternal(host, schema) {
69
63
  }, options.linter === 'eslint'
70
64
  ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
71
65
  : undefined);
66
+ // If we are using the new TS solution
67
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
68
+ if (options.useTsSolution) {
69
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot);
70
+ }
72
71
  (0, sort_fields_1.sortPackageJsonFields)(host, options.appProjectRoot);
73
72
  if (!options.skipFormat) {
74
73
  await (0, devkit_1.formatFiles)(host);
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addE2e = addE2e;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const e2e_web_server_info_utils_1 = require("@nx/devkit/src/generators/e2e-web-server-info-utils");
6
- const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
7
- const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
8
5
  const web_1 = require("@nx/web");
9
- const has_expo_plugin_1 = require("../../../utils/has-expo-plugin");
10
6
  const versions_1 = require("../../../utils/versions");
7
+ const has_expo_plugin_1 = require("../../../utils/has-expo-plugin");
8
+ const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
9
+ const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
10
+ const e2e_web_server_info_utils_1 = require("@nx/devkit/src/generators/e2e-web-server-info-utils");
11
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
11
12
  async function addE2e(tree, options) {
12
13
  const hasPlugin = (0, has_expo_plugin_1.hasExpoPlugin)(tree);
13
14
  if (!hasPlugin) {
@@ -20,15 +21,17 @@ async function addE2e(tree, options) {
20
21
  switch (options.e2eTestRunner) {
21
22
  case 'cypress': {
22
23
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
23
- const packageJson = {
24
- name: options.e2eProjectName,
25
- version: '0.0.1',
26
- private: true,
27
- };
28
- if (!options.useProjectJson) {
29
- packageJson.nx = {
30
- implicitDependencies: [options.projectName],
31
- };
24
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree)) {
25
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
26
+ name: options.e2eProjectName,
27
+ version: '0.0.1',
28
+ private: true,
29
+ nx: {
30
+ projectType: 'application',
31
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
32
+ implicitDependencies: [options.projectName],
33
+ },
34
+ });
32
35
  }
33
36
  else {
34
37
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
@@ -40,9 +43,6 @@ async function addE2e(tree, options) {
40
43
  tags: [],
41
44
  });
42
45
  }
43
- if (!options.useProjectJson || options.isTsSolutionSetup) {
44
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
45
- }
46
46
  const e2eTask = await configurationGenerator(tree, {
47
47
  ...options,
48
48
  project: options.e2eProjectName,
@@ -78,15 +78,17 @@ async function addE2e(tree, options) {
78
78
  }
79
79
  case 'playwright': {
80
80
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
81
- const packageJson = {
82
- name: options.e2eProjectName,
83
- version: '0.0.1',
84
- private: true,
85
- };
86
- if (!options.useProjectJson) {
87
- packageJson.nx = {
88
- implicitDependencies: [options.projectName],
89
- };
81
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree)) {
82
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
83
+ name: options.e2eProjectName,
84
+ version: '0.0.1',
85
+ private: true,
86
+ nx: {
87
+ projectType: 'application',
88
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
89
+ implicitDependencies: [options.projectName],
90
+ },
91
+ });
90
92
  }
91
93
  else {
92
94
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
@@ -95,12 +97,8 @@ async function addE2e(tree, options) {
95
97
  sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
96
98
  targets: {},
97
99
  implicitDependencies: [options.projectName],
98
- tags: [],
99
100
  });
100
101
  }
101
- if (!options.useProjectJson || options.isTsSolutionSetup) {
102
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
103
- }
104
102
  const e2eTask = await configurationGenerator(tree, {
105
103
  project: options.e2eProjectName,
106
104
  skipFormat: true,
@@ -137,7 +135,7 @@ async function addE2e(tree, options) {
137
135
  e2eDirectory: options.e2eProjectRoot,
138
136
  appProject: options.projectName,
139
137
  appDisplayName: options.displayName,
140
- appName: options.simpleName,
138
+ appName: options.name,
141
139
  framework: 'expo',
142
140
  setParserOptionsProject: options.setParserOptionsProject,
143
141
  skipFormat: true,
@@ -2,9 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProject = addProject;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
6
5
  const has_expo_plugin_1 = require("../../../utils/has-expo-plugin");
6
+ const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
7
9
  function addProject(host, options) {
10
+ const nxJson = (0, devkit_1.readNxJson)(host);
8
11
  const hasPlugin = (0, has_expo_plugin_1.hasExpoPlugin)(host);
9
12
  if (!hasPlugin) {
10
13
  (0, target_defaults_utils_1.addBuildTargetDefaults)(host, '@nx/expo:build');
@@ -16,30 +19,24 @@ function addProject(host, options) {
16
19
  targets: hasPlugin ? {} : getTargets(options),
17
20
  tags: options.parsedTags,
18
21
  };
19
- const packageJson = {
20
- name: options.importPath,
21
- version: '0.0.1',
22
- private: true,
23
- };
24
- if (!options.useProjectJson) {
25
- if (options.importPath !== options.projectName) {
26
- packageJson.nx = { name: options.projectName };
27
- }
28
- if (!hasPlugin) {
29
- packageJson.nx ??= {};
30
- packageJson.nx.targets = getTargets(options);
31
- }
32
- if (options.parsedTags?.length) {
33
- packageJson.nx ??= {};
34
- packageJson.nx.tags = options.parsedTags;
35
- }
22
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
23
+ const packageName = (0, get_import_path_1.getImportPath)(host, options.name);
24
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
25
+ name: packageName,
26
+ version: '0.0.1',
27
+ private: true,
28
+ nx: {
29
+ name: packageName === options.name ? undefined : options.name,
30
+ projectType: 'application',
31
+ sourceRoot: `${options.appProjectRoot}/src`,
32
+ targets: hasPlugin ? undefined : getTargets(options),
33
+ tags: options.parsedTags?.length ? options.parsedTags : undefined,
34
+ },
35
+ });
36
36
  }
37
37
  else {
38
38
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, projectConfiguration, options.standaloneConfig);
39
39
  }
40
- if (!options.useProjectJson || options.isTsSolutionSetup) {
41
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
42
- }
43
40
  }
44
41
  function getTargets(options) {
45
42
  const architect = {};
@@ -1,11 +1,9 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from '../schema';
3
- export interface NormalizedSchema extends Omit<Schema, 'name' | 'useTsSolution'> {
3
+ export interface NormalizedSchema extends Schema {
4
4
  className: string;
5
- simpleName: string;
6
5
  projectName: string;
7
6
  appProjectRoot: string;
8
- importPath: string;
9
7
  lowerCaseName: string;
10
8
  parsedTags: string[];
11
9
  rootProject: boolean;
@@ -5,8 +5,8 @@ const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
6
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
7
  async function normalizeOptions(host, options) {
8
- await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
9
- const { projectName, names: projectNames, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
+ await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
9
+ const { projectName: appProjectName, names: projectNames, projectRoot: appProjectRoot, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
10
  name: options.name,
11
11
  projectType: 'application',
12
12
  directory: options.directory,
@@ -15,32 +15,27 @@ async function normalizeOptions(host, options) {
15
15
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
16
16
  nxJson.useInferencePlugins !== false;
17
17
  options.addPlugin ??= addPluginDefault;
18
- const { className } = (0, devkit_1.names)(projectName);
18
+ const { className } = (0, devkit_1.names)(options.name);
19
19
  const parsedTags = options.tags
20
20
  ? options.tags.split(',').map((s) => s.trim())
21
21
  : [];
22
22
  const rootProject = appProjectRoot === '.';
23
- const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
24
- const appProjectName = !isTsSolutionSetup || options.name ? projectName : importPath;
25
- const useProjectJson = options.useProjectJson ?? !isTsSolutionSetup;
26
23
  const e2eProjectName = rootProject ? 'e2e' : `${appProjectName}-e2e`;
27
24
  const e2eProjectRoot = rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
28
25
  return {
29
26
  ...options,
30
27
  unitTestRunner: options.unitTestRunner || 'jest',
31
28
  e2eTestRunner: options.e2eTestRunner || 'none',
32
- simpleName: projectNames.projectSimpleName,
29
+ name: projectNames.projectSimpleName,
33
30
  className,
34
31
  lowerCaseName: className.toLowerCase(),
35
32
  displayName: options.displayName || className,
36
33
  projectName: appProjectName,
37
34
  appProjectRoot,
38
- importPath,
39
35
  parsedTags,
40
36
  rootProject,
41
37
  e2eProjectName,
42
38
  e2eProjectRoot,
43
- isTsSolutionSetup,
44
- useProjectJson,
39
+ isTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
45
40
  };
46
41
  }
@@ -20,5 +20,4 @@ export interface Schema {
20
20
  nxCloudToken?: string;
21
21
  useTsSolution?: boolean;
22
22
  formatter?: 'prettier' | 'none';
23
- useProjectJson?: boolean;
24
23
  }
@@ -86,10 +86,6 @@
86
86
  "type": "boolean",
87
87
  "description": "Do not add dependencies to `package.json`.",
88
88
  "default": false
89
- },
90
- "useProjectJson": {
91
- "type": "boolean",
92
- "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
93
89
  }
94
90
  },
95
91
  "required": ["directory"]
@@ -29,9 +29,7 @@ function addExportsToBarrel(host, options) {
29
29
  const proj = workspace.get(options.projectName);
30
30
  const isApp = (0, ts_solution_setup_1.getProjectType)(host, proj.root, proj.projectType) === 'application';
31
31
  if (options.export && !isApp) {
32
- const indexFilePath = (0, devkit_1.joinPathFragments)(...(options.projectSourceRoot
33
- ? [options.projectSourceRoot]
34
- : [options.projectRoot, 'src']), options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
32
+ const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
35
33
  if (!host.exists(indexFilePath)) {
36
34
  return;
37
35
  }
@@ -10,6 +10,5 @@ export interface NormalizedSchema extends Omit<Schema, 'js'> {
10
10
  className: string;
11
11
  filePath: string;
12
12
  projectName: string;
13
- projectRoot: string;
14
13
  }
15
14
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -31,6 +31,5 @@ async function normalizeOptions(host, options) {
31
31
  filePath,
32
32
  projectSourceRoot,
33
33
  projectName,
34
- projectRoot: root,
35
34
  };
36
35
  }
@@ -1,7 +1,7 @@
1
- # <%= projectName %>
1
+ # <%= name %>
2
2
 
3
3
  This library was generated with [Nx](https://nx.dev).
4
4
 
5
5
  ## Running unit tests
6
6
 
7
- Run `nx test <%= projectName %>` to execute the unit tests via [Jest](https://jestjs.io).
7
+ Run `nx test <%= name %>` to execute the unit tests via [Jest](https://jestjs.io).
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "<%= projectName %>",
3
+ "version": "0.0.1",
4
+ "main": "<%= appMain %>"
5
+ }
@@ -1,12 +1,13 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from '../schema';
3
- export interface NormalizedSchema extends Omit<Schema, 'name'> {
3
+ export interface NormalizedSchema extends Schema {
4
+ name: string;
4
5
  fileName: string;
5
6
  projectName: string;
6
7
  projectRoot: string;
7
- importPath: string;
8
8
  routePath: string;
9
9
  parsedTags: string[];
10
+ appMain: string;
10
11
  isUsingTsSolutionConfig: boolean;
11
12
  }
12
13
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -4,8 +4,9 @@ exports.normalizeOptions = normalizeOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
6
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
7
8
  async function normalizeOptions(host, options) {
8
- await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
9
+ await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
9
10
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
11
  name: options.name,
11
12
  projectType: 'library',
@@ -19,18 +20,21 @@ async function normalizeOptions(host, options) {
19
20
  const parsedTags = options.tags
20
21
  ? options.tags.split(',').map((s) => s.trim())
21
22
  : [];
23
+ const appMain = options.js ? 'src/index.js' : 'src/index.ts';
22
24
  const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
23
- const useProjectJson = options.useProjectJson ?? !isUsingTsSolutionConfig;
24
25
  const normalized = {
25
26
  ...options,
26
27
  fileName: projectName,
27
28
  routePath: `/${projectNames.projectSimpleName}`,
28
- projectName: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
29
+ name: projectName,
30
+ projectName: isUsingTsSolutionConfig
31
+ ? (0, get_import_path_1.getImportPath)(host, projectName)
32
+ : projectName,
29
33
  projectRoot,
30
34
  parsedTags,
31
35
  importPath,
36
+ appMain,
32
37
  isUsingTsSolutionConfig,
33
- useProjectJson,
34
38
  };
35
39
  return normalized;
36
40
  }
@@ -7,21 +7,17 @@ const js_1 = require("@nx/js");
7
7
  const init_1 = require("../init/init");
8
8
  const add_linting_1 = require("../../utils/add-linting");
9
9
  const add_jest_1 = require("../../utils/add-jest");
10
+ const versions_1 = require("../../utils/versions");
10
11
  const normalize_options_1 = require("./lib/normalize-options");
11
12
  const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
12
13
  const init_root_babel_config_1 = require("../../utils/init-root-babel-config");
14
+ const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
13
15
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
14
16
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
15
17
  const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
16
- const add_rollup_build_target_1 = require("@nx/react/src/generators/library/lib/add-rollup-build-target");
17
- const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
18
- const component_1 = require("../component/component");
19
- const path_1 = require("path");
20
- const versions_1 = require("../../utils/versions");
21
18
  async function expoLibraryGenerator(host, schema) {
22
19
  return await expoLibraryGeneratorInternal(host, {
23
20
  addPlugin: false,
24
- useProjectJson: true,
25
21
  ...schema,
26
22
  });
27
23
  }
@@ -37,7 +33,7 @@ async function expoLibraryGeneratorInternal(host, schema) {
37
33
  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)`);
38
34
  }
39
35
  if (options.isUsingTsSolutionConfig) {
40
- await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
36
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
41
37
  }
42
38
  const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
43
39
  tasks.push(initTask);
@@ -60,19 +56,12 @@ async function expoLibraryGeneratorInternal(host, schema) {
60
56
  tasks.push(lintTask);
61
57
  const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin);
62
58
  tasks.push(jestTask);
63
- const relativeCwd = (0, artifact_name_and_directory_utils_1.getRelativeCwd)();
64
- const path = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/lib', options.fileName);
65
- const componentTask = await (0, component_1.expoComponentGenerator)(host, {
66
- path: relativeCwd ? (0, path_1.relative)(relativeCwd, path) : path,
67
- skipTests: options.unitTestRunner === 'none',
68
- export: true,
69
- skipFormat: true,
70
- js: options.js,
71
- });
72
- tasks.push(() => componentTask);
59
+ if (options.publishable || options.buildable) {
60
+ updateLibPackageNpmScope(host, options);
61
+ }
73
62
  if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
74
63
  (0, js_1.addTsConfigPath)(host, options.importPath, [
75
- (0, devkit_1.joinPathFragments)(options.projectRoot, options.js ? './src/index.js' : './src/index.ts'),
64
+ (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
76
65
  ]);
77
66
  }
78
67
  (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
@@ -91,7 +80,7 @@ async function expoLibraryGeneratorInternal(host, schema) {
91
80
  tasks.push(() => (0, devkit_1.installPackagesTask)(host, true));
92
81
  }
93
82
  tasks.push(() => {
94
- (0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
83
+ (0, log_show_project_command_1.logShowProjectCommand)(options.name);
95
84
  });
96
85
  return (0, devkit_1.runTasksInSerial)(...tasks);
97
86
  }
@@ -103,65 +92,72 @@ async function addProject(host, options) {
103
92
  tags: options.parsedTags,
104
93
  targets: {},
105
94
  };
106
- let packageJson = {
107
- name: options.importPath,
108
- version: '0.0.1',
109
- peerDependencies: {
110
- react: versions_1.reactVersion,
111
- 'react-native': versions_1.reactNativeVersion,
112
- },
113
- };
114
95
  if (options.isUsingTsSolutionConfig) {
115
- packageJson = {
116
- ...packageJson,
117
- ...determineEntryFields(options),
118
- files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
119
- };
120
- }
121
- if (!options.useProjectJson) {
122
- if (options.projectName !== options.importPath) {
123
- packageJson.nx = { name: options.projectName };
124
- }
125
- if (options.parsedTags?.length) {
126
- packageJson.nx ??= {};
127
- packageJson.nx.tags = options.parsedTags;
128
- }
96
+ const sourceEntry = !options.buildable
97
+ ? options.js
98
+ ? './src/index.js'
99
+ : './src/index.ts'
100
+ : undefined;
101
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), {
102
+ name: options.projectName,
103
+ version: '0.0.1',
104
+ main: sourceEntry,
105
+ types: sourceEntry,
106
+ // For buildable libraries, the entries are configured by the bundler (i.e. Rollup).
107
+ exports: options.buildable
108
+ ? undefined
109
+ : {
110
+ './package.json': './package.json',
111
+ '.': options.js
112
+ ? './src/index.js'
113
+ : {
114
+ types: './src/index.ts',
115
+ import: './src/index.ts',
116
+ default: './src/index.ts',
117
+ },
118
+ },
119
+ nx: options.parsedTags?.length
120
+ ? {
121
+ tags: options.parsedTags,
122
+ }
123
+ : undefined,
124
+ });
129
125
  }
130
126
  else {
131
- (0, devkit_1.addProjectConfiguration)(host, options.projectName, project);
127
+ (0, devkit_1.addProjectConfiguration)(host, options.name, project);
132
128
  }
133
- if (!options.useProjectJson ||
134
- options.isUsingTsSolutionConfig ||
135
- options.publishable ||
136
- options.buildable) {
137
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), packageJson);
129
+ if (!options.publishable && !options.buildable) {
130
+ return () => { };
138
131
  }
139
- if (options.publishable || options.buildable) {
140
- const external = new Set([
141
- 'react/jsx-runtime',
142
- 'react-native',
143
- 'react',
144
- 'react-dom',
145
- ]);
146
- const rollupTask = await (0, add_rollup_build_target_1.addRollupBuildTarget)(host, {
147
- ...options,
148
- name: options.projectName,
149
- format: ['cjs', 'esm'],
150
- style: 'none',
151
- js: options.js,
152
- skipFormat: true,
153
- }, external);
154
- (0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
155
- json.peerDependencies = {
156
- ...json.peerDependencies,
157
- react: versions_1.reactVersion,
158
- 'react-native': versions_1.reactNativeVersion,
159
- };
160
- return json;
161
- });
162
- return rollupTask;
163
- }
164
- return () => { };
132
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
133
+ const rollupConfigTask = await configurationGenerator(host, {
134
+ ...options,
135
+ project: options.projectName,
136
+ skipFormat: true,
137
+ });
138
+ const external = ['react/jsx-runtime', 'react-native', 'react', 'react-dom'];
139
+ (0, target_defaults_utils_1.addBuildTargetDefaults)(host, '@nx/rollup:rollup');
140
+ project.targets.build = {
141
+ executor: '@nx/rollup:rollup',
142
+ outputs: ['{options.outputPath}'],
143
+ options: {
144
+ outputPath: `dist/${options.projectRoot}`,
145
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
146
+ project: `${options.projectRoot}/package.json`,
147
+ entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
148
+ external,
149
+ rollupConfig: `@nx/react/plugins/bundle-rollup`,
150
+ assets: [
151
+ {
152
+ glob: `${options.projectRoot}/README.md`,
153
+ input: '.',
154
+ output: '.',
155
+ },
156
+ ],
157
+ },
158
+ };
159
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
160
+ return rollupConfigTask;
165
161
  }
166
162
  function updateTsConfig(tree, options) {
167
163
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
@@ -180,29 +176,34 @@ function updateTsConfig(tree, options) {
180
176
  function createFiles(host, options) {
181
177
  (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/lib'), options.projectRoot, {
182
178
  ...options,
179
+ ...(0, devkit_1.names)(options.name),
183
180
  tmpl: '',
184
181
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
185
182
  rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
186
183
  });
184
+ if (!options.publishable &&
185
+ !options.buildable &&
186
+ !options.isUsingTsSolutionConfig) {
187
+ host.delete(`${options.projectRoot}/package.json`);
188
+ }
187
189
  if (options.js) {
188
190
  (0, devkit_1.toJS)(host);
189
191
  }
190
192
  updateTsConfig(host, options);
191
193
  }
192
- function determineEntryFields(options) {
193
- return {
194
- main: options.js ? './src/index.js' : './src/index.ts',
195
- types: options.js ? './src/index.js' : './src/index.ts',
196
- exports: {
197
- '.': options.js
198
- ? './src/index.js'
199
- : {
200
- types: './src/index.ts',
201
- import: './src/index.ts',
202
- default: './src/index.ts',
203
- },
204
- './package.json': './package.json',
205
- },
206
- };
194
+ function updateLibPackageNpmScope(host, options) {
195
+ return (0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
196
+ json.name = options.importPath;
197
+ json.peerDependencies = {
198
+ react: versions_1.reactVersion,
199
+ 'react-native': versions_1.reactNativeVersion,
200
+ };
201
+ return json;
202
+ });
203
+ }
204
+ function maybeJs(options, path) {
205
+ return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
206
+ ? path.replace(/\.tsx?$/, '.js')
207
+ : path;
207
208
  }
208
209
  exports.default = expoLibraryGenerator;
@@ -19,5 +19,4 @@ export interface Schema {
19
19
  setParserOptionsProject?: boolean;
20
20
  skipPackageJson?: boolean; // default is false
21
21
  addPlugin?: boolean;
22
- useProjectJson?: boolean;
23
22
  }
@@ -89,10 +89,6 @@
89
89
  "type": "boolean",
90
90
  "description": "Do not add dependencies to `package.json`.",
91
91
  "default": false
92
- },
93
- "useProjectJson": {
94
- "type": "boolean",
95
- "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
96
92
  }
97
93
  },
98
94
  "required": ["directory"]