complete-cli 1.3.0 → 1.3.2

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.
@@ -1,5 +1,6 @@
1
1
  import { Command, Option } from "clipanion";
2
- import { getPackageRoot, writeFileAsync } from "complete-node";
2
+ import { assertObject, isObject } from "complete-common";
3
+ import { getFilePath, isFileAsync, readFileAsync, writeFileAsync, } from "complete-node";
3
4
  import path from "node:path";
4
5
  export class MetadataCommand extends Command {
5
6
  static paths = [["metadata"], ["m"]];
@@ -14,17 +15,36 @@ export class MetadataCommand extends Command {
14
15
  description: 'Creates a "package-metadata.json" file to document locked dependencies. (The "update" command will respect the contents of this file.)',
15
16
  });
16
17
  async execute() {
17
- const packageMetadata = {
18
- dependencies: {},
19
- };
20
- packageMetadata.dependencies[this.dependencyName] = {
18
+ const packageJSONPath = await getFilePath("package.json", undefined);
19
+ const packageRoot = path.dirname(packageJSONPath);
20
+ const packageMetadataPath = path.join(packageRoot, "package-metadata.json");
21
+ const packageMetadataExists = await isFileAsync(packageMetadataPath);
22
+ let packageMetadata;
23
+ if (packageMetadataExists) {
24
+ const packageMetadataContents = await readFileAsync(packageMetadataPath);
25
+ const packageMetadataUnknown = JSON.parse(packageMetadataContents);
26
+ assertObject(packageMetadataUnknown, `Failed to parse the metadata file at: ${packageMetadataPath}`);
27
+ packageMetadata = packageMetadataUnknown;
28
+ }
29
+ else {
30
+ packageMetadata = {};
31
+ }
32
+ let dependencies;
33
+ if (isObject(packageMetadata["dependencies"])) {
34
+ // eslint-disable-next-line @typescript-eslint/prefer-destructuring
35
+ dependencies = packageMetadata["dependencies"];
36
+ }
37
+ else {
38
+ dependencies = {};
39
+ packageMetadata["dependencies"] = dependencies;
40
+ }
41
+ dependencies[this.dependencyName] = {
21
42
  "lock-version": true,
22
43
  "lock-reason": this.reason ?? "",
23
44
  };
24
- const packageRoot = await getPackageRoot();
25
- const packageMetadataPath = path.join(packageRoot, "package-metadata.json");
26
45
  const packageMetadataJSON = JSON.stringify(packageMetadata, undefined, 2);
27
46
  await writeFileAsync(packageMetadataPath, packageMetadataJSON);
28
- console.log(`Successfully created: ${packageMetadataPath}`);
47
+ const verb = packageMetadataExists ? "modified" : "created";
48
+ console.log(`Successfully ${verb}: ${packageMetadataPath}`);
29
49
  }
30
50
  }
@@ -50,8 +50,8 @@
50
50
  "typescript.suggest.completeFunctionCalls": true,
51
51
 
52
52
  // By default, VSCode will prefer non-relative paths for deeply nested files.
53
- "javascript.preferences.importModuleSpecifier": "relative",
54
- "typescript.preferences.importModuleSpecifier": "relative",
53
+ "javascript.preferences.importModuleSpecifier": "project-relative",
54
+ "typescript.preferences.importModuleSpecifier": "project-relative",
55
55
 
56
56
  // By default, VSCode will not add `import type` automatically.
57
57
  "typescript.preferences.preferTypeOnlyAutoImports": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "complete-cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "A command line tool for bootstrapping TypeScript projects.",
5
5
  "keywords": [
6
6
  "typescript"
@@ -38,17 +38,17 @@
38
38
  "chalk": "5.5.0",
39
39
  "clipanion": "4.0.0-rc.4",
40
40
  "complete-common": "2.5.0",
41
- "complete-node": "7.4.4",
41
+ "complete-node": "7.4.6",
42
42
  "klaw-sync": "7.0.0",
43
- "yaml": "2.8.0"
43
+ "yaml": "2.8.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/klaw-sync": "6.0.5",
47
47
  "@types/node": "24.2.0",
48
48
  "ts-loader": "9.5.2",
49
49
  "tsconfig-paths-webpack-plugin": "4.2.0",
50
- "typescript": "5.8.3",
51
- "typescript-eslint": "8.38.0",
50
+ "typescript": "5.9.2",
51
+ "typescript-eslint": "8.39.0",
52
52
  "webpack": "5.101.0",
53
53
  "webpack-cli": "6.0.1",
54
54
  "webpack-shebang-plugin": "1.1.8"
@@ -1,5 +1,11 @@
1
1
  import { Command, Option } from "clipanion";
2
- import { getPackageRoot, writeFileAsync } from "complete-node";
2
+ import { assertObject, isObject } from "complete-common";
3
+ import {
4
+ getFilePath,
5
+ isFileAsync,
6
+ readFileAsync,
7
+ writeFileAsync,
8
+ } from "complete-node";
3
9
  import path from "node:path";
4
10
 
5
11
  export class MetadataCommand extends Command {
@@ -20,20 +26,44 @@ export class MetadataCommand extends Command {
20
26
  });
21
27
 
22
28
  async execute(): Promise<void> {
23
- const packageMetadata = {
24
- dependencies: {} as Record<string, unknown>,
25
- };
29
+ const packageJSONPath = await getFilePath("package.json", undefined);
30
+ const packageRoot = path.dirname(packageJSONPath);
31
+ const packageMetadataPath = path.join(packageRoot, "package-metadata.json");
32
+ const packageMetadataExists = await isFileAsync(packageMetadataPath);
33
+
34
+ let packageMetadata: Record<string, unknown>;
35
+ if (packageMetadataExists) {
36
+ const packageMetadataContents = await readFileAsync(packageMetadataPath);
37
+ const packageMetadataUnknown = JSON.parse(
38
+ packageMetadataContents,
39
+ ) as unknown;
40
+ assertObject(
41
+ packageMetadataUnknown,
42
+ `Failed to parse the metadata file at: ${packageMetadataPath}`,
43
+ );
44
+ packageMetadata = packageMetadataUnknown;
45
+ } else {
46
+ packageMetadata = {};
47
+ }
26
48
 
27
- packageMetadata.dependencies[this.dependencyName] = {
49
+ let dependencies: Record<string, unknown>;
50
+ if (isObject(packageMetadata["dependencies"])) {
51
+ // eslint-disable-next-line @typescript-eslint/prefer-destructuring
52
+ dependencies = packageMetadata["dependencies"];
53
+ } else {
54
+ dependencies = {};
55
+ packageMetadata["dependencies"] = dependencies;
56
+ }
57
+
58
+ dependencies[this.dependencyName] = {
28
59
  "lock-version": true,
29
60
  "lock-reason": this.reason ?? "",
30
61
  };
31
62
 
32
- const packageRoot = await getPackageRoot();
33
- const packageMetadataPath = path.join(packageRoot, "package-metadata.json");
34
63
  const packageMetadataJSON = JSON.stringify(packageMetadata, undefined, 2);
35
64
  await writeFileAsync(packageMetadataPath, packageMetadataJSON);
36
65
 
37
- console.log(`Successfully created: ${packageMetadataPath}`);
66
+ const verb = packageMetadataExists ? "modified" : "created";
67
+ console.log(`Successfully ${verb}: ${packageMetadataPath}`);
38
68
  }
39
69
  }