Skip to content

Commit

Permalink
Merge branch 'master' into extract-affected-js
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Apr 18, 2023
2 parents a3f0677 + 0d561ef commit c74e78b
Show file tree
Hide file tree
Showing 114 changed files with 663 additions and 550 deletions.
2 changes: 1 addition & 1 deletion e2e/nx-misc/src/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Nx Commands', () => {
expect(listOutput).toContain('NX Installed plugins');

// just check for some, not all
expect(listOutput).toContain('@nrwl/workspace');
expect(listOutput).toContain('@nx/workspace');

// temporarily make it look like this isn't installed
renameSync(
Expand Down
8 changes: 8 additions & 0 deletions nx-dev/nx-dev/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ module.exports = withNx({
permanent: true,
});
}
// Tutorials / Getting started
for (let s of Object.keys(redirectRules.conceptUrls)) {
rules.push({
source: s,
destination: redirectRules.conceptUrls[s],
permanent: true,
});
}

// Packages Indexes
for (let s of Object.keys(redirectRules.packagesIndexes)) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@babel/preset-typescript": "^7.15.0",
"@cypress/react": "^6.0.0",
"@floating-ui/react": "0.19.2",
"@monodon/rust": "1.1.1",
"@monodon/rust": "1.1.2",
"@napi-rs/cli": "2.14.0",
"@nestjs/cli": "^9.0.0",
"@nestjs/common": "^9.0.0",
Expand Down Expand Up @@ -94,7 +94,7 @@
"@svgr/webpack": "^6.1.2",
"@swc-node/register": "^1.4.2",
"@swc/cli": "~0.1.55",
"@swc/core": "^1.2.173",
"@swc/core": "^1.3.51",
"@swc/jest": "^0.2.20",
"@testing-library/react": "13.4.0",
"@types/css-minimizer-webpack-plugin": "^3.0.2",
Expand Down Expand Up @@ -282,7 +282,7 @@
"@markdoc/markdoc": "0.2.2",
"@monaco-editor/react": "^4.4.6",
"@napi-rs/canvas": "^0.1.19",
"@swc/helpers": "~0.4.11",
"@swc/helpers": "~0.5.0",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/line-clamp": "^0.4.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-nx-plugin/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"rules": {
"no-restricted-imports": [
"error",
"@nrwl/workspace",
"@nx/workspace",
"@angular-devkit/core",
"@angular-devkit/architect",
"@angular-devkit/schematics",
"nx",
"@nrwl/devkit"
"@nx/devkit"
]
},
"ignorePatterns": ["!**/*"],
Expand Down
33 changes: 32 additions & 1 deletion packages/create-nx-plugin/bin/create-nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import { createWorkspace, CreateWorkspaceOptions } from 'create-nx-workspace';
import { output } from 'create-nx-workspace/src/utils/output';
import { CI } from 'create-nx-workspace/src/utils/ci/ci-list';
import type { PackageManager } from 'create-nx-workspace/src/utils/package-manager';
import { showNxWarning } from 'create-nx-workspace/src/utils/nx/show-nx-warning';
import { printNxCloudSuccessMessage } from 'create-nx-workspace/src/utils/nx/nx-cloud';
import {
messages,
recordStat,
} from 'create-nx-workspace/src/utils/nx/ab-testing';

