revojs 0.2.5 → 0.2.6

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.
@@ -44,9 +44,11 @@ export interface Command<T extends ParseArgsOptionsConfig = ParseArgsOptionsConf
44
44
  arguments?: T;
45
45
  run: (context: CommandContext<T>) => Awaitable<void>;
46
46
  }
47
+ export type SourceFormat = "object" | "named";
47
48
  export interface Source {
48
49
  match: Array<string>;
49
50
  from: Array<string>;
51
+ format: SourceFormat;
50
52
  }
51
53
  export interface StringVariable {
52
54
  type: "string";
@@ -1,5 +1,5 @@
1
1
  import { mimeType } from "../assets/index.js";
2
- import { mergeObjects } from "../shared/index.js";
2
+ import { mergeObjects, toExportNames } from "../shared/index.js";
3
3
  import package_default from "../package.js";
4
4
  import { findPackageJSON } from "node:module";
5
5
  import { spawnSync } from "child_process";
@@ -115,11 +115,13 @@ async function createConfig(inputConfig) {
115
115
  sources: {
116
116
  plugins: {
117
117
  match: ["**/*.{js,ts}", "!**/*.d.ts"],
118
- from: ["./plugins"]
118
+ from: ["./plugins"],
119
+ format: "object"
119
120
  },
120
121
  commands: {
121
122
  match: ["**/*.{js,ts}", "!**/*.d.ts"],
122
- from: ["./commands", fromModule("../../cli/commands")]
123
+ from: ["./commands", fromModule("../../cli/commands")],
124
+ format: "object"
123
125
  }
124
126
  },
125
127
  templates: {},
@@ -153,21 +155,39 @@ async function core(config) {
153
155
  async config() {
154
156
  for (const [name, source] of Object.entries(config.sources)) {
155
157
  const resolved = resolveSource(source);
156
- addVirtual(config, name, () => {
157
- const cwd = posixPath(resolve("."));
158
- return `export default { ${[...resolved].map(([scope, files]) => {
159
- return `"${scope}": { ${[...files].map(([key, path]) => {
158
+ if (source.format === "named") {
159
+ const entries = new Array();
160
+ for (const files of resolved.values()) for (const entry of files) entries.push(entry);
161
+ const names = toExportNames(entries.map(([key]) => key));
162
+ addVirtual(config, name, () => {
163
+ const cwd = posixPath(resolve("."));
164
+ const lines = entries.map(([, path], index) => {
160
165
  const entry = posixPath(relative(cwd, path));
161
- return `"${key}": () => import("${entry.startsWith(".") ? entry : "./" + entry}").then((module) => module.default)`;
166
+ return `export { default as ${names[index]} } from "${entry.startsWith(".") ? entry : "./" + entry}";`;
167
+ });
168
+ return lines.length > 0 ? lines.join("\n") : "export {};";
169
+ });
170
+ addTypes(config, name, () => {
171
+ const declarations = entries.map(([, path], index) => `export const ${names[index]}: typeof import("${posixPath(path)}").default;`);
172
+ return `declare module "#${name}" { ${declarations.join(" ")} }`;
173
+ });
174
+ } else if (source.format === "object") {
175
+ addVirtual(config, name, () => {
176
+ const cwd = posixPath(resolve("."));
177
+ return `export default { ${[...resolved].map(([scope, files]) => {
178
+ return `"${scope}": { ${[...files].map(([key, path]) => {
179
+ const entry = posixPath(relative(cwd, path));
180
+ return `"${key}": () => import("${entry.startsWith(".") ? entry : "./" + entry}").then((module) => module.default)`;
181
+ }).join(",")} }`;
162
182
  }).join(",")} }`;
163
- }).join(",")} }`;
164
- });
165
- addTypes(config, name, () => {
166
- const scopes = [...resolved].map(([scope, files]) => {
167
- return `"${scope}":{ ${[...files].map(([key, path]) => `"${key}": () => Promise<typeof import("${posixPath(path)}").default>`).join(";")} }`;
168
183
  });
169
- return `declare module "#${name}" { type Entries = { ${scopes.join(";")} }; const entries: Entries; export default entries; }`;
170
- });
184
+ addTypes(config, name, () => {
185
+ const scopes = [...resolved].map(([scope, files]) => {
186
+ return `"${scope}":{ ${[...files].map(([key, path]) => `"${key}": () => Promise<typeof import("${posixPath(path)}").default>`).join(";")} }`;
187
+ });
188
+ return `declare module "#${name}" { type Entries = { ${scopes.join(";")} }; const entries: Entries; export default entries; }`;
189
+ });
190
+ }
171
191
  }
172
192
  addVirtual(config, "variables", (consumer) => {
173
193
  const variables = config.variables[consumer];
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "revojs";
3
- var version = "0.2.5";
3
+ var version = "0.2.6";
4
4
  var repository = {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/tellua/revojs.git"
@@ -33,12 +33,12 @@ var scripts = {
33
33
  };
34
34
  var dependencies = {
35
35
  "@standard-schema/spec": "^1.1.0",
36
- "rolldown": "^1.2.8",
37
- "vite": "^8.3.0"
36
+ "rolldown": "^1.2.12",
37
+ "vite": "^8.3.2"
38
38
  };
39
39
  var devDependencies = {
40
40
  "@revojs/tsconfig": "*",
41
- "@types/node": "^26.4.1"
41
+ "@types/node": "^26.6.4"
42
42
  };
43
43
  var optionalDependencies = { "typescript": "^7.0.2" };
44
44
  var package_default = {
@@ -11,4 +11,5 @@ export interface JSONObject {
11
11
  export type JsonSchema = StandardJSONSchemaV1 | JSONObject;
12
12
  export declare function mergeObjects<TBase, TInput>(base: TBase, input: TInput): TBase & TInput;
13
13
  export declare function toJsonSchema(schema: JsonSchema): JSONObject;
14
+ export declare function toExportNames(keys: Array<string>): string[];
14
15
  export declare const scheduleAliases: Record<string, string>;
@@ -21,6 +21,16 @@ function toJsonSchema(schema) {
21
21
  if (standard?.jsonSchema !== void 0) return standard.jsonSchema.input({ target: "draft-07" });
22
22
  return schema;
23
23
  }
24
+ function toExportNames(keys) {
25
+ const seen = /* @__PURE__ */ new Map();
26
+ return keys.map((key) => {
27
+ const pascalName = key.split("/").flatMap((segment) => segment.split(/[^a-zA-Z0-9]+/)).filter((word) => word.length > 0).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
28
+ const identifier = /^[A-Za-z_$]/.test(pascalName) ? pascalName : `_${pascalName}`;
29
+ const count = seen.get(identifier) ?? 0;
30
+ seen.set(identifier, count + 1);
31
+ return count === 0 ? identifier : `${identifier}${count + 1}`;
32
+ });
33
+ }
24
34
  var scheduleAliases = {
25
35
  "@yearly": "0 0 1 1 *",
26
36
  "@annually": "0 0 1 1 *",
@@ -36,4 +46,4 @@ var DANGEROUS_KEYS = /* @__PURE__ */ new Set([
36
46
  "prototype"
37
47
  ]);
38
48
  //#endregion
39
- export { mergeObjects, scheduleAliases, toJsonSchema };
49
+ export { mergeObjects, scheduleAliases, toExportNames, toJsonSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revojs",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,12 +40,12 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@standard-schema/spec": "^1.1.0",
43
- "rolldown": "^1.2.8",
44
- "vite": "^8.3.0"
43
+ "rolldown": "^1.2.12",
44
+ "vite": "^8.3.2"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@revojs/tsconfig": "*",
48
- "@types/node": "^26.4.1"
48
+ "@types/node": "^26.6.4"
49
49
  },
50
50
  "optionalDependencies": {
51
51
  "typescript": "^7.0.2"