Skip to content

Commit

Permalink
minimum version support at node 14 / npm 8
Browse files Browse the repository at this point in the history
node 12 is EOL
  • Loading branch information
jonabc committed Jan 2, 2023
1 parent a6272b1 commit 5429f28
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ jobs:
needs: core
strategy:
matrix:
node_version: [ 12, 14, 16 ]
node_version: [ 14, 16, 18 ]
steps:
- uses: actions/checkout@v3
- name: Setup node
Expand Down
13 changes: 1 addition & 12 deletions lib/licensed/sources/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,12 @@ def package_metadata_command
# Returns an array of arguments that should be used for all `npm list`
# calls, regardless of how the output is formatted
def package_metadata_args
args = []
args = %w(--all)
args << "--production" unless include_non_production?

# on npm 7+, the --all argument is necessary to evaluate the project's
# full dependency tree
args << "--all" if npm_version >= Gem::Version.new("7.0.0")

return args
end

# Returns the currently installed version of npm as a Gem::Version object
def npm_version
@npm_version ||= begin
Gem::Version.new(Licensed::Shell.execute("npm", "-v").strip)
end
end

# Returns true if a yarn.lock file exists in the current directory
def yarn_lock_present
@yarn_lock_present ||= File.exist?(config.pwd.join("yarn.lock"))
Expand Down
72 changes: 0 additions & 72 deletions test/sources/npm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
let(:config) { Licensed::AppConfiguration.new({ "source_path" => Dir.pwd }) }
let(:fixtures) { File.expand_path("../../fixtures/npm", __FILE__) }
let(:source) { Licensed::Sources::NPM.new(config) }
let(:version) { Gem::Version.new(Licensed::Shell.execute("npm", "-v")) }

describe "enabled?" do
it "is true if package.json exists" do
Expand Down Expand Up @@ -36,9 +35,6 @@
assert dep
assert_equal "npm", dep.record["type"]
assert_equal "5.2.0", dep.version
if source.npm_version < Gem::Version.new("7.0.0")
assert dep.record["homepage"]
end
assert dep.record["summary"]
end
end
Expand All @@ -57,9 +53,6 @@
dep = source.dependencies.detect { |d| d.name == "@github/query-selector" }
assert dep
assert_equal "1.0.3", dep.version
if source.npm_version < Gem::Version.new("7.0.0")
assert dep.record["homepage"]
end
assert dep.record["summary"]
end
end
Expand Down Expand Up @@ -140,9 +133,6 @@
let(:fixtures) { File.expand_path("../../fixtures/npm/packages/a", __FILE__) }

it "finds dependencies" do
# workspaces will only work as expected with npm > 8.5.0
skip if source.npm_version < Gem::Version.new("8.5.0")

Dir.chdir fixtures do
dep = source.dependencies.detect { |d| d.name == "callbackify" }
assert dep
Expand All @@ -152,9 +142,6 @@
end

it "does not include the current workspace project" do
# workspaces will only work as expected with npm > 8.5.0
skip if source.npm_version < Gem::Version.new("8.5.0")

Dir.chdir fixtures do
refute source.dependencies.detect { |d| d.name == "licensed-fixtures-a" }
end
Expand All @@ -163,63 +150,7 @@
end

describe "missing dependencies (glob is missing package)" do
it "includes missing dependencies when yarn.lock is missing" do
# this test is incompatible with npm >=7
skip if source.npm_version >= Gem::Version.new("7.0.0")

Dir.mktmpdir do |dir|
FileUtils.cp_r(fixtures, dir)
dir = File.join(dir, "npm")
FileUtils.rm_rf(File.join(dir, "node_modules/glob"))

Dir.chdir dir do
assert source.dependencies.detect { |dep| dep.name == "autoprefixer" }
assert source.dependencies.detect { |dep| dep.name == "glob" }
end
end
end

it "excludes missing dependencies when yarn.lock is present" do
# this test is incompatible with npm >=7
skip if source.npm_version >= Gem::Version.new("7.0.0")

Dir.mktmpdir do |dir|
FileUtils.cp_r(fixtures, dir)
dir = File.join(dir, "npm")
FileUtils.rm_rf(File.join(dir, "node_modules/glob"))
File.write(File.join(dir, "yarn.lock"), "")

Dir.chdir dir do
assert source.dependencies.detect { |dep| dep.name == "autoprefixer" }
refute source.dependencies.detect { |dep| dep.name == "glob" }
end
end
end

it "raises Licensed::Sources::Source::Error on missing dependencies" do
# this test is incompatible with npm <7, >=7.12.0 (possibly earlier versions as well, I haven't been able to verify)
skip if source.npm_version < Gem::Version.new("7.0.0")
skip if source.npm_version >= Gem::Version.new("7.12.0")

Dir.mktmpdir do |dir|
FileUtils.cp_r(fixtures, dir)
dir = File.join(dir, "npm")
FileUtils.rm_rf(File.join(dir, "node_modules/glob"))

Dir.chdir dir do
error = assert_raises Licensed::Sources::Source::Error do
source.dependencies
end

assert error.message.include? "missing: glob@^7"
end
end
end

it "sets errors on missing dependencies" do
# this test is incompatible with npm <7.12.0, (possibly earlier versions as well, I haven't been able to verify)
skip if source.npm_version < Gem::Version.new("7.12.0")

Dir.mktmpdir do |dir|
FileUtils.cp_r(fixtures, dir)
dir = File.join(dir, "npm")
Expand All @@ -234,9 +165,6 @@
end

it "does not set errors on packages with reported problems that have a path" do
# this test is incompatible with npm <7.12.0, (possibly earlier versions as well, I haven't been able to verify)
skip if source.npm_version < Gem::Version.new("7.12.0")

Dir.mktmpdir do |dir|
FileUtils.cp_r(fixtures, dir)
dir = File.join(dir, "npm")
Expand Down

0 comments on commit 5429f28

Please sign in to comment.