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

apply

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apply - npm Package Compare versions

Comparing version 0.0.1 to 0.2.12

dist/Locators/DiskLocator.d.ts

4

dist/Applier/PresetApplier.d.ts

@@ -1,2 +0,2 @@

import { ApplierContract, ApplierOptionsContract, Bus, ImporterContract, Preset, ResolverContract, ResolverResult } from "../exports";
import { ApplierContract, ApplierOptionsContract, Bus, ImporterContract, Preset, ResolverContract, PresetLocation } from "../exports";
export declare class PresetApplier implements ApplierContract {

@@ -14,3 +14,3 @@ protected resolver: ResolverContract;

*/
protected cleanUp({ path, temporary }: ResolverResult): void;
protected cleanUp({ path, temporary }: PresetLocation): void;
}

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

};
this.bus.debug('Steps: ' + exports_1.color.gray(preset.actions.map(({ name }) => name).join(', ')));
this.bus.debug('Steps: ' + exports_1.color.gray(preset.actions.map(({ name }) => name).join(', ')) || exports_1.color.red('none'));
await this.performActions(preset, applierOptions);

@@ -36,0 +36,0 @@ this.bus.success(`${exports_1.color.magenta((_b = exports_1.contextualizeValue(preset, preset.name)) !== null && _b !== void 0 ? _b : applierOptions.resolvable)} has been applied.`);

@@ -1,10 +0,42 @@