export const yargsDecorator = {
'Options:': `${chalk.green`Options`}:`,
Expand Down Expand Up @@ -120,7 +126,32 @@ async function main(parsedArgs: yargs.Arguments<CreateNxPluginArguments>) {
? parsedArgs.pluginName.split('/')[1]
: parsedArgs.pluginName,
};
await createWorkspace('@nrwl/nx-plugin', populatedArguments);

output.log({
title: `Creating an Nx v${nxVersion} plugin.`,
bodyLines: [
'To make sure the command works reliably in all environments, and that the preset is applied correctly,',
`Nx will run "${parsedArgs.packageManager} install" several times. Please wait.`,
],
});

const workspaceInfo = await createWorkspace(
'@nx/nx-plugin',
populatedArguments
);

showNxWarning(parsedArgs.pluginName);

await recordStat({
nxVersion,
command: 'create-nx-workspace',
useCloud: parsedArgs.nxCloud,
meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'),
});

if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) {
printNxCloudSuccessMessage(workspaceInfo.nxCloudInfo);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"rules": {
"no-restricted-imports": [
"error",
"@nrwl/workspace",
"@nx/workspace",
"@angular-devkit/core",
"@angular-devkit/architect",
"@angular-devkit/schematics",
"nx",
"@nrwl/devkit"
"@nx/devkit"
]
},
"ignorePatterns": ["!**/*"],
Expand Down
29 changes: 28 additions & 1 deletion packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
withOptions,
withPackageManager,
} from '../src/internal-utils/yargs-options';
import { showNxWarning } from '../src/utils/nx/show-nx-warning';
import { printNxCloudSuccessMessage } from '../src/utils/nx/nx-cloud';
import { messages, recordStat } from '../src/utils/nx/ab-testing';

interface Arguments extends CreateWorkspaceOptions {
preset: string;
Expand Down Expand Up @@ -129,7 +132,31 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
) as yargs.Argv<Arguments>;

async function main(parsedArgs: yargs.Arguments<Arguments>) {
await createWorkspace<Arguments>(parsedArgs.preset, parsedArgs);
output.log({
title: `Creating your v${nxVersion} workspace.`,
bodyLines: [
'To make sure the command works reliably in all environments, and that the preset is applied correctly,',
`Nx will run "${parsedArgs.packageManager} install" several times. Please wait.`,
],
});

const workspaceInfo = await createWorkspace<Arguments>(
parsedArgs.preset,
parsedArgs
);

showNxWarning(parsedArgs.name);

await recordStat({
nxVersion,
command: 'create-nx-workspace',
useCloud: parsedArgs.nxCloud,
meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'),
});

if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) {
printNxCloudSuccessMessage(workspaceInfo.nxCloudInfo);
}

