initial commit

This commit is contained in:
Zoe
2023-01-03 09:29:04 -06:00
commit 7851137d88
12889 changed files with 2557443 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
export type Filter = {
bundle?: string | null | undefined;
file?: string | null | undefined;
};
export declare const createFilter: (include: Filter | Filter[] | undefined, exclude: Filter | Filter[] | undefined) => (bundleId: string, id: string) => boolean;

View File

@@ -0,0 +1,56 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createFilter = void 0;
const picomatch_1 = __importDefault(require("picomatch"));
function isArray(arg) {
return Array.isArray(arg);
}
function ensureArray(thing) {
if (isArray(thing))
return thing;
if (thing == null)
return [];
return [thing];
}
const globToTest = (glob) => {
const pattern = glob;
const fn = (0, picomatch_1.default)(pattern, { dot: true });
return {
test: (what) => {
const result = fn(what);
return result;
},
};
};
const testFalse = {
test: () => false,
};
const testTrue = {
test: () => true,
};
const getMatcher = (filter) => {
const bundleTest = "bundle" in filter && filter.bundle != null ? globToTest(filter.bundle) : testTrue;
const fileTest = "file" in filter && filter.file != null ? globToTest(filter.file) : testTrue;
return { bundleTest, fileTest };
};
const createFilter = (include, exclude) => {
const includeMatchers = ensureArray(include).map(getMatcher);
const excludeMatchers = ensureArray(exclude).map(getMatcher);
return (bundleId, id) => {
for (let i = 0; i < excludeMatchers.length; ++i) {
const { bundleTest, fileTest } = excludeMatchers[i];
if (bundleTest.test(bundleId) && fileTest.test(id))
return false;
}
for (let i = 0; i < includeMatchers.length; ++i) {
const { bundleTest, fileTest } = includeMatchers[i];
if (bundleTest.test(bundleId) && fileTest.test(id))
return true;
}
return !includeMatchers.length;
};
};
exports.createFilter = createFilter;

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,106 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const create_filter_1 = require("./create-filter");
(0, globals_1.describe)("createFilter", () => {
(0, globals_1.it)("should return true when input and output is empty", () => {
const isIncluded = (0, create_filter_1.createFilter)([], []);
(0, globals_1.expect)(isIncluded("bundle", "file")).toBe(true);
});
(0, globals_1.describe)("Bundle", () => {
globals_1.it.each([
[[{ bundle: "b1.js" }], "b1.js", "file", false],
[[{ bundle: "b1.js" }], "b2.js", "file", true],
[[{ bundle: "translation-*.js" }], "b2.js", "file", true],
[[{ bundle: "translation-*.js" }], "translation-de.js", "file", false],
])("%# should exclude %j bundle %j file %j - %j", (exclude, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)([], exclude);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
globals_1.it.each([
[[{ bundle: "b1.js" }], "b1.js", "file", true],
[[{ bundle: "b1.js" }], "b2.js", "file", false],
[[{ bundle: "translation-*.js" }], "b2.js", "file", false],
[[{ bundle: "translation-*.js" }], "translation-de.js", "file", true],
])("%# should include %j bundle %j file %j - %j", (include, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)(include, []);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
globals_1.it.each([
[
[{ bundle: "translation-*.js" }],
[{ bundle: "translation-de.js" }],
"translation-de.js",
"file",
false,
],
[
[{ bundle: "translation-*.js" }],
[{ bundle: "translation-de.js" }],
"translation-en.js",
"file",
true,
],
])("%# should exclude included %j %j bundle %j file %j - %j", (include, exclude, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)(include, exclude);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
});
(0, globals_1.describe)("File", () => {
globals_1.it.each([
[[{ file: "b1.js" }], "bundle", "b1.js", false],
[[{ file: "b1.js" }], "bundle", "b2.js", true],
[[{ file: "translation-*.js" }], "bundle", "b2.js", true],
[[{ file: "translation-*.js" }], "bundle", "translation-de.js", false],
])("%# should exclude %j bundle %j file %j - %j", (exclude, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)([], exclude);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
globals_1.it.each([
[[{ file: "b1.js" }], "bundle", "b1.js", true],
[[{ file: "b1.js" }], "bundle", "b2.js", false],
[[{ file: "translation-*.js" }], "bundle", "b2.js", false],
[[{ file: "translation-*.js" }], "bundle", "translation-de.js", true],
])("%# should include %j bundle %j file %j - %j", (include, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)(include, []);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
globals_1.it.each([
[
[{ file: "translations/**" }],
[{ file: "translations/de.js" }],
"bundle",
"translations/de.js",
false,
],
[
[{ file: "translations/**" }],
[{ file: "translations/de.js" }],
"bundle",
"translations/en.js",
true,
],
])("%# should exclude included %j %j bundle %j file %j - %j", (include, exclude, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)(include, exclude);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
});
(0, globals_1.describe)("File in Bundle", () => {
globals_1.it.each([
[[{ bundle: "b1.js", file: "f1.js" }], "b1.js", "f1.js", false],
[[{ bundle: "b1.js", file: "f1.js" }], "b2.js", "f1.js", true],
[[{ bundle: "b1.js", file: "f1.js" }], "b1.js", "f2.js", true],
])("%# should exclude %j bundle %j file %j - %j", (exclude, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)([], exclude);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
globals_1.it.each([
[[{ bundle: "b1.js", file: "f1.js" }], "b1.js", "f1.js", true],
[[{ bundle: "b1.js", file: "f1.js" }], "b2.js", "f1.js", false],
[[{ bundle: "b1.js", file: "f1.js" }], "b1.js", "f2.js", false],
])("%# should include %j bundle %j file %j - %j", (include, bundle, file, result) => {
const isIncluded = (0, create_filter_1.createFilter)(include, []);
(0, globals_1.expect)(isIncluded(bundle, file)).toBe(result);
});
});
});

View File

@@ -0,0 +1,46 @@
export type SizeKey = "renderedLength" | "gzipLength" | "brotliLength";
export declare const isModuleTree: (mod: ModuleTree | ModuleTreeLeaf) => mod is ModuleTree;
export type ModuleUID = string;
export type BundleId = string;
export interface ModuleTreeLeaf {
name: string;
uid: ModuleUID;
}
export interface ModuleTree {
name: string;
children: Array<ModuleTree | ModuleTreeLeaf>;
}
export type ModulePart = {
metaUid: ModuleUID;
} & ModuleLengths;
export type ModuleImport = {
uid: ModuleUID;
dynamic?: boolean;
};
export type ModuleMeta = {
moduleParts: Record<BundleId, ModuleUID>;
importedBy: ModuleImport[];
imported: ModuleImport[];
isEntry?: boolean;
isExternal?: boolean;
id: string;
};
export interface ModuleLengths {
renderedLength: number;
gzipLength: number;
brotliLength: number;
}
export interface VisualizerData {
version: number;
tree: ModuleTree;
nodeParts: Record<ModuleUID, ModulePart>;
nodeMetas: Record<ModuleUID, ModuleMeta>;
env: {
[key: string]: unknown;
};
options: {
gzip: boolean;
brotli: boolean;
sourcemap: boolean;
};
}

View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isModuleTree = void 0;
const isModuleTree = (mod) => "children" in mod;
exports.isModuleTree = isModuleTree;