diff --git a/.changeset/spicy-actors-act.md b/.changeset/spicy-actors-act.md new file mode 100644 index 000000000..44a2b3fab --- /dev/null +++ b/.changeset/spicy-actors-act.md @@ -0,0 +1,5 @@ +--- +'@primer/octicons': patch +--- + +Update octicons in React to no longer set `role="img"` if the icon is aria-hidden. diff --git a/.changeset/tasty-countries-grow.md b/.changeset/tasty-countries-grow.md new file mode 100644 index 000000000..02ab84365 --- /dev/null +++ b/.changeset/tasty-countries-grow.md @@ -0,0 +1,5 @@ +--- +'@primer/octicons': minor +--- + +Update ESM import to use mjs extension when in parent CommonJS module diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b510cb491..7f340f558 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,2 @@ -* @primer/octicons-reviewers +* @primer/engineer-reviewers +icons @primer/octicons-reviewers diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4ec3306a..0b5a9d7dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - name: Building run: yarn build - run: cp -r icons lib/build/svg - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: octicons-build path: ./lib/build @@ -32,7 +32,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 18 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: octicons-build path: ./lib/build @@ -54,7 +54,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 18 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: octicons-build path: ./lib/build @@ -78,7 +78,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 18 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: octicons-build path: ./lib/build @@ -102,8 +102,8 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 - - uses: actions/download-artifact@v3 + ruby-version: 3.3 + - uses: actions/download-artifact@v4 with: name: octicons-build path: ./lib/octicons_gem/lib/build @@ -114,7 +114,7 @@ jobs: run: bundle exec rake test - name: Build run: bundle exec rake build - - uses: actions/upload-artifact@master + - uses: actions/upload-artifact@v4 with: name: octicons-gem path: ./lib/octicons_gem/pkg @@ -131,12 +131,13 @@ jobs: - name: Setup Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 - - uses: actions/download-artifact@v3 + ruby-version: 3.3 + - uses: actions/download-artifact@v4 with: name: octicons-gem path: ./lib/octicons_helper/vendor/cache - - run: bundle install + - name: Run bundle install + run: bundle config set --local disable_checksum_validation true && bundle install - name: Linting run: bundle exec rake lint - name: Testing @@ -154,12 +155,13 @@ jobs: # - name: Setup Ruby # uses: ruby/setup-ruby@v1 # with: -# ruby-version: 2.7 -# - uses: actions/download-artifact@v3 +# ruby-version: 3.3 +# - uses: actions/download-artifact@v4 # with: # name: octicons-gem # path: ./lib/octicons_jekyll/vendor/cache -# - run: bundle install +# - name: Run bundle install +# run: bundle config set --local disable_checksum_validation true && bundle install # - name: Linting # run: bundle exec rake lint # - name: Testing diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d10d12cb1..3b7925ba6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ jobs: - run: npm i - run: npm run build - run: cp -r icons lib/build/svg - - uses: actions/upload-artifact@master + - uses: actions/upload-artifact@v4 with: name: octicons path: ./lib/build @@ -25,7 +25,7 @@ jobs: needs: setup steps: - uses: actions/checkout@master - - uses: actions/download-artifact@master + - uses: actions/download-artifact@v4 with: name: octicons path: ./lib/build @@ -35,7 +35,7 @@ jobs: with: args: octicons_gem - run: ls ./lib/octicons_gem/pkg - - uses: actions/upload-artifact@master + - uses: actions/upload-artifact@v4 with: name: octicons_gem path: ./lib/octicons_gem/pkg @@ -44,11 +44,11 @@ jobs: needs: gem steps: - uses: actions/checkout@master - - uses: actions/download-artifact@master + - uses: actions/download-artifact@v4 with: name: octicons path: ./lib/build - - uses: actions/download-artifact@master + - uses: actions/download-artifact@v4 with: name: octicons_gem path: ./lib/octicons_helper/vendor/cache @@ -62,7 +62,7 @@ jobs: needs: setup steps: - uses: actions/checkout@master - - uses: actions/download-artifact@master + - uses: actions/download-artifact@v4 with: name: octicons path: ./lib/build @@ -76,7 +76,7 @@ jobs: needs: setup steps: - uses: actions/checkout@master - - uses: actions/download-artifact@master + - uses: actions/download-artifact@v4 with: name: octicons path: ./lib/build diff --git a/.rubocop.yml b/.rubocop.yml index 1be334345..2c4b6d408 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,3 +2,6 @@ inherit_gem: rubocop-github: - config/default.yml - config/rails.yml + +AllCops: + NewCops: enable diff --git a/Gemfile b/Gemfile index 2b9d64a82..5dd8f6f14 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,9 @@ +# frozen_string_literal: true + source "https://rubygems.org" group :development, :test do gem "minitest" gem "rake" - gem "rubocop", "0.59" - gem "rubocop-github", "0.12.0" + gem "rubocop-github", "0.20.0" end diff --git a/LICENSE b/LICENSE index 163074d5b..7533bc77a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Inc. +Copyright (c) 2024 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/octicons_gem/Gemfile b/lib/octicons_gem/Gemfile index 6df290a55..cc45e62c5 100644 --- a/lib/octicons_gem/Gemfile +++ b/lib/octicons_gem/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" gemspec @@ -5,6 +7,5 @@ gemspec group :development, :test do gem "minitest" gem "rake" - gem "rubocop", "0.59" - gem "rubocop-github", "0.12.0" + gem "rubocop-github", "0.20.0" end diff --git a/lib/octicons_gem/LICENSE b/lib/octicons_gem/LICENSE index 163074d5b..7533bc77a 100644 --- a/lib/octicons_gem/LICENSE +++ b/lib/octicons_gem/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Inc. +Copyright (c) 2024 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/octicons_gem/Rakefile b/lib/octicons_gem/Rakefile index fb7641f62..2017abd9a 100644 --- a/lib/octicons_gem/Rakefile +++ b/lib/octicons_gem/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rake/testtask" require "rubocop/rake_task" require "bundler/gem_tasks" @@ -12,7 +14,7 @@ Rake::TestTask.new do |t| end task :version, [:v] do |t, args| - out = "module Octicons\n"\ + out = "# frozen_string_literal: true\n\nmodule Octicons\n"\ " VERSION = \"#{args[:v]}\".freeze\n"\ "end" File.open(File.expand_path("../lib/octicons/version.rb", __FILE__), "w") { |file| file.puts out } diff --git a/lib/octicons_gem/lib/octicons.rb b/lib/octicons_gem/lib/octicons.rb index 063186888..744b91b84 100644 --- a/lib/octicons_gem/lib/octicons.rb +++ b/lib/octicons_gem/lib/octicons.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "octicons/version" require "octicons/octicon" require "json" diff --git a/lib/octicons_gem/lib/octicons/octicon.rb b/lib/octicons_gem/lib/octicons/octicon.rb index 7de596ec8..9deb422a0 100644 --- a/lib/octicons_gem/lib/octicons/octicon.rb +++ b/lib/octicons_gem/lib/octicons/octicon.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Octicons class Octicon DEFAULT_HEIGHT = 16 diff --git a/lib/octicons_gem/lib/octicons/version.rb b/lib/octicons_gem/lib/octicons/version.rb index e4d63fc33..3c9e05040 100644 --- a/lib/octicons_gem/lib/octicons/version.rb +++ b/lib/octicons_gem/lib/octicons/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Octicons VERSION = "19.8.0".freeze end diff --git a/lib/octicons_gem/octicons.gemspec b/lib/octicons_gem/octicons.gemspec index bc950f144..e9c62c4a2 100644 --- a/lib/octicons_gem/octicons.gemspec +++ b/lib/octicons_gem/octicons.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path("../lib/octicons/version", __FILE__) Gem::Specification.new do |s| diff --git a/lib/octicons_gem/test/helper.rb b/lib/octicons_gem/test/helper.rb index 0377daa7d..96d3405ba 100644 --- a/lib/octicons_gem/test/helper.rb +++ b/lib/octicons_gem/test/helper.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require "minitest/autorun" require "octicons" def octicon(symbol, options = {}) - ::Octicons::Octicon.new(symbol, options) + Octicons::Octicon.new(symbol, options) end diff --git a/lib/octicons_gem/test/octicon_test.rb b/lib/octicons_gem/test/octicon_test.rb index 80add615d..5d1d84732 100644 --- a/lib/octicons_gem/test/octicon_test.rb +++ b/lib/octicons_gem/test/octicon_test.rb @@ -1,4 +1,6 @@ -require_relative "./helper" +# frozen_string_literal: true + +require_relative "helper" describe Octicons::Octicon do it "fails when the octicon doesn't exist" do diff --git a/lib/octicons_gem/test/octicons_test.rb b/lib/octicons_gem/test/octicons_test.rb index 88e47b68e..8e128a80e 100644 --- a/lib/octicons_gem/test/octicons_test.rb +++ b/lib/octicons_gem/test/octicons_test.rb @@ -1,4 +1,6 @@ -require_relative "./helper" +# frozen_string_literal: true + +require_relative "helper" describe Octicons do it "loads all icons on initialization" do diff --git a/lib/octicons_helper/Gemfile b/lib/octicons_helper/Gemfile index 2df1cda4c..e7051000d 100644 --- a/lib/octicons_helper/Gemfile +++ b/lib/octicons_helper/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" gemspec @@ -8,6 +10,5 @@ gem "rails" group :development, :test do gem "minitest" gem "rake" - gem "rubocop", "0.59" - gem "rubocop-github", "0.12.0" + gem "rubocop-github", "0.20.0" end diff --git a/lib/octicons_helper/LICENSE b/lib/octicons_helper/LICENSE index 163074d5b..7533bc77a 100644 --- a/lib/octicons_helper/LICENSE +++ b/lib/octicons_helper/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Inc. +Copyright (c) 2024 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/octicons_helper/Rakefile b/lib/octicons_helper/Rakefile index b8cb208da..0dc91f69f 100644 --- a/lib/octicons_helper/Rakefile +++ b/lib/octicons_helper/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rake/testtask" require "rubocop/rake_task" require "bundler/gem_tasks" @@ -7,7 +9,7 @@ RuboCop::RakeTask.new(:lint) do |t| end task :version, [:v] do |t, args| - out = "module OcticonsHelper\n"\ + out = "# frozen_string_literal: true\n\nmodule OcticonsHelper\n"\ " VERSION = \"#{args[:v]}\".freeze\n"\ "end" File.open(File.expand_path("../lib/octicons_helper/version.rb", __FILE__), "w") do |file| diff --git a/lib/octicons_helper/lib/octicons_helper.rb b/lib/octicons_helper/lib/octicons_helper.rb index cbe359dc0..e1f85d5ef 100644 --- a/lib/octicons_helper/lib/octicons_helper.rb +++ b/lib/octicons_helper/lib/octicons_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "octicons_helper/version" require "octicons_helper/helper" require "octicons_helper/railtie" if defined?(Rails) diff --git a/lib/octicons_helper/lib/octicons_helper/helper.rb b/lib/octicons_helper/lib/octicons_helper/helper.rb index c7030e6ad..a5e060e1e 100644 --- a/lib/octicons_helper/lib/octicons_helper/helper.rb +++ b/lib/octicons_helper/lib/octicons_helper/helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "octicons" require "action_view" diff --git a/lib/octicons_helper/lib/octicons_helper/railtie.rb b/lib/octicons_helper/lib/octicons_helper/railtie.rb index ff5606388..1d7ed029b 100644 --- a/lib/octicons_helper/lib/octicons_helper/railtie.rb +++ b/lib/octicons_helper/lib/octicons_helper/railtie.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rails" module OcticonsHelper diff --git a/lib/octicons_helper/lib/octicons_helper/version.rb b/lib/octicons_helper/lib/octicons_helper/version.rb index 10cbb57a7..030215509 100644 --- a/lib/octicons_helper/lib/octicons_helper/version.rb +++ b/lib/octicons_helper/lib/octicons_helper/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OcticonsHelper VERSION = "19.8.0".freeze end diff --git a/lib/octicons_helper/octicons_helper.gemspec b/lib/octicons_helper/octicons_helper.gemspec index cb58fe372..a3e7e465b 100644 --- a/lib/octicons_helper/octicons_helper.gemspec +++ b/lib/octicons_helper/octicons_helper.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path("../lib/octicons_helper/version", __FILE__) Gem::Specification.new do |s| diff --git a/lib/octicons_helper/test/helper.rb b/lib/octicons_helper/test/helper.rb index e9664b2ae..2f17289a7 100644 --- a/lib/octicons_helper/test/helper.rb +++ b/lib/octicons_helper/test/helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "minitest/autorun" require "octicons_helper" diff --git a/lib/octicons_helper/test/octicons_helper_test.rb b/lib/octicons_helper/test/octicons_helper_test.rb index 3e2e54369..52de20c16 100644 --- a/lib/octicons_helper/test/octicons_helper_test.rb +++ b/lib/octicons_helper/test/octicons_helper_test.rb @@ -1,4 +1,6 @@ -require_relative "./helper" +# frozen_string_literal: true + +require_relative "helper" describe OcticonsHelper do describe "rendering" do @@ -23,10 +25,10 @@ mock = Minitest::Mock.new def mock.path - @@call_count ||= 0 - @@call_count += 1 + @call_count ||= 0 + @call_count += 1 - raise "Octicon library called twice" if @@call_count > 1 + raise "Octicon library called twice" if @call_count > 1 "foo" end diff --git a/lib/octicons_jekyll/.rubocop.yml b/lib/octicons_jekyll/.rubocop.yml index 448b745ff..2b4bc6dd7 100644 --- a/lib/octicons_jekyll/.rubocop.yml +++ b/lib/octicons_jekyll/.rubocop.yml @@ -4,3 +4,6 @@ inherit_gem: Naming/FileName: Enabled: false + +AllCops: + NewCops: enable diff --git a/lib/octicons_jekyll/Gemfile b/lib/octicons_jekyll/Gemfile index 203a7d846..1de25d9ec 100644 --- a/lib/octicons_jekyll/Gemfile +++ b/lib/octicons_jekyll/Gemfile @@ -1,12 +1,13 @@ +# frozen_string_literal: true + source "https://rubygems.org" gemspec -gem "openproject-octicons", "19.7.0" +gem "openproject-octicons", "19.8.0" group :development, :test do gem "minitest" gem "rake" - gem "rubocop", "0.59" - gem "rubocop-github", "0.12.0" + gem "rubocop-github", "0.20.0" end diff --git a/lib/octicons_jekyll/LICENSE b/lib/octicons_jekyll/LICENSE index 163074d5b..7533bc77a 100644 --- a/lib/octicons_jekyll/LICENSE +++ b/lib/octicons_jekyll/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Inc. +Copyright (c) 2024 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/octicons_jekyll/Rakefile b/lib/octicons_jekyll/Rakefile index 773908aa4..1d5821720 100644 --- a/lib/octicons_jekyll/Rakefile +++ b/lib/octicons_jekyll/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rake/testtask" require "rubocop/rake_task" require "bundler/gem_tasks" @@ -6,8 +8,8 @@ RuboCop::RakeTask.new(:lint) do |t| t.options = ["--display-cop-names"] end -task :version, [:v] do |t, args| - out = "# Prevent bundler errors\n"\ +task :version, [:v] => :environment do |t, args| + out = "# frozen_string_literal: true\n\n# Prevent bundler errors\n"\ "module Liquid; class Tag; end; end\n\n"\ "module Jekyll\n"\ " class Octicons < Liquid::Tag\n"\ diff --git a/lib/octicons_jekyll/jekyll-octicons.gemspec b/lib/octicons_jekyll/jekyll-octicons.gemspec index e48722487..995ffc4c3 100644 --- a/lib/octicons_jekyll/jekyll-octicons.gemspec +++ b/lib/octicons_jekyll/jekyll-octicons.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path("../lib/jekyll-octicons/version", __FILE__) Gem::Specification.new do |s| @@ -14,5 +16,5 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_dependency "jekyll", ">= 3.6", "< 5.0" - s.add_dependency "openproject-octicons", "19.7.0" + s.add_dependency "openproject-octicons", "19.8.0" end diff --git a/lib/octicons_jekyll/lib/jekyll-octicons.rb b/lib/octicons_jekyll/lib/jekyll-octicons.rb index 55255cc6e..9364c2a6d 100644 --- a/lib/octicons_jekyll/lib/jekyll-octicons.rb +++ b/lib/octicons_jekyll/lib/jekyll-octicons.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "octicons" require "jekyll-octicons/version" require "liquid" diff --git a/lib/octicons_jekyll/lib/jekyll-octicons/version.rb b/lib/octicons_jekyll/lib/jekyll-octicons/version.rb index 752463e6d..3e95ecaaa 100644 --- a/lib/octicons_jekyll/lib/jekyll-octicons/version.rb +++ b/lib/octicons_jekyll/lib/jekyll-octicons/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Prevent bundler errors module Liquid; class Tag; end; end diff --git a/lib/octicons_jekyll/test/helper.rb b/lib/octicons_jekyll/test/helper.rb index 062e49110..2bb101bfe 100644 --- a/lib/octicons_jekyll/test/helper.rb +++ b/lib/octicons_jekyll/test/helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "minitest/autorun" require "jekyll-octicons" diff --git a/lib/octicons_jekyll/test/octicon_tag_test.rb b/lib/octicons_jekyll/test/octicon_tag_test.rb index 8ee217bd4..20b0700dd 100644 --- a/lib/octicons_jekyll/test/octicon_tag_test.rb +++ b/lib/octicons_jekyll/test/octicon_tag_test.rb @@ -1,4 +1,6 @@ -require_relative "./helper" +# frozen_string_literal: true + +require_relative "helper" describe Jekyll::Octicons do describe "parsing" do diff --git a/lib/octicons_node/LICENSE b/lib/octicons_node/LICENSE index 163074d5b..7533bc77a 100644 --- a/lib/octicons_node/LICENSE +++ b/lib/octicons_node/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Inc. +Copyright (c) 2024 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/octicons_node/package.json b/lib/octicons_node/package.json index 693562809..d409e7673 100644 --- a/lib/octicons_node/package.json +++ b/lib/octicons_node/package.json @@ -17,7 +17,7 @@ "url": "https://github.com/opf/openproject-octicons/issues" }, "scripts": { - "build": "\\cp -r ../build/ ./build && \\cp index.scss ./build/build.css", + "build": "\\cp -r ../build/. ./build && \\cp index.scss ./build/build.css", "lint": "eslint index.js tests/*.js", "test": "ava --verbose 'tests/*.js'" }, diff --git a/lib/octicons_react/LICENSE b/lib/octicons_react/LICENSE index 163074d5b..7533bc77a 100644 --- a/lib/octicons_react/LICENSE +++ b/lib/octicons_react/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Inc. +Copyright (c) 2024 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/octicons_react/README.md b/lib/octicons_react/README.md index 9ed7b548b..234c55f6f 100644 --- a/lib/octicons_react/README.md +++ b/lib/octicons_react/README.md @@ -158,20 +158,6 @@ export default () => ( ) ``` - -```diff -- -+ -``` - -The `Octicon` component is wrapper that passes props to its icon component. To render a specific icon, you -can pass it either via the `icon` prop, or as the only child: - -```jsx - - -``` - [octicons]: https://primer.style/octicons/ [primer]: https://github.com/primer/primer [docs]: http://primercss.io/ diff --git a/lib/octicons_react/__tests__/tree-shaking.test.js b/lib/octicons_react/__tests__/tree-shaking.test.js index 4dcd08f02..a490c44bf 100644 --- a/lib/octicons_react/__tests__/tree-shaking.test.js +++ b/lib/octicons_react/__tests__/tree-shaking.test.js @@ -50,5 +50,5 @@ test('tree shaking single export', async () => { }) const bundleSize = Buffer.byteLength(output[0].code.trim()) / 1000 - expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"3.47kB"`) + expect(`${bundleSize}kB`).toMatchInlineSnapshot(`"3.563kB"`) }) diff --git a/lib/octicons_react/package.json b/lib/octicons_react/package.json index a4a4218e0..e63a16eea 100644 --- a/lib/octicons_react/package.json +++ b/lib/octicons_react/package.json @@ -5,11 +5,15 @@ "homepage": "https://primer.style/octicons", "author": "GitHub, Inc.", "license": "MIT", + "type": "commonjs", "main": "dist/index.umd.js", - "module": "dist/index.esm.js", + "module": "dist/index.esm.mjs", "exports": { - "types": "./dist/index.d.ts", - "import": "./dist/index.esm.js", + "types": { + "import": "./dist/index.d.mts", + "require": "./dist/index.d.ts" + }, + "import": "./dist/index.esm.mjs", "require": "./dist/index.umd.js" }, "sideEffects": false, @@ -25,7 +29,6 @@ "posttest": "yarn ts-test" }, "files": [ - "build", "dist" ], "keywords": [ diff --git a/lib/octicons_react/rollup.config.js b/lib/octicons_react/rollup.config.js index 1b04c208a..23cfa253a 100644 --- a/lib/octicons_react/rollup.config.js +++ b/lib/octicons_react/rollup.config.js @@ -1,10 +1,20 @@ import babel from '@rollup/plugin-babel' import commonjs from '@rollup/plugin-commonjs' +import packageJson from './package.json' -const formats = ['esm', 'umd'] // 'cjs' ? +const dependencies = [ + ...Object.keys(packageJson.peerDependencies ?? {}), + ...Object.keys(packageJson.dependencies ?? {}), + ...Object.keys(packageJson.devDependencies ?? {}) +] -export default { +function createPackageRegex(name) { + return new RegExp(`^${name}(/.*)?`) +} + +const baseConfig = { input: 'src/index.js', + external: dependencies.map(createPackageRegex), plugins: [ babel({ babelrc: false, @@ -20,10 +30,26 @@ export default { babelHelpers: 'bundled' }), commonjs() - ], - output: formats.map(format => ({ - file: `dist/index.${format}.js`, - format, - name: 'reocticons' - })) + ] } + +export default [ + { + ...baseConfig, + output: { + file: `dist/index.esm.mjs`, + format: 'esm' + } + }, + { + ...baseConfig, + output: { + file: `dist/index.umd.js`, + format: 'umd', + name: 'reocticons', + globals: { + react: 'React' + } + } + } +] diff --git a/lib/octicons_react/script/types.js b/lib/octicons_react/script/types.js index 99860a8ad..43cecec2a 100755 --- a/lib/octicons_react/script/types.js +++ b/lib/octicons_react/script/types.js @@ -10,17 +10,17 @@ const destDir = resolve(__dirname, '../dist') const iconsDest = join(destDir, 'icons.d.ts') const indexDest = join(destDir, 'index.d.ts') -fse - .copy(iconsSrc, iconsDest) - .then(() => { - return fse - .readFile(indexSrc, 'utf8') - .then(content => content.replace(/.\/__generated__\//g, './')) - .then(content => fse.writeFile(indexDest, content, 'utf8')) - }) - .catch(die) +async function main() { + await fse.copy(iconsSrc, iconsDest) -function die(err) { - console.error(err.stack) - process.exitCode = 1 + let contents = await fse.readFile(indexSrc, 'utf8') + contents = contents.replace(/.\/__generated__\//g, './') + + await fse.writeFile(indexDest, contents, 'utf8') + await fse.writeFile(join(destDir, 'index.d.mts'), contents, 'utf8') } + +main().catch(error => { + console.error(error) + process.exitCode = 1 +}) diff --git a/lib/octicons_react/src/__tests__/__snapshots__/octicon.js.snap b/lib/octicons_react/src/__tests__/__snapshots__/octicon.js.snap index 6a702f6d2..2c1947a65 100644 --- a/lib/octicons_react/src/__tests__/__snapshots__/octicon.js.snap +++ b/lib/octicons_react/src/__tests__/__snapshots__/octicon.js.snap @@ -7,7 +7,6 @@ exports[`An icon component matches snapshot 1`] = ` fill="currentColor" focusable="false" height="16" - role="img" style="display: inline-block; user-select: none; vertical-align: text-bottom; overflow: visible;" viewBox="0 0 16 16" width="16" diff --git a/lib/octicons_react/src/__tests__/octicon.js b/lib/octicons_react/src/__tests__/octicon.js index 2364725e6..c4a9493a7 100644 --- a/lib/octicons_react/src/__tests__/octicon.js +++ b/lib/octicons_react/src/__tests__/octicon.js @@ -1,5 +1,5 @@ import '@testing-library/jest-dom' -import {render} from '@testing-library/react' +import {render, screen} from '@testing-library/react' import React from 'react' import {AlertIcon} from '../index' @@ -9,9 +9,29 @@ describe('An icon component', () => { expect(container.querySelector('svg')).toMatchSnapshot() }) + it('defaults to `aria-hidden="true"` if no label is present', () => { + const {container} = render() + expect(container.querySelector('svg')).toHaveAttribute('aria-hidden', 'true') + }) + + it('sets `role="img"` if `aria-label` is provided', () => { + render() + expect(screen.getByLabelText('Alert')).toHaveAttribute('role', 'img') + }) + + it('sets `role="img"` if `aria-labelledby` is provided', () => { + render( + <> + Alert + + + ) + expect(screen.getByLabelText('Alert')).toHaveAttribute('role', 'img') + }) + it('sets aria-hidden="false" if ariaLabel prop is present', () => { const {container} = render() - expect(container.querySelector('svg')).toHaveAttribute('aria-hidden', 'false') + expect(container.querySelector('svg')).not.toHaveAttribute('aria-hidden') expect(container.querySelector('svg')).toHaveAttribute('aria-label', 'icon') }) diff --git a/lib/octicons_react/src/createIconComponent.js b/lib/octicons_react/src/createIconComponent.js index 8b8a51df0..f895c43ec 100644 --- a/lib/octicons_react/src/createIconComponent.js +++ b/lib/octicons_react/src/createIconComponent.js @@ -30,17 +30,19 @@ export function createIconComponent(name, defaultClassName, getSVGData) { const naturalWidth = svgDataByHeight[naturalHeight].width const width = height * (naturalWidth / naturalHeight) const path = svgDataByHeight[naturalHeight].path + const labelled = ariaLabel || arialabelledby + const role = labelled ? 'img' : undefined return ( = 0 ? 'true' : 'false'} aria-label={ariaLabel} aria-labelledby={arialabelledby} - role="img" className={className} + role={role} viewBox={`0 0 ${naturalWidth} ${naturalHeight}`} width={width} height={height} diff --git a/lib/octicons_styled/LICENSE b/lib/octicons_styled/LICENSE index 163074d5b..7533bc77a 100644 --- a/lib/octicons_styled/LICENSE +++ b/lib/octicons_styled/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 GitHub Inc. +Copyright (c) 2024 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index a4bcdeee0..37fdd3fe4 100644 --- a/package.json +++ b/package.json @@ -49,5 +49,6 @@ "github/no-then": 0, "eslint-comments/no-use": 0 } - } + }, + "packageManager": "yarn@1.22.1" }