@poppinss/utils 7.0.0-next.2 → 7.0.0-next.4
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/build/exception-L7vjh-Gv.js +2 -0
- package/build/index.js +96 -167
- package/build/is_script_file-CbSEfxE_.js +20 -0
- package/build/main-_zxQ-frM.js +535 -0
- package/build/modules/assert.js +8 -21
- package/build/modules/base64.js +24 -41
- package/build/modules/exception.js +2 -12
- package/build/modules/fs/main.js +51 -75
- package/build/modules/json/main.js +2 -8
- package/build/modules/string/main.js +1 -4
- package/build/modules/string/string_builder.js +1 -4
- package/build/modules/types.js +1 -1
- package/build/src/compose.d.ts +4 -4
- package/package.json +27 -27
- package/build/chunk-SKNTF5Q5.js +0 -14
- package/build/chunk-XFX47BKO.js +0 -23
- package/build/chunk-YFSCSJNE.js +0 -33
package/build/modules/fs/main.js
CHANGED
|
@@ -1,82 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
naturalSort
|
|
4
|
-
} from "../../chunk-XFX47BKO.js";
|
|
5
|
-
|
|
6
|
-
// modules/fs/fs_read_all.ts
|
|
1
|
+
import { n as naturalSort, t as isScriptFile } from "../../is_script_file-CbSEfxE_.js";
|
|
2
|
+
import { extname, join, relative, sep } from "node:path";
|
|
7
3
|
import string from "@poppinss/string";
|
|
8
|
-
import
|
|
9
|
-
import { readdir, stat } from "fs/promises";
|
|
10
|
-
import { fileURLToPath, pathToFileURL } from "url";
|
|
4
|
+
import lodash from "@poppinss/utils/lodash";
|
|
5
|
+
import { readdir, stat } from "node:fs/promises";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
7
|
async function fsReadAll(location, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
case "url":
|
|
43
|
-
return pathToFileURL(join(file.parentPath, file.name)).href;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
if (normalizedOptions.filter) {
|
|
47
|
-
return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort);
|
|
48
|
-
}
|
|
49
|
-
return files.sort(normalizedOptions.sort);
|
|
8
|
+
const normalizedLocation = typeof location === "string" ? location : fileURLToPath(location);
|
|
9
|
+
const normalizedOptions = Object.assign({
|
|
10
|
+
absolute: false,
|
|
11
|
+
sort: naturalSort
|
|
12
|
+
}, options);
|
|
13
|
+
const pathType = normalizedOptions.pathType || "relative";
|
|
14
|
+
try {
|
|
15
|
+
await stat(normalizedLocation);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (normalizedOptions.ignoreMissingRoot) return [];
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
const files = (await readdir(normalizedLocation, {
|
|
21
|
+
recursive: true,
|
|
22
|
+
withFileTypes: true
|
|
23
|
+
})).filter((dirent) => {
|
|
24
|
+
if (!dirent.isFile()) return false;
|
|
25
|
+
if (dirent.name.startsWith(".") || dirent.parentPath.split(sep).some((segment) => segment.startsWith("."))) return false;
|
|
26
|
+
return true;
|
|
27
|
+
}).map((file) => {
|
|
28
|
+
switch (pathType) {
|
|
29
|
+
case "relative": return join(relative(normalizedLocation, file.parentPath), file.name);
|
|
30
|
+
case "absolute": return join(file.parentPath, file.name);
|
|
31
|
+
case "unixRelative": return string.toUnixSlash(join(relative(normalizedLocation, file.parentPath), file.name));
|
|
32
|
+
case "unixAbsolute": return string.toUnixSlash(join(file.parentPath, file.name));
|
|
33
|
+
case "url": return pathToFileURL(join(file.parentPath, file.name)).href;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (normalizedOptions.filter) return files.filter(normalizedOptions.filter).sort(normalizedOptions.sort);
|
|
37
|
+
return files.sort(normalizedOptions.sort);
|
|
50
38
|
}
|
|
51
|
-
|
|
52
|
-
// modules/fs/fs_import_all.ts
|
|
53
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
54
|
-
import lodash from "@poppinss/utils/lodash";
|
|
55
|
-
import { extname, relative as relative2, sep as sep2 } from "path";
|
|
56
39
|
async function importFile(basePath, fileURL, values, options) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
values,
|
|
63
|
-
options.transformKeys ? options.transformKeys(collectionKey) : collectionKey,
|
|
64
|
-
exportedValue.default ? exportedValue.default : { ...exportedValue }
|
|
65
|
-
);
|
|
40
|
+
const filePath = fileURLToPath(fileURL);
|
|
41
|
+
const fileExtension = extname(filePath);
|
|
42
|
+
const collectionKey = relative(basePath, filePath).replace(/* @__PURE__ */ new RegExp(`${fileExtension}$`), "").split(sep);
|
|
43
|
+
const exportedValue = fileExtension === ".json" ? await import(fileURL, { with: { type: "json" } }) : await import(fileURL);
|
|
44
|
+
lodash.set(values, options.transformKeys ? options.transformKeys(collectionKey) : collectionKey, exportedValue.default ? exportedValue.default : { ...exportedValue });
|
|
66
45
|
}
|
|
67
46
|
async function fsImportAll(location, options) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
47
|
+
options = options || {};
|
|
48
|
+
const collection = {};
|
|
49
|
+
const normalizedLocation = typeof location === "string" ? location : fileURLToPath(location);
|
|
50
|
+
const files = await fsReadAll(normalizedLocation, {
|
|
51
|
+
filter: isScriptFile,
|
|
52
|
+
...options,
|
|
53
|
+
pathType: "url"
|
|
54
|
+
});
|
|
55
|
+
await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options)));
|
|
56
|
+
return collection;
|
|
78
57
|
}
|
|
79
|
-
export {
|
|
80
|
-
fsImportAll,
|
|
81
|
-
fsReadAll
|
|
82
|
-
};
|
|
58
|
+
export { fsImportAll, fsReadAll };
|
package/build/modules/types.js
CHANGED
package/build/src/compose.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare function compose<T extends Constructor<any>, A, B>(superclass: T,
|
|
|
14
14
|
export declare function compose<T extends Constructor<any>, A, B, C>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>): C;
|
|
15
15
|
export declare function compose<T extends Constructor<any>, A, B, C, D>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>): D;
|
|
16
16
|
export declare function compose<T extends Constructor<any>, A, B, C, D, E>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>): E;
|
|
17
|
-
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>): F;
|
|
18
|
-
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F, G>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>): G;
|
|
19
|
-
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F, G, H>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>): H;
|
|
20
|
-
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F, G, H, I>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>, mixinI: UnaryFunction<H, I>): I;
|
|
17
|
+
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>, mixinF: UnaryFunction<E, F>): F;
|
|
18
|
+
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F, G>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>): G;
|
|
19
|
+
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F, G, H>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>): H;
|
|
20
|
+
export declare function compose<T extends Constructor<any>, A, B, C, D, E, F, G, H, I>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>, mixinI: UnaryFunction<H, I>): I;
|
|
21
21
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poppinss/utils",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.4",
|
|
4
4
|
"description": "Handy utilities for repetitive work",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,9 +26,6 @@
|
|
|
26
26
|
"./exception": "./build/modules/exception.js",
|
|
27
27
|
"./types": "./build/modules/types.js"
|
|
28
28
|
},
|
|
29
|
-
"engines": {
|
|
30
|
-
"node": ">=24.0.0"
|
|
31
|
-
},
|
|
32
29
|
"scripts": {
|
|
33
30
|
"pretest": "npm run lint",
|
|
34
31
|
"test": "npm run build:lodash && npm run quick:test",
|
|
@@ -37,7 +34,7 @@
|
|
|
37
34
|
"format": "prettier --write .",
|
|
38
35
|
"typecheck": "tsc --noEmit",
|
|
39
36
|
"precompile": "npm run lint",
|
|
40
|
-
"compile": "
|
|
37
|
+
"compile": "tsdown && tsc --emitDeclarationOnly --declaration",
|
|
41
38
|
"build": "npm run compile && npm run build:lodash",
|
|
42
39
|
"version": "npm run build",
|
|
43
40
|
"prepublishOnly": "npm run build",
|
|
@@ -45,36 +42,36 @@
|
|
|
45
42
|
"quick:test": "node --import=@poppinss/ts-exec bin/test.ts"
|
|
46
43
|
},
|
|
47
44
|
"devDependencies": {
|
|
48
|
-
"@adonisjs/eslint-config": "^3.0.0-next.
|
|
49
|
-
"@adonisjs/logger": "^6.0.
|
|
45
|
+
"@adonisjs/eslint-config": "^3.0.0-next.5",
|
|
46
|
+
"@adonisjs/logger": "^6.0.7",
|
|
50
47
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
51
|
-
"@adonisjs/tsconfig": "^2.0.0-next.
|
|
52
|
-
"@japa/assert": "^4.
|
|
48
|
+
"@adonisjs/tsconfig": "^2.0.0-next.3",
|
|
49
|
+
"@japa/assert": "^4.1.1",
|
|
53
50
|
"@japa/expect-type": "^2.0.3",
|
|
54
|
-
"@japa/runner": "^4.
|
|
55
|
-
"@poppinss/ts-exec": "^1.4.
|
|
56
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
51
|
+
"@japa/runner": "^4.4.0",
|
|
52
|
+
"@poppinss/ts-exec": "^1.4.1",
|
|
53
|
+
"@release-it/conventional-changelog": "^10.0.3",
|
|
57
54
|
"@types/fs-extra": "^11.0.4",
|
|
58
|
-
"@types/node": "^
|
|
55
|
+
"@types/node": "^25.0.1",
|
|
59
56
|
"c8": "^10.1.3",
|
|
60
|
-
"eslint": "^9.
|
|
61
|
-
"fs-extra": "^11.3.
|
|
57
|
+
"eslint": "^9.39.1",
|
|
58
|
+
"fs-extra": "^11.3.2",
|
|
62
59
|
"lodash": "^4.17.21",
|
|
63
60
|
"lodash-cli": "^4.17.5",
|
|
64
61
|
"move-file-cli": "^3.0.0",
|
|
65
|
-
"prettier": "^3.
|
|
66
|
-
"release-it": "^19.0
|
|
67
|
-
"
|
|
68
|
-
"
|
|
62
|
+
"prettier": "^3.7.4",
|
|
63
|
+
"release-it": "^19.1.0",
|
|
64
|
+
"safe-stable-stringify": "^2.5.0",
|
|
65
|
+
"secure-json-parse": "^4.1.0",
|
|
66
|
+
"tsdown": "^0.17.3",
|
|
67
|
+
"typescript": "^5.9.3"
|
|
69
68
|
},
|
|
70
69
|
"dependencies": {
|
|
71
|
-
"@poppinss/exception": "^1.2.
|
|
70
|
+
"@poppinss/exception": "^1.2.3",
|
|
72
71
|
"@poppinss/object-builder": "^1.1.0",
|
|
73
|
-
"@poppinss/string": "^1.
|
|
74
|
-
"@poppinss/types": "^1.1
|
|
75
|
-
"flattie": "^1.1.1"
|
|
76
|
-
"safe-stable-stringify": "^2.5.0",
|
|
77
|
-
"secure-json-parse": "^4.0.0"
|
|
72
|
+
"@poppinss/string": "^1.7.1",
|
|
73
|
+
"@poppinss/types": "^1.2.1",
|
|
74
|
+
"flattie": "^1.1.1"
|
|
78
75
|
},
|
|
79
76
|
"homepage": "https://github.com/poppinss/utils#readme",
|
|
80
77
|
"repository": {
|
|
@@ -94,7 +91,7 @@
|
|
|
94
91
|
"access": "public",
|
|
95
92
|
"provenance": true
|
|
96
93
|
},
|
|
97
|
-
"
|
|
94
|
+
"tsdown": {
|
|
98
95
|
"entry": [
|
|
99
96
|
"./index.ts",
|
|
100
97
|
"./modules/fs/main.ts",
|
|
@@ -109,8 +106,11 @@
|
|
|
109
106
|
"outDir": "./build",
|
|
110
107
|
"clean": true,
|
|
111
108
|
"format": "esm",
|
|
109
|
+
"minify": "dce-only",
|
|
110
|
+
"fixedExtension": false,
|
|
112
111
|
"dts": false,
|
|
113
|
-
"
|
|
112
|
+
"treeshake": false,
|
|
113
|
+
"sourcemaps": false,
|
|
114
114
|
"target": "esnext"
|
|
115
115
|
},
|
|
116
116
|
"release-it": {
|
package/build/chunk-SKNTF5Q5.js
DELETED
package/build/chunk-XFX47BKO.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// src/natural_sort.ts
|
|
2
|
-
function naturalSort(current, next) {
|
|
3
|
-
return current.localeCompare(next, void 0, { numeric: true, sensitivity: "base" });
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// src/is_script_file.ts
|
|
7
|
-
import { extname } from "path";
|
|
8
|
-
var JS_MODULES = [".js", ".json", ".cjs", ".mjs"];
|
|
9
|
-
function isScriptFile(filePath) {
|
|
10
|
-
const ext = extname(filePath);
|
|
11
|
-
if (JS_MODULES.includes(ext)) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
if (ext === ".ts" && !filePath.endsWith(".d.ts")) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
naturalSort,
|
|
22
|
-
isScriptFile
|
|
23
|
-
};
|
package/build/chunk-YFSCSJNE.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// modules/json/safe_parse.ts
|
|
2
|
-
import { parse } from "secure-json-parse";
|
|
3
|
-
function safeParse(jsonString, reviver) {
|
|
4
|
-
return parse(jsonString, reviver, {
|
|
5
|
-
protoAction: "remove",
|
|
6
|
-
constructorAction: "remove"
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// modules/json/safe_stringify.ts
|
|
11
|
-
import { configure } from "safe-stable-stringify";
|
|
12
|
-
var stringify = configure({
|
|
13
|
-
bigint: false,
|
|
14
|
-
circularValue: void 0,
|
|
15
|
-
deterministic: false
|
|
16
|
-
});
|
|
17
|
-
function jsonStringifyReplacer(replacer) {
|
|
18
|
-
return function(key, value) {
|
|
19
|
-
const val = replacer ? replacer.call(this, key, value) : value;
|
|
20
|
-
if (typeof val === "bigint") {
|
|
21
|
-
return val.toString();
|
|
22
|
-
}
|
|
23
|
-
return val;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function safeStringify(value, replacer, space) {
|
|
27
|
-
return stringify(value, jsonStringifyReplacer(replacer), space);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
safeParse,
|
|
32
|
-
safeStringify
|
|
33
|
-
};
|