Skip to content

Commit

Permalink
fix(js): change TS standalone preset to generate at the root
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Sep 5, 2023
1 parent 99eebfb commit 51d9d82
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
15 changes: 15 additions & 0 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
11 changes: 1 addition & 10 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -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"}}}
40 changes: 22 additions & 18 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 51d9d82

Please sign in to comment.