Skip to content

Commit 59b78b0

Browse files
committed
feat(js): remove nx property from package.json
1 parent 251e95d commit 59b78b0

File tree

27 files changed

+208
-160
lines changed

27 files changed

+208
-160
lines changed

packages/js/src/generators/library/library.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import type {
6868
NormalizedLibraryGeneratorOptions,
6969
} from './schema';
7070
import { sortPackageJsonFields } from '../../utils/package-json/sort-fields';
71+
import { getImportPath } from '../../utils/get-import-path';
7172

7273
const defaultOutputDirectory = 'dist';
7374

@@ -365,8 +366,20 @@ async function configureProject(
365366
delete projectConfiguration.tags;
366367
}
367368

369+
// We want a minimal setup, so unless targets and tags are set, just skip the `nx` property in `package.json`.
370+
if (options.isUsingTsSolutionConfig) {
371+
delete projectConfiguration.projectType;
372+
delete projectConfiguration.sourceRoot;
373+
}
374+
368375
// empty targets are cleaned up automatically by `updateProjectConfiguration`
369-
updateProjectConfiguration(tree, options.name, projectConfiguration);
376+
updateProjectConfiguration(
377+
tree,
378+
options.isUsingTsSolutionConfig
379+
? options.importPath ?? options.name
380+
: options.name,
381+
projectConfiguration
382+
);
370383
} else if (options.config === 'workspace' || options.config === 'project') {
371384
addProjectConfiguration(tree, options.name, projectConfiguration);
372385
} else {
@@ -889,7 +902,9 @@ async function normalizeOptions(
889902
return {
890903
...options,
891904
fileName,
892-
name: projectName,
905+
name: isUsingTsSolutionConfig
906+
? getImportPath(tree, projectName)
907+
: projectName,
893908
projectNames,
894909
projectRoot,
895910
parsedTags,

packages/nest/src/generators/library/lib/normalize-options.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope';
77
import type { LibraryGeneratorSchema as JsLibraryGeneratorSchema } from '@nx/js/src/generators/library/schema';
88
import { Linter } from '@nx/eslint';
99
import type { LibraryGeneratorOptions, NormalizedOptions } from '../schema';
10+
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
11+
import { getImportPath } from '@nx/js/src/utils/get-import-path';
1012

1113
export async function normalizeOptions(
1214
tree: Tree,
@@ -47,7 +49,9 @@ export async function normalizeOptions(
4749
linter: options.linter ?? Linter.EsLint,
4850
parsedTags,
4951
prefix: getNpmScope(tree), // we could also allow customizing this
50-
projectName,
52+
projectName: isUsingTsSolutionSetup(tree)
53+
? getImportPath(tree, projectName)
54+
: projectName,
5155
projectRoot,
5256
importPath,
5357
service: options.service ?? false,

packages/node/src/generators/library/library.spec.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ describe('lib', () => {
563563
"main",
564564
"types",
565565
"exports",
566-
"nx",
567566
"dependencies",
568567
]
569568
`);
@@ -580,11 +579,6 @@ describe('lib', () => {
580579
},
581580
"main": "./src/index.ts",
582581
"name": "@proj/mylib",
583-
"nx": {
584-
"name": "mylib",
585-
"projectType": "library",
586-
"sourceRoot": "mylib/src",
587-
},
588582
"private": true,
589583
"types": "./src/index.ts",
590584
"version": "0.0.1",
@@ -684,9 +678,6 @@ describe('lib', () => {
684678
"module": "./dist/index.js",
685679
"name": "@proj/mylib",
686680
"nx": {
687-
"name": "mylib",
688-
"projectType": "library",
689-
"sourceRoot": "mylib/src",
690681
"targets": {
691682
"build": {
692683
"executor": "@nx/js:swc",

packages/node/src/generators/library/library.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export async function libraryGenerator(tree: Tree, schema: Schema) {
5454

5555
export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
5656
const options = await normalizeOptions(tree, schema);
57+
58+
// If we are using the new TS solution
59+
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
60+
if (options.isUsingTsSolutionConfig) {
61+
addProjectToTsSolutionWorkspace(tree, options.projectRoot);
62+
}
63+
5764
const tasks: GeneratorCallback[] = [];
5865

5966
if (options.publishable === true && !schema.importPath) {
@@ -112,12 +119,6 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
112119
tasks.push(() => installPackagesTask(tree, true));
113120
}
114121

115-
// If we are using the new TS solution
116-
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
117-
if (options.isUsingTsSolutionConfig) {
118-
addProjectToTsSolutionWorkspace(tree, options.projectRoot);
119-
}
120-
121122
sortPackageJsonFields(tree, options.projectRoot);
122123

123124
if (!schema.skipFormat) {
@@ -163,14 +164,17 @@ async function normalizeOptions(
163164
? options.tags.split(',').map((s) => s.trim())
164165
: [];
165166

167+
const isUsingTsSolutionConfig = isUsingTsSolutionSetup(tree);
166168
return {
167169
...options,
168170
fileName,
169-
projectName,
171+
projectName: isUsingTsSolutionConfig
172+
? getImportPath(tree, projectName)
173+
: projectName,
170174
projectRoot,
171175
parsedTags,
172176
importPath,
173-
isUsingTsSolutionConfig: isUsingTsSolutionSetup(tree),
177+
isUsingTsSolutionConfig,
174178
};
175179
}
176180

packages/react-native/src/generators/application/application.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ export async function reactNativeApplicationGeneratorInternal(
8282
options.appProjectRoot,
8383
options.js,
8484
options.skipPackageJson,
85-
options.addPlugin
85+
options.addPlugin,
86+
'tsconfig.app.json'
8687
);
8788
tasks.push(jestTask);
8889

8990
const webTask = await webConfigurationGenerator(host, {
9091
...options,
91-
project: options.name,
92+
project: options.projectName,
9293
skipFormat: true,
9394
});
9495
tasks.push(webTask);

packages/react-native/src/generators/application/lib/add-project.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ export function addProject(host: Tree, options: NormalizedSchema) {
2929

3030
if (isUsingTsSolutionSetup(host)) {
3131
writeJson(host, joinPathFragments(options.appProjectRoot, 'package.json'), {
32-
name: getImportPath(host, options.name),
32+
name: options.projectName,
3333
version: '0.0.1',
3434
private: true,
3535
nx: {
36-
name: options.name,
37-
projectType: 'application',
38-
sourceRoot: `${options.appProjectRoot}/src`,
3936
targets: hasPlugin ? {} : getTargets(options),
4037
tags: options.parsedTags?.length ? options.parsedTags : undefined,
4138
},

packages/react-native/src/generators/application/lib/normalize-options.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@nx/devkit/src/generators/project-name-and-root-utils';
66
import { Schema } from '../schema';
77
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
8+
import { getImportPath } from '@nx/js/src/utils/get-import-path';
89

910
export interface NormalizedSchema extends Schema {
1011
className: string; // app name in class case
@@ -56,14 +57,18 @@ export async function normalizeOptions(
5657

5758
const entryFile = options.js ? 'src/main.js' : 'src/main.tsx';
5859

60+
const isTsSolutionSetup = isUsingTsSolutionSetup(host);
61+
5962
return {
6063
...options,
6164
name: projectNames.projectSimpleName,
6265
className,
6366
fileName,
6467
lowerCaseName: className.toLowerCase(),
6568
displayName: options.displayName || className,
66-
projectName: appProjectName,
69+
projectName: isTsSolutionSetup
70+
? getImportPath(host, appProjectName)
71+
: appProjectName,
6772
appProjectRoot,
6873
iosProjectRoot,
6974
androidProjectRoot,
@@ -72,6 +77,6 @@ export async function normalizeOptions(
7277
rootProject,
7378
e2eProjectName,
7479
e2eProjectRoot,
75-
isTsSolutionSetup: isUsingTsSolutionSetup(host),
80+
isTsSolutionSetup,
7681
};
7782
}

packages/react-native/src/generators/library/lib/normalize-options.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@nx/devkit/src/generators/project-name-and-root-utils';
66
import { Schema } from '../schema';
77
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
8+
import { getImportPath } from '@nx/js/src/utils/get-import-path';
89

910
export interface NormalizedSchema extends Schema {
1011
name: string;
@@ -44,15 +45,18 @@ export async function normalizeOptions(
4445
? options.tags.split(',').map((s) => s.trim())
4546
: [];
4647

48+
const isUsingTsSolutionConfig = isUsingTsSolutionSetup(host);
4749
const normalized: NormalizedSchema = {
4850
...options,
4951
fileName: projectName,
5052
routePath: `/${projectNames.projectSimpleName}`,
51-
name: projectName,
53+
name: isUsingTsSolutionConfig
54+
? getImportPath(host, projectName)
55+
: projectName,
5256
projectRoot,
5357
parsedTags,
5458
importPath,
55-
isUsingTsSolutionConfig: isUsingTsSolutionSetup(host),
59+
isUsingTsSolutionConfig,
5660
};
5761

5862
return normalized;

packages/react-native/src/generators/library/library.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export async function reactNativeLibraryGeneratorInternal(
101101
options.projectRoot,
102102
options.js,
103103
options.skipPackageJson,
104-
options.addPlugin
104+
options.addPlugin,
105+
'tsconfig.lib.json'
105106
);
106107
tasks.push(jestTask);
107108

@@ -171,14 +172,11 @@ async function addProject(
171172
'package.json'
172173
);
173174
if (options.isUsingTsSolutionConfig) {
174-
writeJson(host, packageJsonPath, {
175-
name: getImportPath(host, options.name),
175+
writeJson(host, joinPathFragments(options.projectRoot, 'package.json'), {
176+
name: options.name,
176177
version: '0.0.1',
177178
...determineEntryFields(options),
178179
nx: {
179-
name: options.name,
180-
sourceRoot: joinPathFragments(options.projectRoot, 'src'),
181-
projectType: 'library',
182180
tags: options.parsedTags?.length ? options.parsedTags : undefined,
183181
},
184182
});

packages/react-native/src/utils/add-jest.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export async function addJest(
88
appProjectRoot: string,
99
js: boolean,
1010
skipPackageJson: boolean,
11-
addPlugin: boolean
11+
addPlugin: boolean,
12+
runtimeTsconfigFileName: string
1213
) {
1314
if (unitTestRunner !== 'jest') {
1415
return () => {};
@@ -24,6 +25,7 @@ export async function addJest(
2425
skipPackageJson,
2526
skipFormat: true,
2627
addPlugin,
28+
runtimeTsconfigFileName,
2729
});
2830

2931
// overwrite the jest.config.ts file because react native needs to have special transform property

0 commit comments

Comments
 (0)