@poppinss/utils 7.0.0-next.3 → 7.0.0-next.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.
- package/README.md +117 -0
- package/build/chunk-BNZ4_A-W.js +23 -0
- package/build/exception-L7vjh-Gv.js +2 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +142 -167
- package/build/main-CdreHl1_.js +694 -0
- package/build/main-aO4h7ygK.js +514 -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 +52 -75
- package/build/modules/json/main.js +3 -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/build/src/imports_bag.d.ts +24 -0
- package/package.json +28 -25
- 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,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "../../chunk-XFX47BKO.js";
|
|
5
|
-
|
|
6
|
-
// modules/fs/fs_read_all.ts
|
|
1
|
+
import { n as __toESM } from "../../chunk-BNZ4_A-W.js";
|
|
2
|
+
import { n as isScriptFile, r as naturalSort, t as require_main } from "../../main-CdreHl1_.js";
|
|
3
|
+
import { extname, join, relative, sep } from "node:path";
|
|
7
4
|
import string from "@poppinss/string";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { fileURLToPath, pathToFileURL } from "url";
|
|
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";
|
|
39
|
+
var import_main = /* @__PURE__ */ __toESM(require_main());
|
|
56
40
|
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
|
-
);
|
|
41
|
+
const filePath = fileURLToPath(fileURL);
|
|
42
|
+
const fileExtension = extname(filePath);
|
|
43
|
+
const collectionKey = relative(basePath, filePath).replace(/* @__PURE__ */ new RegExp(`${fileExtension}$`), "").split(sep);
|
|
44
|
+
const exportedValue = fileExtension === ".json" ? await import(fileURL, { with: { type: "json" } }) : await import(fileURL);
|
|
45
|
+
import_main.default.set(values, options.transformKeys ? options.transformKeys(collectionKey) : collectionKey, exportedValue.default ? exportedValue.default : { ...exportedValue });
|
|
66
46
|
}
|
|
67
47
|
async function fsImportAll(location, options) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
48
|
+
options = options || {};
|
|
49
|
+
const collection = {};
|
|
50
|
+
const normalizedLocation = typeof location === "string" ? location : fileURLToPath(location);
|
|
51
|
+
const files = await fsReadAll(normalizedLocation, {
|
|
52
|
+
filter: isScriptFile,
|
|
53
|
+
...options,
|
|
54
|
+
pathType: "url"
|
|
55
|
+
});
|
|
56
|
+
await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options)));
|
|
57
|
+
return collection;
|
|
78
58
|
}
|
|
79
|
-
export {
|
|
80
|
-
fsImportAll,
|
|
81
|
-
fsReadAll
|
|
82
|
-
};
|
|
59
|
+
export { fsImportAll, fsReadAll };
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "../../chunk-YFSCSJNE.js";
|
|
5
|
-
export {
|
|
6
|
-
safeParse,
|
|
7
|
-
safeStringify
|
|
8
|
-
};
|
|
1
|
+
import "../../chunk-BNZ4_A-W.js";
|
|
2
|
+
import { n as safeParse, t as safeStringify } from "../../main-aO4h7ygK.js";
|
|
3
|
+
export { safeParse, safeStringify };
|
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 {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ImportInfo = {
|
|
2
|
+
source: string;
|
|
3
|
+
defaultImport?: string;
|
|
4
|
+
namedImports?: string[];
|
|
5
|
+
typeImports?: string[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* ImportsBag manages and deduplicates imports from the same source
|
|
9
|
+
*/
|
|
10
|
+
export declare class ImportsBag {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Add an import to the bag
|
|
14
|
+
*/
|
|
15
|
+
add(importInfo: ImportInfo): this;
|
|
16
|
+
/**
|
|
17
|
+
* Get deduplicated imports as an array
|
|
18
|
+
*/
|
|
19
|
+
toArray(): ImportInfo[];
|
|
20
|
+
/**
|
|
21
|
+
* Get deduplicated imports as a formatted string
|
|
22
|
+
*/
|
|
23
|
+
toString(): string;
|
|
24
|
+
}
|
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.5",
|
|
4
4
|
"description": "Handy utilities for repetitive work",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"format": "prettier --write .",
|
|
35
35
|
"typecheck": "tsc --noEmit",
|
|
36
36
|
"precompile": "npm run lint",
|
|
37
|
-
"compile": "
|
|
37
|
+
"compile": "tsdown && tsc --emitDeclarationOnly --declaration",
|
|
38
38
|
"build": "npm run compile && npm run build:lodash",
|
|
39
39
|
"version": "npm run build",
|
|
40
40
|
"prepublishOnly": "npm run build",
|
|
@@ -42,36 +42,36 @@
|
|
|
42
42
|
"quick:test": "node --import=@poppinss/ts-exec bin/test.ts"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@adonisjs/eslint-config": "^3.0.0-next.
|
|
46
|
-
"@adonisjs/logger": "^6.0.
|
|
45
|
+
"@adonisjs/eslint-config": "^3.0.0-next.5",
|
|
46
|
+
"@adonisjs/logger": "^6.0.7",
|
|
47
47
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
48
|
-
"@adonisjs/tsconfig": "^2.0.0-next.
|
|
49
|
-
"@japa/assert": "^4.0
|
|
50
|
-
"@japa/expect-type": "^2.0.
|
|
51
|
-
"@japa/runner": "^
|
|
52
|
-
"@poppinss/ts-exec": "^1.4.
|
|
53
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
48
|
+
"@adonisjs/tsconfig": "^2.0.0-next.3",
|
|
49
|
+
"@japa/assert": "^4.2.0",
|
|
50
|
+
"@japa/expect-type": "^2.0.4",
|
|
51
|
+
"@japa/runner": "^5.0.0",
|
|
52
|
+
"@poppinss/ts-exec": "^1.4.1",
|
|
53
|
+
"@release-it/conventional-changelog": "^10.0.4",
|
|
54
54
|
"@types/fs-extra": "^11.0.4",
|
|
55
|
-
"@types/node": "^
|
|
55
|
+
"@types/node": "^25.0.3",
|
|
56
56
|
"c8": "^10.1.3",
|
|
57
|
-
"eslint": "^9.
|
|
58
|
-
"fs-extra": "^11.3.
|
|
57
|
+
"eslint": "^9.39.2",
|
|
58
|
+
"fs-extra": "^11.3.3",
|
|
59
59
|
"lodash": "^4.17.21",
|
|
60
60
|
"lodash-cli": "^4.17.5",
|
|
61
61
|
"move-file-cli": "^3.0.0",
|
|
62
|
-
"prettier": "^3.
|
|
63
|
-
"release-it": "^19.
|
|
64
|
-
"
|
|
65
|
-
"
|
|
62
|
+
"prettier": "^3.7.4",
|
|
63
|
+
"release-it": "^19.2.2",
|
|
64
|
+
"safe-stable-stringify": "^2.5.0",
|
|
65
|
+
"secure-json-parse": "^4.1.0",
|
|
66
|
+
"tsdown": "^0.18.4",
|
|
67
|
+
"typescript": "^5.9.3"
|
|
66
68
|
},
|
|
67
69
|
"dependencies": {
|
|
68
|
-
"@poppinss/exception": "^1.2.
|
|
70
|
+
"@poppinss/exception": "^1.2.3",
|
|
69
71
|
"@poppinss/object-builder": "^1.1.0",
|
|
70
|
-
"@poppinss/string": "^1.
|
|
71
|
-
"@poppinss/types": "^1.1
|
|
72
|
-
"flattie": "^1.1.1"
|
|
73
|
-
"safe-stable-stringify": "^2.5.0",
|
|
74
|
-
"secure-json-parse": "^4.0.0"
|
|
72
|
+
"@poppinss/string": "^1.7.1",
|
|
73
|
+
"@poppinss/types": "^1.2.1",
|
|
74
|
+
"flattie": "^1.1.1"
|
|
75
75
|
},
|
|
76
76
|
"homepage": "https://github.com/poppinss/utils#readme",
|
|
77
77
|
"repository": {
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"access": "public",
|
|
92
92
|
"provenance": true
|
|
93
93
|
},
|
|
94
|
-
"
|
|
94
|
+
"tsdown": {
|
|
95
95
|
"entry": [
|
|
96
96
|
"./index.ts",
|
|
97
97
|
"./modules/fs/main.ts",
|
|
@@ -106,8 +106,11 @@
|
|
|
106
106
|
"outDir": "./build",
|
|
107
107
|
"clean": true,
|
|
108
108
|
"format": "esm",
|
|
109
|
+
"minify": "dce-only",
|
|
110
|
+
"fixedExtension": false,
|
|
109
111
|
"dts": false,
|
|
110
|
-
"
|
|
112
|
+
"treeshake": false,
|
|
113
|
+
"sourcemaps": false,
|
|
111
114
|
"target": "esnext"
|
|
112
115
|
},
|
|
113
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
|
-
};
|