@10stars/config 7.2.3 → 7.3.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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "name": "@10stars/config",
7
- "version": "7.2.3",
7
+ "version": "7.3.1",
8
8
  "author": "10stars.dev <web@alexandrov.co> (https://alexandrov.co)",
9
9
  "license": "MIT",
10
10
  "module": "./src/index.ts",
@@ -32,7 +32,7 @@
32
32
  "@typescript-eslint/eslint-plugin": "^5.0.0",
33
33
  "@typescript-eslint/parser": "^5.0.0",
34
34
  "builtin-modules": "^3.3.0",
35
- "esbuild": "~0.15.10",
35
+ "esbuild": "~0.16.10",
36
36
  "tsx": "^3.8.0",
37
37
  "eslint": "^8.0.0",
38
38
  "eslint-config-prettier": "^8.0.0",
@@ -1,7 +1,8 @@
1
- import type * as TF from "type-fest"
2
1
  import fs from "node:fs/promises"
3
2
  import path from "node:path"
4
3
 
4
+ import type * as TF from "type-fest"
5
+
5
6
  const symlink = async (pathTarget: string, pathSymlink: string) => {
6
7
  const stats = await fs.lstat(pathSymlink).catch(() => null)
7
8
  if (!stats) return
@@ -19,19 +20,47 @@ const symlink = async (pathTarget: string, pathSymlink: string) => {
19
20
 
20
21
  export const linkPackages = async (
21
22
  cwd: string,
22
- relativePathsToPkgs: string[],
23
+ packagesToLink: { relativePath: string; isMonorepo?: boolean }[],
23
24
  ) => {
24
- const linkPackage = async (relativePathToPkg: string) => {
25
- const pathPkg = path.join(cwd, relativePathToPkg)
25
+ const linkPackage = async (pathPkg: string) => {
26
26
  const pkgJson: TF.PackageJson = await import(
27
27
  path.join(pathPkg, `package.json`)
28
- )
28
+ ).catch(() => null)
29
+ if (!pkgJson) return
30
+
29
31
  const [orgName, pkgName] = pkgJson.name!.split(`/`)
30
32
 
31
- const pathTarget = path.join(cwd, relativePathToPkg)
32
33
  const pathSymlink = path.join(cwd, `node_modules`, orgName, pkgName)
33
- return symlink(pathTarget, pathSymlink)
34
+ return symlink(pathPkg, pathSymlink)
35
+ }
36
+
37
+ const promises: Promise<unknown>[] = []
38
+ for (const packageToLink of packagesToLink) {
39
+ if (!packageToLink.isMonorepo) {
40
+ promises.push(linkPackage(path.join(cwd, packageToLink.relativePath)))
41
+ continue
42
+ }
43
+
44
+ const files = await fs.readdir(packageToLink.relativePath, {
45
+ withFileTypes: true,
46
+ })
47
+ const directories = files.filter((v) => v.isDirectory()).map((v) => v.name)
48
+ const packages = (
49
+ await Promise.all(
50
+ directories.map(async (v) => {
51
+ const pathPkg = path.join(cwd, packageToLink.relativePath, v)
52
+ const pkgJson: TF.PackageJson = await import(
53
+ path.join(pathPkg, `package.json`)
54
+ ).catch(() => null)
55
+ if (pkgJson) return v
56
+ }),
57
+ )
58
+ ).filter(Boolean)
59
+ for (const pkg of packages) {
60
+ const relativePathToPkg = path.join(cwd, packageToLink.relativePath, pkg!)
61
+ promises.push(linkPackage(relativePathToPkg))
62
+ }
34
63
  }
35
64
 
36
- return Promise.all(relativePathsToPkgs.map(linkPackage))
65
+ return Promise.all(promises)
37
66
  }