xhs-mp-compiler-cli 2.0.33-beta.9 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","path","xhs-mp-pack","xhs-mp-compiler-utils","./serviceChunkPlugin","./resolveLimitPlugin","../../../plugins/InjectorPlugin","../../../plugins/SourceMapDevToolPlugin","../../../../utils/cache"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.presetService=exports.getServiceEntry=void 0;const path_1=__importDefault(require("path")),xhs_mp_pack_1=require("xhs-mp-pack"),xhs_mp_compiler_utils_1=require("xhs-mp-compiler-utils"),serviceChunkPlugin_1=__importDefault(require("./serviceChunkPlugin")),resolveLimitPlugin_1=__importDefault(require("./resolveLimitPlugin")),InjectorPlugin_1=require("../../../plugins/InjectorPlugin"),SourceMapDevToolPlugin_1=require("../../../plugins/SourceMapDevToolPlugin"),cache_1=require("../../../../utils/cache");exports.getServiceEntry=options=>()=>{const entries={},{packSetting:packSetting}=options;return packSetting.enableV2&&appendV2Entry(options,entries),packSetting.enableV1&&appendV1Entry(options,entries),entries};const appendV2Entry=(options,entries)=>{const{packSetting:packSetting}=options,{mainPkg:mainPkg,subPkgs:subPkgs}=packSetting.getCompilePkgsForEntries();mainPkg&&(entries["v2/service"]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`);for(const{root:root}of subPkgs){entries[`v2/${root}/service`]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`}},appendV1Entry=(options,entries)=>{const{packSetting:packSetting}=options,{mainPkg:mainPkg,subPkgs:subPkgs}=packSetting.getCompilePkgsForEntries();mainPkg&&(entries["v1/service"]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`);for(const{root:root}of subPkgs){entries[`v1/${root}/service`]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`}};exports.presetService=(chain,options)=>{const{packSetting:packSetting}=options,{env:env,distDir:distDir,cacheDirectory:cacheDirectory,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment}=packSetting,absCacheDirectory=path_1.default.join(cacheDirectory,"service");if(chain.merge(Object.assign({output:{path:distDir,globalObject:"globalThis",libraryTarget:"umd",uniqueName:"MpService"}},(0,cache_1.getCacheConfig)(absCacheDirectory,options))),chain.plugin("InjectorPlugin").use(InjectorPlugin_1.InjectorPlugin,[options]),chain.plugin("ServiceChunkPlugin").use(serviceChunkPlugin_1.default,[options]),chain.resolve.plugin("ResolveLimitPlugin").use(resolveLimitPlugin_1.default,[options]),chain.devtool(!!enableSourcemap&&"source-map"),enableSourcemap&&!appendSourcemapComment){const SourceMapDevToolPlugin=(0,SourceMapDevToolPlugin_1.getSourceMapDevtoolPlugin)(options.packMode);chain.plugin("SourceMapDevToolPlugin").use(SourceMapDevToolPlugin,[{filename:"[file].map",append:!1}])}if(chain.optimization.runtimeChunk({name:"runtime"}),env!==xhs_mp_pack_1.ENV.development){const allowChunk=(_name,type)=>{if(!_name){return!1}const name=(0,xhs_mp_compiler_utils_1.toUnixPath)(_name),independentSet=new Set,{subPkgs:subPkgs}=packSetting.getCompilePkgsForEntries();return subPkgs.filter((p=>p.independent)).forEach((p=>{
|
|
1
|
+
var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","path","xhs-mp-pack","xhs-mp-compiler-utils","./serviceChunkPlugin","./resolveLimitPlugin","../../../plugins/InjectorPlugin","../../../plugins/SourceMapDevToolPlugin","../../../../utils/cache"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.presetService=exports.getServiceEntry=void 0;const path_1=__importDefault(require("path")),xhs_mp_pack_1=require("xhs-mp-pack"),xhs_mp_compiler_utils_1=require("xhs-mp-compiler-utils"),serviceChunkPlugin_1=__importDefault(require("./serviceChunkPlugin")),resolveLimitPlugin_1=__importDefault(require("./resolveLimitPlugin")),InjectorPlugin_1=require("../../../plugins/InjectorPlugin"),SourceMapDevToolPlugin_1=require("../../../plugins/SourceMapDevToolPlugin"),cache_1=require("../../../../utils/cache");exports.getServiceEntry=options=>()=>{const entries={},{packSetting:packSetting}=options;return packSetting.enableV2&&appendV2Entry(options,entries),packSetting.enableV1&&appendV1Entry(options,entries),entries};const appendV2Entry=(options,entries)=>{const{packSetting:packSetting}=options,{mainPkg:mainPkg,subPkgs:subPkgs}=packSetting.getCompilePkgsForEntries();mainPkg&&(entries["v2/service"]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`);for(const{root:root}of subPkgs){entries[`v2/${root}/service`]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`}},appendV1Entry=(options,entries)=>{const{packSetting:packSetting}=options,{mainPkg:mainPkg,subPkgs:subPkgs}=packSetting.getCompilePkgsForEntries();mainPkg&&(entries["v1/service"]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`);for(const{root:root}of subPkgs){entries[`v1/${root}/service`]=`mp-entry-loader?type=service&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`}};exports.presetService=(chain,options)=>{const{packSetting:packSetting}=options,{env:env,distDir:distDir,cacheDirectory:cacheDirectory,enableSourcemap:enableSourcemap,appendSourcemapComment:appendSourcemapComment}=packSetting,absCacheDirectory=path_1.default.join(cacheDirectory,"service");if(chain.merge(Object.assign({output:{path:distDir,globalObject:"globalThis",libraryTarget:"umd",uniqueName:"MpService"}},(0,cache_1.getCacheConfig)(absCacheDirectory,options))),chain.plugin("InjectorPlugin").use(InjectorPlugin_1.InjectorPlugin,[options]),chain.plugin("ServiceChunkPlugin").use(serviceChunkPlugin_1.default,[options]),chain.resolve.plugin("ResolveLimitPlugin").use(resolveLimitPlugin_1.default,[options]),chain.devtool(!!enableSourcemap&&"source-map"),enableSourcemap&&!appendSourcemapComment){const SourceMapDevToolPlugin=(0,SourceMapDevToolPlugin_1.getSourceMapDevtoolPlugin)(options.packMode);chain.plugin("SourceMapDevToolPlugin").use(SourceMapDevToolPlugin,[{filename:"[file].map",append:!1}])}if(chain.optimization.runtimeChunk({name:"runtime"}),env!==xhs_mp_pack_1.ENV.development){const allowChunk=(_name,type)=>{if(!_name){return!1}const name=(0,xhs_mp_compiler_utils_1.toUnixPath)(_name),independentSet=new Set,{subPkgs:subPkgs}=packSetting.getCompilePkgsForEntries();return subPkgs.filter((p=>p.independent)).forEach((p=>{independentSet.add((0,xhs_mp_compiler_utils_1.toUnixPath)(`${type}/${p.root}/service`))})),!independentSet.has(name)&&(name===`${type}/service`||new RegExp(`^(${type})\\/.+\\/service$`).test(name))};chain.optimization.splitChunks({minSize:0,cacheGroups:{serviceCommonV1:{name:"service-common-v1",chunks:chunk=>allowChunk(chunk.name,"v1"),minChunks:2,enforce:!0,reuseExistingChunk:!0,priority:10},serviceCommonV2:{name:"service-common-v2",chunks:chunk=>allowChunk(chunk.name,"v2"),minChunks:2,enforce:!0,reuseExistingChunk:!0,priority:10}}})}}}));
|
|
@@ -9,7 +9,8 @@ declare class ServiceChunkPlugin {
|
|
|
9
9
|
options: IPresetOptions;
|
|
10
10
|
constructor(options: IPresetOptions);
|
|
11
11
|
apply(compiler: IXhsCompiler): void;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
updateMainService(compilation: Compilation, wrappedRuntimeSource: GeneratedSource, packSetting: any, project: any, assetName: string, commonSourceName: string): void;
|
|
13
|
+
updateIndependentService(compilation: Compilation, wrappedRuntimeSource: GeneratedSource, type: 'v1' | 'v2'): void;
|
|
14
|
+
updateNonIndependentService(compilation: Compilation, type: 'v1' | 'v2'): void;
|
|
14
15
|
}
|
|
15
16
|
export default ServiceChunkPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","webpack","xhs-mp-compiler-utils","./sanbox"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const webpack_1=require("webpack"),xhs_mp_compiler_utils_1=require("xhs-mp-compiler-utils"),sanbox_1=require("./sanbox"),{SourceMapSource:SourceMapSource,RawSource:RawSource,ConcatSource:ConcatSource}=webpack_1.sources;function ensureGeneratedSource(source){return source?"string"==typeof source?new RawSource(source):source:new RawSource("")}function validateSourceMapIntegrity(source,filename){try{const result=source.sourceAndMap();if(result.map){const map=result.map;map.sources&&Array.isArray(map.sources)||console.warn(`⚠️ Invalid sourcemap for ${filename}: missing or invalid sources`),map.mappings&&"string"==typeof map.mappings||console.warn(`⚠️ Invalid sourcemap for ${filename}: missing or invalid mappings`),0===map.sources.length&&console.warn(`⚠️ Empty sourcemap sources for ${filename}`)}}catch(error){console.warn(`⚠️ Failed to validate sourcemap for ${filename}:`,error)}}function createSourceWrapper(prefixCode,originalSource,suffixCode
|
|
1
|
+
!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","webpack","xhs-mp-compiler-utils","./sanbox"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const webpack_1=require("webpack"),xhs_mp_compiler_utils_1=require("xhs-mp-compiler-utils"),sanbox_1=require("./sanbox"),{SourceMapSource:SourceMapSource,RawSource:RawSource,ConcatSource:ConcatSource}=webpack_1.sources;function ensureGeneratedSource(source){return source?"string"==typeof source?new RawSource(source):source:new RawSource("")}function validateSourceMapIntegrity(source,filename){try{const result=source.sourceAndMap();if(result.map){const map=result.map;map.sources&&Array.isArray(map.sources)||console.warn(`⚠️ Invalid sourcemap for ${filename}: missing or invalid sources`),map.mappings&&"string"==typeof map.mappings||console.warn(`⚠️ Invalid sourcemap for ${filename}: missing or invalid mappings`),0===map.sources.length&&console.warn(`⚠️ Empty sourcemap sources for ${filename}`)}}catch(error){console.warn(`⚠️ Failed to validate sourcemap for ${filename}:`,error)}}function createSourceWrapper(prefixCode,originalSource,suffixCode){if(!originalSource){const combinedCode=[prefixCode,suffixCode].filter(Boolean).join("\n");return new RawSource(combinedCode)}const concatSource=new ConcatSource;return prefixCode&&concatSource.add(new RawSource(prefixCode+"\n")),concatSource.add(ensureGeneratedSource(originalSource)),suffixCode&&concatSource.add(new RawSource("\n"+suffixCode)),concatSource}function wrapCodeWithGlobalCheck(source,globalVarName){return createSourceWrapper([`if (!globalThis.${globalVarName}) {`,`globalThis.${globalVarName} = true;`].join("\n"),source,"}")}function createBusinessCodeSource(runtimeSource,serviceSource,filename,commonSource){const concatSource=new ConcatSource;return runtimeSource&&(concatSource.add(ensureGeneratedSource(runtimeSource)),concatSource.add(new RawSource("\n"))),commonSource&&(concatSource.add(ensureGeneratedSource(commonSource)),concatSource.add(new RawSource("\n"))),serviceSource&&concatSource.add(ensureGeneratedSource(serviceSource)),concatSource}const bomVars=["window","document","frames","self","location","navigator","localStorage","history","screen","alert","confirm","prompt"];var SandboxLevel;!function(SandboxLevel){SandboxLevel.CLOSE="close",SandboxLevel.LOOSE="loose",SandboxLevel.STRICT="strict"}(SandboxLevel||(SandboxLevel={}));const DEFAULT_SANDBOX_LEVEL=SandboxLevel.LOOSE;function adapteServiceCode(assetName,serviceSource,packSetting,project,isIndependent){var _a,_b,_c,_d,_e;const subPackages=project.getSubPackages(),sandboxLevelStr=null===(_d=null===(_c=null===(_b=null===(_a=project.projectJsonContent)||void 0===_a?void 0:_a.setting)||void 0===_b?void 0:_b.sandboxLevel)||void 0===_c?void 0:_c.trim)||void 0===_d?void 0:_d.call(_c),sandboxLevel=Object.values(SandboxLevel).includes(sandboxLevelStr)?sandboxLevelStr:DEFAULT_SANDBOX_LEVEL;if(sandboxLevel===SandboxLevel.CLOSE){return"string"==typeof serviceSource?new RawSource(serviceSource):serviceSource}const subPackagesStr=subPackages.map((sub=>sub.root)).join(";"),prefixParts=[],suffixParts=[];switch(prefixParts.push(`globalThis.__XHS_CACHED_SANDBOX__LEVEL__ = "${sandboxLevel}";`),sandboxLevel===SandboxLevel.STRICT&&isIndependent&&prefixParts.push(`globalThis.__XHS_CACHED_SANDBOX__ = globalThis.__XHS_CACHED_SANDBOX__ || (${null===(_e=sanbox_1.getXHSSandBox.toString())||void 0===_e?void 0:_e.replace("${PKG_SLOT}",subPackagesStr)})();`),prefixParts.push(`(function(${bomVars.join(",")}) {`),sandboxLevel){case SandboxLevel.STRICT:prefixParts.push("with (this) {"),suffixParts.push("}"),suffixParts.push("}).call(globalThis.__XHS_CACHED_SANDBOX__);");break;case SandboxLevel.LOOSE:suffixParts.push("}).call(globalThis);")}return createSourceWrapper(prefixParts.join("\n"),serviceSource,suffixParts.join("\n"))}const SERVICE_ASSET_NAME_V1="v1/service.js",SERVICE_ASSET_NAME_V2="v2/service.js",SERVICE_ASSET_NAME_RUNTIME="runtime.js",SERVICE_ASSET_NAME_RUNTIME_MAP="runtime.js.map",SERVICE_ASSET_NAME_COMMON_V1="service-common-v1.js",SERVICE_ASSET_NAME_COMMON_V1_MAP="service-common-v1.js.map",SERVICE_ASSET_NAME_COMMON_V2="service-common-v2.js",SERVICE_ASSET_NAME_COMMON_V2_MAP="service-common-v2.js.map";exports.default=class ServiceChunkPlugin{constructor(options){this.options=options}apply(compiler){compiler.hooks.compilation.tap("ServiceChunkPlugin",(compilation=>{compilation.hooks.processAssets.tap({name:"ServiceChunkPlugin"},(()=>{var _a;const{project:project,packSetting:packSetting}=this.options,wrappedRuntimeSource=wrapCodeWithGlobalCheck(null===(_a=compilation.getAsset("runtime.js"))||void 0===_a?void 0:_a.source,"__XHS_WEBPACK_RUNTIME_REGISTERED__");packSetting.enableV1&&(this.updateMainService(compilation,wrappedRuntimeSource,packSetting,project,SERVICE_ASSET_NAME_V1,SERVICE_ASSET_NAME_COMMON_V1),this.updateIndependentService(compilation,wrappedRuntimeSource,"v1"),this.updateNonIndependentService(compilation,"v1"),compilation.deleteAsset(SERVICE_ASSET_NAME_COMMON_V1),compilation.deleteAsset(SERVICE_ASSET_NAME_COMMON_V1_MAP)),packSetting.enableV2&&(this.updateMainService(compilation,wrappedRuntimeSource,packSetting,project,SERVICE_ASSET_NAME_V2,SERVICE_ASSET_NAME_COMMON_V2),this.updateIndependentService(compilation,wrappedRuntimeSource,"v2"),this.updateNonIndependentService(compilation,"v2"),compilation.deleteAsset(SERVICE_ASSET_NAME_COMMON_V2),compilation.deleteAsset(SERVICE_ASSET_NAME_COMMON_V2_MAP)),compilation.deleteAsset(SERVICE_ASSET_NAME_RUNTIME),compilation.deleteAsset(SERVICE_ASSET_NAME_RUNTIME_MAP)}))}))}updateMainService(compilation,wrappedRuntimeSource,packSetting,project,assetName,commonSourceName){var _a,_b;const serviceSource=null===(_a=compilation.getAsset(assetName))||void 0===_a?void 0:_a.source;if(!serviceSource){return}const finalSourceWithMap=adapteServiceCode(0,createBusinessCodeSource(wrappedRuntimeSource,serviceSource,0,function wrapCommonCodeWithProtection(commonSource){return commonSource?wrapCodeWithGlobalCheck(commonSource,"__XHS_COMMON_SERVICE_REGISTERED__"):null}(null===(_b=compilation.getAsset(commonSourceName))||void 0===_b?void 0:_b.source)),0,project,!0);packSetting.enableSourcemap&&validateSourceMapIntegrity(finalSourceWithMap,assetName),compilation.updateAsset(assetName,finalSourceWithMap)}updateIndependentService(compilation,wrappedRuntimeSource,type){const{project:project,packSetting:packSetting}=this.options;project.getSubPackages().filter((sub=>sub.independent)).forEach((sub=>{var _a;const servicePath=(0,xhs_mp_compiler_utils_1.unixJoin)(type,sub.root,"service.js");if(compilation.getAsset(servicePath)){const independentServiceSource=null===(_a=compilation.getAsset(servicePath))||void 0===_a?void 0:_a.source,finalIndepSourceWithMap=adapteServiceCode(0,createBusinessCodeSource(wrappedRuntimeSource,independentServiceSource),0,project,!0);packSetting.enableSourcemap&&validateSourceMapIntegrity(finalIndepSourceWithMap,servicePath),compilation.updateAsset(servicePath,finalIndepSourceWithMap)}}))}updateNonIndependentService(compilation,type){const{project:project,packSetting:packSetting}=this.options;project.getSubPackages().filter((sub=>!sub.independent)).forEach((sub=>{var _a;const servicePath=(0,xhs_mp_compiler_utils_1.unixJoin)(type,sub.root,"service.js");if(compilation.getAsset(servicePath)){const finalServiceWithMap=adapteServiceCode(0,createBusinessCodeSource(null,null===(_a=compilation.getAsset(servicePath))||void 0===_a?void 0:_a.source),0,project,!1);packSetting.enableSourcemap&&validateSourceMapIntegrity(finalServiceWithMap,servicePath),compilation.updateAsset(servicePath,finalServiceWithMap)}}))}}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-compiler-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "xhs mp command tool.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"category": "esm",
|
|
@@ -89,18 +89,18 @@
|
|
|
89
89
|
"webpack-chain": "^6.5.1",
|
|
90
90
|
"webpack-sources": "^3.2.2",
|
|
91
91
|
"xhs-mp-workerpool": "^9.2.0",
|
|
92
|
-
"xhs-mp-ml-loader": "2.
|
|
93
|
-
"xhs-mp-compiler-utils": "2.
|
|
94
|
-
"xhs-mp-pack": "2.
|
|
95
|
-
"xhs-mp-project": "2.
|
|
96
|
-
"xhs-mp-shared": "2.
|
|
97
|
-
"xhs-mp-shared-fs": "2.
|
|
98
|
-
"xhs-mp-sjs-loader": "2.
|
|
99
|
-
"xhs-mp-sketch-loader": "2.
|
|
92
|
+
"xhs-mp-ml-loader": "2.1.2",
|
|
93
|
+
"xhs-mp-compiler-utils": "2.1.2",
|
|
94
|
+
"xhs-mp-pack": "2.1.2",
|
|
95
|
+
"xhs-mp-project": "2.1.2",
|
|
96
|
+
"xhs-mp-shared": "2.1.2",
|
|
97
|
+
"xhs-mp-shared-fs": "2.1.2",
|
|
98
|
+
"xhs-mp-sjs-loader": "2.1.2",
|
|
99
|
+
"xhs-mp-sketch-loader": "2.1.2",
|
|
100
100
|
"yauzl": "^2.10.0"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
|
-
"xhs-mp-ml-parser": "2.
|
|
103
|
+
"xhs-mp-ml-parser": "2.1.2"
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@types/babel__generator": "7.6.3",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@types/node": "14",
|
|
124
124
|
"typescript": "5.1.6",
|
|
125
125
|
"webpack-dev-server": "4.0.0-beta.3",
|
|
126
|
-
"xhs-mp-ml-parser": "2.
|
|
126
|
+
"xhs-mp-ml-parser": "2.1.2"
|
|
127
127
|
},
|
|
128
128
|
"scripts": {
|
|
129
129
|
"version": "formula changelog && git add .",
|