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

@sewing-kit/plugins

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sewing-kit/plugins - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

32

build/cjs/api.js

@@ -1,1 +0,31 @@

"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createStep = createStep;
const defaultSkip = () => false;
function createStep(runOrStep, run) {
return typeof runOrStep === 'function' ? {
run: runOrStep,
skip: defaultSkip
} : {
run: run,
...normalizeOptions(runOrStep)
};
}
function normalizeOptions({
skip,
...rest
}) {
return { ...rest,
skip: skip ? normalizeSkip(skip) : defaultSkip
};
}
function normalizeSkip(skipper) {
return typeof skipper === 'function' ? skipper : skipped => skipped.some(skip => skipper.test(skip));
}

@@ -6,3 +6,118 @@ "use strict";

});
var _exportNames = {
DiagnosticError: true,
Task: true,
Env: true,
WorkspaceTasks: true,
ProjectTasks: true,
SeriesHook: true,
WaterfallHook: true,
Project: true,
Package: true,
PackageBinary: true,
PackageEntry: true,
Service: true,
WebApp: true,
Workspace: true,
Runtime: true
};
Object.defineProperty(exports, "DiagnosticError", {
enumerable: true,
get: function () {
return _ui.DiagnosticError;
}
});
Object.defineProperty(exports, "Task", {
enumerable: true,
get: function () {
return _tasks.Task;
}
});
Object.defineProperty(exports, "Env", {
enumerable: true,
get: function () {
return _tasks.Env;
}
});
Object.defineProperty(exports, "WorkspaceTasks", {
enumerable: true,
get: function () {
return _tasks.WorkspaceTasks;
}
});
Object.defineProperty(exports, "ProjectTasks", {
enumerable: true,
get: function () {
return _tasks.ProjectTasks;
}
});
Object.defineProperty(exports, "SeriesHook", {
enumerable: true,
get: function () {
return _hooks.SeriesHook;
}
});
Object.defineProperty(exports, "WaterfallHook", {
enumerable: true,
get: function () {
return _hooks.WaterfallHook;
}
});
Object.defineProperty(exports, "Project", {
enumerable: true,
get: function () {
return _model.Project;
}
});
Object.defineProperty(exports, "Package", {
enumerable: true,
get: function () {
return _model.Package;
}
});
Object.defineProperty(exports, "PackageBinary", {
enumerable: true,
get: function () {
return _model.PackageBinary;
}
});
Object.defineProperty(exports, "PackageEntry", {
enumerable: true,
get: function () {
return _model.PackageEntry;
}
});
Object.defineProperty(exports, "Service", {
enumerable: true,
get: function () {
return _model.Service;
}
});
Object.defineProperty(exports, "WebApp", {
enumerable: true,
get: function () {
return _model.WebApp;
}
});
Object.defineProperty(exports, "Workspace", {
enumerable: true,
get: function () {
return _model.Workspace;
}
});
Object.defineProperty(exports, "Runtime", {
enumerable: true,
get: function () {
return _model.Runtime;
}
});
var _ui = require("@sewing-kit/ui");
var _tasks = require("@sewing-kit/tasks");
var _hooks = require("@sewing-kit/hooks");
var _model = require("@sewing-kit/model");
var _api = require("./api");

