extension-create 3.5.0-next.8 → 3.5.0-next.9
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/install-runner.d.ts +10 -0
- package/dist/lib/messages.d.ts +2 -0
- package/dist/module.cjs +469 -3
- package/dist/module.d.ts +1 -1
- package/dist/steps/install-internal-deps.d.ts +20 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type InstallResult = {
|
|
2
|
+
code: number | null;
|
|
3
|
+
stderr: string;
|
|
4
|
+
stdout: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function runInstall(command: string, args: string[], opts: {
|
|
7
|
+
cwd: string;
|
|
8
|
+
stdio: 'inherit' | 'ignore' | 'pipe';
|
|
9
|
+
}): Promise<InstallResult>;
|
|
10
|
+
export {};
|
package/dist/lib/messages.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export declare function initializingGitForRepositoryFailed(gitCommand: string, g
|
|
|
16
16
|
export declare function initializingGitForRepositoryProcessError(projectName: string, error: any): string;
|
|
17
17
|
export declare function initializingGitForRepositoryError(projectName: string, error: any): string;
|
|
18
18
|
export declare function installingDependencies(): string;
|
|
19
|
+
export declare function installingBuildDependencies(dependencies: string[]): string;
|
|
20
|
+
export declare function installingProjectIntegrations(integrations: string[]): string;
|
|
19
21
|
export declare function installingDependenciesFailed(gitCommand: string, gitArgs: string[], code: number | null): string;
|
|
20
22
|
export declare function installingDependenciesProcessError(projectName: string, error: any): string;
|
|
21
23
|
export declare function cantInstallDependencies(projectName: string, error: any): string;
|
package/dist/module.cjs
CHANGED
|
@@ -143,6 +143,30 @@ 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...`;
|
|
148
|
+
}
|
|
149
|
+
function installingBuildDependencies(dependencies) {
|
|
150
|
+
return `${statusPrefix} Installing build tools...`;
|
|
151
|
+
}
|
|
152
|
+
function installingProjectIntegrations(integrations) {
|
|
153
|
+
const formatList = (items)=>{
|
|
154
|
+
if (1 === items.length) return items[0];
|
|
155
|
+
if (2 === items.length) return `${items[0]} and ${items[1]}`;
|
|
156
|
+
return `${items.slice(0, -1).join(', ')}, and ${items[items.length - 1]}`;
|
|
157
|
+
};
|
|
158
|
+
const tools = integrations.length > 0 ? formatList(integrations.map((name)=>external_pintor_default().yellow(name))) : external_pintor_default().gray('project tooling');
|
|
159
|
+
return `${statusPrefix} Installing project integrations for ${tools}...`;
|
|
160
|
+
}
|
|
161
|
+
function installingDependenciesFailed(gitCommand, gitArgs, code) {
|
|
162
|
+
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.')}`;
|
|
163
|
+
}
|
|
164
|
+
function installingDependenciesProcessError(projectName, error) {
|
|
165
|
+
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.')}`;
|
|
166
|
+
}
|
|
167
|
+
function cantInstallDependencies(projectName, error) {
|
|
168
|
+
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.')}`;
|
|
169
|
+
}
|
|
146
170
|
function writingPackageJsonMetadata() {
|
|
147
171
|
return `${statusPrefix} Writing ${external_pintor_default().yellow('package.json')}...`;
|
|
148
172
|
}
|
|
@@ -478,6 +502,193 @@ async function overridePackageJson(projectPath, projectName, { template: _templa
|
|
|
478
502
|
throw error;
|
|
479
503
|
}
|
|
480
504
|
}
|
|
505
|
+
function stripAnsi(input) {
|
|
506
|
+
return input.replace(/\x1b\[[0-9;]*m/g, '');
|
|
507
|
+
}
|
|
508
|
+
function shouldShowProgress() {
|
|
509
|
+
return Boolean(process.stdout.isTTY) && !process.env.CI;
|
|
510
|
+
}
|
|
511
|
+
function startProgressBar(label, options) {
|
|
512
|
+
const enabled = (options?.enabled ?? true) && shouldShowProgress();
|
|
513
|
+
if (!enabled) return {
|
|
514
|
+
stop: ()=>void 0
|
|
515
|
+
};
|
|
516
|
+
const width = Math.max(10, options?.width ?? 24);
|
|
517
|
+
const intervalMs = Math.max(50, options?.intervalMs ?? 90);
|
|
518
|
+
let tick = 0;
|
|
519
|
+
let lastVisibleLength = 0;
|
|
520
|
+
const render = ()=>{
|
|
521
|
+
const filled = tick % (width + 1);
|
|
522
|
+
const empty = width - filled;
|
|
523
|
+
const bar = `[${'='.repeat(filled)}${' '.repeat(empty)}]`;
|
|
524
|
+
const line = `${label} ${bar}`;
|
|
525
|
+
lastVisibleLength = stripAnsi(line).length;
|
|
526
|
+
process.stdout.write(`\r${line}`);
|
|
527
|
+
tick = (tick + 1) % (width + 1);
|
|
528
|
+
};
|
|
529
|
+
render();
|
|
530
|
+
const timer = setInterval(render, intervalMs);
|
|
531
|
+
return {
|
|
532
|
+
stop: ()=>{
|
|
533
|
+
clearInterval(timer);
|
|
534
|
+
if (process.stdout.isTTY) process.stdout.write(`\r${' '.repeat(lastVisibleLength)}\r`);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
const external_cross_spawn_namespaceObject = require("cross-spawn");
|
|
539
|
+
function resolveWindowsCmdExe() {
|
|
540
|
+
const comspec = process.env.ComSpec;
|
|
541
|
+
if (comspec) return comspec;
|
|
542
|
+
const systemRoot = process.env.SystemRoot || 'C:\\Windows';
|
|
543
|
+
return external_path_namespaceObject.join(systemRoot, 'System32', 'cmd.exe');
|
|
544
|
+
}
|
|
545
|
+
function formatCmdArgs(command, args) {
|
|
546
|
+
const quotedCommand = command.includes(' ') ? `"${command}"` : command;
|
|
547
|
+
const quotedArgs = args.map((arg)=>arg.includes(' ') ? `"${arg}"` : arg);
|
|
548
|
+
return `${quotedCommand} ${quotedArgs.join(' ')}`.trim();
|
|
549
|
+
}
|
|
550
|
+
function resolveInstallInvocation(command, args) {
|
|
551
|
+
if ('win32' !== process.platform) return {
|
|
552
|
+
command,
|
|
553
|
+
args
|
|
554
|
+
};
|
|
555
|
+
return {
|
|
556
|
+
command: resolveWindowsCmdExe(),
|
|
557
|
+
args: [
|
|
558
|
+
'/d',
|
|
559
|
+
'/s',
|
|
560
|
+
'/c',
|
|
561
|
+
formatCmdArgs(command, args)
|
|
562
|
+
]
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
function buildExecEnv() {
|
|
566
|
+
if ('win32' !== process.platform) return;
|
|
567
|
+
const nodeDir = external_path_namespaceObject.dirname(process.execPath);
|
|
568
|
+
const pathSep = external_path_namespaceObject.delimiter;
|
|
569
|
+
const existing = process.env.PATH || process.env.Path || '';
|
|
570
|
+
if (existing.includes(nodeDir)) return;
|
|
571
|
+
return {
|
|
572
|
+
...process.env,
|
|
573
|
+
PATH: `${nodeDir}${pathSep}${existing}`.trim(),
|
|
574
|
+
Path: `${nodeDir}${pathSep}${existing}`.trim()
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
async function runInstall(command, args, opts) {
|
|
578
|
+
const invocation = resolveInstallInvocation(command, args);
|
|
579
|
+
const env = buildExecEnv();
|
|
580
|
+
const child = (0, external_cross_spawn_namespaceObject.spawn)(invocation.command, invocation.args, {
|
|
581
|
+
stdio: opts.stdio,
|
|
582
|
+
cwd: opts.cwd,
|
|
583
|
+
env: env || process.env
|
|
584
|
+
});
|
|
585
|
+
let stdout = '';
|
|
586
|
+
let stderr = '';
|
|
587
|
+
if (child.stdout) child.stdout.on('data', (chunk)=>{
|
|
588
|
+
stdout += chunk.toString();
|
|
589
|
+
});
|
|
590
|
+
if (child.stderr) child.stderr.on('data', (chunk)=>{
|
|
591
|
+
stderr += chunk.toString();
|
|
592
|
+
});
|
|
593
|
+
return new Promise((resolve, reject)=>{
|
|
594
|
+
child.on('close', (code)=>{
|
|
595
|
+
resolve({
|
|
596
|
+
code,
|
|
597
|
+
stderr,
|
|
598
|
+
stdout
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
child.on('error', (error)=>{
|
|
602
|
+
reject(error);
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
function getInstallArgs() {
|
|
607
|
+
return [
|
|
608
|
+
'install',
|
|
609
|
+
'--silent'
|
|
610
|
+
];
|
|
611
|
+
}
|
|
612
|
+
function getTagFallback(version) {
|
|
613
|
+
if ('*' === version || 'latest' === version || 'next' === version) return null;
|
|
614
|
+
const cleaned = version.replace(/^[~^]/, '');
|
|
615
|
+
return cleaned.includes('-') ? 'next' : 'latest';
|
|
616
|
+
}
|
|
617
|
+
async function updateExtensionDependencyTag(projectPath, projectName) {
|
|
618
|
+
const packageJsonPath = external_path_namespaceObject.join(projectPath, 'package.json');
|
|
619
|
+
try {
|
|
620
|
+
const raw = await external_fs_namespaceObject.promises.readFile(packageJsonPath, 'utf8');
|
|
621
|
+
const packageJson = JSON.parse(raw);
|
|
622
|
+
const currentVersion = packageJson?.devDependencies?.extension;
|
|
623
|
+
if ('string' != typeof currentVersion) return false;
|
|
624
|
+
const tag = getTagFallback(currentVersion);
|
|
625
|
+
if (!tag || currentVersion === tag) return false;
|
|
626
|
+
packageJson.devDependencies = {
|
|
627
|
+
...packageJson.devDependencies || {},
|
|
628
|
+
extension: tag
|
|
629
|
+
};
|
|
630
|
+
await external_fs_namespaceObject.promises.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
631
|
+
return true;
|
|
632
|
+
} catch (error) {
|
|
633
|
+
console.error(cantInstallDependencies(projectName, error));
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function shouldRetryWithTagFallback(output) {
|
|
638
|
+
const text = output.toLowerCase();
|
|
639
|
+
return text.includes('no matching version found for extension@') || text.includes('notarget') || text.includes('etarget');
|
|
640
|
+
}
|
|
641
|
+
async function install_dependencies_runInstall(command, args, cwd, stdio) {
|
|
642
|
+
return runInstall(command, args, {
|
|
643
|
+
cwd,
|
|
644
|
+
stdio
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
async function installDependencies(projectPath, projectName) {
|
|
648
|
+
const nodeModulesPath = external_path_namespaceObject.join(projectPath, 'node_modules');
|
|
649
|
+
const command = await getInstallCommand();
|
|
650
|
+
const dependenciesArgs = getInstallArgs();
|
|
651
|
+
const installMessage = installingDependencies();
|
|
652
|
+
const progressEnabled = shouldShowProgress();
|
|
653
|
+
const progress = startProgressBar(installMessage, {
|
|
654
|
+
enabled: progressEnabled
|
|
655
|
+
});
|
|
656
|
+
if (!progressEnabled) console.log(installMessage);
|
|
657
|
+
try {
|
|
658
|
+
await external_fs_namespaceObject.promises.mkdir(nodeModulesPath, {
|
|
659
|
+
recursive: true
|
|
660
|
+
});
|
|
661
|
+
const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'pipe';
|
|
662
|
+
let firstRun;
|
|
663
|
+
try {
|
|
664
|
+
firstRun = await install_dependencies_runInstall(command, dependenciesArgs, projectPath, stdio);
|
|
665
|
+
} finally{
|
|
666
|
+
progress.stop();
|
|
667
|
+
}
|
|
668
|
+
if (0 !== firstRun.code) {
|
|
669
|
+
const output = `${firstRun.stdout}\n${firstRun.stderr}`;
|
|
670
|
+
const shouldRetry = shouldRetryWithTagFallback(output);
|
|
671
|
+
const didUpdate = shouldRetry ? await updateExtensionDependencyTag(projectPath, projectName) : false;
|
|
672
|
+
if (didUpdate) {
|
|
673
|
+
const retryProgress = startProgressBar(installMessage, {
|
|
674
|
+
enabled: progressEnabled
|
|
675
|
+
});
|
|
676
|
+
let retryRun;
|
|
677
|
+
try {
|
|
678
|
+
retryRun = await install_dependencies_runInstall(command, dependenciesArgs, projectPath, stdio);
|
|
679
|
+
} finally{
|
|
680
|
+
retryProgress.stop();
|
|
681
|
+
}
|
|
682
|
+
if (0 === retryRun.code) return;
|
|
683
|
+
}
|
|
684
|
+
throw new Error(installingDependenciesFailed(command, dependenciesArgs, firstRun.code));
|
|
685
|
+
}
|
|
686
|
+
} catch (error) {
|
|
687
|
+
console.error(installingDependenciesProcessError(projectName, error));
|
|
688
|
+
console.error(cantInstallDependencies(projectName, error));
|
|
689
|
+
throw error;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
481
692
|
const manifestSearchMaxDepth = 3;
|
|
482
693
|
const ignoredManifestDirs = new Set([
|
|
483
694
|
'node_modules',
|
|
@@ -703,7 +914,6 @@ async function writeGitignore(projectPath) {
|
|
|
703
914
|
throw err;
|
|
704
915
|
});
|
|
705
916
|
}
|
|
706
|
-
const external_cross_spawn_namespaceObject = require("cross-spawn");
|
|
707
917
|
async function initializeGitRepository(projectPath, projectName) {
|
|
708
918
|
const gitCommand = 'git';
|
|
709
919
|
const gitArgs = [
|
|
@@ -741,7 +951,261 @@ async function setupBuiltInTests(projectPath, projectName) {
|
|
|
741
951
|
throw error;
|
|
742
952
|
}
|
|
743
953
|
}
|
|
744
|
-
|
|
954
|
+
const external_module_namespaceObject = require("module");
|
|
955
|
+
const requireFromCreate = (0, external_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
956
|
+
function resolveDevelopRoot() {
|
|
957
|
+
const override = process.env.EXTENSION_CREATE_DEVELOP_ROOT;
|
|
958
|
+
if (override) return override;
|
|
959
|
+
try {
|
|
960
|
+
const pkgPath = requireFromCreate.resolve('extension-develop/package.json', {
|
|
961
|
+
paths: [
|
|
962
|
+
process.cwd(),
|
|
963
|
+
__dirname
|
|
964
|
+
]
|
|
965
|
+
});
|
|
966
|
+
return external_path_namespaceObject.dirname(pkgPath);
|
|
967
|
+
} catch {
|
|
968
|
+
return null;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
function resolveBuildDepsPath(developRoot) {
|
|
972
|
+
return external_path_namespaceObject.join(developRoot, 'webpack', 'webpack-lib', 'build-dependencies.json');
|
|
973
|
+
}
|
|
974
|
+
function loadBuildDependencies(developRoot) {
|
|
975
|
+
const metadataPath = resolveBuildDepsPath(developRoot);
|
|
976
|
+
if (!external_fs_namespaceObject.existsSync(metadataPath)) throw new Error(`Missing build-dependencies.json at ${metadataPath}`);
|
|
977
|
+
return JSON.parse(external_fs_namespaceObject.readFileSync(metadataPath, 'utf8'));
|
|
978
|
+
}
|
|
979
|
+
function readPackageJson(projectPath) {
|
|
980
|
+
try {
|
|
981
|
+
const raw = external_fs_namespaceObject.readFileSync(external_path_namespaceObject.join(projectPath, 'package.json'), 'utf8');
|
|
982
|
+
return JSON.parse(raw);
|
|
983
|
+
} catch {
|
|
984
|
+
return {};
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
function hasDependency(pkg, name) {
|
|
988
|
+
return Boolean(pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
|
|
989
|
+
}
|
|
990
|
+
function canResolve(dependency, paths) {
|
|
991
|
+
try {
|
|
992
|
+
requireFromCreate.resolve(dependency, {
|
|
993
|
+
paths
|
|
994
|
+
});
|
|
995
|
+
return true;
|
|
996
|
+
} catch {
|
|
997
|
+
return false;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function findConfigFile(projectPath, candidates) {
|
|
1001
|
+
return candidates.some((file)=>external_fs_namespaceObject.existsSync(external_path_namespaceObject.join(projectPath, file)));
|
|
1002
|
+
}
|
|
1003
|
+
function detectOptionalDependencies(projectPath) {
|
|
1004
|
+
const pkg = readPackageJson(projectPath);
|
|
1005
|
+
const usesReact = hasDependency(pkg, 'react') || hasDependency(pkg, 'react-dom');
|
|
1006
|
+
const usesPreact = hasDependency(pkg, 'preact');
|
|
1007
|
+
const usesVue = hasDependency(pkg, 'vue');
|
|
1008
|
+
const usesSvelte = hasDependency(pkg, 'svelte');
|
|
1009
|
+
const hasTsConfig = external_fs_namespaceObject.existsSync(external_path_namespaceObject.join(projectPath, 'tsconfig.json'));
|
|
1010
|
+
const usesTypeScript = hasDependency(pkg, "typescript") || hasTsConfig;
|
|
1011
|
+
const usesSass = hasDependency(pkg, 'sass') || hasDependency(pkg, 'sass-loader');
|
|
1012
|
+
const usesLess = hasDependency(pkg, 'less') || hasDependency(pkg, 'less-loader');
|
|
1013
|
+
const postCssConfigFiles = [
|
|
1014
|
+
'.postcssrc',
|
|
1015
|
+
'.postcssrc.json',
|
|
1016
|
+
'.postcssrc.yaml',
|
|
1017
|
+
'.postcssrc.yml',
|
|
1018
|
+
'postcss.config.mjs',
|
|
1019
|
+
'.postcssrc.js',
|
|
1020
|
+
'.postcssrc.cjs',
|
|
1021
|
+
'postcss.config.js',
|
|
1022
|
+
'postcss.config.cjs'
|
|
1023
|
+
];
|
|
1024
|
+
const tailwindConfigFiles = [
|
|
1025
|
+
'tailwind.config.mjs',
|
|
1026
|
+
'tailwind.config.cjs',
|
|
1027
|
+
'tailwind.config.js'
|
|
1028
|
+
];
|
|
1029
|
+
const usesPostCss = hasDependency(pkg, 'postcss') || hasDependency(pkg, 'postcss-loader') || findConfigFile(projectPath, postCssConfigFiles) || hasDependency(pkg, 'tailwindcss') || hasDependency(pkg, '@tailwindcss/postcss') || findConfigFile(projectPath, tailwindConfigFiles);
|
|
1030
|
+
const integrations = new Set();
|
|
1031
|
+
const deps = new Set();
|
|
1032
|
+
if (usesTypeScript) {
|
|
1033
|
+
integrations.add('TypeScript');
|
|
1034
|
+
deps.add("typescript");
|
|
1035
|
+
}
|
|
1036
|
+
if (usesReact) {
|
|
1037
|
+
integrations.add('React');
|
|
1038
|
+
deps.add('react-refresh');
|
|
1039
|
+
deps.add('@rspack/plugin-react-refresh');
|
|
1040
|
+
}
|
|
1041
|
+
if (usesPreact) {
|
|
1042
|
+
integrations.add('Preact');
|
|
1043
|
+
deps.add('@prefresh/core');
|
|
1044
|
+
deps.add('@prefresh/utils');
|
|
1045
|
+
deps.add('@rspack/plugin-preact-refresh');
|
|
1046
|
+
deps.add('preact');
|
|
1047
|
+
}
|
|
1048
|
+
if (usesVue) {
|
|
1049
|
+
integrations.add('Vue');
|
|
1050
|
+
deps.add('vue-loader');
|
|
1051
|
+
deps.add('@vue/compiler-sfc');
|
|
1052
|
+
}
|
|
1053
|
+
if (usesSvelte) {
|
|
1054
|
+
integrations.add('Svelte');
|
|
1055
|
+
deps.add('svelte-loader');
|
|
1056
|
+
deps.add("typescript");
|
|
1057
|
+
}
|
|
1058
|
+
if (usesSass) {
|
|
1059
|
+
integrations.add('Sass');
|
|
1060
|
+
deps.add('sass-loader');
|
|
1061
|
+
deps.add('postcss-loader');
|
|
1062
|
+
deps.add('postcss-scss');
|
|
1063
|
+
deps.add('postcss-preset-env');
|
|
1064
|
+
}
|
|
1065
|
+
if (usesLess) {
|
|
1066
|
+
integrations.add('Less');
|
|
1067
|
+
deps.add('less');
|
|
1068
|
+
deps.add('less-loader');
|
|
1069
|
+
}
|
|
1070
|
+
if (!usesPostCss || usesSass || usesLess) {
|
|
1071
|
+
if (usesPostCss) integrations.add('PostCSS');
|
|
1072
|
+
} else {
|
|
1073
|
+
integrations.add('PostCSS');
|
|
1074
|
+
deps.add('postcss');
|
|
1075
|
+
deps.add('postcss-loader');
|
|
1076
|
+
}
|
|
1077
|
+
return {
|
|
1078
|
+
integrations: Array.from(integrations),
|
|
1079
|
+
dependencies: Array.from(deps)
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
function buildOptionalInstallArgs(pm, dependencies, installDir) {
|
|
1083
|
+
if ('yarn' === pm) return [
|
|
1084
|
+
'add',
|
|
1085
|
+
...dependencies,
|
|
1086
|
+
'--cwd',
|
|
1087
|
+
installDir,
|
|
1088
|
+
'--optional'
|
|
1089
|
+
];
|
|
1090
|
+
if ('pnpm' === pm) return [
|
|
1091
|
+
'add',
|
|
1092
|
+
...dependencies,
|
|
1093
|
+
'--dir',
|
|
1094
|
+
installDir,
|
|
1095
|
+
'--save-optional'
|
|
1096
|
+
];
|
|
1097
|
+
if ('bun' === pm) return [
|
|
1098
|
+
'add',
|
|
1099
|
+
...dependencies,
|
|
1100
|
+
'--cwd',
|
|
1101
|
+
installDir,
|
|
1102
|
+
'--optional'
|
|
1103
|
+
];
|
|
1104
|
+
return [
|
|
1105
|
+
'install',
|
|
1106
|
+
...dependencies,
|
|
1107
|
+
'--prefix',
|
|
1108
|
+
installDir,
|
|
1109
|
+
'--save-optional'
|
|
1110
|
+
];
|
|
1111
|
+
}
|
|
1112
|
+
function buildBuildInstallArgs(pm, dependencies, dependencyMap) {
|
|
1113
|
+
const depsWithVersions = dependencies.map((dep)=>`${dep}@${dependencyMap[dep]}`);
|
|
1114
|
+
if ('yarn' === pm) return [
|
|
1115
|
+
'add',
|
|
1116
|
+
...depsWithVersions
|
|
1117
|
+
];
|
|
1118
|
+
if ('pnpm' === pm) return [
|
|
1119
|
+
'add',
|
|
1120
|
+
'--save',
|
|
1121
|
+
...depsWithVersions
|
|
1122
|
+
];
|
|
1123
|
+
if ('bun' === pm) return [
|
|
1124
|
+
'add',
|
|
1125
|
+
...depsWithVersions
|
|
1126
|
+
];
|
|
1127
|
+
return [
|
|
1128
|
+
'install',
|
|
1129
|
+
'--save',
|
|
1130
|
+
...depsWithVersions
|
|
1131
|
+
];
|
|
1132
|
+
}
|
|
1133
|
+
function resolveMissingBuildDeps(developRoot) {
|
|
1134
|
+
const dependencyMap = loadBuildDependencies(developRoot);
|
|
1135
|
+
const candidates = Object.keys(dependencyMap);
|
|
1136
|
+
const missing = candidates.filter((dep)=>!canResolve(dep, [
|
|
1137
|
+
developRoot,
|
|
1138
|
+
process.cwd()
|
|
1139
|
+
]));
|
|
1140
|
+
return {
|
|
1141
|
+
dependencies: missing,
|
|
1142
|
+
dependencyMap
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
function resolveMissingOptionalDeps(developRoot, projectPath) {
|
|
1146
|
+
const plan = detectOptionalDependencies(projectPath);
|
|
1147
|
+
const missing = plan.dependencies.filter((dep)=>!canResolve(dep, [
|
|
1148
|
+
developRoot,
|
|
1149
|
+
projectPath,
|
|
1150
|
+
process.cwd()
|
|
1151
|
+
]));
|
|
1152
|
+
return {
|
|
1153
|
+
integrations: plan.integrations,
|
|
1154
|
+
dependencies: missing
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
async function installBuildDependencies(developRoot, plan) {
|
|
1158
|
+
if (0 === plan.dependencies.length) return;
|
|
1159
|
+
const pm = detectPackageManagerFromEnv();
|
|
1160
|
+
const installMessage = installingBuildDependencies(plan.dependencies);
|
|
1161
|
+
const progressEnabled = shouldShowProgress();
|
|
1162
|
+
const progress = startProgressBar(installMessage, {
|
|
1163
|
+
enabled: progressEnabled
|
|
1164
|
+
});
|
|
1165
|
+
if (!progressEnabled) console.log(installMessage);
|
|
1166
|
+
try {
|
|
1167
|
+
const args = buildBuildInstallArgs(pm, plan.dependencies, plan.dependencyMap);
|
|
1168
|
+
const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
|
|
1169
|
+
const result = await runInstall(pm, args, {
|
|
1170
|
+
cwd: developRoot,
|
|
1171
|
+
stdio
|
|
1172
|
+
});
|
|
1173
|
+
if (0 !== result.code) throw new Error(installingDependenciesFailed(pm, args, result.code));
|
|
1174
|
+
} finally{
|
|
1175
|
+
progress.stop();
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
async function installOptionalDependencies(developRoot, plan) {
|
|
1179
|
+
if (0 === plan.dependencies.length) return;
|
|
1180
|
+
const pm = detectPackageManagerFromEnv();
|
|
1181
|
+
const installMessage = installingProjectIntegrations(plan.integrations);
|
|
1182
|
+
const progressEnabled = shouldShowProgress();
|
|
1183
|
+
const progress = startProgressBar(installMessage, {
|
|
1184
|
+
enabled: progressEnabled
|
|
1185
|
+
});
|
|
1186
|
+
if (!progressEnabled) console.log(installMessage);
|
|
1187
|
+
try {
|
|
1188
|
+
const args = buildOptionalInstallArgs(pm, plan.dependencies, developRoot);
|
|
1189
|
+
const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
|
|
1190
|
+
const result = await runInstall(pm, args, {
|
|
1191
|
+
cwd: developRoot,
|
|
1192
|
+
stdio
|
|
1193
|
+
});
|
|
1194
|
+
if (0 !== result.code) throw new Error(installingDependenciesFailed(pm, args, result.code));
|
|
1195
|
+
} finally{
|
|
1196
|
+
progress.stop();
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
async function installInternalDependencies(projectPath) {
|
|
1200
|
+
if ('test' === process.env.EXTENSION_ENV || 'true' === process.env.EXTENSION_SKIP_INTERNAL_INSTALL) return;
|
|
1201
|
+
const developRoot = resolveDevelopRoot();
|
|
1202
|
+
if (!developRoot) return;
|
|
1203
|
+
const buildPlan = resolveMissingBuildDeps(developRoot);
|
|
1204
|
+
await installBuildDependencies(developRoot, buildPlan);
|
|
1205
|
+
const optionalPlan = resolveMissingOptionalDeps(developRoot, projectPath);
|
|
1206
|
+
await installOptionalDependencies(developRoot, optionalPlan);
|
|
1207
|
+
}
|
|
1208
|
+
async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install = false }) {
|
|
745
1209
|
if (!projectNameInput) throw new Error(noProjectName());
|
|
746
1210
|
if (projectNameInput.startsWith('http')) throw new Error(noUrlAllowed());
|
|
747
1211
|
const projectPath = external_path_namespaceObject.isAbsolute(projectNameInput) ? projectNameInput : external_path_namespaceObject.join(process.cwd(), projectNameInput);
|
|
@@ -753,13 +1217,15 @@ async function extensionCreate(projectNameInput, { cliVersion, template = 'init'
|
|
|
753
1217
|
template,
|
|
754
1218
|
cliVersion
|
|
755
1219
|
});
|
|
1220
|
+
await installInternalDependencies(projectPath);
|
|
1221
|
+
if (install) await installDependencies(projectPath, projectName);
|
|
756
1222
|
await writeReadmeFile(projectPath, projectName);
|
|
757
1223
|
await writeManifestJson(projectPath, projectName);
|
|
758
1224
|
await initializeGitRepository(projectPath, projectName);
|
|
759
1225
|
await writeGitignore(projectPath);
|
|
760
1226
|
await setupBuiltInTests(projectPath, projectName);
|
|
761
1227
|
if (isTypeScriptTemplate(template)) await generateExtensionTypes(projectPath, projectName);
|
|
762
|
-
const successfulInstall = await successfullInstall(projectPath, projectName,
|
|
1228
|
+
const successfulInstall = await successfullInstall(projectPath, projectName, Boolean(install));
|
|
763
1229
|
console.log(successfulInstall);
|
|
764
1230
|
} catch (error) {
|
|
765
1231
|
throw error;
|
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
|
|
6
|
+
export declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install }: CreateOptions): Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type OptionalDepsPlan = {
|
|
2
|
+
integrations: string[];
|
|
3
|
+
dependencies: string[];
|
|
4
|
+
};
|
|
5
|
+
type BuildDepsPlan = {
|
|
6
|
+
dependencies: string[];
|
|
7
|
+
dependencyMap: Record<string, string>;
|
|
8
|
+
};
|
|
9
|
+
declare function resolveDevelopRoot(): string | null;
|
|
10
|
+
declare function detectOptionalDependencies(projectPath: string): OptionalDepsPlan;
|
|
11
|
+
declare function resolveMissingBuildDeps(developRoot: string): BuildDepsPlan;
|
|
12
|
+
declare function resolveMissingOptionalDeps(developRoot: string, projectPath: string): OptionalDepsPlan;
|
|
13
|
+
export declare function installInternalDependencies(projectPath: string): Promise<void>;
|
|
14
|
+
export declare const __testing__: {
|
|
15
|
+
resolveDevelopRoot: typeof resolveDevelopRoot;
|
|
16
|
+
resolveMissingBuildDeps: typeof resolveMissingBuildDeps;
|
|
17
|
+
resolveMissingOptionalDeps: typeof resolveMissingOptionalDeps;
|
|
18
|
+
detectOptionalDependencies: typeof detectOptionalDependencies;
|
|
19
|
+
};
|
|
20
|
+
export {};
|