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

@nowa/core

Package Overview
Dependencies
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nowa/core - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

22

CHANGELOG.md

@@ -6,2 +6,24 @@ # Change Log

<a name="0.4.0"></a>
# [0.4.0](https://github.com/nowa-webpack/nowa2/compare/@nowa/core@0.3.0...@nowa/core@0.4.0) (2018-01-18)
### Bug Fixes
* **types:** type errors ([dcc040f](https://github.com/nowa-webpack/nowa2/commit/dcc040f))
### Features
* **loadModules:** check if module is a nowa module before instantiate it ([7c62b24](https://github.com/nowa-webpack/nowa2/commit/7c62b24))
* **utils:** parser supports providing a string to set alias ([de8032c](https://github.com/nowa-webpack/nowa2/commit/de8032c))
* add utils definition ([5c75cc3](https://github.com/nowa-webpack/nowa2/commit/5c75cc3))
* export IUtils as Runner.Utils ([144d3be](https://github.com/nowa-webpack/nowa2/commit/144d3be))
* pass utils to modules / plugins ([7d3c0ed](https://github.com/nowa-webpack/nowa2/commit/7d3c0ed))
* support prompt option ([04a8b9c](https://github.com/nowa-webpack/nowa2/commit/04a8b9c))
* warn if nowa command is elevated ([d734a42](https://github.com/nowa-webpack/nowa2/commit/d734a42))
<a name="0.3.0"></a>

@@ -8,0 +30,0 @@ # [0.3.0](https://github.com/nowa-webpack/nowa2/compare/@nowa/core@0.2.0...@nowa/core@0.3.0) (2018-01-04)

4

index.d.ts

@@ -5,4 +5,4 @@ import { Module } from './lib/core/module';

import * as utils from './lib/utils';
export declare const createRunner: (plugins: IPlugin<Runner>[]) => Promise<Runner>;
export declare const createDefaultRunner: (plugins: IPlugin<Runner>[]) => Promise<Runner>;
export declare const createRunner: (createUtils: Runner.UtilsCreator, plugins: IPlugin<Runner>[]) => Promise<Runner>;
export declare const createDefaultRunner: (createUtils: Runner.UtilsCreator, plugins: IPlugin<Runner>[]) => Promise<Runner>;
export { Runner, Module, utils };

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

exports.utils = utils;
const initContext_1 = require("./lib/plugins/initContext");
const initError_1 = require("./lib/plugins/initError");

@@ -20,12 +19,11 @@ const loadConfig_1 = require("./lib/plugins/loadConfig");

const runError_1 = require("./lib/plugins/runError");
exports.createRunner = (plugins) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const runner = new runner_1.Runner();
exports.createRunner = (createUtils, plugins) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const runner = new runner_1.Runner(createUtils);
for (const plugin of plugins) {
yield plugin.apply(runner);
yield plugin.apply(runner, createUtils(plugin.name));
}
return runner;
});
exports.createDefaultRunner = (plugins) => tslib_1.__awaiter(this, void 0, void 0, function* () {
exports.createDefaultRunner = (createUtils, plugins) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const allPlugins = [
new initContext_1.InitContextPlugin(),
new initError_1.InitErrorPlugin(),

@@ -41,3 +39,3 @@ new loadConfig_1.LoadConfigPlugin(),

];
return exports.createRunner(allPlugins);
return exports.createRunner(createUtils, allPlugins);
});

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

import { IUtils } from '../types';
import { Hookable } from './hookable';

@@ -7,6 +8,7 @@ import { Runnable } from './runnable';

$runtime: IRuntime<ModuleOptions>;
$utils: IUtils;
init(): Promise<void>;
}
interface IConstructor<ModuleOptions = {}> extends Async {
new ($runtime: IRuntime<ModuleOptions>): this;
new ($runtime: IRuntime<ModuleOptions>, $utils: IUtils): this;
}

@@ -21,4 +23,5 @@ interface IRuntime<ModuleOptions = {}> {

$runtime: IRuntime<ModuleOptions>;
$utils: IUtils;
abstract $name: string;
constructor($runtime: IRuntime<ModuleOptions>);
constructor($runtime: IRuntime<ModuleOptions>, $utils: IUtils);
abstract init(): Promise<void>;

@@ -28,4 +31,5 @@ }

$runtime: IRuntime<ModuleOptions>;
$utils: IUtils;
abstract $name: string;
constructor($runtime: IRuntime<ModuleOptions>);
constructor($runtime: IRuntime<ModuleOptions>, $utils: IUtils);
abstract init(): Promise<void>;

@@ -32,0 +36,0 @@ }

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

class Async extends runnable_1.Runnable.Async {
constructor($runtime) {
constructor($runtime, $utils) {
super();
this.$runtime = $runtime;
this.$utils = $utils;
}

@@ -15,5 +16,6 @@ }

class Callback extends runnable_1.Runnable.Callback {
constructor($runtime) {
constructor($runtime, $utils) {
super();
this.$runtime = $runtime;
this.$utils = $utils;
}

@@ -20,0 +22,0 @@ }

@@ -7,2 +7,3 @@ import { Runner } from '../runner';

private _loadModule(pathOrModuleName, context, prefixes);
private _checkIsNowaModule(module, path);
}

@@ -9,0 +10,0 @@ export declare namespace LoadModulesPlugin {

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

const prefixes = [...(this.options.modulePrefixes || []), ...modulePrefixes];
runner.$register('load-modules', ({ context, commands, options, solution }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
runner.$register('load-modules', ({ context, commands, options, solution, createUtils }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const moduleArray = solution[1];

@@ -23,3 +23,5 @@ const result = [];

const ClassConstructor = this._loadModule(module, context, prefixes);
instance = new ClassConstructor({ context, commands, options, moduleOptions: {} });
if (this._checkIsNowaModule(ClassConstructor, module)) {
instance = new ClassConstructor({ context, commands, options, moduleOptions: {} }, createUtils(ClassConstructor.name));
}
}

@@ -32,5 +34,12 @@ else {

}
instance = new ClassConstructor({ context, commands, options, moduleOptions });
if (this._checkIsNowaModule(ClassConstructor, module[0])) {
instance = new ClassConstructor({ context, commands, options, moduleOptions }, createUtils(ClassConstructor.name));
}
}
result.push(instance);
if (instance) {
result.push(instance);
}
else {
debug(`ignore ${Array.isArray(module) ? module[0] : module} since its instance is falsy`);
}
}

@@ -61,3 +70,13 @@ return result;

}
_checkIsNowaModule(module, path) {
if (module.prototype.$type && module.$hooks && module.$register) {
debug(`${path} is a nowa module`);
return true;
}
else {
debug(`${path} is not a nowa module`);
return false;
}
}
}
exports.LoadModulesPlugin = LoadModulesPlugin;
import { Module } from './core/module';
import { Runnable } from './core/runnable';
import { ModuleQueue } from './moduleQueue';
import { IConfig, IConfigConfigValues, IPlugin, ISolution, ISolutionCommandDescription } from './types';
import { IConfig, IConfigConfigValues, IPlugin, ISolution, ISolutionCommandDescription, IUtils } from './types';
export declare class Runner extends Runnable.Callback<Runner.PluginGroup> {
$createUtils: Runner.UtilsCreator;
runtime: Runner.IRuntime;
constructor($createUtils: Runner.UtilsCreator);
init(): Promise<void>;

@@ -27,3 +29,5 @@ run(): Promise<void>;

}, IRuntime['parsed']['options']];
'load-modules': [Pick<IRuntime, 'context'> & IRuntime['parsed'], IRuntime['modules']];
'load-modules': [Pick<IRuntime, 'context'> & IRuntime['parsed'] & {
createUtils: Runner.UtilsCreator;
}, IRuntime['modules']];
'init-module-queue': [Pick<IRuntime, 'context'> & IRuntime['parsed'] & {

@@ -33,5 +37,5 @@ modules: IRuntime['modules'];

}, void];
'init-end': [undefined, void];
'run-start': [undefined, void];
'run-end': [undefined, void];
'init-end': [Runner, void];
'run-start': [Runner, void];
'run-end': [Runner, void];
'init-error': [{

@@ -44,2 +48,4 @@ error: any;

};
type UtilsCreator = (name?: string) => IUtils;
type Utils = IUtils;
interface IRuntime {

@@ -46,0 +52,0 @@ context: string;

@@ -9,4 +9,5 @@ "use strict";

class Runner extends runnable_1.Runnable.Callback {
constructor() {
super(...arguments);
constructor($createUtils) {
super();
this.$createUtils = $createUtils;
this.runtime = { parsed: {}, raw: {} };

@@ -19,3 +20,3 @@ }

yield this.$applyHook('init-start');
debug('apply load-info');
debug('apply init-context');
this.runtime.context = yield this.$applyHookBail('init-context');

@@ -37,3 +38,3 @@ debug('apply load-config');

for (const plugin of plugins) {
yield plugin.apply(this);
yield plugin.apply(this, this.$createUtils(plugin.name));
}

@@ -62,3 +63,3 @@ debug('apply load-commands');

debug('apply load-modules');
this.runtime.modules = yield this.$applyHookBail('load-modules', Object.assign({ context: this.runtime.context }, this.runtime.parsed));
this.runtime.modules = yield this.$applyHookBail('load-modules', Object.assign({ context: this.runtime.context, createUtils: this.$createUtils }, this.runtime.parsed));
debug(`load ${this.runtime.modules.length} module(s)`);

@@ -71,3 +72,3 @@ debug('create & init moduleQueue');

debug('apply init-end');
yield this.$applyHook('init-end');
yield this.$applyHook('init-end', this);
}

@@ -85,10 +86,10 @@ catch (e) {

debug('apply run-end');
this.$applyHook('run-end').then(() => process.exit(1));
this.$applyHook('run-end', this).then(() => process.exit(1));
});
debug('apply run-start');
yield this.$applyHook('run-start');
yield this.$applyHook('run-start', this);
debug('run modules');
yield this.runtime.moduleQueue.run(() => {
debug('apply run-end');
this.$applyHook('run-end');
this.$applyHook('run-end', this);
});

@@ -95,0 +96,0 @@ });

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

import { Chalk } from 'chalk';
export interface IPlugin<For> {
apply(hookable: For): void | Promise<void>;
name?: string;
apply(hookable: For, utils: IUtils): void | Promise<void>;
}
export interface ILogger {
error: (...args: any[]) => void;
warn: (...args: any[]) => void;
log: (...args: any[]) => void;
info: (...args: any[]) => void;
debug: (...args: any[]) => void;
}
export interface ISpinner {
start: (text: string) => this;
stop: () => this;
succeed: (text?: string) => this;
fail: (text?: string) => this;
warn: (text?: string) => this;
info: (text?: string) => this;
clear: () => this;
promise(promise: Promise<any>, text?: string): this;
}
export interface IUtils {
chalk: Chalk;
logger: ILogger;
prompt: (desc: string, options?: Partial<IPromptOptionDescription>) => Promise<any>;
spinner: ISpinner;
}
export interface IConfig {

@@ -13,3 +38,3 @@ config?: IConfigConfigRegistry;

export interface IConfigConfigRegistry {
[commandName: string]: IConfigConfigValues | IConfigConfigRegistry;
[commandName: string]: string | IConfigConfigValues | IConfigConfigRegistry;
}

@@ -35,6 +60,6 @@ export declare type IConfigConfigValues = [{

export interface ISolutionCommandRegistry {
[commandName: string]: ISolutionCommandDescription | ISolutionCommandRegistry;
[commandName: string]: string | ISolutionCommandDescription | ISolutionCommandRegistry;
}
export interface IBaseOptionDescription {
type: 'string' | 'number' | 'array' | 'boolean' | 'choice';
type: 'string' | 'number' | 'array' | 'boolean' | 'choice' | 'prompt';
description: string;

@@ -46,3 +71,4 @@ default?: boolean | string | number | string[];

}
export declare type IOptionDescription = IChoiceOptionDescription | IStringOptionDescription | INumberOptionDescription | IArrayOptionDescription | IBooleanOptionDescription;
export declare type IOptionDescription = IChoiceOptionDescription | IStringOptionDescription | INumberOptionDescription | IArrayOptionDescription | IBooleanOptionDescription | IPromptOptionDescription;
export declare type IPromptOptionDescription = ITextPromptOptionDescription | IConfirmPromptOptionDescription | IListPromptOptionDescription | ICheckboxPromptOptionDescription;
export interface IChoiceOptionDescription extends IBaseOptionDescription {

@@ -69,1 +95,37 @@ type: 'choice';

}
export interface IBasePromptOptionDescription extends IBaseOptionDescription {
type: 'prompt';
prompt: 'input' | 'confirm' | 'list' | 'password' | 'checkbox';
order: number;
filter?: (input: any) => Promise<any> | any;
validate?: (result: any) => Promise<any> | any;
choices?: any[];
}
export interface ITextPromptOptionDescription extends IBasePromptOptionDescription {
prompt: 'input' | 'password';
default: string;
}
export interface IConfirmPromptOptionDescription extends IBasePromptOptionDescription {
prompt: 'confirm';
default: boolean;
}
export interface IListPromptOptionDescriptionChoices {
name: string;
value?: string;
short?: string;
}
export interface IListPromptOptionDescription extends IBasePromptOptionDescription {
prompt: 'list';
choices: Array<IListPromptOptionDescriptionChoices | string>;
default: string;
}
export interface ICheckboxPromptOptionDescriptionChoices {
name: string;
value?: string;
checked?: boolean;
}
export interface ICheckboxPromptOptionDescription extends IBasePromptOptionDescription {
prompt: 'checkbox';
choices: Array<IListPromptOptionDescriptionChoices | string>;
default: string[];
}

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

const currentPath = currentCommand.join('.');
const next = cursor[currentCommandPart];
let next = cursor[currentCommandPart];
if (typeof next === 'string') {
next = cursor[next];
}
if (Array.isArray(next)) {

@@ -23,3 +26,3 @@ debug(`find ${target} @ ${target}.${currentPath}`);

}
if (next !== undefined) {
else if (next !== undefined) {
cursor = next;

@@ -26,0 +29,0 @@ index += 1;

{
"name": "@nowa/core",
"version": "0.3.0",
"version": "0.4.0",
"description": "the nowa core",

@@ -26,2 +26,3 @@ "scripts": {

"dependencies": {
"chalk": "^2.3.0",
"debug": "^3.1.0",

@@ -35,6 +36,9 @@ "fs-extra": "^5.0.0",

},
"types": "./",
"publishConfig": {
"access": "public"
},
"types": "./"
"engines": {
"node": ">=6.5"
}
}
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