You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

create-nx-workspace

Package Overview
Dependencies
Maintainers
7
Versions
2335
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

to
0.0.0-pr-31936-ec577e9

3

bin/create-nx-workspace.js

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

rawArgs.nxCloud,
workspaceInfo.pushedToVcs,
],

@@ -172,3 +173,3 @@ });

async function normalizeArgsMiddleware(argv) {
rawArgs = argv;
rawArgs = { ...argv };
output_1.output.log({

@@ -175,0 +176,0 @@ title: "Let's create a new workspace [https://nx.dev/getting-started/intro]",

{
"name": "create-nx-workspace",
"version": "0.0.0-pr-31936-9fedb75",
"version": "0.0.0-pr-31936-ec577e9",
"private": false,

@@ -5,0 +5,0 @@ "description": "Smart Repos · Fast Builds",

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

await (0, child_process_utils_1.execAndWait)(fullCommand, tmpDir);
workspaceSetupSpinner.succeed(`Successfully created the workspace: ${directory}.`);
workspaceSetupSpinner.succeed(`Successfully created the workspace: ${directory}`);
}

@@ -50,0 +50,0 @@ catch (e) {

import { CreateWorkspaceOptions } from './create-workspace-options';
import { VcsPushStatus } from './utils/git/git';
export declare function createWorkspace<T extends CreateWorkspaceOptions>(preset: string, options: T, rawArgs?: T): Promise<{
nxCloudInfo: string | undefined;
directory: string;
pushedToVcs: VcsPushStatus;
}>;
export declare function extractConnectUrl(text: string): string | null;

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

}
let pushedToVcs = false;
let pushedToVcs = git_1.VcsPushStatus.SkippedGit;
if (!skipGit) {

@@ -73,2 +73,3 @@ try {

directory,
pushedToVcs,
};

@@ -75,0 +76,0 @@ }

@@ -0,1 +1,11 @@

export declare enum VcsPushStatus {
PushedToVcs = "PushedToVcs",
OptedOutOfPushingToVcs = "OptedOutOfPushingToVcs",
FailedToPushToVcs = "FailedToPushToVcs",
SkippedGit = "SkippedGit"
}
export declare class GitHubPushSkippedError extends Error {
readonly title = "Push your workspace";
constructor(message: string);
}
export declare function checkGitVersion(): Promise<string | null | undefined>;

@@ -16,2 +26,2 @@ export declare function initializeGitRepo(directory: string, options: {

verbose?: boolean;
}): Promise<boolean>;
}): Promise<VcsPushStatus>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitHubPushSkippedError = exports.VcsPushStatus = void 0;
exports.checkGitVersion = checkGitVersion;

@@ -10,2 +11,17 @@ exports.initializeGitRepo = initializeGitRepo;

const enquirer = require("enquirer");
var VcsPushStatus;
(function (VcsPushStatus) {
VcsPushStatus["PushedToVcs"] = "PushedToVcs";
VcsPushStatus["OptedOutOfPushingToVcs"] = "OptedOutOfPushingToVcs";
VcsPushStatus["FailedToPushToVcs"] = "FailedToPushToVcs";
VcsPushStatus["SkippedGit"] = "SkippedGit";
})(VcsPushStatus || (exports.VcsPushStatus = VcsPushStatus = {}));
class GitHubPushSkippedError extends Error {
constructor(message) {
super(message);
this.title = 'Push your workspace';
this.name = 'GitHubPushSkippedError';
}
}
exports.GitHubPushSkippedError = GitHubPushSkippedError;
async function checkGitVersion() {

@@ -25,3 +41,3 @@ try {

if (!username) {
throw new Error('GitHub CLI is not authenticated');
throw new GitHubPushSkippedError('GitHub CLI is not authenticated');
}

@@ -32,8 +48,37 @@ return username;

try {
const result = await (0, child_process_utils_1.execAndWait)('gh repo list --limit 1000 --json nameWithOwner --jq ".[].nameWithOwner"', directory);
const repos = result.stdout
const allRepos = new Set();
// Get user's personal repos and organizations concurrently
const [userRepos, orgsResult] = await Promise.all([
(0, child_process_utils_1.execAndWait)('gh repo list --limit 1000 --json nameWithOwner --jq ".[].nameWithOwner"', directory),
(0, child_process_utils_1.execAndWait)('gh api user/orgs --jq ".[].login"', directory),
]);
// Add user's personal repos
userRepos.stdout
.trim()
.split('\n')
.filter((repo) => repo.length > 0);
return new Set(repos);
.filter((repo) => repo.length > 0)
.forEach((repo) => allRepos.add(repo));
// Parse organizations
const orgs = orgsResult.stdout
.trim()
.split('\n')
.filter((org) => org.length > 0);
// Get repos from all organizations concurrently
const orgRepoPromises = orgs.map(async (org) => {
try {
const orgRepos = await (0, child_process_utils_1.execAndWait)(`gh repo list ${org} --limit 1000 --json nameWithOwner --jq ".[].nameWithOwner"`, directory);
return orgRepos.stdout
.trim()
.split('\n')
.filter((repo) => repo.length > 0);
}
catch {
// Return empty array if we can't access org repos
return [];
}
});
const orgRepoResults = await Promise.all(orgRepoPromises);
// Add all org repos to the set
orgRepoResults.flat().forEach((repo) => allRepos.add(repo));
return allRepos;
}

@@ -92,2 +137,5 @@ catch {

try {
if (process.env['NX_SKIP_GH_PUSH'] === 'false') {
throw new GitHubPushSkippedError('NX_SKIP_GH_PUSH is false so skipping GitHub push.');
}
const username = await getGitHubUsername(directory);

@@ -104,4 +152,4 @@ // First prompt: Ask if they want to push to GitHub

]);
if (!push) {
return false;
if (push !== 'Yes') {
return VcsPushStatus.OptedOutOfPushingToVcs;
}

@@ -132,7 +180,18 @@ // Preload existing repositories for validation

// This will automatically add remote origin and push the current branch
await (0, child_process_utils_1.spawnAndWait)('gh', ['repo', 'create', repoName, '--public', '--push', '--source', directory], directory);
await (0, child_process_utils_1.spawnAndWait)('gh', [
'repo',
'create',
repoName,
'--private',
'--push',
'--source',
directory,
], directory);
// Get the actual repository URL from GitHub CLI (it could be different from github.com)
const repoResult = await (0, child_process_utils_1.execAndWait)('gh repo view --json url -q .url', directory);
const repoUrl = repoResult.stdout.trim();
output_1.output.log({
title: `Successfully created and pushed to GitHub repository: https://github.com/${repoName}`,
title: `Successfully created and pushed to GitHub repository: ${repoUrl}`,
});
return true;
return VcsPushStatus.PushedToVcs;
}

@@ -142,15 +201,19 @@ catch (e) {

const errorMessage = e instanceof Error ? e.message : String(e);
// Error code 127 means gh wasn't installed
const title = e instanceof GitHubPushSkippedError || e?.code === 127
? 'Push your workspace to GitHub'
: 'Failed to push workspace to GitHub';
const createRepoUrl = `https://github.com/new?name=${encodeURIComponent(options.name)}`;
output_1.output.log({
title: 'Failed to push workspace to GitHub',
title,
bodyLines: isVerbose
? [
`Please create a repo at ${createRepoUrl} and push this workspace.`,
`Please create a repo at ${createRepoUrl} and push this workspace`,
'Error details:',
errorMessage,
]
: [`Please create a repo at ${createRepoUrl} and push this workspace.`],
: [`Please create a repo at ${createRepoUrl} and push this workspace`],
});
return false;
return VcsPushStatus.FailedToPushToVcs;
}
}

@@ -14,4 +14,6 @@ "use strict";

`${pushedToVcs
? 'Return to Nx Cloud'
: 'Once you have pushed your repo, return to Nx Cloud'} and finish the setup${url ? `: ${url}` : ''}`,
? url
? `Go to Nx Cloud and finish the setup: ${url}`
: 'Return to Nx Cloud and finish the setup'
: `Once you have pushed your repo, ${url ? 'go' : 'return'} to Nx Cloud and finish the setup${url ? `: ${url}` : ''}`}`,
],

@@ -31,4 +33,6 @@ };

`${pushedToVcs
? 'Return to Nx Cloud'
: 'Once you have pushed your repo, return to Nx Cloud'} and finish the setup${url ? `: ${url}` : ''}`,
? url
? `Go to Nx Cloud and finish the setup: ${url}`
: 'Return to Nx Cloud and finish the setup'
: `Once you have pushed your repo, ${url ? 'go' : 'return'} to Nx Cloud and finish the setup${url ? `: ${url}` : ''}`}`,
`You can also set up a remote cache later by running \`nx g @nx/nx-cloud:init\``,

@@ -35,0 +39,0 @@ ],

