@10stars/config 9.5.1 → 11.0.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/dist/index.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.run = void 0;
40
+ var node_child_process_1 = require("node:child_process");
41
+ var node_path_1 = require("node:path");
42
+ var link_packages_1 = require("./link-packages");
43
+ var cwd = process.env.PWD;
44
+ var exec = function (cmd) {
45
+ console.info("Executing: ".concat(cmd));
46
+ (0, node_child_process_1.execSync)(cmd, { cwd: cwd, stdio: "inherit" }); // make execSync process to use the parent's: "stdin", "stdout", "stderr" streams
47
+ };
48
+ var getConfig = function () { return __awaiter(void 0, void 0, void 0, function () {
49
+ return __generator(this, function (_a) {
50
+ return [2 /*return*/, Promise.resolve("".concat((0, node_path_1.join)(cwd, "10stars.config.js"))).then(function (s) { return require(s); }).catch(function () {
51
+ throw new Error("10stars.config.js not found.\nYou need to place it in the root of the repository.");
52
+ })];
53
+ });
54
+ }); };
55
+ var checkIsMonorepo = function () { return __awaiter(void 0, void 0, void 0, function () {
56
+ var pkgJson;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0: return [4 /*yield*/, Promise.resolve("".concat((0, node_path_1.join)(cwd, "package.json"))).then(function (s) { return require(s); })];
60
+ case 1:
61
+ pkgJson = _a.sent();
62
+ return [2 /*return*/, Boolean(pkgJson.workspaces)];
63
+ }
64
+ });
65
+ }); };
66
+ var getESLintPaths = function () { return __awaiter(void 0, void 0, void 0, function () {
67
+ var isMonorepo;
68
+ return __generator(this, function (_a) {
69
+ switch (_a.label) {
70
+ case 0: return [4 /*yield*/, checkIsMonorepo()];
71
+ case 1:
72
+ isMonorepo = _a.sent();
73
+ return [2 /*return*/, isMonorepo ? "*/src */*.ts" : "src *.ts"];
74
+ }
75
+ });
76
+ }); };
77
+ var actions = {
78
+ prepare: {
79
+ info: "Runs husky and links packages",
80
+ action: function () { return __awaiter(void 0, void 0, void 0, function () {
81
+ var config;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ exec("husky");
86
+ if (process.env.CI)
87
+ return [2 /*return*/];
88
+ return [4 /*yield*/, getConfig()];
89
+ case 1:
90
+ config = _a.sent();
91
+ if (!config.linkPackages) return [3 /*break*/, 3];
92
+ return [4 /*yield*/, (0, link_packages_1.linkPackages)(cwd, config.linkPackages)];
93
+ case 2:
94
+ _a.sent();
95
+ _a.label = 3;
96
+ case 3: return [2 /*return*/];
97
+ }
98
+ });
99
+ }); },
100
+ },
101
+ format: {
102
+ info: "Format code",
103
+ action: function () { return __awaiter(void 0, void 0, void 0, function () {
104
+ var isMonorepo;
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0: return [4 /*yield*/, checkIsMonorepo()];
108
+ case 1:
109
+ isMonorepo = _a.sent();
110
+ exec("prettier -l --write './".concat(isMonorepo ? "*/" : "", "src/**/*.{t,j}s{x,}'"));
111
+ return [2 /*return*/];
112
+ }
113
+ });
114
+ }); },
115
+ },
116
+ typecheck: {
117
+ info: "Typecheck code (in watch mode)",
118
+ action: function () { return exec("tsc --project ./tsconfig.json --watch --noEmit"); },
119
+ },
120
+ typecheckOnce: {
121
+ info: "Typecheck code (once)",
122
+ action: function () { return exec("tsc --project ./tsconfig.json --noEmit"); },
123
+ },
124
+ lint: {
125
+ info: "Lint code (in watch mode)",
126
+ action: function () { return __awaiter(void 0, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) {
127
+ switch (_c.label) {
128
+ case 0:
129
+ _a = exec;
130
+ _b = "esw --watch --ext .ts,.tsx ".concat;
131
+ return [4 /*yield*/, getESLintPaths()];
132
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply("esw --watch --ext .ts,.tsx ", [_c.sent()])])];
133
+ }
134
+ }); }); },
135
+ },
136
+ lintOnce: {
137
+ info: "Lint code (once)",
138
+ action: function () { return __awaiter(void 0, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) {
139
+ switch (_c.label) {
140
+ case 0:
141
+ _a = exec;
142
+ _b = "eslint --fix --ext .ts,.tsx ".concat;
143
+ return [4 /*yield*/, getESLintPaths()];
144
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply("eslint --fix --ext .ts,.tsx ", [_c.sent()])])];
145
+ }
146
+ }); }); },
147
+ },
148
+ };
149
+ var run = function () { return __awaiter(void 0, void 0, void 0, function () {
150
+ var cmd, availableActions, error, _i, availableActions_1, availableAction;
151
+ return __generator(this, function (_a) {
152
+ switch (_a.label) {
153
+ case 0:
154
+ cmd = process.argv[2];
155
+ availableActions = Object.keys(actions);
156
+ if (!availableActions.includes(cmd)) {
157
+ error = [
158
+ "Unknown command: ".concat(cmd, "\n"),
159
+ "Example CLI cmd: $ config lint",
160
+ "Available commands:",
161
+ ].join("\n");
162
+ for (_i = 0, availableActions_1 = availableActions; _i < availableActions_1.length; _i++) {
163
+ availableAction = availableActions_1[_i];
164
+ error += "\n ".concat(availableAction, " - ").concat(actions[availableAction].info);
165
+ }
166
+ throw new Error("".concat(error, "\n"));
167
+ }
168
+ return [4 /*yield*/, actions[cmd].action()];
169
+ case 1:
170
+ _a.sent();
171
+ return [2 /*return*/];
172
+ }
173
+ });
174
+ }); };
175
+ exports.run = run;
176
+ (0, exports.run)();
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.linkPackages = void 0;
40
+ var promises_1 = require("node:fs/promises");
41
+ var node_path_1 = require("node:path");
42
+ var symlink = function (pathTarget, pathSymlink) { return __awaiter(void 0, void 0, void 0, function () {
43
+ var stats, symlinkRealpath;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0: return [4 /*yield*/, (0, promises_1.lstat)(pathSymlink).catch(function () { return null; })];
47
+ case 1:
48
+ stats = _a.sent();
49
+ if (!stats)
50
+ return [2 /*return*/];
51
+ if (!stats.isSymbolicLink()) return [3 /*break*/, 3];
52
+ return [4 /*yield*/, (0, promises_1.realpath)(pathSymlink).catch(function () { return null; })];
53
+ case 2:
54
+ symlinkRealpath = _a.sent();
55
+ if (pathTarget === symlinkRealpath)
56
+ return [2 /*return*/];
57
+ _a.label = 3;
58
+ case 3:
59
+ if (!stats.isDirectory()) return [3 /*break*/, 5];
60
+ return [4 /*yield*/, (0, promises_1.rm)(pathSymlink, { recursive: true })];
61
+ case 4:
62
+ _a.sent();
63
+ return [3 /*break*/, 7];
64
+ case 5: return [4 /*yield*/, (0, promises_1.unlink)(pathSymlink)];
65
+ case 6:
66
+ _a.sent();
67
+ _a.label = 7;
68
+ case 7: return [4 /*yield*/, (0, promises_1.symlink)(pathTarget, pathSymlink)];
69
+ case 8:
70
+ _a.sent();
71
+ return [2 /*return*/];
72
+ }
73
+ });
74
+ }); };
75
+ var linkPackages = function (cwd, packagesToLink) { return __awaiter(void 0, void 0, void 0, function () {
76
+ var linkPackage, promises, _loop_1, _i, packagesToLink_1, packageToLink;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0:
80
+ console.info("Linking local packages");
81
+ linkPackage = function (pathPkg) { return __awaiter(void 0, void 0, void 0, function () {
82
+ var pkgJson, _a, orgName, pkgName, pathSymlink;
83
+ return __generator(this, function (_b) {
84
+ switch (_b.label) {
85
+ case 0: return [4 /*yield*/, Promise.resolve("".concat((0, node_path_1.join)(pathPkg, "package.json"))).then(function (s) { return require(s); }).catch(function () { return null; })];
86
+ case 1:
87
+ pkgJson = _b.sent();
88
+ if (!pkgJson)
89
+ return [2 /*return*/];
90
+ _a = pkgJson.name.split("/"), orgName = _a[0], pkgName = _a[1];
91
+ pathSymlink = (0, node_path_1.join)(cwd, "node_modules", orgName, pkgName);
92
+ return [2 /*return*/, symlink(pathPkg, pathSymlink)];
93
+ }
94
+ });
95
+ }); };
96
+ promises = [];
97
+ _loop_1 = function (packageToLink) {
98
+ var files, directories, packages, _b, packages_1, pkg, relativePathToPkg;
99
+ return __generator(this, function (_c) {
100
+ switch (_c.label) {
101
+ case 0:
102
+ if (!packageToLink.isMonorepo) {
103
+ promises.push(linkPackage((0, node_path_1.join)(cwd, packageToLink.relativePath)));
104
+ return [2 /*return*/, "continue"];
105
+ }
106
+ return [4 /*yield*/, (0, promises_1.readdir)(packageToLink.relativePath, {
107
+ withFileTypes: true,
108
+ }).catch(function () { return null; })];
109
+ case 1:
110
+ files = _c.sent();
111
+ if (!files)
112
+ return [2 /*return*/, "continue"];
113
+ directories = files.filter(function (v) { return v.isDirectory(); }).map(function (v) { return v.name; });
114
+ return [4 /*yield*/, Promise.all(directories.map(function (v) { return __awaiter(void 0, void 0, void 0, function () {
115
+ var pathPkg, pkgJson;
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0:
119
+ pathPkg = (0, node_path_1.join)(cwd, packageToLink.relativePath, v);
120
+ return [4 /*yield*/, Promise.resolve("".concat((0, node_path_1.join)(pathPkg, "package.json"))).then(function (s) { return require(s); }).catch(function () { return null; })];
121
+ case 1:
122
+ pkgJson = _a.sent();
123
+ if (pkgJson)
124
+ return [2 /*return*/, v];
125
+ return [2 /*return*/];
126
+ }
127
+ });
128
+ }); }))];
129
+ case 2:
130
+ packages = (_c.sent()).filter(Boolean);
131
+ for (_b = 0, packages_1 = packages; _b < packages_1.length; _b++) {
132
+ pkg = packages_1[_b];
133
+ relativePathToPkg = (0, node_path_1.join)(cwd, packageToLink.relativePath, pkg);
134
+ promises.push(linkPackage(relativePathToPkg));
135
+ }
136
+ return [2 /*return*/];
137
+ }
138
+ });
139
+ };
140
+ _i = 0, packagesToLink_1 = packagesToLink;
141
+ _a.label = 1;
142
+ case 1:
143
+ if (!(_i < packagesToLink_1.length)) return [3 /*break*/, 4];
144
+ packageToLink = packagesToLink_1[_i];
145
+ return [5 /*yield**/, _loop_1(packageToLink)];
146
+ case 2:
147
+ _a.sent();
148
+ _a.label = 3;
149
+ case 3:
150
+ _i++;
151
+ return [3 /*break*/, 1];
152
+ case 4: return [4 /*yield*/, Promise.all(promises)];
153
+ case 5:
154
+ _a.sent();
155
+ console.info("Successfully linked local packages!");
156
+ return [2 /*return*/];
157
+ }
158
+ });
159
+ }); };
160
+ exports.linkPackages = linkPackages;
package/package.json CHANGED
@@ -4,13 +4,14 @@
4
4
  "access": "public"
