-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove experimental import assertions (#9955)
* refactor(build): extract getWebFeatureStatus() without import assertion * refactor(build): extract getWebSpec() without import assertion * chore(kumascript): remove import assertion * fix(build): use cwd() as base for node_modules
- Loading branch information
Showing
8 changed files
with
156 additions
and
62 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
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,30 @@ | ||
import { WebFeature, WebFeatureStatus } from "../libs/types/document.js"; | ||
import { importJSON } from "./utils.js"; | ||
|
||
let promise: Promise<Record<string, WebFeature>> | null = null; | ||
|
||
export async function getWebFeatures(): Promise<Record<string, WebFeature>> { | ||
if (!promise) { | ||
promise = importJSON<Record<string, WebFeature>>("web-features/index.json"); | ||
} | ||
|
||
return promise; | ||
} | ||
|
||
export async function getWebFeatureStatus( | ||
...features: string[] | ||
): Promise<WebFeatureStatus | undefined> { | ||
if (features.length === 0) { | ||
return; | ||
} | ||
|
||
const webFeatures = await getWebFeatures(); | ||
for (const feature of Object.values(webFeatures)) { | ||
if ( | ||
feature.status && | ||
feature.compat_features?.some((feature) => features.includes(feature)) | ||
) { | ||
return feature.status; | ||
} | ||
} | ||
} |
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,58 @@ | ||
import { importJSON } from "./utils.js"; | ||
|
||
type WebSpecs = WebSpec[]; | ||
interface WebSpec { | ||
url: string; | ||
seriesComposition: string; | ||
shortname: string; | ||
series: { | ||
shortname: string; | ||
currentSpecification: string; | ||
title: string; | ||
shortTitle: string; | ||
nightlyUrl: string; | ||
}; | ||
nightly: { | ||
url: string; | ||
status: string; | ||
sourcePath: string; | ||
alternateUrls: string[]; | ||
repository: string; | ||
filename: string; | ||
}; | ||
organization: string; | ||
groups: { name: string; url: string }[]; | ||
title: string; | ||
source: string; | ||
shortTitle: string; | ||
categories: string[]; | ||
standing: string; | ||
tests: { repository: string; testPaths: string[] }; | ||
} | ||
|
||
let promise: Promise<WebSpecs> | null = null; | ||
|
||
export async function getWebSpecs(): Promise<WebSpecs> { | ||
if (!promise) { | ||
promise = importJSON<WebSpecs>("web-specs/index.json"); | ||
} | ||
|
||
return promise; | ||
} | ||
|
||
export async function getWebSpec(url: string): Promise<WebSpec | undefined> { | ||
if (!url) { | ||
return; | ||
} | ||
const specs = await getWebSpecs(); | ||
|
||
return specs.find( | ||
(spec) => | ||
url.startsWith(spec.url) || | ||
url.startsWith(spec.nightly.url) || | ||
spec.nightly.alternateUrls.some((s) => url.startsWith(s)) || | ||
// When grabbing series nightly, make sure we're grabbing the latest spec version | ||
(spec.shortname === spec.series.currentSpecification && | ||
url.startsWith(spec.series.nightlyUrl)) | ||
); | ||
} |
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