New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@blitzjs/cli

Package Overview
Dependencies
Maintainers
1
Versions
359
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blitzjs/cli - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2-canary.0

lib/src/utils/dedent.js

8

lib/src/commands/db.js

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

// run migration
//await runMigrate()
yield exports.runMigrate();
server_1.log.success('Your database has been reset.');

@@ -115,3 +115,3 @@ process.exit(0);

return tslib_1.__awaiter(this, void 0, void 0, function* () {
const dbPath = connectionString.replace(/^(?:\.\.\/)+/, '');
const dbPath = connectionString.replace(/^(?:\.\.[\\/])+/, '');
const unlink = util_1.promisify(fs.unlink);

@@ -188,3 +188,5 @@ try {

if (res.confirm) {
const db = require(path.join(get_project_root_1.projectRoot, 'db')).default;
const prismaClientPath = require.resolve('@prisma/client', { paths: [get_project_root_1.projectRoot] });
const { PrismaClient } = require(prismaClientPath);
const db = new PrismaClient();
const dataSource = db.internalDatasources[0];

@@ -191,0 +193,0 @@ const connectorType = dataSource.connectorType;

@@ -6,15 +6,144 @@ "use strict";

const path = tslib_1.__importStar(require("path"));
// eslint-disable-next-line import/no-default-export
const got_1 = tslib_1.__importDefault(require("got"));
const server_1 = require("@blitzjs/server");
const dedent_1 = require("../utils/dedent");
const stream_1 = require("stream");
const util_1 = require("util");
const tar_1 = tslib_1.__importDefault(require("tar"));
const fs_extra_1 = require("fs-extra");
const rimraf_1 = tslib_1.__importDefault(require("rimraf"));
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
const os = tslib_1.__importStar(require("os"));
const pipeline = util_1.promisify(stream_1.Stream.pipeline);
function got(url) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return got_1.default(url).catch((e) => Boolean(console.error(e)) || e);
});
}
function gotJSON(url) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return JSON.parse((yield got(url)).body);
});
}
function isUrlValid(url) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return (yield got(url).catch((e) => e)).statusCode === 200;
});
}
function requireJSON(file) {
return JSON.parse(fs_extra_1.readFileSync(file).toString('utf-8'));
}
const GH_ROOT = 'https://github.com/';
const API_ROOT = 'https://api.github.com/repos/';
const CODE_ROOT = 'https://codeload.github.com/';
var InstallerType;
(function (InstallerType) {
InstallerType[InstallerType["Local"] = 0] = "Local";
InstallerType[InstallerType["Remote"] = 1] = "Remote";
})(InstallerType = exports.InstallerType || (exports.InstallerType = {}));
class Install extends command_1.Command {
// exposed for testing
normalizeInstallerPath(installerArg) {
const isNavtiveInstaller = /^([\w\-_]*)$/.test(installerArg);
const isUrlInstaller = installerArg.startsWith(GH_ROOT);
const isGitHubShorthandInstaller = /^([\w-_]*)\/([\w-_]*)$/.test(installerArg);
if (isNavtiveInstaller || isUrlInstaller || isGitHubShorthandInstaller) {
let repoUrl;
let subdirectory;
switch (true) {
case isUrlInstaller:
repoUrl = installerArg;
break;
case isNavtiveInstaller:
repoUrl = `${GH_ROOT}blitz-js/blitz`;
subdirectory = `installers/${installerArg}`;
break;
case isGitHubShorthandInstaller:
repoUrl = `${GH_ROOT}${installerArg}`;
break;
default:
throw new Error('should be impossible, the 3 cases are the only way to get into this switch');
}
return {
path: repoUrl,
subdirectory,
type: InstallerType.Remote,
};
}
else {
return {
path: installerArg,
type: InstallerType.Local,
};
}
}
/**
* Clones the repository into a temp directory, returning the path to the new directory
*
* Exposed for unit testing
*
* @param repoFullName username and repository name in the form {{user}}/{{repo}}
* @param defaultBranch the name of the repository's default branch
*/
cloneRepo(repoFullName, defaultBranch, subdirectory) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const installerDir = path.join(os.tmpdir(), `blitz-installer-${repoFullName.replace('/', '-')}`);
// clean up from previous run in case of error
rimraf_1.default.sync(installerDir);
fs_extra_1.mkdirSync(installerDir);
process.chdir(installerDir);
const repoName = repoFullName.split('/')[1];
// `tar` top-level filder is `${repoName}-${defaultBranch}`, and then we want to get our installer path
// within that folder
const extractPath = subdirectory ? [`${repoName}-${defaultBranch}/${subdirectory}`] : undefined;
const depth = subdirectory ? subdirectory.split('/').length + 1 : 1;
yield pipeline(got_1.default.stream(`${CODE_ROOT}${repoFullName}/tar.gz/${defaultBranch}`), tar_1.default.extract({ strip: depth }, extractPath));
return installerDir;
});
}
runInstallerAtPath(installerPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const installer = require(installerPath).default;
const installerArgs = this.argv.slice(1).reduce((acc, arg) => (Object.assign(Object.assign({}, acc), { [arg.split('=')[0].replace(/--/g, '')]: arg.split('=')[1]
? JSON.parse(`"${arg.split('=')[1]}"`)
: true })), {});
yield installer.run(installerArgs);
});
}
run() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { args } = this.parse(Install);
const isNavtiveInstaller = /^([\w]*)$/.test(args.installer);
if (isNavtiveInstaller) {
const pkgManager = fs_extra_1.existsSync(path.resolve('yarn.lock')) ? 'yarn' : 'npm';
const originalCwd = process.cwd();
const installerInfo = this.normalizeInstallerPath(args.installer);
if (installerInfo.type === InstallerType.Remote) {
const apiUrl = installerInfo.path.replace(GH_ROOT, API_ROOT);
const packageJsonPath = `${apiUrl}/contents/package.json`;
if (!(yield isUrlValid(packageJsonPath))) {
server_1.log.error(dedent_1.dedent `[blitz install] Installer path "${args.installer}" isn't valid. Please provide:
1. The name of a dependency to install (e.g. "tailwind"),
2. The full name of a GitHub repository (e.g. "blitz-js/example-installer"),
3. A full URL to a Github repository (e.g. "https://github.com/blitz-js/example-installer"), or
4. A file path to a locally-written installer.`);
}
else {
const repoInfo = yield gotJSON(apiUrl);
let spinner = server_1.log.spinner(`Cloning GitHub repository for ${args.installer}`).start();
const installerRepoPath = yield this.cloneRepo(repoInfo.full_name, repoInfo.default_branch, installerInfo.subdirectory);
spinner.stop();
spinner = server_1.log.spinner('Installing package.json dependencies').start();
yield new Promise((resolve) => {
const installProcess = cross_spawn_1.default(pkgManager, ['install']);
installProcess.on('exit', resolve);
});
spinner.stop();
const installerPackageMain = requireJSON('./package.json').main;
const installerEntry = path.resolve(installerPackageMain);
process.chdir(originalCwd);
yield this.runInstallerAtPath(installerEntry);
rimraf_1.default.sync(installerRepoPath);
}
}
else {
const installerPath = path.resolve(args.installer);
const installer = require(installerPath).default;
const installerArgs = this.argv.reduce((acc, arg) => (Object.assign(Object.assign({}, acc), { [arg.split('=')[0]]: JSON.parse(arg.split('=')[1] || String(true)) })), {});
yield installer.run(installerArgs);
yield this.runInstallerAtPath(path.resolve(args.installer));
}

@@ -24,3 +153,3 @@ });

}
exports.default = Install;
exports.Install = Install;
Install.description = 'Install a third-party package into your Blitz app';

