soso-ppm 2.4.34 → 2.5.5
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/bin/soso.js +5 -0
- package/lib/commands/install.js +79 -17
- package/lib/commands/run.js +90 -0
- package/lib/utils/help.js +16 -2
- package/package.json +3 -3
package/bin/soso.js
CHANGED
|
@@ -6,6 +6,7 @@ const { publish } = require('../lib/commands/publish');
|
|
|
6
6
|
const { update } = require('../lib/commands/update');
|
|
7
7
|
const { info } = require('../lib/commands/info');
|
|
8
8
|
const { clean } = require('../lib/commands/clean');
|
|
9
|
+
const { run } = require('../lib/commands/run');
|
|
9
10
|
const { printHelp, printVersion } = require('../lib/utils/help');
|
|
10
11
|
const { enableDebug } = require('../lib/utils/logger');
|
|
11
12
|
|
|
@@ -47,6 +48,10 @@ async function main() {
|
|
|
47
48
|
}
|
|
48
49
|
break;
|
|
49
50
|
|
|
51
|
+
case 'run':
|
|
52
|
+
await run(args.slice(1));
|
|
53
|
+
break;
|
|
54
|
+
|
|
50
55
|
case 'version':
|
|
51
56
|
case '-v':
|
|
52
57
|
case '--version':
|
package/lib/commands/install.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const { spawn } = require('child_process');
|
|
5
6
|
const { loadRegistry, ensureDir } = require('../config');
|
|
6
7
|
const { Resolver } = require('../resolver');
|
|
7
8
|
const { CacheManager } = require('../cache');
|
|
8
9
|
const { Lockfile } = require('../lockfile');
|
|
9
10
|
const { success, error, info, debug } = require('../utils/logger');
|
|
11
|
+
const chalk = require('chalk');
|
|
10
12
|
const git = require('../utils/git');
|
|
11
13
|
const os = require('os');
|
|
12
14
|
|
|
@@ -56,28 +58,51 @@ async function install(args) {
|
|
|
56
58
|
const cache = new CacheManager();
|
|
57
59
|
const lockfile = new Lockfile(cwd);
|
|
58
60
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const resolved = await resolver.resolve(dependencies);
|
|
61
|
+
// Separate SOSO and npm packages
|
|
62
|
+
const sosoPackages = {};
|
|
63
|
+
const npmPackages = {};
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
for (const [name, range] of Object.entries(dependencies)) {
|
|
66
|
+
if (registry.packages[name]) {
|
|
67
|
+
sosoPackages[name] = range;
|
|
68
|
+
} else {
|
|
69
|
+
npmPackages[name] = range;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
65
72
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
// Install SOSO packages
|
|
74
|
+
if (Object.keys(sosoPackages).length > 0) {
|
|
75
|
+
info('Resolving SOSO dependency tree...');
|
|
76
|
+
const resolver = new Resolver(registry);
|
|
77
|
+
const resolved = await resolver.resolve(sosoPackages);
|
|
69
78
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
79
|
+
debug(`Resolved ${Object.keys(resolved).length} SOSO packages`);
|
|
80
|
+
|
|
81
|
+
// Prepare node_modules
|
|
82
|
+
const nodeModulesPath = path.join(cwd, 'node_modules');
|
|
83
|
+
ensureDir(nodeModulesPath);
|
|
76
84
|
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
// Install packages
|
|
86
|
+
const installed = {};
|
|
87
|
+
|
|
88
|
+
for (const [name, version] of Object.entries(resolved)) {
|
|
89
|
+
await installPackage(name, version, nodeModulesPath, cache, registry, installed);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Write lockfile
|
|
93
|
+
lockfile.write(installed);
|
|
94
|
+
|
|
95
|
+
success(`Installed ${Object.keys(installed).length} SOSO packages`);
|
|
96
|
+
}
|
|
79
97
|
|
|
80
|
-
|
|
98
|
+
// Install npm packages
|
|
99
|
+
if (Object.keys(npmPackages).length > 0) {
|
|
100
|
+
info(`Found ${Object.keys(npmPackages).length} packages not in SOSO registry, trying npm...`);
|
|
101
|
+
|
|
102
|
+
for (const [name, range] of Object.entries(npmPackages)) {
|
|
103
|
+
await installFromNpm(name, range, cwd);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
81
106
|
}
|
|
82
107
|
|
|
83
108
|
/**
|
|
@@ -217,4 +242,41 @@ function removeDirectory(dir) {
|
|
|
217
242
|
fs.rmdirSync(dir);
|
|
218
243
|
}
|
|
219
244
|
|
|
245
|
+
/**
|
|
246
|
+
* Install package from npm as fallback
|
|
247
|
+
*/
|
|
248
|
+
async function installFromNpm(packageName, versionRange, cwd) {
|
|
249
|
+
return new Promise((resolve, reject) => {
|
|
250
|
+
info(`Trying npm for ${packageName}...`);
|
|
251
|
+
|
|
252
|
+
const npmInstall = spawn('npm', ['install', `${packageName}@${versionRange}`, '--save'], {
|
|
253
|
+
cwd: cwd,
|
|
254
|
+
stdio: 'pipe',
|
|
255
|
+
shell: true
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
let stderr = '';
|
|
259
|
+
|
|
260
|
+
npmInstall.stderr.on('data', (data) => {
|
|
261
|
+
stderr += data.toString();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
npmInstall.on('close', (code) => {
|
|
265
|
+
if (code !== 0) {
|
|
266
|
+
// npm failed - show error in red
|
|
267
|
+
console.error(chalk.red(`✗ The package ${packageName} has not been found neither in npm repos or soso registries`));
|
|
268
|
+
reject(new Error(`Package ${packageName} not found`));
|
|
269
|
+
} else {
|
|
270
|
+
success(`Installed ${packageName} from npm`);
|
|
271
|
+
resolve();
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
npmInstall.on('error', (err) => {
|
|
276
|
+
console.error(chalk.red(`✗ The package ${packageName} has not been found neither in npm repos or soso registries`));
|
|
277
|
+
reject(new Error(`npm install failed: ${err.message}`));
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
220
282
|
module.exports = { install };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const { success, error, info, debug } = require('../utils/logger');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Run a JavaScript file with SOSO packages
|
|
10
|
+
*/
|
|
11
|
+
async function run(args) {
|
|
12
|
+
// Parse options
|
|
13
|
+
const options = {
|
|
14
|
+
noLog: args.includes('-nL') || args.includes('--no-log'),
|
|
15
|
+
silent: args.includes('-s') || args.includes('--silent')
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Get the script file (first non-option argument)
|
|
19
|
+
const scriptFile = args.find(arg => !arg.startsWith('-'));
|
|
20
|
+
|
|
21
|
+
if (!scriptFile) {
|
|
22
|
+
throw new Error('No script file specified. Usage: soso run <file.js> [options]');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Resolve script path
|
|
26
|
+
const scriptPath = path.resolve(process.cwd(), scriptFile);
|
|
27
|
+
|
|
28
|
+
// Check if file exists
|
|
29
|
+
if (!fs.existsSync(scriptPath)) {
|
|
30
|
+
throw new Error(`Script file not found: ${scriptFile}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Check if it's a .js file
|
|
34
|
+
if (!scriptPath.endsWith('.js')) {
|
|
35
|
+
throw new Error('Script must be a .js file');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!options.silent) {
|
|
39
|
+
info(`Running: ${scriptFile}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Prepare Node.js arguments
|
|
43
|
+
const nodeArgs = [scriptPath];
|
|
44
|
+
|
|
45
|
+
// Add additional arguments (those not consumed by soso run)
|
|
46
|
+
const extraArgs = args.filter(arg =>
|
|
47
|
+
arg !== scriptFile &&
|
|
48
|
+
arg !== '-nL' &&
|
|
49
|
+
arg !== '--no-log' &&
|
|
50
|
+
arg !== '-s' &&
|
|
51
|
+
arg !== '--silent'
|
|
52
|
+
);
|
|
53
|
+
nodeArgs.push(...extraArgs);
|
|
54
|
+
|
|
55
|
+
// Spawn Node.js process
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const stdio = options.silent ? 'ignore' : 'inherit';
|
|
58
|
+
|
|
59
|
+
const child = spawn('node', nodeArgs, {
|
|
60
|
+
cwd: process.cwd(),
|
|
61
|
+
stdio: stdio,
|
|
62
|
+
env: {
|
|
63
|
+
...process.env,
|
|
64
|
+
SOSO_RUN: '1',
|
|
65
|
+
SOSO_NO_LOG: options.noLog ? '1' : '0',
|
|
66
|
+
SOSO_SILENT: options.silent ? '1' : '0'
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
child.on('error', (err) => {
|
|
71
|
+
reject(new Error(`Failed to run script: ${err.message}`));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
child.on('close', (code) => {
|
|
75
|
+
if (code !== 0) {
|
|
76
|
+
if (!options.silent) {
|
|
77
|
+
error(`Script exited with code ${code}`);
|
|
78
|
+
}
|
|
79
|
+
process.exit(code);
|
|
80
|
+
} else {
|
|
81
|
+
if (!options.silent && !options.noLog) {
|
|
82
|
+
success('Script completed successfully');
|
|
83
|
+
}
|
|
84
|
+
resolve();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = { run };
|
package/lib/utils/help.js
CHANGED
|
@@ -22,28 +22,42 @@ ${chalk.bold('COMMANDS')}
|
|
|
22
22
|
${chalk.cyan('publish')} Publish current package to registry
|
|
23
23
|
${chalk.cyan('update')} [package] Update dependencies (or specific package)
|
|
24
24
|
${chalk.cyan('info')} <package> Show package information
|
|
25
|
+
${chalk.cyan('run')} <yourscript.js> Run JavaScript file with SOSO packages
|
|
25
26
|
${chalk.cyan('cache clean')} Clear the package cache
|
|
26
27
|
${chalk.cyan('version')} Show version number
|
|
27
28
|
${chalk.cyan('help')} Show this help message
|
|
28
29
|
|
|
29
30
|
${chalk.bold('OPTIONS')}
|
|
30
31
|
${chalk.cyan('--debug, -d')} Enable debug output
|
|
32
|
+
|
|
33
|
+
${chalk.bold('RUN OPTIONS')}
|
|
34
|
+
${chalk.cyan('-nL, --no-log')} Run without success log
|
|
35
|
+
${chalk.cyan('-s, --silent')} Run completely silent (no output)
|
|
31
36
|
|
|
32
37
|
${chalk.bold('EXAMPLES')}
|
|
33
38
|
${chalk.gray('# Install all dependencies')}
|
|
34
39
|
soso install
|
|
35
40
|
|
|
36
41
|
${chalk.gray('# Install specific package')}
|
|
37
|
-
soso install
|
|
42
|
+
soso install <Package>
|
|
38
43
|
|
|
39
44
|
${chalk.gray('# Publish current package')}
|
|
40
45
|
soso publish
|
|
41
46
|
|
|
42
47
|
${chalk.gray('# Show package info')}
|
|
43
|
-
soso info
|
|
48
|
+
soso info <Package>
|
|
44
49
|
|
|
45
50
|
${chalk.gray('# Clear cache')}
|
|
46
51
|
soso cache clean
|
|
52
|
+
|
|
53
|
+
${chalk.gray('# Run a script')}
|
|
54
|
+
soso run app.js
|
|
55
|
+
|
|
56
|
+
${chalk.gray('# Run silently')}
|
|
57
|
+
soso run yourscript.js -s
|
|
58
|
+
|
|
59
|
+
${chalk.gray('# Run without success log')}
|
|
60
|
+
soso run yourscript.js -nL
|
|
47
61
|
`);
|
|
48
62
|
}
|
|
49
63
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soso-ppm",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "Package manager made using nodejs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/Nitogx/soso-ppm.git"
|
|
22
|
+
"url": "git+https://github.com/Nitogx/soso-ppm.git"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/Nitogx/soso-ppm/issues"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.com/Nitogx/soso-ppm
|
|
27
|
+
"homepage": "https://github.com/Nitogx/soso-ppm/tree/master",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"semver": "^7.5.4",
|
|
30
30
|
"chalk": "^4.1.2",
|