export interface ResolverResult {
/**
* Information about a preset hosted on the local disk.
*/
export interface LocalPreset {
type: 'local';
/**
* The absolute path to the resolved generator.
* The absolute path to the preset on the local disk.
*/
path: string;
}
/**
* Information about a preset hosted on Git.
*/
export interface RepositoryPreset {
type: 'repository';
/**
* A value indicating whether or not the resolved path is temporary. If yes, this path
* should be deleted after processing.
* Whether or not to use SSH.
*/
ssh?: boolean;
/**
* The organization (or user) name.
*/
organization: string;
/**
* The repository name.
*/
repository: string;
/**
* The Git tag or branch to check out.
*/
tag?: string;
}
/**
* Information about a preset that was resolved from the user input.
*/
export declare type LocatedPreset = LocalPreset | RepositoryPreset;
/**
* Information about the location of a preset after being persisted.
*/
export interface PresetLocation {
path: string;
temporary: boolean;

@@ -35,25 +67,15 @@ }

*/
resolve(resolvable: string, options: ResolverOptions): Promise<ResolverResult>;
resolve(resolvable: string, options: ResolverOptions): Promise<PresetLocation>;
}
export interface GitResolverResult {
export interface LocatorContract {
/**
* Whether or not to use SSH.
* The locator name.
*/
ssh?: boolean;
name?: string;
/**
* The organization (or user) name.
* Determines where a preset is hosted thanks to its resolvable string.
*
* @param resolvable Any input.
*/
organization: string;
/**
* The repository name.
*/
repository: string;
/**
* The Git tag to check out.
*/
tag?: string;
/**
* The path to the subdirectory in the resolved directory.
*/
path?: string;
locate(resolvable: string): Promise<LocatedPreset>;
}

@@ -9,3 +9,3 @@ export declare class ExecutionError extends Error {

withoutStack(): this;
withMessage(message: string): this;
withMessage(...message: string[]): this;
}

@@ -34,4 +34,4 @@ "use strict";

}
withMessage(message) {
this.message = message;
withMessage(...message) {
this.message = message.join(' ');
return this;

@@ -38,0 +38,0 @@ }

@@ -1,6 +0,6 @@

import { ExecutionError, GitResolverResult } from "../exports";
import { ExecutionError, RepositoryPreset } from "../exports";
export declare class ResolutionError extends ExecutionError {
static localSubdirectoryNotFound(subdirectory: string): ResolutionError;
static localDirectoryNotFound(directory: string): ResolutionError;
static repositorySubdirectoryNotFound(subdirectory: string, repository: string): ResolutionError;
static subdirectoryNotFound(subdirectory: string, path: string): ResolutionError;
static notRepository(resolvable: string): ResolutionError;

@@ -10,3 +10,3 @@ static notCommunityOrganization(resolvable: string): ResolutionError;

static resolutionFailed(resolvable: string): ResolutionError;
static cloneFailed(options: GitResolverResult, error: Error): ResolutionError;
static cloneFailed(preset: RepositoryPreset, error: Error): ResolutionError;
}

@@ -16,5 +16,5 @@ "use strict";

}
static repositorySubdirectoryNotFound(subdirectory, repository) {
static subdirectoryNotFound(subdirectory, path) {
return new ResolutionError() //
.withMessage(`Subdirectory ${exports_1.color.underline(subdirectory)} does not exist in ${exports_1.color.magenta(repository)}.`)
.withMessage(`Subdirectory ${exports_1.color.underline(subdirectory)} does not exist in ${exports_1.color.underline(path)}.`)
.recoverable();

@@ -43,14 +43,20 @@ }

}
static cloneFailed(options, error) {
static cloneFailed(preset, error) {
var _a, _b, _c;
const repository = exports_1.color.magenta(`${options.organization}/${options.repository}`);
if ((_a = error.stack) === null || _a === void 0 ? void 0 : _a.includes('Could not find remote branch')) {
const repository = exports_1.color.magenta(`${preset.organization}/${preset.repository}`);
if ((_a = error.stack) === null || _a === void 0 ? void 0 : _a.includes('Remote branch')) {
return new ResolutionError()
.stopsExecution()
.withMessage(`The ${exports_1.color.magenta((_b = options.tag) !== null && _b !== void 0 ? _b : '<undefined>')}" branch does not exist in the remote repository.`)
.withMessage(`The ${exports_1.color.magenta((_b = preset.tag) !== null && _b !== void 0 ? _b : '<undefined>')} branch does not exist in the remote repository.`)
.withoutStack();
}
if ((_c = error.stack) === null || _c === void 0 ? void 0 : _c.includes('ERROR: Repository not found')) {
if ((_c = error.stack) === null || _c === void 0 ? void 0 : _c.includes('Permission denied (publickey)')) {
return new ResolutionError()
.stopsExecution()
.withMessage(`Access to ${exports_1.color.magenta(repository)} denied.`, `If you think it's an error, make sure you have an SSH key set up and linked to your Git account.`, `If the repository is public and you don't want to configure SSH, use the ${exports_1.color.magenta('--no-ssh')} flag.`)
.withoutStack();
}
if (['fatal: could not read Username', 'ERROR: Repository not found'].some((message) => { var _a; return (_a = error.stack) === null || _a === void 0 ? void 0 : _a.includes(message); })) {
return new ResolutionError()
.stopsExecution()
.withMessage(`Repository ${repository} could not be found. Make sure it exists and you have read access to it.`)

@@ -57,0 +63,0 @@ .withoutStack();

@@ -16,7 +16,7 @@ import 'reflect-metadata';

export * from "./Importer/index";
export * from "./Resolver/Resolvers/GitHubResolver";
export * from "./Resolver/Resolvers/CommunityResolver";
export * from "./Resolver/Resolvers/LocalResolver";
export * from "./Resolver/Resolver";
export * from "./Locators/GitLocator";
export * from "./Locators/DiskLocator";
export * from "./Resolvers/DefaultResolver";
export * from "./Resolvers/AliasResolver";
export * from "./Applier/index";
export * from "./Support/container";

@@ -19,7 +19,7 @@ "use strict";

tslib_1.__exportStar(require("./Importer"), exports);
tslib_1.__exportStar(require("./Resolver/Resolvers/GitHubResolver"), exports);
tslib_1.__exportStar(require("./Resolver/Resolvers/CommunityResolver"), exports);
tslib_1.__exportStar(require("./Resolver/Resolvers/LocalResolver"), exports);
tslib_1.__exportStar(require("./Resolver/Resolver"), exports);
tslib_1.__exportStar(require("./Locators/GitLocator"), exports);
tslib_1.__exportStar(require("./Locators/DiskLocator"), exports);
tslib_1.__exportStar(require("./Resolvers/DefaultResolver"), exports);
tslib_1.__exportStar(require("./Resolvers/AliasResolver"), exports);
tslib_1.__exportStar(require("./Applier"), exports);
tslib_1.__exportStar(require("./Support/container"), exports);

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

const lineImports = ['import', 'require'].some((statement) => line.includes(statement));
const lineMentionsImportValue = [exports_1.getPackage().name, 'color', '@/api'].some((imp) => line.includes(imp));
const lineMentionsImportValue = [exports_1.getPackage().name, 'color', '@/api', 'use-preset'].some((imp) => line.includes(imp));
if (lineImports && lineMentionsImportValue) {

@@ -97,0 +97,0 @@ return false;

export declare const Binding: {
Applier: symbol;
Resolver: symbol;
AliasResolver: symbol;
AliasResolverPath: symbol;
Locator: symbol;
Importer: symbol;

@@ -12,6 +15,6 @@ Handler: symbol;

export declare const Name: {
Resolver: string;
LocalResolver: string;
CommunityResolver: string;
GitHubResolver: string;
ResolverConfiguration: string;
DefaultResolver: string;
DiskLocator: string;
GitLocator: string;
Handler: {

@@ -18,0 +21,0 @@ readonly ApplyPreset: "apply-preset-handler";

@@ -7,2 +7,5 @@ "use strict";

Resolver: Symbol.for('resolver'),
AliasResolver: Symbol.for('resolver-configuration'),
AliasResolverPath: Symbol.for('resolver-configuration-path'),
Locator: Symbol.for('locator'),
Importer: Symbol.for('importer'),

@@ -16,6 +19,6 @@ Handler: Symbol.for('handler'),

exports.Name = {
Resolver: 'resolver',
LocalResolver: 'local-resolver',
CommunityResolver: 'community-resolver',
GitHubResolver: 'github-resolver',
ResolverConfiguration: 'resolver-configuration',
DefaultResolver: 'resolver',
DiskLocator: 'disk-locator',
GitLocator: 'git-locator',
Handler: {

@@ -22,0 +25,0 @@ ApplyPreset: 'apply-preset-handler',

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.container = void 0;
const os_1 = require("os");
const inversify_1 = require("inversify");
const exports_1 = require("@/exports");
const AliasResolver_1 = require("@/Resolvers/AliasResolver");
/**

@@ -18,6 +20,7 @@ * The application container.

// Resolvers
container.bind(exports_1.Binding.Resolver).to(exports_1.Resolver).whenTargetIsDefault();
container.bind(exports_1.Binding.Resolver).to(exports_1.LocalResolver).whenTargetNamed(exports_1.Name.LocalResolver);
container.bind(exports_1.Binding.Resolver).to(exports_1.CommunityResolver).whenTargetNamed(exports_1.Name.CommunityResolver);
container.bind(exports_1.Binding.Resolver).to(exports_1.GitHubResolver).whenTargetNamed(exports_1.Name.GitHubResolver);
container.bind(exports_1.Binding.AliasResolver).to(AliasResolver_1.AliasResolver).whenTargetIsDefault();
container.bind(exports_1.Binding.AliasResolverPath).toConstantValue(os_1.homedir());
container.bind(exports_1.Binding.Resolver).to(exports_1.DefaultResolver).whenTargetIsDefault();
container.bind(exports_1.Binding.Locator).to(exports_1.DiskLocator).whenTargetNamed(exports_1.Name.DiskLocator);
container.bind(exports_1.Binding.Locator).to(exports_1.GitLocator).whenTargetNamed(exports_1.Name.GitLocator);
// Importers

@@ -24,0 +27,0 @@ container.bind(exports_1.Binding.Importer).to(exports_1.ModuleImporter).whenTargetIsDefault();

{
"name": "{{ kebabPresetName }}",
"version": "0.1",
"author": "{{ author }}",
"license": "MIT",
"preset": "preset.ts",
"devDependencies": {
"use-preset": "^0.2"
}
"name": "{{ kebabPresetName }}",
"version": "0.1",
"author": "{{ author }}",
"license": "MIT",
"preset": "preset.ts",
"devDependencies": {
"apply": "^0.2"
}
}

@@ -1,4 +0,4 @@

import { Preset } from 'use-preset';
import { Preset } from 'apply';
Preset.setName('{{ presetName }}');
Preset.extract();
{
"name": "apply",
"version": "0.0.1",
"version": "0.2.12",
"description": "Elegant, ecosystem-agnostic preset mechanism",

@@ -11,3 +11,3 @@ "license": "MIT",

},
"repository": "https://github.com/use-preset/cli",
"repository": "https://github.com/preset/cli",
"main": "dist/api.js",

@@ -65,2 +65,3 @@ "typings": "dist/api.d.ts",

"cac": "^6.6.1",
"cosmiconfig": "^7.0.0",
"debug": "4.2.0",

@@ -67,0 +68,0 @@ "deepmerge": "^4.2.2",

@@ -13,8 +13,8 @@ <p align="center">

<br />
<a href="https://github.com/use-preset/use-preset/actions?query=workflow%3Atests">
<img alt="Status" src="https://github.com/use-preset/use-preset/workflows/tests/badge.svg">
<a href="https://github.com/preset/cli/actions?query=workflow%3Atests">
<img alt="Status" src="https://github.com/preset/cli/workflows/tests/badge.svg">
</a>
<span>&nbsp;</span>
<a href="https://www.npmjs.com/package/use-preset">
<img alt="npm" src="https://img.shields.io/npm/v/use-preset">
<a href="https://www.npmjs.com/package/apply">
<img alt="npm" src="https://img.shields.io/npm/v/apply">
</a>

@@ -31,3 +31,3 @@ <span>&nbsp;</span>

<br />
<pre align="center">npx use-preset &lt;your-username/your-preset&gt;</pre>
<pre align="center">npx apply &lt;your-username/your-preset&gt;</pre>
</p>

@@ -34,0 +34,0 @@

@@ -20,3 +20,3 @@ import fs from 'fs-extra';

ResolverContract,
ResolverResult,
PresetLocation,
wrap,

@@ -62,3 +62,3 @@ } from '@/exports';

this.bus.debug('Steps: ' + color.gray(preset.actions.map(({ name }) => name).join(', ')));
this.bus.debug('Steps: ' + color.gray(preset.actions.map(({ name }) => name).join(', ')) || color.red('none'));

@@ -130,3 +130,3 @@ await this.performActions(preset, applierOptions);

*/
protected cleanUp({ path, temporary }: ResolverResult): void {
protected cleanUp({ path, temporary }: PresetLocation): void {
if (!temporary) {

@@ -133,0 +133,0 @@ return;

@@ -1,11 +0,50 @@

export interface ResolverResult {
/**
* Information about a preset hosted on the local disk.
*/
export interface LocalPreset {
type: 'local';
/**
* The absolute path to the resolved generator.
* The absolute path to the preset on the local disk.
*/
path: string;
}
/**
* Information about a preset hosted on Git.
*/
export interface RepositoryPreset {
type: 'repository';
/**
* A value indicating whether or not the resolved path is temporary. If yes, this path
* should be deleted after processing.
* Whether or not to use SSH.
*/
ssh?: boolean;
/**
* The organization (or user) name.
*/
organization: string;
/**
* The repository name.
*/
repository: string;
/**
* The Git tag or branch to check out.
*/
tag?: string;
}
/**
* Information about a preset that was resolved from the user input.
*/
export type LocatedPreset = LocalPreset | RepositoryPreset;
/**
* Information about the location of a preset after being persisted.
*/
export interface PresetLocation {
path: string;
temporary: boolean;

@@ -40,30 +79,17 @@ }

*/
resolve(resolvable: string, options: ResolverOptions): Promise<ResolverResult>;
resolve(resolvable: string, options: ResolverOptions): Promise<PresetLocation>;
}
export interface GitResolverResult {
export interface LocatorContract {
/**
* Whether or not to use SSH.
* The locator name.
*/
ssh?: boolean;
name?: string;
/**
* The organization (or user) name.
* Determines where a preset is hosted thanks to its resolvable string.
*
* @param resolvable Any input.
*/
organization: string;
/**
* The repository name.
*/
repository: string;
/**
* The Git tag to check out.
*/
tag?: string;
/**
* The path to the subdirectory in the resolved directory.
*/
path?: string;
locate(resolvable: string): Promise<LocatedPreset>;
}

@@ -40,6 +40,6 @@ export class ExecutionError extends Error {

withMessage(message: string): this {
this.message = message;
withMessage(...message: string[]): this {
this.message = message.join(' ');
return this;
}
}

@@ -1,2 +0,2 @@

import { color, ExecutionError, GitResolverResult } from '@/exports';
import { color, ExecutionError, RepositoryPreset } from '@/exports';

@@ -16,5 +16,5 @@ export class ResolutionError extends ExecutionError {

static repositorySubdirectoryNotFound(subdirectory: string, repository: string): ResolutionError {
static subdirectoryNotFound(subdirectory: string, path: string): ResolutionError {
return new ResolutionError() //
.withMessage(`Subdirectory ${color.underline(subdirectory)} does not exist in ${color.magenta(repository)}.`)
.withMessage(`Subdirectory ${color.underline(subdirectory)} does not exist in ${color.underline(path)}.`)
.recoverable();

@@ -48,15 +48,26 @@ }

static cloneFailed(options: GitResolverResult, error: Error): ResolutionError {
const repository = color.magenta(`${options.organization}/${options.repository}`);
static cloneFailed(preset: RepositoryPreset, error: Error): ResolutionError {
const repository = color.magenta(`${preset.organization}/${preset.repository}`);
if (error.stack?.includes('Could not find remote branch')) {
if (error.stack?.includes('Remote branch')) {
return new ResolutionError()
.stopsExecution()
.withMessage(`The ${color.magenta(options.tag ?? '<undefined>')}" branch does not exist in the remote repository.`)
.withMessage(`The ${color.magenta(preset.tag ?? '<undefined>')} branch does not exist in the remote repository.`)
.withoutStack();
}
if (error.stack?.includes('ERROR: Repository not found')) {
if (error.stack?.includes('Permission denied (publickey)')) {
return new ResolutionError()
.stopsExecution()
.withMessage(
`Access to ${color.magenta(repository)} denied.`,
`If you think it's an error, make sure you have an SSH key set up and linked to your Git account.`,
`If the repository is public and you don't want to configure SSH, use the ${color.magenta('--no-ssh')} flag.`,
)
.withoutStack();
}
if (['fatal: could not read Username', 'ERROR: Repository not found'].some((message) => error.stack?.includes(message))) {
return new ResolutionError()
.stopsExecution()
.withMessage(`Repository ${repository} could not be found. Make sure it exists and you have read access to it.`)

@@ -63,0 +74,0 @@ .withoutStack();

@@ -20,6 +20,6 @@ import 'reflect-metadata';

export * from './Resolver/Resolvers/GitHubResolver';
export * from './Resolver/Resolvers/CommunityResolver';
export * from './Resolver/Resolvers/LocalResolver';
export * from './Resolver/Resolver';
export * from './Locators/GitLocator';
export * from './Locators/DiskLocator';
export * from './Resolvers/DefaultResolver';
export * from './Resolvers/AliasResolver';

@@ -26,0 +26,0 @@ export * from './Applier';

@@ -109,3 +109,3 @@ import vm from 'vm';

const lineImports = ['import', 'require'].some((statement) => line.includes(statement));
const lineMentionsImportValue = [getPackage().name, 'color', '@/api'].some((imp) => line.includes(imp));
const lineMentionsImportValue = [getPackage().name, 'color', '@/api', 'use-preset'].some((imp) => line.includes(imp));

@@ -112,0 +112,0 @@ if (lineImports && lineMentionsImportValue) {

export const Binding = {
Applier: Symbol.for('applier'),
Resolver: Symbol.for('resolver'),
AliasResolver: Symbol.for('resolver-configuration'),
AliasResolverPath: Symbol.for('resolver-configuration-path'),
Locator: Symbol.for('locator'),
Importer: Symbol.for('importer'),

@@ -13,6 +16,6 @@ Handler: Symbol.for('handler'),

export const Name = {
Resolver: 'resolver',
LocalResolver: 'local-resolver',
CommunityResolver: 'community-resolver',
GitHubResolver: 'github-resolver',
ResolverConfiguration: 'resolver-configuration',
DefaultResolver: 'resolver',
DiskLocator: 'disk-locator',
GitLocator: 'git-locator',

@@ -19,0 +22,0 @@ Handler: {

@@ -0,1 +1,2 @@

import { homedir } from 'os';
import { Container } from 'inversify';

@@ -6,3 +7,2 @@ import {

bus,
CommunityResolver,
ConsoleOutput,

@@ -16,7 +16,8 @@ CustomPrompt,

ExtractHandler,
GitHubResolver,
GroupHandler,
HookHandler,
InstallDependenciesHandler,
LocalResolver,
DefaultResolver,
DiskLocator,
GitLocator,
ModuleImporter,

@@ -26,4 +27,4 @@ Name,

PromptHandler,
Resolver,
} from '@/exports';
import { AliasResolver } from '@/Resolvers/AliasResolver';

@@ -44,7 +45,9 @@ /**

// Resolvers
container.bind(Binding.Resolver).to(Resolver).whenTargetIsDefault();
container.bind(Binding.Resolver).to(LocalResolver).whenTargetNamed(Name.LocalResolver);
container.bind(Binding.Resolver).to(CommunityResolver).whenTargetNamed(Name.CommunityResolver);
container.bind(Binding.Resolver).to(GitHubResolver).whenTargetNamed(Name.GitHubResolver);
container.bind(Binding.AliasResolver).to(AliasResolver).whenTargetIsDefault();
container.bind(Binding.AliasResolverPath).toConstantValue(homedir());
container.bind(Binding.Resolver).to(DefaultResolver).whenTargetIsDefault();
container.bind(Binding.Locator).to(DiskLocator).whenTargetNamed(Name.DiskLocator);
container.bind(Binding.Locator).to(GitLocator).whenTargetNamed(Name.GitLocator);
// Importers

@@ -51,0 +54,0 @@ container.bind(Binding.Importer).to(ModuleImporter).whenTargetIsDefault();

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