skuba 4.4.1 → 5.0.0-beta.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 (313) hide show
  1. package/config/tsconfig.json +1 -0
  2. package/jest/moduleNameMapper.js +50 -78
  3. package/jest/moduleNameMapper.test.ts +4 -14
  4. package/jest/transform.js +10 -1
  5. package/jest/tsConfig.js +26 -0
  6. package/lib/api/buildkite/annotate.js +46 -33
  7. package/lib/api/buildkite/annotate.js.map +7 -1
  8. package/lib/api/buildkite/index.js +31 -7
  9. package/lib/api/buildkite/index.js.map +7 -1
  10. package/lib/api/buildkite/md.js +31 -8
  11. package/lib/api/buildkite/md.js.map +7 -1
  12. package/lib/api/git/commit.js +45 -17
  13. package/lib/api/git/commit.js.map +7 -1
  14. package/lib/api/git/commitAllChanges.js +57 -27
  15. package/lib/api/git/commitAllChanges.js.map +7 -1
  16. package/lib/api/git/currentBranch.js +50 -28
  17. package/lib/api/git/currentBranch.js.map +7 -1
  18. package/lib/api/git/getChangedFiles.js +49 -27
  19. package/lib/api/git/getChangedFiles.js.map +7 -1
  20. package/lib/api/git/index.js +54 -22
  21. package/lib/api/git/index.js.map +7 -1
  22. package/lib/api/git/log.js +63 -42
  23. package/lib/api/git/log.js.map +7 -1
  24. package/lib/api/git/pull.js +62 -31
  25. package/lib/api/git/pull.js.map +7 -1
  26. package/lib/api/git/push.js +63 -31
  27. package/lib/api/git/push.js.map +7 -1
  28. package/lib/api/git/remote.js +59 -56
  29. package/lib/api/git/remote.js.map +7 -1
  30. package/lib/api/git/reset.js +55 -27
  31. package/lib/api/git/reset.js.map +7 -1
  32. package/lib/api/git/statusMatrix.js +46 -13
  33. package/lib/api/git/statusMatrix.js.map +7 -1
  34. package/lib/api/github/checkRun.js +70 -79
  35. package/lib/api/github/checkRun.js.map +7 -1
  36. package/lib/api/github/environment.js +40 -33
  37. package/lib/api/github/environment.js.map +7 -1
  38. package/lib/api/github/index.js +47 -17
  39. package/lib/api/github/index.js.map +7 -1
  40. package/lib/api/github/issueComment.js +73 -81
  41. package/lib/api/github/issueComment.js.map +7 -1
  42. package/lib/api/github/pullRequest.js +60 -61
  43. package/lib/api/github/pullRequest.js.map +7 -1
  44. package/lib/api/github/push.js +138 -133
  45. package/lib/api/github/push.js.map +7 -1
  46. package/lib/api/jest/index.d.ts +2 -1
  47. package/lib/api/jest/index.js +35 -14
  48. package/lib/api/jest/index.js.map +7 -1
  49. package/lib/api/net/compose.js +45 -17
  50. package/lib/api/net/compose.js.map +7 -1
  51. package/lib/api/net/index.js +28 -5
  52. package/lib/api/net/index.js.map +7 -1
  53. package/lib/api/net/socket.js +58 -36
  54. package/lib/api/net/socket.js.map +7 -1
  55. package/lib/api/net/waitFor.js +38 -18
  56. package/lib/api/net/waitFor.js.map +7 -1
  57. package/lib/cli/adapter/eslint.js +95 -72
  58. package/lib/cli/adapter/eslint.js.map +7 -1
  59. package/lib/cli/adapter/prettier.js +126 -124
  60. package/lib/cli/adapter/prettier.js.map +7 -1
  61. package/lib/cli/build/args.d.ts +7 -0
  62. package/lib/cli/build/args.js +69 -0
  63. package/lib/cli/build/args.js.map +7 -0
  64. package/lib/cli/build/esbuild.d.ts +5 -0
  65. package/lib/cli/build/esbuild.js +128 -0
  66. package/lib/cli/build/esbuild.js.map +7 -0
  67. package/lib/cli/build/index.d.ts +1 -1
  68. package/lib/cli/build/index.js +68 -5
  69. package/lib/cli/build/index.js.map +7 -1
  70. package/lib/cli/build/tsc.d.ts +1 -1
  71. package/lib/cli/build/tsc.js +34 -23
  72. package/lib/cli/build/tsc.js.map +7 -1
  73. package/lib/cli/buildPackage.js +53 -23
  74. package/lib/cli/buildPackage.js.map +7 -1
  75. package/lib/cli/configure/addEmptyExports.d.ts +5 -0
  76. package/lib/cli/configure/addEmptyExports.js +67 -0
  77. package/lib/cli/configure/addEmptyExports.js.map +7 -0
  78. package/lib/cli/configure/analyseConfiguration.js +61 -31
  79. package/lib/cli/configure/analyseConfiguration.js.map +7 -1
  80. package/lib/cli/configure/analyseDependencies.js +122 -113
  81. package/lib/cli/configure/analyseDependencies.js.map +7 -1
  82. package/lib/cli/configure/analysis/diff.js +37 -11
  83. package/lib/cli/configure/analysis/diff.js.map +7 -1
  84. package/lib/cli/configure/analysis/files.js +49 -22
  85. package/lib/cli/configure/analysis/files.js.map +7 -1
  86. package/lib/cli/configure/analysis/git.js +46 -16
  87. package/lib/cli/configure/analysis/git.js.map +7 -1
  88. package/lib/cli/configure/analysis/package.js +99 -52
  89. package/lib/cli/configure/analysis/package.js.map +7 -1
  90. package/lib/cli/configure/analysis/project.js +90 -54
  91. package/lib/cli/configure/analysis/project.js.map +7 -1
  92. package/lib/cli/configure/dependencies/index.js +40 -13
  93. package/lib/cli/configure/dependencies/index.js.map +7 -1
  94. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js +57 -32
  95. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js.map +7 -1
  96. package/lib/cli/configure/dependencies/seekKoala.js +53 -31
  97. package/lib/cli/configure/dependencies/seekKoala.js.map +7 -1
  98. package/lib/cli/configure/dependencies/skuba.js +49 -27
  99. package/lib/cli/configure/dependencies/skuba.js.map +7 -1
  100. package/lib/cli/configure/dependencies/skubaDeps.js +49 -28
  101. package/lib/cli/configure/dependencies/skubaDeps.js.map +7 -1
  102. package/lib/cli/configure/dependencies/skubaDive.js +65 -38
  103. package/lib/cli/configure/dependencies/skubaDive.js.map +7 -1
  104. package/lib/cli/configure/ensureTemplateCompletion.js +69 -41
  105. package/lib/cli/configure/ensureTemplateCompletion.js.map +7 -1
  106. package/lib/cli/configure/getEntryPoint.js +62 -32
  107. package/lib/cli/configure/getEntryPoint.js.map +7 -1
  108. package/lib/cli/configure/getProjectType.js +50 -28
  109. package/lib/cli/configure/getProjectType.js.map +7 -1
  110. package/lib/cli/configure/index.js +134 -109
  111. package/lib/cli/configure/index.js.map +7 -1
  112. package/lib/cli/configure/modules/eslint.js +57 -26
  113. package/lib/cli/configure/modules/eslint.js.map +7 -1
  114. package/lib/cli/configure/modules/ignore.js +37 -14
  115. package/lib/cli/configure/modules/ignore.js.map +7 -1
  116. package/lib/cli/configure/modules/index.js +53 -28
  117. package/lib/cli/configure/modules/index.js.map +7 -1
  118. package/lib/cli/configure/modules/jest.js +84 -47
  119. package/lib/cli/configure/modules/jest.js.map +7 -1
  120. package/lib/cli/configure/modules/nodemon.js +29 -6
  121. package/lib/cli/configure/modules/nodemon.js.map +7 -1
  122. package/lib/cli/configure/modules/package.js +113 -92
  123. package/lib/cli/configure/modules/package.js.map +7 -1
  124. package/lib/cli/configure/modules/prettier.js +48 -19
  125. package/lib/cli/configure/modules/prettier.js.map +7 -1
  126. package/lib/cli/configure/modules/renovate.js +52 -39
  127. package/lib/cli/configure/modules/renovate.js.map +7 -1
  128. package/lib/cli/configure/modules/serverless.js +33 -15
  129. package/lib/cli/configure/modules/serverless.js.map +7 -1
  130. package/lib/cli/configure/modules/skubaDive.js +63 -37
  131. package/lib/cli/configure/modules/skubaDive.js.map +7 -1
  132. package/lib/cli/configure/modules/tsconfig.js +79 -63
  133. package/lib/cli/configure/modules/tsconfig.js.map +7 -1
  134. package/lib/cli/configure/modules/tslint.js +29 -6
  135. package/lib/cli/configure/modules/tslint.js.map +7 -1
  136. package/lib/cli/configure/processing/deleteFiles.js +30 -8
  137. package/lib/cli/configure/processing/deleteFiles.js.map +7 -1
  138. package/lib/cli/configure/processing/ignoreFile.js +65 -59
  139. package/lib/cli/configure/processing/ignoreFile.js.map +7 -1
  140. package/lib/cli/configure/processing/javascript.js +35 -15
  141. package/lib/cli/configure/processing/javascript.js.map +7 -1
  142. package/lib/cli/configure/processing/json.js +51 -20
  143. package/lib/cli/configure/processing/json.js.map +7 -1
  144. package/lib/cli/configure/processing/loadFiles.js +30 -8
  145. package/lib/cli/configure/processing/loadFiles.js.map +7 -1
  146. package/lib/cli/configure/processing/module.js +37 -14
  147. package/lib/cli/configure/processing/module.js.map +7 -1
  148. package/lib/cli/configure/processing/package.js +73 -43
  149. package/lib/cli/configure/processing/package.js.map +7 -1
  150. package/lib/cli/configure/processing/prettier.js +37 -11
  151. package/lib/cli/configure/processing/prettier.js.map +7 -1
  152. package/lib/cli/configure/processing/record.js +54 -31
  153. package/lib/cli/configure/processing/record.js.map +7 -1
  154. package/lib/cli/configure/processing/typescript.js +176 -158
  155. package/lib/cli/configure/processing/typescript.js.map +7 -1
  156. package/lib/cli/configure/refreshIgnoreFiles.js +64 -40
  157. package/lib/cli/configure/refreshIgnoreFiles.js.map +7 -1
  158. package/lib/cli/configure/types.js +16 -2
  159. package/lib/cli/configure/types.js.map +7 -1
  160. package/lib/cli/format.js +58 -31
  161. package/lib/cli/format.js.map +7 -1
  162. package/lib/cli/help.js +31 -8
  163. package/lib/cli/help.js.map +7 -1
  164. package/lib/cli/init/getConfig.js +238 -207
  165. package/lib/cli/init/getConfig.js.map +7 -1
  166. package/lib/cli/init/git.js +70 -63
  167. package/lib/cli/init/git.js.map +7 -1
  168. package/lib/cli/init/index.js +133 -100
  169. package/lib/cli/init/index.js.map +7 -1
  170. package/lib/cli/init/prompts.js +84 -54
  171. package/lib/cli/init/prompts.js.map +7 -1
  172. package/lib/cli/init/types.js +52 -52
  173. package/lib/cli/init/types.js.map +7 -1
  174. package/lib/cli/init/validation.js +34 -12
  175. package/lib/cli/init/validation.js.map +7 -1
  176. package/lib/cli/init/writePackageJson.js +51 -22
  177. package/lib/cli/init/writePackageJson.js.map +7 -1
  178. package/lib/cli/lint/annotate/buildkite/eslint.js +34 -28
  179. package/lib/cli/lint/annotate/buildkite/eslint.js.map +7 -1
  180. package/lib/cli/lint/annotate/buildkite/index.js +50 -44
  181. package/lib/cli/lint/annotate/buildkite/index.js.map +7 -1
  182. package/lib/cli/lint/annotate/buildkite/prettier.js +41 -35
  183. package/lib/cli/lint/annotate/buildkite/prettier.js.map +7 -1
  184. package/lib/cli/lint/annotate/buildkite/tsc.js +39 -39
  185. package/lib/cli/lint/annotate/buildkite/tsc.js.map +7 -1
  186. package/lib/cli/lint/annotate/github/eslint.js +40 -16
  187. package/lib/cli/lint/annotate/github/eslint.js.map +7 -1
  188. package/lib/cli/lint/annotate/github/index.js +55 -51
  189. package/lib/cli/lint/annotate/github/index.js.map +7 -1
  190. package/lib/cli/lint/annotate/github/prettier.js +36 -13
  191. package/lib/cli/lint/annotate/github/prettier.js.map +7 -1
  192. package/lib/cli/lint/annotate/github/tsc.js +52 -52
  193. package/lib/cli/lint/annotate/github/tsc.js.map +7 -1
  194. package/lib/cli/lint/annotate/index.js +33 -10
  195. package/lib/cli/lint/annotate/index.js.map +7 -1
  196. package/lib/cli/lint/autofix.js +122 -117
  197. package/lib/cli/lint/autofix.js.map +7 -1
  198. package/lib/cli/lint/eslint.js +48 -18
  199. package/lib/cli/lint/eslint.js.map +7 -1
  200. package/lib/cli/lint/external.js +102 -81
  201. package/lib/cli/lint/external.js.map +7 -1
  202. package/lib/cli/lint/index.js +42 -18
  203. package/lib/cli/lint/index.js.map +7 -1
  204. package/lib/cli/lint/internal.js +54 -21
  205. package/lib/cli/lint/internal.js.map +7 -1
  206. package/lib/cli/lint/prettier.js +48 -18
  207. package/lib/cli/lint/prettier.js.map +7 -1
  208. package/lib/cli/lint/tsc.js +56 -32
  209. package/lib/cli/lint/tsc.js.map +7 -1
  210. package/lib/cli/lint/types.js +16 -2
  211. package/lib/cli/lint/types.js.map +7 -1
  212. package/lib/cli/node.js +65 -58
  213. package/lib/cli/node.js.map +7 -1
  214. package/lib/cli/release.js +29 -6
  215. package/lib/cli/release.js.map +7 -1
  216. package/lib/cli/start.js +61 -24
  217. package/lib/cli/start.js.map +7 -1
  218. package/lib/cli/test/index.js +35 -11
  219. package/lib/cli/test/index.js.map +7 -1
  220. package/lib/cli/test/reporters/github/annotations.js +89 -92
  221. package/lib/cli/test/reporters/github/annotations.js.map +7 -1
  222. package/lib/cli/test/reporters/github/index.js +68 -68
  223. package/lib/cli/test/reporters/github/index.js.map +7 -1
  224. package/lib/cli/version.js +31 -8
  225. package/lib/cli/version.js.map +7 -1
  226. package/lib/enquirer.d.js +2 -0
  227. package/lib/enquirer.d.js.map +7 -0
  228. package/lib/index.d.ts +6 -0
  229. package/lib/index.js +45 -41
  230. package/lib/index.js.map +7 -1
  231. package/lib/skuba.js +45 -38
  232. package/lib/skuba.js.map +7 -1
  233. package/lib/utils/args.js +97 -96
  234. package/lib/utils/args.js.map +7 -1
  235. package/lib/utils/command.js +64 -33
  236. package/lib/utils/command.js.map +7 -1
  237. package/lib/utils/copy.js +88 -51
  238. package/lib/utils/copy.js.map +7 -1
  239. package/lib/utils/dir.js +79 -67
  240. package/lib/utils/dir.js.map +7 -1
  241. package/lib/utils/env.js +27 -7
  242. package/lib/utils/env.js.map +7 -1
  243. package/lib/utils/error.js +58 -56
  244. package/lib/utils/error.js.map +7 -1
  245. package/lib/utils/exec.js +139 -110
  246. package/lib/utils/exec.js.map +7 -1
  247. package/lib/utils/help.js +31 -8
  248. package/lib/utils/help.js.map +7 -1
  249. package/lib/utils/logging.js +52 -24
  250. package/lib/utils/logging.js.map +7 -1
  251. package/lib/utils/logo.js +65 -27
  252. package/lib/utils/logo.js.map +7 -1
  253. package/lib/utils/manifest.d.ts +1 -0
  254. package/lib/utils/manifest.js +65 -51
  255. package/lib/utils/manifest.js.map +7 -1
  256. package/lib/utils/port.js +38 -17
  257. package/lib/utils/port.js.map +7 -1
  258. package/lib/utils/template.js +106 -87
  259. package/lib/utils/template.js.map +7 -1
  260. package/lib/utils/validation.js +43 -18
  261. package/lib/utils/validation.js.map +7 -1
  262. package/lib/utils/version.js +72 -82
  263. package/lib/utils/version.js.map +7 -1
  264. package/lib/utils/wait.js +52 -25
  265. package/lib/utils/wait.js.map +7 -1
  266. package/lib/utils/worker.js +59 -44
  267. package/lib/utils/worker.js.map +7 -1
  268. package/lib/wrapper/function-arguments.d.js +2 -0
  269. package/lib/wrapper/function-arguments.d.js.map +7 -0
  270. package/lib/wrapper/functionHandler.js +56 -29
  271. package/lib/wrapper/functionHandler.js.map +7 -1
  272. package/lib/wrapper/http.js +66 -56
  273. package/lib/wrapper/http.js.map +7 -1
  274. package/lib/wrapper/index.js +9 -21
  275. package/lib/wrapper/index.js.map +7 -1
  276. package/lib/wrapper/main.js +39 -20
  277. package/lib/wrapper/main.js.map +7 -1
  278. package/lib/wrapper/requestListener.js +50 -35
  279. package/lib/wrapper/requestListener.js.map +7 -1
  280. package/package.json +19 -13
  281. package/template/base/jest.config.ts +0 -6
  282. package/template/base/jest.setup.ts +2 -0
  283. package/template/express-rest-api/.buildkite/pipeline.yml +1 -1
  284. package/template/express-rest-api/package.json +1 -1
  285. package/template/greeter/.buildkite/pipeline.yml +1 -1
  286. package/template/greeter/package.json +1 -1
  287. package/template/greeter/src/app.test.ts +3 -1
  288. package/template/koa-rest-api/.buildkite/pipeline.yml +1 -1
  289. package/template/koa-rest-api/package.json +6 -7
  290. package/template/koa-rest-api/src/api/jobs/postJob.test.ts +3 -7
  291. package/template/koa-rest-api/src/api/jobs/postJob.ts +2 -2
  292. package/template/koa-rest-api/src/framework/validation.test.ts +17 -15
  293. package/template/koa-rest-api/src/framework/validation.ts +50 -9
  294. package/template/koa-rest-api/src/testing/types.ts +5 -10
  295. package/template/koa-rest-api/src/types/jobs.ts +5 -10
  296. package/template/lambda-sqs-worker/.buildkite/pipeline.yml +3 -3
  297. package/template/lambda-sqs-worker/package.json +2 -6
  298. package/template/lambda-sqs-worker/src/app.ts +2 -2
  299. package/template/lambda-sqs-worker/src/framework/validation.test.ts +37 -17
  300. package/template/lambda-sqs-worker/src/framework/validation.ts +4 -2
  301. package/template/lambda-sqs-worker/src/services/jobScorer.ts +2 -2
  302. package/template/lambda-sqs-worker/src/testing/types.ts +5 -10
  303. package/template/lambda-sqs-worker/src/types/jobScorer.ts +9 -16
  304. package/template/lambda-sqs-worker/src/types/pipelineEvents.ts +13 -20
  305. package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +3 -3
  306. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +6 -0
  307. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +3 -3
  308. package/template/lambda-sqs-worker-cdk/infra/index.ts +2 -2
  309. package/template/lambda-sqs-worker-cdk/package.json +2 -2
  310. package/template/lambda-sqs-worker-cdk/shared/context-types.ts +16 -25
  311. package/template/oss-npm-package/_package.json +1 -1
  312. package/template/private-npm-package/_package.json +1 -1
  313. package/jest/resolver.js +0 -24
