mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
45d182308b
* instancing works * misc opts * material.setproperty typing * baked skinning model instancing works * fix isNormalized * custom chunk rules injection framework * profiler instance count * seperate custom joint textures * fix joint mapped buffers * WebGL 1 doesn't allow int attributes * should rebuild instances after pso change * set instance attribute * constants naming
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
|
|
import fs from 'fs-extra';
|
|
import ps from 'path';
|
|
|
|
async function summarizeFilesInDirectory (directory: string) {
|
|
return (await fs.readdir(directory)).map((file) => ps.join(directory, file));
|
|
}
|
|
|
|
declare global {
|
|
const cc: object;
|
|
const _cc: object;
|
|
}
|
|
|
|
test('global variables are sealed', async () => {
|
|
const files = await summarizeFilesInDirectory(ps.join(__dirname, '..', '..', 'exports'));
|
|
for (const file of files) {
|
|
require(file);
|
|
}
|
|
|
|
const globalVariables: string[] = [];
|
|
const visited: Set<object> = new Set();
|
|
const getMembersRecursive = (object: {}, prefix: string) => {
|
|
const memberNames = Object.getOwnPropertyNames(object);
|
|
for (const memberName of memberNames) {
|
|
const member = object[memberName];
|
|
if (visited.has(member)) {
|
|
continue;
|
|
} else {
|
|
visited.add(member);
|
|
}
|
|
const path = `${prefix}.${memberName}`;
|
|
globalVariables.push(path);
|
|
// TODO: Recursive
|
|
// if (member === null) {
|
|
// console.warn(`${path} is \`null\`, is it intended?`);
|
|
// }
|
|
// else if (typeof member === 'object' && member.constructor === Object) {
|
|
// getMembersRecursive(member, path);
|
|
// }
|
|
}
|
|
};
|
|
// Global variable `cc`
|
|
getMembersRecursive(cc, 'cc');
|
|
|
|
const sealedGlobalVariablesFile = ps.join(__dirname, 'sealed-global-variables.json');
|
|
const output = false; // DO NOT CHANGE THIS PROPERTY EXCEPT IF YOU KNOW WHAT ARE YOU DOING.
|
|
if (output) {
|
|
// Update the sealed-global-variables.json.
|
|
// Please take care.
|
|
await fs.writeFile(sealedGlobalVariablesFile, JSON.stringify({
|
|
thisFile: {
|
|
stamp: new Date().toISOString(),
|
|
},
|
|
variables: globalVariables,
|
|
}, undefined, 4));
|
|
} else {
|
|
const sealedGlobalVariables = (await fs.readJson(sealedGlobalVariablesFile)).variables as string[];
|
|
const difference = globalVariables.filter((v) => !sealedGlobalVariables.includes(v));
|
|
expect(difference).toEqual([]);
|
|
}
|
|
|
|
}, 30000);
|