typesync 0.13.4 → 0.13.5-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 (57) hide show
  1. package/README.md +23 -25
  2. package/bin/typesync +2 -2
  3. package/{lib → dist}/cli-util.d.ts +17 -17
  4. package/{lib → dist}/cli.d.ts +2 -2
  5. package/dist/cli.js +297 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config-service.d.ts +11 -0
  8. package/dist/globber.d.ts +15 -0
  9. package/dist/index.d.ts +4 -0
  10. package/dist/index.js +3 -0
  11. package/dist/package-json-file-service.d.ts +15 -0
  12. package/dist/package-source.d.ts +25 -0
  13. package/dist/type-syncer-C_rkDNfx.js +320 -0
  14. package/dist/type-syncer-C_rkDNfx.js.map +1 -0
  15. package/dist/type-syncer.d.ts +13 -0
  16. package/dist/types.d.ts +103 -0
  17. package/dist/util.d.ts +53 -0
  18. package/dist/versioning.d.ts +14 -0
  19. package/dist/workspace-resolver.d.ts +75 -0
  20. package/package.json +33 -53
  21. package/lib/cli-util.js +0 -74
  22. package/lib/cli-util.js.map +0 -1
  23. package/lib/cli.js +0 -141
  24. package/lib/cli.js.map +0 -1
  25. package/lib/config-service.d.ts +0 -11
  26. package/lib/config-service.js +0 -61
  27. package/lib/config-service.js.map +0 -1
  28. package/lib/fs-utils.js +0 -28
  29. package/lib/fs-utils.js.map +0 -1
  30. package/lib/globber.d.ts +0 -15
  31. package/lib/globber.js +0 -43
  32. package/lib/globber.js.map +0 -1
  33. package/lib/index.d.ts +0 -4
  34. package/lib/index.js +0 -21
  35. package/lib/index.js.map +0 -1
  36. package/lib/package-json-file-service.d.ts +0 -15
  37. package/lib/package-json-file-service.js +0 -48
  38. package/lib/package-json-file-service.js.map +0 -1
  39. package/lib/package-source.d.ts +0 -25
  40. package/lib/package-source.js +0 -49
  41. package/lib/package-source.js.map +0 -1
  42. package/lib/type-syncer.d.ts +0 -13
  43. package/lib/type-syncer.js +0 -239
  44. package/lib/type-syncer.js.map +0 -1
  45. package/lib/types.d.ts +0 -103
  46. package/lib/types.js +0 -14
  47. package/lib/types.js.map +0 -1
  48. package/lib/util.d.ts +0 -53
  49. package/lib/util.js +0 -142
  50. package/lib/util.js.map +0 -1
  51. package/lib/versioning.d.ts +0 -14
  52. package/lib/versioning.js +0 -48
  53. package/lib/versioning.js.map +0 -1
  54. package/lib/workspace-resolver.d.ts +0 -79
  55. package/lib/workspace-resolver.js +0 -70
  56. package/lib/workspace-resolver.js.map +0 -1
  57. /package/{lib → dist}/fs-utils.d.ts +0 -0
package/README.md CHANGED
@@ -1,48 +1,46 @@
1
- # typesync
1
+ # TypeSync
2
2
 