5
5
  },
6
6
  "name": "@10stars/config",
7
- "version": "9.5.1",
7
+ "version": "11.0.0",
8
8
  "author": "10stars.dev <web@alexandrov.co> (https://alexandrov.co)",
9
9
  "license": "MIT",
10
- "module": "./src/index.ts",
11
- "main": "./src/index.ts",
10
+ "bin": {
11
+ "config": "./dist/index.js"
12
+ },
12
13
  "files": [
13
- "src",
14
+ "dist",
14
15
  ".eslintrc.js",
15
16
  ".prettierrc.js",
16
17
  "commitlint.config.js",
@@ -18,31 +19,32 @@
18
19
  ],
19
20
  "tsconfig": "./tsconfig.json",
20
21
  "scripts": {
22
+ "prepare": "tsc ./src/index.ts --outDir ./dist",
21
23
  "test": "npm run lint",
22
24
  "lint": "eslint .",
23
25
  "lint-rule-timings": "cross-env TIMING=1 npm run lint"
24
26
  },
25
27
  "dependencies": {
26
28
  "@10stars/eslint-plugin-react-hooks": "^4.3.4",
27
- "@commitlint/cli": "^18.0.0",
28
- "@commitlint/config-conventional": "^18.0.0",
29
+ "@commitlint/cli": "^19.0.0",
30
+ "@commitlint/config-conventional": "^19.0.0",
29
31
  "@types/lodash": "^4.0.0",
30
32
  "@types/node": "^20.0.0",
31
33
  "@types/react": "^18.0.0",
32
- "@typescript-eslint/eslint-plugin": "^6.0.0",
33
- "@typescript-eslint/parser": "^6.0.0",
34
+ "@typescript-eslint/eslint-plugin": "^7.0.0",
35
+ "@typescript-eslint/parser": "^7.0.0",
34
36
  "builtin-modules": "^3.3.0",
35
- "esbuild": "~0.19.5",
37
+ "esbuild": "~0.20.1",
36
38
  "tsx": "^4.0.0",
37
39
  "eslint": "^8.0.0",
38
40
  "eslint-config-prettier": "^9.0.0",
39
41
  "eslint-plugin-import": "^2.0.0",
40
42
  "eslint-plugin-react": "^7.0.0",
41
43
  "eslint-plugin-regexp": "^2.0.0",
42
- "eslint-plugin-simple-import-sort": "^10.0.0",
44
+ "eslint-plugin-simple-import-sort": "^12.0.0",
43
45
  "eslint-plugin-sort-keys-fix": "^1.0.0",
44
46
  "eslint-watch": "^8.0.0",
45
- "husky": "^8.0.0",
47
+ "husky": "^9.0.0",
46
48
  "prettier": "^3.0.0",
47
49
  "type-fest": "^4.0.0",
48
50
  "typescript": "^5.2.2"
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./link-packages"
@@ -1,72 +0,0 @@
1
- import fs from "node:fs/promises"
2
- import path from "node:path"
3
-
4
- import type * as TF from "type-fest"
5
-
6
- const symlink = async (pathTarget: string, pathSymlink: string) => {
7
- const stats = await fs.lstat(pathSymlink).catch(() => null)
8
- if (!stats) return
9
-
10
- if (stats.isSymbolicLink()) {
11
- const symlinkRealpath = await fs.realpath(pathSymlink).catch(() => null)
12
- if (pathTarget === symlinkRealpath) return
13
- }
14
-
15
- if (stats.isDirectory()) await fs.rm(pathSymlink, { recursive: true })
16
- else await fs.unlink(pathSymlink)
17
-
18
- await fs.symlink(pathTarget, pathSymlink)
19
- }
20
-
21
- export const linkPackages = async (
22
- cwd: string,
23
- packagesToLink: { relativePath: string; isMonorepo?: boolean }[],
24
- ) => {
25
- console.info(`Linking local packages`)
26
-
27
- const linkPackage = async (pathPkg: string) => {
28
- const pkgJson: TF.PackageJson = await import(
29
- path.join(pathPkg, `package.json`)
30
- ).catch(() => null)
31
- if (!pkgJson) return
32
-
33
- const [orgName, pkgName] = pkgJson.name!.split(`/`)
34
-
35
- const pathSymlink = path.join(cwd, `node_modules`, orgName, pkgName)
36
- return symlink(pathPkg, pathSymlink)
37
- }
38
-
39
- const promises: Promise<unknown>[] = []
40
- for (const packageToLink of packagesToLink) {
41
- if (!packageToLink.isMonorepo) {
42
- promises.push(linkPackage(path.join(cwd, packageToLink.relativePath)))
43
- continue
44
- }
45
-
46
- const files = await fs
47
- .readdir(packageToLink.relativePath, { withFileTypes: true })
48
- .catch(() => null)
49
- if (!files) continue
50
-
51
- const directories = files.filter((v) => v.isDirectory()).map((v) => v.name)
52
- const packages = (
53
- await Promise.all(
54
- directories.map(async (v) => {
55
- const pathPkg = path.join(cwd, packageToLink.relativePath, v)
56
- const pkgJson: TF.PackageJson = await import(
57
- path.join(pathPkg, `package.json`)
58
- ).catch(() => null)
59
- if (pkgJson) return v
60
- }),
61
- )
62
- ).filter(Boolean)
63
- for (const pkg of packages) {
64
- const relativePathToPkg = path.join(cwd, packageToLink.relativePath, pkg!)
65
- promises.push(linkPackage(relativePathToPkg))
66
- }
67
- }
68
-
69
- await Promise.all(promises)
70
-
71
- console.info(`Successfully linked local packages!`)
72
- }