diff --git a/packages/remix/src/generators/library/lib/add-tsconfig-entry-points.ts b/packages/remix/src/generators/library/lib/add-tsconfig-entry-points.ts index f1081b544c91f..891bf3a1c78b8 100644 --- a/packages/remix/src/generators/library/lib/add-tsconfig-entry-points.ts +++ b/packages/remix/src/generators/library/lib/add-tsconfig-entry-points.ts @@ -6,12 +6,16 @@ import { } from '@nx/devkit'; import { getRootTsConfigPathInTree } from '@nx/js'; import type { RemixLibraryOptions } from './normalize-options'; +import { resolveImportPath } from '@nx/devkit/src/generators/project-name-and-root-utils'; export function addTsconfigEntryPoints( tree: Tree, options: RemixLibraryOptions ) { - const { sourceRoot } = readProjectConfiguration(tree, options.projectName); + const { root: projectRoot, sourceRoot } = readProjectConfiguration( + tree, + options.projectName + ); const serverFilePath = joinPathFragments(sourceRoot, 'server.ts'); tree.write( @@ -20,14 +24,13 @@ export function addTsconfigEntryPoints( ); const baseTsConfig = getRootTsConfigPathInTree(tree); + // Use same logic as `determineProjectNameAndRootOptions` to get the import path + const importPath = resolveImportPath(tree, options.name, projectRoot); updateJson(tree, baseTsConfig, (json) => { - if ( - json.compilerOptions.paths && - json.compilerOptions.paths[options.importPath] - ) { - json.compilerOptions.paths[ - joinPathFragments(options.importPath, 'server') - ] = [serverFilePath]; + if (json.compilerOptions.paths && json.compilerOptions.paths[importPath]) { + json.compilerOptions.paths[joinPathFragments(importPath, 'server')] = [ + serverFilePath, + ]; } return json; diff --git a/packages/remix/src/generators/library/lib/normalize-options.ts b/packages/remix/src/generators/library/lib/normalize-options.ts index 8351fc042f134..ebbf1ff26d0d7 100644 --- a/packages/remix/src/generators/library/lib/normalize-options.ts +++ b/packages/remix/src/generators/library/lib/normalize-options.ts @@ -3,7 +3,6 @@ import { determineProjectNameAndRootOptions, ensureProjectName, } from '@nx/devkit/src/generators/project-name-and-root-utils'; -import { getImportPath } from '@nx/js/src/utils/get-import-path'; import type { NxRemixGeneratorSchema } from '../schema'; export interface RemixLibraryOptions extends NxRemixGeneratorSchema { @@ -31,12 +30,9 @@ export async function normalizeOptions( nxJson.useInferencePlugins !== false; options.addPlugin ??= addPluginDefault; - const importPath = options.importPath ?? getImportPath(tree, projectRoot); - return { ...options, unitTestRunner: options.unitTestRunner ?? 'vitest', - importPath, projectName, projectRoot, }; diff --git a/packages/remix/src/generators/library/library.impl.spec.ts b/packages/remix/src/generators/library/library.impl.spec.ts index 6c983760de0d6..d52397d20cc6f 100644 --- a/packages/remix/src/generators/library/library.impl.spec.ts +++ b/packages/remix/src/generators/library/library.impl.spec.ts @@ -1,6 +1,12 @@ import 'nx/src/internal-testing-utils/mock-project-graph'; -import { readJson, readProjectConfiguration } from '@nx/devkit'; +import { + readJson, + readProjectConfiguration, + Tree, + updateJson, + writeJson, +} from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import applicationGenerator from '../application/application.impl'; import libraryGenerator from './library.impl'; @@ -129,4 +135,48 @@ describe('Remix Library Generator', () => { expect(pkgJson.main).toEqual('./dist/index.cjs.js'); expect(pkgJson.typings).toEqual('./dist/index.d.ts'); }); + describe('TS solution setup', () => { + let tree: Tree; + + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + updateJson(tree, 'package.json', (json) => { + json.workspaces = ['packages/*', 'apps/*']; + return json; + }); + writeJson(tree, 'tsconfig.base.json', { + compilerOptions: { + composite: true, + declaration: true, + }, + }); + writeJson(tree, 'tsconfig.json', { + extends: './tsconfig.base.json', + files: [], + references: [], + }); + }); + + it('should generate valid package.json', async () => { + await libraryGenerator(tree, { + directory: 'packages/foo', + style: 'css', + addPlugin: true, + }); + + expect(readJson(tree, 'packages/foo/package.json')) + .toMatchInlineSnapshot(` + { + "main": "./src/index.ts", + "name": "@proj/foo", + "nx": { + "name": "foo", + "projectType": "library", + "sourceRoot": "packages/foo/src", + }, + "types": "./src/index.ts", + } + `); + }); + }); }); diff --git a/packages/remix/src/generators/library/library.impl.ts b/packages/remix/src/generators/library/library.impl.ts index 1f0553763b160..93bb3a565948a 100644 --- a/packages/remix/src/generators/library/library.impl.ts +++ b/packages/remix/src/generators/library/library.impl.ts @@ -32,12 +32,12 @@ export async function remixLibraryGeneratorInternal( tasks.push(jsInitTask); const libGenTask = await libraryGenerator(tree, { - name: options.projectName, + directory: options.directory, + name: options.name, style: options.style, unitTestRunner: options.unitTestRunner, tags: options.tags, importPath: options.importPath, - directory: options.projectRoot, skipFormat: true, skipTsConfig: false, linter: options.linter,