mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Generated
+145
-161
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -30,7 +30,7 @@
|
||||
"@babel/core": "^7.13.10",
|
||||
"@babel/preset-env": "7.8.7",
|
||||
"@cocos/babel-preset-cc": "2.2.0",
|
||||
"@cocos/build-engine": "4.2.19-patch.3",
|
||||
"@cocos/build-engine": "4.2.19",
|
||||
"@cocos/typedoc-plugin-internal-external": "^1.0.1",
|
||||
"@cocos/typedoc-plugin-localization": "^1.0.0",
|
||||
"@types/fs-extra": "^5.0.4",
|
||||
|
||||
Generated
+5
-5
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cocos/build-engine",
|
||||
"version": "4.2.19-patch.3",
|
||||
"version": "4.2.19-patch.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -2725,9 +2725,9 @@
|
||||
}
|
||||
},
|
||||
"tfig": {
|
||||
"version": "3.2.3",
|
||||
"resolved": "https://registry.npmmirror.com/tfig/download/tfig-3.2.3.tgz",
|
||||
"integrity": "sha512-goaWScDX50AorEETh9+QNSRf0UzYU0ztQ/HycpWnTgbwtGA40MuVyu5lbl60XZQQlCFWD4vRLyR2Tyky+9miEQ==",
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmmirror.com/tfig/download/tfig-3.2.2.tgz?cache=0&sync_timestamp=1636105695153&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Ftfig%2Fdownload%2Ftfig-3.2.2.tgz",
|
||||
"integrity": "sha1-sqgkI7L3FXQLph8jyJv1Q6HvpDY=",
|
||||
"requires": {
|
||||
"fs-extra": "^7.0.1",
|
||||
"typescript": "^4.2.3",
|
||||
@@ -2851,7 +2851,7 @@
|
||||
},
|
||||
"yargs-parser": {
|
||||
"version": "13.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/yargs-parser/download/yargs-parser-13.1.2.tgz?cache=0&sync_timestamp=1637031023704&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fyargs-parser%2Fdownload%2Fyargs-parser-13.1.2.tgz",
|
||||
"resolved": "https://registry.nlark.com/yargs-parser/download/yargs-parser-13.1.2.tgz?cache=0&sync_timestamp=1624233514145&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fyargs-parser%2Fdownload%2Fyargs-parser-13.1.2.tgz",
|
||||
"integrity": "sha1-Ew8JcC667vJlDVTObj5XBvek+zg=",
|
||||
"requires": {
|
||||
"camelcase": "^5.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cocos/build-engine",
|
||||
"version": "4.2.19-patch.3",
|
||||
"version": "4.2.19-patch.1",
|
||||
"description": "",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -32,7 +32,7 @@
|
||||
"rollup-plugin-progress": "^1.1.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"semver": "^7.3.2",
|
||||
"tfig": "^3.2.3",
|
||||
"tfig": "^3.2.2",
|
||||
"typescript": "^4.3.5",
|
||||
"yargs": "^15.1.0"
|
||||
},
|
||||
|
||||
@@ -8,7 +8,6 @@ const DEBUG = false;
|
||||
const REMOVE_TMP = true;
|
||||
const REMOVE_OLD = !DEBUG;
|
||||
const RECOMPILE = !DEBUG;
|
||||
const REMOVE_UNBUNDLED_CACHE = !DEBUG;
|
||||
|
||||
export async function build (options: {
|
||||
engine: string;
|
||||
@@ -36,15 +35,14 @@ export async function build (options: {
|
||||
|
||||
const tsConfigPath = statsQuery.tsConfigPath;
|
||||
|
||||
const unbundledOutDir = ps.join(outDir, '__before_bundle');
|
||||
const unbundledOutFile = ps.join(outDir, `cc-before-rollup.js`);
|
||||
const parsedCommandLine = ts.getParsedCommandLineOfConfigFile(
|
||||
tsConfigPath, {
|
||||
declaration: true,
|
||||
noEmit: false,
|
||||
emitDeclarationOnly: true,
|
||||
outFile: undefined,
|
||||
outDir: unbundledOutDir,
|
||||
allowJs: true,
|
||||
outFile: unbundledOutFile,
|
||||
outDir: undefined,
|
||||
}, {
|
||||
onUnRecoverableConfigFileDiagnostic: () => {},
|
||||
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
||||
@@ -58,12 +56,28 @@ export async function build (options: {
|
||||
throw new Error(`Can not get 'parsedCommandLine'.`);
|
||||
}
|
||||
|
||||
const unbundledOutDirNormalized = ps.resolve(engine, parsedCommandLine.options.outDir!);
|
||||
console.debug(`Unbundled will write to: ${unbundledOutDirNormalized}`);
|
||||
const outputJSPath = ps.join(ps.dirname(tsConfigPath), unbundledOutFile);
|
||||
// console.log(outputJSPath);
|
||||
|
||||
await fs.ensureDir(unbundledOutDirNormalized);
|
||||
const extName = ps.extname(outputJSPath);
|
||||
if (extName !== '.js') {
|
||||
console.error(`Unexpected output extension ${extName}, please check it.`);
|
||||
return undefined;
|
||||
}
|
||||
const dirName = ps.dirname(outputJSPath);
|
||||
const baseName = ps.basename(outputJSPath, extName);
|
||||
const destExtensions = [
|
||||
'.d.ts',
|
||||
'.d.ts.map',
|
||||
];
|
||||
if (REMOVE_OLD) {
|
||||
await fs.emptyDir(unbundledOutDirNormalized);
|
||||
for (const destExtension of destExtensions) {
|
||||
const destFile = ps.join(dirName, baseName + destExtension);
|
||||
if (await fs.pathExists(destFile)) {
|
||||
console.log(`Delete old ${destFile}.`);
|
||||
await fs.unlink(destFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Generating...`);
|
||||
@@ -116,58 +130,31 @@ export async function build (options: {
|
||||
}
|
||||
}
|
||||
|
||||
const patchSpineCoreDtsSource = ps.join(engine, 'cocos', 'spine', 'lib', 'spine-core.d.ts');
|
||||
const patchSpineCoreDtsTarget = ps.join(unbundledOutDirNormalized, 'cocos', 'spine', 'lib', 'spine-core.d.ts');
|
||||
if (!await fs.pathExists(patchSpineCoreDtsSource)) {
|
||||
console.debug(`Does 'cocos/spine/lib/spine-core.d.ts' no longer existed? I have a patch for it.`);
|
||||
} else {
|
||||
console.debug(`It's ${new Date().toLocaleString()}, we're still doing the hack for spine-core.d.ts`);
|
||||
await fs.ensureDir(ps.dirname(patchSpineCoreDtsTarget));
|
||||
await fs.copyFile(
|
||||
patchSpineCoreDtsSource,
|
||||
patchSpineCoreDtsTarget,
|
||||
);
|
||||
const tscOutputDtsFile = ps.join(dirName, `${baseName}.d.ts`);
|
||||
if (!await fs.pathExists(tscOutputDtsFile)) {
|
||||
console.error(`Failed to compile.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const types = parsedCommandLine.options.types?.map((typeFile) => `${typeFile}.d.ts`);
|
||||
if (types) {
|
||||
for (const file of types) {
|
||||
const destPath = ps.join(unbundledOutDirNormalized, ps.isAbsolute(file) ? ps.basename(file) : file);
|
||||
const destPath = ps.join(outDir, ps.isAbsolute(file) ? ps.basename(file) : file);
|
||||
await fs.ensureDir(ps.dirname(destPath));
|
||||
await fs.copyFile(file, destPath);
|
||||
}
|
||||
}
|
||||
|
||||
const giftInputs: string[] = [];
|
||||
const listGiftInputs = async (dir: string) => {
|
||||
for (const file of await fs.readdir(dir)) {
|
||||
const path = ps.join(dir, file);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const stats = await fs.stat(path);
|
||||
if (stats.isFile()) {
|
||||
giftInputs.push(path);
|
||||
} else if (stats.isDirectory()) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await listGiftInputs(path);
|
||||
}
|
||||
}
|
||||
};
|
||||
await listGiftInputs(unbundledOutDirNormalized);
|
||||
const giftInputs = [tscOutputDtsFile];
|
||||
|
||||
const giftEntries: Record<string, string> = { };
|
||||
|
||||
const cleanupFiles: string[] = [];
|
||||
|
||||
const getModuleNameInTsOutFile = (moduleFile: string) => {
|
||||
const path = ps.relative(statsQuery.path, moduleFile);
|
||||
const pathDts = path.replace(/\.ts$/, '.d.ts');
|
||||
return ps.join(unbundledOutDirNormalized, pathDts);
|
||||
};
|
||||
const cleanupFiles = [tscOutputDtsFile];
|
||||
|
||||
if (withExports) {
|
||||
for (const exportEntry of featureUnits) {
|
||||
giftEntries[exportEntry] = getModuleNameInTsOutFile(
|
||||
statsQuery.getFeatureUnitFile(exportEntry),
|
||||
statsQuery.getFeatureUnitFile(exportEntry), statsQuery,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -175,39 +162,37 @@ export async function build (options: {
|
||||
if (withEditorExports) {
|
||||
for (const editorExportModule of editorExportModules) {
|
||||
giftEntries[editorExportModule] = getModuleNameInTsOutFile(
|
||||
statsQuery.getEditorPublicModuleFile(editorExportModule),
|
||||
statsQuery.getEditorPublicModuleFile(editorExportModule), statsQuery,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let ccDtsFile: string | undefined;
|
||||
if (withIndex && !withExports) {
|
||||
ccDtsFile = ps.join(unbundledOutDirNormalized, 'virtual-cc.d.ts');
|
||||
giftEntries.cc = ccDtsFile;
|
||||
giftEntries.cc = 'cc';
|
||||
const ccDtsFile = ps.join(dirName, 'virtual-cc.d.ts');
|
||||
giftInputs.push(ccDtsFile);
|
||||
cleanupFiles.push(ccDtsFile);
|
||||
const code = `${
|
||||
const code = `declare module "cc" {\n${
|
||||
statsQuery.evaluateIndexModuleSource(featureUnits,
|
||||
(featureUnit) => getModuleNameInTsOutFile(statsQuery.getFeatureUnitFile(featureUnit)).replace(/\\/g, '/').replace(/\.d.ts$/, ''))
|
||||
}\n`;
|
||||
(featureUnit) => getModuleNameInTsOutFile(statsQuery.getFeatureUnitFile(featureUnit), statsQuery))
|
||||
}\n}`;
|
||||
await fs.writeFile(ccDtsFile, code, { encoding: 'utf8' });
|
||||
}
|
||||
|
||||
console.log(`Bundling...`);
|
||||
try {
|
||||
const indexOutputPath = ps.join(outDir, 'cc.d.ts');
|
||||
const indexOutputPath = ps.join(dirName, 'cc.d.ts');
|
||||
const giftResult = gift.bundle({
|
||||
input: giftInputs,
|
||||
rootDir: unbundledOutDirNormalized,
|
||||
name: 'cc',
|
||||
rootModule: 'index',
|
||||
entries: giftEntries,
|
||||
priority: [
|
||||
...(ccDtsFile ? [ccDtsFile] : []), // Things should be exported to 'cc' as far as possible.
|
||||
'cc', // Things should be exported to 'cc' as far as possible.
|
||||
],
|
||||
groups: [
|
||||
{ test: /^cc\/editor.*$/, path: ps.join(outDir, 'cc.editor.d.ts') },
|
||||
{ test: /^cc\/.*$/, path: ps.join(outDir, 'index.d.ts') },
|
||||
{ test: /^cc\/editor.*$/, path: ps.join(dirName, 'cc.editor.d.ts') },
|
||||
{ test: /^cc\/.*$/, path: ps.join(dirName, 'index.d.ts') },
|
||||
{ test: /^cc.*$/, path: indexOutputPath },
|
||||
],
|
||||
nonExportedSymbolDistribution: [{
|
||||
@@ -237,10 +222,6 @@ export async function build (options: {
|
||||
if (REMOVE_TMP) {
|
||||
await Promise.all((cleanupFiles.map(async (file) => fs.unlink(file))));
|
||||
}
|
||||
|
||||
if (REMOVE_UNBUNDLED_CACHE) {
|
||||
await fs.remove(unbundledOutDirNormalized);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -254,3 +235,9 @@ export function buildIndexModule (featureUnits: string[], statsQuery: StatsQuery
|
||||
.join('\n')
|
||||
}\n}`;
|
||||
}
|
||||
|
||||
function getModuleNameInTsOutFile (moduleFile: string, statsQuery: StatsQuery) {
|
||||
const path = ps.relative(statsQuery.path, moduleFile);
|
||||
const tsOutFileModuleName = ps.join(ps.dirname(path), ps.basename(path, ps.extname(path))).replace(/\\/g, '/');
|
||||
return tsOutFileModuleName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user