From 51d9d829af75685eaf4a2b13c6748b3d09065be3 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Tue, 5 Sep 2023 10:03:09 -0400 Subject: [PATCH] fix(js): change TS standalone preset to generate at the root --- .../src/create-nx-workspace.test.ts | 15 +++++++ lerna.json | 11 +---- .../bin/create-nx-workspace.ts | 40 ++++++++++--------- .../workspace/src/generators/preset/preset.ts | 2 +- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/e2e/workspace-create/src/create-nx-workspace.test.ts b/e2e/workspace-create/src/create-nx-workspace.test.ts index 601f84721fc01c..581d3a7f6f14c2 100644 --- a/e2e/workspace-create/src/create-nx-workspace.test.ts +++ b/e2e/workspace-create/src/create-nx-workspace.test.ts @@ -351,6 +351,21 @@ describe('create-nx-workspace', () => { expectCodeIsFormatted(); }); + it('should be able to create a ts standalone workspace', () => { + const wsName = uniq('pkg'); + + runCreateWorkspace(wsName, { + preset: 'ts-standalone', + packageManager, + extraArgs: `--no-js`, + }); + + checkFilesExist('package.json'); + checkFilesExist('project.json'); + checkFilesExist('src/index.ts'); + expectCodeIsFormatted(); + }); + it('should respect package manager preference', () => { const wsName = uniq('pm'); diff --git a/lerna.json b/lerna.json index 7aacb77687b732..5c60aa676a9857 100644 --- a/lerna.json +++ b/lerna.json @@ -1,10 +1 @@ -{ - "packages": ["build/packages/*", "build/packages/nx/native-packages/*"], - "version": "16.8.0-beta.7", - "granularPathspec": false, - "command": { - "publish": { - "graphType": "all" - } - } -} +{"packages":["build/packages/*","build/packages/nx/native-packages/*"],"version":"16.7.4","granularPathspec":false,"command":{"publish":{"graphType":"all"}}} \ No newline at end of file diff --git a/packages/create-nx-workspace/bin/create-nx-workspace.ts b/packages/create-nx-workspace/bin/create-nx-workspace.ts index 025aca3f012061..74b9fcd2cf5445 100644 --- a/packages/create-nx-workspace/bin/create-nx-workspace.ts +++ b/packages/create-nx-workspace/bin/create-nx-workspace.ts @@ -450,26 +450,30 @@ async function determineNoneOptions( if (parsedArgs.js !== undefined) { js = parsedArgs.js; - } else if (preset === Preset.TsStandalone) { + } + + if (preset === Preset.TsStandalone) { // Only standalone TS preset generates a default package, so we need to provide --js and --appName options. appName = parsedArgs.name; - const reply = await enquirer.prompt<{ ts: 'Yes' | 'No' }>([ - { - name: 'ts', - message: `Would you like to use TypeScript with this project?`, - type: 'autocomplete', - choices: [ - { - name: 'Yes', - }, - { - name: 'No', - }, - ], - initial: 'Yes' as any, - }, - ]); - js = reply.ts === 'No'; + if (js === undefined) { + const reply = await enquirer.prompt<{ ts: 'Yes' | 'No' }>([ + { + name: 'ts', + message: `Would you like to use TypeScript with this project?`, + type: 'autocomplete', + choices: [ + { + name: 'Yes', + }, + { + name: 'No', + }, + ], + initial: 'Yes' as any, + }, + ]); + js = reply.ts === 'No'; + } } return { preset, js, appName }; diff --git a/packages/workspace/src/generators/preset/preset.ts b/packages/workspace/src/generators/preset/preset.ts index b3e722bcb9857b..285d861d76814d 100644 --- a/packages/workspace/src/generators/preset/preset.ts +++ b/packages/workspace/src/generators/preset/preset.ts @@ -169,7 +169,7 @@ async function createPreset(tree: Tree, options: Schema) { const { libraryGenerator } = require('@nx' + '/js'); return libraryGenerator(tree, { name: options.name, - directory: join('packages', options.name), + directory: '.', projectNameAndRootFormat: 'as-provided', bundler: 'tsc', unitTestRunner: 'vitest',