@slicemachine/plugin-kit 0.4.39-beta.6 → 0.4.39-beta.8

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.
@@ -29,6 +29,7 @@ function _interopNamespaceDefault(e) {
29
29
  }
30
30
  const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
31
31
  const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
32
+ const prettier__namespace = /* @__PURE__ */ _interopNamespaceDefault(prettier);
32
33
  const createSliceMachineHelpers = (project) => {
33
34
  return new SliceMachineHelpers(project);
34
35
  };
@@ -74,8 +75,8 @@ class SliceMachineHelpers {
74
75
  });
75
76
  __publicField(this, "format", async (source, filePath, options) => {
76
77
  let formatted = commonTags.stripIndent(source);
77
- const prettierOptions = await prettier.resolveConfig(filePath || this._project.root);
78
- formatted = await prettier.format(formatted, {
78
+ const prettierOptions = await prettier__namespace.resolveConfig(filePath || this._project.root);
79
+ formatted = await prettier__namespace.format(formatted, {
79
80
  ...prettierOptions,
80
81
  filepath: filePath,
81
82
  ...(options == null ? void 0 : options.prettier) ?? {}
@@ -1 +1 @@
1
- {"version":3,"file":"createSliceMachineHelpers.cjs","sources":["../../src/createSliceMachineHelpers.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport prettier from \"prettier\";\nimport { stripIndent } from \"common-tags\";\n\nimport { decodeSliceMachineConfig } from \"./lib/decodeSliceMachineConfig\";\n\nimport { SliceMachineConfig, SliceMachineProject } from \"./types\";\n\ntype UpdateSliceMachineConfigOptions = {\n\tformat?: boolean;\n};\n\ntype FormatOptions = {\n\tprettier?: prettier.Options;\n\t/**\n\t * Determines if a newline is included at the end of the formatted result.\n\t *\n\t * @defaultValue `true`\n\t */\n\tincludeNewlineAtEnd?: boolean;\n};\n\n/**\n * Creates Slice Machine helpers.\n *\n * @internal\n */\nexport const createSliceMachineHelpers = (\n\tproject: SliceMachineProject,\n): SliceMachineHelpers => {\n\treturn new SliceMachineHelpers(project);\n};\n\n/**\n * Slice Machine helpers shared to plugins and hooks.\n */\nexport class SliceMachineHelpers {\n\t/**\n\t * The Slice Machine project's metadata.\n\t *\n\t * @internal\n\t */\n\tprivate _project: SliceMachineProject;\n\n\tconstructor(project: SliceMachineProject) {\n\t\tthis._project = project;\n\t}\n\n\tgetProject = async (): Promise<SliceMachineProject> => {\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch {\n\t\t\t// noop\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\treturn {\n\t\t\t...this._project,\n\t\t\tconfig: sliceMachineConfig,\n\t\t};\n\t};\n\n\tupdateSliceMachineConfig = async (\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t\toptions?: UpdateSliceMachineConfigOptions,\n\t): Promise<void> => {\n\t\tconst { value: decodedSliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(sliceMachineConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config provided. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\t\tlet content = JSON.stringify(decodedSliceMachineConfig, null, 2);\n\n\t\tif (options?.format) {\n\t\t\tcontent = await this.format(content, configFilePath);\n\t\t}\n\n\t\tawait fs.writeFile(configFilePath, content);\n\t};\n\n\tformat = async (\n\t\tsource: string,\n\t\tfilePath?: string,\n\t\toptions?: FormatOptions,\n\t): Promise<string> => {\n\t\tlet formatted = stripIndent(source);\n\n\t\tconst prettierOptions = await prettier.resolveConfig(\n\t\t\tfilePath || this._project.root,\n\t\t);\n\n\t\tformatted = await prettier.format(formatted, {\n\t\t\t...prettierOptions,\n\t\t\tfilepath: filePath,\n\t\t\t...(options?.prettier ?? {}),\n\t\t});\n\n\t\tif (options?.includeNewlineAtEnd === false) {\n\t\t\tformatted = formatted.replace(/[\\r\\n]+$/, \"\");\n\t\t}\n\n\t\treturn formatted;\n\t};\n\n\tjoinPathFromRoot = (...paths: string[]): string => {\n\t\treturn path.join(this._project.root, ...paths);\n\t};\n}\n"],"names":["fs","decodeSliceMachineConfig","stripIndent","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Ba,MAAA,4BAA4B,CACxC,YACwB;AACjB,SAAA,IAAI,oBAAoB,OAAO;AACvC;MAKa,oBAAmB;AAAA,EAQ/B,YAAY,SAA4B;AAFhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAMR,sCAAa,YAAyC;AAC/C,YAAA,iBAAiB,KAAK,iBAAiB,0BAA0B;AAEnE,UAAA;AACA,UAAA;AACH,cAAM,WAAW,MAAMA,cAAG,SAAS,gBAAgB,MAAM;AAC7C,oBAAA,KAAK,MAAM,QAAQ;AAAA,MAAA,QAC9B;AAAA,MAED;AAED,UAAI,CAAC,WAAW;AAET,cAAA,IAAI,MAAM,kBAAkB;AAAA,MAClC;AAED,YAAM,EAAE,OAAO,oBAAoB,MAAO,IACzCC,yBAAAA,yBAAyB,SAAS;AAEnC,UAAI,OAAO;AAEV,cAAM,IAAI,MAAM,mBAAmB,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,MAC5D;AAEM,aAAA;AAAA,QACN,GAAG,KAAK;AAAA,QACR,QAAQ;AAAA,MAAA;AAAA;AAIV,oDAA2B,OAC1B,oBACA,YACkB;AAClB,YAAM,EAAE,OAAO,2BAA2B,MAAO,IAChDA,yBAAAA,yBAAyB,kBAAkB;AAE5C,UAAI,OAAO;AAEV,cAAM,IAAI,MAAM,4BAA4B,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,MACrE;AAEK,YAAA,iBAAiB,KAAK,iBAAiB,0BAA0B;AACvE,UAAI,UAAU,KAAK,UAAU,2BAA2B,MAAM,CAAC;AAE/D,UAAI,mCAAS,QAAQ;AACpB,kBAAU,MAAM,KAAK,OAAO,SAAS,cAAc;AAAA,MACnD;AAEK,YAAAD,cAAG,UAAU,gBAAgB,OAAO;AAAA,IAAA;AAG3C,kCAAS,OACR,QACA,UACA,YACoB;AAChB,UAAA,YAAYE,uBAAY,MAAM;AAElC,YAAM,kBAAkB,MAAM,SAAS,cACtC,YAAY,KAAK,SAAS,IAAI;AAGnB,kBAAA,MAAM,SAAS,OAAO,WAAW;AAAA,QAC5C,GAAG;AAAA,QACH,UAAU;AAAA,QACV,IAAI,mCAAS,aAAY;OACzB;AAEG,WAAA,mCAAS,yBAAwB,OAAO;AAC/B,oBAAA,UAAU,QAAQ,YAAY,EAAE;AAAA,MAC5C;AAEM,aAAA;AAAA,IAAA;AAGR,4CAAmB,IAAI,UAA2B;AACjD,aAAOC,gBAAK,KAAK,KAAK,SAAS,MAAM,GAAG,KAAK;AAAA,IAAA;AAhF7C,SAAK,WAAW;AAAA,EACjB;AAiFA;;;"}
1
+ {"version":3,"file":"createSliceMachineHelpers.cjs","sources":["../../src/createSliceMachineHelpers.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport * as prettier from \"prettier\";\nimport { stripIndent } from \"common-tags\";\n\nimport { decodeSliceMachineConfig } from \"./lib/decodeSliceMachineConfig\";\n\nimport { SliceMachineConfig, SliceMachineProject } from \"./types\";\n\ntype UpdateSliceMachineConfigOptions = {\n\tformat?: boolean;\n};\n\ntype FormatOptions = {\n\tprettier?: prettier.Options;\n\t/**\n\t * Determines if a newline is included at the end of the formatted result.\n\t *\n\t * @defaultValue `true`\n\t */\n\tincludeNewlineAtEnd?: boolean;\n};\n\n/**\n * Creates Slice Machine helpers.\n *\n * @internal\n */\nexport const createSliceMachineHelpers = (\n\tproject: SliceMachineProject,\n): SliceMachineHelpers => {\n\treturn new SliceMachineHelpers(project);\n};\n\n/**\n * Slice Machine helpers shared to plugins and hooks.\n */\nexport class SliceMachineHelpers {\n\t/**\n\t * The Slice Machine project's metadata.\n\t *\n\t * @internal\n\t */\n\tprivate _project: SliceMachineProject;\n\n\tconstructor(project: SliceMachineProject) {\n\t\tthis._project = project;\n\t}\n\n\tgetProject = async (): Promise<SliceMachineProject> => {\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch {\n\t\t\t// noop\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\treturn {\n\t\t\t...this._project,\n\t\t\tconfig: sliceMachineConfig,\n\t\t};\n\t};\n\n\tupdateSliceMachineConfig = async (\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t\toptions?: UpdateSliceMachineConfigOptions,\n\t): Promise<void> => {\n\t\tconst { value: decodedSliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(sliceMachineConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config provided. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\t\tlet content = JSON.stringify(decodedSliceMachineConfig, null, 2);\n\n\t\tif (options?.format) {\n\t\t\tcontent = await this.format(content, configFilePath);\n\t\t}\n\n\t\tawait fs.writeFile(configFilePath, content);\n\t};\n\n\tformat = async (\n\t\tsource: string,\n\t\tfilePath?: string,\n\t\toptions?: FormatOptions,\n\t): Promise<string> => {\n\t\tlet formatted = stripIndent(source);\n\n\t\tconst prettierOptions = await prettier.resolveConfig(\n\t\t\tfilePath || this._project.root,\n\t\t);\n\n\t\tformatted = await prettier.format(formatted, {\n\t\t\t...prettierOptions,\n\t\t\tfilepath: filePath,\n\t\t\t...(options?.prettier ?? {}),\n\t\t});\n\n\t\tif (options?.includeNewlineAtEnd === false) {\n\t\t\tformatted = formatted.replace(/[\\r\\n]+$/, \"\");\n\t\t}\n\n\t\treturn formatted;\n\t};\n\n\tjoinPathFromRoot = (...paths: string[]): string => {\n\t\treturn path.join(this._project.root, ...paths);\n\t};\n}\n"],"names":["fs","decodeSliceMachineConfig","stripIndent","prettier","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6Ba,MAAA,4BAA4B,CACxC,YACwB;AACjB,SAAA,IAAI,oBAAoB,OAAO;AACvC;MAKa,oBAAmB;AAAA,EAQ/B,YAAY,SAA4B;AAFhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAMR,sCAAa,YAAyC;AAC/C,YAAA,iBAAiB,KAAK,iBAAiB,0BAA0B;AAEnE,UAAA;AACA,UAAA;AACH,cAAM,WAAW,MAAMA,cAAG,SAAS,gBAAgB,MAAM;AAC7C,oBAAA,KAAK,MAAM,QAAQ;AAAA,MAAA,QAC9B;AAAA,MAED;AAED,UAAI,CAAC,WAAW;AAET,cAAA,IAAI,MAAM,kBAAkB;AAAA,MAClC;AAED,YAAM,EAAE,OAAO,oBAAoB,MAAO,IACzCC,yBAAAA,yBAAyB,SAAS;AAEnC,UAAI,OAAO;AAEV,cAAM,IAAI,MAAM,mBAAmB,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,MAC5D;AAEM,aAAA;AAAA,QACN,GAAG,KAAK;AAAA,QACR,QAAQ;AAAA,MAAA;AAAA;AAIV,oDAA2B,OAC1B,oBACA,YACkB;AAClB,YAAM,EAAE,OAAO,2BAA2B,MAAO,IAChDA,yBAAAA,yBAAyB,kBAAkB;AAE5C,UAAI,OAAO;AAEV,cAAM,IAAI,MAAM,4BAA4B,MAAM,OAAO,KAAK,IAAI,GAAG;AAAA,MACrE;AAEK,YAAA,iBAAiB,KAAK,iBAAiB,0BAA0B;AACvE,UAAI,UAAU,KAAK,UAAU,2BAA2B,MAAM,CAAC;AAE/D,UAAI,mCAAS,QAAQ;AACpB,kBAAU,MAAM,KAAK,OAAO,SAAS,cAAc;AAAA,MACnD;AAEK,YAAAD,cAAG,UAAU,gBAAgB,OAAO;AAAA,IAAA;AAG3C,kCAAS,OACR,QACA,UACA,YACoB;AAChB,UAAA,YAAYE,uBAAY,MAAM;AAElC,YAAM,kBAAkB,MAAMC,oBAAS,cACtC,YAAY,KAAK,SAAS,IAAI;AAGnB,kBAAA,MAAMA,oBAAS,OAAO,WAAW;AAAA,QAC5C,GAAG;AAAA,QACH,UAAU;AAAA,QACV,IAAI,mCAAS,aAAY;OACzB;AAEG,WAAA,mCAAS,yBAAwB,OAAO;AAC/B,oBAAA,UAAU,QAAQ,YAAY,EAAE;AAAA,MAC5C;AAEM,aAAA;AAAA,IAAA;AAGR,4CAAmB,IAAI,UAA2B;AACjD,aAAOC,gBAAK,KAAK,KAAK,SAAS,MAAM,GAAG,KAAK;AAAA,IAAA;AAhF7C,SAAK,WAAW;AAAA,EACjB;AAiFA;;;"}
@@ -1,4 +1,4 @@
1
- import prettier from "prettier";
1
+ import * as prettier from "prettier";
2
2
  import { SliceMachineConfig, SliceMachineProject } from "./types";
3
3
  type UpdateSliceMachineConfigOptions = {
4
4
  format?: boolean;
@@ -6,7 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import * as path from "node:path";
8
8
  import * as fs from "node:fs/promises";
9
- import prettier from "prettier";
9
+ import * as prettier from "prettier";
10
10
  import { stripIndent } from "common-tags";
11
11
  import { decodeSliceMachineConfig } from "./lib/decodeSliceMachineConfig.js";
12
12
  const createSliceMachineHelpers = (project) => {
@@ -1 +1 @@
1
- {"version":3,"file":"createSliceMachineHelpers.js","sources":["../../src/createSliceMachineHelpers.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport prettier from \"prettier\";\nimport { stripIndent } from \"common-tags\";\n\nimport { decodeSliceMachineConfig } from \"./lib/decodeSliceMachineConfig\";\n\nimport { SliceMachineConfig, SliceMachineProject } from \"./types\";\n\ntype UpdateSliceMachineConfigOptions = {\n\tformat?: boolean;\n};\n\ntype FormatOptions = {\n\tprettier?: prettier.Options;\n\t/**\n\t * Determines if a newline is included at the end of the formatted result.\n\t *\n\t * @defaultValue `true`\n\t */\n\tincludeNewlineAtEnd?: boolean;\n};\n\n/**\n * Creates Slice Machine helpers.\n *\n * @internal\n */\nexport const createSliceMachineHelpers = (\n\tproject: SliceMachineProject,\n): SliceMachineHelpers => {\n\treturn new SliceMachineHelpers(project);\n};\n\n/**\n * Slice Machine helpers shared to plugins and hooks.\n */\nexport class SliceMachineHelpers {\n\t/**\n\t * The Slice Machine project's metadata.\n\t *\n\t * @internal\n\t */\n\tprivate _project: SliceMachineProject;\n\n\tconstructor(project: SliceMachineProject) {\n\t\tthis._project = project;\n\t}\n\n\tgetProject = async (): Promise<SliceMachineProject> => {\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch {\n\t\t\t// noop\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\treturn {\n\t\t\t...this._project,\n\t\t\tconfig: sliceMachineConfig,\n\t\t};\n\t};\n\n\tupdateSliceMachineConfig = async (\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t\toptions?: UpdateSliceMachineConfigOptions,\n\t): Promise<void> => {\n\t\tconst { value: decodedSliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(sliceMachineConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config provided. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\t\tlet content = JSON.stringify(decodedSliceMachineConfig, null, 2);\n\n\t\tif (options?.format) {\n\t\t\tcontent = await this.format(content, configFilePath);\n\t\t}\n\n\t\tawait fs.writeFile(configFilePath, content);\n\t};\n\n\tformat = async (\n\t\tsource: string,\n\t\tfilePath?: string,\n\t\toptions?: FormatOptions,\n\t): Promise<string> => {\n\t\tlet formatted = stripIndent(source);\n\n\t\tconst prettierOptions = await prettier.resolveConfig(\n\t\t\tfilePath || this._project.root,\n\t\t);\n\n\t\tformatted = await prettier.format(formatted, {\n\t\t\t...prettierOptions,\n\t\t\tfilepath: filePath,\n\t\t\t...(options?.prettier ?? {}),\n\t\t});\n\n\t\tif (options?.includeNewlineAtEnd === false) {\n\t\t\tformatted = formatted.replace(/[\\r\\n]+$/, \"\");\n\t\t}\n\n\t\treturn formatted;\n\t};\n\n\tjoinPathFromRoot = (...paths: string[]): string => {\n\t\treturn path.join(this._project.root, ...paths);\n\t};\n}\n"],"names":[],"mappings":";;;;;;;;;;;AA6Ba,MAAA,4BAA4B,CACxC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AU;AAAA,QACV,IAAI,mCAAS,aAAY;OACzB;AAEG,WAAA,mCAAS,yBAAwB,OAAO;AAC/B,oBAAA,UAAU,QAAQ,YAAY,EAAE;AAAA,MAC5C;AAEM,aAAA;AAAA,IAAA;AAGR,4CAAmB,IAAI,UAA2B;AACjD,aAAO,KAAK,KAAK,KAAK,SAAS,MAAM,GAAG,KAAK;AAAA,IAAA;AAhF7C,SAAK,WAAW;AAAA,EACjB;AAiFA;"}
1
+ {"version":3,"file":"createSliceMachineHelpers.js","sources":["../../src/createSliceMachineHelpers.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs/promises\";\n\nimport * as prettier from \"prettier\";\nimport { stripIndent } from \"common-tags\";\n\nimport { decodeSliceMachineConfig } from \"./lib/decodeSliceMachineConfig\";\n\nimport { SliceMachineConfig, SliceMachineProject } from \"./types\";\n\ntype UpdateSliceMachineConfigOptions = {\n\tformat?: boolean;\n};\n\ntype FormatOptions = {\n\tprettier?: prettier.Options;\n\t/**\n\t * Determines if a newline is included at the end of the formatted result.\n\t *\n\t * @defaultValue `true`\n\t */\n\tincludeNewlineAtEnd?: boolean;\n};\n\n/**\n * Creates Slice Machine helpers.\n *\n * @internal\n */\nexport const createSliceMachineHelpers = (\n\tproject: SliceMachineProject,\n): SliceMachineHelpers => {\n\treturn new SliceMachineHelpers(project);\n};\n\n/**\n * Slice Machine helpers shared to plugins and hooks.\n */\nexport class SliceMachineHelpers {\n\t/**\n\t * The Slice Machine project's metadata.\n\t *\n\t * @internal\n\t */\n\tprivate _project: SliceMachineProject;\n\n\tconstructor(project: SliceMachineProject) {\n\t\tthis._project = project;\n\t}\n\n\tgetProject = async (): Promise<SliceMachineProject> => {\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch {\n\t\t\t// noop\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\treturn {\n\t\t\t...this._project,\n\t\t\tconfig: sliceMachineConfig,\n\t\t};\n\t};\n\n\tupdateSliceMachineConfig = async (\n\t\tsliceMachineConfig: SliceMachineConfig,\n\t\toptions?: UpdateSliceMachineConfigOptions,\n\t): Promise<void> => {\n\t\tconst { value: decodedSliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(sliceMachineConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config provided. ${error.errors.join(\", \")}`);\n\t\t}\n\n\t\tconst configFilePath = this.joinPathFromRoot(\"slicemachine.config.json\");\n\t\tlet content = JSON.stringify(decodedSliceMachineConfig, null, 2);\n\n\t\tif (options?.format) {\n\t\t\tcontent = await this.format(content, configFilePath);\n\t\t}\n\n\t\tawait fs.writeFile(configFilePath, content);\n\t};\n\n\tformat = async (\n\t\tsource: string,\n\t\tfilePath?: string,\n\t\toptions?: FormatOptions,\n\t): Promise<string> => {\n\t\tlet formatted = stripIndent(source);\n\n\t\tconst prettierOptions = await prettier.resolveConfig(\n\t\t\tfilePath || this._project.root,\n\t\t);\n\n\t\tformatted = await prettier.format(formatted, {\n\t\t\t...prettierOptions,\n\t\t\tfilepath: filePath,\n\t\t\t...(options?.prettier ?? {}),\n\t\t});\n\n\t\tif (options?.includeNewlineAtEnd === false) {\n\t\t\tformatted = formatted.replace(/[\\r\\n]+$/, \"\");\n\t\t}\n\n\t\treturn formatted;\n\t};\n\n\tjoinPathFromRoot = (...paths: string[]): string => {\n\t\treturn path.join(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AS,IAAI;AAGnB,kBAAA,MAAM,SAAS,OAAO,WAAW;AAAA,QAC5C,GAAG;AAAA,QACH,UAAU;AAAA,QACV,IAAI,mCAAS,aAAY;OACzB;AAEG,WAAA,mCAAS,yBAAwB,OAAO;AAC/B,oBAAA,UAAU,QAAQ,YAAY,EAAE;AAAA,MAC5C;AAEM,aAAA;AAAA,IAAA;AAGR,4CAAmB,IAAI,UAA2B;AACjD,aAAO,KAAK,KAAK,KAAK,SAAS,MAAM,GAAG,KAAK;AAAA,IAAA;AAhF7C,SAAK,WAAW;AAAA,EACjB;AAiFA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/plugin-kit",
3
- "version": "0.4.39-beta.6",
3
+ "version": "0.4.39-beta.8",
4
4
  "description": "A set of helpers to develop and run Slice Machine plugins",
5
5
  "keywords": [
6
6
  "typescript",
@@ -1,7 +1,7 @@
1
1
  import * as path from "node:path";
2
2
  import * as fs from "node:fs/promises";
3
3
 
4
- import prettier from "prettier";
4
+ import * as prettier from "prettier";
5
5
  import { stripIndent } from "common-tags";
6
6
 
7
7
  import { decodeSliceMachineConfig } from "./lib/decodeSliceMachineConfig";