pluggable-codegen 0.4.0 → 0.5.0

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.
Files changed (45) hide show
  1. package/README.md +2 -2
  2. package/dist/_virtual/_rolldown/runtime.cjs +2 -4
  3. package/dist/_virtual/_rolldown/runtime.mjs +2 -3
  4. package/dist/cache.cjs +10 -7
  5. package/dist/cache.mjs +9 -5
  6. package/dist/cli.d.mts +1 -1
  7. package/dist/cli.mjs +6 -5
  8. package/dist/codegen.cjs +30 -54
  9. package/dist/codegen.d.mts +4 -8
  10. package/dist/codegen.mjs +25 -49
  11. package/dist/file.cjs +1 -3
  12. package/dist/file.d.mts +2 -5
  13. package/dist/file.mjs +1 -2
  14. package/dist/index.cjs +7 -5
  15. package/dist/index.d.mts +4 -2
  16. package/dist/index.mjs +2 -1
  17. package/dist/options.cjs +8 -8
  18. package/dist/options.mjs +7 -6
  19. package/dist/plugin.cjs +2 -3
  20. package/dist/plugin.d.mts +4 -8
  21. package/dist/plugin.mjs +1 -2
  22. package/dist/postprocessors/eslint.cjs +20 -0
  23. package/dist/postprocessors/eslint.d.mts +8 -0
  24. package/dist/postprocessors/eslint.mjs +20 -0
  25. package/dist/postprocessors/index.cjs +12 -0
  26. package/dist/postprocessors/index.d.mts +7 -0
  27. package/dist/postprocessors/index.mjs +12 -0
  28. package/dist/postprocessors/oxfmt.cjs +34 -0
  29. package/dist/postprocessors/oxfmt.d.mts +9 -0
  30. package/dist/postprocessors/oxfmt.mjs +34 -0
  31. package/dist/postprocessors/prettier.cjs +15 -0
  32. package/dist/postprocessors/prettier.d.mts +7 -0
  33. package/dist/postprocessors/prettier.mjs +15 -0
  34. package/dist/postprocessors/types.d.mts +9 -0
  35. package/dist/presets/graphql-codegen.cjs +2 -4
  36. package/dist/presets/graphql-codegen.d.mts +2 -6
  37. package/dist/presets/graphql-codegen.mjs +2 -3
  38. package/dist/types.cjs +1 -3
  39. package/dist/types.d.mts +11 -23
  40. package/dist/types.mjs +1 -2
  41. package/dist/utils.cjs +1 -3
  42. package/dist/utils.mjs +1 -2
  43. package/package.json +31 -36
  44. package/dist/oxfmt.cjs +0 -24
  45. package/dist/oxfmt.mjs +0 -23
package/README.md CHANGED
@@ -82,9 +82,9 @@ Within a bundler config, such as `vite.config.ts`, you would just use
82
82
  the `codegen()` plugin instead of the `defineCodegen()` typing helper:
83
83
 
84
84
  ```typescript
85
+ import { codegen } from 'pluggable-codegen';
85
86
  // vite.config.ts
86
87
  import { defineConfig } from 'vite';
87
- import { codegen } from 'pluggable-codegen';
88
88
 
89
89
  export default defineConfig({
90
90
  plugins: [
@@ -100,8 +100,8 @@ and before `svelte-check`:
100
100
  ```typescript
101
101
  // vite.config.ts
102
102
 
103
- import { defineConfig } from 'vite';
104
103
  import { codegen } from 'pluggable-codegen';
104
+ import { defineConfig } from 'vite';
105
105
  import codegenConfig from './codegen.config';
106
106
 
