@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.
@@ -1,82 +1,59 @@
1
- import {
2
- isScriptFile,
3
- naturalSort
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 { join, relative, sep } from "path";
9
- import { readdir, stat } from "fs/promises";
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
- const normalizedLocation = typeof location === "string" ? location : fileURLToPath(location);
13
- const normalizedOptions = Object.assign({ absolute: false, sort: naturalSort }, options);
14
- const pathType = normalizedOptions.pathType || "relative";
15
- try {
16
- await stat(normalizedLocation);
17
- } catch (error) {
18
- if (normalizedOptions.ignoreMissingRoot) {
19
- return [];
20
- }
21
- throw error;
22
- }
23
- const dirents = await readdir(normalizedLocation, { recursive: true, withFileTypes: true });
24
- const files = dirents.filter((dirent) => {
25
- if (!dirent.isFile()) {
26
- return false;
27
- }
28
- if (dirent.name.startsWith(".") || dirent.parentPath.split(sep).some((segment) => segment.startsWith("."))) {
29
- return false;
30
- }
31
- return true;
32
- }).map((file) => {
33
- switch (pathType) {
34
- case "relative":
35
- return join(relative(normalizedLocation, file.parentPath), file.name);
36
- case "absolute":
37
- return join(file.parentPath, file.name);
38
- case "unixRelative":
39
- return string.toUnixSlash(join(relative(normalizedLocation, file.parentPath), file.name));
40
- case "unixAbsolute":
41
- return string.toUnixSlash(join(file.parentPath, file.name));
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
- const filePath = fileURLToPath2(fileURL);
58
- const fileExtension = extname(filePath);
59
- const collectionKey = relative2(basePath, filePath).replace(new RegExp(`${fileExtension}$`), "").split(sep2);
60
- const exportedValue = fileExtension === ".json" ? await import(fileURL, { with: { type: "json" } }) : await import(fileURL);
61
- lodash.set(
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
- options = options || {};
69
- const collection = {};
70
- const normalizedLocation = typeof location === "string" ? location : fileURLToPath2(location);
71
- const files = await fsReadAll(normalizedLocation, {
72
- filter: isScriptFile,
73
- ...options,
74
- pathType: "url"
75
- });
76
- await Promise.all(files.map((file) => importFile(normalizedLocation, file, collection, options)));
77
- return collection;
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
- safeParse,
3
- safeStringify
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 };
@@ -1,6 +1,3 @@
1
- // modules/string/main.ts
2
1
  import string from "@poppinss/string";
3
2
  var main_default = string;
4
- export {
5
- main_default as default
6
- };
3
+ export { main_default as default };
@@ -1,6 +1,3 @@
1
- // modules/string/string_builder.ts
2
1
  import StringBuilder from "@poppinss/string/builder";
3
2
  var string_builder_default = StringBuilder;
4
- export {
5
- string_builder_default as default
6
- };
3
+ export { string_builder_default as default };
@@ -1,2 +1,2 @@
1
- // modules/types.ts
2
1
  export * from "@poppinss/types";
2
+ export {};
@@ -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",
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": "tsup-node && tsc --emitDeclarationOnly --declaration",
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.0",
46
- "@adonisjs/logger": "^6.0.6",
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.0",
49
- "@japa/assert": "^4.0.1",
50
- "@japa/expect-type": "^2.0.3",
51
- "@japa/runner": "^4.2.0",
52
- "@poppinss/ts-exec": "^1.4.0",
53
- "@release-it/conventional-changelog": "^10.0.1",
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": "^24.0.3",
55
+ "@types/node": "^25.0.3",
56
56
  "c8": "^10.1.3",
57
- "eslint": "^9.29.0",
58
- "fs-extra": "^11.3.0",
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.5.3",
63
- "release-it": "^19.0.3",
64
- "tsup": "^8.5.0",
65
- "typescript": "^5.8.3"
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.1",
70
+ "@poppinss/exception": "^1.2.3",
69
71
  "@poppinss/object-builder": "^1.1.0",
70
- "@poppinss/string": "^1.6.0",
71
- "@poppinss/types": "^1.1.0",
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
- "tsup": {
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
- "sourcemap": false,
112
+ "treeshake": false,
113
+ "sourcemaps": false,
111
114
  "target": "esnext"
112
115
  },
113
116
  "release-it": {
@@ -1,14 +0,0 @@
1
- // modules/exception.ts
2
- import {
3
- RuntimeException,
4
- InvalidArgumentsException,
5
- Exception,
6
- createError
7
- } from "@poppinss/exception";
8
-
9
- export {
10
- RuntimeException,
11
- InvalidArgumentsException,
12
- Exception,
13
- createError
14
- };
@@ -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
- };
@@ -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
- };