@@ -12,2 +127,3 @@

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {

@@ -25,2 +141,3 @@ enumerable: true,

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {

@@ -38,2 +155,3 @@ enumerable: true,

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {

@@ -51,2 +169,3 @@ enumerable: true,

if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
Object.defineProperty(exports, key, {

@@ -53,0 +172,0 @@ enumerable: true,

147

build/cjs/plugins.js

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

exports.createComposedWorkspacePlugin = createComposedWorkspacePlugin;
exports.createWorkspaceTestPlugin = exports.createWorkspaceTypeCheckPlugin = exports.createWorkspaceLintPlugin = exports.createWorkspaceDevPlugin = exports.createWorkspaceBuildPlugin = exports.createProjectTestPlugin = exports.createProjectDevPlugin = exports.createProjectBuildPlugin = exports.PluginTarget = exports.PLUGIN_MARKER = void 0;
exports.createWorkspaceLintPlugin = exports.createWorkspaceTypeCheckPlugin = exports.createWorkspaceTestPlugin = exports.createWorkspaceDevPlugin = exports.createWorkspaceBuildPlugin = exports.createProjectTestPlugin = exports.createProjectDevPlugin = exports.createProjectBuildPlugin = exports.PluginTarget = exports.PLUGIN_MARKER = void 0;
const PLUGIN_MARKER = Symbol('SewingKit.Plugin');

@@ -22,4 +22,6 @@ exports.PLUGIN_MARKER = PLUGIN_MARKER;

function createProjectPlugin(plugin) {
return { ...plugin,
function createProjectPlugin(id, run) {
return {
id,
run,
target: PluginTarget.Project,

@@ -30,2 +32,35 @@ [PLUGIN_MARKER]: true

const createProjectBuildPlugin = (id, run) => createProjectPlugin(id, ({
tasks,
...context
}) => {
tasks.build.hook(task => run({ ...context,
...task
}));
});
exports.createProjectBuildPlugin = createProjectBuildPlugin;
const createProjectDevPlugin = (id, run) => createProjectPlugin(id, ({
tasks,
...context
}) => {
tasks.dev.hook(task => run({ ...context,
...task
}));
});
exports.createProjectDevPlugin = createProjectDevPlugin;
const createProjectTestPlugin = (id, run) => createProjectPlugin(id, ({
tasks,
...context
}) => {
tasks.test.hook(task => run({ ...context,
...task
}));
});
exports.createProjectTestPlugin = createProjectTestPlugin;
function createComposedProjectPlugin(id, pluginsOrCompose) {

@@ -37,10 +72,14 @@ const compose = typeof pluginsOrCompose === 'function' ? pluginsOrCompose : composer => {

};
return createProjectPlugin({
return {
id,
compose
});
compose,
target: PluginTarget.Project,
[PLUGIN_MARKER]: true
};
}
function createWorkspacePlugin(plugin) {
return { ...plugin,
function createWorkspacePlugin(id, run) {
return {
id,
run,
target: PluginTarget.Workspace,

@@ -51,49 +90,69 @@ [PLUGIN_MARKER]: true

function createComposedWorkspacePlugin(id, plugins) {
return createWorkspacePlugin({
id,
const createWorkspaceBuildPlugin = (id, run) => createWorkspacePlugin(id, ({
tasks,
...context
}) => {
tasks.build.hook(task => run({ ...context,
...task
}));
});
compose(composer) {
for (const plugin of plugins) {
composer.use(plugin);
}
}
exports.createWorkspaceBuildPlugin = createWorkspaceBuildPlugin;
});
}
const createWorkspaceDevPlugin = (id, run) => createWorkspacePlugin(id, ({
tasks,
...context
}) => {
tasks.dev.hook(task => run({ ...context,
...task
}));
});
const createProjectTaskPluginCreator = task => (id, run) => createProjectPlugin({
id,
exports.createWorkspaceDevPlugin = createWorkspaceDevPlugin;
run(tasks, api) {
tasks[task].tapPromise(id, task => Promise.resolve(run(task, api)));
}
const createWorkspaceTestPlugin = (id, run) => createWorkspacePlugin(id, ({
tasks,
...context
}) => {
tasks.test.hook(task => run({ ...context,
...task
}));
});
const createProjectBuildPlugin = createProjectTaskPluginCreator('build');
exports.createProjectBuildPlugin = createProjectBuildPlugin;
const createProjectDevPlugin = createProjectTaskPluginCreator('dev');
exports.createProjectDevPlugin = createProjectDevPlugin;
const createProjectTestPlugin = createProjectTaskPluginCreator('test');
exports.createProjectTestPlugin = createProjectTestPlugin;
exports.createWorkspaceTestPlugin = createWorkspaceTestPlugin;
const createWorkspaceTaskPluginCreator = task => (id, run) => createWorkspacePlugin({
id,
const createWorkspaceTypeCheckPlugin = (id, run) => createWorkspacePlugin(id, ({
tasks,
...context
}) => {
tasks.typeCheck.hook(task => run({ ...context,
...task
}));
});
run(tasks, api) {
tasks[task].tapPromise(id, task => Promise.resolve(run(task, api)));
}
exports.createWorkspaceTypeCheckPlugin = createWorkspaceTypeCheckPlugin;
const createWorkspaceLintPlugin = (id, run) => createWorkspacePlugin(id, ({
tasks,
...context
}) => {
tasks.lint.hook(task => run({ ...context,
...task
}));
});
const createWorkspaceBuildPlugin = createWorkspaceTaskPluginCreator('build');
exports.createWorkspaceBuildPlugin = createWorkspaceBuildPlugin;
const createWorkspaceDevPlugin = createWorkspaceTaskPluginCreator('dev');
exports.createWorkspaceDevPlugin = createWorkspaceDevPlugin;
const createWorkspaceLintPlugin = createWorkspaceTaskPluginCreator('lint');
exports.createWorkspaceLintPlugin = createWorkspaceLintPlugin;
const createWorkspaceTypeCheckPlugin = createWorkspaceTaskPluginCreator('typeCheck');
exports.createWorkspaceTypeCheckPlugin = createWorkspaceTypeCheckPlugin;
const createWorkspaceTestPlugin = createWorkspaceTaskPluginCreator('test');
exports.createWorkspaceTestPlugin = createWorkspaceTestPlugin;
function createComposedWorkspacePlugin(id, pluginsOrCompose) {
const compose = typeof pluginsOrCompose === 'function' ? pluginsOrCompose : composer => {
for (const plugin of pluginsOrCompose) {
if (plugin) composer.use(plugin);
}
};
return {
id,
compose,
target: PluginTarget.Workspace,
[PLUGIN_MARKER]: true
};
}

@@ -6,14 +6,6 @@ "use strict";

});
exports.addHooks = addHooks;
exports.toArgs = toArgs;
exports.lazy = lazy;
var _changeCase = require("change-case");
function addHooks(adder) {
return hooks => {
Object.assign(hooks, adder());
};
}
function toArgs(flags, {

@@ -38,8 +30,2 @@ dasherize = false

}, []);
}
function lazy(asyncImport) {
return async (...args) => {
return (await asyncImport())(...args);
};
}

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

declare type Step = import('@sewing-kit/ui').Step;
export interface PluginApi {

@@ -8,3 +9,10 @@ read(path: string): Promise<string>;

tmpPath(...parts: string[]): string;
createStep: typeof createStep;
}
declare type Skipper = ((skipped: readonly string[]) => boolean) | RegExp;
export declare function createStep(run: Step['run']): Step;
export declare function createStep(options: Omit<Step, 'run' | 'skip'> & {
skip?: Skipper;
}, run: Step['run']): Step;
export {};
//# sourceMappingURL=api.d.ts.map
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const defaultSkip = () => false;
function createStep(runOrStep, run) {
return typeof runOrStep === 'function'
? { run: runOrStep, skip: defaultSkip }
: Object.assign({ run: run }, normalizeOptions(runOrStep));
}
exports.createStep = createStep;
function normalizeOptions(_a) {
var { skip } = _a, rest = __rest(_a, ["skip"]);
return Object.assign(Object.assign({}, rest), { skip: skip ? normalizeSkip(skip) : defaultSkip });
}
function normalizeSkip(skipper) {
return typeof skipper === 'function'
? skipper
: (skipped) => skipped.some((skip) => skipper.test(skip));
}

@@ -0,1 +1,5 @@

export { DiagnosticError } from '@sewing-kit/ui';
export { Task, Env, WorkspaceTasks, ProjectTasks } from '@sewing-kit/tasks';
export { SeriesHook, WaterfallHook } from '@sewing-kit/hooks';
export { Project, Package, PackageBinary, PackageEntry, Service, WebApp, Workspace, Runtime, } from '@sewing-kit/model';
export * from './api';

@@ -2,0 +6,0 @@ export * from './plugins';

@@ -6,4 +6,21 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var ui_1 = require("@sewing-kit/ui");
exports.DiagnosticError = ui_1.DiagnosticError;
var tasks_1 = require("@sewing-kit/tasks");
exports.Task = tasks_1.Task;
exports.Env = tasks_1.Env;
var hooks_1 = require("@sewing-kit/hooks");
exports.SeriesHook = hooks_1.SeriesHook;
exports.WaterfallHook = hooks_1.WaterfallHook;
var model_1 = require("@sewing-kit/model");
exports.Package = model_1.Package;
exports.PackageBinary = model_1.PackageBinary;
exports.PackageEntry = model_1.PackageEntry;
exports.Service = model_1.Service;
exports.WebApp = model_1.WebApp;
exports.Workspace = model_1.Workspace;
exports.Runtime = model_1.Runtime;
__export(require("./api"));
__export(require("./plugins"));
__export(require("./utilities"));
__export(require("./errors"));

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

import { ProjectTasks, WorkspaceTasks } from '@sewing-kit/tasks';
import { Project, WebApp, Package, Service, Workspace } from '@sewing-kit/model';
import { ProjectTasks, WorkspaceTasks, DevProjectTask, DevWorkspaceTask, TestProjectTask, TestWorkspaceTask, BuildProjectTask, BuildWorkspaceTask, LintWorkspaceTask, TypeCheckWorkspaceTask } from '@sewing-kit/tasks';
import { PluginApi } from './api';

@@ -14,28 +15,39 @@ export declare const PLUGIN_MARKER: unique symbol;

export interface PluginComposer<Plugin extends BasePlugin> {
use(...plugins: Plugin[]): void;
use(...plugins: (Plugin | false | undefined | null)[]): void;
}
export interface ProjectPlugin extends BasePlugin {
export interface ProjectPluginContext<Type extends Project> {
readonly api: PluginApi;
readonly tasks: ProjectTasks<Type>;
readonly project: Type;
readonly workspace: Workspace;
}
export interface ProjectPlugin<Type extends Project = Project> extends BasePlugin {
readonly target: PluginTarget.Project;
run?(tasks: ProjectTasks, api: PluginApi): any;
compose?(composer: PluginComposer<ProjectPlugin>): any;
run?(context: ProjectPluginContext<Type>): any;
compose?(composer: PluginComposer<ProjectPlugin<Type>>): any;
}
export interface WorkspacePluginContext {
readonly api: PluginApi;
readonly tasks: WorkspaceTasks;
readonly workspace: Workspace;
}
export interface WorkspacePlugin extends BasePlugin {
readonly target: PluginTarget.Workspace;
run?(tasks: WorkspaceTasks, api: PluginApi): any;
run?(context: WorkspacePluginContext): any;
compose?(composer: PluginComposer<WorkspacePlugin>): any;
}
export declare type AnyPlugin = ProjectPlugin | WorkspacePlugin;
export declare function createProjectPlugin(plugin: Omit<ProjectPlugin, typeof PLUGIN_MARKER | 'target'>): ProjectPlugin;
export declare function createComposedProjectPlugin(id: BasePlugin['id'], pluginsOrCompose: readonly (ProjectPlugin | false | null | undefined)[] | NonNullable<ProjectPlugin['compose']>): ProjectPlugin;
export declare function createWorkspacePlugin(plugin: Omit<WorkspacePlugin, typeof PLUGIN_MARKER | 'target'>): WorkspacePlugin;
export declare function createComposedWorkspacePlugin(id: BasePlugin['id'], plugins: readonly WorkspacePlugin[]): WorkspacePlugin;
export declare const createProjectBuildPlugin: (id: string, run: (task: import("@sewing-kit/tasks").BuildProjectTask, api: PluginApi) => void | Promise<void>) => ProjectPlugin;
export declare const createProjectDevPlugin: (id: string, run: (task: import("@sewing-kit/tasks").DevProjectTask, api: PluginApi) => void | Promise<void>) => ProjectPlugin;
export declare const createProjectTestPlugin: (id: string, run: (task: import("@sewing-kit/tasks").TestProjectTask, api: PluginApi) => void | Promise<void>) => ProjectPlugin;
export declare const createWorkspaceBuildPlugin: (id: string, run: (task: import("@sewing-kit/tasks").BuildWorkspaceTask, api: PluginApi) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceDevPlugin: (id: string, run: (task: import("@sewing-kit/tasks").DevWorkspaceTask, api: PluginApi) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceLintPlugin: (id: string, run: (task: import("@sewing-kit/tasks").LintWorkspaceTask, api: PluginApi) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceTypeCheckPlugin: (id: string, run: (task: import("@sewing-kit/tasks").TypeCheckWorkspaceTask, api: PluginApi) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceTestPlugin: (id: string, run: (task: import("@sewing-kit/tasks").TestWorkspaceTask, api: PluginApi) => void | Promise<void>) => WorkspacePlugin;
export declare type AnyPlugin = ProjectPlugin<Project> | WorkspacePlugin;
export declare function createProjectPlugin<Type extends Project = WebApp | Service | Package>(id: BasePlugin['id'], run: NonNullable<ProjectPlugin<Type>['run']>): ProjectPlugin<Type>;
export declare const createProjectBuildPlugin: <Type extends Project = Project>(id: string, run: (context: Pick<ProjectPluginContext<Type>, "api" | "project" | "workspace"> & BuildProjectTask<Type>) => void | Promise<void>) => ProjectPlugin<Type>;
export declare const createProjectDevPlugin: <Type extends Project = Project>(id: string, run: (context: Pick<ProjectPluginContext<Type>, "api" | "project" | "workspace"> & DevProjectTask<Type>) => void | Promise<void>) => ProjectPlugin<Type>;
export declare const createProjectTestPlugin: <Type extends Project = Project>(id: string, run: (context: Pick<ProjectPluginContext<Type>, "api" | "project" | "workspace"> & TestProjectTask<Type>) => void | Promise<void>) => ProjectPlugin<Type>;
export declare function createComposedProjectPlugin<Type extends Project = WebApp | Service | Package>(id: BasePlugin['id'], pluginsOrCompose: readonly (ProjectPlugin<Type> | false | null | undefined)[] | NonNullable<ProjectPlugin<Type>['compose']>): ProjectPlugin<Type>;
export declare function createWorkspacePlugin(id: BasePlugin['id'], run: NonNullable<WorkspacePlugin['run']>): WorkspacePlugin;
export declare const createWorkspaceBuildPlugin: (id: string, run: (context: Pick<WorkspacePluginContext, "api" | "workspace"> & BuildWorkspaceTask) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceDevPlugin: (id: string, run: (context: Pick<WorkspacePluginContext, "api" | "workspace"> & DevWorkspaceTask) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceTestPlugin: (id: string, run: (context: Pick<WorkspacePluginContext, "api" | "workspace"> & TestWorkspaceTask) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceTypeCheckPlugin: (id: string, run: (context: Pick<WorkspacePluginContext, "api" | "workspace"> & TypeCheckWorkspaceTask) => void | Promise<void>) => WorkspacePlugin;
export declare const createWorkspaceLintPlugin: (id: string, run: (context: Pick<WorkspacePluginContext, "api" | "workspace"> & LintWorkspaceTask) => void | Promise<void>) => WorkspacePlugin;
export declare function createComposedWorkspacePlugin(id: BasePlugin['id'], pluginsOrCompose: readonly (WorkspacePlugin | false | null | undefined)[] | NonNullable<WorkspacePlugin['compose']>): WorkspacePlugin;
export {};
//# sourceMappingURL=plugins.d.ts.map
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,6 +20,18 @@ exports.PLUGIN_MARKER = Symbol('SewingKit.Plugin');

})(PluginTarget = exports.PluginTarget || (exports.PluginTarget = {}));
function createProjectPlugin(plugin) {
return Object.assign(Object.assign({}, plugin), { target: PluginTarget.Project, [exports.PLUGIN_MARKER]: true });
function createProjectPlugin(id, run) {
return { id, run, target: PluginTarget.Project, [exports.PLUGIN_MARKER]: true };
}
exports.createProjectPlugin = createProjectPlugin;
exports.createProjectBuildPlugin = (id, run) => createProjectPlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.build.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
exports.createProjectDevPlugin = (id, run) => createProjectPlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.dev.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
exports.createProjectTestPlugin = (id, run) => createProjectPlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.test.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
function createComposedProjectPlugin(id, pluginsOrCompose) {

@@ -23,42 +46,40 @@ const compose = typeof pluginsOrCompose === 'function'

};
return createProjectPlugin({
id,
compose,
});
return { id, compose, target: PluginTarget.Project, [exports.PLUGIN_MARKER]: true };
}
exports.createComposedProjectPlugin = createComposedProjectPlugin;
function createWorkspacePlugin(plugin) {
return Object.assign(Object.assign({}, plugin), { target: PluginTarget.Workspace, [exports.PLUGIN_MARKER]: true });
function createWorkspacePlugin(id, run) {
return { id, run, target: PluginTarget.Workspace, [exports.PLUGIN_MARKER]: true };
}
exports.createWorkspacePlugin = createWorkspacePlugin;
function createComposedWorkspacePlugin(id, plugins) {
return createWorkspacePlugin({
id,
compose(composer) {
for (const plugin of plugins) {
composer.use(plugin);
exports.createWorkspaceBuildPlugin = (id, run) => createWorkspacePlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.build.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
exports.createWorkspaceDevPlugin = (id, run) => createWorkspacePlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.dev.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
exports.createWorkspaceTestPlugin = (id, run) => createWorkspacePlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.test.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
exports.createWorkspaceTypeCheckPlugin = (id, run) => createWorkspacePlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.typeCheck.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
exports.createWorkspaceLintPlugin = (id, run) => createWorkspacePlugin(id, (_a) => {
var { tasks } = _a, context = __rest(_a, ["tasks"]);
tasks.lint.hook((task) => run(Object.assign(Object.assign({}, context), task)));
});
function createComposedWorkspacePlugin(id, pluginsOrCompose) {
const compose = typeof pluginsOrCompose === 'function'
? pluginsOrCompose
: (composer) => {
for (const plugin of pluginsOrCompose) {
if (plugin)
composer.use(plugin);
}
},
});
};
return { id, compose, target: PluginTarget.Workspace, [exports.PLUGIN_MARKER]: true };
}
exports.createComposedWorkspacePlugin = createComposedWorkspacePlugin;
const createProjectTaskPluginCreator = (task) => (id, run) => createProjectPlugin({
id,
run(tasks, api) {
tasks[task].tapPromise(id, (task) => Promise.resolve(run(task, api)));
},
});
exports.createProjectBuildPlugin = createProjectTaskPluginCreator('build');
exports.createProjectDevPlugin = createProjectTaskPluginCreator('dev');
exports.createProjectTestPlugin = createProjectTaskPluginCreator('test');
const createWorkspaceTaskPluginCreator = (task) => (id, run) => createWorkspacePlugin({
id,
run(tasks, api) {
tasks[task].tapPromise(id, (task) => Promise.resolve(run(task, api)));
},
});
exports.createWorkspaceBuildPlugin = createWorkspaceTaskPluginCreator('build');
exports.createWorkspaceDevPlugin = createWorkspaceTaskPluginCreator('dev');
exports.createWorkspaceLintPlugin = createWorkspaceTaskPluginCreator('lint');
exports.createWorkspaceTypeCheckPlugin = createWorkspaceTaskPluginCreator('typeCheck');
exports.createWorkspaceTestPlugin = createWorkspaceTaskPluginCreator('test');

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

declare type OptionalKeys<T> = {
[K in keyof T]-?: undefined extends T[K] ? K : never;
}[keyof T];
declare type HookAdder<T> = () => {
[K in OptionalKeys<T>]?: T[K];
};
export declare function addHooks<T>(adder: HookAdder<T>): (hooks: T) => void;
export declare function toArgs(flags: object, { dasherize }?: {
dasherize?: boolean | undefined;
}): string[];
export declare function lazy<Args extends any[], ReturnType>(asyncImport: () => Promise<(...args: Args) => ReturnType>): (...args: Args) => Promise<ReturnType>;
export {};
//# sourceMappingURL=utilities.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const change_case_1 = require("change-case");
function addHooks(adder) {
return (hooks) => {
Object.assign(hooks, adder());
};
}
exports.addHooks = addHooks;
function toArgs(flags, { dasherize = false } = {}) {

@@ -32,7 +26,1 @@ return Object.entries(flags).reduce((all, [key, value]) => {

exports.toArgs = toArgs;
function lazy(asyncImport) {
return async (...args) => {
return (await asyncImport())(...args);
};
}
exports.lazy = lazy;
{
"name": "@sewing-kit/plugins",
"license": "MIT",
"version": "0.0.11",
"version": "0.0.12",
"sideEffects": false,

@@ -11,8 +11,9 @@ "publishConfig": {

"dependencies": {
"@sewing-kit/tasks": "^0.0.9",
"@sewing-kit/ui": "^0.0.16",
"@sewing-kit/model": "^0.0.8",
"@sewing-kit/tasks": "^0.0.10",
"@sewing-kit/ui": "^0.0.17",
"change-case": "^4.1.0",
"tapable": "^1.1.3"
},
"gitHead": "e26abf556b9e0ddcb48ac6a0b8f37e7403a118a3"
"gitHead": "caf250b7f097fcc53d984457f33d447460566dfb"
}

@@ -6,3 +6,3 @@ import {createPackage, Runtime} from '@sewing-kit/config';

pkg.runtime(Runtime.Node);
pkg.plugin(createSewingKitPackagePlugin());
pkg.use(createSewingKitPackagePlugin());
});

@@ -0,1 +1,3 @@

type Step = import('@sewing-kit/ui').Step;
export interface PluginApi {

@@ -8,2 +10,35 @@ read(path: string): Promise<string>;

tmpPath(...parts: string[]): string;
createStep: typeof createStep;
}
type Skipper = ((skipped: readonly string[]) => boolean) | RegExp;
const defaultSkip = () => false;
export function createStep(run: Step['run']): Step;
export function createStep(
options: Omit<Step, 'run' | 'skip'> & {skip?: Skipper},
run: Step['run'],
): Step;
export function createStep(
runOrStep: Step['run'] | (Omit<Step, 'run' | 'skip'> & {skip?: Skipper}),
run?: Step['run'],
): Step {
return typeof runOrStep === 'function'
? {run: runOrStep, skip: defaultSkip}
: {run: run!, ...normalizeOptions(runOrStep!)};
}
function normalizeOptions({
skip,
...rest
}: Omit<Step, 'run' | 'skip'> & {skip?: Skipper}): Omit<Step, 'run'> {
return {...rest, skip: skip ? normalizeSkip(skip) : defaultSkip};
}
function normalizeSkip(skipper: Skipper) {
return typeof skipper === 'function'
? skipper
: (skipped: readonly string[]) =>
skipped.some((skip) => skipper.test(skip));
}

@@ -0,1 +1,15 @@

export {DiagnosticError} from '@sewing-kit/ui';
export {Task, Env, WorkspaceTasks, ProjectTasks} from '@sewing-kit/tasks';
export {SeriesHook, WaterfallHook} from '@sewing-kit/hooks';
export {
Project,
Package,
PackageBinary,
PackageEntry,
Service,
WebApp,
Workspace,
Runtime,
} from '@sewing-kit/model';
export * from './api';

@@ -2,0 +16,0 @@ export * from './plugins';

@@ -1,3 +0,14 @@

import {AsyncSeriesHook} from 'tapable';
import {ProjectTasks, WorkspaceTasks} from '@sewing-kit/tasks';
import {Project, WebApp, Package, Service, Workspace} from '@sewing-kit/model';
import {
ProjectTasks,
WorkspaceTasks,
DevProjectTask,
DevWorkspaceTask,
TestProjectTask,
TestWorkspaceTask,
BuildProjectTask,
BuildWorkspaceTask,
LintWorkspaceTask,
TypeCheckWorkspaceTask,
} from '@sewing-kit/tasks';

@@ -20,32 +31,87 @@ import {PluginApi} from './api';

export interface PluginComposer<Plugin extends BasePlugin> {
use(...plugins: Plugin[]): void;
use(...plugins: (Plugin | false | undefined | null)[]): void;
}
export interface ProjectPlugin extends BasePlugin {
export interface ProjectPluginContext<Type extends Project> {
readonly api: PluginApi;
readonly tasks: ProjectTasks<Type>;
readonly project: Type;
readonly workspace: Workspace;
}
export interface ProjectPlugin<Type extends Project = Project>
extends BasePlugin {
readonly target: PluginTarget.Project;
run?(tasks: ProjectTasks, api: PluginApi): any;
compose?(composer: PluginComposer<ProjectPlugin>): any;
run?(context: ProjectPluginContext<Type>): any;
compose?(composer: PluginComposer<ProjectPlugin<Type>>): any;
}
export interface WorkspacePluginContext {
readonly api: PluginApi;
readonly tasks: WorkspaceTasks;
readonly workspace: Workspace;
}
export interface WorkspacePlugin extends BasePlugin {
readonly target: PluginTarget.Workspace;
run?(tasks: WorkspaceTasks, api: PluginApi): any;
run?(context: WorkspacePluginContext): any;
compose?(composer: PluginComposer<WorkspacePlugin>): any;
}
export type AnyPlugin = ProjectPlugin | WorkspacePlugin;
export type AnyPlugin = ProjectPlugin<Project> | WorkspacePlugin;
export function createProjectPlugin(
plugin: Omit<ProjectPlugin, typeof PLUGIN_MARKER | 'target'>,
): ProjectPlugin {
return {...plugin, target: PluginTarget.Project, [PLUGIN_MARKER]: true};
export function createProjectPlugin<
Type extends Project = WebApp | Service | Package
>(
id: BasePlugin['id'],
run: NonNullable<ProjectPlugin<Type>['run']>,
): ProjectPlugin<Type> {
return {id, run, target: PluginTarget.Project, [PLUGIN_MARKER]: true};
}
export function createComposedProjectPlugin(
export const createProjectBuildPlugin = <
Type extends Project = WebApp | Service | Package
>(
id: BasePlugin['id'],
run: (
context: Omit<ProjectPluginContext<Type>, 'tasks'> & BuildProjectTask<Type>,
) => void | Promise<void>,
) =>
createProjectPlugin<Type>(id, ({tasks, ...context}) => {
tasks.build.hook((task) => run({...context, ...task}));
});
export const createProjectDevPlugin = <
Type extends Project = WebApp | Service | Package
>(
id: BasePlugin['id'],
run: (
context: Omit<ProjectPluginContext<Type>, 'tasks'> & DevProjectTask<Type>,
) => void | Promise<void>,
) =>
createProjectPlugin<Type>(id, ({tasks, ...context}) => {
tasks.dev.hook((task) => run({...context, ...task}));
});
export const createProjectTestPlugin = <
Type extends Project = WebApp | Service | Package
>(
id: BasePlugin['id'],
run: (
context: Omit<ProjectPluginContext<Type>, 'tasks'> & TestProjectTask<Type>,
) => void | Promise<void>,
) =>
createProjectPlugin<Type>(id, ({tasks, ...context}) => {
tasks.test.hook((task) => run({...context, ...task}));
});
export function createComposedProjectPlugin<
Type extends Project = WebApp | Service | Package
>(
id: BasePlugin['id'],
pluginsOrCompose:
| readonly (ProjectPlugin | false | null | undefined)[]
| NonNullable<ProjectPlugin['compose']>,
) {
const compose: NonNullable<ProjectPlugin['compose']> =
| readonly (ProjectPlugin<Type> | false | null | undefined)[]
| NonNullable<ProjectPlugin<Type>['compose']>,
): ProjectPlugin<Type> {
const compose: NonNullable<ProjectPlugin<Type>['compose']> =
typeof pluginsOrCompose === 'function'

@@ -59,78 +125,78 @@ ? pluginsOrCompose

return createProjectPlugin({
id,
compose,
});
return {id, compose, target: PluginTarget.Project, [PLUGIN_MARKER]: true};
}
export function createWorkspacePlugin(
plugin: Omit<WorkspacePlugin, typeof PLUGIN_MARKER | 'target'>,
id: BasePlugin['id'],
run: NonNullable<WorkspacePlugin['run']>,
): WorkspacePlugin {
return {...plugin, target: PluginTarget.Workspace, [PLUGIN_MARKER]: true};
return {id, run, target: PluginTarget.Workspace, [PLUGIN_MARKER]: true};
}
export function createComposedWorkspacePlugin(
export const createWorkspaceBuildPlugin = (
id: BasePlugin['id'],
plugins: readonly WorkspacePlugin[],
) {
return createWorkspacePlugin({
id,
compose(composer) {
for (const plugin of plugins) {
composer.use(plugin);
}
},
run: (
context: Omit<WorkspacePluginContext, 'tasks'> & BuildWorkspaceTask,
) => void | Promise<void>,
) =>
createWorkspacePlugin(id, ({tasks, ...context}) => {
tasks.build.hook((task) => run({...context, ...task}));
});
}
type IndividualTaskRunner<
Tasks extends WorkspaceTasks | ProjectTasks,
Task extends keyof Tasks
> = Tasks[Task] extends AsyncSeriesHook<infer Context>
? (task: Context, api: PluginApi) => void | Promise<void>
: never;
export const createWorkspaceDevPlugin = (
id: BasePlugin['id'],
run: (
context: Omit<WorkspacePluginContext, 'tasks'> & DevWorkspaceTask,
) => void | Promise<void>,
) =>
createWorkspacePlugin(id, ({tasks, ...context}) => {
tasks.dev.hook((task) => run({...context, ...task}));
});
const createProjectTaskPluginCreator = <Task extends keyof ProjectTasks>(
task: Task,
) => (id: ProjectPlugin['id'], run: IndividualTaskRunner<ProjectTasks, Task>) =>
createProjectPlugin({
id,
run(tasks, api) {
tasks[task].tapPromise(id, (task: any) =>
Promise.resolve(run(task, api)),
);
},
export const createWorkspaceTestPlugin = (
id: BasePlugin['id'],
run: (
context: Omit<WorkspacePluginContext, 'tasks'> & TestWorkspaceTask,
) => void | Promise<void>,
) =>
createWorkspacePlugin(id, ({tasks, ...context}) => {
tasks.test.hook((task) => run({...context, ...task}));
});
export const createProjectBuildPlugin = createProjectTaskPluginCreator('build');
export const createProjectDevPlugin = createProjectTaskPluginCreator('dev');
export const createProjectTestPlugin = createProjectTaskPluginCreator('test');
export const createWorkspaceTypeCheckPlugin = (
id: BasePlugin['id'],
run: (
context: Omit<WorkspacePluginContext, 'tasks'> & TypeCheckWorkspaceTask,
) => void | Promise<void>,
) =>
createWorkspacePlugin(id, ({tasks, ...context}) => {
tasks.typeCheck.hook((task) => run({...context, ...task}));
});
const createWorkspaceTaskPluginCreator = <Task extends keyof WorkspaceTasks>(
task: Task,
) => (
id: WorkspacePlugin['id'],
run: IndividualTaskRunner<WorkspaceTasks, Task>,
export const createWorkspaceLintPlugin = (
id: BasePlugin['id'],
run: (
context: Omit<WorkspacePluginContext, 'tasks'> & LintWorkspaceTask,
) => void | Promise<void>,
) =>
createWorkspacePlugin({
id,
run(tasks, api) {
tasks[task].tapPromise(id, (task: any) =>
Promise.resolve(run(task, api)),
);
},
createWorkspacePlugin(id, ({tasks, ...context}) => {
tasks.lint.hook((task) => run({...context, ...task}));
});
export const createWorkspaceBuildPlugin = createWorkspaceTaskPluginCreator(
'build',
);
export const createWorkspaceDevPlugin = createWorkspaceTaskPluginCreator('dev');
export const createWorkspaceLintPlugin = createWorkspaceTaskPluginCreator(
'lint',
);
export const createWorkspaceTypeCheckPlugin = createWorkspaceTaskPluginCreator(
'typeCheck',
);
export const createWorkspaceTestPlugin = createWorkspaceTaskPluginCreator(
'test',
);
export function createComposedWorkspacePlugin(
id: BasePlugin['id'],
pluginsOrCompose:
| readonly (WorkspacePlugin | false | null | undefined)[]
| NonNullable<WorkspacePlugin['compose']>,
): WorkspacePlugin {
const compose: NonNullable<WorkspacePlugin['compose']> =
typeof pluginsOrCompose === 'function'
? pluginsOrCompose
: (composer) => {
for (const plugin of pluginsOrCompose) {
if (plugin) composer.use(plugin);
}
};
return {id, compose, target: PluginTarget.Workspace, [PLUGIN_MARKER]: true};
}
import {paramCase} from 'change-case';
type OptionalKeys<T> = {
[K in keyof T]-?: undefined extends T[K] ? K : never;
}[keyof T];
type HookAdder<T> = () => {[K in OptionalKeys<T>]?: T[K]};
export function addHooks<T>(adder: HookAdder<T>): (hooks: T) => void {
return (hooks) => {
Object.assign(hooks, adder());
};
}
export function toArgs(flags: object, {dasherize = false} = {}) {

@@ -38,9 +26,1 @@ return Object.entries(flags).reduce<string[]>((all, [key, value]) => {

}
export function lazy<Args extends any[], ReturnType>(
asyncImport: () => Promise<(...args: Args) => ReturnType>,
) {
return async (...args: Args) => {
return (await asyncImport())(...args);
};
}

@@ -9,3 +9,3 @@ {

"include": ["src/**/*.ts"],
"references": [{"path": "../ui"}, {"path": "../tasks"}]
"references": [{"path": "../ui"}, {"path": "../tasks"}, {"path": "../model"}]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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