fix(js): generate ts standalone project with better import path (#18197)
This commit is contained in:
parent
54dcc0f8be
commit
810b584c33
@ -79,7 +79,7 @@ describe('Storybook generators and executors for standalone workspaces - using R
|
|||||||
writeFileSync(
|
writeFileSync(
|
||||||
tmpProjPath(`src/app/test-button.tsx`),
|
tmpProjPath(`src/app/test-button.tsx`),
|
||||||
`
|
`
|
||||||
import { MyLib } from '@${appName}/my-lib';
|
import { MyLib } from 'my-lib';
|
||||||
|
|
||||||
export function TestButton() {
|
export function TestButton() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -383,6 +383,33 @@ describe('lib', () => {
|
|||||||
|
|
||||||
expect.assertions(1);
|
expect.assertions(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should provide a default import path using npm scope', async () => {
|
||||||
|
await libraryGenerator(tree, {
|
||||||
|
...defaultOptions,
|
||||||
|
name: 'myLib',
|
||||||
|
});
|
||||||
|
|
||||||
|
const tsconfigJson = readJson(tree, '/tsconfig.base.json');
|
||||||
|
expect(
|
||||||
|
tsconfigJson.compilerOptions.paths['@proj/my-lib']
|
||||||
|
).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should read import path from existing name in package.json', async () => {
|
||||||
|
updateJson(tree, 'package.json', (json) => {
|
||||||
|
json.name = '@acme/core';
|
||||||
|
return json;
|
||||||
|
});
|
||||||
|
await libraryGenerator(tree, {
|
||||||
|
...defaultOptions,
|
||||||
|
rootProject: true,
|
||||||
|
name: 'myLib',
|
||||||
|
});
|
||||||
|
|
||||||
|
const tsconfigJson = readJson(tree, '/tsconfig.base.json');
|
||||||
|
expect(tsconfigJson.compilerOptions.paths['@acme/core']).toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('--pascalCaseFiles', () => {
|
describe('--pascalCaseFiles', () => {
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
names,
|
names,
|
||||||
offsetFromRoot,
|
offsetFromRoot,
|
||||||
ProjectConfiguration,
|
ProjectConfiguration,
|
||||||
|
readJson,
|
||||||
runTasksInSerial,
|
runTasksInSerial,
|
||||||
toJS,
|
toJS,
|
||||||
Tree,
|
Tree,
|
||||||
@ -35,8 +36,6 @@ import {
|
|||||||
swcHelpersVersion,
|
swcHelpersVersion,
|
||||||
tsLibVersion,
|
tsLibVersion,
|
||||||
typesNodeVersion,
|
typesNodeVersion,
|
||||||
swcNodeVersion,
|
|
||||||
swcCoreVersion,
|
|
||||||
} from '../../utils/versions';
|
} from '../../utils/versions';
|
||||||
import jsInitGenerator from '../init/init';
|
import jsInitGenerator from '../init/init';
|
||||||
import { type PackageJson } from 'nx/src/utils/package-json';
|
import { type PackageJson } from 'nx/src/utils/package-json';
|
||||||
@ -539,8 +538,9 @@ function normalizeOptions(
|
|||||||
? options.tags.split(',').map((s) => s.trim())
|
? options.tags.split(',').map((s) => s.trim())
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const importPath =
|
const importPath = options.rootProject
|
||||||
options.importPath || getImportPath(tree, projectDirectory);
|
? readJson(tree, 'package.json').name ?? getImportPath(tree, 'core')
|
||||||
|
: options.importPath || getImportPath(tree, projectDirectory);
|
||||||
|
|
||||||
options.minimal ??= false;
|
options.minimal ??= false;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@<%= formattedNames.fileName %>/source",
|
"name": "<%= formattedNames.fileName %>",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user