mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-18 16:04:32 -04:00
@@ -15,6 +15,7 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const md5 = require('md5');
|
||||
|
||||
const { readFile } = require('./lib/utils');
|
||||
const { WORKERS_DIR } = require('./lib/pre_define');
|
||||
@@ -54,6 +55,8 @@ function initProjectConfig(projectConfig) {
|
||||
projectConfig.aceModuleJsonPath = projectConfig.aceModuleJsonPath || process.env.aceModuleJsonPath;
|
||||
projectConfig.aceSuperVisualPath = projectConfig.aceSuperVisualPath ||
|
||||
process.env.aceSuperVisualPath
|
||||
projectConfig.hashProjectPath = projectConfig.hashProjectPath ||
|
||||
hashProjectPath(projectConfig.projectPath)
|
||||
}
|
||||
|
||||
function loadEntryObj(projectConfig) {
|
||||
@@ -243,6 +246,17 @@ function processResourceArr(resourceArr, resourceMap, filePath) {
|
||||
}
|
||||
}
|
||||
|
||||
function hashProjectPath(projectPath) {
|
||||
const ASSCIIStart = 65;
|
||||
const ASSCIIEnd = 90;
|
||||
const deviation = 1;
|
||||
process.env.hashProjectPath =
|
||||
String.fromCharCode(Math.floor(Math.random() * (ASSCIIEnd - ASSCIIStart + deviation) + ASSCIIStart)) +
|
||||
md5(projectPath).substring(9, 16) +
|
||||
String.fromCharCode(Math.floor(Math.random() * (ASSCIIEnd - ASSCIIStart + deviation) + ASSCIIStart));
|
||||
return process.env.hashProjectPath;
|
||||
}
|
||||
|
||||
exports.projectConfig = projectConfig;
|
||||
exports.loadEntryObj = loadEntryObj;
|
||||
exports.readAppResource = readAppResource;
|
||||
|
||||
Generated
+30
@@ -1925,6 +1925,11 @@
|
||||
"supports-color": "^7.1.0"
|
||||
}
|
||||
},
|
||||
"charenc": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/charenc/-/charenc-0.0.2.tgz",
|
||||
"integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA=="
|
||||
},
|
||||
"check-error": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.nlark.com/check-error/download/check-error-1.0.2.tgz",
|
||||
@@ -2101,6 +2106,11 @@
|
||||
"which": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"crypt": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/crypt/-/crypt-0.0.2.tgz",
|
||||
"integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow=="
|
||||
},
|
||||
"date-format": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.nlark.com/date-format/download/date-format-3.0.0.tgz",
|
||||
@@ -2732,6 +2742,11 @@
|
||||
"resolved": "https://registry.npmmirror.com/ignore/download/ignore-5.2.0.tgz",
|
||||
"integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ=="
|
||||
},
|
||||
"ignore-loader": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/ignore-loader/-/ignore-loader-0.1.2.tgz",
|
||||
"integrity": "sha512-yOJQEKrNwoYqrWLS4DcnzM7SEQhRKis5mB+LdKKh4cPmGYlLPR0ozRzHV5jmEk2IxptqJNQA5Cc0gw8Fj12bXA=="
|
||||
},
|
||||
"import-fresh": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npm.taobao.org/import-fresh/download/import-fresh-3.3.0.tgz?cache=0&sync_timestamp=1608469520474&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fimport-fresh%2Fdownload%2Fimport-fresh-3.3.0.tgz",
|
||||
@@ -2793,6 +2808,11 @@
|
||||
"binary-extensions": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmmirror.com/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||
},
|
||||
"is-core-module": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmmirror.com/is-core-module/download/is-core-module-2.8.0.tgz?cache=0&sync_timestamp=1634236702465&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fis-core-module%2Fdownload%2Fis-core-module-2.8.0.tgz",
|
||||
@@ -3063,6 +3083,16 @@
|
||||
"integrity": "sha1-LrLjfqm2fEiR9oShOUeZr0hM96I=",
|
||||
"dev": true
|
||||
},
|
||||
"md5": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/md5/-/md5-2.3.0.tgz",
|
||||
"integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==",
|
||||
"requires": {
|
||||
"charenc": "0.0.2",
|
||||
"crypt": "0.0.2",
|
||||
"is-buffer": "~1.1.6"
|
||||
}
|
||||
},
|
||||
"memory-fs": {
|
||||
"version": "0.5.0",
|
||||
"resolved": "https://registry.nlark.com/memory-fs/download/memory-fs-0.5.0.tgz",
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
"eslint": "^7.16.0",
|
||||
"mocha": "^8.2.1",
|
||||
"mocha-context": "^0.1.5",
|
||||
"pegjs": "^0.10.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"uglify-js": "^3.13.0",
|
||||
"pegjs": "^0.10.0"
|
||||
"uglify-js": "^3.13.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
@@ -40,6 +40,7 @@
|
||||
"deccjsunit": "^1.0.6",
|
||||
"ignore-loader": "^0.1.2",
|
||||
"log4js": "^6.3.0",
|
||||
"md5": "^2.3.0",
|
||||
"ts-loader": "^8.0.12",
|
||||
"typescript": "^4.1.3",
|
||||
"webpack": "^5.48.0",
|
||||
|
||||
@@ -52,13 +52,6 @@ configure({
|
||||
export const logger = getLogger('ETS');
|
||||
|
||||
export const props: string[] = [];
|
||||
const GLOBAL_COMMON_MODULE_CACHE: string = `
|
||||
globalThis["__common_module_cache__"] = globalThis["__common_module_cache__"] || {};
|
||||
globalThis["webpackChunkcompilier"].forEach((item)=> {
|
||||
Object.keys(item[1]).forEach((element) => {
|
||||
globalThis["__common_module_cache__"][element] = null;
|
||||
})
|
||||
});`;
|
||||
|
||||
interface Info {
|
||||
message?: string;
|
||||
@@ -82,6 +75,7 @@ export class ResultStates {
|
||||
private modulePaths: Set<string> = new Set([]);
|
||||
|
||||
public apply(compiler: Compiler): void {
|
||||
|
||||
compiler.hooks.compilation.tap('SourcemapFixer', compilation => {
|
||||
compilation.hooks.afterProcessAssets.tap('SourcemapFixer', assets => {
|
||||
Reflect.ownKeys(assets).forEach(key => {
|
||||
@@ -116,6 +110,15 @@ export class ResultStates {
|
||||
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
||||
},
|
||||
(assets) => {
|
||||
const GLOBAL_COMMON_MODULE_CACHE = `
|
||||
globalThis["__common_module_cache__${projectConfig.hashProjectPath}"] =` +
|
||||
` globalThis["__common_module_cache__${projectConfig.hashProjectPath}"] || {};
|
||||
globalThis["webpackChunk${projectConfig.hashProjectPath}"].forEach((item)=> {
|
||||
Object.keys(item[1]).forEach((element) => {
|
||||
globalThis["__common_module_cache__${projectConfig.hashProjectPath}"][element] = null;
|
||||
})
|
||||
});`
|
||||
|
||||
if (assets['commons.js']) {
|
||||
assets['commons.js'] = new CachedSource(
|
||||
new ConcatSource(assets['commons.js'], GLOBAL_COMMON_MODULE_CACHE));
|
||||
@@ -129,13 +132,18 @@ export class ResultStates {
|
||||
compiler.hooks.compilation.tap('Require', compilation => {
|
||||
JavascriptModulesPlugin.getCompilationHooks(compilation).renderRequire.tap('renderRequire',
|
||||
(source) => {
|
||||
return `var commonCachedModule = globalThis["__common_module_cache__"] ? ` +
|
||||
`globalThis["__common_module_cache__"][moduleId]: null;\n` +
|
||||
return `var commonCachedModule = globalThis` +
|
||||
`["__common_module_cache__${projectConfig.hashProjectPath}"] ? ` +
|
||||
`globalThis["__common_module_cache__${projectConfig.hashProjectPath}"]` +
|
||||
`[moduleId]: null;\n` +
|
||||
`if (commonCachedModule) { return commonCachedModule.exports; }\n` +
|
||||
source.replace('// Execute the module function',
|
||||
`if (globalThis["__common_module_cache__"] && moduleId.indexOf("?name=") < 0 && ` +
|
||||
`Object.keys(globalThis["__common_module_cache__"]).indexOf(moduleId) >= 0) {\n` +
|
||||
` globalThis["__common_module_cache__"][moduleId] = module;\n}`);
|
||||
`if (globalThis["__common_module_cache__${projectConfig.hashProjectPath}"]` +
|
||||
` && moduleId.indexOf("?name=") < 0 && ` +
|
||||
`Object.keys(globalThis["__common_module_cache__${projectConfig.hashProjectPath}"])` +
|
||||
`.indexOf(moduleId) >= 0) {\n` +
|
||||
` globalThis["__common_module_cache__${projectConfig.hashProjectPath}"]` +
|
||||
`[moduleId] = module;\n}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -266,5 +266,6 @@ module.exports = (env, argv) => {
|
||||
if (appResourcePath) {
|
||||
readAppResource(resources, appResourcePath);
|
||||
}
|
||||
config.output.library = projectConfig.hashProjectPath;
|
||||
return config;
|
||||
}
|
||||
Reference in New Issue
Block a user