@@ -1,178 +1,196 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.transformModuleImportsAndExports = exports.readModuleExports = exports.createPropAppender = exports.createPropFilter = void 0;
7
- const typescript_1 = __importDefault(require("typescript"));
8
- const prettier_1 = require("./prettier");
9
- const BLANK_LINE_PLACEHOLDER = ' __BLANK_LINE_PLACEHOLDER__';
10
- const BLANK_LINE_REGEXP = new RegExp(`//${BLANK_LINE_PLACEHOLDER}`, 'g');
11
- /**
12
- * Append a placeholder comment to the start of a node.
13
- *
14
- * Blank lines can be annotated and preserved through the TypeScript printer
15
- * when this is paired with a dodgy `String.prototype.replace` post-processor.
16
- */
17
- const withLeadingBlankLinePlaceholder = (node) => typescript_1.default.addSyntheticLeadingComment(node, typescript_1.default.SyntaxKind.SingleLineCommentTrivia, BLANK_LINE_PLACEHOLDER, true);
18
- /**
19
- * Create the following expression:
20
- *
21
- * ```javascript
22
- * export default {};
23
- * ```
24
- */
25
- const createExportDefaultObjectLiteralExpression = (factory, props, callExpression) => factory.createExportAssignment(undefined, undefined, undefined, callExpression === undefined
26
- ? factory.createObjectLiteralExpression(props, true)
27
- : factory.createCallExpression(callExpression, undefined, [
28
- factory.createObjectLiteralExpression(props, true),
29
- ]));
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var typescript_exports = {};
26
+ __export(typescript_exports, {
27
+ createPropAppender: () => createPropAppender,
28
+ createPropFilter: () => createPropFilter,
29
+ readModuleExports: () => readModuleExports,
30
+ transformModuleImportsAndExports: () => transformModuleImportsAndExports
31
+ });
32
+ module.exports = __toCommonJS(typescript_exports);
33
+ var import_typescript = __toESM(require("typescript"));
34
+ var import_prettier = require("./prettier");
35
+ const BLANK_LINE_PLACEHOLDER = " __BLANK_LINE_PLACEHOLDER__";
36
+ const BLANK_LINE_REGEXP = new RegExp(`//${BLANK_LINE_PLACEHOLDER}`, "g");
37
+ const withLeadingBlankLinePlaceholder = (node) => import_typescript.default.addSyntheticLeadingComment(
38
+ node,
39
+ import_typescript.default.SyntaxKind.SingleLineCommentTrivia,
40
+ BLANK_LINE_PLACEHOLDER,
41
+ true
42
+ );
43
+ const createExportDefaultObjectLiteralExpression = (factory, props, callExpression) => factory.createExportAssignment(
44
+ void 0,
45
+ void 0,
46
+ void 0,
47
+ callExpression === void 0 ? factory.createObjectLiteralExpression(props, true) : factory.createCallExpression(callExpression, void 0, [
48
+ factory.createObjectLiteralExpression(props, true)
49
+ ])
50
+ );
30
51
  const createImportFromExpression = (factory, moduleName, importNames) => {
31
- const importClause = typeof importNames === 'string'
32
- ? factory.createImportClause(false, factory.createIdentifier(importNames), undefined)
33
- : factory.createImportClause(false, undefined, factory.createNamedImports(importNames.map((importName) => factory.createImportSpecifier(false, undefined, factory.createIdentifier(importName)))));
34
- return factory.createImportDeclaration(undefined, undefined, importClause, factory.createStringLiteral(moduleName));
52
+ const importClause = typeof importNames === "string" ? factory.createImportClause(
53
+ false,
54
+ factory.createIdentifier(importNames),
55
+ void 0
56
+ ) : factory.createImportClause(
57
+ false,
58
+ void 0,
59
+ factory.createNamedImports(
60
+ importNames.map(
61
+ (importName) => factory.createImportSpecifier(
62
+ false,
63
+ void 0,
64
+ factory.createIdentifier(importName)
65
+ )
66
+ )
67
+ )
68
+ );
69
+ return factory.createImportDeclaration(
70
+ void 0,
71
+ void 0,
72
+ importClause,
73
+ factory.createStringLiteral(moduleName)
74
+ );
35
75
  };
