-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[kbn/optimizer] only build specified themes #70389
Merged
spalger
merged 37 commits into
elastic:master
from
spalger:implement/kbn-optimizer-theme-config
Jul 2, 2020
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
c453894
[kbn/optimizer] only build specified themes
spalger 36ecb1b
Merge branch 'master' into implement/kbn-optimizer-theme-config
elasticmachine 1fa1000
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 6a09eac
build all themes when building the dist
spalger 5690ce6
fix outdated types and remove @ts-ignore usage
spalger 44b84ab
Merge branch 'implement/kbn-optimizer-theme-config' of github.com:spa…
spalger 6fa8873
[SASS] 4 `_styling_constants_[theme].scss` files
5c541ce
add tests
spalger 3924b25
Merge branch 'implement/kbn-optimizer-theme-config' of github.com:spa…
spalger 2f32a66
integrate new styling_constants* files
spalger 8f339bb
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 0e6e023
remove sass importer, now that we have specific constants files for e…
spalger 1d32ef2
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 5891b40
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger a8bfe97
unify automatic insertion of globals with legacy styles (which only u…
spalger a30f343
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 645b4b0
revert usage of global_styling/index as it creates duplicate selectors
spalger 7d2cc0b
rename globals to `_globals_[theme].scss`
spalger 8c9ff5f
use relative path for globals link
spalger e498718
expand docs and opitions for new `themes` param
spalger 3ddeed1
log a warning when only a subset of themes are being built
spalger 5899072
use plural KBN_OPTIMIZER_THEMES env var
spalger 54e67cd
fix v8 import paths and include unthemed imports
spalger 552c35c
parse actual lines from worker stdio so that sass deprecation message…
spalger 3874e64
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 2b0b0cd
update fixtures and snapshots for integration tests
spalger 47ef959
fix use of WorkerStdio
spalger 4b5bd8c
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 5d508c9
Merge branch 'master' into implement/kbn-optimizer-theme-config
elasticmachine 4670722
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 80cf271
remove unnecessary globals, rely on theme tag everywhere
spalger d0f1d15
add docs about using the `KBN_OPTIMIZER_THEMES` env var
spalger 1a4924e
improve error message to make it more obvious that a specific part of…
spalger addbc68
build `v7light` and `v7dark` by default
spalger 4bea131
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger ca991fc
handle undefined __kbnThemeTag__ globals caused by test runners
spalger 3f6830f
update snapshots
spalger 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
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...bn-optimizer/src/__fixtures__/mock_repo/src/legacy/ui/public/styles/_globals_v7light.scss
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 @@ | ||
$globalStyleConstant: 11; |
1 change: 1 addition & 0 deletions
1
...kbn-optimizer/src/__fixtures__/mock_repo/src/legacy/ui/public/styles/_globals_v8dark.scss
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 @@ | ||
$globalStyleConstant: 12; |
1 change: 1 addition & 0 deletions
1
...bn-optimizer/src/__fixtures__/mock_repo/src/legacy/ui/public/styles/_globals_v8light.scss
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 @@ | ||
$globalStyleConstant: 13; |
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,92 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { parseThemeTags } from './theme_tags'; | ||
|
||
it('returns default tags when passed undefined', () => { | ||
expect(parseThemeTags()).toMatchInlineSnapshot(` | ||
Array [ | ||
"v7dark", | ||
"v7light", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns all tags when passed *', () => { | ||
expect(parseThemeTags('*')).toMatchInlineSnapshot(` | ||
Array [ | ||
"v7dark", | ||
"v7light", | ||
"v8dark", | ||
"v8light", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns specific tag when passed a single value', () => { | ||
expect(parseThemeTags('v8light')).toMatchInlineSnapshot(` | ||
Array [ | ||
"v8light", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns specific tags when passed a comma separated list', () => { | ||
expect(parseThemeTags('v8light, v7dark,v7light')).toMatchInlineSnapshot(` | ||
Array [ | ||
"v7dark", | ||
"v7light", | ||
"v8light", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns specific tags when passed an array', () => { | ||
expect(parseThemeTags(['v8light', 'v7light'])).toMatchInlineSnapshot(` | ||
Array [ | ||
"v7light", | ||
"v8light", | ||
] | ||
`); | ||
}); | ||
|
||
it('throws when an invalid tag is in the array', () => { | ||
expect(() => parseThemeTags(['v8light', 'v7light', 'bar'])).toThrowErrorMatchingInlineSnapshot( | ||
`"Invalid theme tags [bar], options: [v7dark, v7light, v8dark, v8light]"` | ||
); | ||
}); | ||
|
||
it('throws when an invalid tags in comma separated list', () => { | ||
expect(() => parseThemeTags('v8light ,v7light,bar,box ')).toThrowErrorMatchingInlineSnapshot( | ||
`"Invalid theme tags [bar, box], options: [v7dark, v7light, v8dark, v8light]"` | ||
); | ||
}); | ||
|
||
it('returns tags in alphabetical order', () => { | ||
const tags = parseThemeTags(['v7light', 'v8light']); | ||
expect(tags).toEqual(tags.slice().sort((a, b) => a.localeCompare(b))); | ||
}); | ||
|
||
it('returns an immutable array', () => { | ||
expect(() => { | ||
const tags = parseThemeTags('v8light'); | ||
// @ts-expect-error | ||
tags.push('foo'); | ||
}).toThrowErrorMatchingInlineSnapshot(`"Cannot add property 1, object is not extensible"`); | ||
}); |
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,65 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { ascending } from './array_helpers'; | ||
|
||
const tags = (...themeTags: string[]) => | ||
Object.freeze(themeTags.sort(ascending((tag) => tag)) as ThemeTag[]); | ||
|
||
const validTag = (tag: any): tag is ThemeTag => ALL_THEMES.includes(tag); | ||
const isArrayOfStrings = (input: unknown): input is string[] => | ||
Array.isArray(input) && input.every((v) => typeof v === 'string'); | ||
|
||
export type ThemeTags = readonly ThemeTag[]; | ||
export type ThemeTag = 'v7light' | 'v7dark' | 'v8light' | 'v8dark'; | ||
export const DEFAULT_THEMES = tags('v7light', 'v7dark'); | ||
export const ALL_THEMES = tags('v7light', 'v7dark', 'v8light', 'v8dark'); | ||
|
||
export function parseThemeTags(input?: any): ThemeTags { | ||
if (!input) { | ||
return DEFAULT_THEMES; | ||
} | ||
|
||
if (input === '*') { | ||
return ALL_THEMES; | ||
} | ||
|
||
if (typeof input === 'string') { | ||
input = input.split(',').map((tag) => tag.trim()); | ||
} | ||
|
||
if (!isArrayOfStrings(input)) { | ||
throw new Error(`Invalid theme tags, must be an array of strings`); | ||
} | ||
|
||
if (!input.length) { | ||
throw new Error( | ||
`Invalid theme tags, you must specify at least one of [${ALL_THEMES.join(', ')}]` | ||
); | ||
} | ||
|
||
const invalidTags = input.filter((t) => !validTag(t)); | ||
if (invalidTags.length) { | ||
throw new Error( | ||
`Invalid theme tags [${invalidTags.join(', ')}], options: [${ALL_THEMES.join(', ')}]` | ||
); | ||
} | ||
|
||
return tags(...input); | ||
} |
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
Oops, something went wrong.
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 like the rename too