pluggable-codegen 0.5.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.
@@ -0,0 +1,10 @@
1
+ import { CodegenInput, CodegenOptions } from "./types.cjs";
2
+ export declare class Codegen {
3
+ #private;
4
+ static init(...jobs: CodegenInput[]): Promise<Codegen>;
5
+ static init(options: CodegenOptions, ...jobs: CodegenInput[]): Promise<Codegen>;
6
+ static init(jobOrOptions: CodegenInput | CodegenOptions, ...moreJobs: CodegenInput[]): Promise<Codegen>;
7
+ private constructor();
8
+ generateAll(): Promise<boolean>;
9
+ generateMatching(path: string): Promise<boolean>;
10
+ }
@@ -0,0 +1,9 @@
1
+ export declare class File {
2
+ #private;
3
+ readonly fullPath: string;
4
+ readonly localPath: string;
5
+ constructor(path: string, rootDir: string);
6
+ buffer(): Promise<Buffer>;
7
+ text(encoding?: BufferEncoding): Promise<string>;
8
+ json(): Promise<any>;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { File } from "./file.cjs";
2
+ import { Postprocessor, PostprocessorId } from "./postprocessors/types.cjs";
3
+ import { PostprocessorOptions, postprocessors } from "./postprocessors/index.cjs";
4
+ import { CodegenInput, CodegenJob, CodegenJobGenerator, CodegenOptions, CodegenPresetOptions, MaybePromise, NormalizedCodegenOptions, defineCodegen } from "./types.cjs";
5
+ import { Codegen } from "./codegen.cjs";
6
+ import { Plugin, codegen } from "./plugin.cjs";
7
+ export { Codegen, CodegenInput, CodegenJob, CodegenJobGenerator, CodegenOptions, CodegenPresetOptions, File, MaybePromise, NormalizedCodegenOptions, Plugin, type Postprocessor, type PostprocessorId, PostprocessorOptions, codegen, defineCodegen, postprocessors };
@@ -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;
@@ -0,0 +1,8 @@
1
+ import { Postprocessor } from "./types.cjs";
2
+ export declare class ESLint implements Postprocessor {
3
+ #private;
4
+ readonly id = "eslint";
5
+ readonly packageName = "eslint";
6
+ readonly conflicts: never[];
7
+ apply(source: string, path: string): Promise<string>;
8
+ }
@@ -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,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,7 @@
1
+ import { Postprocessor } from "./types.cjs";
2
+ export declare class Prettier implements Postprocessor {
3
+ readonly id = "prettier";
4
+ readonly packageName = "prettier";
5
+ readonly conflicts: never[];
6
+ apply(source: string, path: string): Promise<string>;
7
+ }
@@ -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,6 @@
1
+ import { CodegenJob } from "../types.cjs";
2
+ export type GraphqlCodegenOptions = {
3
+ config?: string;
4
+ project?: string;
5
+ };
6
+ export declare function graphqlCodegen(options?: GraphqlCodegenOptions): () => Promise<CodegenJob[]>;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pluggable-codegen",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "homepage": "https://github.com/jahudka/pluggable-codegen",
5
5
  "bugs": {
6
6
  "url": "https://github.com/jahudka/pluggable-codegen/issues"
@@ -24,19 +24,30 @@
24
24
  "dist"
25
25
  ],
26
26
  "type": "module",
27
+ "sideEffects": false,
27
28
  "main": "./dist/index.cjs",
28
29
  "module": "./dist/index.mjs",
29
- "types": "./dist/index.d.ts",
30
+ "types": "./dist/index.d.mts",
30
31
  "exports": {
31
32
  ".": {
32
- "types": "./dist/index.d.ts",
33
- "require": "./dist/index.cjs",
34
- "import": "./dist/index.mjs"
33
+ "types": {
34
+ "require": "./dist/index.d.cts",
35
+ "import": "./dist/index.d.mts"
36
+ },
37
+ "default": {
38
+ "require": "./dist/index.cjs",
39
+ "import": "./dist/index.mjs"
40
+ }
35
41
  },
36
42
  "./presets/*": {
37
- "types": "./dist/presets/*.d.ts",
38
- "require": "./dist/presets/*.cjs",
39
- "import": "./dist/presets/*.mjs"
43
+ "types": {
44
+ "require": "./dist/presets/*.d.cts",
45
+ "import": "./dist/presets/*.d.mts"
46
+ },
47
+ "default": {
48
+ "require": "./dist/presets/*.cjs",
49
+ "import": "./dist/presets/*.mjs"
50
+ }
40
51
  }
41
52
  },
42
53
  "dependencies": {
@@ -51,6 +62,7 @@
51
62
  "oxfmt": "^0.75.0",
52
63
  "oxlint": "^1.90.0",
53
64
  "prettier": "^3.9.10",
65
+ "publint": "^0.3.25",
54
66
  "tsdown": "^0.23.2",
55
67
  "typescript": "^6.0.3",
56
68
  "yaml": "^2.9.1"
@@ -67,6 +79,9 @@
67
79
  "optional": true
68
80
  }
69
81
  },
82
+ "engines": {
83
+ "node": ">=24"
84
+ },
70
85
  "scripts": {
71
86
  "clean": "rm -rf dist",
72
87
  "oxlint": "oxlint",
@@ -75,6 +90,7 @@
75
90
  "oxfmt:fix": "oxfmt --write",
76
91
  "lint": "pnpm run '/^(oxlint|oxfmt)$/'",
77
92
  "format": "pnpm run --sequential '/^(oxlint|oxfmt):fix$/'",
78
- "build": "tsc && tsdown"
93
+ "build": "tsc && tsdown",
94
+ "publint": "publint"
79
95
  }
80
96
  }