-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: spalger <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
677670b
commit 4cdbdfe
Showing
69 changed files
with
1,036 additions
and
260 deletions.
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
17 changes: 17 additions & 0 deletions
17
...lopment/core/server/kibana-plugin-core-server.pluginmanifest.extrapublicdirs.md
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,17 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [PluginManifest](./kibana-plugin-core-server.pluginmanifest.md) > [extraPublicDirs](./kibana-plugin-core-server.pluginmanifest.extrapublicdirs.md) | ||
|
||
## PluginManifest.extraPublicDirs property | ||
|
||
> Warning: This API is now obsolete. | ||
> | ||
> | ||
Specifies directory names that can be imported by other ui-plugins built using the same instance of the @<!-- -->kbn/optimizer. A temporary measure we plan to replace with better mechanisms for sharing static code between plugins | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly extraPublicDirs?: string[]; | ||
``` |
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
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
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
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,130 @@ | ||
/* | ||
* 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 Path from 'path'; | ||
|
||
import { Bundle } from './bundle'; | ||
import { UnknownVals } from './ts_helpers'; | ||
|
||
export interface BundleRef { | ||
bundleId: string; | ||
contextDir: string; | ||
contextPrefix: string; | ||
entry: string; | ||
exportId: string; | ||
} | ||
|
||
export class BundleRefs { | ||
static fromBundles(bundles: Bundle[]) { | ||
return new BundleRefs( | ||
bundles.reduce( | ||
(acc: BundleRef[], b) => [ | ||
...acc, | ||
...b.publicDirNames.map( | ||
(name): BundleRef => ({ | ||
bundleId: b.id, | ||
contextDir: b.contextDir, | ||
// Path.resolve converts separators and strips the final separator | ||
contextPrefix: Path.resolve(b.contextDir) + Path.sep, | ||
entry: name, | ||
exportId: `${b.type}/${b.id}/${name}`, | ||
}) | ||
), | ||
], | ||
[] | ||
) | ||
); | ||
} | ||
|
||
static parseSpec(json: unknown) { | ||
if (typeof json !== 'string') { | ||
throw new Error('expected `bundleRefs` spec to be a JSON string'); | ||
} | ||
|
||
let spec; | ||
try { | ||
spec = JSON.parse(json); | ||
} catch (error) { | ||
throw new Error('`bundleRefs` spec must be valid JSON'); | ||
} | ||
|
||
if (!Array.isArray(spec)) { | ||
throw new Error('`bundleRefs` spec must be an array'); | ||
} | ||
|
||
return new BundleRefs( | ||
spec.map( | ||
(refSpec: UnknownVals<BundleRef>): BundleRef => { | ||
if (typeof refSpec !== 'object' || !refSpec) { | ||
throw new Error('`bundleRefs[]` must be an object'); | ||
} | ||
|
||
const { bundleId } = refSpec; | ||
if (typeof bundleId !== 'string') { | ||
throw new Error('`bundleRefs[].bundleId` must be a string'); | ||
} | ||
|
||
const { contextDir } = refSpec; | ||
if (typeof contextDir !== 'string' || !Path.isAbsolute(contextDir)) { | ||
throw new Error('`bundleRefs[].contextDir` must be an absolute directory'); | ||
} | ||
|
||
const { contextPrefix } = refSpec; | ||
if (typeof contextPrefix !== 'string' || !Path.isAbsolute(contextPrefix)) { | ||
throw new Error('`bundleRefs[].contextPrefix` must be an absolute directory'); | ||
} | ||
|
||
const { entry } = refSpec; | ||
if (typeof entry !== 'string') { | ||
throw new Error('`bundleRefs[].entry` must be a string'); | ||
} | ||
|
||
const { exportId } = refSpec; | ||
if (typeof exportId !== 'string') { | ||
throw new Error('`bundleRefs[].exportId` must be a string'); | ||
} | ||
|
||
return { | ||
bundleId, | ||
contextDir, | ||
contextPrefix, | ||
entry, | ||
exportId, | ||
}; | ||
} | ||
) | ||
); | ||
} | ||
|
||
constructor(private readonly refs: BundleRef[]) {} | ||
|
||
public filterByExportIds(exportIds: string[]) { | ||
return this.refs.filter((r) => exportIds.includes(r.exportId)); | ||
} | ||
|
||
public filterByContextPrefix(bundle: Bundle, absolutePath: string) { | ||
return this.refs.filter( | ||
(ref) => ref.bundleId !== bundle.id && absolutePath.startsWith(ref.contextPrefix) | ||
); | ||
} | ||
|
||
public toSpecJson() { | ||
return JSON.stringify(this.refs); | ||
} | ||
} |
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.