@dittowords/cli 3.10.1 → 4.0.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 (134) hide show
  1. package/README.md +125 -36
  2. package/bin/add-project.js +101 -33
  3. package/bin/add-project.js.map +1 -1
  4. package/bin/api.js +49 -15
  5. package/bin/api.js.map +1 -1
  6. package/bin/component-folders.js +56 -7
  7. package/bin/component-folders.js.map +1 -1
  8. package/bin/config.js +206 -170
  9. package/bin/config.js.map +1 -1
  10. package/bin/config.test.js +92 -0
  11. package/bin/config.test.js.map +1 -0
  12. package/bin/consts.js +64 -18
  13. package/bin/consts.js.map +1 -1
  14. package/bin/ditto.js +250 -200
  15. package/bin/ditto.js.map +1 -1
  16. package/bin/generate-suggestions.js +155 -78
  17. package/bin/generate-suggestions.js.map +1 -1
  18. package/bin/generate-suggestions.test.js +189 -0
  19. package/bin/generate-suggestions.test.js.map +1 -0
  20. package/bin/http/fetchComponentFolders.js +60 -8
  21. package/bin/http/fetchComponentFolders.js.map +1 -1
  22. package/bin/http/fetchComponents.js +65 -18
  23. package/bin/http/fetchComponents.js.map +1 -1
  24. package/bin/http/fetchVariants.js +74 -14
  25. package/bin/http/fetchVariants.js.map +1 -1
  26. package/bin/http/importComponents.js +100 -49
  27. package/bin/http/importComponents.js.map +1 -1
  28. package/bin/importComponents.js +61 -10
  29. package/bin/importComponents.js.map +1 -1
  30. package/bin/init/init.js +120 -44
  31. package/bin/init/init.js.map +1 -1
  32. package/bin/init/project.js +160 -83
  33. package/bin/init/project.js.map +1 -1
  34. package/bin/init/project.test.js +49 -0
  35. package/bin/init/project.test.js.map +1 -0
  36. package/bin/init/token.js +134 -74
  37. package/bin/init/token.js.map +1 -1
  38. package/bin/init/token.test.js +69 -0
  39. package/bin/init/token.test.js.map +1 -0
  40. package/bin/output.js +72 -30
  41. package/bin/output.js.map +1 -1
  42. package/bin/pull.js +424 -213
  43. package/bin/pull.js.map +1 -1
  44. package/bin/pull.test.js +410 -0
  45. package/bin/pull.test.js.map +1 -0
  46. package/bin/remove-project.js +91 -27
  47. package/bin/remove-project.js.map +1 -1
  48. package/bin/replace.js +140 -100
  49. package/bin/replace.js.map +1 -1
  50. package/bin/replace.test.js +155 -0
  51. package/bin/replace.test.js.map +1 -0
  52. package/bin/sentry-test.js.map +1 -0
  53. package/bin/types.js +20 -2
  54. package/bin/types.js.map +1 -1
  55. package/bin/utils/cleanFileName.js +32 -8
  56. package/bin/utils/cleanFileName.js.map +1 -1
  57. package/bin/utils/createSentryContext.js +43 -0
  58. package/bin/utils/createSentryContext.js.map +1 -0
  59. package/bin/utils/generateJsDriver.js +114 -51
  60. package/bin/utils/generateJsDriver.js.map +1 -1
  61. package/bin/utils/getSelectedProjects.js +58 -52
  62. package/bin/utils/getSelectedProjects.js.map +1 -1
  63. package/bin/utils/processMetaOption.js +36 -11
  64. package/bin/utils/processMetaOption.js.map +1 -1
  65. package/bin/utils/processMetaOption.test.js +45 -0
  66. package/bin/utils/processMetaOption.test.js.map +1 -0
  67. package/bin/utils/projectsToText.js +52 -19
  68. package/bin/utils/projectsToText.js.map +1 -1
  69. package/bin/utils/promptForProject.js +89 -36
  70. package/bin/utils/promptForProject.js.map +1 -1
  71. package/bin/utils/quit.js +36 -7
  72. package/bin/utils/quit.js.map +1 -1
  73. package/bin/utils/sourcesToText.js +51 -19
  74. package/bin/utils/sourcesToText.js.map +1 -1
  75. package/etsc.config.js +13 -0
  76. package/lib/config.ts +27 -8
  77. package/lib/ditto.ts +6 -0
  78. package/lib/init/project.ts +3 -3
  79. package/lib/pull.ts +190 -52
  80. package/lib/types.ts +24 -7
  81. package/lib/utils/createSentryContext.ts +20 -0
  82. package/lib/utils/generateJsDriver.ts +40 -6
  83. package/lib/utils/quit.ts +2 -3
  84. package/package.json +10 -6
  85. package/tsconfig.json +4 -1
  86. package/bin/lib/add-project.js +0 -36
  87. package/bin/lib/add-project.js.map +0 -1
  88. package/bin/lib/api.js +0 -20
  89. package/bin/lib/api.js.map +0 -1
  90. package/bin/lib/config.js +0 -202
  91. package/bin/lib/config.js.map +0 -1
  92. package/bin/lib/consts.js +0 -21
  93. package/bin/lib/consts.js.map +0 -1
  94. package/bin/lib/ditto.js +0 -121
  95. package/bin/lib/ditto.js.map +0 -1
  96. package/bin/lib/generate-suggestions.js +0 -71
  97. package/bin/lib/generate-suggestions.js.map +0 -1
  98. package/bin/lib/http/fetchComponents.js +0 -13
  99. package/bin/lib/http/fetchComponents.js.map +0 -1
  100. package/bin/lib/http/fetchVariants.js +0 -26
  101. package/bin/lib/http/fetchVariants.js.map +0 -1
  102. package/bin/lib/init/init.js +0 -50
  103. package/bin/lib/init/init.js.map +0 -1
  104. package/bin/lib/init/project.js +0 -108
  105. package/bin/lib/init/project.js.map +0 -1
  106. package/bin/lib/init/token.js +0 -91
  107. package/bin/lib/init/token.js.map +0 -1
  108. package/bin/lib/output.js +0 -34
  109. package/bin/lib/output.js.map +0 -1
  110. package/bin/lib/pull.js +0 -264
  111. package/bin/lib/pull.js.map +0 -1
  112. package/bin/lib/remove-project.js +0 -35
  113. package/bin/lib/remove-project.js.map +0 -1
  114. package/bin/lib/replace.js +0 -107
  115. package/bin/lib/replace.js.map +0 -1
  116. package/bin/lib/types.js +0 -3
  117. package/bin/lib/types.js.map +0 -1
  118. package/bin/lib/utils/cleanFileName.js +0 -11
  119. package/bin/lib/utils/cleanFileName.js.map +0 -1
  120. package/bin/lib/utils/generateJsDriver.js +0 -56
  121. package/bin/lib/utils/generateJsDriver.js.map +0 -1
  122. package/bin/lib/utils/getSelectedProjects.js +0 -61
  123. package/bin/lib/utils/getSelectedProjects.js.map +0 -1
  124. package/bin/lib/utils/processMetaOption.js +0 -15
  125. package/bin/lib/utils/processMetaOption.js.map +0 -1
  126. package/bin/lib/utils/projectsToText.js +0 -25
  127. package/bin/lib/utils/projectsToText.js.map +0 -1
  128. package/bin/lib/utils/promptForProject.js +0 -43
  129. package/bin/lib/utils/promptForProject.js.map +0 -1
  130. package/bin/lib/utils/quit.js +0 -10
  131. package/bin/lib/utils/quit.js.map +0 -1
  132. package/bin/lib/utils/sourcesToText.js +0 -25
  133. package/bin/lib/utils/sourcesToText.js.map +0 -1
  134. package/bin/package.json +0 -76