36
- const getPropName = (prop) => typescript_1.default.isPropertyAssignment(prop) && typescript_1.default.isIdentifier(prop.name)
37
- ? prop.name.escapedText.toString()
38
- : undefined;
39
- const expressionAsDefaultExport = (context, transformProps, expression) => withLeadingBlankLinePlaceholder((() => {
40
- // {}
41
- if (typescript_1.default.isObjectLiteralExpression(expression)) {
42
- const props = transformProps(context, expression.properties);
43
- return createExportDefaultObjectLiteralExpression(context.factory, props);
76
+ const getPropName = (prop) => import_typescript.default.isPropertyAssignment(prop) && import_typescript.default.isIdentifier(prop.name) ? prop.name.escapedText.toString() : void 0;
77
+ const expressionAsDefaultExport = (context, transformProps, expression) => withLeadingBlankLinePlaceholder(
78
+ (() => {
79
+ if (import_typescript.default.isObjectLiteralExpression(expression)) {
80
+ const props = transformProps(context, expression.properties);
81
+ return createExportDefaultObjectLiteralExpression(
82
+ context.factory,
83
+ props
84
+ );
44
85
  }
45
- // fn({})
46
- if (typescript_1.default.isCallExpression(expression) &&
47
- expression.arguments.length === 1) {
48
- const [firstArgument] = expression.arguments;
49
- if (typescript_1.default.isObjectLiteralExpression(firstArgument)) {
50
- const props = transformProps(context, firstArgument.properties);
51
- return createExportDefaultObjectLiteralExpression(context.factory, props, expression.expression);
52
- }
86
+ if (import_typescript.default.isCallExpression(expression) && expression.arguments.length === 1) {
87
+ const [firstArgument] = expression.arguments;
88
+ if (import_typescript.default.isObjectLiteralExpression(firstArgument)) {
89
+ const props = transformProps(context, firstArgument.properties);
90
+ return createExportDefaultObjectLiteralExpression(
91
+ context.factory,
92
+ props,
93
+ expression.expression
94
+ );
95
+ }
53
96
  }
54
- // Anything else
55
- return context.factory.createExportAssignment(undefined, undefined, undefined, expression);
56
- })());
57
- /**
58
- * Mutate `const x = require('')` into `import x from ''`:
59
- *
60
- * ```javascript
61
- * const x = require('');
62
- *
63
- * const { x } = require('');
64
- * ```
65
- *
66
- * There's no recursion needed here as we expect the import statement to be a
67
- * top-level node and therefore an immediate child of the source file.
68
- */
69
- const requireImportsTransformer = (context) => (rootNode) => typescript_1.default.visitEachChild(rootNode, (node) => {
97
+ return context.factory.createExportAssignment(
98
+ void 0,
99
+ void 0,
100
+ void 0,
101
+ expression
102
+ );
103
+ })()
104
+ );
105
+ const requireImportsTransformer = (context) => (rootNode) => import_typescript.default.visitEachChild(
106
+ rootNode,
107
+ (node) => {
70
108
  let declaration, moduleName;
71
- if (typescript_1.default.isVariableStatement(node) &&
72
- node.declarationList.declarations.length === 1 &&
73
- typescript_1.default.isVariableDeclaration((declaration = node.declarationList.declarations[0])) &&
74
- declaration.initializer &&
75
- typescript_1.default.isCallExpression(declaration.initializer) &&
76
- declaration.initializer.arguments.length === 1 &&
77
- typescript_1.default.isStringLiteral((moduleName = declaration.initializer.arguments[0])) &&
78
- typescript_1.default.isIdentifier(declaration.initializer.expression) &&
79
- declaration.initializer.expression.text === 'require') {
80
- // const x
81
- if (typescript_1.default.isIdentifier(declaration.name)) {
82
- return createImportFromExpression(context.factory, moduleName.text, declaration.name.text);
83
- }
84
- // const { x }
85
- if (typescript_1.default.isObjectBindingPattern(declaration.name)) {
86
- return createImportFromExpression(context.factory, moduleName.text, declaration.name.elements.flatMap((element) => typescript_1.default.isIdentifier(element.name) ? [element.name.text] : []));
87
- }
109
+ if (import_typescript.default.isVariableStatement(node) && node.declarationList.declarations.length === 1 && import_typescript.default.isVariableDeclaration(
110
+ declaration = node.declarationList.declarations[0]
111
+ ) && declaration.initializer && import_typescript.default.isCallExpression(declaration.initializer) && declaration.initializer.arguments.length === 1 && import_typescript.default.isStringLiteral(
112
+ moduleName = declaration.initializer.arguments[0]
113
+ ) && import_typescript.default.isIdentifier(declaration.initializer.expression) && declaration.initializer.expression.text === "require") {
114
+ if (import_typescript.default.isIdentifier(declaration.name)) {
115
+ return createImportFromExpression(
116
+ context.factory,
117
+ moduleName.text,
118
+ declaration.name.text
119
+ );
120
+ }
121
+ if (import_typescript.default.isObjectBindingPattern(declaration.name)) {
122
+ return createImportFromExpression(
123
+ context.factory,
124
+ moduleName.text,
125
+ declaration.name.elements.flatMap(
126
+ (element) => import_typescript.default.isIdentifier(element.name) ? [element.name.text] : []
127
+ )
128
+ );
129
+ }
88
130
  }
89
131
  return node;
90
- }, context);
91
- /**
92
- * Create a transformer to mutate `module.exports` and `export default`:
93
- *
94
- * ```javascript
95
- * export default {};
96
- *
97
- * module.exports = {};
98
- * ```
99
- *
100
- * If the export is a call expression with a single argument, it will try to
101
- * transform the props of that argument.
102
- *
103
- * ```javascript
104
- * module.exports = fn({});
105
- * ```
106
- *
107
- * There's no recursion needed here as we expect the export statement to be a
108
- * top-level node and therefore an immediate child of the source file.
109
- */
110
- const createModuleExportsTransformer = (transformProps) => (context) => (rootNode) => typescript_1.default.visitEachChild(rootNode, (node) => {
111
- // module.exports =
112
- if (typescript_1.default.isExpressionStatement(node) &&
113
- typescript_1.default.isBinaryExpression(node.expression) &&
114
- typescript_1.default.isPropertyAccessExpression(node.expression.left) &&
115
- typescript_1.default.isIdentifier(node.expression.left.expression) &&
116
- node.expression.left.expression.escapedText === 'module' &&
117
- node.expression.left.name.text === 'exports' &&
118
- node.expression.operatorToken.kind === typescript_1.default.SyntaxKind.EqualsToken) {
119
- return (expressionAsDefaultExport(context, transformProps, node.expression.right) ?? node);
132
+ },
133
+ context
134
+ );
135
+ const createModuleExportsTransformer = (transformProps) => (context) => (rootNode) => import_typescript.default.visitEachChild(
136
+ rootNode,
137
+ (node) => {
138
+ if (import_typescript.default.isExpressionStatement(node) && import_typescript.default.isBinaryExpression(node.expression) && import_typescript.default.isPropertyAccessExpression(node.expression.left) && import_typescript.default.isIdentifier(node.expression.left.expression) && node.expression.left.expression.escapedText === "module" && node.expression.left.name.text === "exports" && node.expression.operatorToken.kind === import_typescript.default.SyntaxKind.EqualsToken) {
139
+ return expressionAsDefaultExport(
140
+ context,
141
+ transformProps,
142
+ node.expression.right
143
+ ) ?? node;
120
144
  }
121
- // export default
122
- if (typescript_1.default.isExportAssignment(node)) {
123
- return (expressionAsDefaultExport(context, transformProps, node.expression) ?? node);
145
+ if (import_typescript.default.isExportAssignment(node)) {
146
+ return expressionAsDefaultExport(
147
+ context,
148
+ transformProps,
149
+ node.expression
150
+ ) ?? node;
124
151
  }
125
152
  return node;
126
- }, context);
127
- /**
128
- * Create a transformer to filter out unspecified props from an object literal.
129
- */
153
+ },
154
+ context
155
+ );
130
156
  const createPropFilter = (names) => (context, props) => {
131
- const nameSet = new Set(names);
132
- const factory = context?.factory ?? typescript_1.default.factory;
133
- return factory.createNodeArray(props.filter((prop) => nameSet.has(getPropName(prop))));
157
+ const nameSet = new Set(names);
158
+ const factory = context?.factory ?? import_typescript.default.factory;
159
+ return factory.createNodeArray(
160
+ props.filter((prop) => nameSet.has(getPropName(prop)))
161
+ );
134
162
  };
135
- exports.createPropFilter = createPropFilter;
136
163
  const createPropAppender = (appendingProps) => (context, props) => {
137
- const nameSet = new Set(props.map(getPropName).filter((prop) => typeof prop === 'string'));
138
- const factory = context?.factory ?? typescript_1.default.factory;
139
- return factory.createNodeArray([
140
- ...props,
141
- ...appendingProps.filter((prop) => !nameSet.has(getPropName(prop))),
142
- ]);
164
+ const nameSet = new Set(
165
+ props.map(getPropName).filter((prop) => typeof prop === "string")
166
+ );
167
+ const factory = context?.factory ?? import_typescript.default.factory;
168
+ return factory.createNodeArray([
169
+ ...props,
170
+ ...appendingProps.filter((prop) => !nameSet.has(getPropName(prop)))
171
+ ]);
143
172
  };
144
- exports.createPropAppender = createPropAppender;
145
- /**
146
- * Read out `export default` or `module.exports` props from a source file.
147
- *
148
- * The props can then be used when transforming another source file.
149
- */
150
173
  const readModuleExports = (inputFile) => {
151
- let result;
152
- (0, exports.transformModuleImportsAndExports)(inputFile, (_, props) => (result = props));
153
- return result;
174
+ let result;
175
+ transformModuleImportsAndExports(inputFile, (_, props) => result = props);
176
+ return result;
154
177
  };
155
- exports.readModuleExports = readModuleExports;
156
- /**
157
- * Mutate imports and exports in a source file:
158
- *
159
- * - Convert `const x = require('')` into `import x from ''`
160
- * - Convert `module.exports =` into `export default`
161
- * - Run a transformer over the exported props
162
- */
163
178
  const transformModuleImportsAndExports = (inputFile, transformProps) => {
164
- const sourceFile = typescript_1.default.createSourceFile('', inputFile, typescript_1.default.ScriptTarget.Latest);
165
- const moduleExportsTransformer = createModuleExportsTransformer(transformProps);
166
- const result = typescript_1.default.transform(sourceFile, [
167
- requireImportsTransformer,
168
- moduleExportsTransformer,
169
- ]);
170
- const [transformedFile] = result.transformed;
171
- const text = typescript_1.default
172
- .createPrinter()
173
- .printNode(typescript_1.default.EmitHint.SourceFile, transformedFile, sourceFile)
174
- .replace(BLANK_LINE_REGEXP, '');
175
- return (0, prettier_1.formatPrettier)(text, { parser: 'typescript' });
179
+ const sourceFile = import_typescript.default.createSourceFile("", inputFile, import_typescript.default.ScriptTarget.Latest);
180
+ const moduleExportsTransformer = createModuleExportsTransformer(transformProps);
181
+ const result = import_typescript.default.transform(sourceFile, [
182
+ requireImportsTransformer,
183
+ moduleExportsTransformer
184
+ ]);
185
+ const [transformedFile] = result.transformed;
186
+ const text = import_typescript.default.createPrinter().printNode(import_typescript.default.EmitHint.SourceFile, transformedFile, sourceFile).replace(BLANK_LINE_REGEXP, "");
187
+ return (0, import_prettier.formatPrettier)(text, { parser: "typescript" });
176
188
  };
177
- exports.transformModuleImportsAndExports = transformModuleImportsAndExports;
178
- //# sourceMappingURL=typescript.js.map
189
+ // Annotate the CommonJS export names for ESM import in node:
190
+ 0 && (module.exports = {
191
+ createPropAppender,
192
+ createPropFilter,
193
+ readModuleExports,
194
+ transformModuleImportsAndExports
195
+ });
196
+ //# sourceMappingURL=typescript.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../../../src/cli/configure/processing/typescript.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA4B;AAE5B,yCAA4C;AAM5C,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AAC7D,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAAC,KAAK,sBAAsB,EAAE,EAAE,GAAG,CAAC,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,+BAA+B,GAAG,CAAoB,IAAO,EAAE,EAAE,CACrE,oBAAE,CAAC,0BAA0B,CAC3B,IAAI,EACJ,oBAAE,CAAC,UAAU,CAAC,uBAAuB,EACrC,sBAAsB,EACtB,IAAI,CACL,CAAC;AAEJ;;;;;;GAMG;AACH,MAAM,0CAA0C,GAAG,CACjD,OAAuB,EACvB,KAAY,EACZ,cAA8B,EACT,EAAE,CACvB,OAAO,CAAC,sBAAsB,CAC5B,SAAS,EACT,SAAS,EACT,SAAS,EACT,cAAc,KAAK,SAAS;IAC1B,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,IAAI,CAAC;IACpD,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,cAAc,EAAE,SAAS,EAAE;QACtD,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,IAAI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ACZ,aAAa,EAAE;SACf,SAAS,CAAC,oBAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,eAAe,EAAE,UAAU,CAAC;SAC9D,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IAElC,OAAO,IAAA,yBAAc,EAAC,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;AACxD,CAAC,CAAC;AAtBW,QAAA,gCAAgC,oCAsB3C"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/cli/configure/processing/typescript.ts"],
4
+ "sourcesContent": ["import ts from 'typescript';\n\nimport { formatPrettier } from './prettier';\n\ntype Props = ts.NodeArray<ts.ObjectLiteralElementLike>;\n\ntype Transformer<T> = (context: ts.TransformationContext | null, props: T) => T;\n\nconst BLANK_LINE_PLACEHOLDER = ' __BLANK_LINE_PLACEHOLDER__';\nconst BLANK_LINE_REGEXP = new RegExp(`//${BLANK_LINE_PLACEHOLDER}`, 'g');\n\n/**\n * Append a placeholder comment to the start of a node.\n *\n * Blank lines can be annotated and preserved through the TypeScript printer\n * when this is paired with a dodgy `String.prototype.replace` post-processor.\n */\nconst withLeadingBlankLinePlaceholder = <T extends ts.Node>(node: T) =>\n ts.addSyntheticLeadingComment(\n node,\n ts.SyntaxKind.SingleLineCommentTrivia,\n BLANK_LINE_PLACEHOLDER,\n true,\n );\n\n/**\n * Create the following expression:\n *\n * ```javascript\n * export default {};\n * ```\n */\nconst createExportDefaultObjectLiteralExpression = (\n factory: ts.NodeFactory,\n props: Props,\n callExpression?: ts.Expression,\n): ts.ExportAssignment =>\n factory.createExportAssignment(\n undefined,\n undefined,\n undefined,\n callExpression === undefined\n ? factory.createObjectLiteralExpression(props, true)\n : factory.createCallExpression(callExpression, undefined, [\n factory.createObjectLiteralExpression(props, true),\n ]),\n );\n\nconst createImportFromExpression = (\n factory: ts.NodeFactory,\n moduleName: string,\n importNames: string | string[],\n) => {\n const importClause =\n typeof importNames === 'string'\n ? factory.createImportClause(\n false,\n factory.createIdentifier(importNames),\n undefined,\n )\n : factory.createImportClause(\n false,\n undefined,\n factory.createNamedImports(\n importNames.map((importName) =>\n factory.createImportSpecifier(\n false,\n undefined,\n factory.createIdentifier(importName),\n ),\n ),\n ),\n );\n\n return factory.createImportDeclaration(\n undefined,\n undefined,\n importClause,\n factory.createStringLiteral(moduleName),\n );\n};\n\nconst getPropName = (prop: ts.ObjectLiteralElementLike) =>\n ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)\n ? prop.name.escapedText.toString()\n : undefined;\n\nconst expressionAsDefaultExport = (\n context: ts.TransformationContext,\n transformProps: Transformer<Props>,\n expression: ts.Expression,\n): ts.ExportAssignment | null =>\n withLeadingBlankLinePlaceholder(\n (() => {\n // {}\n if (ts.isObjectLiteralExpression(expression)) {\n const props = transformProps(context, expression.properties);\n\n return createExportDefaultObjectLiteralExpression(\n context.factory,\n props,\n );\n }\n\n // fn({})\n if (\n ts.isCallExpression(expression) &&\n expression.arguments.length === 1\n ) {\n const [firstArgument] = expression.arguments;\n\n if (ts.isObjectLiteralExpression(firstArgument)) {\n const props = transformProps(context, firstArgument.properties);\n\n return createExportDefaultObjectLiteralExpression(\n context.factory,\n props,\n expression.expression,\n );\n }\n }\n\n // Anything else\n return context.factory.createExportAssignment(\n undefined,\n undefined,\n undefined,\n expression,\n );\n })(),\n );\n\n/**\n * Mutate `const x = require('')` into `import x from ''`:\n *\n * ```javascript\n * const x = require('');\n *\n * const { x } = require('');\n * ```\n *\n * There's no recursion needed here as we expect the import statement to be a\n * top-level node and therefore an immediate child of the source file.\n */\nconst requireImportsTransformer: ts.TransformerFactory<ts.Node> =\n (context) => (rootNode) =>\n ts.visitEachChild(\n rootNode,\n (node) => {\n let declaration, moduleName;\n\n if (\n ts.isVariableStatement(node) &&\n node.declarationList.declarations.length === 1 &&\n ts.isVariableDeclaration(\n (declaration = node.declarationList.declarations[0]),\n ) &&\n declaration.initializer &&\n ts.isCallExpression(declaration.initializer) &&\n declaration.initializer.arguments.length === 1 &&\n ts.isStringLiteral(\n (moduleName = declaration.initializer.arguments[0]),\n ) &&\n ts.isIdentifier(declaration.initializer.expression) &&\n declaration.initializer.expression.text === 'require'\n ) {\n // const x\n if (ts.isIdentifier(declaration.name)) {\n return createImportFromExpression(\n context.factory,\n moduleName.text,\n declaration.name.text,\n );\n }\n\n // const { x }\n if (ts.isObjectBindingPattern(declaration.name)) {\n return createImportFromExpression(\n context.factory,\n moduleName.text,\n declaration.name.elements.flatMap((element) =>\n ts.isIdentifier(element.name) ? [element.name.text] : [],\n ),\n );\n }\n }\n\n return node;\n },\n context,\n );\n\n/**\n * Create a transformer to mutate `module.exports` and `export default`:\n *\n * ```javascript\n * export default {};\n *\n * module.exports = {};\n * ```\n *\n * If the export is a call expression with a single argument, it will try to\n * transform the props of that argument.\n *\n * ```javascript\n * module.exports = fn({});\n * ```\n *\n * There's no recursion needed here as we expect the export statement to be a\n * top-level node and therefore an immediate child of the source file.\n */\nconst createModuleExportsTransformer =\n (transformProps: Transformer<Props>): ts.TransformerFactory<ts.Node> =>\n (context) =>\n (rootNode) =>\n ts.visitEachChild(\n rootNode,\n (node) => {\n // module.exports =\n if (\n ts.isExpressionStatement(node) &&\n ts.isBinaryExpression(node.expression) &&\n ts.isPropertyAccessExpression(node.expression.left) &&\n ts.isIdentifier(node.expression.left.expression) &&\n node.expression.left.expression.escapedText === 'module' &&\n node.expression.left.name.text === 'exports' &&\n node.expression.operatorToken.kind === ts.SyntaxKind.EqualsToken\n ) {\n return (\n expressionAsDefaultExport(\n context,\n transformProps,\n node.expression.right,\n ) ?? node\n );\n }\n\n // export default\n if (ts.isExportAssignment(node)) {\n return (\n expressionAsDefaultExport(\n context,\n transformProps,\n node.expression,\n ) ?? node\n );\n }\n\n return node;\n },\n context,\n );\n\n/**\n * Create a transformer to filter out unspecified props from an object literal.\n */\nexport const createPropFilter =\n (names: string[]): Transformer<Props> =>\n (context, props) => {\n const nameSet = new Set<unknown>(names);\n\n const factory = context?.factory ?? ts.factory;\n\n return factory.createNodeArray(\n props.filter((prop) => nameSet.has(getPropName(prop))),\n );\n };\n\nexport const createPropAppender =\n (appendingProps: Props): Transformer<Props> =>\n (context, props) => {\n const nameSet = new Set<unknown>(\n props.map(getPropName).filter((prop) => typeof prop === 'string'),\n );\n\n const factory = context?.factory ?? ts.factory;\n\n return factory.createNodeArray([\n ...props,\n ...appendingProps.filter((prop) => !nameSet.has(getPropName(prop))),\n ]);\n };\n\n/**\n * Read out `export default` or `module.exports` props from a source file.\n *\n * The props can then be used when transforming another source file.\n */\nexport const readModuleExports = (inputFile: string): Props | undefined => {\n let result: Props | undefined;\n\n transformModuleImportsAndExports(inputFile, (_, props) => (result = props));\n\n return result;\n};\n\n/**\n * Mutate imports and exports in a source file:\n *\n * - Convert `const x = require('')` into `import x from ''`\n * - Convert `module.exports =` into `export default`\n * - Run a transformer over the exported props\n */\nexport const transformModuleImportsAndExports = (\n inputFile: string,\n transformProps: Transformer<Props>,\n): string => {\n const sourceFile = ts.createSourceFile('', inputFile, ts.ScriptTarget.Latest);\n\n const moduleExportsTransformer =\n createModuleExportsTransformer(transformProps);\n\n const result = ts.transform(sourceFile, [\n requireImportsTransformer,\n moduleExportsTransformer,\n ]);\n\n const [transformedFile] = result.transformed;\n\n const text = ts\n .createPrinter()\n .printNode(ts.EmitHint.SourceFile, transformedFile, sourceFile)\n .replace(BLANK_LINE_REGEXP, '');\n\n return formatPrettier(text, { parser: 'typescript' });\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAe;AAEf,sBAA+B;AAM/B,MAAM,yBAAyB;AAC/B,MAAM,oBAAoB,IAAI,OAAO,KAAK,0BAA0B,GAAG;AAQvE,MAAM,kCAAkC,CAAoB,SAC1D,kBAAAA,QAAG;AAAA,EACD;AAAA,EACA,kBAAAA,QAAG,WAAW;AAAA,EACd;AAAA,EACA;AACF;AASF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,GAAG,UAAW,SAAS,KAAM;AAE1E,SAAO;AACT;AASO,MAAM,mCAAmC,CAC9C,WACA,mBACW;AACX,QAAM,aAAa,kBAAAA,QAAG,iBAAiB,IAAI,WAAW,kBAAAA,QAAG,aAAa,MAAM;AAE5E,QAAM,2BACJ,+BAA+B,cAAc;AAE/C,QAAM,SAAS,kBAAAA,QAAG,UAAU,YAAY;AAAA,IACtC;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,CAAC,eAAe,IAAI,OAAO;AAEjC,QAAM,OAAO,kBAAAA,QACV,cAAc,EACd,UAAU,kBAAAA,QAAG,SAAS,YAAY,iBAAiB,UAAU,EAC7D,QAAQ,mBAAmB,EAAE;AAEhC,aAAO,gCAAe,MAAM,EAAE,QAAQ,aAAa,CAAC;AACtD;",
6
+ "names": ["ts"]
7
+ }
@@ -1,47 +1,71 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.tryRefreshIgnoreFiles = exports.refreshIgnoreFiles = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const util_1 = require("util");
9
- const fs_extra_1 = __importDefault(require("fs-extra"));
10
- const logging_1 = require("../../utils/logging");
11
- const template_1 = require("../../utils/template");
12
- const package_1 = require("./analysis/package");
13
- const project_1 = require("./analysis/project");
14
- const ignoreFile_1 = require("./processing/ignoreFile");
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var refreshIgnoreFiles_exports = {};
26
+ __export(refreshIgnoreFiles_exports, {
27
+ refreshIgnoreFiles: () => refreshIgnoreFiles,
28
+ tryRefreshIgnoreFiles: () => tryRefreshIgnoreFiles
29
+ });
30
+ module.exports = __toCommonJS(refreshIgnoreFiles_exports);
31
+ var import_path = __toESM(require("path"));
32
+ var import_util = require("util");
33
+ var import_fs_extra = __toESM(require("fs-extra"));
34
+ var import_logging = require("../../utils/logging");
35
+ var import_template = require("../../utils/template");
36
+ var import_package = require("./analysis/package");
37
+ var import_project = require("./analysis/project");
38
+ var import_ignoreFile = require("./processing/ignoreFile");
15
39
  const refreshIgnoreFiles = async () => {
16
- const manifest = await (0, package_1.getDestinationManifest)();
17
- const destinationRoot = path_1.default.dirname(manifest.path);
18
- const readDestinationFile = (0, project_1.createDestinationFileReader)(destinationRoot);
19
- const refreshIgnoreFile = async (filename) => {
20
- const [inputFile, templateFile] = await Promise.all([
21
- readDestinationFile(filename),
22
- (0, template_1.readBaseTemplateFile)(`_${filename}`),
23
- ]);
24
- const data = inputFile
25
- ? (0, ignoreFile_1.mergeWithIgnoreFile)(templateFile)(inputFile)
26
- : templateFile;
27
- const filepath = path_1.default.join(destinationRoot, filename);
28
- await fs_extra_1.default.promises.writeFile(filepath, data);
29
- };
30
- await Promise.all([
31
- refreshIgnoreFile('.eslintignore'),
32
- refreshIgnoreFile('.gitignore'),
33
- refreshIgnoreFile('.prettierignore'),
40
+ const manifest = await (0, import_package.getDestinationManifest)();
41
+ const destinationRoot = import_path.default.dirname(manifest.path);
42
+ const readDestinationFile = (0, import_project.createDestinationFileReader)(destinationRoot);
43
+ const refreshIgnoreFile = async (filename) => {
44
+ const [inputFile, templateFile] = await Promise.all([
45
+ readDestinationFile(filename),
46
+ (0, import_template.readBaseTemplateFile)(`_${filename}`)
34
47
  ]);
48
+ const data = inputFile ? (0, import_ignoreFile.mergeWithIgnoreFile)(templateFile)(inputFile) : templateFile;
49
+ const filepath = import_path.default.join(destinationRoot, filename);
50
+ await import_fs_extra.default.promises.writeFile(filepath, data);
51
+ };
52
+ await Promise.all([
53
+ refreshIgnoreFile(".eslintignore"),
54
+ refreshIgnoreFile(".gitignore"),
55
+ refreshIgnoreFile(".prettierignore")
56
+ ]);
35
57
  };
36
- exports.refreshIgnoreFiles = refreshIgnoreFiles;
37
58
  const tryRefreshIgnoreFiles = async () => {
38
- try {
39
- await (0, exports.refreshIgnoreFiles)();
40
- }
41
- catch (err) {
42
- logging_1.log.warn('Failed to refresh ignore files.');
43
- logging_1.log.subtle((0, util_1.inspect)(err));
44
- }
59
+ try {
60
+ await refreshIgnoreFiles();
61
+ } catch (err) {
62
+ import_logging.log.warn("Failed to refresh ignore files.");
63
+ import_logging.log.subtle((0, import_util.inspect)(err));
64
+ }
45
65
  };
46
- exports.tryRefreshIgnoreFiles = tryRefreshIgnoreFiles;
47
- //# sourceMappingURL=refreshIgnoreFiles.js.map
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ refreshIgnoreFiles,
69
+ tryRefreshIgnoreFiles
70
+ });
71
+ //# sourceMappingURL=refreshIgnoreFiles.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"refreshIgnoreFiles.js","sourceRoot":"","sources":["../../../src/cli/configure/refreshIgnoreFiles.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,+BAA+B;AAE/B,wDAA0B;AA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AI,CAAC,iCAAiC,CAAC,CAAC;QAC5C,aAAG,CAAC,MAAM,CAAC,IAAA,cAAO,EAAC,GAAG,CAAC,CAAC,CAAC;KAC1B;AACH,CAAC,CAAC;AAPW,QAAA,qBAAqB,yBAOhC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/cli/configure/refreshIgnoreFiles.ts"],
4
+ "sourcesContent": ["import path from 'path';\nimport { inspect } from 'util';\n\nimport fs from 'fs-extra';\n\nimport { log } from '../../utils/logging';\nimport { readBaseTemplateFile } from '../../utils/template';\n\nimport { getDestinationManifest } from './analysis/package';\nimport { createDestinationFileReader } from './analysis/project';\nimport { mergeWithIgnoreFile } from './processing/ignoreFile';\n\nexport const refreshIgnoreFiles = async () => {\n const manifest = await getDestinationManifest();\n\n const destinationRoot = path.dirname(manifest.path);\n\n const readDestinationFile = createDestinationFileReader(destinationRoot);\n\n const refreshIgnoreFile = async (filename: string) => {\n const [inputFile, templateFile] = await Promise.all([\n readDestinationFile(filename),\n readBaseTemplateFile(`_${filename}`),\n ]);\n\n const data = inputFile\n ? mergeWithIgnoreFile(templateFile)(inputFile)\n : templateFile;\n\n const filepath = path.join(destinationRoot, filename);\n\n await fs.promises.writeFile(filepath, data);\n };\n\n await Promise.all([\n refreshIgnoreFile('.eslintignore'),\n refreshIgnoreFile('.gitignore'),\n refreshIgnoreFile('.prettierignore'),\n ]);\n};\n\nexport const tryRefreshIgnoreFiles = async () => {\n try {\n await refreshIgnoreFiles();\n } catch (err) {\n log.warn('Failed to refresh ignore files.');\n log.subtle(inspect(err));\n }\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,kBAAwB;AAExB,sBAAe;AAEf,qBAAoB;AACpB,sBAAqC;AAErC,qBAAuC;AACvC,qBAA4C;AAC5C,wBAAoC;AAE7B,MAAM,qBAAqB,YAAY;AAC5C,QAAM,WAAW,UAAM,uCAAuB;AAE9C,QAAM,kBAAkB,YAAAA,QAAK,QAAQ,SAAS,IAAI;AAElD,QAAM,0BAAsB,4CAA4B,eAAe;AAEvE,QAAM,oBAAoB,OAAO,aAAqB;AACpD,UAAM,CAAC,WAAW,YAAY,IAAI,MAAM,QAAQ,IAAI;AAAA,MAClD,oBAAoB,QAAQ;AAAA,UAC5B,sCAAqB,IAAI,UAAU;AAAA,IACrC,CAAC;AAED,UAAM,OAAO,gBACT,uCAAoB,YAAY,EAAE,SAAS,IAC3C;AAEJ,UAAM,WAAW,YAAAA,QAAK,KAAK,iBAAiB,QAAQ;AAEpD,UAAM,gBAAAC,QAAG,SAAS,UAAU,UAAU,IAAI;AAAA,EAC5C;AAEA,QAAM,QAAQ,IAAI;AAAA,IAChB,kBAAkB,eAAe;AAAA,IACjC,kBAAkB,YAAY;AAAA,IAC9B,kBAAkB,iBAAiB;AAAA,EACrC,CAAC;AACH;AAEO,MAAM,wBAAwB,YAAY;AAC/C,MAAI;AACF,UAAM,mBAAmB;AAAA,EAC3B,SAAS,KAAP;AACA,uBAAI,KAAK,iCAAiC;AAC1C,uBAAI,WAAO,qBAAQ,GAAG,CAAC;AAAA,EACzB;AACF;",
6
+ "names": ["path", "fs"]
7
+ }
@@ -1,3 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
17
+ //# sourceMappingURL=types.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cli/configure/types.ts"],"names":[],"mappings":""}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/cli/configure/types.ts"],
4
+ "sourcesContent": ["import type { PackageJson as TypeFestPackageJson } from 'type-fest';\n\nimport type { ProjectType } from '../../utils/manifest';\n\nexport type { TsConfigJson } from 'type-fest';\n\nexport type PackageJson = TypeFestPackageJson & Record<string, unknown>;\n\nexport interface DependencySet {\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n type: ProjectType;\n}\n\nexport type DependencyDiff = Record<\n string,\n { operation: string; version: string }\n>;\n\ntype FileProcessor = (\n file: string | undefined,\n files: Files,\n initialFiles: Readonly<Files>,\n) => string | undefined;\n\nexport type FileDiff = Record<\n string,\n { data: string | undefined; operation: string }\n>;\n\nexport type Files = Record<string, string | undefined>;\n\nexport type Module = Record<string, FileProcessor>;\n\nexport interface Options {\n destinationRoot: string;\n entryPoint: string;\n firstRun: boolean;\n type: ProjectType;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }