@nx/expo 0.0.0-pr-3-e51e28c → 0.0.0-pr-30418-4e2b721
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/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 +2 -3
- package/src/generators/library/lib/normalize-options.js +4 -8
- package/src/generators/library/library.js +88 -89
- 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": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-30418-4e2b721",
|
|
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-
|
|
32
|
-
"@nx/eslint": "0.0.0-pr-
|
|
33
|
-
"@nx/jest": "0.0.0-pr-
|
|
34
|
-
"@nx/js": "0.0.0-pr-
|
|
35
|
-
"@nx/react": "0.0.0-pr-
|
|
36
|
-
"@nx/web": "0.0.0-pr-
|
|
37
|
-
"@nx/webpack": "0.0.0-pr-
|
|
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",
|
|
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 = {};
|
|
@@ -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,13 +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;
|
|
6
5
|
projectName: string;
|
|
7
6
|
projectRoot: string;
|
|
7
|
+
importPath: string;
|
|
8
8
|
routePath: string;
|
|
9
9
|
parsedTags: string[];
|
|
10
|
-
appMain: string;
|
|
11
10
|
isUsingTsSolutionConfig: boolean;
|
|
12
11
|
}
|
|
13
12
|
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -4,9 +4,8 @@ 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");
|
|
8
7
|
async function normalizeOptions(host, options) {
|
|
9
|
-
await (0, project_name_and_root_utils_1.
|
|
8
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
|
|
10
9
|
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
11
10
|
name: options.name,
|
|
12
11
|
projectType: 'library',
|
|
@@ -20,21 +19,18 @@ async function normalizeOptions(host, options) {
|
|
|
20
19
|
const parsedTags = options.tags
|
|
21
20
|
? options.tags.split(',').map((s) => s.trim())
|
|
22
21
|
: [];
|
|
23
|
-
const appMain = options.js ? 'src/index.js' : 'src/index.ts';
|
|
24
22
|
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
23
|
+
const useProjectJson = options.useProjectJson ?? !isUsingTsSolutionConfig;
|
|
25
24
|
const normalized = {
|
|
26
25
|
...options,
|
|
27
26
|
fileName: projectName,
|
|
28
27
|
routePath: `/${projectNames.projectSimpleName}`,
|
|
29
|
-
name: projectName,
|
|
30
|
-
projectName: isUsingTsSolutionConfig
|
|
31
|
-
? (0, get_import_path_1.getImportPath)(host, projectName)
|
|
32
|
-
: projectName,
|
|
28
|
+
projectName: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
|
|
33
29
|
projectRoot,
|
|
34
30
|
parsedTags,
|
|
35
31
|
importPath,
|
|
36
|
-
appMain,
|
|
37
32
|
isUsingTsSolutionConfig,
|
|
33
|
+
useProjectJson,
|
|
38
34
|
};
|
|
39
35
|
return normalized;
|
|
40
36
|
}
|
|
@@ -7,17 +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
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");
|
|
18
21
|
async function expoLibraryGenerator(host, schema) {
|
|
19
22
|
return await expoLibraryGeneratorInternal(host, {
|
|
20
23
|
addPlugin: false,
|
|
24
|
+
useProjectJson: true,
|
|
21
25
|
...schema,
|
|
22
26
|
});
|
|
23
27
|
}
|
|
@@ -33,7 +37,7 @@ async function expoLibraryGeneratorInternal(host, schema) {
|
|
|
33
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)`);
|
|
34
38
|
}
|
|
35
39
|
if (options.isUsingTsSolutionConfig) {
|
|
36
|
-
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
|
40
|
+
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
|
37
41
|
}
|
|
38
42
|
const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
|
|
39
43
|
tasks.push(initTask);
|
|
@@ -56,12 +60,19 @@ async function expoLibraryGeneratorInternal(host, schema) {
|
|
|
56
60
|
tasks.push(lintTask);
|
|
57
61
|
const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin);
|
|
58
62
|
tasks.push(jestTask);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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);
|
|
62
73
|
if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
|
|
63
74
|
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
64
|
-
(0, devkit_1.joinPathFragments)(options.projectRoot,
|
|
75
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, options.js ? './src/index.js' : './src/index.ts'),
|
|
65
76
|
]);
|
|
66
77
|
}
|
|
67
78
|
(0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
|
|
@@ -80,7 +91,7 @@ async function expoLibraryGeneratorInternal(host, schema) {
|
|
|
80
91
|
tasks.push(() => (0, devkit_1.installPackagesTask)(host, true));
|
|
81
92
|
}
|
|
82
93
|
tasks.push(() => {
|
|
83
|
-
(0, log_show_project_command_1.logShowProjectCommand)(options.
|
|
94
|
+
(0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
|
|
84
95
|
});
|
|
85
96
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
86
97
|
}
|
|
@@ -92,72 +103,65 @@ async function addProject(host, options) {
|
|
|
92
103
|
tags: options.parsedTags,
|
|
93
104
|
targets: {},
|
|
94
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
|
+
};
|
|
95
114
|
if (options.isUsingTsSolutionConfig) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
});
|
|
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
|
+
}
|
|
125
129
|
}
|
|
126
130
|
else {
|
|
127
|
-
(0, devkit_1.addProjectConfiguration)(host, options.
|
|
131
|
+
(0, devkit_1.addProjectConfiguration)(host, options.projectName, project);
|
|
128
132
|
}
|
|
129
|
-
if (!options.
|
|
130
|
-
|
|
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);
|
|
131
138
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
};
|
|
159
|
-
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
|
|
160
|
-
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 () => { };
|
|
161
165
|
}
|
|
162
166
|
function updateTsConfig(tree, options) {
|
|
163
167
|
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
|
|
@@ -176,34 +180,29 @@ function updateTsConfig(tree, options) {
|
|
|
176
180
|
function createFiles(host, options) {
|
|
177
181
|
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files/lib'), options.projectRoot, {
|
|
178
182
|
...options,
|
|
179
|
-
...(0, devkit_1.names)(options.name),
|
|
180
183
|
tmpl: '',
|
|
181
184
|
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
182
185
|
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
|
|
183
186
|
});
|
|
184
|
-
if (!options.publishable &&
|
|
185
|
-
!options.buildable &&
|
|
186
|
-
!options.isUsingTsSolutionConfig) {
|
|
187
|
-
host.delete(`${options.projectRoot}/package.json`);
|
|
188
|
-
}
|
|
189
187
|
if (options.js) {
|
|
190
188
|
(0, devkit_1.toJS)(host);
|
|
191
189
|
}
|
|
192
190
|
updateTsConfig(host, options);
|
|
193
191
|
}
|
|
194
|
-
function
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
'
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
};
|
|
208
207
|
}
|
|
209
208
|
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"]
|