@yarn-tool/pkg-entry-util 1.0.1
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/CHANGELOG.md +11 -0
- package/README.md +12 -0
- package/lib/field/exports.d.ts +8 -0
- package/lib/field/exports.js +59 -0
- package/lib/field/exports.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/package.json +64 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 1.0.1 (2021-12-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 📦 Code Refactoring
|
|
10
|
+
|
|
11
|
+
* `@yarn-tool/pkg-entry-util` ([b450ad0](https://github.com/bluelovers/ws-yarn-workspaces/commit/b450ad0e274785b6d4d76e8b1bc47a1eeb65fc37))
|
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IPackageJson } from '@ts-type/package-dts/package-json';
|
|
2
|
+
import { PackageExportsEntry, PackageExportsFallback } from '@ts-type/package-dts/types/package.json';
|
|
3
|
+
export declare function _pkgExportsAddPJsonEntryCore<T extends IPackageJson["exports"]>(pkgExports: T): T;
|
|
4
|
+
export declare function pkgExportsAddPJsonEntry<T extends IPackageJson>(pkg: T): T;
|
|
5
|
+
export declare function _isPackageExportsEntry(entry: string | keyof keyof IPackageJson["exports"], value: PackageExportsEntry | PackageExportsFallback): value is PackageExportsEntry;
|
|
6
|
+
export declare function pkgExportsVerify<T extends IPackageJson>(pkg: T, options?: {
|
|
7
|
+
cwd?: string;
|
|
8
|
+
}): null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pkgExportsVerify = exports._isPackageExportsEntry = exports.pkgExportsAddPJsonEntry = exports._pkgExportsAddPJsonEntryCore = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_extra_1 = require("fs-extra");
|
|
6
|
+
const find_root_1 = require("@yarn-tool/find-root");
|
|
7
|
+
function _pkgExportsAddPJsonEntryCore(pkgExports) {
|
|
8
|
+
var _a;
|
|
9
|
+
if (typeof pkgExports === 'object') {
|
|
10
|
+
(_a = pkgExports['./package.json']) !== null && _a !== void 0 ? _a : (pkgExports['./package.json'] = './package.json');
|
|
11
|
+
}
|
|
12
|
+
return pkgExports;
|
|
13
|
+
}
|
|
14
|
+
exports._pkgExportsAddPJsonEntryCore = _pkgExportsAddPJsonEntryCore;
|
|
15
|
+
function pkgExportsAddPJsonEntry(pkg) {
|
|
16
|
+
_pkgExportsAddPJsonEntryCore(pkg.exports);
|
|
17
|
+
return pkg;
|
|
18
|
+
}
|
|
19
|
+
exports.pkgExportsAddPJsonEntry = pkgExportsAddPJsonEntry;
|
|
20
|
+
function _isPackageExportsEntry(entry, value) {
|
|
21
|
+
return entry.startsWith('./') && !!(value !== null && value !== void 0 ? value : false);
|
|
22
|
+
}
|
|
23
|
+
exports._isPackageExportsEntry = _isPackageExportsEntry;
|
|
24
|
+
function pkgExportsVerify(pkg, options) {
|
|
25
|
+
if (typeof pkg.exports === 'object') {
|
|
26
|
+
const rootData = (0, find_root_1.findRootLazy)({
|
|
27
|
+
cwd: options === null || options === void 0 ? void 0 : options.cwd,
|
|
28
|
+
});
|
|
29
|
+
if (!rootData.isWorkspace && rootData.pkg) {
|
|
30
|
+
const list = [];
|
|
31
|
+
Object.entries(pkg.exports)
|
|
32
|
+
.forEach(([entry, value]) => {
|
|
33
|
+
if (_isPackageExportsEntry(entry, value)) {
|
|
34
|
+
[typeof value === 'string' ? value : Object.values(value)]
|
|
35
|
+
.flat()
|
|
36
|
+
.forEach(file => {
|
|
37
|
+
const bool = (0, fs_extra_1.pathExistsSync)((0, path_1.resolve)(rootData.pkg, file));
|
|
38
|
+
if (!bool) {
|
|
39
|
+
list.push(`path of '${entry}' does not exist: '${file}'`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (list.length > 0) {
|
|
45
|
+
let err = new Error(`Invalid package exports: ${rootData.pkg}\n${list.slice().map(v => ` - ${v}`).join('\n')}`);
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
err.list = list;
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
err.rootData = rootData;
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
err.pkgExports = pkg.exports;
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
exports.pkgExportsVerify = pkgExportsVerify;
|
|
59
|
+
//# sourceMappingURL=exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["exports.ts"],"names":[],"mappings":";;;AAEA,+BAA+B;AAC/B,uCAA0C;AAC1C,oDAAoD;AAEpD,SAAgB,4BAA4B,CAAoC,UAAa;;IAE5F,IAAI,OAAO,UAAU,KAAK,QAAQ,EAClC;QACC,MAAA,UAAU,CAAC,gBAAgB,qCAA3B,UAAU,CAAC,gBAAgB,IAAM,gBAAgB,EAAC;KAClD;IAED,OAAO,UAAU,CAAA;AAClB,CAAC;AARD,oEAQC;AAED,SAAgB,uBAAuB,CAAyB,GAAM;IAErE,4BAA4B,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,GAAG,CAAA;AACX,CAAC;AALD,0DAKC;AAED,SAAgB,sBAAsB,CAAC,KAAmD,EACzF,KAAmD;IAGnD,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,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,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAEhH,aAAa;gBACb,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;gBAChB,aAAa;gBACb,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBACxB,aAAa;gBACb,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC;gBAE7B,MAAM,GAAG,CAAC;aACV;SACD;KAED;IAED,OAAO,IAAY,CAAA;AACpB,CAAC;AAtDD,4CAsDC","sourcesContent":["import { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { PackageExportsEntry, PackageExportsFallback } from '@ts-type/package-dts/types/package.json';\nimport { resolve } from 'path';\nimport { pathExistsSync } from 'fs-extra';\nimport { findRootLazy } from '@yarn-tool/find-root';\n\nexport function _pkgExportsAddPJsonEntryCore<T extends IPackageJson[\"exports\"]>(pkgExports: T)\n{\n\tif (typeof pkgExports === 'object')\n\t{\n\t\tpkgExports['./package.json'] ??= './package.json';\n\t}\n\n\treturn pkgExports\n}\n\nexport function pkgExportsAddPJsonEntry<T extends IPackageJson>(pkg: T)\n{\n\t_pkgExportsAddPJsonEntryCore(pkg.exports);\n\n\treturn pkg\n}\n\nexport function _isPackageExportsEntry(entry: string | keyof keyof IPackageJson[\"exports\"],\n\tvalue: PackageExportsEntry | PackageExportsFallback,\n): value is PackageExportsEntry\n{\n\treturn entry.startsWith('./') && !!(value ?? false)\n}\n\nexport function pkgExportsVerify<T extends IPackageJson>(pkg: T, options?: {\n\tcwd?: string,\n})\n{\n\tif (typeof pkg.exports === 'object')\n\t{\n\t\tconst rootData = findRootLazy({\n\t\t\tcwd: options?.cwd,\n\t\t});\n\n\t\tif (!rootData.isWorkspace && rootData.pkg)\n\t\t{\n\t\t\tconst list: string[] = [];\n\n\t\t\tObject.entries(pkg.exports)\n\t\t\t\t.forEach(([entry, value]) =>\n\t\t\t\t{\n\t\t\t\t\tif (_isPackageExportsEntry(entry, value))\n\t\t\t\t\t{\n\t\t\t\t\t\t([typeof value === 'string' ? value : Object.values(value)] as string[])\n\t\t\t\t\t\t\t.flat()\n\t\t\t\t\t\t\t.forEach(file =>\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tconst bool = pathExistsSync(resolve(rootData.pkg, file));\n\n\t\t\t\t\t\t\t\tif (!bool)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlist.push(`path of '${entry}' does not exist: '${file}'`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t;\n\n\t\t\tif (list.length > 0)\n\t\t\t{\n\t\t\t\tlet err = new Error(`Invalid package exports: ${rootData.pkg}\\n${list.slice().map(v => ` - ${v}`).join('\\n')}`);\n\n\t\t\t\t// @ts-ignore\n\t\t\t\terr.list = list;\n\t\t\t\t// @ts-ignore\n\t\t\t\terr.rootData = rootData;\n\t\t\t\t// @ts-ignore\n\t\t\t\terr.pkgExports = pkg.exports;\n\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t}\n\n\t}\n\n\treturn null as null\n}\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pkgExportsAddPJsonEntry, pkgExportsVerify } from './field/exports';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pkgExportsVerify = exports.pkgExportsAddPJsonEntry = void 0;
|
|
4
|
+
var exports_1 = require("./field/exports");
|
|
5
|
+
Object.defineProperty(exports, "pkgExportsAddPJsonEntry", { enumerable: true, get: function () { return exports_1.pkgExportsAddPJsonEntry; } });
|
|
6
|
+
Object.defineProperty(exports, "pkgExportsVerify", { enumerable: true, get: function () { return exports_1.pkgExportsVerify; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AACA,2CAA4E;AAAnE,kHAAA,uBAAuB,OAAA;AAAE,2GAAA,gBAAgB,OAAA","sourcesContent":["\nexport { pkgExportsAddPJsonEntry, pkgExportsVerify } from './field/exports';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yarn-tool/pkg-entry-util",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"yarn",
|
|
7
|
+
"yarn-tool",
|
|
8
|
+
"npm",
|
|
9
|
+
"lerna",
|
|
10
|
+
"workspaces",
|
|
11
|
+
"pkg",
|
|
12
|
+
"dependencies",
|
|
13
|
+
"monorepo",
|
|
14
|
+
"yarnlock",
|
|
15
|
+
"node-modules",
|
|
16
|
+
"packages",
|
|
17
|
+
"package",
|
|
18
|
+
"create-by-yarn-tool"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/pkg-entry-util#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/bluelovers/ws-yarn-workspaces/issues"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/bluelovers/ws-yarn-workspaces.git"
|
|
27
|
+
},
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"author": "bluelovers",
|
|
30
|
+
"main": "lib/index.js",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"coverage": "yarn run test -- --coverage",
|
|
33
|
+
"lint": "ynpx --quiet eslint -- **/*.ts",
|
|
34
|
+
"test": "jest --passWithNoTests",
|
|
35
|
+
"test:jest": "jest --passWithNoTests",
|
|
36
|
+
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
37
|
+
"test:tsdx": "ynpx @bluelovers/tsdx test --passWithNoTests",
|
|
38
|
+
"build:dts": "ynpx dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner & echo build:dts",
|
|
39
|
+
"build:tsdx": "ynpx @bluelovers/tsdx build --target node --name index",
|
|
40
|
+
"preversion": "echo preversion && yarn run test",
|
|
41
|
+
"version": "echo version",
|
|
42
|
+
"postversion": "echo postversion",
|
|
43
|
+
"prepublish": "echo prepublish",
|
|
44
|
+
"prepublishOnly": "echo prepublishOnly",
|
|
45
|
+
"prepublishOnly:update": "yarn run ncu && yarn run sort-package-json",
|
|
46
|
+
"publish": "echo publish",
|
|
47
|
+
"postpublish": "echo postpublish",
|
|
48
|
+
"postpublishOnly": "echo postpublishOnly",
|
|
49
|
+
"ncu": "yarn-tool ncu -u",
|
|
50
|
+
"sort-package-json": "yarn-tool sort",
|
|
51
|
+
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@ts-type/package-dts": "^1.0.56",
|
|
55
|
+
"@yarn-tool/find-root": "^1.0.58",
|
|
56
|
+
"fs-extra": "^10.0.0",
|
|
57
|
+
"tslib": "^2.3.1"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
},
|
|
62
|
+
"packageManager": "yarn@^1.22.11",
|
|
63
|
+
"gitHead": "986788ee567cc010c0085405a18a032640b9d368"
|
|
64
|
+
}
|