Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Jul 13, 2022
2 parents 3e26be4 + 0d49a13 commit 4dc8618
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 78 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [14.x]
node: [14]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
- uses: pnpm/[email protected]
with:
node-version: ${{ matrix.node }}
version: 7.4.1

- uses: pnpm/action-setup@v1.2.1
- uses: actions/setup-node@v3
with:
version: 5.13.6
run_install: |
- cwd: vite-plugin-ruby
- recursive: false
cache: 'pnpm'
node-version: ${{ matrix.node }}

- run: pnpm -C vite-plugin-ruby install --frozen-lockfile

- name: Build
run: pnpm -C vite-plugin-ruby build
Expand Down
22 changes: 4 additions & 18 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ jobs:
build:
name: Rubocop
runs-on: ${{ matrix.os }}
env:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -17,23 +14,12 @@ jobs:
]

steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: /home/runner/bundle
key: bundle-use-ruby-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
bundle-use-ruby-gems-
- uses: actions/checkout@v3

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Bundle install
run: |
gem install bundler -v 2.1.4
bundle config path /home/runner/bundle
bundle install
- name: Ruby linter
run: bundle exec rubocop
- name: Rubocop
run: bin/rubocop
48 changes: 8 additions & 40 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,47 @@ jobs:
name: build
runs-on: ${{ matrix.os }}
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' || matrix.experimental }}
env:
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
bundler: ["2.1.4"]
ruby: [
"2.5",
"2.7",
"3.0",
"3.1",
]
gemfile: [
"gemfiles/Gemfile-rails.5.2.x",
"gemfiles/Gemfile-rails.6.0.x",
"gemfiles/Gemfile-rails.6.1.x"
"gemfiles/Gemfile-rails.6.1.x",
"gemfiles/Gemfile-rails.7.0.x"
]
experimental: [false]
exclude:
- ruby: "2.5"
gemfile: gemfiles/Gemfile-rails-edge
- ruby: "3.0"
gemfile: gemfiles/Gemfile-rails.5.2.x
include:
- ruby: "2.4"
bundler: "1.17.3"
os: ubuntu-latest
gemfile: gemfiles/Gemfile-rails.4.2.x
experimental: true
- ruby: "2.7"
bundler: "2.1.4"
os: ubuntu-latest
gemfile: gemfiles/Gemfile-rails-edge
experimental: true
- ruby: "3.1"
bundler: "2.1.4"
os: ubuntu-latest
gemfile: gemfiles/Gemfile-rails-edge
experimental: true

steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: /home/runner/bundle
key: bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-${{ hashFiles(matrix.gemfile) }}-${{ hashFiles('**/*.gemspec') }}
restore-keys: |
bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-
- uses: actions/checkout@v3

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '14'

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: Bundle install
run: |
gem install bundler -v ${{ matrix.bundler }}
bundle _${{ matrix.bundler }}_ config path /home/runner/bundle
bundle _${{ matrix.bundler }}_ config --global gemfile ${{ matrix.gemfile }}
bundle _${{ matrix.bundler }}_ install # --jobs 4 --retry 3
bundler-cache: true

- name: Setup Code Climate test-reporter
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: Ruby specs
run: bundle _${{ matrix.bundler }}_ exec rake test
- name: Ruby Tests
run: bin/rake test

- name: Upload code coverage to Code Climate
if: ${{ contains(github.ref, 'main') }}
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ require:
- rubocop-performance
- rubocop-minitest

inherit_mode:
merge:
- Exclude

AllCops:
Exclude:
- "node_modules/**/*"
Expand Down
44 changes: 42 additions & 2 deletions docs/src/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
[resolve.alias]: https://vitejs.dev/config/#resolve-alias
[sprockets]: https://github.com/rails/sprockets-rails
[sprockets example]: https://github.com/ElMassimo/vite_ruby/pull/165
[stimulus-vite-helpers]: https://github.com/ElMassimo/stimulus-vite-helpers

# Migrating to Vite

