pluggable-codegen 0.3.3 → 0.3.4

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 CHANGED
@@ -38,8 +38,6 @@ export default defineCodegen(
38
38
  // auto-detected based on devDependencies:
39
39
  eslint: undefined,
40
40
  prettier: undefined,
41
- // global overrides for tinyglobby options:
42
- glob: undefined,
43
41
  },
44
42
  // followed by one or more codegen jobs:
45
43
  {
@@ -52,19 +50,20 @@ export default defineCodegen(
52
50
 
53
51
  // now do something fun and return a Buffer or a string;
54
52
  // you can also return null, in which case nothing will be written
55
- return `export const fileList = ${JSON.stringify(files)};`;
53
+ const fileList = files.map((file) => file.fullPath);
54
+ return `export const fileList = ${JSON.stringify(fileList, null, 2)};`;
56
55
  },
57
56
  // set to 'files' if your generated output is based only on
58
57
  // the list of file names, or to 'contents' if the output is
59
- // based on the files' contents:
58
+ // based on the files' contents; leave undefined to disable cache:
60
59
  cacheBy: undefined,
61
60
  // provide an array of additional glob patterns to consider when
62
61
  // checking the cache; this can include e.g. `import.meta.filename`
63
62
  // to make the job rebuild when its definition changes
64
63
  extraDeps: undefined,
65
- // you can override the global 'eslint', 'prettier',
66
- // and 'glob' options per-job:
67
- // prettier: false,
64
+ // you can override the global 'eslint' and 'prettier' options
65
+ // per-job, e.g.:
66
+ prettier: false,
68
67
  },
69
68
  );
70
69
  ```
package/dist/codegen.cjs CHANGED
@@ -42,30 +42,29 @@ var Codegen = class Codegen {
42
42
  const files = await this.#scanFiles(job.input);
43
43
  const extraDeps = job.extraDeps?.length ? await this.#scanFiles(job.extraDeps) : [];
44
44
  await this.#cache.check([...files, ...extraDeps], job.output, job.cacheBy, async () => {
45
- const file = (0, node_path.resolve)(this.#options.rootDir, job.output);
46
- let output;
47
45
  try {
48
- output = await job.generate(files, controller.signal);
46
+ const file = (0, node_path.resolve)(this.#options.rootDir, job.output);
47
+ let output = await job.generate(files, controller.signal);
48
+ if (output === null) return;
49
+ if (controller.signal.aborted) return;
50
+ if (typeof output === "string" && (job.eslint ?? this.#options.eslint)) output = await this.#applyESLint(output, file);
51
+ if (controller.signal.aborted) return;
52
+ if (typeof output === "string" && (job.prettier ?? this.#options.prettier)) output = await this.#applyPrettier(output, file);
53
+ if (controller.signal.aborted) return;
54
+ try {
55
+ await (0, node_fs_promises.mkdir)((0, node_path.dirname)(file), {
56
+ mode: 488,
57
+ recursive: true
58
+ });
59
+ } catch {}
60
+ await (0, node_fs_promises.writeFile)(file, output);
61
+ return require_utils.hash(output);
49
62
  } catch (e) {
50
63
  console.log(`\nError while generating '${job.output}':`);
51
64
  console.log(e);
52
65
  console.log("");
53
66
  return;
54
67
  }
55
- if (output === null) return;
56
- if (controller.signal.aborted) return;
57
- if (typeof output === "string" && (job.eslint ?? this.#options.eslint)) output = await this.#applyESLint(output, file);
58
- if (controller.signal.aborted) return;
59
- if (typeof output === "string" && (job.prettier ?? this.#options.prettier)) output = await this.#applyPrettier(output, file);
60
- if (controller.signal.aborted) return;
61
- try {
62
- await (0, node_fs_promises.mkdir)((0, node_path.dirname)(file), {
63
- mode: 488,
64
- recursive: true
65
- });
66
- } catch {}
67
- await (0, node_fs_promises.writeFile)(file, output);
68
- return require_utils.hash(output);
69
68
  });
70
69
  }
71
70
  async #scanFiles(patterns) {
package/dist/codegen.mjs CHANGED
@@ -40,30 +40,29 @@ var Codegen = class Codegen {
40
40
  const files = await this.#scanFiles(job.input);
41
41
  const extraDeps = job.extraDeps?.length ? await this.#scanFiles(job.extraDeps) : [];
42
42
  await this.#cache.check([...files, ...extraDeps], job.output, job.cacheBy, async () => {
43
- const file = resolve(this.#options.rootDir, job.output);
44
- let output;
45
43
  try {
46
- output = await job.generate(files, controller.signal);
44
+ const file = resolve(this.#options.rootDir, job.output);
45
+ let output = await job.generate(files, controller.signal);
46
+ if (output === null) return;
47
+ if (controller.signal.aborted) return;
48
+ if (typeof output === "string" && (job.eslint ?? this.#options.eslint)) output = await this.#applyESLint(output, file);
49
+ if (controller.signal.aborted) return;
50
+ if (typeof output === "string" && (job.prettier ?? this.#options.prettier)) output = await this.#applyPrettier(output, file);
51
+ if (controller.signal.aborted) return;
52
+ try {
53
+ await mkdir(dirname(file), {
54
+ mode: 488,
55
+ recursive: true
56
+ });
57
+ } catch {}
58
+ await writeFile(file, output);
59
+ return hash(output);
47
60
  } catch (e) {
48
61
  console.log(`\nError while generating '${job.output}':`);
49
62
  console.log(e);
50
63
  console.log("");
51
64
  return;
52
65
  }
53
- if (output === null) return;
54
- if (controller.signal.aborted) return;
55
- if (typeof output === "string" && (job.eslint ?? this.#options.eslint)) output = await this.#applyESLint(output, file);
56
- if (controller.signal.aborted) return;
57
- if (typeof output === "string" && (job.prettier ?? this.#options.prettier)) output = await this.#applyPrettier(output, file);
58
- if (controller.signal.aborted) return;
59
- try {
60
- await mkdir(dirname(file), {
61
- mode: 488,
62
- recursive: true
63
- });
64
- } catch {}
65
- await writeFile(file, output);
66
- return hash(output);
67
66
  });
68
67
  }
69
68
  async #scanFiles(patterns) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pluggable-codegen",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/jahudka/pluggable-codegen",
6
6
  "repository": {