package_json 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7701de73f335d8ffa510d3b70b14760f14e9f6e0f788731dae5906b161096f0
4
- data.tar.gz: b69e61483d713e9042f3caa6f6ab9aef9fd34b544ee71c43e576a7d865995023
3
+ metadata.gz: f55805d478e11aa4c918eb7b8acd0b1dc2dfead0488cc931f50a10a1b0b4ea18
4
+ data.tar.gz: 727ce06575bfe624628999e5ad6ef18b07caf10c4bad32af75a8fb78837b4f6d
5
5
  SHA512:
6
- metadata.gz: fc64ad921756cbdd7a4c9e31b3378dcb70e71d92a2c396d3458c61d0945c73ae0a6a05dfef3d407eba4f42529e04f80f363175523d407835e3460a7a14879447
7
- data.tar.gz: a6ac06b455574ac417158caaf27f5d2a5472c11c9645d2a7a967fd6af017f5f6d4ccfc897e6fb4c4a5699e7168a4ad29cf68f0dd8143811f46e1dc92d8504e65
6
+ metadata.gz: 876cae7108678cb22b42c15e8fa68a65e301235b4420309a077410dc06fc311a531335d0d5382c581477d70e2cd96dabc5f7177b2be05c05f7b9d623ae19ef97
7
+ data.tar.gz: f91171d95c197651ee4257d0beb728d9b5c504cd2d3290a8bfae5a36d1d18163108ec119a17c04408c3bf9c9c7fec0da8600b909a6f44989f9b4c8b477bac8ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-11-06
4
+
5
+ ### Added
6
+
7
+ - Add support for `exact` parameter in `add` method to install packages with
8
+ exact versions ([#29](https://github.com/shakacode/package_json/pull/29))
9
+
10
+ ### Fixed
11
+
12
+ - Ensure RBS for `PackageJson` class is correct
13
+ ([#39](https://github.com/shakacode/package_json/pull/39))
14
+
3
15
  ## [0.1.1] - 2025-11-04
4
16
 
5
17
  ### Changed
data/CLAUDE.md CHANGED
@@ -79,6 +79,13 @@ files and JavaScript package managers.
79
79
  - **Testing**: RSpec for Ruby tests
80
80
  - **Linting**: RuboCop for Ruby
81
81
 
82
+ ## Type Signatures & Documentation
83
+
84
+ **This project uses RBS (Ruby Signature) files for type documentation**
85
+
86
+ Everything should be captured in the type definitions, including private
87
+ methods.
88
+
82
89
  ## Important Notes
83
90
 
84
91
  - This gem provides a "middle-level" abstraction over JavaScript package
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- package_json (0.1.1)
4
+ package_json (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -177,11 +177,15 @@ package_json.manager.add(["eslint", "prettier"], type: :dev)
177
177
 
178
178
  # adds dotenv-webpack v6 as a production dependency
179
179
  package_json.manager.add(["dotenv-webpack@^6"])
180
+
181
+ # adds react-on-rails with exact version (no ^ or ~)
182
+ package_json.manager.add(["react-on-rails@16.0.0"], exact: true)
180
183
  ```
181
184
 
182
- | Option | Description |
183
- | ------ | ------------------------------------------------------------------------------------------- |
184
- | `type` | The type to add the dependencies as; either `:production` (default), `:dev`, or `:optional` |
185
+ | Option | Description |
186
+ | ------- | ------------------------------------------------------------------------------------------- |
187
+ | `type` | The type to add the dependencies as; either `:production` (default), `:dev`, or `:optional` |
188
+ | `exact` | If true, saves packages with exact versions (no `^` or `~` prefix) |
185
189
 
186
190
  #### Removing dependencies
187
191
 
@@ -40,13 +40,13 @@ class PackageJson
40
40
  end
41
41
 
42
42
  # Adds the given packages
43
- def add(packages, type: :production)
43
+ def add(packages, type: :production, exact: false)
44
44
  raise NotImplementedError
45
45
  end
46
46
 
47
47
  # Adds the given packages
48
- def add!(packages, type: :production)
49
- raise_exited_with_non_zero_code_error unless add(packages, type: type)
48
+ def add!(packages, type: :production, exact: false)
49
+ raise_exited_with_non_zero_code_error unless add(packages, type: type, exact: exact)
50
50
  end
51
51
 
52
52
  # Removes the given packages
@@ -16,8 +16,9 @@ class PackageJson
16
16
  end
17
17
 
18
18
  # Adds the given packages
19
- def add(packages, type: :production)
20
- raw("add", [package_type_install_flag(type)].compact + packages)
19
+ def add(packages, type: :production, exact: false)
20
+ flags = [package_type_install_flag(type), exact_flag(exact)].compact
21
+ raw("add", flags + packages)
21
22
  end
22
23
 
23
24
  # Removes the given packages
@@ -62,6 +63,12 @@ class PackageJson
62
63
  []
63
64
  end
64
65
 
66
+ def exact_flag(exact)
67
+ return "--exact" if exact
68
+
69
+ nil
70
+ end
71
+
65
72
  def package_type_install_flag(type)
66
73
  case type
67
74
  when :production
@@ -22,8 +22,9 @@ class PackageJson
22
22
  end
23
23
 
24
24
  # Adds the given packages
25
- def add(packages, type: :production)
26
- raw("install", [package_type_install_flag(type)] + packages)
25
+ def add(packages, type: :production, exact: false)
26
+ flags = [package_type_install_flag(type), exact_flag(exact)].compact
27
+ raw("install", flags + packages)
27
28
  end
28
29
 
29
30
  # Removes the given packages
@@ -66,6 +67,12 @@ class PackageJson
66
67
  args
67
68
  end
68
69
 
70
+ def exact_flag(exact)
71
+ return "--save-exact" if exact
72
+
73
+ nil
74
+ end
75
+
69
76
  def package_type_install_flag(type)
70
77
  case type
71
78
  when :production
@@ -16,8 +16,9 @@ class PackageJson
16
16
  end
17
17
 
18
18
  # Adds the given packages
19
- def add(packages, type: :production)
20
- raw("add", [package_type_install_flag(type)] + packages)
19
+ def add(packages, type: :production, exact: false)
20
+ flags = [package_type_install_flag(type), exact_flag(exact)].compact
21
+ raw("add", flags + packages)
21
22
  end
22
23
 
23
24
  # Removes the given packages
@@ -67,6 +68,12 @@ class PackageJson
67
68
  ["--no-frozen-lockfile"]
68
69
  end
69
70
 
71
+ def exact_flag(exact)
72
+ return "--save-exact" if exact
73
+
74
+ nil
75
+ end
76
+
70
77
  def package_type_install_flag(type)
71
78
  case type
72
79
  when :production
@@ -16,8 +16,9 @@ class PackageJson
16
16
  end
17
17
 
18
18
  # Adds the given packages
19
- def add(packages, type: :production)
20
- raw("add", [package_type_install_flag(type)].compact + packages)
19
+ def add(packages, type: :production, exact: false)
20
+ flags = [package_type_install_flag(type), exact_flag(exact)].compact
21
+ raw("add", flags + packages)
21
22
  end
22
23
 
23
24
  # Removes the given packages
@@ -64,6 +65,12 @@ class PackageJson
64
65
  ["--no-immutable"]
65
66
  end
66
67
 
68
+ def exact_flag(exact)
69
+ return "--exact" if exact
70
+
71
+ nil
72
+ end
73
+
67
74
  def package_type_install_flag(type)
68
75
  case type
69
76
  when :production
@@ -16,8 +16,9 @@ class PackageJson
16
16
  end
17
17
 
18
18
  # Adds the given packages
19
- def add(packages, type: :production)
20
- raw("add", [package_type_install_flag(type)].compact + packages)
19
+ def add(packages, type: :production, exact: false)
20
+ flags = [package_type_install_flag(type), exact_flag(exact)].compact
21
+ raw("add", flags + packages)
21
22
  end
22
23
 
23
24
  # Removes the given packages
@@ -79,6 +80,12 @@ class PackageJson
79
80
  []
80
81
  end
81
82
 
83
+ def exact_flag(exact)
84
+ return "--exact" if exact
85
+
86
+ nil
87
+ end
88
+
82
89
  def package_type_install_flag(type)
83
90
  case type
84
91
  when :production
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PackageJson
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -13,9 +13,9 @@ class PackageJson
13
13
 
14
14
  def native_install_command: (?frozen: bool) -> Array[String]
15
15
 
16
- def add: (Array[String] packages, ?type: :production | :dev | :optional) -> (bool | nil)
16
+ def add: (Array[String] packages, ?type: :production | :dev | :optional, ?exact: bool) -> (bool | nil)
17
17
 
18
- def add!: (Array[String] packages, ?type: :production | :dev | :optional) -> void
18
+ def add!: (Array[String] packages, ?type: :production | :dev | :optional, ?exact: bool) -> void
19
19
 
20
20
  def remove: (Array[String] packages) -> (bool | nil)
21
21
 
@@ -13,6 +13,8 @@ class PackageJson
13
13
 
14
14
  def with_frozen_flag: (bool frozen) -> Array[String]
15
15
 
16
+ def exact_flag: (bool exact) -> (String | nil)
17
+
16
18
  def package_type_install_flag: (Symbol type) -> (String | nil)
17
19
  end
18
20
  end
@@ -11,6 +11,8 @@ class PackageJson
11
11
  silent: bool
12
12
  ) -> Array[String]
13
13
 
14
+ def exact_flag: (bool exact) -> (String | nil)
15
+
14
16
  def package_type_install_flag: (Symbol type) -> String
15
17
  end
16
18
  end
@@ -13,6 +13,8 @@ class PackageJson
13
13
 
14
14
  def with_frozen_flag: (bool frozen) -> Array[String]
15
15
 
16
+ def exact_flag: (bool exact) -> (String | nil)
17
+
16
18
  def package_type_install_flag: (Symbol type) -> String
17
19
  end
18
20
  end
@@ -13,6 +13,8 @@ class PackageJson
13
13
 
14
14
  def with_frozen_flag: (bool frozen) -> Array[String]
15
15
 
16
+ def exact_flag: (bool exact) -> (String | nil)
17
+
16
18
  def package_type_install_flag: (Symbol type) -> (String | nil)
17
19
  end
18
20
  end
@@ -15,6 +15,8 @@ class PackageJson
15
15
 
16
16
  def with_frozen_flag: (bool frozen) -> Array[String]
17
17
 
18
+ def exact_flag: (bool exact) -> (String | nil)
19
+
18
20
  def package_type_install_flag: (Symbol type) -> (String | nil)
19
21
  end
20
22
  end
data/sig/package_json.rbs CHANGED
@@ -12,14 +12,18 @@ class PackageJson
12
12
 
13
13
  def self.fetch_default_fallback_manager: () -> Symbol
14
14
 
15
- def self.read: (?String path_to_directory, ?package_manager: (:npm | :yarn_berry | :yarn_classic | :pnpm | :bun)) -> PackageJson
15
+ def self.read: (?String path_to_directory, ?fallback_manager: (:npm | :yarn_berry | :yarn_classic | :pnpm | :bun)) -> PackageJson
16
16
 
17
- def initialize: (?String path_to_directory, ?package_manager: (:npm | :yarn_berry | :yarn_classic | :pnpm | :bun)) -> PackageJson
17
+ def initialize: (?String path_to_directory, ?fallback_manager: (:npm | :yarn_berry | :yarn_classic | :pnpm | :bun)) -> PackageJson
18
18
 
19
19
  def fetch: (String key, ?untyped default) -> (String | Hash[String, untyped] | Array[untyped])
20
20
 
21
21
  def merge!: () { (Hash[String | Symbol, untyped]) -> Hash[String | Symbol, untyped] } -> void
22
22
 
23
+ def delete!: (String key) -> untyped
24
+
25
+ def record_package_manager!: () -> void
26
+
23
27
  private
24
28
 
25
29
  @directory: String
@@ -30,9 +34,9 @@ class PackageJson
30
34
 
31
35
  def package_json_path: () -> String
32
36
 
33
- def ensure_package_json_exists: ((:npm | :yarn_berry | :yarn_classic | :pnpm | :bun) package_manager) -> void
37
+ def ensure_package_json_exists: () -> bool
34
38
 
35
- def read_package_json: () -> void
39
+ def read_package_json: () -> Hash[String, untyped]
36
40
 
37
41
  def write_package_json: (_ToJson contents) -> void
38
42
  end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: package_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gareth Jones
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-11-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - open-source@ackama.com
16
14
  executables: []
@@ -56,7 +54,6 @@ metadata:
56
54
  source_code_uri: https://github.com/shakacode/package_json
57
55
  changelog_uri: https://github.com/shakacode/package_json/blob/main/CHANGELOG.md
58
56
  rubygems_mfa_required: 'true'
59
- post_install_message:
60
57
  rdoc_options: []
61
58
  require_paths:
62
59
  - lib
@@ -71,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
68
  - !ruby/object:Gem::Version
72
69
  version: '0'
73
70
  requirements: []
74
- rubygems_version: 3.3.27
75
- signing_key:
71
+ rubygems_version: 3.6.9
76
72
  specification_version: 4
77
73
  summary: The missing gem for managing package.json files in Ruby
78
74
  test_files: []