107
107
  export default defineConfig({
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ // \0rolldown/runtime.js
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -19,11 +19,9 @@ var __copyProps = (to, from, except, desc) => {
19
19
  }
20
20
  return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
23
23
  value: mod,
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
 
27
- //#endregion
28
-
29
27
  exports.__toESM = __toESM;
@@ -1,7 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
 
3
- //#region \0rolldown/runtime.js
4
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+ // \0rolldown/runtime.js
4
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
5
5
 
6
- //#endregion
7
6
  export { __require };
package/dist/cache.cjs CHANGED
@@ -1,15 +1,14 @@
1
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
- const require_utils = require('./utils.cjs');
1
+ const require_utils = require("./utils.cjs");
3
2
  let node_fs_promises = require("node:fs/promises");
4
3
  let node_path = require("node:path");
5
4
  let node_crypto = require("node:crypto");
6
5
 
7
- //#region src/cache.ts
6
+ // src/cache.ts
8
7
  var Cache = class {
9
8
  #rootDir;
10
9
  #cacheFile;
11
10
  #cacheData;
12
- #writeTmr;
11
+ #dirty = false;
13
12
  constructor(rootDir, cacheFile) {
14
13
  this.#rootDir = rootDir;
15
14
  this.#cacheFile = cacheFile;
@@ -32,8 +31,13 @@ var Cache = class {
32
31
  source: sourceHash,
33
32
  output: newHash
34
33
  });
35
- clearTimeout(this.#writeTmr);
36
- this.#writeTmr = setTimeout(() => this.#writeCacheData(cacheData), 250);
34
+ this.#dirty = true;
35
+ }
36
+ async flush() {
37
+ if (this.#dirty) {
38
+ this.#dirty = false;
39
+ await this.#writeCacheData(await (this.#cacheData ??= this.#readCacheData()));
40
+ }
37
41
  }
38
42
  async #getSourceHash(files, mode) {
39
43
  const hash = (0, node_crypto.createHash)("sha256");
@@ -73,5 +77,4 @@ function isValidEntry(v) {
73
77
  return Object.keys(v).length === 2 && "source" in v && typeof v.source === "string" && "output" in v && typeof v.output === "string";
74
78
  }
75
79
 
76
- //#endregion
77
80
  exports.Cache = Cache;
package/dist/cache.mjs CHANGED
@@ -3,12 +3,12 @@ import { readFile, writeFile } from "node:fs/promises";
3
3
  import { resolve } from "node:path";
4
4
  import { createHash } from "node:crypto";
5
5
 
6
- //#region src/cache.ts
6
+ // src/cache.ts
7
7
  var Cache = class {
8
8
  #rootDir;
9
9
  #cacheFile;
10
10
  #cacheData;
11
- #writeTmr;
11
+ #dirty = false;
12
12
  constructor(rootDir, cacheFile) {
13
13
  this.#rootDir = rootDir;
14
14
  this.#cacheFile = cacheFile;
@@ -31,8 +31,13 @@ var Cache = class {
31
31
  source: sourceHash,
32
32
  output: newHash
33
33
  });
34
- clearTimeout(this.#writeTmr);
35
- this.#writeTmr = setTimeout(() => this.#writeCacheData(cacheData), 250);
34
+ this.#dirty = true;
35
+ }
36
+ async flush() {
37
+ if (this.#dirty) {
38
+ this.#dirty = false;
39
+ await this.#writeCacheData(await (this.#cacheData ??= this.#readCacheData()));
40
+ }
36
41
  }
37
42
  async #getSourceHash(files, mode) {
38
43
  const hash = createHash("sha256");
@@ -72,5 +77,4 @@ function isValidEntry(v) {
72
77
  return Object.keys(v).length === 2 && "source" in v && typeof v.source === "string" && "output" in v && typeof v.output === "string";
73
78
  }
74
79
 
75
- //#endregion
76
80
  export { Cache };
package/dist/cli.d.mts CHANGED
@@ -1 +1 @@
1
- export { };
1
+ export {}
package/dist/cli.mjs CHANGED
@@ -4,7 +4,7 @@ import { lookupPath } from "./utils.mjs";
4
4
  import { Codegen } from "./codegen.mjs";
5
5
  import { resolve } from "node:path";
6
6
 
7
- //#region src/cli.ts
7
+ // src/cli.ts
8
8
  const configFiles = [
9
9
  "codegen.config.mjs",
10
10
  "codegen.config.cjs",
@@ -14,13 +14,15 @@ const configFiles = [
14
14
  const config = process.argv.length > 2 ? await importConfig(resolve(process.argv[2])) : await lookupPath(process.cwd(), configFiles, importConfig);
15
15
  if (!config) {
16
16
  console.log(`Usage: pluggable-codegen [config]`);
17
- process.exit(1);
17
+ process.exitCode = 1;
18
+ return;
18
19
  }
19
20
  if (!validateConfig(config)) {
20
21
  console.log(`Invalid config`);
21
- process.exit(1);
22
+ process.exitCode = 1;
23
+ return;
22
24
  }
23
- await (await Codegen.init(...config)).generateAll();
25
+ if (!await (await Codegen.init(...config)).generateAll()) process.exitCode = 1;
24
26
  })();
25
27
  async function importConfig(path) {
26
28
  try {
@@ -38,5 +40,4 @@ function validateConfig(config) {
38
40
  return true;
39
41
  }
40
42
 
41
- //#endregion
42
43
  export { };
package/dist/codegen.cjs CHANGED
@@ -1,28 +1,26 @@
1
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
- const require_utils = require('./utils.cjs');
3
- const require_cache = require('./cache.cjs');
4
- const require_file = require('./file.cjs');
5
- const require_options = require('./options.cjs');
6
- const require_oxfmt = require('./oxfmt.cjs');
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_utils = require("./utils.cjs");
3
+ const require_cache = require("./cache.cjs");
4
+ const require_file = require("./file.cjs");
5
+ const require_index = require("./postprocessors/index.cjs");
6
+ const require_options = require("./options.cjs");
7
7
  let node_fs_promises = require("node:fs/promises");
8
8
  let node_path = require("node:path");
9
9
  let picomatch = require("picomatch");
10
10
  picomatch = require_runtime.__toESM(picomatch, 1);
11
11
  let tinyglobby = require("tinyglobby");
12
12
 
13
- //#region src/codegen.ts
13
+ // src/codegen.ts
14
14
  var Codegen = class Codegen {
15
15
  #options;
16
16
  #cache;
17
17
  #jobs;
18
18
  #running = /* @__PURE__ */ new Map();
19
- #oxfmt;
20
- #eslint;
21
- #prettier;
22
19
  static async init(jobOrOptions, ...moreJobs) {
23
20
  const [options, jobs] = typeof jobOrOptions === "function" || "input" in jobOrOptions ? [void 0, [jobOrOptions, ...moreJobs]] : [jobOrOptions, moreJobs];
24
21
  const normalizedOptions = await require_options.normalizeOptions(options);
25
- return new Codegen(normalizedOptions, await require_options.normalizeJobs(normalizedOptions.rootDir, jobs));
22
+ const normalizedJobs = await require_options.normalizeJobs(normalizedOptions.rootDir, jobs);
23
+ return new Codegen(normalizedOptions, normalizedJobs);
26
24
  }
27
25
  constructor(options, jobs) {
28
26
  this.#options = options;
@@ -30,33 +28,38 @@ var Codegen = class Codegen {
30
28
  this.#jobs = this.#createJobMap(jobs);
31
29
  }
32
30
  async generateAll() {
33
- await Promise.allSettled([...this.#jobs.values()].map(async (job) => this.#generate(job)));
31
+ const results = await Promise.all([...this.#jobs.values()].map(this.#generate));
32
+ await this.#cache.flush();
33
+ return results.every((v) => v);
34
34
  }
35
35
  async generateMatching(path) {
36
- await Promise.allSettled([...this.#jobs].map(async ([match, job]) => {
36
+ const results = await Promise.all([...this.#jobs].map(async ([match, job]) => {
37
37
  if (match(path)) await this.#generate(job);
38
38
  }));
39
+ await this.#cache.flush();
40
+ return results.every((v) => v);
39
41
  }
40
- async #generate(job) {
42
+ #generate = async (job) => {
41
43
  this.#running.get(job)?.abort();
42
44
  const controller = new AbortController();
43
45
  this.#running.set(job, controller);
44
46
  const files = await this.#scanFiles(job.input);
45
47
  const extraDeps = job.extraDeps?.length ? await this.#scanFiles(job.extraDeps) : [];
48
+ let success = true;
46
49
  await this.#cache.check([...files, ...extraDeps], job.output, job.cacheBy, async () => {
47
50
  try {
48
51
  const file = (0, node_path.resolve)(this.#options.rootDir, job.output);
49
52
  let output = await job.generate(files, controller.signal);
50
53
  if (output === null) return;
51
54
  if (controller.signal.aborted) return;
52
- const oxfmt = job.oxfmt ?? this.#options.oxfmt;
53
- const eslint = job.eslint ?? this.#options.eslint;
54
- const prettier = job.prettier ?? this.#options.prettier;
55
- if (typeof output === "string" && oxfmt) output = await this.#applyOxfmt(output, file);
56
- if (controller.signal.aborted) return;
57
- if (typeof output === "string" && !oxfmt && eslint) output = await this.#applyESLint(output, file);
58
- if (controller.signal.aborted) return;
59
- if (typeof output === "string" && !oxfmt && prettier) output = await this.#applyPrettier(output, file);
55
+ const disabled = /* @__PURE__ */ new Set();
56
+ for (const postprocessor of require_index.postprocessors) {
57
+ if (typeof output !== "string") break;
58
+ if (!(job[postprocessor.id] ?? this.#options[postprocessor.id]) || disabled.has(postprocessor.id)) continue;
59
+ for (const id of postprocessor.conflicts) disabled.add(id);
60
+ output = await postprocessor.apply(output, file);
61
+ if (controller.signal.aborted) return;
62
+ }
60
63
  if (controller.signal.aborted) return;
61
64
  try {
62
65
  await (0, node_fs_promises.mkdir)((0, node_path.dirname)(file), {
@@ -70,53 +73,26 @@ var Codegen = class Codegen {
70
73
  console.log(`\nError while generating '${job.output}':`);
71
74
  console.log(e);
72
75
  console.log("");
76
+ success = false;
73
77
  return;
74
78
  }
75
79
  });
76
- }
80
+ return success;
81
+ };
77
82
  async #scanFiles(patterns) {
78
83
  return (await (0, tinyglobby.glob)(patterns, {
79
84
  cwd: this.#options.rootDir,
80
85
  absolute: true
81
86
  })).sort().map((path) => new require_file.File(path, this.#options.rootDir));
82
87
  }
83
- async #applyOxfmt(source, path) {
84
- const oxfmt = await this.#loadOxfmt();
85
- const config = await require_oxfmt.resolveOxfmtConfig(path);
86
- const { code, errors } = await oxfmt.format(path, source, config);
87
- const firstError = errors.filter((e) => e.severity === "Error").pop();
88
- if (firstError) throw new Error(firstError.message);
89
- return code;
90
- }
91
- async #applyESLint(source, path) {
92
- const [result] = await (await this.#loadESLint()).lintText(source, { filePath: path });
93
- return result?.output ?? source;
94
- }
95
- async #applyPrettier(source, path) {
96
- const prettier = await this.#loadPrettier();
97
- const options = await prettier.resolveConfig(path);
98
- return prettier.format(source, {
99
- ...options ?? {},
100
- filepath: path
101
- });
102
- }
103
- async #loadOxfmt() {
104
- return this.#oxfmt ??= import("oxfmt");
105
- }
106
- async #loadESLint() {
107
- return this.#eslint ??= import("eslint").then(({ ESLint }) => new ESLint({ fix: true }));
108
- }
109
- async #loadPrettier() {
110
- return this.#prettier ??= import("prettier");
111
- }
112
88
  #createJobMap(jobs) {
113
89
  return new Map(jobs.map((job) => [this.#createMatcher(job), job]));
114
90
  }
115
91
  #createMatcher(job) {
116
92
  const root = (0, tinyglobby.escapePath)(this.#options.rootDir);
117
- return (0, picomatch.default)([job.input, job.extraDeps ?? []].flat().map((pattern) => (0, node_path.resolve)(root, pattern)));
93
+ const patterns = [job.input, job.extraDeps ?? []];
94
+ return (0, picomatch.default)(patterns.flat().map((pattern) => (0, node_path.resolve)(root, pattern)));
118
95
  }
119
96
  };
120
97
 
121
- //#endregion
122
98
  exports.Codegen = Codegen;
@@ -1,14 +1,10 @@
1
1
  import { CodegenInput, CodegenOptions } from "./types.mjs";
2
-
3
- //#region src/codegen.d.ts
4
- declare class Codegen {
2
+ export declare class Codegen {
5
3
  #private;
6
4
  static init(...jobs: CodegenInput[]): Promise<Codegen>;
7
5
  static init(options: CodegenOptions, ...jobs: CodegenInput[]): Promise<Codegen>;
8
6
  static init(jobOrOptions: CodegenInput | CodegenOptions, ...moreJobs: CodegenInput[]): Promise<Codegen>;
9
7
  private constructor();
10
- generateAll(): Promise<void>;
11
- generateMatching(path: string): Promise<void>;
12
- }
13
- //#endregion
14
- export { Codegen };
8
+ generateAll(): Promise<boolean>;
9
+ generateMatching(path: string): Promise<boolean>;
10
+ }
package/dist/codegen.mjs CHANGED
@@ -1,26 +1,24 @@
1
1
  import { hash } from "./utils.mjs";
2
2
  import { Cache } from "./cache.mjs";
3
3
  import { File } from "./file.mjs";
4
+ import { postprocessors } from "./postprocessors/index.mjs";
4
5
  import { normalizeJobs, normalizeOptions } from "./options.mjs";
5
- import { resolveOxfmtConfig } from "./oxfmt.mjs";
6
6
  import { mkdir, writeFile } from "node:fs/promises";
7
7
  import { dirname, resolve } from "node:path";
8
8
  import picomatch from "picomatch";
9
9
  import { escapePath, glob } from "tinyglobby";
10
10
 
11
- //#region src/codegen.ts
11
+ // src/codegen.ts
12
12
  var Codegen = class Codegen {
13
13
  #options;
14
14
  #cache;
15
15
  #jobs;
16
16
  #running = /* @__PURE__ */ new Map();
17
- #oxfmt;
18
- #eslint;
19
- #prettier;
20
17
  static async init(jobOrOptions, ...moreJobs) {
21
18
  const [options, jobs] = typeof jobOrOptions === "function" || "input" in jobOrOptions ? [void 0, [jobOrOptions, ...moreJobs]] : [jobOrOptions, moreJobs];
22
19
  const normalizedOptions = await normalizeOptions(options);
23
- return new Codegen(normalizedOptions, await normalizeJobs(normalizedOptions.rootDir, jobs));
20
+ const normalizedJobs = await normalizeJobs(normalizedOptions.rootDir, jobs);
21
+ return new Codegen(normalizedOptions, normalizedJobs);
24
22
  }
25
23
  constructor(options, jobs) {
26
24
  this.#options = options;
@@ -28,33 +26,38 @@ var Codegen = class Codegen {
28
26
  this.#jobs = this.#createJobMap(jobs);
29
27
  }
30
28
  async generateAll() {
31
- await Promise.allSettled([...this.#jobs.values()].map(async (job) => this.#generate(job)));
29
+ const results = await Promise.all([...this.#jobs.values()].map(this.#generate));
30
+ await this.#cache.flush();
31
+ return results.every((v) => v);
32
32
  }
33
33
  async generateMatching(path) {
34
- await Promise.allSettled([...this.#jobs].map(async ([match, job]) => {
34
+ const results = await Promise.all([...this.#jobs].map(async ([match, job]) => {
35
35
  if (match(path)) await this.#generate(job);
36
36
  }));
37
+ await this.#cache.flush();
38
+ return results.every((v) => v);
37
39
  }
38
- async #generate(job) {
40
+ #generate = async (job) => {
39
41
  this.#running.get(job)?.abort();
40
42
  const controller = new AbortController();
41
43
  this.#running.set(job, controller);
42
44
  const files = await this.#scanFiles(job.input);
43
45
  const extraDeps = job.extraDeps?.length ? await this.#scanFiles(job.extraDeps) : [];
46
+ let success = true;
44
47
  await this.#cache.check([...files, ...extraDeps], job.output, job.cacheBy, async () => {
45
48
  try {
46
49
  const file = resolve(this.#options.rootDir, job.output);
47
50
  let output = await job.generate(files, controller.signal);
48
51
  if (output === null) return;
49
52
  if (controller.signal.aborted) return;
50
- const oxfmt = job.oxfmt ?? this.#options.oxfmt;
51
- const eslint = job.eslint ?? this.#options.eslint;
52
- const prettier = job.prettier ?? this.#options.prettier;
53
- if (typeof output === "string" && oxfmt) output = await this.#applyOxfmt(output, file);
54
- if (controller.signal.aborted) return;
55
- if (typeof output === "string" && !oxfmt && eslint) output = await this.#applyESLint(output, file);
56
- if (controller.signal.aborted) return;
57
- if (typeof output === "string" && !oxfmt && prettier) output = await this.#applyPrettier(output, file);
53
+ const disabled = /* @__PURE__ */ new Set();
54
+ for (const postprocessor of postprocessors) {
55
+ if (typeof output !== "string") break;
56
+ if (!(job[postprocessor.id] ?? this.#options[postprocessor.id]) || disabled.has(postprocessor.id)) continue;
57
+ for (const id of postprocessor.conflicts) disabled.add(id);
58
+ output = await postprocessor.apply(output, file);
59
+ if (controller.signal.aborted) return;
60
+ }
58
61
  if (controller.signal.aborted) return;
59
62
  try {
60
63
  await mkdir(dirname(file), {
@@ -68,53 +71,26 @@ var Codegen = class Codegen {
68
71
  console.log(`\nError while generating '${job.output}':`);
69
72
  console.log(e);
70
73
  console.log("");
74
+ success = false;
71
75
  return;
72
76
  }
73
77
  });
74
- }
78
+ return success;
79
+ };
75
80
  async #scanFiles(patterns) {
76
81
  return (await glob(patterns, {
77
82
  cwd: this.#options.rootDir,
78
83
  absolute: true
79
84
  })).sort().map((path) => new File(path, this.#options.rootDir));
80
85
  }
81
- async #applyOxfmt(source, path) {
82
- const oxfmt = await this.#loadOxfmt();
83
- const config = await resolveOxfmtConfig(path);
84
- const { code, errors } = await oxfmt.format(path, source, config);
85
- const firstError = errors.filter((e) => e.severity === "Error").pop();
86
- if (firstError) throw new Error(firstError.message);
87
- return code;
88
- }
89
- async #applyESLint(source, path) {
90
- const [result] = await (await this.#loadESLint()).lintText(source, { filePath: path });
91
- return result?.output ?? source;
92
- }
93
- async #applyPrettier(source, path) {
94
- const prettier = await this.#loadPrettier();
95
- const options = await prettier.resolveConfig(path);
96
- return prettier.format(source, {
97
- ...options ?? {},
98
- filepath: path
99
- });
100
- }
101
- async #loadOxfmt() {
102
- return this.#oxfmt ??= import("oxfmt");
103
- }
104
- async #loadESLint() {
105
- return this.#eslint ??= import("eslint").then(({ ESLint }) => new ESLint({ fix: true }));
106
- }
107
- async #loadPrettier() {
108
- return this.#prettier ??= import("prettier");
109
- }
110
86
  #createJobMap(jobs) {
111
87
  return new Map(jobs.map((job) => [this.#createMatcher(job), job]));
112
88
  }
113
89
  #createMatcher(job) {
114
90
  const root = escapePath(this.#options.rootDir);
115
- return picomatch([job.input, job.extraDeps ?? []].flat().map((pattern) => resolve(root, pattern)));
91
+ const patterns = [job.input, job.extraDeps ?? []];
92
+ return picomatch(patterns.flat().map((pattern) => resolve(root, pattern)));
116
93
  }
117
94
  };
118
95
 
119
- //#endregion
120
96
  export { Codegen };
package/dist/file.cjs CHANGED
@@ -1,8 +1,7 @@
1
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
1
  let node_fs_promises = require("node:fs/promises");
3
2
  let node_path = require("node:path");
4
3
 
5
- //#region src/file.ts
4
+ // src/file.ts
6
5
  var File = class {
7
6
  fullPath;
8
7
  localPath;
@@ -22,5 +21,4 @@ var File = class {
22
21
  }
23
22
  };
24
23
 
25
- //#endregion
26
24
  exports.File = File;
package/dist/file.d.mts CHANGED
@@ -1,5 +1,4 @@
1
- //#region src/file.d.ts
2
- declare class File {
1
+ export declare class File {
3
2
  #private;
4
3
  readonly fullPath: string;
5
4
  readonly localPath: string;
@@ -7,6 +6,4 @@ declare class File {
7
6
  buffer(): Promise<Buffer>;
8
7
  text(encoding?: BufferEncoding): Promise<string>;
9
8
  json(): Promise<any>;
10
- }
11
- //#endregion
12
- export { File };
9
+ }
package/dist/file.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { relative } from "node:path";
3
3
 
4
- //#region src/file.ts
4
+ // src/file.ts
5
5
  var File = class {
6
6
  fullPath;
7
7
  localPath;
@@ -21,5 +21,4 @@ var File = class {
21
21
  }
22
22
  };
23
23
 
24
- //#endregion
25
24
  export { File };
package/dist/index.cjs CHANGED
@@ -1,10 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_file = require('./file.cjs');
3
- const require_codegen = require('./codegen.cjs');
4
- const require_plugin = require('./plugin.cjs');
5
- const require_types = require('./types.cjs');
2
+ const require_file = require("./file.cjs");
3
+ const require_index = require("./postprocessors/index.cjs");
4
+ const require_codegen = require("./codegen.cjs");
5
+ const require_plugin = require("./plugin.cjs");
6
+ const require_types = require("./types.cjs");
6
7
 
7
8
  exports.Codegen = require_codegen.Codegen;
8
9
  exports.File = require_file.File;
9
10
  exports.codegen = require_plugin.codegen;
10
- exports.defineCodegen = require_types.defineCodegen;
11
+ exports.defineCodegen = require_types.defineCodegen;
12
+ exports.postprocessors = require_index.postprocessors;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { File } from "./file.mjs";
2
- import { CodegenInput, CodegenJob, CodegenJobGenerator, CodegenOptions, CodegenPresetOptions, NormalizedCodegenOptions, defineCodegen } from "./types.mjs";
2
+ import { Postprocessor, PostprocessorId } from "./postprocessors/types.mjs";
3
+ import { PostprocessorOptions, postprocessors } from "./postprocessors/index.mjs";
4
+ import { CodegenInput, CodegenJob, CodegenJobGenerator, CodegenOptions, CodegenPresetOptions, MaybePromise, NormalizedCodegenOptions, defineCodegen } from "./types.mjs";
3
5
  import { Codegen } from "./codegen.mjs";
4
6
  import { Plugin, codegen } from "./plugin.mjs";
5
- export { Codegen, CodegenInput, CodegenJob, CodegenJobGenerator, CodegenOptions, CodegenPresetOptions, File, NormalizedCodegenOptions, Plugin, codegen, defineCodegen };
7
+ export { Codegen, CodegenInput, CodegenJob, CodegenJobGenerator, CodegenOptions, CodegenPresetOptions, File, MaybePromise, NormalizedCodegenOptions, Plugin, type Postprocessor, type PostprocessorId, PostprocessorOptions, codegen, defineCodegen, postprocessors };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { File } from "./file.mjs";
2
+ import { postprocessors } from "./postprocessors/index.mjs";
2
3
  import { Codegen } from "./codegen.mjs";
3
4
  import { codegen } from "./plugin.mjs";
4
5
  import { defineCodegen } from "./types.mjs";
5
6
 
6
- export { Codegen, File, codegen, defineCodegen };
7
+ export { Codegen, File, codegen, defineCodegen, postprocessors };
package/dist/options.cjs CHANGED
@@ -1,18 +1,19 @@
1
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
- const require_utils = require('./utils.cjs');
1
+ const require_utils = require("./utils.cjs");
2
+ const require_index = require("./postprocessors/index.cjs");
3
3
  let node_fs_promises = require("node:fs/promises");
4
4
  let node_path = require("node:path");
5
5
 
6
- //#region src/options.ts
6
+ // src/options.ts
7
7
  async function normalizeOptions(options = {}) {
8
8
  let packageJson;
9
9
  const rootDir = (0, node_path.resolve)(options.rootDir ?? process.cwd());
10
+ const cacheFile = await resolveCacheFile(rootDir, options.cacheFile);
11
+ const ppopts = {};
12
+ for (const postprocessor of require_index.postprocessors) ppopts[postprocessor.id] = options[postprocessor.id] ?? hasDevDep(await getPackageJson(), postprocessor.packageName);
10
13
  return {
11
14
  rootDir,
12
- cacheFile: await resolveCacheFile(rootDir, options.cacheFile),
13
- oxfmt: options.oxfmt ?? hasDevDep(await getPackageJson(), "oxfmt"),
14
- prettier: options.prettier ?? hasDevDep(await getPackageJson(), "prettier"),
15
- eslint: options.eslint ?? hasDevDep(await getPackageJson(), "eslint")
15
+ cacheFile,
16
+ ...ppopts
16
17
  };
17
18
  async function getPackageJson() {
18
19
  return packageJson ??= readPackageJson(rootDir);
@@ -47,6 +48,5 @@ async function readPackageJson(dir) {
47
48
  });
48
49
  }
49
50
 
50
- //#endregion
51
51
  exports.normalizeJobs = normalizeJobs;
52
52
  exports.normalizeOptions = normalizeOptions;
package/dist/options.mjs CHANGED
@@ -1,17 +1,19 @@
1
1
  import { lookupPath } from "./utils.mjs";
2
+ import { postprocessors } from "./postprocessors/index.mjs";
2
3
  import { mkdir, readFile } from "node:fs/promises";
3
4
  import { dirname, resolve } from "node:path";
4
5
 
5
- //#region src/options.ts
6
+ // src/options.ts
6
7
  async function normalizeOptions(options = {}) {
7
8
  let packageJson;
8
9
  const rootDir = resolve(options.rootDir ?? process.cwd());
10
+ const cacheFile = await resolveCacheFile(rootDir, options.cacheFile);
11
+ const ppopts = {};
12
+ for (const postprocessor of postprocessors) ppopts[postprocessor.id] = options[postprocessor.id] ?? hasDevDep(await getPackageJson(), postprocessor.packageName);
9
13
  return {
10
14
  rootDir,
11
- cacheFile: await resolveCacheFile(rootDir, options.cacheFile),
12
- oxfmt: options.oxfmt ?? hasDevDep(await getPackageJson(), "oxfmt"),
13
- prettier: options.prettier ?? hasDevDep(await getPackageJson(), "prettier"),
14
- eslint: options.eslint ?? hasDevDep(await getPackageJson(), "eslint")
15
+ cacheFile,
16
+ ...ppopts
15
17
  };
16
18
  async function getPackageJson() {
17
19
  return packageJson ??= readPackageJson(rootDir);
@@ -46,5 +48,4 @@ async function readPackageJson(dir) {
46
48
  });
47
49
  }
48
50
 
49
- //#endregion
50
51
  export { normalizeJobs, normalizeOptions };
package/dist/plugin.cjs CHANGED
@@ -1,6 +1,6 @@
1
- const require_codegen = require('./codegen.cjs');
1
+ const require_codegen = require("./codegen.cjs");
2
2
 
3
- //#region src/plugin.ts
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;
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
- //#region src/plugin.ts
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,8 @@
1
+ import { Postprocessor } from "./types.mjs";
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,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.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.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,7 @@
1
+ import { Postprocessor } from "./types.mjs";
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,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;
@@ -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
- //#region src/presets/graphql-codegen.ts
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
- //#region src/presets/graphql-codegen.ts
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
@@ -1,8 +1,6 @@
1
-
2
- //#region src/types.ts
1
+ // src/types.ts
3
2
  function defineCodegen(optionsOrJob, ...jobs) {
4
3
  return [optionsOrJob, ...jobs];
5
4
  }
6
5
 
7
- //#endregion
8
6
  exports.defineCodegen = defineCodegen;
package/dist/types.d.mts CHANGED
@@ -1,36 +1,24 @@
1
1
  import { File } from "./file.mjs";
2
-
3
- //#region src/types.d.ts
4
- type MaybePromise<T> = Promise<T> | T;
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
@@ -1,7 +1,6 @@
1
- //#region src/types.ts
1
+ // src/types.ts
2
2
  function defineCodegen(optionsOrJob, ...jobs) {
3
3
  return [optionsOrJob, ...jobs];
4
4
  }
5
5
 
6
- //#endregion
7
6
  export { defineCodegen };
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
- //#region src/utils.ts
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
- //#region src/utils.ts
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 };
package/package.json CHANGED
@@ -1,15 +1,11 @@
1
1
  {
2
2
  "name": "pluggable-codegen",
3
- "version": "0.4.0",
4
- "license": "MIT",
3
+ "version": "0.5.0",
5
4
  "homepage": "https://github.com/jahudka/pluggable-codegen",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/jahudka/pluggable-codegen.git"
9
- },
10
5
  "bugs": {
11
6
  "url": "https://github.com/jahudka/pluggable-codegen/issues"
12
7
  },
8
+ "license": "MIT",
13
9
  "maintainers": [
14
10
  {
15
11
  "name": "Eliška Daniela Kaderová",
@@ -17,16 +13,20 @@
17
13
  "url": "https://github.com/jahudka"
18
14
  }
19
15
  ],
20
- "files": [
21
- "dist"
22
- ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/jahudka/pluggable-codegen.git"
19
+ },
23
20
  "bin": {
24
21
  "pluggable-codegen": "dist/cli.mjs"
25
22
  },
23
+ "files": [
24
+ "dist"
25
+ ],
26
26
  "type": "module",
27
- "types": "./dist/index.d.ts",
28
27
  "main": "./dist/index.cjs",
29
28
  "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.ts",
30
30
  "exports": {
31
31
  ".": {
32
32
  "types": "./dist/index.d.ts",
@@ -40,12 +40,24 @@
40
40
  }
41
41
  },
42
42
  "dependencies": {
43
- "picomatch": "^4.0.4",
44
- "tinyglobby": "^0.2.16"
43
+ "picomatch": "^4.0.7",
44
+ "tinyglobby": "^0.2.17"
45
+ },
46
+ "devDependencies": {
47
+ "@graphql-codegen/cli": "^7.4.6",
48
+ "@types/node": "^24.19.2",
49
+ "@types/picomatch": "^4.0.3",
50
+ "eslint": "^10.13.0",
51
+ "oxfmt": "^0.75.0",
52
+ "oxlint": "^1.90.0",
53
+ "prettier": "^3.9.10",
54
+ "tsdown": "^0.23.2",
55
+ "typescript": "^6.0.3",
56
+ "yaml": "^2.9.1"
45
57
  },
46
58
  "peerDependencies": {
47
59
  "@graphql-codegen/cli": "^5.0.0 || ^6.0.0 || ^7.0.0",
48
- "yaml": "^2.9.0"
60
+ "yaml": "^2.9.1"
49
61
  },
50
62
  "peerDependenciesMeta": {
51
63
  "@graphql-codegen/cli": {
@@ -55,31 +67,14 @@
55
67
  "optional": true
56
68
  }
57
69
  },
58
- "devDependencies": {
59
- "@eslint/js": "^10.0.1",
60
- "@graphql-codegen/cli": "^7.0.0",
61
- "@types/node": "^22.19.19",
62
- "@types/picomatch": "^4.0.3",
63
- "eslint": "^10.4.0",
64
- "eslint-config-prettier": "^10.1.8",
65
- "eslint-plugin-simple-import-sort": "^13.0.0",
66
- "eslint-plugin-unused-imports": "^4.4.1",
67
- "globals": "^17.6.0",
68
- "oxfmt": "^0.63.0",
69
- "prettier": "^3.8.3",
70
- "tsdown": "^0.22.0",
71
- "typescript": "^6.0.3",
72
- "typescript-eslint": "^8.59.3",
73
- "yaml": "^2.9.0"
74
- },
75
70
  "scripts": {
76
71
  "clean": "rm -rf dist",
77
- "eslint": "eslint .",
78
- "eslint:fix": "eslint --fix .",
79
- "prettier": "prettier --check .",
80
- "prettier:fix": "prettier --write .",
81
- "lint": "pnpm run '/^(eslint|prettier)$/'",
82
- "format": "pnpm run --sequential '/^(eslint|prettier):fix$/'",
72
+ "oxlint": "oxlint",
73
+ "oxlint:fix": "oxlint --fix",
74
+ "oxfmt": "oxfmt --check",
75
+ "oxfmt:fix": "oxfmt --write",
76
+ "lint": "pnpm run '/^(oxlint|oxfmt)$/'",
77
+ "format": "pnpm run --sequential '/^(oxlint|oxfmt):fix$/'",
83
78
  "build": "tsc && tsdown"
84
79
  }
85
80
  }
package/dist/oxfmt.cjs DELETED
@@ -1,24 +0,0 @@
1
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
- const require_utils = require('./utils.cjs');
3
- let node_fs_promises = require("node:fs/promises");
4
- let node_path = require("node:path");
5
-
6
- //#region src/oxfmt.ts
7
- const candidates = [".oxfmtrc.json"];
8
- const cache = /* @__PURE__ */ new Map();
9
- async function resolveOxfmtConfig(from) {
10
- const dir = (0, node_path.dirname)(from);
11
- const cached = cache.get(dir);
12
- if (cached) return cached;
13
- const { promise, resolve } = Promise.withResolvers();
14
- cache.set(dir, promise);
15
- resolve(await require_utils.lookupPath(dir, candidates, loadConfig));
16
- return promise;
17
- }
18
- async function loadConfig(file) {
19
- const contents = await (0, node_fs_promises.readFile)(file, "utf-8");
20
- return JSON.parse(contents);
21
- }
22
-
23
- //#endregion
24
- exports.resolveOxfmtConfig = resolveOxfmtConfig;
package/dist/oxfmt.mjs DELETED
@@ -1,23 +0,0 @@
1
- import { lookupPath } from "./utils.mjs";
2
- import { readFile } from "node:fs/promises";
3
- import { dirname } from "node:path";
4
-
5
- //#region src/oxfmt.ts
6
- const candidates = [".oxfmtrc.json"];
7
- const cache = /* @__PURE__ */ new Map();
8
- async function resolveOxfmtConfig(from) {
9
- const dir = dirname(from);
10
- const cached = cache.get(dir);
11
- if (cached) return cached;
12
- const { promise, resolve } = Promise.withResolvers();
13
- cache.set(dir, promise);
14
- resolve(await lookupPath(dir, candidates, loadConfig));
15
- return promise;
16
- }
17
- async function loadConfig(file) {
18
- const contents = await readFile(file, "utf-8");
19
- return JSON.parse(contents);
20
- }
21
-
22
- //#endregion
23
- export { resolveOxfmtConfig };