Expand Down Expand Up @@ -71,6 +72,8 @@ Proceed to fix any errors that occur (i.e. differences between Webpack and Vite.
+ import TextInput from '@/components/TextInput.vue'
```

The same is true, when importing <kbd>.svelte</kbd> or <kbd>.scss</kbd> files from Javascript.

- Replace usages of [tag helpers] as you move the [entrypoints].

```diff
Expand All @@ -94,15 +97,52 @@ Proceed to fix any errors that occur (i.e. differences between Webpack and Vite.
+ const controllers = import.meta.globEager('./**/*_controller.js')
```

- If importing code that is located outside of the <kbd>[sourceCodeDir]</kbd>, make sure to add a [glob expression] in <kbd>[watchAdditionalPaths]</kbd>, so that changes to these files are detected, and trigger a recompilation.
If you want to automatically register the Stimulus Controllers, have a look at <kbd>[stimulus-vite-helpers]</kbd> as a replacement for <kbd>@hotwired/stimulus-webpack-helpers</kbd>

- If importing code that is located outside of the <kbd>[sourceCodeDir]</kbd>, make sure to add a [glob expression] in <kbd>[watchAdditionalPaths]</kbd>, so that changes to these files are detected, and trigger a recompilation.

- If you were using <kbd>[rails-erb-loader]</kbd>, you might want to check <kbd>[vite-plugin-erb]</kbd> to ease the transition, but it's better to avoid mixing ERB in frontend assets.

- Make sure <kbd>[npx]</kbd> is available (comes by default in most node.js installations), or [clear][clear rake] the <kbd>[vite:install_dependencies]</kbd> rake task and provide your own implementation.

- If you are importing your own source code without absolute path prefix (such as ``@/`` or ``~/``) you can either prefix all imports with ``@/``:

```diff

- import MyModule from "admin/components/MyModule.vue"
+ import MyModule from "@/admin/components/MyModule.vue"
```

Or you can define an <kbd>alias</kbd> for every folder under <kbd>[sourceCodeDir]</kbd> (``app/javascript``):

```javascript
// vite.config.js
import path from 'path';
import fs from 'fs'

const sourceCodeDir = "app/javascript"
const items = fs.readdirSync(sourceCodeDir)
const directories = items.filter(item => fs.lstatSync(path.join(sourceCodeDir, item)).isDirectory())
const aliasesFromJavascriptRoot = {}
directories.forEach(directory => {
aliasesFromJavascriptRoot[directory] = path.resolve(__dirname, sourceCodeDir, directory)
})
export default defineConfig({
resolve: {
alias: {
...aliasesFromJavascriptRoot,
// can add more aliases, as "old" images or "@assets", see below
images: path.resolve(__dirname, './app/assets/images'),
},
},
```


::: tip Loaders to Plugins
Vite provides many features [out of the box], which reduce the
need for configuration.
need for configuration. You may just need to install the required
package, for example <kbd>sass</kbd>, <kbd>typescript</kbd>, <kbd>pug</kbd>
just need to be available, so Vite can pick them up.

In complex setups, the app might depend on specific webpack loaders, which can't
be used in Vite, which uses [Rollup] under the hood.
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/Gemfile-rails.7.0.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

gem 'rails', '~> 7.0.3'

gemspec path: '../vite_ruby'
gemspec path: '../vite_rails'
gemspec path: '../vite_plugin_legacy'
8 changes: 4 additions & 4 deletions vite_ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# [](https://github.com/ElMassimo/vite_ruby/compare/[email protected]_ruby@) (2022-07-01)

## [3.1.7](https://github.com/ElMassimo/vite_ruby/compare/[email protected][email protected]) (2022-07-13)

### Features

* allow starting an ESM SSR server from a CJS app ([17c8926](https://github.com/ElMassimo/vite_ruby/commit/17c89265f2f5e291ed76784aad647c94e2915d96))
### Bug Fixes

* npm deprecation warning on assets:precompile ([#226](https://github.com/ElMassimo/vite_ruby/issues/226)) ([e4f4b75](https://github.com/ElMassimo/vite_ruby/commit/e4f4b7540ef34296f1a8a4d8f1d2838549ee8460)), closes [#220](https://github.com/ElMassimo/vite_ruby/issues/220)
# [](https://github.com/ElMassimo/vite_ruby/compare/[email protected]_ruby@) (2022-07-01)


## [3.1.6](https://github.com/ElMassimo/vite_ruby/compare/[email protected][email protected]) (2022-06-02)
Expand Down
9 changes: 6 additions & 3 deletions vite_ruby/lib/tasks/vite.rake
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ namespace :vite do

desc 'Ensure build dependencies like Vite are installed before bundling'
task :install_dependencies do
legacy_flag = `npm --version`.to_i < 7 rescue false
cmd = legacy_flag ? 'npx ci --yes' : 'npx --yes ci'
cmd = ViteRuby.commands.legacy_npm_version? ? 'npx ci --yes' : 'npx --yes ci'
system({ 'NODE_ENV' => 'development' }, cmd)
end

Expand Down Expand Up @@ -82,6 +81,10 @@ end

# Any prerequisite task that installs packages should also install build dependencies.
if ARGV.include?('assets:precompile')
ENV['NPM_CONFIG_PRODUCTION'] = 'false'
if ViteRuby.commands.legacy_npm_version?
ENV['NPM_CONFIG_PRODUCTION'] = 'false'
else
ENV['NPM_CONFIG_INCLUDE'] = 'dev'
end
ENV['YARN_PRODUCTION'] = 'false'
end
5 changes: 5 additions & 0 deletions vite_ruby/lib/vite_ruby/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def install_binstubs
`bundle config --delete bin`
end

# Internal: Checks if the npm version is 6 or lower.
def legacy_npm_version?
`npm --version`.to_i < 7 rescue false
end

# Internal: Verifies if ViteRuby is properly installed.
def verify_install
unless File.exist?(config.root.join('bin/vite'))
Expand Down
2 changes: 1 addition & 1 deletion vite_ruby/lib/vite_ruby/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# lookup_entrypoint('calendar', type: :javascript)
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e314.js", "imports" => [] }
#
# NOTE: Using "autoBuild": true` in `config/vite.json` file will trigger a build
# NOTE: Using `"autoBuild": true` in `config/vite.json` file will trigger a build
# on demand as needed, before performing any lookup.
class ViteRuby::Manifest
def initialize(vite_ruby)
Expand Down

0 comments on commit 4dc8618

Please sign in to comment.