5c2a08de6d
* Update browserslist * Add browserslistrc * ember-cli-update --to 3.26, fix conflicts * Run codemodes that start with ember-* * More codemods - before cp* * More codemods (curly data-test-*) * WIP ember-basic-dropdown template errors * updates ember-basic-dropdown and related deps to fix build issues * updates basic dropdown instances to new version API * updates more deps -- ember-template-lint is working again * runs no-implicit-this codemod * creates and runs no-quoteless-attributes codemod * runs angle brackets codemod * updates lint:hbs globs to only touch hbs files * removes yield only templates * creates and runs deprecated args transform * supresses lint error for invokeAction on LinkTo component * resolves remaining ambiguous path lint errors * resolves simple-unless lint errors * adds warnings for deprecated tagName arg on LinkTo components * adds warnings for remaining curly component invocation * updates global template lint rules * resolves remaining template lint errors * disables some ember specfic lint rules that target pre octane patterns * js lint fix run * resolves remaining js lint errors * fixes test run * adds npm-run-all dep * fixes test attribute issues * fixes console acceptance tests * fixes tests * adds yield only wizard/tutorial-active template * fixes more tests * attempts to fix more flaky tests * removes commented out settled in transit test * updates deprecations workflow and adds initializer to filter by version * updates flaky policies acl old test * updates to flaky transit test * bumps ember deps down to LTS version * runs linters after main merge * fixes client count tests after bad merge conflict fixes * fixes client count history test * more updates to lint config * another round of hbs lint fixes after extending stylistic rule * updates lint-staged commands * removes indent eslint rule since it seems to break things * fixes bad attribute in transform-edit-form template * test fixes * fixes enterprise tests * adds changelog * removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters * flaky test fix Co-authored-by: hashishaw <cshaw@hashicorp.com>
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import flat from 'flat';
|
|
import deepmerge from 'deepmerge';
|
|
|
|
const { unflatten } = flat;
|
|
const DOT_REPLACEMENT = '☃';
|
|
|
|
//function that takes a list of path and returns a deeply nested object
|
|
//representing a tree of all of those paths
|
|
//
|
|
//
|
|
// given ["foo", "bar", "foo1", "foo/bar", "foo/baz", "foo/bar/baz"]
|
|
//
|
|
// returns {
|
|
// bar: null,
|
|
// foo: {
|
|
// bar: {
|
|
// baz: null
|
|
// },
|
|
// baz: null,
|
|
// },
|
|
// foo1: null,
|
|
// }
|
|
export default function (paths) {
|
|
// first sort the list by length, then alphanumeric
|
|
let list = paths.slice(0).sort((a, b) => b.length - a.length || b.localeCompare(a));
|
|
// then reduce to an array
|
|
// and we remove all of the items that have a string
|
|
// that starts with the same prefix from the list
|
|
// so if we have "foo/bar/baz", both "foo" and "foo/bar"
|
|
// won't be included in the list
|
|
let tree = list.reduce((accumulator, ns) => {
|
|
let nsWithPrefix = accumulator.find((path) => path.startsWith(ns));
|
|
// we need to make sure it's a match for the full path part
|
|
let isFullMatch = nsWithPrefix && nsWithPrefix.charAt(ns.length) === '/';
|
|
if (!isFullMatch) {
|
|
accumulator.push(ns);
|
|
}
|
|
return accumulator;
|
|
}, []);
|
|
|
|
tree = tree.sort((a, b) => a.localeCompare(b));
|
|
// after the reduction we're left with an array that contains
|
|
// strings that represent the longest branches
|
|
// we'll replace the dots in the paths, then expand the path
|
|
// to a nested object that we can then query with Ember.get
|
|
return deepmerge.all(
|
|
tree.map((p) => {
|
|
p = p.replace(/\.+/g, DOT_REPLACEMENT);
|
|
return unflatten({ [p]: null }, { delimiter: '/', object: true });
|
|
})
|
|
);
|
|
}
|