-
Notifications
You must be signed in to change notification settings - Fork 6
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
FT Bundle Splitting Strategy Helper #210
Merged
Merged
Changes from all commits
Commits
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
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
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 @@ | ||
__test__/ |
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,2 @@ | ||
package-lock=false | ||
shrinkwrap=false |
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,23 @@ | ||
{ | ||
"name": "@financial-times/anvil-server-ft-preset", | ||
"version": "0.0.0", | ||
"description": "", | ||
"main": "dist/cjs/index.js", | ||
"types": "src/index.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"tsc": "../../node_modules/.bin/tsc", | ||
"clean": "npm run clean:dist && npm run clean:node_modules", | ||
"clean:dist": "rm -rf dist", | ||
"clean:node_modules": "rm -rf node_modules", | ||
"build:cjs": "npm run tsc -- --outDir ./dist/cjs", | ||
"build": "npm run clean:dist && npm run build:cjs", | ||
"dev": "npm run clean:dist && npm run build:cjs -- --watch" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@financial-times/anvil-server-asset-loader": "file:../../packages/anvil-server-asset-loader" | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/anvil-server-ft-preset/src/__test__/getFTBundleAssetUrls.spec.ts
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,46 @@ | ||
import { getFTBundleAssetUrls } from '../getFTBundleAssetUrls' | ||
import { AssetLoader, AssetLoaderOptions } from '@financial-times/anvil-server-asset-loader' | ||
|
||
const $manifest = { | ||
'main.js': 'main.bundle.js', | ||
'vendor.js': 'vendor.bundle.js', | ||
'runtime.js': 'runtime.bundle.js', | ||
'o-ads.js': 'o-ads.bundle.js', | ||
'o-date.js': 'o-date.bundle.js', | ||
'shared.stable.js': 'shared.stable.bundle.js', | ||
'shared.volatile.js': 'shared.volatile.bundle.js', | ||
'anvil-ui-ft-footer.js': 'anvil-ui-ft-footer.bundle.js', | ||
'anvil-ui-ft-header.js': 'anvil-ui-ft-header.bundle.js' | ||
} | ||
|
||
function createAssetLoader({ | ||
manifest = $manifest, | ||
publicPath = 'public/assets', | ||
fileSystemPath = '/internal/path/to/assets', | ||
...otherOptions | ||
}: AssetLoaderOptions = {}) { | ||
return new AssetLoader({ manifest, publicPath, fileSystemPath, ...otherOptions }) | ||
} | ||
|
||
describe('getFTBundleAssetUrls(assetUrl)', () => { | ||
it('should return the vendor asset urls', () => { | ||
const assetLoader = createAssetLoader() | ||
const result = getFTBundleAssetUrls(assetLoader) | ||
expect(result).toEqual([ | ||
'public/assets/runtime.bundle.js', | ||
'public/assets/vendor.bundle.js', | ||
'public/assets/shared.stable.bundle.js', | ||
'public/assets/shared.volatile.bundle.js', | ||
'public/assets/o-ads.bundle.js', | ||
'public/assets/o-date.bundle.js', | ||
'public/assets/anvil-ui-ft-footer.bundle.js', | ||
'public/assets/anvil-ui-ft-header.bundle.js' | ||
]) | ||
}) | ||
|
||
it('should not error if an asset url cannot be found', () => { | ||
const assetLoader = createAssetLoader({ manifest: {} }) | ||
const result = getFTBundleAssetUrls(assetLoader) | ||
expect(result).toEqual([]) | ||
}) | ||
}) |
30 changes: 30 additions & 0 deletions
30
packages/anvil-server-ft-preset/src/getFTBundleAssetUrls.ts
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,30 @@ | ||
import AssetLoader from '@financial-times/anvil-server-asset-loader' | ||
|
||
/** | ||
* Returns an array of public asset urls that are specific to the FT app bundle splitting strategy | ||
*/ | ||
export function getFTBundleAssetUrls(assetLoader: AssetLoader) { | ||
return [] | ||
.concat(concatablySilent(() => assetLoader.getPublicURL('runtime.js'))) | ||
.concat(concatablySilent(() => assetLoader.getPublicURL('vendor.js'))) | ||
.concat(concatablySilent(() => assetLoader.getPublicURL('shared.stable.js'))) | ||
.concat(concatablySilent(() => assetLoader.getPublicURL('shared.volatile.js'))) | ||
.concat(concatablySilent(() => assetLoader.getPublicURLOfHashedAssetsMatching(/o-(.*)\.js/))) | ||
.concat(concatablySilent(() => assetLoader.getPublicURLOfHashedAssetsMatching(/anvil-ui-(.*)\.js/))) | ||
} | ||
|
||
function concatablySilent(invoke: Function) { | ||
return asArray(silently(invoke)) | ||
} | ||
|
||
function asArray(value: any) { | ||
if (value === undefined) return [] | ||
if (Array.isArray(value)) return value | ||
return [value] | ||
} | ||
|
||
function silently(action: Function) { | ||
try { | ||
return action() | ||
} catch (e) {} | ||
} |
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 @@ | ||
export * from './getFTBundleAssetUrls' |
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,4 @@ | ||
{ | ||
"rootDir": "./src/", | ||
"extends": "../../tsconfig.json" | ||
} |
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.
I think this is unused
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.
It's being used for typings. See line 6