3
3
  Install missing TypeScript typings for dependencies in your `package.json`.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/typesync.svg?maxAge=1000)](https://www.npmjs.com/package/typesync)
6
- [![dependency Status](https://img.shields.io/david/jeffijoe/typesync.svg?maxAge=1000)](https://david-dm.org/jeffijoe/typesync)
7
- [![devDependency Status](https://img.shields.io/david/dev/jeffijoe/typesync.svg?maxAge=1000)](https://david-dm.org/jeffijoe/typesync)
8
- [![Build Status](https://img.shields.io/travis/jeffijoe/typesync.svg?maxAge=1000)](https://travis-ci.com/jeffijoe/typesync)
6
+ [![Build Status](https://github.com/jeffijoe/typesync/workflows/ci.yml/badge.svg?branch=master)](https://github.com/jeffijoe/typesync/actions)
9
7
  [![Coveralls](https://img.shields.io/coveralls/jeffijoe/typesync.svg?maxAge=1000)](https://coveralls.io/github/jeffijoe/typesync)
10
8
  [![npm](https://img.shields.io/npm/dt/typesync.svg?maxAge=1000)](https://www.npmjs.com/package/typesync)
11
- [![npm](https://img.shields.io/npm/l/typesync.svg?maxAge=1000)](https://github.com/jeffijoe/typesync/blob/master/LICENSE.md)
9
+ [![license](https://img.shields.io/npm/l/typesync.svg?maxAge=1000)](https://github.com/jeffijoe/typesync/blob/master/LICENSE.md)
12
10
  [![node](https://img.shields.io/node/v/typesync.svg?maxAge=1000)](https://www.npmjs.com/package/typesync)
13
11
 
14
12
  ![TypeSync](/typesync.gif)
15
13
 
16
- # Install
14
+ ## Install
17
15
 
18
- ```
16
+ ```sh
19
17
  npm install -g typesync
20
18
  ```
21
19
 
22
20
  You can also use it directly with `npx` which will install it for you:
23
21
 
24
- ```
22
+ ```sh
25
23
  npx typesync
26
24
  ```
27
25
 
28
- # Usage
26
+ ## Usage
29
27
 
30
- ```
28
+ ```sh
31
29
  typesync [path/to/package.json] [--dry]
32
30
  ```
33
31
 
34
32
  Path is relative to the current working directory. If omitted, defaults to `package.json`.
35
33
 
36
- **Note**: `typesync` only modifies your `package.json` - you still need to run `npm install`, or — if drinking the k00laid — `yarn`.
34
+ **Note**: TypeSync only modifies your `package.json` - you still need to run an installer.
37
35
 
38
- ## `--dry[=fail]`
36
+ ### `--dry[=fail]`
39
37
 
40
38
  If `--dry` is specified, will not actually write to the file, it only prints added/removed typings.
41
39
 
42
40
  The same is true for `--dry=fail`, with the additional effect of failing the command in case there are changes.
43
41
  This is useful for CI scenarios.
44
42
 
45
- ## `--ignoredeps`
43
+ ### `--ignoredeps`
46
44
 
47
45
  To ignore certain sections, you can use the `--ignoredeps=` flag. For example, to ignore `devDependencies`, use `--ignoredeps=dev`. To ignore multiple, comma-separate them, like this: `--ignoredeps=deps,peer` (ignores `dependencies` and `peerDependencies`).
48
46
 
@@ -51,12 +49,12 @@ To ignore certain sections, you can use the `--ignoredeps=` flag. For example, t
51
49
  - `--ignoredeps=peer` — ignores `peerDependencies`
52
50
  - `--ignoredeps=optional` — ignores `optionalDependencies`
53
51
 
54
- ## `--ignorepackages`
52
+ ### `--ignorepackages`
55
53
 
56
54
  To ignore certain packages, you can use the `--ignorepackages=` flag. For example, to ignore `nodemon`, use `--ignorepackages=nodemon`.
57
55
  To ignore multiple, comma-separate them, like this: `--ignorepackages=nodemon,whatever` (ignores `nodemon` and `whatever`).
58
56
 
59
- ## Using a config file
57
+ ### Using a config file
60
58
 
61
59
  Alternatively, you can use a TypeSync config file: `.typesyncrc` or a `"typesync"` section in your `package.json`. TypeSync will **automatically** search for configuration files. See [cosmiconfig][cosmiconfig] for details.
62
60
 
@@ -68,7 +66,7 @@ Alternatively, you can use a TypeSync config file: `.typesyncrc` or a `"typesync
68
66
  }
69
67
  ```
70
68
 
71
- ## Run TypeSync Automatically After Every Install
69
+ ### Run TypeSync automatically after every install
72
70
 
73
71
  To run TypeSync and install packages automatically after every package install, create a file called `install-with-types.sh` with the following content:
74
72
 
@@ -104,39 +102,39 @@ Add the following to `package.json`:
104
102
 
105
103
  Then install packages like this:
106
104
 
107
- ```bash
105
+ ```sh
108
106
  npm run i <pkg name>
109
107
 
110
- # Or, with yarn:
108
+ # Or with Yarn:
111
109
  yarn i <pkg name>
112
110
  ```
113
111
 
114
- # Typings packages
112
+ ## Typings packages
115
113
 
116
114
  TypeSync will add typings for packages that:
117
115
 
118
116
  - have a `@types/package` available
119
117
  - don't already provide typings internally (the `typings` and `types` field in `package.json`)
120
118
 
121
- TypeSync will try to respect semver parity for the code and typings packages, and will fall back to the latest available typings package.
119
+ TypeSync will try to respect SemVer parity for the code and typings packages, and will fall back to the latest available typings package.
122
120
 
123
- When writing the typings package version to `package.json`, the `~` semver range is used. This is because typings published via [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library) align typings versions with library versions using major and minor only.
121
+ When writing the typings package version to `package.json`, the `~` SemVer range is used. This is because typings published via [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library) align typings versions with library versions using major and minor only.
124
122
 
125
123
  For example, if you depend on `react@^16.14.0`, then TypeSync will only look for typings packages that match `16.14.*`.
126
124
 
127
- # Monorepos
125
+ ## Monorepos
128
126
 
129
127
  TypeSync added support for monorepos in v0.4.0. It will look at `packages`/`workspaces` globs in `package.json` and sync every matching file in one fell swoop.
130
128
 
131
- # Why?
129
+ ## Why?
132
130
 
133
131
  Installing typings manually sucks. Flow has `flow-typed` which installs type definitions by looking at a `package.json`, which would be cool to have for TypeScript. Now we do!
134
132
 
135
- # Changelog
133
+ ## Changelog
136
134
 
137
135
  See [CHANGELOG.md](/CHANGELOG.md)
138
136
 
139
- # Author
137
+ ## Author
140
138
 
141
139
  Jeff Hansen - [@Jeffijoe](https://twitter.com/jeffijoe)
142
140
 
package/bin/typesync CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- const { startCli } = require('../lib/cli')
2
+ import { startCli } from '../dist/cli.js'
3
3
 
4
- startCli()
4
+ await startCli()
@@ -1,27 +1,27 @@
1
- import type { ICLIArguments } from './types';
1
+ import type { ICLIArguments } from "./types.js";
2
2
  /**
3
- * Like regular console.log, but better.
4
- * @param message
5
- */
3
+ * Like regular console.log, but better.
4
+ * @param message
5
+ */
6
6
  export declare function log(message: string): void;
7
7
  /**
8
- * Makes success feel even sweeter.
9
- * @param text
10
- */
8
+ * Makes success feel even sweeter.
9
+ * @param text
10
+ */
11
11
  export declare function success(text: string): void;
12
12
  /**
13
- * Logs an error all pretty.
14
- * @param err
15
- */
13
+ * Logs an error all pretty.
14
+ * @param err
15
+ */
16
16
  export declare function error(err: Error | string): void;
17
17
  /**
18
- * Spins while doing work. Stops when done.
19
- * @param text
20
- * @param fn
21
- */
18
+ * Spins while doing work. Stops when done.
19
+ * @param text
20
+ * @param fn
21
+ */
22
22
  export declare function spinWhile<T>(text: string, fn: () => Promise<T>): Promise<T>;
23
23
  /**
24
- * Super simple argument parser.
25
- * @param argv
26
- */
24
+ * Super simple argument parser.
25
+ * @param argv
26
+ */
27
27
  export declare function parseArguments(argv: Array<string>): ICLIArguments;
@@ -1,4 +1,4 @@
1
1
  /**
2
- * Starts the TypeSync CLI.
3
- */
2
+ * Starts the TypeSync CLI.
3
+ */
4
4
  export declare function startCli(): Promise<void>;
package/dist/cli.js ADDED
@@ -0,0 +1,297 @@
1
+ import { createConfigService, createPackageSource, createTypeSyncer, ensureWorkspacesArray, uniq } from "./type-syncer-C_rkDNfx.js";
2
+ import * as path$1 from "node:path";
3
+ import * as path from "node:path";
4
+ import { InjectionMode, asFunction, createContainer } from "awilix";
5
+ import chalk, { default as chalk$1 } from "chalk";
6
+ import { oraPromise } from "ora";
7
+ import { glob } from "tinyglobby";
8
+ import * as fsp from "node:fs/promises";
9
+ import { readFile } from "node:fs/promises";
10
+ import detectIndent from "detect-indent";
11
+ import yaml from "js-yaml";
12
+
13
+ //#region rolldown:runtime
14
+ var __defProp = Object.defineProperty;
15
+ var __export = (target, all) => {
16
+ for (var name$1 in all) __defProp(target, name$1, {
17
+ get: all[name$1],
18
+ enumerable: true
19
+ });
20
+ };
21
+
22
+ //#endregion
23
+ //#region src/cli-util.ts
24
+ function log(message) {
25
+ console.log(`${chalk$1.white("»")} ${chalk$1.gray(message)}`);
26
+ }
27
+ function success(text) {
28
+ console.log(`${chalk$1.green("✔")} ${chalk$1.white(text)}`);
29
+ }
30
+ function error(err) {
31
+ const msg = err instanceof Error ? err.message : err;
32
+ const stack = err instanceof Error ? `\nStack:\n${err.stack}` : "";
33
+ console.log(`${chalk$1.red("✖")} ${chalk$1.bgRed(chalk$1.white(msg))}${stack}`);
34
+ }
35
+ async function spinWhile(text, fn) {
36
+ return await oraPromise(fn(), { text: ` ${chalk$1.gray(text)}` });
37
+ }
38
+ function parseArguments(argv) {
39
+ const flags = {};
40
+ const args = [];
41
+ for (const arg of argv) if (arg.startsWith("--")) if (arg.includes("=")) {
42
+ const idx = arg.indexOf("=");
43
+ const afterEq = arg.substring(idx + 1);
44
+ flags[arg.substring(2, idx)] = afterEq;
45
+ } else flags[arg.substring(2)] = true;
46
+ else args.push(arg);
47
+ return {
48
+ flags,
49
+ args
50
+ };
51
+ }
52
+
53
+ //#endregion
54
+ //#region src/globber.ts
55
+ function createGlobber() {
56
+ return { async glob(root, filenames, ignore = []) {
57
+ const source = await glob(filenames, {
58
+ cwd: root,
59
+ ignore: ["**/node_modules/**", ...ignore]
60
+ });
61
+ return uniq(source);
62
+ } };
63
+ }
64
+
65
+ //#endregion
66
+ //#region src/fs-utils.ts
67
+ var fs_utils_exports = {};
68
+ __export(fs_utils_exports, { readFileContents: () => readFileContents });
69
+ async function readFileContents(filePath) {
70
+ try {
71
+ return readFile(filePath, "utf-8");
72
+ } catch (err) {
73
+ if (err.code === "ENOENT") throw new Error(`${filePath} does not exist.`);
74
+ throw err;
75
+ }
76
+ }
77
+
78
+ //#endregion
79
+ //#region src/package-json-file-service.ts
80
+ function createPackageJSONFileService() {
81
+ return {
82
+ readPackageFile: async (filePath) => {
83
+ const contents = await readFileContents(filePath);
84
+ return JSON.parse(contents);
85
+ },
86
+ writePackageFile: async (filePath, fileContent) => {
87
+ const contents = await readFileContents(filePath);
88
+ const { indent } = detectIndent(contents);
89
+ const trailingNewline = contents.length ? contents.endsWith("\n") : false;
90
+ const data = JSON.stringify(fileContent, null, indent || " ");
91
+ await fsp.writeFile(filePath, data + (trailingNewline ? "\n" : ""));
92
+ }
93
+ };
94
+ }
95
+
96
+ //#endregion
97
+ //#region src/workspace-resolver.ts
98
+ function createWorkspaceResolverService({ readFileContents: readFileContents$1 }) {
99
+ return { getWorkspaces: async (packageJson, root, globber, ignored) => {
100
+ const [workspaces, ignoredWorkspaces] = await Promise.all([getWorkspaces(packageJson, root), globber.glob(root, ignored)]);
101
+ return await globber.glob(root, ensureWorkspacesArray(workspaces), ignoredWorkspaces);
102
+ } };
103
+ async function getWorkspaces(packageJson, root) {
104
+ const packageJsonWorkspaces = packageJson.workspaces;
105
+ if (packageJsonWorkspaces !== undefined) return packageJsonWorkspaces;
106
+ return await getPnpmWorkspaces(root);
107
+ }
108
+ async function getPnpmWorkspaces(root) {
109
+ try {
110
+ const filePath = path$1.relative(root, "pnpm-workspace.yaml");
111
+ const contents = await readFileContents$1(filePath);
112
+ const pnpmWorkspaces = yaml.load(contents);
113
+ return pnpmWorkspaces.packages;
114
+ } catch {
115
+ return undefined;
116
+ }
117
+ }
118
+ }
119
+
120
+ //#endregion
121
+ //#region package.json
122
+ var name = "typesync";
123
+ var version = "0.13.5-0";
124
+ var type = "module";
125
+ var description = "Install missing TypeScript typings for your dependencies.";
126
+ var engines = { "node": "^18.20.0 || ^20.10.0 || >=22.0.0" };
127
+ var files = ["dist", "bin"];
128
+ var bin = { "typesync": "./bin/typesync" };
129
+ var exports = { ".": {
130
+ "types": "./dist/index.d.ts",
131
+ "default": "./dist/index.js"
132
+ } };
133
+ var scripts = {
134
+ "test": "vitest run",
135
+ "test:watch": "vitest --ui",
136
+ "lint": "eslint --fix && tsc && npm run format",
137
+ "format": "prettier --write 'src/**/*.ts'",
138
+ "lint:watch": "nodemon --exec npm run lint -e ts,js",
139
+ "build": "tsdown",
140
+ "run-cli": "npm run build && node bin/typesync",
141
+ "run-cli:dry": "npm run run-cli -- --dry",
142
+ "precommit": "lint-staged",
143
+ "do:publish": "npm run lint && npm run test && npm run build && npm publish",
144
+ "release:patch": "npm version patch && npm run do:publish && git push --follow-tags",
145
+ "release:minor": "npm version minor && npm run do:publish && git push --follow-tags",
146
+ "release:prerelease": "npm version prerelease && npm run do:publish && git push --follow-tags"
147
+ };
148
+ var lint_staged = { "*.ts": [
149
+ "eslint --fix",
150
+ "prettier --write",
151
+ "git add"
152
+ ] };
153
+ var repository = {
154
+ "type": "git",
155
+ "url": "git+https://github.com/jeffijoe/typesync.git"
156
+ };
157
+ var author = "Jeff Hansen <jeff@jeffijoe.com>";
158
+ var license = "MIT";
159
+ var bugs = { "url": "https://github.com/jeffijoe/typesync/issues" };
160
+ var homepage = "https://github.com/jeffijoe/typesync#readme";
161
+ var dependencies = {
162
+ "awilix": "^10.0.2",
163
+ "chalk": "^5.3.0",
164
+ "cosmiconfig": "^9.0.0",
165
+ "detect-indent": "^7.0.1",
166
+ "js-yaml": "^4.1.0",
167
+ "npm-registry-fetch": "^17.1.0",
168
+ "ora": "^8.1.1",
169
+ "semver": "^7.6.2",
170
+ "tinyglobby": "^0.2.10"
171
+ };
172
+ var devDependencies = {
173
+ "@eslint/js": "^9.16.0",
174
+ "@types/js-yaml": "~4.0.9 || ~4.1.0",
175
+ "@types/node": "~18.19.67",
176
+ "@types/npm-registry-fetch": "^8.0.7 || ~17.1.0",
177
+ "@types/semver": "~7.5.8 || ~7.6.0",
178
+ "@vitest/coverage-v8": "^2.1.6",
179
+ "@vitest/ui": "^2.1.6",
180
+ "eslint": "^9.16.0",
181
+ "globals": "^15.12.0",
182
+ "nodemon": "^3.1.4",
183
+ "oxc-transform": "^0.38.0",
184
+ "prettier": "^3.3.2",
185
+ "tsdown": "^0.3.1",
186
+ "typescript": "^5.5.3",
187
+ "typescript-eslint": "^8.16.0",
188
+ "vitest": "^2.1.6"
189
+ };
190
+ var packageManager = "npm@8.19.4";
191
+ var package_default = {
192
+ name,
193
+ version,
194
+ type,
195
+ description,
196
+ engines,
197
+ files,
198
+ bin,
199
+ exports,
200
+ scripts,
201
+ "lint-staged": lint_staged,
202
+ repository,
203
+ author,
204
+ license,
205
+ bugs,
206
+ homepage,
207
+ dependencies,
208
+ devDependencies,
209
+ packageManager
210
+ };
211
+
212
+ //#endregion
213
+ //#region src/cli.ts
214
+ async function startCli() {
215
+ try {
216
+ const container = createContainer({ injectionMode: InjectionMode.CLASSIC }).register({
217
+ packageJSONService: asFunction(createPackageJSONFileService).singleton(),
218
+ workspaceResolverService: asFunction(() => createWorkspaceResolverService(fs_utils_exports)).singleton(),
219
+ packageSource: asFunction(createPackageSource).singleton(),
220
+ configService: asFunction(createConfigService).singleton(),
221
+ globber: asFunction(createGlobber).singleton(),
222
+ typeSyncer: asFunction(createTypeSyncer)
223
+ });
224
+ await run(container.resolve("typeSyncer"));
225
+ } catch (err) {
226
+ error(err);
227
+ process.exitCode = 1;
228
+ }
229
+ }
230
+ /**
231
+ * Actual CLI runner. Uses the `syncer` instance to sync.
232
+ * @param syncer
233
+ */
234
+ async function run(syncer) {
235
+ const { args, flags } = parseArguments(process.argv.slice(2));
236
+ const [filePath = "package.json"] = args;
237
+ if (flags.help) {
238
+ printHelp();
239
+ return;
240
+ }
241
+ log(`TypeSync v${chalk.white(package_default.version)}`);
242
+ if (flags.dry) log("—— DRY RUN — will not modify file ——");
243
+ const result = await spinWhile(`Syncing type definitions in ${chalk.cyan(filePath)}...`, () => syncer.sync(filePath, flags));
244
+ const syncedFilesOutput = result.syncedFiles.map(renderSyncedFile).join("\n\n");
245
+ const totals = result.syncedFiles.reduce((accum, f) => ({ newTypings: accum.newTypings + f.newTypings.length }), { newTypings: 0 });
246
+ const syncMessage = `\n\n${syncedFilesOutput}\n\n✨ Run ${chalk.green("typesync")} again without the ${chalk.gray("--dry")} flag to update your ${chalk.gray("package.json")}.`;
247
+ if (flags.dry === "fail" && totals.newTypings > 0) {
248
+ error("Typings changed; check failed.");
249
+ log(syncMessage);
250
+ process.exitCode = 1;
251
+ return;
252
+ }
253
+ success(totals.newTypings === 0 ? `No new typings to add, looks like you're all synced up!` : flags.dry ? `${totals.newTypings.toString()} new typings can be added.${syncMessage}` : `${totals.newTypings.toString()} new typings added.\n\n${syncedFilesOutput}\n\n✨ Go ahead and run ${chalk.green("npm install")}, ${chalk.green("yarn")}, or ${chalk.green("pnpm i")} to install the packages that were added.`);
254
+ }
255
+ /**
256
+ * Renders a type definition.
257
+ * @param typeDef
258
+ * @param isLast
259
+ */
260
+ function renderTypeDef(typeDef, isLast) {
261
+ const treeNode = isLast ? "└─" : "├─";
262
+ return `${treeNode} ${chalk.green.bold("+")} ${chalk.gray("@types/")}${chalk.bold.blue(typeDef.typingsName)}`;
263
+ }
264
+ /**
265
+ * Renders a synced file.
266
+ *
267
+ * @param file
268
+ */
269
+ function renderSyncedFile(file) {
270
+ const badge = file.newTypings.length === 0 ? chalk.blue.bold("(no new typings added)") : chalk.green.bold(`(${file.newTypings.length.toString()} new typings added)`);
271
+ const dirName = path.basename(path.dirname(path.resolve(file.filePath)));
272
+ const title = `📦 ${file.package.name ?? dirName} ${chalk.gray.italic(`— ${file.filePath}`)} ${badge}`;
273
+ const nl = "\n";
274
+ const combined = [...file.newTypings.map((t) => ({
275
+ ...t,
276
+ action: "add"
277
+ }))];
278
+ const rendered = title + nl + combined.map((t) => renderTypeDef(t, combined[combined.length - 1] === t)).join(nl);
279
+ return rendered;
280
+ }
281
+ /**
282
+ * Prints the help text.
283
+ */
284
+ function printHelp() {
285
+ console.log(`
286
+ ${chalk.blue.bold("typesync")} - adds missing TypeScript definitions to package.json
287
+
288
+ Options
289
+ ${chalk.magenta.bold("--dry")} dry run, won't save the package.json
290
+ ${chalk.magenta.bold("--ignoredeps=<deps|dev|peer|optional>")} ignores dependencies in the specified sections (comma separate for multiple). Example: ${chalk.magenta("ignoredeps=dev,peer")}
291
+ ${chalk.magenta.bold("--help")} shows this help menu
292
+ `.trim());
293
+ }
294
+
295
+ //#endregion
296
+ export { startCli };
297
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":["message: string","text: string","err: Error | string","fn: () => Promise<T>","argv: Array<string>","flags: ICLIArguments['flags']","args: Array<string>","filePath: string","packageJson: IPackageFile","root: string","fsUtils","syncer: ITypeSyncer","packageJson","typeDef: IPackageTypingDescriptor","isLast: boolean","file: ISyncedFile"],"sources":["../src/cli-util.ts","../src/globber.ts","../src/fs-utils.ts","../src/package-json-file-service.ts","../src/workspace-resolver.ts","../package.json","../src/cli.ts"],"sourcesContent":["import chalk from 'chalk'\nimport { oraPromise } from 'ora'\nimport type { ICLIArguments } from './types'\n\n/**\n * Like regular console.log, but better.\n * @param message\n */\nexport function log(message: string): void {\n console.log(`${chalk.white('»')} ${chalk.gray(message)}`)\n}\n\n/**\n * Makes success feel even sweeter.\n * @param text\n */\nexport function success(text: string): void {\n console.log(`${chalk.green('✔')} ${chalk.white(text)}`)\n}\n\n/**\n * Logs an error all pretty.\n * @param err\n */\nexport function error(err: Error | string): void {\n const msg = err instanceof Error ? err.message : err\n const stack = err instanceof Error ? `\\nStack:\\n${err.stack}` : ''\n console.log(`${chalk.red('✖')} ${chalk.bgRed(chalk.white(msg))}${stack}`)\n}\n\n/**\n * Spins while doing work. Stops when done.\n * @param text\n * @param fn\n */\nexport async function spinWhile<T>(\n text: string,\n fn: () => Promise<T>,\n): Promise<T> {\n return await oraPromise(fn(), {\n text: ` ${chalk.gray(text)}`,\n })\n}\n\n/**\n * Super simple argument parser.\n * @param argv\n */\nexport function parseArguments(argv: Array<string>): ICLIArguments {\n const flags: ICLIArguments['flags'] = {}\n const args: Array<string> = []\n for (const arg of argv) {\n if (arg.startsWith('--')) {\n if (arg.includes('=')) {\n const idx = arg.indexOf('=')\n const afterEq = arg.substring(idx + 1)\n flags[arg.substring(2, idx)] = afterEq\n } else {\n flags[arg.substring(2)] = true\n }\n } else {\n args.push(arg)\n }\n }\n return { flags, args }\n}\n","import { glob } from 'tinyglobby'\nimport { uniq } from './util'\n\n/**\n * Globber interface.\n */\nexport interface IGlobber {\n /**\n * Globs for filenames.\n *\n * @param root\n */\n glob(\n this: void,\n root: string,\n filenames: Array<string>,\n ignore?: Array<string>,\n ): Promise<Array<string>>\n}\n\n/**\n * Creates a globber.\n */\nexport function createGlobber(): IGlobber {\n return {\n async glob(root, filenames, ignore = []): Promise<Array<string>> {\n const source = await glob(filenames, {\n cwd: root,\n ignore: ['**/node_modules/**', ...ignore],\n })\n\n return uniq(source)\n },\n }\n}\n","import { readFile } from 'node:fs/promises'\n\nexport async function readFileContents(filePath: string): Promise<string> {\n try {\n return readFile(filePath, 'utf-8')\n /* v8 ignore next */\n } catch (err) {\n /* v8 ignore next 3 */\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n throw new Error(`${filePath} does not exist.`)\n }\n\n /* v8 ignore next 2 */\n throw err\n }\n}\n","import * as fsp from 'node:fs/promises'\nimport detectIndent from 'detect-indent'\nimport { readFileContents } from './fs-utils'\nimport type { IPackageFile } from './types'\n\n/**\n * File service.\n */\nexport interface IPackageJSONService {\n /**\n * Reads and parses JSON from the specified file. Path is relative to the current working directory.\n */\n readPackageFile(this: void, filePath: string): Promise<IPackageFile>\n /**\n * Writes the JSON to the specified file.\n */\n writePackageFile(\n this: void,\n filePath: string,\n fileContents: IPackageFile,\n ): Promise<void>\n}\n\nexport function createPackageJSONFileService(): IPackageJSONService {\n return {\n readPackageFile: async (filePath) => {\n const contents = await readFileContents(filePath)\n return JSON.parse(contents) as IPackageFile\n },\n writePackageFile: async (filePath, fileContent) => {\n const contents = await readFileContents(filePath)\n const { indent } = detectIndent(contents)\n const trailingNewline = contents.length ? contents.endsWith('\\n') : false\n const data = JSON.stringify(\n fileContent,\n null,\n indent /* v8 ignore next */ || ' ',\n )\n await fsp.writeFile(filePath, data + (trailingNewline ? '\\n' : ''))\n },\n }\n}\n","import * as path from 'node:path'\nimport yaml from 'js-yaml'\nimport type * as fsUtils from './fs-utils'\nimport type { IGlobber } from './globber'\nimport { ensureWorkspacesArray } from './util'\nimport type { IPackageFile } from './types'\n\n/**\n * Service for fetching monorepo workspaces in a standardized format agnostic of the package manager used.\n * It is used to allow syncing all types in a workspace when run from the root of a monorepo.\n */\nexport interface IWorkspaceResolverService {\n /**\n * Reads, parses, and normalizes a workspaces configuration from the following files, in this order:\n * - `package.json` `workspaces` field, as an array of globs.\n * - `package.json` `workspaces` field, as an object with a `packages` field, which is an array of globs.\n * - `pnpm-workspace.yaml` `packages` field, as an array of globs.\n *\n * Path is relative to the current working directory.\n * Note that this returns a list of directories, not paths to the manifests themselves.\n */\n getWorkspaces(\n this: void,\n packageJson: IPackageFile,\n root: string,\n globber: IGlobber,\n ignored: IWorkspacesArray,\n ): Promise<IWorkspacesArray>\n}\n\n/**\n * @example\n * ```json\n * \"workspaces\": [\n * \"packages/*\",\n * ]\n * ```\n */\nexport type IWorkspacesArray = Array<string>\n\n/**\n * @example\n * ```yaml\n * packages:\n * - 'packages/*'\n * ```\n */\nexport interface IWorkspacesObject {\n packages?: IWorkspacesArray\n}\n\n/**\n * @see {@link IWorkspacesArray}\n */\nexport type NpmWorkspacesConfig = IWorkspacesArray\n\n/**\n * Yarn is a special snowflake.\n *\n * @example\n * ```json\n * \"workspaces\": {\n * \"packages\": [\n * \"packages/*\",\n * ],\n * \"nohoist\": []\n * }\n * ```\n */\nexport type YarnWorkspacesConfig =\n | IWorkspacesArray\n | (IWorkspacesObject & { nohoist?: Array<string> })\n\n/**\n * The contents of a `pnpm-workspace.yaml` file.\n *\n * @example\n * ```yaml\n * packages:\n * - 'packages/*'\n * ```\n */\nexport type PnpmWorkspacesConfig = IWorkspacesObject\n\n/**\n * @see {@link IWorkspacesArray}\n */\nexport type BunWorkspacesConfig = IWorkspacesArray\n\n/**\n * Section in `package.json` representing workspaces.\n */\nexport type IWorkspacesSection =\n | NpmWorkspacesConfig\n | YarnWorkspacesConfig\n // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents -- We want to explicitly enumerate each package manager's options.\n | BunWorkspacesConfig\n\nexport function createWorkspaceResolverService({\n readFileContents,\n}: {\n readFileContents: typeof fsUtils.readFileContents\n}): IWorkspaceResolverService {\n return {\n getWorkspaces: async (packageJson, root, globber, ignored) => {\n const [workspaces, ignoredWorkspaces] = await Promise.all([\n getWorkspaces(packageJson, root),\n globber.glob(root, ignored),\n ])\n\n return await globber.glob(\n root,\n ensureWorkspacesArray(workspaces),\n ignoredWorkspaces,\n )\n },\n }\n\n async function getWorkspaces(\n packageJson: IPackageFile,\n root: string,\n ): Promise<IWorkspacesSection | undefined> {\n const packageJsonWorkspaces = packageJson.workspaces\n if (packageJsonWorkspaces !== undefined) {\n return packageJsonWorkspaces\n }\n\n return await getPnpmWorkspaces(root)\n }\n\n async function getPnpmWorkspaces(\n root: string,\n ): Promise<IWorkspacesArray | undefined> {\n try {\n const filePath = path.relative(root, 'pnpm-workspace.yaml')\n const contents = await readFileContents(filePath)\n const pnpmWorkspaces = yaml.load(contents) as PnpmWorkspacesConfig\n\n return pnpmWorkspaces.packages\n } catch {\n return undefined\n }\n }\n}\n","({\n \"name\": \"typesync\",\n \"version\": \"0.13.5-0\",\n \"type\": \"module\",\n \"description\": \"Install missing TypeScript typings for your dependencies.\",\n \"engines\": {\n \"node\": \"^18.20.0 || ^20.10.0 || >=22.0.0\"\n },\n \"files\": [\n \"dist\",\n \"bin\"\n ],\n \"bin\": {\n \"typesync\": \"./bin/typesync\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n }\n },\n \"scripts\": {\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest --ui\",\n \"lint\": \"eslint --fix && tsc && npm run format\",\n \"format\": \"prettier --write 'src/**/*.ts'\",\n \"lint:watch\": \"nodemon --exec npm run lint -e ts,js\",\n \"build\": \"tsdown\",\n \"run-cli\": \"npm run build && node bin/typesync\",\n \"run-cli:dry\": \"npm run run-cli -- --dry\",\n \"precommit\": \"lint-staged\",\n \"do:publish\": \"npm run lint && npm run test && npm run build && npm publish\",\n \"release:patch\": \"npm version patch && npm run do:publish && git push --follow-tags\",\n \"release:minor\": \"npm version minor && npm run do:publish && git push --follow-tags\",\n \"release:prerelease\": \"npm version prerelease && npm run do:publish && git push --follow-tags\"\n },\n \"lint-staged\": {\n \"*.ts\": [\n \"eslint --fix\",\n \"prettier --write\",\n \"git add\"\n ]\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jeffijoe/typesync.git\"\n },\n \"author\": \"Jeff Hansen <jeff@jeffijoe.com>\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jeffijoe/typesync/issues\"\n },\n \"homepage\": \"https://github.com/jeffijoe/typesync#readme\",\n \"dependencies\": {\n \"awilix\": \"^10.0.2\",\n \"chalk\": \"^5.3.0\",\n \"cosmiconfig\": \"^9.0.0\",\n \"detect-indent\": \"^7.0.1\",\n \"js-yaml\": \"^4.1.0\",\n \"npm-registry-fetch\": \"^17.1.0\",\n \"ora\": \"^8.1.1\",\n \"semver\": \"^7.6.2\",\n \"tinyglobby\": \"^0.2.10\"\n },\n \"devDependencies\": {\n \"@eslint/js\": \"^9.16.0\",\n \"@types/js-yaml\": \"~4.0.9 || ~4.1.0\",\n \"@types/node\": \"~18.19.67\",\n \"@types/npm-registry-fetch\": \"^8.0.7 || ~17.1.0\",\n \"@types/semver\": \"~7.5.8 || ~7.6.0\",\n \"@vitest/coverage-v8\": \"^2.1.6\",\n \"@vitest/ui\": \"^2.1.6\",\n \"eslint\": \"^9.16.0\",\n \"globals\": \"^15.12.0\",\n \"nodemon\": \"^3.1.4\",\n \"oxc-transform\": \"^0.38.0\",\n \"prettier\": \"^3.3.2\",\n \"tsdown\": \"^0.3.1\",\n \"typescript\": \"^5.5.3\",\n \"typescript-eslint\": \"^8.16.0\",\n \"vitest\": \"^2.1.6\"\n },\n \"packageManager\": \"npm@8.19.4\"\n}\n)","import * as path from 'node:path'\nimport { asFunction, createContainer, InjectionMode } from 'awilix'\nimport chalk from 'chalk'\nimport * as C from './cli-util'\nimport { createConfigService } from './config-service'\nimport { createGlobber } from './globber'\nimport { createPackageJSONFileService } from './package-json-file-service'\nimport { createPackageSource } from './package-source'\nimport { createTypeSyncer } from './type-syncer'\nimport type {\n IPackageTypingDescriptor,\n ISyncedFile,\n ITypeSyncer,\n} from './types'\nimport { createWorkspaceResolverService } from './workspace-resolver'\nimport * as fsUtils from './fs-utils'\nimport packageJson from '../package.json' with { type: 'json' }\n\n/**\n * Starts the TypeSync CLI.\n */\nexport async function startCli(): Promise<void> {\n try {\n // Awilix is a dependency injection container.\n const container = createContainer({\n injectionMode: InjectionMode.CLASSIC,\n }).register({\n packageJSONService: asFunction(createPackageJSONFileService).singleton(),\n workspaceResolverService: asFunction(() =>\n createWorkspaceResolverService(fsUtils),\n ).singleton(),\n packageSource: asFunction(createPackageSource).singleton(),\n configService: asFunction(createConfigService).singleton(),\n globber: asFunction(createGlobber).singleton(),\n typeSyncer: asFunction(createTypeSyncer),\n })\n await run(container.resolve<ITypeSyncer>('typeSyncer'))\n } catch (err) {\n C.error(err as any)\n process.exitCode = 1\n }\n}\n\n/**\n * Actual CLI runner. Uses the `syncer` instance to sync.\n * @param syncer\n */\nasync function run(syncer: ITypeSyncer) {\n const { args, flags } = C.parseArguments(process.argv.slice(2))\n const [filePath = 'package.json'] = args\n if (flags.help) {\n printHelp()\n return\n }\n\n C.log(`TypeSync v${chalk.white(packageJson.version)}`)\n if (flags.dry) {\n C.log('—— DRY RUN — will not modify file ——')\n }\n const result = await C.spinWhile(\n `Syncing type definitions in ${chalk.cyan(filePath)}...`,\n () => syncer.sync(filePath, flags),\n )\n\n const syncedFilesOutput = result.syncedFiles\n .map(renderSyncedFile)\n .join('\\n\\n')\n const totals = result.syncedFiles.reduce(\n (accum, f) => ({\n newTypings: accum.newTypings + f.newTypings.length,\n }),\n { newTypings: 0 },\n )\n\n const syncMessage = `\\n\\n${syncedFilesOutput}\\n\\n✨ Run ${chalk.green('typesync')} again without the ${chalk.gray('--dry')} flag to update your ${chalk.gray('package.json')}.`\n if (flags.dry === 'fail' && totals.newTypings > 0) {\n C.error('Typings changed; check failed.')\n C.log(syncMessage)\n process.exitCode = 1\n return\n }\n C.success(\n totals.newTypings === 0\n ? `No new typings to add, looks like you're all synced up!`\n : flags.dry\n ? `${totals.newTypings.toString()} new typings can be added.${syncMessage}`\n : `${totals.newTypings.toString()} new typings added.\\n\\n${syncedFilesOutput}\\n\\n✨ Go ahead and run ${chalk.green('npm install')}, ${chalk.green('yarn')}, or ${chalk.green('pnpm i')} to install the packages that were added.`,\n )\n}\n\n/**\n * Renders a type definition.\n * @param typeDef\n * @param isLast\n */\nfunction renderTypeDef(typeDef: IPackageTypingDescriptor, isLast: boolean) {\n const treeNode = isLast ? '└─' : '├─'\n return `${treeNode} ${chalk.green.bold('+')} ${chalk.gray('@types/')}${chalk.bold.blue(typeDef.typingsName)}`\n}\n\n/**\n * Renders a synced file.\n *\n * @param file\n */\nfunction renderSyncedFile(file: ISyncedFile) {\n const badge =\n file.newTypings.length === 0\n ? chalk.blue.bold('(no new typings added)')\n : chalk.green.bold(\n `(${file.newTypings.length.toString()} new typings added)`,\n )\n\n const dirName = path.basename(path.dirname(path.resolve(file.filePath)))\n const title = `📦 ${file.package.name ?? dirName} ${chalk.gray.italic(\n `— ${file.filePath}`,\n )} ${badge}`\n\n const nl = '\\n'\n const combined = [...file.newTypings.map((t) => ({ ...t, action: 'add' }))]\n const rendered =\n title +\n nl +\n combined\n .map((t) => renderTypeDef(t, combined[combined.length - 1] === t))\n .join(nl)\n\n return rendered\n}\n\n/**\n * Prints the help text.\n */\nfunction printHelp() {\n console.log(\n `\n${chalk.blue.bold('typesync')} - adds missing TypeScript definitions to package.json\n\nOptions\n ${chalk.magenta.bold('--dry')} dry run, won't save the package.json\n ${chalk.magenta.bold('--ignoredeps=<deps|dev|peer|optional>')} ignores dependencies in the specified sections (comma separate for multiple). Example: ${chalk.magenta('ignoredeps=dev,peer')}\n ${chalk.magenta.bold('--help')} shows this help menu\n `.trim(),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAQO,SAAS,IAAIA,SAAuB;AACzC,SAAQ,KAAK,EAAE,QAAM,MAAM,IAAI,CAAC,IAAI,QAAM,KAAK,QAAQ,CAAC,EAAE;AAC3D;AAMM,SAAS,QAAQC,MAAoB;AAC1C,SAAQ,KAAK,EAAE,QAAM,MAAM,IAAI,CAAC,IAAI,QAAM,MAAM,KAAK,CAAC,EAAE;AACzD;AAMM,SAAS,MAAMC,KAA2B;CAC/C,MAAM,MAAM,eAAe,QAAQ,IAAI,UAAU;CACjD,MAAM,QAAQ,eAAe,SAAS,YAAY,IAAI,MAAM,IAAI;AAChE,SAAQ,KAAK,EAAE,QAAM,IAAI,IAAI,CAAC,IAAI,QAAM,MAAM,QAAM,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE;AAC3E;AAOM,eAAe,UACpBD,MACAE,IACY;AACZ,QAAO,MAAM,WAAW,IAAI,EAAE,EAC5B,OAAO,GAAG,QAAM,KAAK,KAAK,C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,QAAQ;CAAO,GAAE,AAAC;CAC3E,MAAM,WACJ,QACA,KACA,SACG,IAAI,CAAC,MAAM,cAAc,GAAG,SAAS,SAAS,SAAS,OAAO,EAAE,CAAC,CACjE,KAAK,GAAG;AAEb,QAAO;AACR;;;;AAKD,SAAS,YAAY;AACnB,SAAQ,IACN,CAAC;EACH,MAAM,KAAK,KAAK,WAAW,CAAC;;;IAG1B,MAAM,QAAQ,KAAK,QAAQ,CAAC;IAC5B,MAAM,QAAQ,KAAK,wCAAwC,CAAC,4FAA4F,MAAM,QAAQ,sBAAsB,CAAC;IAC7L,MAAM,QAAQ,KAAK,SAAS,CAAC;IAC7B,MAAM,CACP;AACF"}
@@ -0,0 +1,11 @@
1
+ import { type ICLIArguments, type ISyncOptions } from "./types.js";
2
+ /**
3
+ * Config Service.
4
+ */
5
+ export interface IConfigService {
6
+ /**
7
+ * Get typesync config.
8
+ */
9
+ readConfig(this: void, filePath: string, flags: ICLIArguments["flags"]): Promise<ISyncOptions>;
10
+ }
11
+ export declare function createConfigService(): IConfigService;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Globber interface.
3
+ */
4
+ export interface IGlobber {
5
+ /**
6
+ * Globs for filenames.
7
+ *
8
+ * @param root
9
+ */
10
+ glob(this: void, root: string, filenames: Array<string>, ignore?: Array<string>): Promise<Array<string>>;
11
+ }
12
+ /**
13
+ * Creates a globber.
14
+ */
15
+ export declare function createGlobber(): IGlobber;
@@ -0,0 +1,4 @@
1
+ export * from "./config-service.js";
2
+ export * from "./package-source.js";
3
+ export * from "./type-syncer.js";
4
+ export * from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { IDependencySection, createConfigService, createPackageSource, createTypeSyncer } from "./type-syncer-C_rkDNfx.js";
2
+
3
+ export { IDependencySection, createConfigService, createPackageSource, createTypeSyncer };
@@ -0,0 +1,15 @@
1
+ import type { IPackageFile } from "./types.js";
2
+ /**
3
+ * File service.
4
+ */
5
+ export interface IPackageJSONService {
6
+ /**
7
+ * Reads and parses JSON from the specified file. Path is relative to the current working directory.
8
+ */
9
+ readPackageFile(this: void, filePath: string): Promise<IPackageFile>;
10
+ /**
11
+ * Writes the JSON to the specified file.
12
+ */
13
+ writePackageFile(this: void, filePath: string, fileContents: IPackageFile): Promise<void>;
14
+ }
15
+ export declare function createPackageJSONFileService(): IPackageJSONService;
@@ -0,0 +1,25 @@
1
+ import type { IPackageVersionInfo } from "./versioning.js";
2
+ /**
3
+ * Fetches info about a package.
4
+ */
5
+ export interface IPackageSource {
6
+ /**
7
+ * Fetches package info from an external source.
8
+ *
9
+ * @param packageName
10
+ */
11
+ fetch(this: void, packageName: string): Promise<IPackageInfo | null>;
12
+ }
13
+ /**
14
+ * Interface for the Package Info structure.
15
+ */
16
+ export interface IPackageInfo {
17
+ name: string;
18
+ latestVersion: string;
19
+ deprecated: boolean;
20
+ versions: Array<IPackageVersionInfo>;
21
+ }
22
+ /**
23
+ * Creates a package source.
24
+ */
25
+ export declare function createPackageSource(): IPackageSource;