Skip to content

Commit

Permalink
Allow using nested entries
Browse files Browse the repository at this point in the history
Nested entries were removed in v6.0.

This PR allows using them with a configuration switch.

By default they are turned off.
  • Loading branch information
justin808 committed May 20, 2022
1 parent 32571a4 commit df707eb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*

## 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.

## [v6.3.0] - May 19, 2022

### Improved
Expand All @@ -34,7 +37,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.

Expand Down
8 changes: 8 additions & 0 deletions lib/install/config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions package/environments/__tests__/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ describe('Base config', () => {
])
})

test('should return only 2 entry points with config.nested_entries == 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(
resolve('app', 'packs', 'entrypoints', 'generated', 'something.js')
)
})

test('should return 3 entry points with config.nested_entries == true', () => {
expect(baseConfig.entry.multi_entry.length).toEqual(2)
})

test('should return output', () => {
expect(baseConfig.output.filename).toEqual('js/[name].js')
expect(baseConfig.output.chunkFilename).toEqual(
Expand Down
9 changes: 8 additions & 1 deletion package/environments/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/test_app/config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
Expand Down

0 comments on commit df707eb

Please sign in to comment.