Restructure package files, add exports (#13530)

Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com>
This commit is contained in:
fisker CheungandSosuke Suzuki authored and GitHub committed 2022-10-06 15:20:19 +08:00
1 parent e132a9ba43
commit 31a796d32c
17 files changed
+232 -111

No files matched your search

+4 -2
View File
@@ -5,13 +5,15 @@
importScripts("lib/parsers-location.js");
importScripts("https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js");
const parsers = Object.keys(parsersLocation).map((file) => `lib/${file}`);
const plugins = [
...new Set(Object.values(parsersLocation).map((file) => `lib/${file}`)),
];
toolbox.precache([
// Scripts
"lib/standalone.js",
"lib/parsers-location.js",
...parsers,
...plugins,
"playground.js",
"https://unpkg.com/sw-toolbox@3.6.0/sw-toolbox.js",
+10 -11
View File
@@ -15,17 +15,16 @@ importScripts("lib/standalone.js");
// this is required to only load parsers when we need them
const parsers = Object.create(null);
for (const file in parsersLocation) {
const { parsers: moduleParsers, property } = parsersLocation[file];
const url = `lib/${file}`;
for (const parserName of moduleParsers) {
Object.defineProperty(parsers, parserName, {
get() {
importScriptOnce(url);
return prettierPlugins[property].parsers[parserName];
},
});
}
for (const [parser, file] of Object.entries(parsersLocation)) {
Object.defineProperty(parsers, parser, {
get() {
const url = `lib/${file}`;
importScriptOnce(url);
return Object.values(prettierPlugins).find((plugin) =>
Object.hasOwn(plugin.parsers, parser)
).parsers[parser];
},
});
}
const docExplorerPlugin = {