@keycloakify/svelte 0.2.5 → 0.2.7

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.
@@ -784,7 +784,8 @@ async function command(params) {
784
784
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
785
785
 
786
786
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
787
- /* harmony export */ J: () => (/* binding */ getThisCodebaseRootDirPath)
787
+ /* harmony export */ J: () => (/* binding */ getThisCodebaseRootDirPath),
788
+ /* harmony export */ x: () => (/* binding */ getNearestPackageJsonDirPath)
788
789
  /* harmony export */ });
789
790
  /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(896);
790
791
  /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_0__);
@@ -809,6 +810,12 @@ function getThisCodebaseRootDirPath() {
809
810
  }
810
811
  return (result = getThisCodebaseRootDirPath_rec(__dirname));
811
812
  }
813
+ function getNearestPackageJsonDirPath(dirPath) {
814
+ if (fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(path__WEBPACK_IMPORTED_MODULE_1__.join(dirPath, 'package.json'))) {
815
+ return dirPath;
816
+ }
817
+ return getNearestPackageJsonDirPath(path__WEBPACK_IMPORTED_MODULE_1__.join(dirPath, '..'));
818
+ }
812
819
 
813
820
 
814
821
  /***/ }),
@@ -837,13 +844,35 @@ function kebabCaseToCamelCase(kebabCaseString) {
837
844
  /* harmony export */ });
838
845
  /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(928);
839
846
  /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
847
+ /* harmony import */ var _getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(697);
848
+
840
849
 
841
850
  let cache = undefined;
851
+ /** NOTE: Careful, this function can fail when the binary
852
+ * Used is not in the node_modules directory of the project
853
+ * (for example when running tests with vscode extension we'll get
854
+ * '/Users/dylan/.vscode/extensions/vitest.explorer-1.16.0/dist/worker.js'
855
+ *
856
+ * instead of
857
+ * '/Users/joseph/.nvm/versions/node/v22.12.0/bin/node'
858
+ * or
859
+ * '/Users/joseph/github/keycloakify-starter/node_modules/.bin/vite'
860
+ *
861
+ * as the value of process.argv[1]
862
+ */
842
863
  function getNodeModulesBinDirPath() {
843
864
  if (cache !== undefined) {
844
865
  return cache;
845
866
  }
846
867
  const binPath = process.argv[1];
868
+ special_case_running_not_from_distribution: {
869
+ if (!binPath.endsWith('.ts')) {
870
+ break special_case_running_not_from_distribution;
871
+ }
872
+ const packageJsonDirPath = (0,_getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_1__/* .getNearestPackageJsonDirPath */ .x)((0,path__WEBPACK_IMPORTED_MODULE_0__.dirname)(binPath));
873
+ const nodeModulesBinDirPath = (0,path__WEBPACK_IMPORTED_MODULE_0__.join)(packageJsonDirPath, 'node_modules', '.bin');
874
+ return nodeModulesBinDirPath;
875
+ }
847
876
  const segments = ['.bin'];
848
877
  let foundNodeModules = false;
849
878
  for (const segment of binPath.split(path__WEBPACK_IMPORTED_MODULE_0__.sep).reverse()) {
@@ -859,42 +888,15 @@ function getNodeModulesBinDirPath() {
859
888
  }
860
889
  segments.unshift(segment);
861
890
  }
891
+ if (!foundNodeModules) {
892
+ throw new Error(`Could not find node_modules in path ${binPath}`);
893
+ }
862
894
  const nodeModulesBinDirPath = segments.join(path__WEBPACK_IMPORTED_MODULE_0__.sep);
863
895
  cache = nodeModulesBinDirPath;
864
896
  return nodeModulesBinDirPath;
865
897
  }
866
898
 
867
899
 
868
- /***/ }),
869
-
870
- /***/ 704:
871
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
872
-
873
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
874
- /* harmony export */ M: () => (/* binding */ readThisNpmPackageVersion)
875
- /* harmony export */ });
876
- /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(896);
877
- /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_0__);
878
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(928);
879
- /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
880
- /* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(966);
881
- /* harmony import */ var _getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(697);
882
-
883
-
884
-
885
-
886
- let cache = undefined;
887
- function readThisNpmPackageVersion() {
888
- if (cache !== undefined) {
889
- return cache;
890
- }
891
- const version = JSON.parse(fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync((0,path__WEBPACK_IMPORTED_MODULE_1__.join)((0,_getThisCodebaseRootDirPath__WEBPACK_IMPORTED_MODULE_2__/* .getThisCodebaseRootDirPath */ .J)(), 'package.json')).toString('utf8'))['version'];
892
- (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_3__/* .assert */ .v)(typeof version === 'string');
893
- cache = version;
894
- return version;
895
- }
896
-
897
-
898
900
  /***/ }),
