Socket
Socket
Sign inDemoInstall

create-nx-workspace

Package Overview
Dependencies
Maintainers
7
Versions
1687
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-nx-workspace - npm Package Compare versions

Comparing version 0.0.0-pr-27085-57245c5 to 0.0.0-pr-27530-4059102

src/utils/nx/messages.d.ts

4

bin/create-nx-workspace.js

@@ -17,3 +17,2 @@ "use strict";

const show_nx_warning_1 = require("../src/utils/nx/show-nx-warning");
const nx_cloud_1 = require("../src/utils/nx/nx-cloud");
const ab_testing_1 = require("../src/utils/nx/ab-testing");

@@ -126,6 +125,7 @@ const error_utils_1 = require("../src/utils/error-utils");

ab_testing_1.messages.codeOfSelectedPromptMessage('setupNxCloud'),
parsedArgs.nxCloud,
],
});
if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) {
(0, nx_cloud_1.printNxCloudSuccessMessage)(workspaceInfo.nxCloudInfo);
console.log(workspaceInfo.nxCloudInfo);
}

@@ -132,0 +132,0 @@ if ((0, preset_1.isKnownPreset)(parsedArgs.preset)) {

{
"name": "create-nx-workspace",
"version": "0.0.0-pr-27085-57245c5",
"version": "0.0.0-pr-27530-4059102",
"private": false,

@@ -40,3 +40,3 @@ "description": "Smart Monorepos · Fast CI",

"yargs": "^17.6.2",
"axios": "^1.6.0"
"axios": "^1.7.4"
},

@@ -47,3 +47,4 @@ "publishConfig": {

"main": "./index.js",
"type": "commonjs"
"type": "commonjs",
"types": "./index.d.ts"
}

@@ -25,3 +25,3 @@ <p style="text-align: center;">

Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.

@@ -28,0 +28,0 @@ ## What is It?

@@ -6,1 +6,2 @@ import { CreateWorkspaceOptions } from './create-workspace-options';

}>;
export declare function extractConnectUrl(text: string): string | null;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWorkspace = createWorkspace;
exports.extractConnectUrl = extractConnectUrl;
const output_1 = require("./utils/output");

