@qiwi/semrel-plugin-creator
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -0,1 +1,8 @@ | ||
# @qiwi/semrel-plugin-creator [1.1.0](https://github.com/qiwi/semantic-release-toolkit/compare/@qiwi/semrel-plugin-creator@1.0.2...@qiwi/semrel-plugin-creator@1.1.0) (2020-12-29) | ||
### Features | ||
* **plugin-creator:** add required steps checker ([c78b6f2](https://github.com/qiwi/semantic-release-toolkit/commit/c78b6f2dfc6d85a1af4478c9b99abdc9af5b7c09)), closes [#15](https://github.com/qiwi/semantic-release-toolkit/issues/15) | ||
## @qiwi/semrel-plugin-creator [1.0.2](https://github.com/qiwi/semantic-release-toolkit/compare/@qiwi/semrel-plugin-creator@1.0.1...@qiwi/semrel-plugin-creator@1.0.2) (2020-12-29) | ||
@@ -2,0 +9,0 @@ |
@@ -31,2 +31,3 @@ /** | ||
exclude: empty[], | ||
require: empty[], | ||
handler: () => Promise<void>, | ||
@@ -77,2 +78,3 @@ name: string, | ||
exclude: TReleaseStep[], | ||
require: TReleaseStep[], | ||
... | ||
@@ -87,2 +89,6 @@ }; | ||
) => TPlugin; | ||
declare export type TPluginMetaContext = { | ||
invoked: TReleaseStep[], | ||
... | ||
}; | ||
} | ||
@@ -114,2 +120,3 @@ | ||
exclude: empty[], | ||
require: empty[], | ||
handler: () => Promise<void>, | ||
@@ -160,2 +167,3 @@ name: string, | ||
exclude: TReleaseStep[], | ||
require: TReleaseStep[], | ||
... | ||
@@ -170,2 +178,6 @@ }; | ||
) => TPlugin; | ||
declare export type TPluginMetaContext = { | ||
invoked: TReleaseStep[], | ||
... | ||
}; | ||
} | ||
@@ -172,0 +184,0 @@ |
{ | ||
"name": "@qiwi/semrel-plugin-creator", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -7,2 +7,3 @@ import { TPluginFactory, TPluginFactoryOptions, TPluginFactoryOptionsNormalized, TReleaseHandler, TReleaseStep } from './interface'; | ||
exclude: never[]; | ||
require: never[]; | ||
handler: () => Promise<void>; | ||
@@ -9,0 +10,0 @@ name: string; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;var tslib_1=require("tslib"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],handler:function(){return tslib_1.__awaiter(void 0,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2]}))}))},name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};var normalizeOptions=function(e){var r="function"==typeof e?{handler:e}:e;return tslib_1.__assign(tslib_1.__assign({},exports.defaultOptions),r)};exports.normalizeOptions=normalizeOptions;var createPlugin=function(e){var r=exports.normalizeOptions(e),t=r.handler,n=r.include,i=r.exclude;return exports.releaseSteps.filter((function(e){return n.includes(e)&&!i.includes(e)})).reduce((function(e,r){return e[r]=function(e,n){return t({pluginConfig:e,context:n,step:r})},e}),{})};exports.createPlugin=createPlugin; | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;var tslib_1=require("tslib"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],require:[],handler:function(){return tslib_1.__awaiter(void 0,void 0,void 0,(function(){return tslib_1.__generator(this,(function(e){return[2]}))}))},name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};var normalizeOptions=function(e){var r="function"==typeof e?{handler:e}:e;return tslib_1.__assign(tslib_1.__assign({},exports.defaultOptions),r)};exports.normalizeOptions=normalizeOptions;var checkPrevSteps=function(e,r,n){var t=e.invoked,i=r.name,o=r.require;if(0!==o.length){var s=exports.releaseSteps.slice(0,exports.releaseSteps.indexOf(n)).find((function(e){return o.includes(e)&&!t.includes(e)}));if(s)throw new Error("plugin '"+i+"' requires "+s+" to be invoked before "+n)}},createPlugin=function(e){var r=exports.normalizeOptions(e),n=r.handler,t=r.include,i=r.exclude,o={invoked:[]};return exports.releaseSteps.filter((function(e){return t.includes(e)&&!i.includes(e)})).reduce((function(e,t){return e[t]=function(e,i){return checkPrevSteps(o,r,t),o.invoked.push(t),n({pluginConfig:e,context:i,step:t})},e}),{})};exports.createPlugin=createPlugin; |
@@ -28,5 +28,9 @@ import { Context } from 'semantic-release'; | ||
exclude: TReleaseStep[]; | ||
require: TReleaseStep[]; | ||
}; | ||
export declare type TPluginFactoryOptions = Partial<TPluginFactoryOptionsNormalized>; | ||
export declare type TPluginFactory = (handler: TPluginFactoryOptions | TReleaseHandler) => TPlugin; | ||
export declare type TPluginMetaContext = { | ||
invoked: TReleaseStep[]; | ||
}; | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -7,2 +7,3 @@ import { TPluginFactory, TPluginFactoryOptions, TPluginFactoryOptionsNormalized, TReleaseHandler, TReleaseStep } from './interface'; | ||
exclude: never[]; | ||
require: never[]; | ||
handler: () => Promise<void>; | ||
@@ -9,0 +10,0 @@ name: string; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;const tslib_1=require("tslib"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],handler:()=>tslib_1.__awaiter(void 0,void 0,void 0,(function*(){})),name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};const normalizeOptions=e=>{const t="function"==typeof e?{handler:e}:e;return Object.assign(Object.assign({},exports.defaultOptions),t)};exports.normalizeOptions=normalizeOptions;const createPlugin=e=>{const{handler:t,include:i,exclude:o}=exports.normalizeOptions(e);return exports.releaseSteps.filter((e=>i.includes(e)&&!o.includes(e))).reduce(((e,i)=>(e[i]=(e,o)=>t({pluginConfig:e,context:o,step:i}),e)),{})};exports.createPlugin=createPlugin; | ||
"use strict";var _a,_b,_c;Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPlugin=exports.normalizeOptions=exports.defaultOptions=exports.releaseSteps=void 0;const tslib_1=require("tslib"),read_pkg_up_1=require("read-pkg-up");tslib_1.__exportStar(require("./interface"),exports),exports.releaseSteps=["verifyConditions","analyzeCommits","verifyRelease","generateNotes","prepare","publish","success","fail"],exports.defaultOptions={include:exports.releaseSteps,exclude:[],require:[],handler:()=>tslib_1.__awaiter(void 0,void 0,void 0,(function*(){})),name:String(null===(_c=null===(_b=read_pkg_up_1.sync({cwd:null===(_a=null===module||void 0===module?void 0:module.parent)||void 0===_a?void 0:_a.filename}))||void 0===_b?void 0:_b.packageJson)||void 0===_c?void 0:_c.name)};const normalizeOptions=e=>{const r="function"==typeof e?{handler:e}:e;return Object.assign(Object.assign({},exports.defaultOptions),r)};exports.normalizeOptions=normalizeOptions;const checkPrevSteps=({invoked:e},{name:r,require:t},i)=>{if(0===t.length)return;const s=exports.releaseSteps.slice(0,exports.releaseSteps.indexOf(i)).find((r=>t.includes(r)&&!e.includes(r)));if(s)throw new Error(`plugin '${r}' requires ${s} to be invoked before ${i}`)},createPlugin=e=>{const r=exports.normalizeOptions(e),{handler:t,include:i,exclude:s}=r,n={invoked:[]};return exports.releaseSteps.filter((e=>i.includes(e)&&!s.includes(e))).reduce(((e,i)=>(e[i]=(e,s)=>(checkPrevSteps(n,r,i),n.invoked.push(i),t({pluginConfig:e,context:s,step:i})),e)),{})};exports.createPlugin=createPlugin; |
@@ -28,5 +28,9 @@ import { Context } from 'semantic-release'; | ||
exclude: TReleaseStep[]; | ||
require: TReleaseStep[]; | ||
}; | ||
export declare type TPluginFactoryOptions = Partial<TPluginFactoryOptionsNormalized>; | ||
export declare type TPluginFactory = (handler: TPluginFactoryOptions | TReleaseHandler) => TPlugin; | ||
export declare type TPluginMetaContext = { | ||
invoked: TReleaseStep[]; | ||
}; | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -9,2 +9,3 @@ import { sync as readPkgUp } from 'read-pkg-up' | ||
TPluginFactoryOptionsNormalized, | ||
TPluginMetaContext, | ||
TReleaseHandler, | ||
@@ -31,6 +32,7 @@ TReleaseStep, | ||
exclude: [], | ||
require: [], | ||
handler: async (): Promise<void> => { | ||
/* async noop */ | ||
}, | ||
name: String(readPkgUp({ cwd: module?.parent?.filename })?.packageJson?.name) | ||
name: String(readPkgUp({ cwd: module?.parent?.filename })?.packageJson?.name), | ||
} | ||
@@ -47,4 +49,29 @@ | ||
const checkPrevSteps = ( | ||
{ invoked }: TPluginMetaContext, | ||
{ name, require }: TPluginFactoryOptionsNormalized, | ||
step: TReleaseStep, | ||
): void => { | ||
if (require.length === 0) { | ||
return | ||
} | ||
const prevSteps = releaseSteps.slice(0, releaseSteps.indexOf(step)) | ||
const missedStep = prevSteps.find( | ||
(step) => require.includes(step) && !invoked.includes(step), | ||
) | ||
if (missedStep) { | ||
throw new Error( | ||
`plugin '${name}' requires ${missedStep} to be invoked before ${step}`, | ||
) | ||
} | ||
} | ||
export const createPlugin: TPluginFactory = (options) => { | ||
const { handler, include, exclude } = normalizeOptions(options) | ||
const normalizedOpions = normalizeOptions(options) | ||
const { handler, include, exclude } = normalizedOpions | ||
const metaContext: TPluginMetaContext = { | ||
invoked: [], | ||
} | ||
@@ -54,7 +81,12 @@ return releaseSteps | ||
.reduce<TPlugin>((m, step) => { | ||
m[step] = (pluginConfig: TPluginConfig, context: TSemrelContext) => | ||
handler({ pluginConfig, context, step }) | ||
m[step] = (pluginConfig: TPluginConfig, context: TSemrelContext) => { | ||
checkPrevSteps(metaContext, normalizedOpions, step) | ||
metaContext.invoked.push(step) | ||
return handler({ pluginConfig, context, step }) | ||
} | ||
return m | ||
}, {}) | ||
} |
@@ -40,2 +40,3 @@ import { Context } from 'semantic-release' | ||
exclude: TReleaseStep[] | ||
require: TReleaseStep[] | ||
} | ||
@@ -48,1 +49,5 @@ | ||
) => TPlugin | ||
export type TPluginMetaContext = { | ||
invoked: TReleaseStep[] | ||
} |
@@ -12,2 +12,3 @@ // Generated by dts-bundle v0.7.4 | ||
exclude: never[]; | ||
require: never[]; | ||
handler: () => Promise<void>; | ||
@@ -48,5 +49,9 @@ name: string; | ||
exclude: TReleaseStep[]; | ||
require: TReleaseStep[]; | ||
}; | ||
export type TPluginFactoryOptions = Partial<TPluginFactoryOptionsNormalized>; | ||
export type TPluginFactory = (handler: TPluginFactoryOptions | TReleaseHandler) => TPlugin; | ||
export type TPluginMetaContext = { | ||
invoked: TReleaseStep[]; | ||
}; | ||
} | ||
@@ -65,2 +70,3 @@ | ||
exclude: never[]; | ||
require: never[]; | ||
handler: () => Promise<void>; | ||
@@ -101,5 +107,9 @@ name: string; | ||
exclude: TReleaseStep[]; | ||
require: TReleaseStep[]; | ||
}; | ||
export type TPluginFactoryOptions = Partial<TPluginFactoryOptionsNormalized>; | ||
export type TPluginFactory = (handler: TPluginFactoryOptions | TReleaseHandler) => TPlugin; | ||
export type TPluginMetaContext = { | ||
invoked: TReleaseStep[]; | ||
}; | ||
} | ||
@@ -106,0 +116,0 @@ |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32631
485
2