899
901
 
900
902
  /***/ 479:
@@ -915,9 +917,8 @@ function readThisNpmPackageVersion() {
915
917
  /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_3__);
916
918
  /* harmony import */ var tsafe_assert__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(966);
917
919
  /* harmony import */ var tsafe_id__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(94);
918
- /* harmony import */ var tsafe_symToStr__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(886);
920
+ /* harmony import */ var tsafe_symToStr__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(886);
919
921
  /* harmony import */ var _nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(399);
920
- /* harmony import */ var _readThisNpmPackageVersion__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(704);
921
922
  /* module decorator */ module = __webpack_require__.hmd(module);
922
923
 
923
924
 
@@ -927,8 +928,6 @@ function readThisNpmPackageVersion() {
927
928
 
928
929
 
929
930
 
930
-
931
-
932
931
  getIsPrettierAvailable.cache = (0,tsafe_id__WEBPACK_IMPORTED_MODULE_4__.id)(undefined);
933
932
  async function getIsPrettierAvailable() {
934
933
  var _a;
@@ -950,36 +949,32 @@ async function getPrettier() {
950
949
  }
951
950
  let prettier = (0,tsafe_id__WEBPACK_IMPORTED_MODULE_4__.id)(undefined);
952
951
  import_prettier: {
953
- // NOTE: When module is linked we want to make sure we import the correct version
954
- // of prettier, that is the one of the project, not the one of this repo.
955
- // So we do a sketchy eval to bypass ncc.
956
- // We make sure to only do that when linking, otherwise we import properly.
957
- if ((0,_readThisNpmPackageVersion__WEBPACK_IMPORTED_MODULE_7__/* .readThisNpmPackageVersion */ .M)().startsWith('0.0.0')) {
958
- const prettierDirPath = (0,path__WEBPACK_IMPORTED_MODULE_3__.resolve)((0,path__WEBPACK_IMPORTED_MODULE_3__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_5__/* .getNodeModulesBinDirPath */ .p)(), '..', 'prettier'));
959
- const isCJS = true && module.exports;
960
- if (isCJS) {
961
- eval(`${(0,tsafe_symToStr__WEBPACK_IMPORTED_MODULE_8__/* .symToStr */ .I)({ prettier })} = require("${prettierDirPath}")`);
962
- }
963
- else {
964
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
965
- prettier = await new Promise((_resolve) => {
966
- eval(`import("file:///${(0,path__WEBPACK_IMPORTED_MODULE_3__.join)(prettierDirPath, 'index.mjs').replace(/\\/g, '/')}").then(prettier => _resolve(prettier))`);
967
- });
968
- }
969
- (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_6__/* .assert */ .v)(!(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_6__.is)(prettier));
970
- break import_prettier;
952
+ const prettierDirPath = (0,path__WEBPACK_IMPORTED_MODULE_3__.resolve)((0,path__WEBPACK_IMPORTED_MODULE_3__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_5__/* .getNodeModulesBinDirPath */ .p)(), '..', 'prettier'));
953
+ const isCJS = true && module.exports;
954
+ if (isCJS) {
955
+ eval(`${(0,tsafe_symToStr__WEBPACK_IMPORTED_MODULE_7__/* .symToStr */ .I)({ prettier })} = require("${prettierDirPath}")`);
956
+ }
957
+ else {
958
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
959
+ prettier = await new Promise((_resolve) => {
960
+ eval(`import("file:///${(0,path__WEBPACK_IMPORTED_MODULE_3__.join)(prettierDirPath, 'index.mjs').replace(/\\/g, '/')}").then(prettier => _resolve(prettier))`);
961
+ });
971
962
  }
972
- prettier = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 261));
963
+ (0,tsafe_assert__WEBPACK_IMPORTED_MODULE_6__/* .assert */ .v)(!(0,tsafe_assert__WEBPACK_IMPORTED_MODULE_6__.is)(prettier));
964
+ break import_prettier;
973
965
  }