@@ -0,4 +1,5 @@

import { VcsPushStatus } from '../git/git';
export type NxCloud = 'yes' | 'github' | 'gitlab' | 'azure' | 'bitbucket-pipelines' | 'circleci' | 'skip';
export declare function readNxCloudToken(directory: string): string | undefined;
export declare function createNxCloudOnboardingUrl(nxCloud: NxCloud, token: string, directory: string, useGitHub?: boolean): Promise<string>;
export declare function getNxCloudInfo(nxCloud: NxCloud, connectCloudUrl: string, pushedToVcs: boolean, rawNxCloud?: NxCloud): Promise<string>;
export declare function getNxCloudInfo(nxCloud: NxCloud, connectCloudUrl: string, pushedToVcs: VcsPushStatus, rawNxCloud?: NxCloud): Promise<string>;

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

exports.getNxCloudInfo = getNxCloudInfo;
const git_1 = require("../git/git");
const output_1 = require("../output");

@@ -42,3 +43,3 @@ const messages_1 = require("./messages");

const out = new output_1.CLIOutput(false);
const message = createMessage(typeof rawNxCloud === 'string' ? null : connectCloudUrl, pushedToVcs);
const message = createMessage(typeof rawNxCloud === 'string' ? null : connectCloudUrl, pushedToVcs === git_1.VcsPushStatus.PushedToVcs);
if (message.type === 'success') {

@@ -45,0 +46,0 @@ out.success(message);