pluggable-codegen 0.4.0 → 0.5.1
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 +2 -2
- package/dist/_virtual/_rolldown/runtime.cjs +2 -4
- package/dist/_virtual/_rolldown/runtime.mjs +2 -3
- package/dist/cache.cjs +10 -7
- package/dist/cache.mjs +9 -5
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +6 -5
- package/dist/codegen.cjs +30 -54
- package/dist/codegen.d.cts +10 -0
- package/dist/codegen.d.mts +4 -8
- package/dist/codegen.mjs +25 -49
- package/dist/file.cjs +1 -3
- package/dist/file.d.cts +9 -0
- package/dist/file.d.mts +2 -5
- package/dist/file.mjs +1 -2
- package/dist/index.cjs +7 -5
- package/dist/index.d.cts +7 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +2 -1
- package/dist/options.cjs +8 -8
- package/dist/options.mjs +7 -6
- package/dist/plugin.cjs +2 -3
- package/dist/plugin.d.cts +9 -0
- package/dist/plugin.d.mts +4 -8
- package/dist/plugin.mjs +1 -2
- package/dist/postprocessors/eslint.cjs +20 -0
- package/dist/postprocessors/eslint.d.cts +8 -0
- package/dist/postprocessors/eslint.d.mts +8 -0
- package/dist/postprocessors/eslint.mjs +20 -0
- package/dist/postprocessors/index.cjs +12 -0
- package/dist/postprocessors/index.d.cts +7 -0
- package/dist/postprocessors/index.d.mts +7 -0
- package/dist/postprocessors/index.mjs +12 -0
- package/dist/postprocessors/oxfmt.cjs +34 -0
- package/dist/postprocessors/oxfmt.d.cts +9 -0
- package/dist/postprocessors/oxfmt.d.mts +9 -0
- package/dist/postprocessors/oxfmt.mjs +34 -0
- package/dist/postprocessors/prettier.cjs +15 -0
- package/dist/postprocessors/prettier.d.cts +7 -0
- package/dist/postprocessors/prettier.d.mts +7 -0
- package/dist/postprocessors/prettier.mjs +15 -0
- package/dist/postprocessors/types.d.cts +9 -0
- package/dist/postprocessors/types.d.mts +9 -0
- package/dist/presets/graphql-codegen.cjs +2 -4
- package/dist/presets/graphql-codegen.d.cts +6 -0
- package/dist/presets/graphql-codegen.d.mts +2 -6
- package/dist/presets/graphql-codegen.mjs +2 -3
- package/dist/types.cjs +1 -3
- package/dist/types.d.cts +24 -0
- package/dist/types.d.mts +11 -23
- package/dist/types.mjs +1 -2
- package/dist/utils.cjs +1 -3
- package/dist/utils.mjs +1 -2
- package/package.json +53 -42
- package/dist/oxfmt.cjs +0 -24
- package/dist/oxfmt.mjs +0 -23
package/dist/plugin.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const require_codegen = require(
|
|
1
|
+
const require_codegen = require("./codegen.cjs");
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/plugin.ts
|
|
4
4
|
function codegen(jobOrOptions, ...moreJobs) {
|
|
5
5
|
const init = require_codegen.Codegen.init(jobOrOptions, ...moreJobs);
|
|
6
6
|
return {
|
|
@@ -14,5 +14,4 @@ function codegen(jobOrOptions, ...moreJobs) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
//#endregion
|
|
18
17
|
exports.codegen = codegen;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CodegenInput, CodegenOptions } from "./types.cjs";
|
|
2
|
+
export type Plugin = {
|
|
3
|
+
name: string;
|
|
4
|
+
buildStart(): Promise<void>;
|
|
5
|
+
watchChange(id: string): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare function codegen(...jobs: CodegenInput[]): Plugin;
|
|
8
|
+
export declare function codegen(options: CodegenOptions, ...jobs: CodegenInput[]): Plugin;
|
|
9
|
+
export declare function codegen(jobOrOptions: CodegenInput | CodegenOptions, ...moreJobs: CodegenInput[]): Plugin;
|
package/dist/plugin.d.mts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { CodegenInput, CodegenOptions } from "./types.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/plugin.d.ts
|
|
4
|
-
type Plugin = {
|
|
2
|
+
export type Plugin = {
|
|
5
3
|
name: string;
|
|
6
4
|
buildStart(): Promise<void>;
|
|
7
5
|
watchChange(id: string): Promise<void>;
|
|
8
6
|
};
|
|
9
|
-
declare function codegen(...jobs: CodegenInput[]): Plugin;
|
|
10
|
-
declare function codegen(options: CodegenOptions, ...jobs: CodegenInput[]): Plugin;
|
|
11
|
-
declare function codegen(jobOrOptions: CodegenInput | CodegenOptions, ...moreJobs: CodegenInput[]): Plugin;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { Plugin, codegen };
|
|
7
|
+
export declare function codegen(...jobs: CodegenInput[]): Plugin;
|
|
8
|
+
export declare function codegen(options: CodegenOptions, ...jobs: CodegenInput[]): Plugin;
|
|
9
|
+
export declare function codegen(jobOrOptions: CodegenInput | CodegenOptions, ...moreJobs: CodegenInput[]): Plugin;
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Codegen } from "./codegen.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/plugin.ts
|
|
4
4
|
function codegen(jobOrOptions, ...moreJobs) {
|
|
5
5
|
const init = Codegen.init(jobOrOptions, ...moreJobs);
|
|
6
6
|
return {
|
|
@@ -14,5 +14,4 @@ function codegen(jobOrOptions, ...moreJobs) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
//#endregion
|
|
18
17
|
export { codegen };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/postprocessors/eslint.ts
|
|
2
|
+
var ESLint = class {
|
|
3
|
+
id = "eslint";
|
|
4
|
+
packageName = "eslint";
|
|
5
|
+
conflicts = [];
|
|
6
|
+
#linter;
|
|
7
|
+
async apply(source, path) {
|
|
8
|
+
const [result] = await (await this.#getLinter()).lintText(source, { filePath: path });
|
|
9
|
+
return result?.output ?? source;
|
|
10
|
+
}
|
|
11
|
+
#getLinter() {
|
|
12
|
+
return this.#linter ??= this.#loadLinter();
|
|
13
|
+
}
|
|
14
|
+
async #loadLinter() {
|
|
15
|
+
const { ESLint: Linter } = await import("eslint");
|
|
16
|
+
return new Linter({ fix: true });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.ESLint = ESLint;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/postprocessors/eslint.ts
|
|
2
|
+
var ESLint = class {
|
|
3
|
+
id = "eslint";
|
|
4
|
+
packageName = "eslint";
|
|
5
|
+
conflicts = [];
|
|
6
|
+
#linter;
|
|
7
|
+
async apply(source, path) {
|
|
8
|
+
const [result] = await (await this.#getLinter()).lintText(source, { filePath: path });
|
|
9
|
+
return result?.output ?? source;
|
|
10
|
+
}
|
|
11
|
+
#getLinter() {
|
|
12
|
+
return this.#linter ??= this.#loadLinter();
|
|
13
|
+
}
|
|
14
|
+
async #loadLinter() {
|
|
15
|
+
const { ESLint: Linter } = await import("eslint");
|
|
16
|
+
return new Linter({ fix: true });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { ESLint };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_eslint = require("./eslint.cjs");
|
|
2
|
+
const require_oxfmt = require("./oxfmt.cjs");
|
|
3
|
+
const require_prettier = require("./prettier.cjs");
|
|
4
|
+
|
|
5
|
+
// src/postprocessors/index.ts
|
|
6
|
+
const postprocessors = [
|
|
7
|
+
new require_oxfmt.Oxfmt(),
|
|
8
|
+
new require_eslint.ESLint(),
|
|
9
|
+
new require_prettier.Prettier()
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
exports.postprocessors = postprocessors;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Postprocessor, PostprocessorId } from "./types.cjs";
|
|
2
|
+
import { ESLint } from "./eslint.cjs";
|
|
3
|
+
import { Oxfmt } from "./oxfmt.cjs";
|
|
4
|
+
import { Prettier } from "./prettier.cjs";
|
|
5
|
+
export declare const postprocessors: [Oxfmt, ESLint, Prettier];
|
|
6
|
+
export type PostprocessorOptions = Record<PostprocessorId<(typeof postprocessors)[number]>, boolean>;
|
|
7
|
+
export type { Postprocessor, PostprocessorId };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Postprocessor, PostprocessorId } from "./types.mjs";
|
|
2
|
+
import { ESLint } from "./eslint.mjs";
|
|
3
|
+
import { Oxfmt } from "./oxfmt.mjs";
|
|
4
|
+
import { Prettier } from "./prettier.mjs";
|
|
5
|
+
export declare const postprocessors: [Oxfmt, ESLint, Prettier];
|
|
6
|
+
export type PostprocessorOptions = Record<PostprocessorId<(typeof postprocessors)[number]>, boolean>;
|
|
7
|
+
export type { Postprocessor, PostprocessorId };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ESLint } from "./eslint.mjs";
|
|
2
|
+
import { Oxfmt } from "./oxfmt.mjs";
|
|
3
|
+
import { Prettier } from "./prettier.mjs";
|
|
4
|
+
|
|
5
|
+
// src/postprocessors/index.ts
|
|
6
|
+
const postprocessors = [
|
|
7
|
+
new Oxfmt(),
|
|
8
|
+
new ESLint(),
|
|
9
|
+
new Prettier()
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export { postprocessors };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const require_utils = require("../utils.cjs");
|
|
2
|
+
let node_fs_promises = require("node:fs/promises");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
|
|
5
|
+
// src/postprocessors/oxfmt.ts
|
|
6
|
+
const candidates = [".oxfmtrc.json"];
|
|
7
|
+
var Oxfmt = class {
|
|
8
|
+
id = "oxfmt";
|
|
9
|
+
packageName = "oxfmt";
|
|
10
|
+
conflicts = ["eslint", "prettier"];
|
|
11
|
+
cache = /* @__PURE__ */ new Map();
|
|
12
|
+
async apply(source, path) {
|
|
13
|
+
const { format } = await import("oxfmt");
|
|
14
|
+
const { code, errors } = await format(path, source, await this.#resolveConfig(path));
|
|
15
|
+
const firstError = errors.filter((e) => e.severity === "Error").pop();
|
|
16
|
+
if (firstError) throw new Error(firstError.message);
|
|
17
|
+
return code;
|
|
18
|
+
}
|
|
19
|
+
async #resolveConfig(from) {
|
|
20
|
+
const dir = (0, node_path.dirname)(from);
|
|
21
|
+
const cached = this.cache.get(dir);
|
|
22
|
+
if (cached) return cached;
|
|
23
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
24
|
+
this.cache.set(dir, promise);
|
|
25
|
+
resolve(await require_utils.lookupPath(dir, candidates, this.#loadConfig));
|
|
26
|
+
return promise;
|
|
27
|
+
}
|
|
28
|
+
#loadConfig = async (file) => {
|
|
29
|
+
const contents = await (0, node_fs_promises.readFile)(file, "utf-8");
|
|
30
|
+
return JSON.parse(contents);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.Oxfmt = Oxfmt;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Postprocessor } from "./types.cjs";
|
|
2
|
+
export declare class Oxfmt implements Postprocessor {
|
|
3
|
+
#private;
|
|
4
|
+
readonly id = "oxfmt";
|
|
5
|
+
readonly packageName = "oxfmt";
|
|
6
|
+
readonly conflicts: string[];
|
|
7
|
+
private cache;
|
|
8
|
+
apply(source: string, path: string): Promise<string>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Postprocessor } from "./types.mjs";
|
|
2
|
+
export declare class Oxfmt implements Postprocessor {
|
|
3
|
+
#private;
|
|
4
|
+
readonly id = "oxfmt";
|
|
5
|
+
readonly packageName = "oxfmt";
|
|
6
|
+
readonly conflicts: string[];
|
|
7
|
+
private cache;
|
|
8
|
+
apply(source: string, path: string): Promise<string>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { lookupPath } from "../utils.mjs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/postprocessors/oxfmt.ts
|
|
6
|
+
const candidates = [".oxfmtrc.json"];
|
|
7
|
+
var Oxfmt = class {
|
|
8
|
+
id = "oxfmt";
|
|
9
|
+
packageName = "oxfmt";
|
|
10
|
+
conflicts = ["eslint", "prettier"];
|
|
11
|
+
cache = /* @__PURE__ */ new Map();
|
|
12
|
+
async apply(source, path) {
|
|
13
|
+
const { format } = await import("oxfmt");
|
|
14
|
+
const { code, errors } = await format(path, source, await this.#resolveConfig(path));
|
|
15
|
+
const firstError = errors.filter((e) => e.severity === "Error").pop();
|
|
16
|
+
if (firstError) throw new Error(firstError.message);
|
|
17
|
+
return code;
|
|
18
|
+
}
|
|
19
|
+
async #resolveConfig(from) {
|
|
20
|
+
const dir = dirname(from);
|
|
21
|
+
const cached = this.cache.get(dir);
|
|
22
|
+
if (cached) return cached;
|
|
23
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
24
|
+
this.cache.set(dir, promise);
|
|
25
|
+
resolve(await lookupPath(dir, candidates, this.#loadConfig));
|
|
26
|
+
return promise;
|
|
27
|
+
}
|
|
28
|
+
#loadConfig = async (file) => {
|
|
29
|
+
const contents = await readFile(file, "utf-8");
|
|
30
|
+
return JSON.parse(contents);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { Oxfmt };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/postprocessors/prettier.ts
|
|
2
|
+
var Prettier = class {
|
|
3
|
+
id = "prettier";
|
|
4
|
+
packageName = "prettier";
|
|
5
|
+
conflicts = [];
|
|
6
|
+
async apply(source, path) {
|
|
7
|
+
const { resolveConfig, format } = await import("prettier");
|
|
8
|
+
return format(source, {
|
|
9
|
+
...await resolveConfig(path) ?? {},
|
|
10
|
+
filepath: path
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.Prettier = Prettier;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/postprocessors/prettier.ts
|
|
2
|
+
var Prettier = class {
|
|
3
|
+
id = "prettier";
|
|
4
|
+
packageName = "prettier";
|
|
5
|
+
conflicts = [];
|
|
6
|
+
async apply(source, path) {
|
|
7
|
+
const { resolveConfig, format } = await import("prettier");
|
|
8
|
+
return format(source, {
|
|
9
|
+
...await resolveConfig(path) ?? {},
|
|
10
|
+
filepath: path
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { Prettier };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Postprocessor {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly packageName: string;
|
|
4
|
+
readonly conflicts: string[];
|
|
5
|
+
apply(source: string, path: string): Promise<string> | string;
|
|
6
|
+
}
|
|
7
|
+
export type PostprocessorId<P extends Postprocessor> = P extends {
|
|
8
|
+
id: infer Id;
|
|
9
|
+
} ? Id : never;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Postprocessor {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly packageName: string;
|
|
4
|
+
readonly conflicts: string[];
|
|
5
|
+
apply(source: string, path: string): Promise<string> | string;
|
|
6
|
+
}
|
|
7
|
+
export type PostprocessorId<P extends Postprocessor> = P extends {
|
|
8
|
+
id: infer Id;
|
|
9
|
+
} ? Id : never;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
let _graphql_codegen_cli = require("@graphql-codegen/cli");
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
// src/presets/graphql-codegen.ts
|
|
6
5
|
function graphqlCodegen(options = {}) {
|
|
7
6
|
return async () => {
|
|
8
7
|
const context = await (0, _graphql_codegen_cli.createContext)({
|
|
@@ -23,7 +22,7 @@ function graphqlCodegen(options = {}) {
|
|
|
23
22
|
input: [...normalizeDocuments(config.documents), ...Array.isArray(options) ? [] : normalizeDocuments(options.documents)],
|
|
24
23
|
output,
|
|
25
24
|
cacheBy: "contents",
|
|
26
|
-
extraDeps: [context.filepath],
|
|
25
|
+
extraDeps: context.filepath?.length ? [context.filepath] : [],
|
|
27
26
|
generate: async (files) => {
|
|
28
27
|
const [generatedFile] = await (0, _graphql_codegen_cli.generate)({
|
|
29
28
|
...config,
|
|
@@ -46,5 +45,4 @@ function normalizeDocuments(documents) {
|
|
|
46
45
|
return documents;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
//#endregion
|
|
50
48
|
exports.graphqlCodegen = graphqlCodegen;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { CodegenJob } from "../types.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/presets/graphql-codegen.d.ts
|
|
4
|
-
type GraphqlCodegenOptions = {
|
|
2
|
+
export type GraphqlCodegenOptions = {
|
|
5
3
|
config?: string;
|
|
6
4
|
project?: string;
|
|
7
5
|
};
|
|
8
|
-
declare function graphqlCodegen(options?: GraphqlCodegenOptions): () => Promise<CodegenJob[]>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { GraphqlCodegenOptions, graphqlCodegen };
|
|
6
|
+
export declare function graphqlCodegen(options?: GraphqlCodegenOptions): () => Promise<CodegenJob[]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, generate } from "@graphql-codegen/cli";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/presets/graphql-codegen.ts
|
|
4
4
|
function graphqlCodegen(options = {}) {
|
|
5
5
|
return async () => {
|
|
6
6
|
const context = await createContext({
|
|
@@ -21,7 +21,7 @@ function graphqlCodegen(options = {}) {
|
|
|
21
21
|
input: [...normalizeDocuments(config.documents), ...Array.isArray(options) ? [] : normalizeDocuments(options.documents)],
|
|
22
22
|
output,
|
|
23
23
|
cacheBy: "contents",
|
|
24
|
-
extraDeps: [context.filepath],
|
|
24
|
+
extraDeps: context.filepath?.length ? [context.filepath] : [],
|
|
25
25
|
generate: async (files) => {
|
|
26
26
|
const [generatedFile] = await generate({
|
|
27
27
|
...config,
|
|
@@ -44,5 +44,4 @@ function normalizeDocuments(documents) {
|
|
|
44
44
|
return documents;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//#endregion
|
|
48
47
|
export { graphqlCodegen };
|
package/dist/types.cjs
CHANGED
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { File } from "./file.cjs";
|
|
2
|
+
import { PostprocessorOptions } from "./postprocessors/index.cjs";
|
|
3
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
4
|
+
export type CodegenOptions = Partial<PostprocessorOptions> & {
|
|
5
|
+
rootDir?: string;
|
|
6
|
+
cacheFile?: string | false;
|
|
7
|
+
};
|
|
8
|
+
export type NormalizedCodegenOptions = PostprocessorOptions & {
|
|
9
|
+
rootDir: string;
|
|
10
|
+
cacheFile?: string;
|
|
11
|
+
};
|
|
12
|
+
export type CodegenJob = Partial<PostprocessorOptions> & {
|
|
13
|
+
input: string | string[];
|
|
14
|
+
output: string;
|
|
15
|
+
generate: (files: File[], signal: AbortSignal) => MaybePromise<Buffer | string | null>;
|
|
16
|
+
cacheBy?: 'files' | 'contents';
|
|
17
|
+
extraDeps?: string[];
|
|
18
|
+
};
|
|
19
|
+
export type CodegenJobGenerator = (rootDir: string) => MaybePromise<CodegenJob[] | CodegenJob>;
|
|
20
|
+
export type CodegenInput = CodegenJobGenerator | CodegenJob;
|
|
21
|
+
export type CodegenPresetOptions = Omit<CodegenJob, 'input' | 'output' | 'generate'>;
|
|
22
|
+
export declare function defineCodegen(job: CodegenInput, ...jobs: CodegenInput[]): [CodegenInput, ...CodegenInput[]];
|
|
23
|
+
export declare function defineCodegen(options: CodegenOptions, ...jobs: CodegenInput[]): [CodegenOptions, ...CodegenInput[]];
|
|
24
|
+
export declare function defineCodegen(optionsOrJob: CodegenOptions | CodegenInput, ...jobs: CodegenInput[]): [CodegenOptions | CodegenInput, ...CodegenInput[]];
|
package/dist/types.d.mts
CHANGED
|
@@ -1,36 +1,24 @@
|
|
|
1
1
|
import { File } from "./file.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type CodegenOptions = {
|
|
2
|
+
import { PostprocessorOptions } from "./postprocessors/index.mjs";
|
|
3
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
4
|
+
export type CodegenOptions = Partial<PostprocessorOptions> & {
|
|
6
5
|
rootDir?: string;
|
|
7
6
|
cacheFile?: string | false;
|
|
8
|
-
oxfmt?: boolean;
|
|
9
|
-
prettier?: boolean;
|
|
10
|
-
eslint?: boolean;
|
|
11
7
|
};
|
|
12
|
-
type NormalizedCodegenOptions = {
|
|
8
|
+
export type NormalizedCodegenOptions = PostprocessorOptions & {
|
|
13
9
|
rootDir: string;
|
|
14
10
|
cacheFile?: string;
|
|
15
|
-
oxfmt: boolean;
|
|
16
|
-
prettier: boolean;
|
|
17
|
-
eslint: boolean;
|
|
18
11
|
};
|
|
19
|
-
type CodegenJob = {
|
|
12
|
+
export type CodegenJob = Partial<PostprocessorOptions> & {
|
|
20
13
|
input: string | string[];
|
|
21
14
|
output: string;
|
|
22
15
|
generate: (files: File[], signal: AbortSignal) => MaybePromise<Buffer | string | null>;
|
|
23
16
|
cacheBy?: 'files' | 'contents';
|
|
24
17
|
extraDeps?: string[];
|
|
25
|
-
oxfmt?: boolean;
|
|
26
|
-
prettier?: boolean;
|
|
27
|
-
eslint?: boolean;
|
|
28
18
|
};
|
|
29
|
-
type CodegenJobGenerator = (rootDir: string) => MaybePromise<CodegenJob[] | CodegenJob>;
|
|
30
|
-
type CodegenInput = CodegenJobGenerator | CodegenJob;
|
|
31
|
-
type CodegenPresetOptions = Omit<CodegenJob, 'input' | 'output' | 'generate'>;
|
|
32
|
-
declare function defineCodegen(job: CodegenInput, ...jobs: CodegenInput[]): [CodegenInput, ...CodegenInput[]];
|
|
33
|
-
declare function defineCodegen(options: CodegenOptions, ...jobs: CodegenInput[]): [CodegenOptions, ...CodegenInput[]];
|
|
34
|
-
declare function defineCodegen(optionsOrJob: CodegenOptions | CodegenInput, ...jobs: CodegenInput[]): [CodegenOptions | CodegenInput, ...CodegenInput[]];
|
|
35
|
-
//#endregion
|
|
36
|
-
export { CodegenInput, CodegenJob, CodegenJobGenerator, CodegenOptions, CodegenPresetOptions, NormalizedCodegenOptions, defineCodegen };
|
|
19
|
+
export type CodegenJobGenerator = (rootDir: string) => MaybePromise<CodegenJob[] | CodegenJob>;
|
|
20
|
+
export type CodegenInput = CodegenJobGenerator | CodegenJob;
|
|
21
|
+
export type CodegenPresetOptions = Omit<CodegenJob, 'input' | 'output' | 'generate'>;
|
|
22
|
+
export declare function defineCodegen(job: CodegenInput, ...jobs: CodegenInput[]): [CodegenInput, ...CodegenInput[]];
|
|
23
|
+
export declare function defineCodegen(options: CodegenOptions, ...jobs: CodegenInput[]): [CodegenOptions, ...CodegenInput[]];
|
|
24
|
+
export declare function defineCodegen(optionsOrJob: CodegenOptions | CodegenInput, ...jobs: CodegenInput[]): [CodegenOptions | CodegenInput, ...CodegenInput[]];
|
package/dist/types.mjs
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
1
|
let node_path = require("node:path");
|
|
3
2
|
let node_crypto = require("node:crypto");
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
// src/utils.ts
|
|
6
5
|
async function lookupPath(dir, candidates, check) {
|
|
7
6
|
if (!Array.isArray(candidates)) candidates = [candidates];
|
|
8
7
|
do
|
|
@@ -26,6 +25,5 @@ function hash(data) {
|
|
|
26
25
|
return hash.digest("hex");
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
//#endregion
|
|
30
28
|
exports.hash = hash;
|
|
31
29
|
exports.lookupPath = lookupPath;
|
package/dist/utils.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dirname, resolve } from "node:path";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/utils.ts
|
|
5
5
|
async function lookupPath(dir, candidates, check) {
|
|
6
6
|
if (!Array.isArray(candidates)) candidates = [candidates];
|
|
7
7
|
do
|
|
@@ -25,5 +25,4 @@ function hash(data) {
|
|
|
25
25
|
return hash.digest("hex");
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
//#endregion
|
|
29
28
|
export { hash, lookupPath };
|