974
966
  const configHash = await (async () => {
975
- const configFilePath = await prettier.resolveConfigFile((0,path__WEBPACK_IMPORTED_MODULE_3__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_5__/* .getNodeModulesBinDirPath */ .p)(), '..'));
967
+ const configFilePath = await prettier.resolveConfigFile((0,path__WEBPACK_IMPORTED_MODULE_3__.join)((0,_nodeModulesBinDirPath__WEBPACK_IMPORTED_MODULE_5__/* .getNodeModulesBinDirPath */ .p)(), '..', '..'));
976
968
  if (configFilePath === null) {
977
969
  return '';
978
970
  }
979
971
  const data = await fs_promises__WEBPACK_IMPORTED_MODULE_2__.readFile(configFilePath);
980
972
  return crypto__WEBPACK_IMPORTED_MODULE_1__.createHash('sha256').update(data).digest('hex');
981
973
  })();
982
- const prettierAndConfig = { prettier, configHash };
974
+ const prettierAndConfig = {
975
+ prettier,
976
+ configHash,
977
+ };
983
978
  getPrettier.cache = prettierAndConfig;
984
979
  return prettierAndConfig;
985
980
  }
@@ -988,18 +983,20 @@ async function runPrettier(params) {
988
983
  let formattedSourceCode;
989
984
  try {
990
985
  const { prettier } = await getPrettier();
991
- const { ignored, inferredParser } = await prettier.getFileInfo(filePath, { resolveConfig: true });
992
- if (ignored) {
986
+ const { ignored, inferredParser } = await prettier.getFileInfo(filePath, {
987
+ resolveConfig: true,
988
+ });
989
+ if (ignored || inferredParser === null) {
993
990
  return sourceCode;
994
991
  }
995
992
  const config = await prettier.resolveConfig(filePath);
996
- formattedSourceCode = await prettier.format(sourceCode, Object.assign(Object.assign({}, config), { filePath, parser: inferredParser !== null && inferredParser !== void 0 ? inferredParser : undefined }));
993
+ formattedSourceCode = await prettier.format(typeof sourceCode === 'string' ? sourceCode : sourceCode.toString('utf8'), Object.assign(Object.assign({}, config), { filePath, parser: inferredParser }));
997
994
  }
998
995
  catch (error) {
999
996
  console.log(chalk__WEBPACK_IMPORTED_MODULE_0___default().red(`You probably need to upgrade the version of prettier in your project`));
1000
997
  throw error;
1001
998
  }
1002
- return formattedSourceCode;
999
+ return typeof sourceCode === 'string' ? formattedSourceCode : Buffer.from(formattedSourceCode, 'utf8');
1003
1000
  }
1004
1001
 
1005
1002
 
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import * as __WEBPACK_EXTERNAL_MODULE_prettier__ from "prettier";
3
2
  import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
4
3
  /******/ var __webpack_modules__ = ({
5
4
 
@@ -1867,7 +1866,8 @@ const LOGIN_THEME_PAGE_IDS = [
1867
1866
  "login-x509-info.ftl",
1868
1867
  "webauthn-error.ftl",
1869
1868
  "login-passkeys-conditional-authenticate.ftl",
1870
- "login-idp-link-confirm-override.ftl"
1869
+ "login-idp-link-confirm-override.ftl",
1870
+ "select-organization.ftl"
1871
1871
  ];
1872
1872
  const ACCOUNT_THEME_PAGE_IDS = [
1873
1873
  "password.ftl",
@@ -2033,13 +2033,6 @@ module.exports = {
2033
2033
  };
2034
2034
 
2035
2035
 
2036
- /***/ }),
2037
-
2038
- /***/ 261:
2039
- /***/ ((module) => {
2040
-
2041
- module.exports = __WEBPACK_EXTERNAL_MODULE_prettier__;
2042
-
2043
2036
  /***/ }),
2044
2037
 
2045
2038
  /***/ 317:
@@ -2446,7 +2439,7 @@ const { buildContext, commandName } = readParams({ apiVersion: 'v1' });
2446
2439
  return;
2447
2440
  case 'initialize-account-theme':
2448
2441
  {
2449
- const { command } = await Promise.all(/* import() */[__nccwpck_require__.e(135), __nccwpck_require__.e(709)]).then(__nccwpck_require__.bind(__nccwpck_require__, 709));
2442
+ const { command } = await Promise.all(/* import() */[__nccwpck_require__.e(343), __nccwpck_require__.e(709)]).then(__nccwpck_require__.bind(__nccwpck_require__, 709));
2450
2443
  command({ buildContext });
2451
2444
  }
2452
2445
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keycloakify/svelte",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Svelte Components for Keycloakify",
5
5
  "keywords": [
6
6
  "keycloak",
@@ -437,36 +437,36 @@
437
437
  "svelte": "^5.0.0"
438
438
  },
439
439
  "devDependencies": {
440
- "@sveltejs/adapter-auto": "^6.1.0",
441
- "@sveltejs/kit": "^2.41.0",
442
- "@sveltejs/package": "^2.5.2",
443
- "@sveltejs/vite-plugin-svelte": "^6.2.0",
440
+ "@sveltejs/adapter-auto": "^7.0.0",
441
+ "@sveltejs/kit": "^2.48.5",
442
+ "@sveltejs/package": "^2.5.4",
443
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
444
444
  "@types/eslint": "^9.6.1",
445
- "@types/node": "^22.15.18",
446
- "@vercel/ncc": "^0.38.3",
445
+ "@types/node": "^24.10.1",
446
+ "@vercel/ncc": "^0.38.4",
447
447
  "cli-select": "^1.1.2",
448
448
  "conventional-changelog": "^7.1.1",
449
- "conventional-changelog-angular": "^8.0.0",
450
- "eslint": "^9.35.0",
449
+ "conventional-changelog-angular": "^8.1.0",
450
+ "eslint": "^9.39.1",
451
451
  "eslint-config-prettier": "^10.1.8",
452
452
  "eslint-plugin-prettier": "^5.5.4",
453
- "eslint-plugin-svelte": "^3.12.3",
454
- "eslint-plugin-unused-imports": "^4.2.0",
455
- "globals": "^16.4.0",
453
+ "eslint-plugin-svelte": "^3.13.0",
454
+ "eslint-plugin-unused-imports": "^4.3.0",
455
+ "globals": "^16.5.0",
456
456
  "husky": "^9.1.7",
457
- "keycloakify": "^11.9.6",
458
- "npm-check-updates": "^18.1.1",
457
+ "keycloakify": "^11.11.3",
458
+ "npm-check-updates": "^19.1.2",
459
459
  "prettier": "^3.6.2",
460
460
  "prettier-plugin-svelte": "^3.4.0",
461
- "publint": "^0.3.12",
462
- "svelte": "^5.38.10",
463
- "svelte-check": "^4.3.1",
461
+ "publint": "^0.3.15",
462
+ "svelte": "^5.43.7",
463
+ "svelte-check": "^4.3.4",
464
464
  "ts-node": "^10.9.2",
465
465
  "tsx": "4.20.4",
466
- "typescript": "~5.9.2",
467
- "typescript-eslint": "^8.44.0",
468
- "vite": "^7.1.5",
469
- "zod": "^4.1.8"
466
+ "typescript": "~5.9.3",
467
+ "typescript-eslint": "^8.46.4",
468
+ "vite": "^7.2.2",
469
+ "zod": "^4.1.12"
470
470
  },
471
471
  "bin": {
472
472
  "_keycloakify-custom-handler": "keycloakify-svelte/bin/index.js"
@@ -20,3 +20,10 @@ export function getThisCodebaseRootDirPath(): string {
20
20
 
21
21
  return (result = getThisCodebaseRootDirPath_rec(__dirname));
22
22
  }
23
+
24
+ export function getNearestPackageJsonDirPath(dirPath: string): string {
25
+ if (fs.existsSync(path.join(dirPath, 'package.json'))) {
26
+ return dirPath;
27
+ }
28
+ return getNearestPackageJsonDirPath(path.join(dirPath, '..'));
29
+ }
@@ -1,7 +1,20 @@
1
- import { sep as pathSep } from 'path';
1
+ import { dirname as pathDirname, join as pathJoin, sep as pathSep } from 'path';
2
+ import { getNearestPackageJsonDirPath } from './getThisCodebaseRootDirPath';
2
3
 
3
4
  let cache: string | undefined = undefined;
4
5
 
6
+ /** NOTE: Careful, this function can fail when the binary
7
+ * Used is not in the node_modules directory of the project
8
+ * (for example when running tests with vscode extension we'll get
9
+ * '/Users/dylan/.vscode/extensions/vitest.explorer-1.16.0/dist/worker.js'
10
+ *
11
+ * instead of
12
+ * '/Users/joseph/.nvm/versions/node/v22.12.0/bin/node'
13
+ * or
14
+ * '/Users/joseph/github/keycloakify-starter/node_modules/.bin/vite'
15
+ *
16
+ * as the value of process.argv[1]
17
+ */
5
18
  export function getNodeModulesBinDirPath() {
6
19
  if (cache !== undefined) {
7
20
  return cache;
@@ -9,6 +22,18 @@ export function getNodeModulesBinDirPath() {
9
22
 
10
23
  const binPath = process.argv[1];
11
24
 
25
+ special_case_running_not_from_distribution: {
26
+ if (!binPath.endsWith('.ts')) {
27
+ break special_case_running_not_from_distribution;
28
+ }
29
+
30
+ const packageJsonDirPath = getNearestPackageJsonDirPath(pathDirname(binPath));
31
+
32
+ const nodeModulesBinDirPath = pathJoin(packageJsonDirPath, 'node_modules', '.bin');
33
+
34
+ return nodeModulesBinDirPath;
35
+ }
36
+
12
37
  const segments: string[] = ['.bin'];
13
38
 
14
39
  let foundNodeModules = false;
@@ -30,6 +55,10 @@ export function getNodeModulesBinDirPath() {
30
55
  segments.unshift(segment);
31
56
  }
32
57
 
58
+ if (!foundNodeModules) {
59
+ throw new Error(`Could not find node_modules in path ${binPath}`);
60
+ }
61
+
33
62
  const nodeModulesBinDirPath = segments.join(pathSep);
34
63
 
35
64
  cache = nodeModulesBinDirPath;
@@ -2,12 +2,10 @@ import chalk from 'chalk';
2
2
  import * as crypto from 'crypto';
3
3
  import * as fsPr from 'fs/promises';
4
4
  import { join as pathJoin, resolve as pathResolve } from 'path';
5
- import { assert } from 'tsafe/assert';
5
+ import { assert, is } from 'tsafe/assert';
6
6
  import { id } from 'tsafe/id';
7
- import { is } from 'tsafe/is';
8
7
  import { symToStr } from 'tsafe/symToStr';
9
8
  import { getNodeModulesBinDirPath } from './nodeModulesBinDirPath';
10
- import { readThisNpmPackageVersion } from './readThisNpmPackageVersion';
11
9
 
12
10
  getIsPrettierAvailable.cache = id<boolean | undefined>(undefined);
13
11
 
@@ -29,7 +27,10 @@ export async function getIsPrettierAvailable(): Promise<boolean> {
29
27
  return isPrettierAvailable;
30
28
  }
31
29
 
32
- type PrettierAndConfigHash = { prettier: typeof import('prettier'); configHash: string };
30
+ type PrettierAndConfigHash = {
31
+ prettier: typeof import('prettier');
32
+ configHash: string;
33
+ };
33
34
 
34
35
  getPrettier.cache = id<PrettierAndConfigHash | undefined>(undefined);
35
36
 
@@ -43,36 +44,28 @@ export async function getPrettier(): Promise<PrettierAndConfigHash> {
43
44
  let prettier = id<typeof import('prettier') | undefined>(undefined);
44
45
 
45
46
  import_prettier: {
46
- // NOTE: When module is linked we want to make sure we import the correct version
47
- // of prettier, that is the one of the project, not the one of this repo.
48
- // So we do a sketchy eval to bypass ncc.
49
- // We make sure to only do that when linking, otherwise we import properly.
50
- if (readThisNpmPackageVersion().startsWith('0.0.0')) {
51
- const prettierDirPath = pathResolve(pathJoin(getNodeModulesBinDirPath(), '..', 'prettier'));
52
-
53
- const isCJS = typeof module !== 'undefined' && module.exports;
54
-
55
- if (isCJS) {
56
- eval(`${symToStr({ prettier })} = require("${prettierDirPath}")`);
57
- } else {
58
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
59
- prettier = await new Promise((_resolve) => {
60
- eval(
61
- `import("file:///${pathJoin(prettierDirPath, 'index.mjs').replace(/\\/g, '/')}").then(prettier => _resolve(prettier))`,
62
- );
63
- });
64
- }
65
-
66
- assert(!is<undefined>(prettier));
67
-
68
- break import_prettier;
47
+ const prettierDirPath = pathResolve(pathJoin(getNodeModulesBinDirPath(), '..', 'prettier'));
48
+
49
+ const isCJS = typeof module !== 'undefined' && module.exports;
50
+
51
+ if (isCJS) {
52
+ eval(`${symToStr({ prettier })} = require("${prettierDirPath}")`);
53
+ } else {
54
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
55
+ prettier = await new Promise((_resolve) => {
56
+ eval(
57
+ `import("file:///${pathJoin(prettierDirPath, 'index.mjs').replace(/\\/g, '/')}").then(prettier => _resolve(prettier))`,
58
+ );
59
+ });
69
60
  }
70
61
 
71
- prettier = await import('prettier');
62
+ assert(!is<undefined>(prettier));
63
+
64
+ break import_prettier;
72
65
  }
73
66
 
74
67
  const configHash = await (async () => {
75
- const configFilePath = await prettier.resolveConfigFile(pathJoin(getNodeModulesBinDirPath(), '..'));
68
+ const configFilePath = await prettier.resolveConfigFile(pathJoin(getNodeModulesBinDirPath(), '..', '..'));
76
69
 
77
70
  if (configFilePath === null) {
78
71
  return '';
@@ -83,14 +76,19 @@ export async function getPrettier(): Promise<PrettierAndConfigHash> {
83
76
  return crypto.createHash('sha256').update(data).digest('hex');
84
77
  })();
85
78
 
86
- const prettierAndConfig: PrettierAndConfigHash = { prettier, configHash };
79
+ const prettierAndConfig: PrettierAndConfigHash = {
80
+ prettier,
81
+ configHash,
82
+ };
87
83
 
88
84
  getPrettier.cache = prettierAndConfig;
89
85
 
90
86
  return prettierAndConfig;
91
87
  }
92
88
 
93
- export async function runPrettier(params: { sourceCode: string; filePath: string }): Promise<string> {
89
+ export async function runPrettier(params: { sourceCode: string; filePath: string }): Promise<string>;
90
+ export async function runPrettier(params: { sourceCode: Buffer; filePath: string }): Promise<Buffer>;
91
+ export async function runPrettier(params: { sourceCode: string | Buffer; filePath: string }): Promise<string | Buffer> {
94
92
  const { sourceCode, filePath } = params;
95
93
 
96
94
  let formattedSourceCode: string;
@@ -98,24 +96,29 @@ export async function runPrettier(params: { sourceCode: string; filePath: string
98
96
  try {
99
97
  const { prettier } = await getPrettier();
100
98
 
101
- const { ignored, inferredParser } = await prettier.getFileInfo(filePath, { resolveConfig: true });
99
+ const { ignored, inferredParser } = await prettier.getFileInfo(filePath, {
100
+ resolveConfig: true,
101
+ });
102
102
 
103
- if (ignored) {
103
+ if (ignored || inferredParser === null) {
104
104
  return sourceCode;
105
105
  }
106
106
 
107
107
  const config = await prettier.resolveConfig(filePath);
108
108
 
109
- formattedSourceCode = await prettier.format(sourceCode, {
110
- ...config,
111
- filePath,
112
- parser: inferredParser ?? undefined,
113
- });
109
+ formattedSourceCode = await prettier.format(
110
+ typeof sourceCode === 'string' ? sourceCode : sourceCode.toString('utf8'),
111
+ {
112
+ ...config,
113
+ filePath,
114
+ parser: inferredParser,
115
+ },
116
+ );
114
117
  } catch (error) {
115
118
  console.log(chalk.red(`You probably need to upgrade the version of prettier in your project`));
116
119
 
117
120
  throw error;
118
121
  }
119
122
 
120
- return formattedSourceCode;
123
+ return typeof sourceCode === 'string' ? formattedSourceCode : Buffer.from(formattedSourceCode, 'utf8');
121
124
  }
@@ -1,22 +0,0 @@
1
- import * as fs from 'fs';
2
- import { join as pathJoin } from 'path';
3
- import { assert } from 'tsafe/assert';
4
- import { getThisCodebaseRootDirPath } from './getThisCodebaseRootDirPath';
5
-
6
- let cache: string | undefined = undefined;
7
-
8
- export function readThisNpmPackageVersion(): string {
9
- if (cache !== undefined) {
10
- return cache;
11
- }
12
-
13
- const version = JSON.parse(fs.readFileSync(pathJoin(getThisCodebaseRootDirPath(), 'package.json')).toString('utf8'))[
14
- 'version'
15
- ];
16
-
17
- assert(typeof version === 'string');
18
-
19
- cache = version;
20
-
21
- return version;
22
- }