@@ -1,35 +1,99 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="02db58e2-181b-532d-8678-792f107e5740")}catch(e){}}();
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
4
13
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const config_1 = __importDefault(require("./config"));
7
- const consts_1 = __importDefault(require("./consts"));
8
- const output_1 = __importDefault(require("./output"));
9
- const getSelectedProjects_1 = require("./utils/getSelectedProjects");
10
- const promptForProject_1 = __importDefault(require("./utils/promptForProject"));
11
- async function removeProject() {
12
- const projects = (0, getSelectedProjects_1.getSelectedProjects)();
13
- const isUsingComponents = (0, getSelectedProjects_1.getIsUsingComponents)();
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var __async = (__this, __arguments, generator) => {
32
+ return new Promise((resolve, reject) => {
33
+ var fulfilled = (value) => {
34
+ try {
35
+ step(generator.next(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var rejected = (value) => {
41
+ try {
42
+ step(generator.throw(value));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ };
47
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
48
+ step((generator = generator.apply(__this, __arguments)).next());
49
+ });
50
+ };
51
+ var remove_project_exports = {};
52
+ __export(remove_project_exports, {
53
+ default: () => remove_project_default
54
+ });
55
+ module.exports = __toCommonJS(remove_project_exports);
56
+ var import_config = __toESM(require("./config"));
57
+ var import_consts = __toESM(require("./consts"));
58
+ var import_output = __toESM(require("./output"));
59
+ var import_getSelectedProjects = require("./utils/getSelectedProjects");
60
+ var import_promptForProject = __toESM(require("./utils/promptForProject"));
61
+ function removeProject() {
62
+ return __async(this, null, function* () {
63
+ const projects = (0, import_getSelectedProjects.getSelectedProjects)();
64
+ const isUsingComponents = (0, import_getSelectedProjects.getIsUsingComponents)();
14
65
  if (!projects.length && !isUsingComponents) {
15
- console.log("\n" +
16
- "No projects found in your current configuration.\n" +
17
- `Try adding one with: ${output_1.default.info("ditto-cli project add")}\n`);
18
- return;
66
+ console.log(
67
+ `
68
+ No projects found in your current configuration.
69
+ Try adding one with: ${import_output.default.info("ditto-cli project add")}
70
+ `
71
+ );
72
+ return;
19
73
  }
20
- const projectToRemove = await (0, promptForProject_1.default)({
21
- projects,
22
- message: "Select a project to remove",
74
+ const projectToRemove = yield (0, import_promptForProject.default)({
75
+ projects,
76
+ message: "Select a project to remove"
23
77
  });
24
78
  if (!projectToRemove)
25
- return;
26
- config_1.default.writeProjectConfigData(consts_1.default.PROJECT_CONFIG_FILE, {
27
- components: isUsingComponents && projectToRemove.id !== "components",
28
- projects: projects.filter(({ id }) => id !== projectToRemove.id),
79
+ return;
80
+ import_config.default.writeProjectConfigData(import_consts.default.PROJECT_CONFIG_FILE, {
81
+ components: isUsingComponents && projectToRemove.id !== "components",
82
+ projects: projects.filter(({ id }) => id !== projectToRemove.id)
29
83
  });
30
- console.log(`\n${output_1.default.info(projectToRemove.name)} has been removed from your selected projects. ` +
31
- `\nWe saved your updated configuration to: ${output_1.default.info(consts_1.default.PROJECT_CONFIG_FILE)}` +
32
- "\n");
84
+ console.log(
85
+ `
86
+ ${import_output.default.info(
87
+ projectToRemove.name
88
+ )} has been removed from your selected projects.
89
+ We saved your updated configuration to: ${import_output.default.info(
90
+ import_consts.default.PROJECT_CONFIG_FILE
91
+ )}
92
+ `
93
+ );
94
+ });
33
95
  }
34
- exports.default = removeProject;
35
- //# sourceMappingURL=remove-project.js.map
96
+ var remove_project_default = removeProject;
97
+ //# sourceMappingURL=remove-project.js.map
98
+
99
+ //# debugId=02db58e2-181b-532d-8678-792f107e5740
@@ -1 +1 @@
1
- {"version":3,"file":"remove-project.js","sourceRoot":"","sources":["../lib/remove-project.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,sDAA8B;AAC9B,sDAA8B;AAC9B,qEAGqC;AACrC,gFAAwD;AAExD,KAAK,UAAU,aAAa;IAC1B,MAAM,QAAQ,GAAG,IAAA,yCAAmB,GAAE,CAAC;IACvC,MAAM,iBAAiB,GAAG,IAAA,0CAAoB,GAAE,CAAC;IACjD,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,iBAAiB,EAAE;QAC1C,OAAO,CAAC,GAAG,CACT,IAAI;YACF,oDAAoD;YACpD,wBAAwB,gBAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CACnE,CAAC;QACF,OAAO;KACR;IAED,MAAM,eAAe,GAAG,MAAM,IAAA,0BAAgB,EAAC;QAC7C,QAAQ;QACR,OAAO,EAAE,4BAA4B;KACtC,CAAC,CAAC;IACH,IAAI,CAAC,eAAe;QAAE,OAAO;IAE7B,gBAAM,CAAC,sBAAsB,CAAC,gBAAM,CAAC,mBAAmB,EAAE;QACxD,UAAU,EAAE,iBAAiB,IAAI,eAAe,CAAC,EAAE,KAAK,YAAY;QACpE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,eAAe,CAAC,EAAE,CAAC;KACjE,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CACT,KAAK,gBAAM,CAAC,IAAI,CACd,eAAe,CAAC,IAAI,CACrB,iDAAiD;QAChD,6CAA6C,gBAAM,CAAC,IAAI,CACtD,gBAAM,CAAC,mBAAmB,CAC3B,EAAE;QACH,IAAI,CACP,CAAC;AACJ,CAAC;AAED,kBAAe,aAAa,CAAC"}
1
+ {"version":3,"sources":["../lib/remove-project.ts"],"sourcesContent":["import config from \"./config\";\nimport consts from \"./consts\";\nimport output from \"./output\";\nimport {\n getSelectedProjects,\n getIsUsingComponents,\n} from \"./utils/getSelectedProjects\";\nimport promptForProject from \"./utils/promptForProject\";\n\nasync function removeProject() {\n const projects = getSelectedProjects();\n const isUsingComponents = getIsUsingComponents();\n if (!projects.length && !isUsingComponents) {\n console.log(\n \"\\n\" +\n \"No projects found in your current configuration.\\n\" +\n `Try adding one with: ${output.info(\"ditto-cli project add\")}\\n`\n );\n return;\n }\n\n const projectToRemove = await promptForProject({\n projects,\n message: \"Select a project to remove\",\n });\n if (!projectToRemove) return;\n\n config.writeProjectConfigData(consts.PROJECT_CONFIG_FILE, {\n components: isUsingComponents && projectToRemove.id !== \"components\",\n projects: projects.filter(({ id }) => id !== projectToRemove.id),\n });\n\n console.log(\n `\\n${output.info(\n projectToRemove.name\n )} has been removed from your selected projects. ` +\n `\\nWe saved your updated configuration to: ${output.info(\n consts.PROJECT_CONFIG_FILE\n )}` +\n \"\\n\"\n );\n}\n\nexport default removeProject;\n"],"names":["output","promptForProject","config","consts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AACnB,oBAAmB;AACnB,oBAAmB;AACnB,iCAGO;AACP,8BAA6B;AAE7B,SAAe,gBAAgB;AAAA;AAC7B,UAAM,eAAW,gDAAoB;AACrC,UAAM,wBAAoB,iDAAqB;AAC/C,QAAI,CAAC,SAAS,UAAU,CAAC,mBAAmB;AAC1C,cAAQ;AAAA,QACN;AAAA;AAAA,uBAE0B,cAAAA,QAAO,KAAK,uBAAuB,CAAC;AAAA;AAAA,MAChE;AACA;AAAA,IACF;AAEA,UAAM,kBAAkB,UAAM,wBAAAC,SAAiB;AAAA,MAC7C;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AACD,QAAI,CAAC;AAAiB;AAEtB,kBAAAC,QAAO,uBAAuB,cAAAC,QAAO,qBAAqB;AAAA,MACxD,YAAY,qBAAqB,gBAAgB,OAAO;AAAA,MACxD,UAAU,SAAS,OAAO,CAAC,EAAE,GAAG,MAAM,OAAO,gBAAgB,EAAE;AAAA,IACjE,CAAC;AAED,YAAQ;AAAA,MACN;AAAA,EAAK,cAAAH,QAAO;AAAA,QACV,gBAAgB;AAAA,MAClB,CAAC;AAAA,0CAC8C,cAAAA,QAAO;AAAA,QAClD,cAAAG,QAAO;AAAA,MACT,CAAC;AAAA;AAAA,IAEL;AAAA,EACF;AAAA;AAEA,IAAO,yBAAQ","debug_id":"02db58e2-181b-532d-8678-792f107e5740"}
package/bin/replace.js CHANGED
@@ -1,114 +1,154 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="176ee92a-54a5-5a85-aae1-a4ff1f467ec8")}catch(e){}}();
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
24
21
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var __async = (__this, __arguments, generator) => {
32
+ return new Promise((resolve, reject) => {
33
+ var fulfilled = (value) => {
34
+ try {
35
+ step(generator.next(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var rejected = (value) => {
41
+ try {
42
+ step(generator.throw(value));
43
+ } catch (e) {
44
+ reject(e);
45
+ }
46
+ };
47
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
48
+ step((generator = generator.apply(__this, __arguments)).next());
49
+ });
27
50
  };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.replaceJSXTextInFile = exports.parseOptions = exports.replace = void 0;
30
- const fs_extra_1 = __importDefault(require("fs-extra"));
31
- const parser_1 = require("@babel/parser");
32
- const traverse_1 = __importDefault(require("@babel/traverse"));
33
- const t = __importStar(require("@babel/types"));
34
- const core_1 = require("@babel/core");
35
- async function replaceJSXTextInFile(filePath, replacement, flags) {
36
- const code = await fs_extra_1.default.readFile(filePath, "utf-8");
37
- const ast = (0, parser_1.parse)(code, {
38
- sourceType: "module",
39
- plugins: ["jsx", "typescript"],
51
+ var replace_exports = {};
52
+ __export(replace_exports, {
53
+ parseOptions: () => parseOptions,
54
+ replace: () => replace,
55
+ replaceJSXTextInFile: () => replaceJSXTextInFile
56
+ });
57
+ module.exports = __toCommonJS(replace_exports);
58
+ var import_fs_extra = __toESM(require("fs-extra"));
59
+ var import_parser = require("@babel/parser");
60
+ var import_traverse = __toESM(require("@babel/traverse"));
61
+ var t = __toESM(require("@babel/types"));
62
+ var import_core = require("@babel/core");
63
+ function replaceJSXTextInFile(filePath, replacement, flags) {
64
+ return __async(this, null, function* () {
65
+ const code = yield import_fs_extra.default.readFile(filePath, "utf-8");
66
+ const ast = (0, import_parser.parse)(code, {
67
+ sourceType: "module",
68
+ plugins: ["jsx", "typescript"]
40
69
  });
41
- (0, traverse_1.default)(ast, {
42
- JSXText(path) {
43
- const { searchString, replaceWith } = replacement;
44
- const searchStringEscaped = searchString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
45
- const regex = new RegExp(searchStringEscaped, "gi");
46
- if (regex.test(path.node.value)) {
47
- // Ignore if not on a line number that we want to replace.
48
- if (flags.lineNumbers &&
49
- path.node.loc &&
50
- !flags.lineNumbers.includes(path.node.loc.start.line)) {
51
- return;
52
- }
53
- const splitValues = splitByCaseInsensitive(path.node.value, searchStringEscaped);
54
- const nodes = [];
55
- splitValues.forEach((splitValue) => {
56
- if (splitValue.toLowerCase() === searchString.toLowerCase()) {
57
- const identifier = t.jsxIdentifier("DittoComponent");
58
- const componentId = t.jsxAttribute(t.jsxIdentifier("componentId"), t.stringLiteral(replaceWith));
59
- const o = t.jsxOpeningElement(identifier, [componentId], true);
60
- const jsxElement = t.jsxElement(o, undefined, [], true);
61
- nodes.push(jsxElement);
62
- }
63
- else {
64
- nodes.push(t.jsxText(splitValue));
65
- }
66
- });
67
- path.replaceWithMultiple(nodes);
70
+ (0, import_traverse.default)(ast, {
71
+ JSXText(path) {
72
+ const { searchString, replaceWith } = replacement;
73
+ const searchStringEscaped = searchString.replace(
74
+ /[.*+?^${}()|[\]\\]/g,
75
+ "\\$&"
76
+ );
77
+ const regex = new RegExp(searchStringEscaped, "gi");
78
+ if (regex.test(path.node.value)) {
79
+ if (flags.lineNumbers && path.node.loc && !flags.lineNumbers.includes(path.node.loc.start.line)) {
80
+ return;
81
+ }
82
+ const splitValues = splitByCaseInsensitive(
83
+ path.node.value,
84
+ searchStringEscaped
85
+ );
86
+ const nodes = [];
87
+ splitValues.forEach((splitValue) => {
88
+ if (splitValue.toLowerCase() === searchString.toLowerCase()) {
89
+ const identifier = t.jsxIdentifier("DittoComponent");
90
+ const componentId = t.jsxAttribute(
91
+ t.jsxIdentifier("componentId"),
92
+ t.stringLiteral(replaceWith)
93
+ );
94
+ const o = t.jsxOpeningElement(identifier, [componentId], true);
95
+ const jsxElement = t.jsxElement(o, void 0, [], true);
96
+ nodes.push(jsxElement);
97
+ } else {
98
+ nodes.push(t.jsxText(splitValue));
68
99
  }
69
- },
100
+ });
101
+ path.replaceWithMultiple(nodes);
102
+ }
103
+ }
70
104
  });
71
- // transfromFromAst types are wrong?
72
- /* @ts-ignore */
73
- const { code: transformedCode } = (0, core_1.transformFromAst)(ast, code, {
74
- // Don't let this codebase's Babel config affect the code we're transforming.
75
- configFile: false,
105
+ const { code: transformedCode } = (0, import_core.transformFromAst)(ast, code, {
106
+ // Don't let this codebase's Babel config affect the code we're transforming.
107
+ configFile: false
76
108
  });
77
- fs_extra_1.default.writeFile(filePath, transformedCode);
109
+ import_fs_extra.default.writeFile(filePath, transformedCode);
110
+ });
78
111
  }
79
- exports.replaceJSXTextInFile = replaceJSXTextInFile;
80
112
  function splitByCaseInsensitive(str, delimiter) {
81
- return str.split(new RegExp(`(${delimiter})`, "gi")).filter((s) => s !== "");
113
+ return str.split(new RegExp(`(${delimiter})`, "gi")).filter((s) => s !== "");
82
114
  }
83
115
  function replace(options, flags) {
84
- let filePath;
85
- let searchString;
86
- let replaceWith;
87
- try {
88
- const parsedOptions = parseOptions(options);
89
- filePath = parsedOptions.filePath;
90
- searchString = parsedOptions.searchString;
91
- replaceWith = parsedOptions.replaceWith;
92
- }
93
- catch (e) {
94
- console.error(e);
95
- console.error("Usage for replace: ditto-cli replace <file path> <search string> <replace with>");
96
- return;
97
- }
98
- replaceJSXTextInFile(filePath, { searchString, replaceWith }, flags);
116
+ let filePath;
117
+ let searchString;
118
+ let replaceWith;
119
+ try {
120
+ const parsedOptions = parseOptions(options);
121
+ filePath = parsedOptions.filePath;
122
+ searchString = parsedOptions.searchString;
123
+ replaceWith = parsedOptions.replaceWith;
124
+ } catch (e) {
125
+ console.error(e);
126
+ console.error(
127
+ "Usage for replace: ditto-cli replace <file path> <search string> <replace with>"
128
+ );
129
+ return;
130
+ }
131
+ replaceJSXTextInFile(filePath, { searchString, replaceWith }, flags);
99
132
  }
100
- exports.replace = replace;
101
133
  function parseOptions(options) {
102
- if (options.length !== 3) {
103
- throw new Error("The options array must contain <file path> <search string> <replace with>.");
104
- }
105
- const filePath = options[0];
106
- // Check if the file path exists and points to a regular file (not a directory or other file system object).
107
- const isFilePathValid = fs_extra_1.default.existsSync(filePath) && fs_extra_1.default.lstatSync(filePath).isFile();
108
- if (!isFilePathValid) {
109
- throw new Error(`${filePath} is not a valid file path.`);
110
- }
111
- return { filePath, searchString: options[1], replaceWith: options[2] };
134
+ if (options.length !== 3) {
135
+ throw new Error(
136
+ "The options array must contain <file path> <search string> <replace with>."
137
+ );
138
+ }
139
+ const filePath = options[0];
140
+ const isFilePathValid = import_fs_extra.default.existsSync(filePath) && import_fs_extra.default.lstatSync(filePath).isFile();
141
+ if (!isFilePathValid) {
142
+ throw new Error(`${filePath} is not a valid file path.`);
143
+ }
144
+ return { filePath, searchString: options[1], replaceWith: options[2] };
112
145
  }
113
- exports.parseOptions = parseOptions;
114
- //# sourceMappingURL=replace.js.map
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ parseOptions,
149
+ replace,
150
+ replaceJSXTextInFile
151
+ });
152
+ //# sourceMappingURL=replace.js.map
153
+
154
+ //# debugId=176ee92a-54a5-5a85-aae1-a4ff1f467ec8
@@ -1 +1 @@
1
- {"version":3,"file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"fs-extra\";\nimport { parse } from \"@babel/parser\";\nimport traverse from \"@babel/traverse\";\nimport * as t from \"@babel/types\";\nimport { transformFromAst } from \"@babel/core\";\n\nasync function replaceJSXTextInFile(\n filePath: string,\n replacement: { searchString: string; replaceWith: string },\n flags: {\n lineNumbers?: number[];\n }\n) {\n const code = await fs.readFile(filePath, \"utf-8\");\n const ast = parse(code, {\n sourceType: \"module\",\n plugins: [\"jsx\", \"typescript\"],\n });\n\n traverse(ast, {\n JSXText(path) {\n const { searchString, replaceWith } = replacement;\n\n const searchStringEscaped = searchString.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n \"\\\\$&\"\n );\n const regex = new RegExp(searchStringEscaped, \"gi\");\n if (regex.test(path.node.value)) {\n // Ignore if not on a line number that we want to replace.\n if (\n flags.lineNumbers &&\n path.node.loc &&\n !flags.lineNumbers.includes(path.node.loc.start.line)\n ) {\n return;\n }\n\n const splitValues = splitByCaseInsensitive(\n path.node.value,\n searchStringEscaped\n );\n const nodes: (t.JSXElement | t.JSXText)[] = [];\n\n splitValues.forEach((splitValue) => {\n if (splitValue.toLowerCase() === searchString.toLowerCase()) {\n const identifier = t.jsxIdentifier(\"DittoComponent\");\n const componentId = t.jsxAttribute(\n t.jsxIdentifier(\"componentId\"),\n t.stringLiteral(replaceWith)\n );\n const o = t.jsxOpeningElement(identifier, [componentId], true);\n const jsxElement = t.jsxElement(o, undefined, [], true);\n nodes.push(jsxElement);\n } else {\n nodes.push(t.jsxText(splitValue));\n }\n });\n\n path.replaceWithMultiple(nodes);\n }\n },\n });\n\n // transfromFromAst types are wrong?\n /* @ts-ignore */\n const { code: transformedCode } = transformFromAst(ast, code, {\n // Don't let this codebase's Babel config affect the code we're transforming.\n configFile: false,\n });\n fs.writeFile(filePath, transformedCode);\n}\n\nfunction splitByCaseInsensitive(str: string, delimiter: string) {\n return str.split(new RegExp(`(${delimiter})`, \"gi\")).filter((s) => s !== \"\");\n}\n\nfunction replace(options: string[], flags: { lineNumbers?: number[] }) {\n let filePath: string;\n let searchString: string;\n let replaceWith: string;\n\n try {\n const parsedOptions = parseOptions(options);\n filePath = parsedOptions.filePath;\n searchString = parsedOptions.searchString;\n replaceWith = parsedOptions.replaceWith;\n } catch (e) {\n console.error(e);\n console.error(\n \"Usage for replace: ditto-cli replace <file path> <search string> <replace with>\"\n );\n return;\n }\n\n replaceJSXTextInFile(filePath, { searchString, replaceWith }, flags);\n}\n\nfunction parseOptions(options: string[]): {\n filePath: string;\n searchString: string;\n replaceWith: string;\n} {\n if (options.length !== 3) {\n throw new Error(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n }\n\n const filePath = options[0];\n // Check if the file path exists and points to a regular file (not a directory or other file system object).\n const isFilePathValid =\n fs.existsSync(filePath) && fs.lstatSync(filePath).isFile();\n\n if (!isFilePathValid) {\n throw new Error(`${filePath} is not a valid file path.`);\n }\n\n return { filePath, searchString: options[1], replaceWith: options[2] };\n}\n\nexport { replace, parseOptions, replaceJSXTextInFile };\n"],"names":["fs","traverse"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAe;AACf,oBAAsB;AACtB,sBAAqB;AACrB,QAAmB;AACnB,kBAAiC;AAEjC,SAAe,qBACb,UACA,aACA,OAGA;AAAA;AACA,UAAM,OAAO,MAAM,gBAAAA,QAAG,SAAS,UAAU,OAAO;AAChD,UAAM,UAAM,qBAAM,MAAM;AAAA,MACtB,YAAY;AAAA,MACZ,SAAS,CAAC,OAAO,YAAY;AAAA,IAC/B,CAAC;AAED,wBAAAC,SAAS,KAAK;AAAA,MACZ,QAAQ,MAAM;AACZ,cAAM,EAAE,cAAc,YAAY,IAAI;AAEtC,cAAM,sBAAsB,aAAa;AAAA,UACvC;AAAA,UACA;AAAA,QACF;AACA,cAAM,QAAQ,IAAI,OAAO,qBAAqB,IAAI;AAClD,YAAI,MAAM,KAAK,KAAK,KA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EAC9B,SAAS,GAAG;AACV,YAAQ,MAAM,CAAC;AACf,YAAQ;AAAA,MACN;AAAA,IACF;AACA;AAAA,EACF;AAEA,uBAAqB,UAAU,EAAE,cAAc,YAAY,GAAG,KAAK;AACrE;AAEA,SAAS,aAAa,SAIpB;AACA,MAAI,QAAQ,WAAW,GAAG;AACxB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WAAW,QAAQ,CAAC;AAE1B,QAAM,kBACJ,gBAAAA,QAAG,WAAW,QAAQ,KAAK,gBAAAA,QAAG,UAAU,QAAQ,EAAE,OAAO;AAE3D,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI,MAAM,GAAG,QAAQ,4BAA4B;AAAA,EACzD;AAEA,SAAO,EAAE,UAAU,cAAc,QAAQ,CAAC,GAAG,aAAa,QAAQ,CAAC,EAAE;AACvE","debug_id":"176ee92a-54a5-5a85-aae1-a4ff1f467ec8"}
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="88bc0e18-7209-5d12-95f3-62e752160eb4")}catch(e){}}();
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+ var __async = (__this, __arguments, generator) => {
27
+ return new Promise((resolve, reject) => {
28
+ var fulfilled = (value) => {
29
+ try {
30
+ step(generator.next(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ };
35
+ var rejected = (value) => {
36
+ try {
37
+ step(generator.throw(value));
38
+ } catch (e) {
39
+ reject(e);
40
+ }
41
+ };
42
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
43
+ step((generator = generator.apply(__this, __arguments)).next());
44
+ });
45
+ };
46
+ var import_promises = __toESM(require("fs/promises"));
47
+ var import_replace = require("./replace");
48
+ function createTempJSXFile(content) {
49
+ return __async(this, null, function* () {
50
+ const tempFile = "tempFile.jsx";
51
+ yield import_promises.default.writeFile(tempFile, content);
52
+ return tempFile;
53
+ });
54
+ }
55
+ function deleteTempFile(filePath) {
56
+ return __async(this, null, function* () {
57
+ yield import_promises.default.unlink(filePath);
58
+ });
59
+ }
60
+ describe("parseOptions", () => {
61
+ test("should pass with valid input", () => __async(exports, null, function* () {
62
+ const tempFile = yield createTempJSXFile("<div>Hello, world!</div>");
63
+ expect(
64
+ () => (0, import_replace.parseOptions)([tempFile, "secondString", "thirdString"])
65
+ ).not.toThrow();
66
+ const result = (0, import_replace.parseOptions)([tempFile, "secondString", "thirdString"]);
67
+ expect(result).toEqual({
68
+ filePath: tempFile,
69
+ searchString: "secondString",
70
+ replaceWith: "thirdString"
71
+ });
72
+ deleteTempFile(tempFile);
73
+ }));
74
+ test("should throw error when options array does not have exactly three strings", () => {
75
+ expect(() => (0, import_replace.parseOptions)(["oneString"])).toThrow(
76
+ "The options array must contain <file path> <search string> <replace with>."
77
+ );
78
+ expect(() => (0, import_replace.parseOptions)(["one", "two"])).toThrow(
79
+ "The options array must contain <file path> <search string> <replace with>."
80
+ );
81
+ expect(() => (0, import_replace.parseOptions)(["one", "two", "three", "four"])).toThrow(
82
+ "The options array must contain <file path> <search string> <replace with>."
83
+ );
84
+ });
85
+ test("should throw error when the first string is not a valid file path", () => {
86
+ const invalidFilePath = "/path/to/invalid/file.txt";
87
+ expect(
88
+ () => (0, import_replace.parseOptions)([invalidFilePath, "secondString", "thirdString"])
89
+ ).toThrow(`${invalidFilePath} is not a valid file path.`);
90
+ });
91
+ test("should throw error when the first string is a directory", () => {
92
+ const directoryPath = ".";
93
+ expect(
94
+ () => (0, import_replace.parseOptions)([directoryPath, "secondString", "thirdString"])
95
+ ).toThrow(`${directoryPath} is not a valid file path.`);
96
+ });
97
+ });
98
+ describe("replaceJSXTextInFile", () => {
99
+ afterEach(() => __async(exports, null, function* () {
100
+ yield deleteTempFile("tempFile.jsx");
101
+ }));
102
+ test("should replace JSX text with a DittoComponent", () => __async(exports, null, function* () {
103
+ const tempFile = yield createTempJSXFile("<div>Hello, world</div>");
104
+ const searchString = "world";
105
+ const replaceWith = "some-id";
106
+ yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
107
+ const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
108
+ expect(transformedCode).toContain(
109
+ `<div>Hello, <DittoComponent componentId="${replaceWith}" /></div>`
110
+ );
111
+ }));
112
+ test("should replace JSX text with a DittoComponent with a flag", () => __async(exports, null, function* () {
113
+ const tempFile = yield createTempJSXFile(
114
+ `<>
115
+ <div>Hello, world</div>
116
+ <div>Hello, world</div>
117
+ </>`
118
+ );
119
+ const searchString = "world";
120
+ const replaceWith = "some-id";
121
+ yield (0, import_replace.replaceJSXTextInFile)(
122
+ tempFile,
123
+ { searchString, replaceWith },
124
+ { lineNumbers: [3] }
125
+ );
126
+ const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
127
+ expect(transformedCode).toContain(
128
+ `<>
129
+ <div>Hello, world</div>
130
+ <div>Hello, <DittoComponent componentId="some-id" /></div>
131
+ </>;`
132
+ );
133
+ }));
134
+ test("should handle case-insensitive search", () => __async(exports, null, function* () {
135
+ const tempFile = yield createTempJSXFile("<div>HeLLo, WoRlD</div>");
136
+ const searchString = "world";
137
+ const replaceWith = "some-id";
138
+ yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
139
+ const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
140
+ expect(transformedCode).toContain(
141
+ `<div>HeLLo, <DittoComponent componentId="${replaceWith}" /></div>`
142
+ );
143
+ }));
144
+ test("should not replace JSX text if searchString is not found", () => __async(exports, null, function* () {
145
+ const tempFile = yield createTempJSXFile("<div>Hello, world!</div>");
146
+ const searchString = "foobar";
147
+ const replaceWith = "some-id";
148
+ yield (0, import_replace.replaceJSXTextInFile)(tempFile, { searchString, replaceWith }, {});
149
+ const transformedCode = yield import_promises.default.readFile(tempFile, "utf-8");
150
+ expect(transformedCode).toContain("<div>Hello, world!</div>");
151
+ }));
152
+ });
153
+ //# sourceMappingURL=replace.test.js.map
154
+
155
+ //# debugId=88bc0e18-7209-5d12-95f3-62e752160eb4
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../lib/replace.test.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport { parseOptions, replaceJSXTextInFile } from \"./replace\"; // Assuming the function is exported in a separate file\n\n// Helper function to create a temporary file\nasync function createTempJSXFile(content: string): Promise<string> {\n const tempFile = \"tempFile.jsx\";\n await fs.writeFile(tempFile, content);\n return tempFile;\n}\n\n// Helper function to delete the temporary file\nasync function deleteTempFile(filePath: string): Promise<void> {\n await fs.unlink(filePath);\n}\n\ndescribe(\"parseOptions\", () => {\n test(\"should pass with valid input\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world!</div>\");\n expect(() =>\n parseOptions([tempFile, \"secondString\", \"thirdString\"])\n ).not.toThrow();\n\n const result = parseOptions([tempFile, \"secondString\", \"thirdString\"]);\n expect(result).toEqual({\n filePath: tempFile,\n searchString: \"secondString\",\n replaceWith: \"thirdString\",\n });\n\n deleteTempFile(tempFile);\n });\n\n test(\"should throw error when options array does not have exactly three strings\", () => {\n expect(() => parseOptions([\"oneString\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n expect(() => parseOptions([\"one\", \"two\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n expect(() => parseOptions([\"one\", \"two\", \"three\", \"four\"])).toThrow(\n \"The options array must contain <file path> <search string> <replace with>.\"\n );\n });\n\n test(\"should throw error when the first string is not a valid file path\", () => {\n const invalidFilePath = \"/path/to/invalid/file.txt\";\n expect(() =>\n parseOptions([invalidFilePath, \"secondString\", \"thirdString\"])\n ).toThrow(`${invalidFilePath} is not a valid file path.`);\n });\n\n test(\"should throw error when the first string is a directory\", () => {\n const directoryPath = \".\";\n expect(() =>\n parseOptions([directoryPath, \"secondString\", \"thirdString\"])\n ).toThrow(`${directoryPath} is not a valid file path.`);\n });\n});\n\n// TODO: this is flaky\ndescribe(\"replaceJSXTextInFile\", () => {\n afterEach(async () => {\n await deleteTempFile(\"tempFile.jsx\");\n });\n\n test(\"should replace JSX text with a DittoComponent\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world</div>\");\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\n `<div>Hello, <DittoComponent componentId=\"${replaceWith}\" /></div>`\n );\n });\n\n test(\"should replace JSX text with a DittoComponent with a flag\", async () => {\n const tempFile = await createTempJSXFile(\n `<>\\n<div>Hello, world</div>\\n<div>Hello, world</div>\\n</>`\n );\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(\n tempFile,\n { searchString, replaceWith },\n { lineNumbers: [3] }\n );\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\n `<>\\n <div>Hello, world</div>\\n <div>Hello, <DittoComponent componentId=\\\"some-id\\\" /></div>\\n</>;`\n );\n });\n\n test(\"should handle case-insensitive search\", async () => {\n const tempFile = await createTempJSXFile(\"<div>HeLLo, WoRlD</div>\");\n const searchString = \"world\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\n `<div>HeLLo, <DittoComponent componentId=\"${replaceWith}\" /></div>`\n );\n });\n\n test(\"should not replace JSX text if searchString is not found\", async () => {\n const tempFile = await createTempJSXFile(\"<div>Hello, world!</div>\");\n const searchString = \"foobar\";\n const replaceWith = \"some-id\";\n\n await replaceJSXTextInFile(tempFile, { searchString, replaceWith }, {});\n\n const transformedCode = await fs.readFile(tempFile, \"utf-8\");\n expect(transformedCode).toContain(\"<div>Hello, world!</div>\");\n });\n});\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sBAAe;AACf,qBAAmD;AAGnD,SAAe,kBAAkB,SAAkC;AAAA;AACjE,UAAM,WAAW;AACjB,UAAM,gBAAAA,QAAG,UAAU,UAAU,OAAO;AACpC,WAAO;AAAA,EACT;AAAA;AAGA,SAAe,eAAe,UAAiC;AAAA;AAC7D,UAAM,gBAAAA,QAAG,OAAO,QAAQ;AAAA,EAC1B;AAAA;AAEA,SAAS,gBAAgB,MAAM;AAC7B,OAAK,gCAAgC,MAAY;AAC/C,UAAM,WAAW,MAAM,kBAAkB,0BAA0B;AACnE;AAAA,MAAO,UACL,6BAAa,CAAC,UAAU,gBAAgB,aAAa,CAAC;AAAA,IACxD,EAAE,IAAI,QAAQ;AAEd,UAAM,aAAS,6BAA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OAAK,6DAA6D,MAAY;AAC5E,UAAM,WAAW,MAAM;AAAA,MACrB;AAAA;AAAA;AAAA;AAAA,IACF;AACA,UAAM,eAAe;AACrB,UAAM,cAAc;AAEpB,cAAM;AAAA,MACJ;AAAA,MACA,EAAE,cAAc,YAAY;AAAA,MAC5B,EAAE,aAAa,CAAC,CAAC,EAAE;AAAA,IACrB;AAEA,UAAM,kBAAkB,MAAM,gBAAAA,QAAG,SAAS,UAAU,OAAO;AAC3D,WAAO,eAAe,EAAE;AAAA,MACtB;AAAA;AAAA;AAAA;AAAA,IACF;AAAA,EACF,EAAC;AAED,OAAK,yCAAyC,MAAY;AACxD,UAAM,WAAW,MAAM,kBAAkB,yBAAyB;AAClE,UAAM,eAAe;AACrB,UAAM,cAAc;AAEpB,cAAM,qCAAqB,UAAU,EAAE,cAAc,YAAY,GAAG,CAAC,CAAC;AAEtE,UAAM,kBAAkB,MAAM,gBAAAA,QAAG,SAAS,UAAU,OAAO;AAC3D,WAAO,eAAe,EAAE;AAAA,MACtB,4CAA4C,WAAW;AAAA,IACzD;AAAA,EACF,EAAC;AAED,OAAK,4DAA4D,MAAY;AAC3E,UAAM,WAAW,MAAM,kBAAkB,0BAA0B;AACnE,UAAM,eAAe;AACrB,UAAM,cAAc;AAEpB,cAAM,qCAAqB,UAAU,EAAE,cAAc,YAAY,GAAG,CAAC,CAAC;AAEtE,UAAM,kBAAkB,MAAM,gBAAAA,QAAG,SAAS,UAAU,OAAO;AAC3D,WAAO,eAAe,EAAE,UAAU,0BAA0B;AAAA,EAC9D,EAAC;AACH,CAAC","debug_id":"88bc0e18-7209-5d12-95f3-62e752160eb4"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../lib/sentry-test.ts"],"sourcesContent":["import * as Sentry from \"@sentry/node\";\nSentry.init({\n dsn: \"https://9c1d99fa4267f54c6b914f720b4ed3a2@o979374.ingest.sentry.io/4505705213919232\",\n debug: true,\n});\nSentry.captureException(new Error(\"new test exception\"));\nconsole.log(\"captured exception\");\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,aAAwB;AACxB,OAAO,KAAK;AAAA,EACV,KAAK;AAAA,EACL,OAAO;AACT,CAAC;AACD,OAAO,iBAAiB,IAAI,MAAM,oBAAoB,CAAC;AACvD,QAAQ,IAAI,oBAAoB","debug_id":"01741d01-3103-54ae-87e5-0199defce6e9"}