if (isKnownPreset(parsedArgs.preset)) {
pointToTutorialAndCourse(parsedArgs.preset as Preset);
Expand Down
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/src/create-empty-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export async function createEmptyWorkspace<T extends CreateWorkspaceOptions>(
await execAndWait(fullCommand, tmpDir);

workspaceSetupSpinner.succeed(
`Nx has successfully created the workspace: ${getFileName(name)}.`
`Successfully created the workspace: ${getFileName(name)}.`
);
} catch (e) {
workspaceSetupSpinner.fail();
if (e instanceof Error) {
output.error({
title: `Nx failed to create a workspace.`,
title: `Failed to create a workspace.`,
bodyLines: mapErrorToBodyLines(e),
});
} else {
Expand Down
4 changes: 0 additions & 4 deletions packages/create-nx-workspace/src/create-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ export async function createPreset<T extends CreateWorkspaceOptions>(
...command.split(' ')
);
await spawnAndWait(exec, args, directory);

output.log({
title: `Successfully applied preset: ${preset}.`,
});
} catch (e) {
output.error({
title: `Failed to apply preset: ${preset}`,
Expand Down
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/src/create-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function createSandbox(packageManager: PackageManager) {
JSON.stringify({
dependencies: {
nx: nxVersion,
'@nrwl/workspace': nxVersion,
'@nx/workspace': nxVersion,
},
license: 'MIT',
})
Expand All @@ -46,7 +46,7 @@ export async function createSandbox(packageManager: PackageManager) {
installSpinner.fail();
if (e instanceof Error) {
output.error({
title: `Nx failed to install dependencies`,
title: `Failed to install dependencies`,
bodyLines: mapErrorToBodyLines(e),
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export interface CreateWorkspaceOptions {
email: string; // Email to use for the initial commit
message: string; // Message to use for the initial commit
};
cliName?: string; // Name of the CLI, used when displaying outputs. e.g. nx, Nx
}
32 changes: 10 additions & 22 deletions packages/create-nx-workspace/src/create-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { CreateWorkspaceOptions } from './create-workspace-options';
import { output } from './utils/output';
import { printNxCloudSuccessMessage, setupNxCloud } from './utils/nx/nx-cloud';
import { setupNxCloud } from './utils/nx/nx-cloud';
import { createSandbox } from './create-sandbox';
import { createEmptyWorkspace } from './create-empty-workspace';
import { createPreset } from './create-preset';
import { showNxWarning } from './utils/nx/show-nx-warning';
import { setupCI } from './utils/ci/setup-ci';
import { messages, recordStat } from './utils/nx/ab-testing';
import { initializeGitRepo } from './utils/git/git';
Expand All @@ -24,15 +23,12 @@ export async function createWorkspace<T extends CreateWorkspaceOptions>(
skipGit = false,
defaultBase = 'main',
commit,
cliName,
} = options;

output.log({
title: `Nx is creating your v${nxVersion} workspace.`,
bodyLines: [
'To make sure the command works reliably in all environments, and that the preset is applied correctly,',
`Nx will run "${options.packageManager} install" several times. Please wait.`,
],
});
if (cliName) {
output.setCliName(cliName ?? 'NX');
}

const tmpDir = await createSandbox(packageManager);

Expand All @@ -46,7 +42,7 @@ export async function createWorkspace<T extends CreateWorkspaceOptions>(

// If the preset is a third-party preset, we need to call createPreset to install it
// For first-party presets, it will created by createEmptyWorkspace instead.
// In createEmptyWorkspace, it will call `nx new` -> `@nrwl/workspace newGenerator` -> `@nrwl/workspace generatePreset`.
// In createEmptyWorkspace, it will call `nx new` -> `@nx/workspace newGenerator` -> `@nx/workspace generatePreset`.
const thirdPartyPreset = await getThirdPartyPreset(preset);
if (thirdPartyPreset) {
await createPreset(thirdPartyPreset, options, packageManager, directory);
Expand Down Expand Up @@ -79,16 +75,8 @@ export async function createWorkspace<T extends CreateWorkspaceOptions>(
}
}

showNxWarning(name);

if (nxCloud && nxCloudInstallRes?.code === 0) {
printNxCloudSuccessMessage(nxCloudInstallRes.stdout);
}

await recordStat({
nxVersion,
command: 'create-nx-workspace',
useCloud: nxCloud,
meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'),
});
return {
nxCloudInfo: nxCloudInstallRes?.stdout,
directory,
};
}
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/src/utils/ci/setup-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function setupCI(
try {
const pmc = getPackageManagerCommand(packageManager);
const res = await execAndWait(
`${pmc.exec} nx g @nrwl/workspace:ci-workflow --ci=${ci}`,
`${pmc.exec} nx g @nx/workspace:ci-workflow --ci=${ci}`,
join(process.cwd(), getFileName(name))
);
ciSpinner.succeed('CI workflow has been generated successfully');
Expand All @@ -35,7 +35,7 @@ export async function setupCI(
ciSpinner.fail();
if (e instanceof Error) {
output.error({
title: `Nx failed to generate CI workflow`,
title: `Failed to generate CI workflow`,
bodyLines: mapErrorToBodyLines(e),
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/src/utils/git/default-base.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { execSync } from 'child_process';

/*
* Because we don't want to depend on @nrwl/workspace (to speed up the workspace creation)
* we duplicate the helper functions from @nrwl/workspace in this file.
* Because we don't want to depend on @nx/workspace (to speed up the workspace creation)
* we duplicate the helper functions from @nx/workspace in this file.
*/
export function deduceDefaultBase(): string {
const nxDefaultBase = 'main';
Expand Down
3 changes: 0 additions & 3 deletions packages/create-nx-workspace/src/utils/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,4 @@ export async function initializeGitRepo(
const message = options.commit.message || 'initial commit';
await execute(['commit', `-m "${message}"`]);
}
output.log({
title: 'Successfully initialized git.',
});
}
2 changes: 1 addition & 1 deletion packages/create-nx-workspace/src/utils/nx/nx-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function setupNxCloud(

if (e instanceof Error) {
output.error({
title: `Nx failed to setup NxCloud`,
title: `Failed to setup NxCloud`,
bodyLines: mapErrorToBodyLines(e),
});
} else {
Expand Down
Loading

0 comments on commit c74e78b

Please sign in to comment.