-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbcc72f
commit ee2b94e
Showing
15 changed files
with
16,704 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
env: | ||
WIREIT_FAILURES: continue | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: npm | ||
cache-dependency-path: package-lock.json | ||
|
||
- uses: google/wireit@setup-github-actions-caching/v1 | ||
|
||
- name: NPM install | ||
run: npm ci | ||
|
||
- name: Test | ||
run: npm 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/lib/ | ||
/test/ | ||
/test/* | ||
!/test/test-data/ | ||
|
||
/index.js | ||
/index.js.map | ||
/index.d.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
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 |
---|---|---|
@@ -1 +1,10 @@ | ||
export {}; | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
export * from './lib/get-custom-elements.js'; | ||
export * from './lib/resolve-reference.js'; | ||
export * from './lib/get-module.js'; | ||
export * from './lib/predicates.js'; |
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,68 @@ | ||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import type { | ||
CustomElementDeclaration, | ||
CustomElementExport, | ||
Module, | ||
Package, | ||
Reference, | ||
} from 'custom-elements-manifest/schema.js'; | ||
import {isCustomElementDeclaration} from './predicates.js'; | ||
import {resolveReference} from './resolve-reference.js'; | ||
|
||
export type CustomElementInfo = { | ||
package: Package; | ||
module: Module; | ||
export: CustomElementExport; | ||
declaration: CustomElementDeclaration; | ||
declarationReference: Reference; | ||
}; | ||
|
||
/** | ||
* Gets all the custom element exports of a package | ||
* | ||
* @param pkg The package to search | ||
* @param packageName The name of the package | ||
* @param packageVersion The version of the package | ||
*/ | ||
export const getCustomElements = ( | ||
pkg: Package, | ||
packageName: string, | ||
packageVersion: string | ||
): Array<CustomElementInfo> => { | ||
const customElements: Array<CustomElementInfo> = []; | ||
for (const mod of pkg.modules) { | ||
if (mod.exports) { | ||
for (const e of mod.exports) { | ||
if (e.kind === 'custom-element-definition') { | ||
// TODO (justinfagnani): for large manifests we want to index ahead | ||
// of time to avoid polynomial lookups | ||
const decl = resolveReference( | ||
pkg, | ||
mod, | ||
e.declaration, | ||
packageName, | ||
packageVersion | ||
); | ||
if (decl !== undefined && isCustomElementDeclaration(decl)) { | ||
customElements.push({ | ||
package: pkg, | ||
module: mod, | ||
export: e, | ||
declaration: decl, | ||
declarationReference: e.declaration, | ||
}); | ||
} else { | ||
// This is some kind of manifest error, should we warn? | ||
// Or assume it was handled in a validation pass? | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return customElements; | ||
}; |
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,27 @@ | ||
/** | ||
* @license | ||
* Copyright 2021 Google LLC | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import type {Package} from 'custom-elements-manifest/schema.js'; | ||
|
||
/** | ||
* Gets a module by path from a package. | ||
*/ | ||
export const getModule = (pkg: Package, path: string) => { | ||
path = normalizeModulePath(path); | ||
for (const mod of pkg.modules) { | ||
const modulePath = normalizeModulePath(mod.path); | ||
if (modulePath === path) { | ||
return mod; | ||
} | ||
} | ||
return undefined; | ||
}; | ||
|
||
/** | ||
* Normalizes a module path by removing leading slashes. | ||
*/ | ||
export const normalizeModulePath = (path: string) => | ||
path.startsWith('/') ? path.substring(1) : path; |
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,42 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import type { | ||
Declaration, | ||
ClassDeclaration, | ||
CustomElementDeclaration, | ||
FunctionDeclaration, | ||
CustomElement, | ||
CustomElementMixinDeclaration, | ||
} from 'custom-elements-manifest/schema.js'; | ||
|
||
export const isClassDeclaration = (d: Declaration): d is ClassDeclaration => | ||
d.kind === 'class'; | ||
|
||
export const isFunctionDeclaration = ( | ||
d: Declaration | ||
): d is FunctionDeclaration => d.kind === 'function'; | ||
|
||
export const isMixinDeclaration = (d: Declaration): d is FunctionDeclaration => | ||
d.kind === 'mixin'; | ||
|
||
export const isVariableDeclaration = ( | ||
d: Declaration | ||
): d is FunctionDeclaration => d.kind === 'variable'; | ||
|
||
export const isCustomElement = ( | ||
d: Declaration | ||
): d is CustomElementDeclaration | CustomElementMixinDeclaration => | ||
(d as CustomElement).customElement === true; | ||
|
||
export const isCustomElementDeclaration = ( | ||
d: Declaration | ||
): d is CustomElementDeclaration => isClassDeclaration(d) && isCustomElement(d); | ||
|
||
export const isCustomElementMixinDeclaration = ( | ||
d: Declaration | ||
): d is CustomElementMixinDeclaration => | ||
isMixinDeclaration(d) && isCustomElement(d); |
Oops, something went wrong.