@newhighsco/yarn-plugin-preset 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/bundles/@yarnpkg/plugin-preset.js +9 -0
- package/package.json +36 -0
- package/scripts/postinstall.ts +13 -0
- package/src/index.ts +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# yarn-plugin-preset
|
|
2
|
+
|
|
3
|
+
New High Score [shareable plugins](https://yarnpkg.com/advanced/plugin-tutorial) for [Yarn](https://yarnpkg.com/)
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install `@newhighsco/yarn-plugin-preset`:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
yarn plugin import https://github.com/newhighsco/yarn/releases/download/%40newhighsco%2Fyarn-plugin-preset%401.0.0/plugin-preset.js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## [CHANGELOG](CHANGELOG.md)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
//prettier-ignore
|
|
3
|
+
module.exports = {
|
|
4
|
+
name: "@yarnpkg/plugin-preset",
|
|
5
|
+
factory: function (require) {
|
|
6
|
+
var plugin=(()=>{var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var f=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var y=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},m=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of p(e))!l.call(r,n)&&n!==t&&s(r,n,{get:()=>e[n],enumerable:!(o=c(e,n))||o.enumerable});return r};var P=r=>m(s({},"__esModule",{value:!0}),r);var d={};y(d,{default:()=>T});var i=f("@yarnpkg/shell"),g=async(r,e)=>{for(let t of r)if(await e(t))return!0;return!1},u=(r,{topLevelWorkspace:e})=>e.manifest.scripts.has(r)?(0,i.execute)(`yarn ${r}`):Promise.resolve(0),w={hooks:{afterAllInstalled:r=>{u("prepare",r)},wrapScriptExecution:async(r,e,t,o)=>/^p(re|ost)(?!pare).+/.test(o)?r:async()=>await g(["pre",void 0,"post"],async a=>a?await u(`${a}${o}`,e):await r())?1:0}},T=w;return P(d);})();
|
|
7
|
+
return plugin;
|
|
8
|
+
}
|
|
9
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@newhighsco/yarn-plugin-preset",
|
|
3
|
+
"description": "New High Score shareable Yarn plugins",
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"author": "New High Score",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/newhighsco/yarn.git",
|
|
10
|
+
"directory": "packages/yarn-plugin-preset"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/newhighsco/yarn/tree/main/packages/yarn-plugin-preset#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/newhighsco/yarn/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "src/index.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"bundles",
|
|
20
|
+
"scripts"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"postinstall": "tsx scripts/postinstall",
|
|
24
|
+
"prepublishOnly": "yarn build",
|
|
25
|
+
"clean": "rm -rf bundles",
|
|
26
|
+
"build": "builder build plugin && yarn plugin import ./bundles/@yarnpkg/plugin-preset.js --no-checksum"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@yarnpkg/core": "4.5.0",
|
|
30
|
+
"@yarnpkg/shell": "4.1.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@yarnpkg/builder": "4.2.3",
|
|
34
|
+
"tsx": "4.21.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { execute } from '@yarnpkg/shell'
|
|
2
|
+
|
|
3
|
+
import packageJson from '../package.json' with { type: 'json' }
|
|
4
|
+
|
|
5
|
+
const { name, repository, version } = packageJson
|
|
6
|
+
|
|
7
|
+
const tag = encodeURIComponent(`${name}@${version}`)
|
|
8
|
+
const url = new URL(
|
|
9
|
+
`releases/download/${tag}/plugin-preset.js`,
|
|
10
|
+
repository.url.replace(/\.[^/.]+$/, '/')
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
execute(`yarn plugin import ${url.href}`)
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Hooks, Plugin, Project } from '@yarnpkg/core'
|
|
2
|
+
import { execute } from '@yarnpkg/shell'
|
|
3
|
+
|
|
4
|
+
const some = async <TValue, TReturn>(
|
|
5
|
+
array: TValue[],
|
|
6
|
+
predicate: (value: TValue) => Promise<TReturn>
|
|
7
|
+
) => {
|
|
8
|
+
for (const value of array) {
|
|
9
|
+
if (await predicate(value)) return true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const executeScript = (name: string, { topLevelWorkspace }: Project) => {
|
|
16
|
+
if (!topLevelWorkspace.manifest.scripts.has(name)) return Promise.resolve(0)
|
|
17
|
+
|
|
18
|
+
return execute(`yarn ${name}`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const plugin: Plugin<Hooks> = {
|
|
22
|
+
hooks: {
|
|
23
|
+
afterAllInstalled: project => {
|
|
24
|
+
executeScript('prepare', project)
|
|
25
|
+
},
|
|
26
|
+
wrapScriptExecution: async (executor, project, _, scriptName) => {
|
|
27
|
+
if (/^p(re|ost)(?!pare).+/.test(scriptName)) {
|
|
28
|
+
return executor
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return async () => {
|
|
32
|
+
const prefixes = ['pre', undefined, 'post']
|
|
33
|
+
const errors = await some(prefixes, async prefix => {
|
|
34
|
+
if (prefix) {
|
|
35
|
+
return await executeScript(`${prefix}${scriptName}`, project)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return await executor()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return errors ? 1 : 0
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default plugin
|