@@ -27,0 +156,0 @@ Install.aliases = ['i'];

{
"name": "@blitzjs/cli",
"description": "Blitz.js CLI",
"version": "0.9.1",
"version": "0.9.2-canary.0",
"license": "MIT",

@@ -30,31 +30,35 @@ "scripts": {

"dependencies": {
"@oclif/command": "^1.5.20",
"@oclif/config": "^1.15.1",
"@oclif/plugin-help": "^2.2.3",
"@oclif/plugin-not-found": "^1.2.3",
"camelcase": "^6.0.0",
"chalk": "^4.0.0",
"chokidar": "^3.3.1",
"cross-spawn": "^7.0.2",
"dotenv": "^8.2.0",
"enquirer": "^2.3.4",
"globby": "^11.0.0",
"got": "^11.0.2",
"has-yarn": "^2.1.0",
"hasbin": "^1.2.3",
"minimist": "^1.2.5",
"pkg-dir": "^4.2.0",
"pluralize": "^8.0.0",
"ts-node": "^8.9.0",
"@oclif/command": "1.5.20",
"@oclif/config": "1.15.1",
"@oclif/plugin-help": "2.2.3",
"@oclif/plugin-not-found": "1.2.3",
"camelcase": "6.0.0",
"chalk": "4.0.0",
"chokidar": "3.3.1",
"cross-spawn": "7.0.2",
"dotenv": "8.2.0",
"enquirer": "2.3.4",
"globby": "11.0.0",
"got": "11.1.3",
"has-yarn": "2.1.0",
"hasbin": "1.2.3",
"minimist": "1.2.5",
"pkg-dir": "4.2.0",
"pluralize": "8.0.0",
"rimraf": "3.0.2",
"tar": "6.0.2",
"ts-node": "8.9.0",
"tsconfig-paths": "3.9.0"
},
"devDependencies": {
"@blitzjs/generator": "0.9.1",
"@blitzjs/installer": "0.9.1",
"@blitzjs/server": "0.9.1",
"@oclif/dev-cli": "^1.22.2",
"@oclif/test": "^1.2.5",
"@blitzjs/generator": "0.9.2-canary.0",
"@blitzjs/installer": "0.9.2-canary.0",
"@blitzjs/server": "0.9.2-canary.0",
"@oclif/dev-cli": "1.22.2",
"@oclif/test": "1.2.5",
"@prisma/cli": "2.0.0-beta.3",
"@rollup/pluginutils": "^3.0.8",
"@types/pluralize": "^0.0.29",
"@rollup/pluginutils": "3.0.8",
"@types/pluralize": "0.0.29",
"@types/rimraf": "3.0.0",
"@types/tar": "4.0.3",
"nock": "13.0.0-beta.3"

@@ -83,3 +87,3 @@ },

},
"gitHead": "ea91de84c01f5045fc71828b63cdab77c0855826"
"gitHead": "114ae77bec73166558817bad87d4a18c98bfd0c0"
}
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