@nx/expo 21.0.0-beta.0 → 21.0.0-beta.2
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 +8 -8
- package/src/generators/application/application.js +6 -5
- package/src/generators/application/lib/add-e2e.js +30 -28
- package/src/generators/application/lib/add-project.js +21 -18
- package/src/generators/application/lib/create-application-files.js +1 -10
- package/src/generators/application/lib/normalize-options.d.ts +3 -1
- package/src/generators/application/lib/normalize-options.js +10 -5
- package/src/generators/application/schema.d.ts +1 -0
- package/src/generators/application/schema.json +4 -0
- package/src/generators/component/component.js +3 -1
- package/src/generators/component/lib/normalize-options.d.ts +1 -0
- package/src/generators/component/lib/normalize-options.js +1 -0
- package/src/generators/library/files/lib/README.md +2 -2
- package/src/generators/library/lib/normalize-options.d.ts +3 -3
- package/src/generators/library/lib/normalize-options.js +6 -5
- package/src/generators/library/library.js +98 -81
- package/src/generators/library/schema.d.ts +1 -0
- package/src/generators/library/schema.json +4 -0
- package/src/generators/library/files/lib/package.json.template +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/expo",
|
|
3
|
-
"version": "21.0.0-beta.
|
|
3
|
+
"version": "21.0.0-beta.2",
|
|
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": "21.0.0-beta.
|
|
32
|
-
"@nx/eslint": "21.0.0-beta.
|
|
33
|
-
"@nx/jest": "21.0.0-beta.
|
|
34
|
-
"@nx/js": "21.0.0-beta.
|
|
35
|
-
"@nx/react": "21.0.0-beta.
|
|
36
|
-
"@nx/web": "21.0.0-beta.
|
|
37
|
-
"@nx/webpack": "21.0.0-beta.
|
|
31
|
+
"@nx/devkit": "21.0.0-beta.2",
|
|
32
|
+
"@nx/eslint": "21.0.0-beta.2",
|
|
33
|
+
"@nx/jest": "21.0.0-beta.2",
|
|
34
|
+
"@nx/js": "21.0.0-beta.2",
|
|
35
|
+
"@nx/react": "21.0.0-beta.2",
|
|
36
|
+
"@nx/web": "21.0.0-beta.2",
|
|
37
|
+
"@nx/webpack": "21.0.0-beta.2",
|
|
38
38
|
"enhanced-resolve": "^5.8.3",
|
|
39
39
|
"metro-config": "~0.80.4",
|
|
40
40
|
"metro-resolver": "~0.80.4",
|
|
@@ -20,6 +20,7 @@ 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,
|
|
23
24
|
...schema,
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -42,6 +43,11 @@ async function expoApplicationGeneratorInternal(host, schema) {
|
|
|
42
43
|
(0, init_root_babel_config_1.initRootBabelConfig)(host);
|
|
43
44
|
await (0, create_application_files_1.createApplicationFiles)(host, options);
|
|
44
45
|
(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
|
+
}
|
|
45
51
|
const lintTask = await (0, add_linting_1.addLinting)(host, {
|
|
46
52
|
...options,
|
|
47
53
|
projectRoot: options.appProjectRoot,
|
|
@@ -63,11 +69,6 @@ async function expoApplicationGeneratorInternal(host, schema) {
|
|
|
63
69
|
}, options.linter === 'eslint'
|
|
64
70
|
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
|
65
71
|
: 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
|
-
}
|
|
71
72
|
(0, sort_fields_1.sortPackageJsonFields)(host, options.appProjectRoot);
|
|
72
73
|
if (!options.skipFormat) {
|
|
73
74
|
await (0, devkit_1.formatFiles)(host);
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addE2e = addE2e;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
6
|
-
const versions_1 = require("../../../utils/versions");
|
|
7
|
-
const has_expo_plugin_1 = require("../../../utils/has-expo-plugin");
|
|
5
|
+
const e2e_web_server_info_utils_1 = require("@nx/devkit/src/generators/e2e-web-server-info-utils");
|
|
8
6
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
9
7
|
const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
8
|
+
const web_1 = require("@nx/web");
|
|
9
|
+
const has_expo_plugin_1 = require("../../../utils/has-expo-plugin");
|
|
10
|
+
const versions_1 = require("../../../utils/versions");
|
|
12
11
|
async function addE2e(tree, options) {
|
|
13
12
|
const hasPlugin = (0, has_expo_plugin_1.hasExpoPlugin)(tree);
|
|
14
13
|
if (!hasPlugin) {
|
|
@@ -21,17 +20,15 @@ async function addE2e(tree, options) {
|
|
|
21
20
|
switch (options.e2eTestRunner) {
|
|
22
21
|
case 'cypress': {
|
|
23
22
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
});
|
|
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
|
+
};
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
34
|
(0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
|
|
@@ -43,6 +40,9 @@ async function addE2e(tree, options) {
|
|
|
43
40
|
tags: [],
|
|
44
41
|
});
|
|
45
42
|
}
|
|
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,17 +78,15 @@ 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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
},
|
|
91
|
-
});
|
|
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
|
+
};
|
|
92
90
|
}
|
|
93
91
|
else {
|
|
94
92
|
(0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
|
|
@@ -97,8 +95,12 @@ async function addE2e(tree, options) {
|
|
|
97
95
|
sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
|
|
98
96
|
targets: {},
|
|
99
97
|
implicitDependencies: [options.projectName],
|
|
98
|
+
tags: [],
|
|
100
99
|
});
|
|
101
100
|
}
|
|
101
|
+
if (!options.useProjectJson || options.isTsSolutionSetup) {
|
|
102
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
|
|
103
|
+
}
|
|
102
104
|
const e2eTask = await configurationGenerator(tree, {
|
|
103
105
|
project: options.e2eProjectName,
|
|
104
106
|
skipFormat: true,
|
|
@@ -135,7 +137,7 @@ async function addE2e(tree, options) {
|
|
|
135
137
|
e2eDirectory: options.e2eProjectRoot,
|
|
136
138
|
appProject: options.projectName,
|
|
137
139
|
appDisplayName: options.displayName,
|
|
138
|
-
appName: options.
|
|
140
|
+
appName: options.simpleName,
|
|
139
141
|
framework: 'expo',
|
|
140
142
|
setParserOptionsProject: options.setParserOptionsProject,
|
|
141
143
|
skipFormat: true,
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addProject = addProject;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const has_expo_plugin_1 = require("../../../utils/has-expo-plugin");
|
|
6
5
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
7
|
-
const
|
|
8
|
-
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
|
6
|
+
const has_expo_plugin_1 = require("../../../utils/has-expo-plugin");
|
|
9
7
|
function addProject(host, options) {
|
|
10
|
-
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
11
8
|
const hasPlugin = (0, has_expo_plugin_1.hasExpoPlugin)(host);
|
|
12
9
|
if (!hasPlugin) {
|
|
13
10
|
(0, target_defaults_utils_1.addBuildTargetDefaults)(host, '@nx/expo:build');
|
|
@@ -19,24 +16,30 @@ function addProject(host, options) {
|
|
|
19
16
|
targets: hasPlugin ? {} : getTargets(options),
|
|
20
17
|
tags: options.parsedTags,
|
|
21
18
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
}
|
|
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
|
+
}
|
|
40
43
|
}
|
|
41
44
|
function getTargets(options) {
|
|
42
45
|
const architect = {};
|
|
@@ -2,17 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createApplicationFiles = createApplicationFiles;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const path_1 = require("path");
|
|
6
5
|
const onboarding_1 = require("nx/src/nx-cloud/utilities/onboarding");
|
|
6
|
+
const path_1 = require("path");
|
|
7
7
|
async function createApplicationFiles(host, options) {
|
|
8
|
-
const packageManagerLockFile = {
|
|
9
|
-
npm: 'package-lock.json',
|
|
10
|
-
yarn: 'yarn.lock',
|
|
11
|
-
pnpm: 'pnpm-lock.yaml',
|
|
12
|
-
bun: 'bun.lockb',
|
|
13
|
-
};
|
|
14
8
|
const packageManager = (0, devkit_1.detectPackageManager)(host.root);
|
|
15
|
-
const packageLockFile = packageManagerLockFile[packageManager];
|
|
16
9
|
const onBoardingStatus = await (0, onboarding_1.createNxCloudOnboardingURLForWelcomeApp)(host, options.nxCloudToken);
|
|
17
10
|
const connectCloudUrl = onBoardingStatus === 'unclaimed' &&
|
|
18
11
|
(await (0, onboarding_1.getNxCloudAppOnBoardingUrl)(options.nxCloudToken));
|
|
@@ -20,14 +13,12 @@ async function createApplicationFiles(host, options) {
|
|
|
20
13
|
...options,
|
|
21
14
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
|
|
22
15
|
packageManager,
|
|
23
|
-
packageLockFile,
|
|
24
16
|
});
|
|
25
17
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `../files/nx-welcome/${onBoardingStatus}`), options.appProjectRoot, {
|
|
26
18
|
...options,
|
|
27
19
|
connectCloudUrl,
|
|
28
20
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
|
|
29
21
|
packageManager,
|
|
30
|
-
packageLockFile,
|
|
31
22
|
});
|
|
32
23
|
if (options.unitTestRunner === 'none') {
|
|
33
24
|
host.delete((0, path_1.join)(options.appProjectRoot, `App.spec.tsx`));
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { Schema } from '../schema';
|
|
3
|
-
export interface NormalizedSchema extends Schema {
|
|
3
|
+
export interface NormalizedSchema extends Omit<Schema, 'name' | 'useTsSolution'> {
|
|
4
4
|
className: string;
|
|
5
|
+
simpleName: string;
|
|
5
6
|
projectName: string;
|
|
6
7
|
appProjectRoot: string;
|
|
8
|
+
importPath: string;
|
|
7
9
|
lowerCaseName: string;
|
|
8
10
|
parsedTags: string[];
|
|
9
11
|
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.
|
|
9
|
-
const { projectName
|
|
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, {
|
|
10
10
|
name: options.name,
|
|
11
11
|
projectType: 'application',
|
|
12
12
|
directory: options.directory,
|
|
@@ -15,27 +15,32 @@ 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)(
|
|
18
|
+
const { className } = (0, devkit_1.names)(projectName);
|
|
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;
|
|
23
26
|
const e2eProjectName = rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
|
24
27
|
const e2eProjectRoot = rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
|
25
28
|
return {
|
|
26
29
|
...options,
|
|
27
30
|
unitTestRunner: options.unitTestRunner || 'jest',
|
|
28
31
|
e2eTestRunner: options.e2eTestRunner || 'none',
|
|
29
|
-
|
|
32
|
+
simpleName: projectNames.projectSimpleName,
|
|
30
33
|
className,
|
|
31
34
|
lowerCaseName: className.toLowerCase(),
|
|
32
35
|
displayName: options.displayName || className,
|
|
33
36
|
projectName: appProjectName,
|
|
34
37
|
appProjectRoot,
|
|
38
|
+
importPath,
|
|
35
39
|
parsedTags,
|
|
36
40
|
rootProject,
|
|
37
41
|
e2eProjectName,
|
|
38
42
|
e2eProjectRoot,
|
|
39
|
-
isTsSolutionSetup
|
|
43
|
+
isTsSolutionSetup,
|
|
44
|
+
useProjectJson,
|
|
40
45
|
};
|
|
41
46
|
}
|
|
@@ -86,6 +86,10 @@
|
|
|
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."
|
|
89
93
|
}
|
|
90
94
|
},
|
|
91
95
|
"required": ["directory"]
|
|
@@ -29,7 +29,9 @@ 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
|
|
32
|
+
const indexFilePath = (0, devkit_1.joinPathFragments)(...(options.projectSourceRoot
|
|
33
|
+
? [options.projectSourceRoot]
|
|
34
|
+
: [options.projectRoot, 'src']), options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
|
|
33
35
|
if (!host.exists(indexFilePath)) {
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# <%=
|
|
1
|
+
# <%= projectName %>
|
|
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 <%=
|
|
7
|
+
Run `nx test <%= projectName %>` to execute the unit tests via [Jest](https://jestjs.io).
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { Schema } from '../schema';
|
|
3
|
-
export interface NormalizedSchema extends Schema {
|
|
4
|
-
name: string;
|
|
3
|
+
export interface NormalizedSchema extends Omit<Schema, 'name'> {
|
|
5
4
|
fileName: string;
|
|
5
|
+
projectName: string;
|
|
6
6
|
projectRoot: string;
|
|
7
|
+
importPath: string;
|
|
7
8
|
routePath: string;
|
|
8
9
|
parsedTags: string[];
|
|
9
|
-
appMain: string;
|
|
10
10
|
isUsingTsSolutionConfig: boolean;
|
|
11
11
|
}
|
|
12
12
|
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -5,7 +5,7 @@ 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.
|
|
8
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
|
|
9
9
|
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
10
10
|
name: options.name,
|
|
11
11
|
projectType: 'library',
|
|
@@ -19,17 +19,18 @@ async function normalizeOptions(host, options) {
|
|
|
19
19
|
const parsedTags = options.tags
|
|
20
20
|
? options.tags.split(',').map((s) => s.trim())
|
|
21
21
|
: [];
|
|
22
|
-
const
|
|
22
|
+
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
23
|
+
const useProjectJson = options.useProjectJson ?? !isUsingTsSolutionConfig;
|
|
23
24
|
const normalized = {
|
|
24
25
|
...options,
|
|
25
26
|
fileName: projectName,
|
|
26
27
|
routePath: `/${projectNames.projectSimpleName}`,
|
|
27
|
-
name: projectName,
|
|
28
|
+
projectName: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
|
|
28
29
|
projectRoot,
|
|
29
30
|
parsedTags,
|
|
30
31
|
importPath,
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
isUsingTsSolutionConfig,
|
|
33
|
+
useProjectJson,
|
|
33
34
|
};
|
|
34
35
|
return normalized;
|
|
35
36
|
}
|
|
@@ -7,18 +7,21 @@ 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");
|
|
11
10
|
const normalize_options_1 = require("./lib/normalize-options");
|
|
12
11
|
const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
|
|
13
12
|
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");
|
|
15
13
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
16
14
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
17
|
-
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
|
18
15
|
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");
|
|
19
21
|
async function expoLibraryGenerator(host, schema) {
|
|
20
22
|
return await expoLibraryGeneratorInternal(host, {
|
|
21
23
|
addPlugin: false,
|
|
24
|
+
useProjectJson: true,
|
|
22
25
|
...schema,
|
|
23
26
|
});
|
|
24
27
|
}
|
|
@@ -33,6 +36,9 @@ async function expoLibraryGeneratorInternal(host, schema) {
|
|
|
33
36
|
if (options.publishable === true && !schema.importPath) {
|
|
34
37
|
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)`);
|
|
35
38
|
}
|
|
39
|
+
if (options.isUsingTsSolutionConfig) {
|
|
40
|
+
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
|
41
|
+
}
|
|
36
42
|
const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
|
|
37
43
|
tasks.push(initTask);
|
|
38
44
|
if (!options.skipPackageJson) {
|
|
@@ -46,20 +52,27 @@ async function expoLibraryGeneratorInternal(host, schema) {
|
|
|
46
52
|
}
|
|
47
53
|
const lintTask = await (0, add_linting_1.addLinting)(host, {
|
|
48
54
|
...options,
|
|
49
|
-
projectName: options.
|
|
55
|
+
projectName: options.projectName,
|
|
50
56
|
tsConfigPaths: [
|
|
51
57
|
(0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
|
|
52
58
|
],
|
|
53
59
|
});
|
|
54
60
|
tasks.push(lintTask);
|
|
55
|
-
const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.
|
|
61
|
+
const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin);
|
|
56
62
|
tasks.push(jestTask);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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);
|
|
60
73
|
if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
|
|
61
74
|
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
62
|
-
(0, devkit_1.joinPathFragments)(options.projectRoot,
|
|
75
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, options.js ? './src/index.js' : './src/index.ts'),
|
|
63
76
|
]);
|
|
64
77
|
}
|
|
65
78
|
(0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
|
|
@@ -69,9 +82,6 @@ async function expoLibraryGeneratorInternal(host, schema) {
|
|
|
69
82
|
}, options.linter === 'eslint'
|
|
70
83
|
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
|
71
84
|
: undefined);
|
|
72
|
-
if (options.isUsingTsSolutionConfig) {
|
|
73
|
-
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
|
74
|
-
}
|
|
75
85
|
(0, sort_fields_1.sortPackageJsonFields)(host, options.projectRoot);
|
|
76
86
|
if (!options.skipFormat) {
|
|
77
87
|
await (0, devkit_1.formatFiles)(host);
|
|
@@ -81,7 +91,7 @@ async function expoLibraryGeneratorInternal(host, schema) {
|
|
|
81
91
|
tasks.push(() => (0, devkit_1.installPackagesTask)(host, true));
|
|
82
92
|
}
|
|
83
93
|
tasks.push(() => {
|
|
84
|
-
(0, log_show_project_command_1.logShowProjectCommand)(options.
|
|
94
|
+
(0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
|
|
85
95
|
});
|
|
86
96
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
87
97
|
}
|
|
@@ -93,61 +103,65 @@ async function addProject(host, options) {
|
|
|
93
103
|
tags: options.parsedTags,
|
|
94
104
|
targets: {},
|
|
95
105
|
};
|
|
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
|
+
};
|
|
96
114
|
if (options.isUsingTsSolutionConfig) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
nx
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
112
|
-
tags: options.parsedTags?.length ? options.parsedTags : undefined,
|
|
113
|
-
},
|
|
114
|
-
});
|
|
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
|
+
}
|
|
115
129
|
}
|
|
116
130
|
else {
|
|
117
|
-
(0, devkit_1.addProjectConfiguration)(host, options.
|
|
131
|
+
(0, devkit_1.addProjectConfiguration)(host, options.projectName, project);
|
|
118
132
|
}
|
|
119
|
-
if (!options.
|
|
120
|
-
|
|
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);
|
|
121
138
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
(0, devkit_1.updateProjectConfiguration)(host, options.name, project);
|
|
150
|
-
return rollupConfigTask;
|
|
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 () => { };
|
|
151
165
|
}
|
|
152
166
|
function updateTsConfig(tree, options) {
|
|
153
167
|
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
|
|
@@ -166,32 +180,35 @@ function updateTsConfig(tree, options) {
|
|
|
166
180
|
function createFiles(host, options) {
|
|
167
181
|
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/lib'), options.projectRoot, {
|
|
168
182
|
...options,
|
|
169
|
-
...(0, devkit_1.names)(options.name),
|
|
170
183
|
tmpl: '',
|
|
171
184
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
172
185
|
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
|
|
173
186
|
});
|
|
174
|
-
if (!options.publishable && !options.buildable) {
|
|
175
|
-
host.delete(`${options.projectRoot}/package.json`);
|
|
176
|
-
}
|
|
177
187
|
if (options.js) {
|
|
178
188
|
(0, devkit_1.toJS)(host);
|
|
179
189
|
}
|
|
180
190
|
updateTsConfig(host, options);
|
|
181
191
|
}
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
function determineEntryFields(options) {
|
|
193
|
+
if (options.buildable ||
|
|
194
|
+
options.publishable ||
|
|
195
|
+
!options.isUsingTsSolutionConfig) {
|
|
196
|
+
// For buildable libraries, the entries are configured by the bundler (i.e. Rollup).
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
main: options.js ? './src/index.js' : './src/index.ts',
|
|
201
|
+
types: options.js ? './src/index.js' : './src/index.ts',
|
|
202
|
+
exports: {
|
|
203
|
+
'.': options.js
|
|
204
|
+
? './src/index.js'
|
|
205
|
+
: {
|
|
206
|
+
types: './src/index.ts',
|
|
207
|
+
import: './src/index.ts',
|
|
208
|
+
default: './src/index.ts',
|
|
209
|
+
},
|
|
210
|
+
'./package.json': './package.json',
|
|
211
|
+
},
|
|
212
|
+
};
|
|
196
213
|
}
|
|
197
214
|
exports.default = expoLibraryGenerator;
|
|
@@ -89,6 +89,10 @@
|
|
|
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."
|
|
92
96
|
}
|
|
93
97
|
},
|
|
94
98
|
"required": ["directory"]
|