-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for keeping public assets and ember-addon.public-assets meta in sync #1368
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6813c5f
Add support for copying the public assets all at once.
phndiaye fc94ad2
nit: declare untouched variable straight as const
phndiaye 5db5ee7
Add support for include glob pattern option & allow the asset path to…
phndiaye e4ee19d
Fix prettier linting issue
phndiaye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { readJsonSync, writeJsonSync } from 'fs-extra'; | ||
import walkSync from 'walk-sync'; | ||
import type { Plugin } from 'rollup'; | ||
|
||
export default function publicAssets(opts: { exclude: string[] }): Plugin { | ||
return { | ||
name: 'public-assets-bundler', | ||
generateBundle() { | ||
let pkg = readJsonSync('package.json'); | ||
const filenames = walkSync('public', { | ||
directories: false, | ||
ignore: opts?.exclude || [], | ||
}); | ||
const publicAssets: Record<string, string> = filenames.reduce( | ||
(acc: Record<string, string>, v): Record<string, string> => { | ||
acc['./public/' + v] = ['/', pkg.name, '/', v].join(''); | ||
return acc; | ||
}, | ||
{} | ||
); | ||
|
||
pkg['ember-addon'] = Object.assign({}, pkg['ember-addon'], { | ||
'public-assets': publicAssets, | ||
}); | ||
|
||
writeJsonSync('package.json', pkg, { spaces: 2 }); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { default as appReexports } from './rollup-app-reexports'; | |
import { default as clean } from 'rollup-plugin-delete'; | ||
import { default as keepAssets } from './rollup-keep-assets'; | ||
import { default as dependencies } from './rollup-addon-dependencies'; | ||
import { default as publicReexports } from './rollup-public-reexports'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: I wouldn't call it (re)exports, as this is not getting imported. Rather it's more of the classic push models vs. pull. Maybe just name it just similar to the public API for users, like |
||
import type { Plugin } from 'rollup'; | ||
|
||
export class Addon { | ||
|
@@ -83,4 +84,8 @@ export class Addon { | |
dependencies() { | ||
return dependencies(); | ||
} | ||
|
||
publicAssets(opts: { exclude: string[] }) { | ||
return publicReexports(opts); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my knowledge, the
public
folder is not something that's configurable. Otherwise, this could be part of the options (w/ a default value)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is any specific path mandated here, according to https://rfcs.emberjs.com/id/0507-embroider-v2-package-format#assets. Also this is about the v2 addon's internal file layout, and that should be seen as an implementation detail.
So I would suggest to make this configurable. Also, maybe we should also have an
include
pattern that we can pass toglob
ofwalkSync
? So users could say e.g.publicAssets({ path: 'assets', include: '**/*.svg')
, to make all svgs in./assets
(instead of./public
).