@windwalker-io/core 4.2.4 → 4.2.5

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.
@@ -1,47 +1,47 @@
1
- import path, { resolve } from 'node:path';
2
- import { loadJson } from './fs';
3
-
4
- export function findModules(suffix = '', rootModule: string | null = 'src/Module'): string[] {
5
- const pkg = path.resolve(process.cwd(), 'composer.json');
6
-
7
- const pkgJson = loadJson(pkg);
8
-
9
- const vendors = Object.keys(pkgJson['require'] || {})
10
- .concat(Object.keys(pkgJson['require-dev'] || {}))
11
- .map(id => `vendor/${id}/composer.json`)
12
- .map((file) => loadJson(file))
13
- .filter(pkgJson => pkgJson?.extra?.windwalker != null)
14
- .map(pkgJson => {
15
- return pkgJson?.extra?.windwalker?.modules?.map((module: string) => {
16
- return `vendor/${pkgJson.name}/${module}/${suffix}`;
17
- }) || [];
18
- })
19
- .flat();
20
-
21
- if (rootModule) {
22
- vendors.push(rootModule + '/' + suffix);
23
- }
24
-
25
- return [...new Set(vendors)];
26
- }
27
-
28
- export function findPackages(suffix = '', withRoot = true): string[] {
29
- const pkg = path.resolve(process.cwd(), 'composer.json');
30
-
31
- const pkgJson = loadJson(pkg);
32
-
33
- const vendors = Object.keys(pkgJson['require'] || {})
34
- .concat(Object.keys(pkgJson['require-dev'] || {}))
35
- .map(id => `vendor/${id}/composer.json`)
36
- .map((file) => loadJson(file))
37
- .filter((pkgJson) => pkgJson?.extra?.windwalker != null)
38
- .map((pkgJson) => `vendor/${pkgJson.name}/${suffix}`)
39
- .flat();
40
-
41
- if (withRoot) {
42
- vendors.unshift(suffix);
43
- }
44
-
45
- return [...new Set(vendors)];
46
- }
47
-
1
+ import path, { resolve } from 'node:path';
2
+ import { loadJson } from './fs';
3
+
4
+ export function findModules(suffix = '', rootModule: string | null = 'src/Module'): string[] {
5
+ const pkg = path.resolve(process.cwd(), 'composer.json');
6
+
7
+ const pkgJson = loadJson(pkg);
8
+
9
+ const vendors = Object.keys(pkgJson['require'] || {})
10
+ .concat(Object.keys(pkgJson['require-dev'] || {}))
11
+ .map(id => `vendor/${id}/composer.json`)
12
+ .map((file) => loadJson(file))
13
+ .filter(pkgJson => pkgJson?.extra?.windwalker != null)
14
+ .map(pkgJson => {
15
+ return pkgJson?.extra?.windwalker?.modules?.map((module: string) => {
16
+ return `vendor/${pkgJson.name}/${module}/${suffix}`;
17
+ }) || [];
18
+ })
19
+ .flat();
20
+
21
+ if (rootModule) {
22
+ vendors.push(rootModule + '/' + suffix);
23
+ }
24
+
25
+ return [...new Set(vendors)];
26
+ }
27
+
28
+ export function findPackages(suffix = '', withRoot = true): string[] {
29
+ const pkg = path.resolve(process.cwd(), 'composer.json');
30
+
31
+ const pkgJson = loadJson(pkg);
32
+
33
+ const vendors = Object.keys(pkgJson['require'] || {})
34
+ .concat(Object.keys(pkgJson['require-dev'] || {}))
35
+ .map(id => `vendor/${id}/composer.json`)
36
+ .map((file) => loadJson(file))
37
+ .filter((pkgJson) => pkgJson?.extra?.windwalker != null)
38
+ .map((pkgJson) => `vendor/${pkgJson.name}/${suffix}`)
39
+ .flat();
40
+
41
+ if (withRoot) {
42
+ vendors.unshift(suffix);
43
+ }
44
+
45
+ return [...new Set(vendors)];
46
+ }
47
+
@@ -1,11 +1,11 @@
1
- import { randomBytes } from 'node:crypto';
2
-
3
- export function uniqId(prefix: string = '', size = 16): string {
4
- let id = randomBytes(size).toString('hex');
5
-
6
- if (prefix) {
7
- id = prefix + id;
8
- }
9
-
10
- return id;
11
- }
1
+ import { randomBytes } from 'node:crypto';
2
+
3
+ export function uniqId(prefix: string = '', size = 16): string {
4
+ let id = randomBytes(size).toString('hex');
5
+
6
+ if (prefix) {
7
+ id = prefix + id;
8
+ }
9
+
10
+ return id;
11
+ }
@@ -1,61 +1,61 @@
1
- import { getGlobBaseFromPattern } from '@windwalker-io/fusion-next';
2
- import fs from 'node:fs';
3
- import fg from 'fast-glob';
4
- import isGlob from 'is-glob';
5
- import { relative } from 'node:path';
6
-
7
- export function loadJson(file: string) {
8
- if (!fs.existsSync(file)) {
9
- return null;
10
- }
11
-
12
- return JSON.parse(fs.readFileSync(file, 'utf8'));
13
- }
14
-
15
- export function containsMiddleGlob(str: string) {
16
- return isGlob(removeLastGlob(str));
17
- }
18
-
19
- export function removeLastGlob(str: string) {
20
- // Remove `/**` `/*` `/**/*` at the end of the string
21
- return str.replace(/(\/\*|\/\*\*?|\*\*\/\*?)$/, '');
22
- }
23
-
24
- const ds = process.platform === 'win32' ? '\\' : '/';
25
-
26
- export function ensureDirPath(path: string, slash: '/' | '\\' = ds): string {
27
- if (!path.endsWith(slash)) {
28
- return path + slash;
29
- }
30
-
31
- return path;
32
- }
33
-
34
- export interface FindFileResult {
35
- fullpath: string;
36
- relativePath: string;
37
- }
38
-
39
- export function findFilesFromGlobArray(sources: string[]): FindFileResult[] {
40
- let files: FindFileResult[] = [];
41
-
42
- for (const source of sources) {
43
- files = [
44
- ...files,
45
- ...findFiles(source)
46
- ];
47
- }
48
-
49
- return files;
50
- }
51
-
52
- function findFiles(src: string): FindFileResult[] {
53
- return fg.globSync(src).map((file: string) => {
54
- file = file.replace(/\\/g, '/');
55
-
56
- return {
57
- fullpath: file,
58
- relativePath: relative(getGlobBaseFromPattern(src), file).replace(/\\/g, '/')
59
- };
60
- });
61
- }
1
+ import { getGlobBaseFromPattern } from '@windwalker-io/fusion-next';
2
+ import fs from 'node:fs';
3
+ import fg from 'fast-glob';
4
+ import isGlob from 'is-glob';
5
+ import { relative } from 'node:path';
6
+
7
+ export function loadJson(file: string) {
8
+ if (!fs.existsSync(file)) {
9
+ return null;
10
+ }
11
+
12
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
13
+ }
14
+
15
+ export function containsMiddleGlob(str: string) {
16
+ return isGlob(removeLastGlob(str));
17
+ }
18
+
19
+ export function removeLastGlob(str: string) {
20
+ // Remove `/**` `/*` `/**/*` at the end of the string
21
+ return str.replace(/(\/\*|\/\*\*?|\*\*\/\*?)$/, '');
22
+ }
23
+
24
+ const ds = process.platform === 'win32' ? '\\' : '/';
25
+
26
+ export function ensureDirPath(path: string, slash: '/' | '\\' = ds): string {
27
+ if (!path.endsWith(slash)) {
28
+ return path + slash;
29
+ }
30
+
31
+ return path;
32
+ }
33
+
34
+ export interface FindFileResult {
35
+ fullpath: string;
36
+ relativePath: string;
37
+ }
38
+
39
+ export function findFilesFromGlobArray(sources: string[]): FindFileResult[] {
40
+ let files: FindFileResult[] = [];
41
+
42
+ for (const source of sources) {
43
+ files = [
44
+ ...files,
45
+ ...findFiles(source)
46
+ ];
47
+ }
48
+
49
+ return files;
50
+ }
51
+
52
+ function findFiles(src: string): FindFileResult[] {
53
+ return fg.globSync(src).map((file: string) => {
54
+ file = file.replace(/\\/g, '/');
55
+
56
+ return {
57
+ fullpath: file,
58
+ relativePath: relative(getGlobBaseFromPattern(src), file).replace(/\\/g, '/')
59
+ };
60
+ });
61
+ }
@@ -1,5 +1,5 @@
1
- export * from './asset-sync';
2
- export * from './fs';
3
- export * from './crypto';
4
- export * from './modules';
5
-
1
+ export * from './asset-sync';
2
+ export * from './fs';
3
+ export * from './crypto';
4
+ export * from './modules';
5
+
@@ -1,17 +1,17 @@
1
- import { createRequire } from 'node:module';
2
-
3
- export function resolveModuleRealpath(url: string, module: string) {
4
- const require = createRequire(url);
5
-
6
- return require.resolve(module);
7
- }
8
-
9
- export function stripUrlQuery(src: string) {
10
- const qPos = src.indexOf('?');
11
-
12
- if (qPos !== -1) {
13
- return src.substring(0, qPos);
14
- }
15
-
16
- return src;
17
- }
1
+ import { createRequire } from 'node:module';
2
+
3
+ export function resolveModuleRealpath(url: string, module: string) {
4
+ const require = createRequire(url);
5
+
6
+ return require.resolve(module);
7
+ }
8
+
9
+ export function stripUrlQuery(src: string) {
10
+ const qPos = src.indexOf('?');
11
+
12
+ if (qPos !== -1) {
13
+ return src.substring(0, qPos);
14
+ }
15
+
16
+ return src;
17
+ }