Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@omlet/cli

Package Overview
Dependencies
Maintainers
1
Versions
662
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@omlet/cli - npm Package Compare versions

Comparing version 0.0.1-alpha.7 to 0.0.1-alpha.8

dist/node-src/auth.d.ts

23

dist/node-src/analyzer.d.ts

@@ -9,5 +9,11 @@ interface ParseOptions {

corePatterns: string[];
repo?: {
name?: string;
url?: string;
branch?: string;
scope?: string;
};
}
interface ModuleId {
hash: number;
hash: string;
path: string;

@@ -53,3 +59,3 @@ mtype: "package" | "local";

name: string;
type: "custom" | "core";
tags: string[];
source: SymbolWithSource;

@@ -60,8 +66,13 @@ declaration: Declaration;

}
interface AnalyzeResult {
export declare function parse(projectRoot: string, options: ParseOptions): Module[];
export declare function analyze(projectRoot: string, options: AnalyzeOptions): Promise<{
repo: {
scope: string | undefined;
url: string | undefined;
name: string;
branch: string;
};
components: Component[];
exports: Export[];
}
export declare function parse(projectRoot: string, options: ParseOptions): Module[];
export declare function analyze(projectRoot: string, options: AnalyzeOptions): AnalyzeResult;
}>;
export {};
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -7,4 +16,13 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.analyze = exports.parse = void 0;
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
const minimatch_1 = __importDefault(require("minimatch"));
const hosted_git_info_1 = __importDefault(require("hosted-git-info"));
const parse_git_config_1 = __importDefault(require("parse-git-config"));
const find_git_root_1 = __importDefault(require("find-git-root"));
const current_git_branch_1 = __importDefault(require("current-git-branch"));
const node_fetch_1 = __importDefault(require("node-fetch"));
const auth_1 = require("./auth");
const binding_1 = require("./binding");
const config_1 = require("./config");
function getComponentName(component) {

@@ -37,3 +55,3 @@ return component.declaration.symbol.split("#")[0];

function transformComponent(nativeComp, globMatcher) {
return (Object.assign(Object.assign({}, nativeComp), { id: getComponentId(nativeComp), name: getComponentName(nativeComp), type: globMatcher(nativeComp.source.source.path) ? "core" : "custom", dependencies: nativeComp.dependencies.map(transformDependency), reverse_dependencies: nativeComp.reverse_dependencies.map(transformDependency) }));
return (Object.assign(Object.assign({}, nativeComp), { id: getComponentId(nativeComp), name: getComponentName(nativeComp), tags: globMatcher(nativeComp.source.source.path) ? ["core"] : [], dependencies: nativeComp.dependencies.map(transformDependency), reverse_dependencies: nativeComp.reverse_dependencies.map(transformDependency) }));
}

@@ -45,3 +63,3 @@ function parse(projectRoot, options) {

exports.parse = parse;
function analyze(projectRoot, options) {
function runAnalysis(projectRoot, options) {
const result = JSON.parse((0, binding_1.analyze)(projectRoot, options.inputPatterns, options.ignorePatterns));

@@ -54,2 +72,100 @@ const globMatcher = createGlobMatcher(options.corePatterns);

}
function getGitUrl(repoPath) {
return __awaiter(this, void 0, void 0, function* () {
const packageJson = JSON.parse(yield promises_1.default.readFile(path_1.default.join(repoPath, "package.json"), "utf8"));
if (packageJson.repository) {
return typeof packageJson.repository === "string" ? packageJson.repository : packageJson.repository.url;
}
try {
const gitRoot = path_1.default.dirname((0, find_git_root_1.default)(repoPath));
const gitConfig = yield (0, parse_git_config_1.default)({ cwd: gitRoot, path: ".git/config" });
if (!gitConfig) {
return;
}
const remote = gitConfig["remote \"origin\""];
if (!remote) {
return;
}
return remote.url;
}
catch (e) {
return;
}
});
}
function getCurrentBranch(repoPath) {
const branch = (0, current_git_branch_1.default)({ altPath: repoPath });
if (!branch) {
return;
}
return branch;
}
function getRepoInfo(repoPath) {
return __awaiter(this, void 0, void 0, function* () {
const url = yield getGitUrl(repoPath);
if (!url) {
return;
}
const info = hosted_git_info_1.default.fromUrl(url);
if (!info) {
return;
}
return {
scope: info && info.user,
name: info && info.project,
url: info && info.https({ noGitPlus: true }),
branch: getCurrentBranch(repoPath)
};
});
}
function apiRequest(pathname, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const token = yield (0, auth_1.getToken)();
if (!token) {
throw new Error("Login required");
}
const response = yield (0, node_fetch_1.default)(`${config_1.BASE_URL}${pathname}`, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { "Content-Type": "application/json", "Cookie": `omlet-auth-token=${token}` }) }));
if (!response.ok) {
throw new Error(`${response.status} ${response.statusText}`);
}
return { data: yield response.json(), response };
});
}
function getDefaultWorkspace() {
return __awaiter(this, void 0, void 0, function* () {
const { data } = yield apiRequest(`/api/workspaces/default`);
return data;
});
}
function postAnalysis(workspace, analysisData) {
return __awaiter(this, void 0, void 0, function* () {
return apiRequest(`/api/workspaces/${workspace.slug}/analyses`, {
method: "POST",
body: JSON.stringify(analysisData),
});
});
}
function analyze(projectRoot, options) {
var _a, _b, _c, _d, _e, _f, _g, _h;
return __awaiter(this, void 0, void 0, function* () {
const workspace = yield getDefaultWorkspace();
const result = runAnalysis(projectRoot, options);
const repoInfo = yield getRepoInfo(projectRoot);
const repoScope = (_b = (_a = options.repo) === null || _a === void 0 ? void 0 : _a.scope) !== null && _b !== void 0 ? _b : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.scope;
const repoName = (_d = (_c = options.repo) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.name;
const repoUrl = (_f = (_e = options.repo) === null || _e === void 0 ? void 0 : _e.url) !== null && _f !== void 0 ? _f : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.name;
const branch = (_h = (_g = options.repo) === null || _g === void 0 ? void 0 : _g.branch) !== null && _h !== void 0 ? _h : repoInfo === null || repoInfo === void 0 ? void 0 : repoInfo.branch;
if (!repoName || !branch) {
throw Error("Repository name and current branch are required");
}
const analysisData = Object.assign(Object.assign({}, result), { repo: {
scope: repoScope,
url: repoUrl,
name: repoName,
branch
} });
yield postAnalysis(workspace, analysisData);
return analysisData;
});
}
exports.analyze = analyze;

@@ -19,2 +19,4 @@ "use strict";

const fs_1 = require("fs");
const auth_1 = require("./auth");
const LOGIN_SERVER_PORT = "8989";
function accumulateValues(value, previous = []) {

@@ -27,3 +29,3 @@ return previous.concat(value);

.version(package_json_1.version);
program.command("parse")
program.command("parse", { hidden: true })
.description("Parse JS/TS modules and extract component information")

@@ -44,19 +46,43 @@ .requiredOption("-r, --root <path>", "Path to the repository's root directory", process.cwd())

.requiredOption("-i, --input <glob-pattern>", "List of glob patterns for input files", accumulateValues)
.option("--repo-name <repo-name>", "Name of the repository <scope>/<name> (e.g. omlet/cli)")
.option("--repo-url <repo-url>", "URL of the repository")
.option("--current-branch <repo-url>", "Current branch in the repository")
.option("--ignore <glob-pattern>", "List of ignore patterns for skipping input files", accumulateValues, ["**/node_modules/**", "**/*.d.ts"])
.option("-c, --core <glob-pattern>", "List of core patterns to identify reusable components", accumulateValues, [])
.requiredOption("-o, --output <path|->", "Specify path for resulting output file", "omlet.json")
.option("-o, --output <path|->", "Specify path for resulting output file")
.action((args) => __awaiter(void 0, void 0, void 0, function* () {
const result = (0, analyzer_1.analyze)(args.root, {
var _a, _b;
if (!(yield (0, auth_1.isAuthenticated)())) {
console.log("Looks like you need to login first");
yield (0, auth_1.login)(parseInt(LOGIN_SERVER_PORT, 10));
console.log("Login successful!");
}
const [repoScope, repoName] = (_b = (_a = args.repoName) === null || _a === void 0 ? void 0 : _a.split("/")) !== null && _b !== void 0 ? _b : [];
const result = yield (0, analyzer_1.analyze)(args.root, {
inputPatterns: args.input,
ignorePatterns: args.ignore,
corePatterns: args.core
corePatterns: args.core,
repo: {
url: args.repoUrl,
scope: repoScope,
name: repoName,
branch: args.currentBranch
}
});
const output = JSON.stringify(result, null, 2);
if (args.output === "-") {
console.log(output);
}
else {
if (args.output) {
yield fs_1.promises.writeFile(args.output, JSON.stringify(result, null, 2));
}
console.log("Analysis submitted successfully.");
}));
program.command("login")
.description("Login to Omlet and get an access token")
.requiredOption("-p, --local-port <port>", "Port to be used by the local login server", LOGIN_SERVER_PORT)
.option("--print-token", "Prints token to the command line instead of saving it to the .omletrc file")
.action((args) => __awaiter(void 0, void 0, void 0, function* () {
const token = yield (0, auth_1.login)(parseInt(args.localPort, 10));
console.log("Login successful!");
if (args.printToken) {
console.log(token);
}
}));
program.on("command:*", () => {

@@ -63,0 +89,0 @@ program.outputHelp();

{
"name": "@omlet/cli",
"version": "0.0.1-alpha.7",
"version": "0.0.1-alpha.6",
"bin": {

@@ -29,5 +29,10 @@ "omlet": "bin/omlet"

"@napi-rs/cli": "^2.4.4",
"@types/current-git-branch": "^1.1.2",
"@types/hosted-git-info": "^3.0.2",
"@types/jest": "^27.4.1",
"@types/minimatch": "^3.0.5",
"@types/node": "^17.0.21",
"@types/node-fetch": "^2.6.1",
"@types/parse-git-config": "^3.0.1",
"@types/server-destroy": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.13.0",

@@ -63,18 +68,25 @@ "@typescript-eslint/parser": "^5.13.0",

"optionalDependencies": {
"@omlet/cli-win32-x64-msvc": "0.0.1-alpha.6",
"@omlet/cli-darwin-arm64": "0.0.1-alpha.6",
"@omlet/cli-darwin-x64": "0.0.1-alpha.6",
"@omlet/cli-linux-x64-gnu": "0.0.1-alpha.6",
"@omlet/cli-darwin-arm64": "0.0.1-alpha.6",
"@omlet/cli-freebsd-x64": "0.0.1-alpha.6",
"@omlet/cli-linux-arm-gnueabihf": "0.0.1-alpha.6",
"@omlet/cli-linux-arm64-gnu": "0.0.1-alpha.6",
"@omlet/cli-linux-arm64-musl": "0.0.1-alpha.6",
"@omlet/cli-linux-x64-gnu": "0.0.1-alpha.6",
"@omlet/cli-linux-x64-musl": "0.0.1-alpha.6",
"@omlet/cli-win32-arm64-msvc": "0.0.1-alpha.6",
"@omlet/cli-linux-arm-gnueabihf": "0.0.1-alpha.6",
"@omlet/cli-linux-x64-musl": "0.0.1-alpha.6",
"@omlet/cli-freebsd-x64": "0.0.1-alpha.6",
"@omlet/cli-win32-ia32-msvc": "0.0.1-alpha.6"
"@omlet/cli-win32-ia32-msvc": "0.0.1-alpha.6",
"@omlet/cli-win32-x64-msvc": "0.0.1-alpha.6"
},
"dependencies": {
"commander": "^9.0.0",
"minimatch": "^5.0.1"
"current-git-branch": "^1.1.0",
"find-git-root": "^1.0.4",
"hosted-git-info": "^5.0.0",
"minimatch": "^5.0.1",
"node-fetch": "^2.6.6",
"open": "^8.4.0",
"parse-git-config": "^3.0.0",
"server-destroy": "^1.0.1"
}
}
{
"name": "@omlet/cli",
"version": "0.0.1-alpha.7",
"version": "0.0.1-alpha.8",
"bin": {

@@ -29,5 +29,10 @@ "omlet": "bin/omlet"

"@napi-rs/cli": "^2.4.4",
"@types/current-git-branch": "^1.1.2",
"@types/hosted-git-info": "^3.0.2",
"@types/jest": "^27.4.1",
"@types/minimatch": "^3.0.5",
"@types/node": "^17.0.21",
"@types/node-fetch": "^2.6.1",
"@types/parse-git-config": "^3.0.1",
"@types/server-destroy": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.13.0",

@@ -63,18 +68,25 @@ "@typescript-eslint/parser": "^5.13.0",

"optionalDependencies": {
"@omlet/cli-win32-x64-msvc": "0.0.1-alpha.7",
"@omlet/cli-darwin-x64": "0.0.1-alpha.7",
"@omlet/cli-linux-x64-gnu": "0.0.1-alpha.7",
"@omlet/cli-darwin-arm64": "0.0.1-alpha.7",
"@omlet/cli-linux-arm64-gnu": "0.0.1-alpha.7",
"@omlet/cli-linux-arm64-musl": "0.0.1-alpha.7",
"@omlet/cli-win32-arm64-msvc": "0.0.1-alpha.7",
"@omlet/cli-linux-arm-gnueabihf": "0.0.1-alpha.7",
"@omlet/cli-linux-x64-musl": "0.0.1-alpha.7",
"@omlet/cli-freebsd-x64": "0.0.1-alpha.7",
"@omlet/cli-win32-ia32-msvc": "0.0.1-alpha.7"
"@omlet/cli-win32-x64-msvc": "0.0.1-alpha.8",
"@omlet/cli-darwin-x64": "0.0.1-alpha.8",
"@omlet/cli-linux-x64-gnu": "0.0.1-alpha.8",
"@omlet/cli-darwin-arm64": "0.0.1-alpha.8",
"@omlet/cli-linux-arm64-gnu": "0.0.1-alpha.8",
"@omlet/cli-linux-arm64-musl": "0.0.1-alpha.8",
"@omlet/cli-win32-arm64-msvc": "0.0.1-alpha.8",
"@omlet/cli-linux-arm-gnueabihf": "0.0.1-alpha.8",
"@omlet/cli-linux-x64-musl": "0.0.1-alpha.8",
"@omlet/cli-freebsd-x64": "0.0.1-alpha.8",
"@omlet/cli-win32-ia32-msvc": "0.0.1-alpha.8"
},
"dependencies": {
"commander": "^9.0.0",
"minimatch": "^5.0.1"
"current-git-branch": "^1.1.0",
"find-git-root": "^1.0.4",
"hosted-git-info": "^5.0.0",
"minimatch": "^5.0.1",
"node-fetch": "^2.6.6",
"open": "^8.4.0",
"parse-git-config": "^3.0.0",
"server-destroy": "^1.0.1"
}
}
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