@@ -28,7 +29,16 @@ const nx_cloud_1 = require("./utils/nx/nx-cloud");

}
let gitSuccess = false;
if (!skipGit && commit) {
let connectUrl;
let nxCloudInfo;
if (nxCloud !== 'skip') {
const token = (0, nx_cloud_1.readNxCloudToken)(directory);
if (nxCloud !== 'yes') {
await (0, setup_ci_1.setupCI)(directory, nxCloud, packageManager);
}
const { connectCloudUrl, output } = await (0, nx_cloud_1.getOnboardingInfo)(nxCloud, token, directory, useGitHub);
connectUrl = connectCloudUrl;
nxCloudInfo = output;
}
if (!skipGit) {
try {
await (0, git_1.initializeGitRepo)(directory, { defaultBase, commit });
gitSuccess = true;
await (0, git_1.initializeGitRepo)(directory, { defaultBase, commit, connectUrl });
}

@@ -47,16 +57,11 @@ catch (e) {

}
let nxCloudInstallRes;
if (nxCloud !== 'skip') {
nxCloudInstallRes = await (0, nx_cloud_1.setupNxCloud)(directory, packageManager, nxCloud, useGitHub);
if (nxCloud !== 'yes') {
const nxCIsetupRes = await (0, setup_ci_1.setupCI)(directory, nxCloud, packageManager, nxCloudInstallRes?.code === 0);
if (nxCIsetupRes?.code === 0) {
(0, git_1.commitChanges)(directory, `feat(nx): Generated CI workflow`);
}
}
}
return {
nxCloudInfo: nxCloudInstallRes?.stdout,
nxCloudInfo,
directory,
};
}
function extractConnectUrl(text) {
const urlPattern = /(https:\/\/[^\s]+\/connect\/[^\s]+)/g;
const match = text.match(urlPattern);
return match ? match[0] : null;
}
import { PackageManager } from '../package-manager';
export declare function setupCI(directory: string, ci: string, packageManager: PackageManager, nxCloudSuccessfullyInstalled: boolean): Promise<{
export declare function setupCI(directory: string, ci: string, packageManager: PackageManager): Promise<{
code: number;
stdout: string;
}>;

@@ -9,12 +9,3 @@ "use strict";

const package_manager_1 = require("../package-manager");
async function setupCI(directory, ci, packageManager, nxCloudSuccessfullyInstalled) {
if (!nxCloudSuccessfullyInstalled) {
output_1.output.error({
title: `CI workflow generation skipped`,
bodyLines: [
`Nx Cloud was not installed`,
`The autogenerated CI workflow requires Nx Cloud to be set-up.`,
],
});
}
async function setupCI(directory, ci, packageManager) {
const ciSpinner = ora(`Generating CI workflow`).start();

@@ -21,0 +12,0 @@ try {

@@ -12,4 +12,5 @@ "use strict";

try {
return ((0, child_process_1.execSync)('git config --get init.defaultBranch').toString().trim() ||
nxDefaultBase);
return ((0, child_process_1.execSync)('git config --get init.defaultBranch', { windowsHide: true })
.toString()
.trim() || nxDefaultBase);
}

@@ -16,0 +17,0 @@ catch {

@@ -9,3 +9,3 @@ export declare function checkGitVersion(): string | null | undefined;

};
connectUrl?: string | null;
}): Promise<void>;
export declare function commitChanges(directory: string, message: string): void;

@@ -5,3 +5,2 @@ "use strict";

exports.initializeGitRepo = initializeGitRepo;
exports.commitChanges = commitChanges;
const child_process_1 = require("child_process");

@@ -12,3 +11,5 @@ const default_base_1 = require("./default-base");

try {
let gitVersionOutput = (0, child_process_1.execSync)('git --version').toString().trim();
let gitVersionOutput = (0, child_process_1.execSync)('git --version', { windowsHide: true })
.toString()
.trim();
return gitVersionOutput.match(/[0-9]+\.[0-9]+\.+[0-9]+/)?.[0];

@@ -77,21 +78,14 @@ }

if (options.commit) {
const message = options.commit.message || 'initial commit';
let message = `${options.commit.message}` || 'initial commit';
if (options.connectUrl) {
message = `${message}
To connect your workspace to Nx Cloud, push your repository
to your git hosting provider and go to the following URL:
${options.connectUrl}
`;
}
await execute(['commit', `-m "${message}"`]);
}
}
function commitChanges(directory, message) {
try {
(0, child_process_1.execSync)('git add -A', { encoding: 'utf8', stdio: 'pipe', cwd: directory });
(0, child_process_1.execSync)('git commit --no-verify -F -', {
encoding: 'utf8',
stdio: 'pipe',
input: message,
cwd: directory,
});
}
catch (e) {
console.error(`There was an error committing your Nx Cloud token.\n
Please commit the changes manually and push to your new repository.\n
\n${e}`);
}
}

@@ -122,3 +122,6 @@ "use strict";

try {
const stdout = (0, node_child_process_1.execSync)(pmc.getRegistryUrl, { encoding: 'utf-8' });
const stdout = (0, node_child_process_1.execSync)(pmc.getRegistryUrl, {
encoding: 'utf-8',
windowsHide: true,
});
const url = new URL(stdout.trim());

@@ -125,0 +128,0 @@ // don't record stats when testing locally

@@ -1,7 +0,6 @@

import { PackageManager } from '../package-manager';
export type NxCloud = 'yes' | 'github' | 'circleci' | 'skip';
export declare function setupNxCloud(directory: string, packageManager: PackageManager, nxCloud: NxCloud, useGitHub?: boolean): Promise<{
code: number;
stdout: string;
export declare function readNxCloudToken(directory: string): string | undefined;
export declare function getOnboardingInfo(nxCloud: NxCloud, token: string, directory: string, useGithub?: boolean): Promise<{
output: string;
connectCloudUrl: string;
}>;
export declare function printNxCloudSuccessMessage(nxCloudOut: string): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupNxCloud = setupNxCloud;
exports.printNxCloudSuccessMessage = printNxCloudSuccessMessage;
exports.readNxCloudToken = readNxCloudToken;
exports.getOnboardingInfo = getOnboardingInfo;
const output_1 = require("../output");
const messages_1 = require("./messages");
const ora = require("ora");
const child_process_utils_1 = require("../child-process-utils");
const output_1 = require("../output");
const package_manager_1 = require("../package-manager");
const error_utils_1 = require("../error-utils");
async function setupNxCloud(directory, packageManager, nxCloud, useGitHub) {
const nxCloudSpinner = ora(`Setting up Nx Cloud`).start();
try {
const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
const res = await (0, child_process_utils_1.execAndWait)(`${pmc.exec} nx g nx:connect-to-nx-cloud --installationSource=create-nx-workspace --directory=${directory} ${useGitHub ? '--github' : ''} --no-interactive`, directory);
if (nxCloud !== 'yes') {
nxCloudSpinner.succeed('CI workflow with Nx Cloud has been generated successfully');
}
else {
nxCloudSpinner.succeed('Nx Cloud has been set up successfully');
}
return res;
function readNxCloudToken(directory) {
const nxCloudSpinner = ora(`Checking Nx Cloud setup`).start();
// nx-ignore-next-line
const { getCloudOptions } = require(require.resolve('nx/src/nx-cloud/utilities/get-cloud-options', {
paths: [directory],
}
catch (e) {
nxCloudSpinner.fail();
if (e instanceof Error) {
output_1.output.error({
title: `Failed to setup Nx Cloud`,
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(e),
});
}
else {
console.error(e);
}
process.exit(1);
// nx-ignore-next-line
));
const { accessToken } = getCloudOptions(directory);
nxCloudSpinner.succeed('Nx Cloud has been set up successfully');
return accessToken;
}
async function getOnboardingInfo(nxCloud, token, directory, useGithub) {
// nx-ignore-next-line
const { createNxCloudOnboardingURL } = require(require.resolve('nx/src/nx-cloud/utilities/url-shorten', {
paths: [directory],
}
finally {
nxCloudSpinner.stop();
// nx-ignore-next-line
));
const source = nxCloud === 'yes'
? 'create-nx-workspace-success-cache-setup'
: 'create-nx-workspace-success-ci-setup';
const { code, createMessage } = (0, messages_1.getMessageFactory)(source);
const connectCloudUrl = await createNxCloudOnboardingURL(source, token, useGithub ??
(nxCloud === 'yes' || nxCloud === 'github' || nxCloud === 'circleci'), code);
const out = new output_1.CLIOutput(false);
const message = createMessage(connectCloudUrl);
if (message.type === 'success') {
out.success(message);
}
else {
out.warn(message);
}
return { output: out.getOutput(), connectCloudUrl };
}
function printNxCloudSuccessMessage(nxCloudOut) {
// remove leading Nx carret and any new lines
const logContent = nxCloudOut.split('NX ')[1];
const indexOfTitleEnd = logContent.indexOf('\n');
const title = logContent.slice(0, logContent.indexOf('\n')).trim();
const bodyLines = logContent
.slice(indexOfTitleEnd)
.replace(/^\n*/, '') // remove leading new lines
.replace(/\n*$/, '') // remove trailing new lines
.split('\n')
.map((r) => r.trim());
output_1.output.warn({
title,
bodyLines,
});
}

@@ -14,2 +14,3 @@ "use strict";

stdio: ['ignore', 'ignore', 'ignore'],
windowsHide: true,
});

@@ -16,0 +17,0 @@ }

@@ -18,3 +18,6 @@ import * as chalk from 'chalk';

}
declare class CLIOutput {
export declare class CLIOutput {
private real;
private outstream;
constructor(real?: boolean);
/**

@@ -57,4 +60,4 @@ * Longer dash character which forms more of a continuous line when place side to side

}): void;
getOutput(): string;
}
export declare const output: CLIOutput;
export {};

@@ -7,3 +7,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.output = void 0;
exports.output = exports.CLIOutput = void 0;
const chalk = require("chalk");

@@ -19,3 +19,5 @@ const os_1 = require("os");

class CLIOutput {
constructor() {
constructor(real = true) {
this.real = real;
this.outstream = this.real ? process.stdout : new FakeStdout();
/**

@@ -50,3 +52,3 @@ * Expose some color and other utility functions so that other parts of the codebase that need

writeToStdOut(str) {
process.stdout.write(str);
this.outstream.write(str);
}

@@ -140,3 +142,18 @@ writeOutputTitle({ color, title, }) {

}
getOutput() {
return this.outstream.toString();
}
}
exports.CLIOutput = CLIOutput;
exports.output = new CLIOutput();
class FakeStdout {
constructor() {
this.content = '';
}
write(str) {
this.content += str;
}
toString() {
return this.content;
}
}

@@ -104,2 +104,3 @@ "use strict";

encoding: 'utf-8',
windowsHide: true,
}).trim();

@@ -106,0 +107,0 @@ pmVersionCache.set(packageManager, version);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc