extension-create 3.5.0-next.0 → 3.5.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/progress.d.ts +11 -0
- package/dist/module.cjs +3 -158
- package/dist/module.d.ts +1 -1
- package/package.json +1 -1
- package/dist/steps/preflight-optional-deps.d.ts +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type ProgressOptions = {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
intervalMs?: number;
|
|
4
|
+
width?: number;
|
|
5
|
+
};
|
|
6
|
+
type ProgressHandle = {
|
|
7
|
+
stop: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function shouldShowProgress(): boolean;
|
|
10
|
+
export declare function startProgressBar(label: string, options?: ProgressOptions): ProgressHandle;
|
|
11
|
+
export {};
|
package/dist/module.cjs
CHANGED
|
@@ -143,18 +143,6 @@ function initializingGitForRepositoryProcessError(projectName, error) {
|
|
|
143
143
|
function initializingGitForRepositoryError(projectName, error) {
|
|
144
144
|
return `${external_pintor_default().red('Error')} Couldn't initialize ${external_pintor_default().yellow('git')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error?.message || error))}\n${external_pintor_default().red('Next step: retry initialization or create the repository manually.')}`;
|
|
145
145
|
}
|
|
146
|
-
function installingDependencies() {
|
|
147
|
-
return `${statusPrefix} Installing dependencies (this may take a moment)...`;
|
|
148
|
-
}
|
|
149
|
-
function installingDependenciesFailed(gitCommand, gitArgs, code) {
|
|
150
|
-
return `${external_pintor_default().red('Error')} Command ${external_pintor_default().yellow(gitCommand)} ${external_pintor_default().yellow(gitArgs.join(' '))} failed.\n${external_pintor_default().red(`Exit code: ${external_pintor_default().yellow(String(code))}`)}\n${external_pintor_default().red('Next step: run the command manually to inspect the error.')}`;
|
|
151
|
-
}
|
|
152
|
-
function installingDependenciesProcessError(projectName, error) {
|
|
153
|
-
return `${external_pintor_default().red('Error')} Child process failed while installing dependencies for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: run the install command manually to inspect the error.')}`;
|
|
154
|
-
}
|
|
155
|
-
function cantInstallDependencies(projectName, error) {
|
|
156
|
-
return `${external_pintor_default().red('Error')} Couldn't install dependencies for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error?.message || error))}\n${external_pintor_default().red('Next step: check your package manager settings, then try again.')}`;
|
|
157
|
-
}
|
|
158
146
|
function writingPackageJsonMetadata() {
|
|
159
147
|
return `${statusPrefix} Writing ${external_pintor_default().yellow('package.json')}...`;
|
|
160
148
|
}
|
|
@@ -490,136 +478,6 @@ async function overridePackageJson(projectPath, projectName, { template: _templa
|
|
|
490
478
|
throw error;
|
|
491
479
|
}
|
|
492
480
|
}
|
|
493
|
-
const external_cross_spawn_namespaceObject = require("cross-spawn");
|
|
494
|
-
function getInstallArgs() {
|
|
495
|
-
return [
|
|
496
|
-
'install',
|
|
497
|
-
'--silent'
|
|
498
|
-
];
|
|
499
|
-
}
|
|
500
|
-
function resolveWindowsCmdExe() {
|
|
501
|
-
const comspec = process.env.ComSpec;
|
|
502
|
-
if (comspec) return comspec;
|
|
503
|
-
const systemRoot = process.env.SystemRoot || 'C:\\Windows';
|
|
504
|
-
return external_path_namespaceObject.join(systemRoot, 'System32', 'cmd.exe');
|
|
505
|
-
}
|
|
506
|
-
function formatCmdArgs(command, args) {
|
|
507
|
-
const quotedCommand = command.includes(' ') ? `"${command}"` : command;
|
|
508
|
-
const quotedArgs = args.map((arg)=>arg.includes(' ') ? `"${arg}"` : arg);
|
|
509
|
-
return `${quotedCommand} ${quotedArgs.join(' ')}`.trim();
|
|
510
|
-
}
|
|
511
|
-
function resolveInstallInvocation(command, args) {
|
|
512
|
-
if ('win32' !== process.platform) return {
|
|
513
|
-
command,
|
|
514
|
-
args
|
|
515
|
-
};
|
|
516
|
-
return {
|
|
517
|
-
command: resolveWindowsCmdExe(),
|
|
518
|
-
args: [
|
|
519
|
-
'/d',
|
|
520
|
-
'/s',
|
|
521
|
-
'/c',
|
|
522
|
-
formatCmdArgs(command, args)
|
|
523
|
-
]
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
function buildExecEnv() {
|
|
527
|
-
if ('win32' !== process.platform) return;
|
|
528
|
-
const nodeDir = external_path_namespaceObject.dirname(process.execPath);
|
|
529
|
-
const pathSep = external_path_namespaceObject.delimiter;
|
|
530
|
-
const existing = process.env.PATH || process.env.Path || '';
|
|
531
|
-
if (existing.includes(nodeDir)) return;
|
|
532
|
-
return {
|
|
533
|
-
...process.env,
|
|
534
|
-
PATH: `${nodeDir}${pathSep}${existing}`.trim(),
|
|
535
|
-
Path: `${nodeDir}${pathSep}${existing}`.trim()
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
function getTagFallback(version) {
|
|
539
|
-
if ('*' === version || 'latest' === version || 'next' === version) return null;
|
|
540
|
-
const cleaned = version.replace(/^[~^]/, '');
|
|
541
|
-
return cleaned.includes('-') ? 'next' : 'latest';
|
|
542
|
-
}
|
|
543
|
-
async function updateExtensionDependencyTag(projectPath, projectName) {
|
|
544
|
-
const packageJsonPath = external_path_namespaceObject.join(projectPath, 'package.json');
|
|
545
|
-
try {
|
|
546
|
-
const raw = await external_fs_namespaceObject.promises.readFile(packageJsonPath, 'utf8');
|
|
547
|
-
const packageJson = JSON.parse(raw);
|
|
548
|
-
const currentVersion = packageJson?.devDependencies?.extension;
|
|
549
|
-
if ('string' != typeof currentVersion) return false;
|
|
550
|
-
const tag = getTagFallback(currentVersion);
|
|
551
|
-
if (!tag || currentVersion === tag) return false;
|
|
552
|
-
packageJson.devDependencies = {
|
|
553
|
-
...packageJson.devDependencies || {},
|
|
554
|
-
extension: tag
|
|
555
|
-
};
|
|
556
|
-
await external_fs_namespaceObject.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
557
|
-
return true;
|
|
558
|
-
} catch (error) {
|
|
559
|
-
console.error(cantInstallDependencies(projectName, error));
|
|
560
|
-
return false;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
function shouldRetryWithTagFallback(output) {
|
|
564
|
-
const text = output.toLowerCase();
|
|
565
|
-
return text.includes('no matching version found for extension@') || text.includes('notarget') || text.includes('etarget');
|
|
566
|
-
}
|
|
567
|
-
async function runInstall(command, args, cwd, stdio) {
|
|
568
|
-
const invocation = resolveInstallInvocation(command, args);
|
|
569
|
-
const env = buildExecEnv();
|
|
570
|
-
const child = (0, external_cross_spawn_namespaceObject.spawn)(invocation.command, invocation.args, {
|
|
571
|
-
stdio,
|
|
572
|
-
cwd,
|
|
573
|
-
env: env || process.env
|
|
574
|
-
});
|
|
575
|
-
let stdout = '';
|
|
576
|
-
let stderr = '';
|
|
577
|
-
if (child.stdout) child.stdout.on('data', (chunk)=>{
|
|
578
|
-
stdout += chunk.toString();
|
|
579
|
-
});
|
|
580
|
-
if (child.stderr) child.stderr.on('data', (chunk)=>{
|
|
581
|
-
stderr += chunk.toString();
|
|
582
|
-
});
|
|
583
|
-
return new Promise((resolve, reject)=>{
|
|
584
|
-
child.on('close', (code)=>{
|
|
585
|
-
resolve({
|
|
586
|
-
code,
|
|
587
|
-
stderr,
|
|
588
|
-
stdout
|
|
589
|
-
});
|
|
590
|
-
});
|
|
591
|
-
child.on('error', (error)=>{
|
|
592
|
-
reject(error);
|
|
593
|
-
});
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
async function installDependencies(projectPath, projectName) {
|
|
597
|
-
const nodeModulesPath = external_path_namespaceObject.join(projectPath, 'node_modules');
|
|
598
|
-
const command = await getInstallCommand();
|
|
599
|
-
const dependenciesArgs = getInstallArgs();
|
|
600
|
-
console.log(installingDependencies());
|
|
601
|
-
try {
|
|
602
|
-
await external_fs_namespaceObject.promises.mkdir(nodeModulesPath, {
|
|
603
|
-
recursive: true
|
|
604
|
-
});
|
|
605
|
-
const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'pipe';
|
|
606
|
-
const firstRun = await runInstall(command, dependenciesArgs, projectPath, stdio);
|
|
607
|
-
if (0 !== firstRun.code) {
|
|
608
|
-
const output = `${firstRun.stdout}\n${firstRun.stderr}`;
|
|
609
|
-
const shouldRetry = shouldRetryWithTagFallback(output);
|
|
610
|
-
const didUpdate = shouldRetry ? await updateExtensionDependencyTag(projectPath, projectName) : false;
|
|
611
|
-
if (didUpdate) {
|
|
612
|
-
const retryRun = await runInstall(command, dependenciesArgs, projectPath, stdio);
|
|
613
|
-
if (0 === retryRun.code) return;
|
|
614
|
-
}
|
|
615
|
-
throw new Error(installingDependenciesFailed(command, dependenciesArgs, firstRun.code));
|
|
616
|
-
}
|
|
617
|
-
} catch (error) {
|
|
618
|
-
console.error(installingDependenciesProcessError(projectName, error));
|
|
619
|
-
console.error(cantInstallDependencies(projectName, error));
|
|
620
|
-
throw error;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
481
|
const manifestSearchMaxDepth = 3;
|
|
624
482
|
const ignoredManifestDirs = new Set([
|
|
625
483
|
'node_modules',
|
|
@@ -845,6 +703,7 @@ async function writeGitignore(projectPath) {
|
|
|
845
703
|
throw err;
|
|
846
704
|
});
|
|
847
705
|
}
|
|
706
|
+
const external_cross_spawn_namespaceObject = require("cross-spawn");
|
|
848
707
|
async function initializeGitRepository(projectPath, projectName) {
|
|
849
708
|
const gitCommand = 'git';
|
|
850
709
|
const gitArgs = [
|
|
@@ -882,16 +741,7 @@ async function setupBuiltInTests(projectPath, projectName) {
|
|
|
882
741
|
throw error;
|
|
883
742
|
}
|
|
884
743
|
}
|
|
885
|
-
|
|
886
|
-
async function preflightOptionalDependenciesForCreate(projectPath) {
|
|
887
|
-
try {
|
|
888
|
-
const requireFromProject = (0, external_module_namespaceObject.createRequire)(external_path_namespaceObject.join(projectPath, 'package.json'));
|
|
889
|
-
const develop = requireFromProject('extension-develop');
|
|
890
|
-
const preflight = develop?.preflightOptionalDependenciesForProject;
|
|
891
|
-
if ('function' == typeof preflight) await preflight(projectPath, 'development');
|
|
892
|
-
} catch {}
|
|
893
|
-
}
|
|
894
|
-
async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install = false }) {
|
|
744
|
+
async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install: _install = false }) {
|
|
895
745
|
if (!projectNameInput) throw new Error(noProjectName());
|
|
896
746
|
if (projectNameInput.startsWith('http')) throw new Error(noUrlAllowed());
|
|
897
747
|
const projectPath = external_path_namespaceObject.isAbsolute(projectNameInput) ? projectNameInput : external_path_namespaceObject.join(process.cwd(), projectNameInput);
|
|
@@ -903,20 +753,15 @@ async function extensionCreate(projectNameInput, { cliVersion, template = 'init'
|
|
|
903
753
|
template,
|
|
904
754
|
cliVersion
|
|
905
755
|
});
|
|
906
|
-
if (install) {
|
|
907
|
-
await installDependencies(projectPath, projectName);
|
|
908
|
-
await preflightOptionalDependenciesForCreate(projectPath);
|
|
909
|
-
}
|
|
910
756
|
await writeReadmeFile(projectPath, projectName);
|
|
911
757
|
await writeManifestJson(projectPath, projectName);
|
|
912
758
|
await initializeGitRepository(projectPath, projectName);
|
|
913
759
|
await writeGitignore(projectPath);
|
|
914
760
|
await setupBuiltInTests(projectPath, projectName);
|
|
915
761
|
if (isTypeScriptTemplate(template)) await generateExtensionTypes(projectPath, projectName);
|
|
916
|
-
const successfulInstall = await successfullInstall(projectPath, projectName,
|
|
762
|
+
const successfulInstall = await successfullInstall(projectPath, projectName, false);
|
|
917
763
|
console.log(successfulInstall);
|
|
918
764
|
} catch (error) {
|
|
919
|
-
console.error(error);
|
|
920
765
|
throw error;
|
|
921
766
|
}
|
|
922
767
|
}
|
package/dist/module.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export interface CreateOptions {
|
|
|
3
3
|
install?: boolean;
|
|
4
4
|
cliVersion?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install }: CreateOptions): Promise<void>;
|
|
6
|
+
export declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install: _install }: CreateOptions): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function preflightOptionalDependenciesForCreate(projectPath: string): Promise<void>;
|