diff --git a/CHANGELOG.md b/CHANGELOG.md index a384a684..2903e452 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,19 @@ ## [Unreleased] Changes since last non-beta release. -*Please add entries here for your pull requests that are not yet released.* -### Improved -- Allow v10 of `compression-webpack-plugin` as a peer dependency. [PR 117](https://github.com/shakacode/shakapacker/pull/117) by [aried3r](https://github.com/aried3r). _Please add entries here for your pull requests that are not yet released._ -### Changed +## [v6.4.0] - June 2, 2022 +### Fixed +- Fixed [Issue 123: Rails 7.0.3 - Webpacker configuration file not found when running rails webpacker:install (shakapacker v6.3)](https://github.com/shakacode/shakapacker/issues/123) in [PR 136: Don't enhance precompile if no config #136](https://github.com/shakacode/shakapacker/pull/136) by [justin808](https://github.com/justin808). + +### Added +- Configuration boolean option `nested_entries` to use nested entries. This was the default prior to v6.0. Because entries maybe generated, it's useful to allow a `generated` subdirectory. [PR 121](https://github.com/shakacode/shakapacker/pull/121) by [justin808](https://github.com/justin808). + +### Improved +- Allow v10 of `compression-webpack-plugin` as a peer dependency. [PR 117](https://github.com/shakacode/shakapacker/pull/117) by [aried3r](https://github.com/aried3r). -- Removed the `yarn:install` Rake task, and no longer enhance `assets:precompile` with said task. These tasks were used to ensure required NPM packages were installed before asset precompilation. Going forward you will need to ensure these packages are already installed yourself. Should you wish to restore this behaviour you'll need to [reimplement the task](https://github.com/shakacode/shakapacker/blob/bee661422f2c902aa8ac9cf8fa1f7ccb8142c914/lib/tasks/yarn.rake) in your own application. +- [Remove assets:precompile task enhancement #131](https://github.com/shakacode/shakapacker/pull/131) by [James Herdman](https://github.com/jherdman): Removed the `yarn:install` Rake task, and no longer enhance `assets:precompile` with said task. These tasks were used to ensure required NPM packages were installed before asset precompilation. Going forward you will need to ensure these packages are already installed yourself. Should you wish to restore this behaviour you'll need to [reimplement the task](https://github.com/shakacode/shakapacker/blob/bee661422f2c902aa8ac9cf8fa1f7ccb8142c914/lib/tasks/yarn.rake) in your own application. ## [v6.3.0] - May 19, 2022 @@ -41,7 +46,7 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions ### Improved - Use last modified timestamps rather than file digest to determine compiler freshness. [PR 97](https://github.com/shakacode/shakapacker/pull/97) by [tomdracz](https://github.com/tomdracz). - Rather than calculating SHA digest of all the files in the paths watched by the compiler, we are now comparing the modified time of the `manifest.json` file versues the latest modified timestamp of files and directories in watched paths. Unlike calculating digest, which only looked at the files, the new calculation also considers directory timestamps, including the parent ones (i.e. `config.source_path` folder timestamp will be checked together will timestamps of all files and directories inside of it). + Rather than calculating SHA digest of all the files in the paths watched by the compiler, we are now comparing the modified time of the `manifest.json` file versus the latest modified timestamp of files and directories in watched paths. Unlike calculating digest, which only looked at the files, the new calculation also considers directory timestamps, including the parent ones (i.e. `config.source_path` folder timestamp will be checked together will timestamps of all files and directories inside of it). This change should result in improved compiler checks performance but might be breaking for certain setups and edge cases. If you encounter any issues, please report them at https://github.com/shakacode/shakapacker/issues. @@ -132,9 +137,9 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions ## v5.4.3 and prior changes from rails/webpacker See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md) -[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.3.0...master -[v6.3.0]: https://github.com/shakacode/shakapacker/compare/v6.3.0-rc.1...v6.3.0 -[v6.3.0-rc.1]: https://github.com/shakacode/shakapacker/compare/v6.2.1...v6.3.0-rc.1 +[Unreleased]: https://github.com/shakacode/shakapacker/compare/v6.4.0...master +[v6.4.0]: https://github.com/shakacode/shakapacker/compare/v6.3.0...v6.4.0 +[v6.3.0]: https://github.com/shakacode/shakapacker/compare/v6.2.1...v6.3.0 [v6.2.1]: https://github.com/shakacode/shakapacker/compare/v6.2.0...v6.2.1 [v6.2.0]: https://github.com/shakacode/shakapacker/compare/v6.1.1...v6.2.0 [v6.1.1]: https://github.com/shakacode/shakapacker/compare/v6.1.0...v6.1.1 diff --git a/README.md b/README.md index 24aad6be..d14991be 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ At it's core, Shakapacker's essential functionality is to: You will need your file system to correspond to the setup of your `webpacker.yml` file. -Suppose you have the following files: +Suppose you have the following configuration: `webacker.yml` ```yml @@ -168,6 +168,7 @@ default: &default source_entry_path: packs public_root_path: public public_output_path: packs + nested_entries: false # And more ``` @@ -189,6 +190,8 @@ public/packs # webpack output Webpack intelligently includes only necessary files. In this example, the file `packs/application.js` would reference `../src/my_component.js` +`nested_entries` allows you to have webpack entry points nested in subdirectories. This defaults to false so you don't accidentally create entry points for an entire tree of files. In other words, with `nested_entries: false`, you can have your entire `source_path` used for your source (using the `source_entry_path: /`) and you place files at the top level that you want as entry points. `nested_entries: true` allows you to have entries that are in subdirectories. This is useful if you have entries that are generated, so you can have a `generated` subdirectory and easily separate generated files from the rest of your codebase. + ### View Helpers The Shakapacker view helpers generate the script and link tags to get the webpack output onto your views. diff --git a/lib/install/config/webpacker.yml b/lib/install/config/webpacker.yml index b4feeb0b..8e10b842 100644 --- a/lib/install/config/webpacker.yml +++ b/lib/install/config/webpacker.yml @@ -2,7 +2,15 @@ default: &default source_path: app/javascript + + # You can have a subdirectory of the source_path, like 'packs' (recommended). + # Alternatively, you can use '/' to use the whole source_path directory. source_entry_path: / + + # If nested_entries is true, then we'll pick up subdirectories within the source_entry_path. + # You cannot set this option to true if you set source_entry_path to '/' + nested_entries: false + public_root_path: public public_output_path: packs cache_path: tmp/webpacker diff --git a/package/environments/__tests__/base.js b/package/environments/__tests__/base.js index 79971596..d24a651c 100644 --- a/package/environments/__tests__/base.js +++ b/package/environments/__tests__/base.js @@ -3,15 +3,18 @@ // environment.js expects to find config/webpacker.yml and resolved modules from // the root of a Rails project -const { chdirTestApp, chdirCwd } = require('../../utils/helpers') +const { chdirTestApp, chdirCwd, resetEnv } = require('../../utils/helpers') chdirTestApp() const { resolve } = require('path') -const rules = require('../../rules') + const baseConfig = require('../base') +const config = require("../../config"); describe('Base config', () => { + beforeEach(() => jest.resetModules() && resetEnv()) + afterAll(chdirCwd) describe('config', () => { @@ -21,11 +24,33 @@ describe('Base config', () => { ) }) - test('should return multi file entry points', () => { + test('should return only 2 entry points with config.nested_entries == false', () => { + expect(config.nested_entries).toEqual(false) + + expect(baseConfig.entry.multi_entry.sort()).toEqual([ + resolve('app', 'packs', 'entrypoints', 'multi_entry.css'), + resolve('app', 'packs', 'entrypoints', 'multi_entry.js') + ]) + expect(baseConfig.entry['generated/something']).toEqual(undefined) + }) + + test('should returns top level and nested entry points with config.nested_entries == true', () => { + process.env.WEBPACKER_CONFIG = 'config/webpacker_nested_entries.yml' + const config = require("../../config"); + const baseConfig = require('../base') + + expect(config.nested_entries).toEqual(true) + + expect(baseConfig.entry.application).toEqual( + resolve('app', 'packs', 'entrypoints', 'application.js') + ) expect(baseConfig.entry.multi_entry.sort()).toEqual([ resolve('app', 'packs', 'entrypoints', 'multi_entry.css'), resolve('app', 'packs', 'entrypoints', 'multi_entry.js') ]) + expect(baseConfig.entry['generated/something']).toEqual( + resolve('app', 'packs', 'entrypoints', 'generated', 'something.js') + ) }) test('should return output', () => { @@ -36,6 +61,8 @@ describe('Base config', () => { }) test('should return default loader rules for each file in config/loaders', () => { + const rules = require('../../rules') + const defaultRules = Object.keys(rules) const configRules = baseConfig.module.rules diff --git a/package/environments/base.js b/package/environments/base.js index 4325b199..68089941 100644 --- a/package/environments/base.js +++ b/package/environments/base.js @@ -14,8 +14,15 @@ const { moduleExists } = require('../utils/helpers') const getEntryObject = () => { const entries = {} const rootPath = join(config.source_path, config.source_entry_path) + if (config.source_entry_path === '/' && config.nested_entries) { + throw new Error( + "Your webpacker config specified using a source_entry_path of '/' with 'nested_entries' == " + + "'true'. Doing this would result in packs for every one of your source files" + ) + } + const nesting = config.nested_entries ? '**/' : '' - globSync(`${rootPath}/*.*`).forEach((path) => { + globSync(`${rootPath}/${nesting}*.*`).forEach((path) => { const namespace = relative(join(rootPath), dirname(path)) const name = join(namespace, basename(path, extname(path))) let assetPaths = resolve(path) diff --git a/test/test_app/app/packs/entrypoints/generated/something.js b/test/test_app/app/packs/entrypoints/generated/something.js new file mode 100644 index 00000000..90c6f94e --- /dev/null +++ b/test/test_app/app/packs/entrypoints/generated/something.js @@ -0,0 +1,2 @@ +/* eslint no-console:0 */ +console.log('entrypoints/nested/something') diff --git a/test/test_app/config/webpacker.yml b/test/test_app/config/webpacker.yml index 53fe81ee..60a6fc15 100644 --- a/test/test_app/config/webpacker.yml +++ b/test/test_app/config/webpacker.yml @@ -3,6 +3,7 @@ default: &default source_path: app/packs source_entry_path: entrypoints + nested_entries: false public_root_path: public public_output_path: packs cache_path: tmp/webpacker diff --git a/test/test_app/config/webpacker_nested_entries.yml b/test/test_app/config/webpacker_nested_entries.yml new file mode 100644 index 00000000..5bec1cae --- /dev/null +++ b/test/test_app/config/webpacker_nested_entries.yml @@ -0,0 +1,83 @@ +# Note: You must restart bin/webpacker-dev-server for changes to take effect + +default: &default + source_path: app/packs + source_entry_path: entrypoints + nested_entries: true + public_root_path: public + public_output_path: packs + cache_path: tmp/webpacker + webpack_compile_output: false + webpack_loader: babel + + # Location for manifest.json, defaults to {public_output_path}/manifest.json if unset + # manifest_path: public/packs/manifest.json + + # Additional paths webpack should look up modules + # ['app/assets', 'engine/foo/app/assets'] + additional_paths: + - app/assets + - /etc/yarn + - some.config.js + - app/elm + + # Reload manifest.json on all requests so we reload latest compiled packs + cache_manifest: false + + static_assets_extensions: + - .jpg + - .jpeg + - .png + - .gif + - .tiff + - .ico + - .svg + + extensions: + - .mjs + - .js + +development: + <<: *default + compile: true + ensure_consistent_versioning: true + + # Reference: https://webpack.js.org/configuration/dev-server/ + dev_server: + https: false + host: localhost + port: 3035 + public: localhost:3035 + hmr: false + overlay: true + disable_host_check: true + use_local_ip: false + pretty: false + +test: + <<: *default + compile: true + + # Compile test packs to a separate directory + public_output_path: packs-test + +production: + <<: *default + + # Production depends on precompilation of packs prior to booting for performance. + compile: false + + # Cache manifest.json for performance + cache_manifest: true + +staging: + <<: *default + + # Production depends on precompilation of packs prior to booting for performance. + compile: false + + # Cache manifest.json for performance + cache_manifest: true + + # Compile staging packs to a separate directory + public_output_path: packs-staging