xhs-mp-compiler-cli 1.1.3 → 1.1.4
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.
- package/dist/bin/xhs-mp-cli-build.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +40 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +59 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/compiler.d.ts +76 -0
- package/dist/compiler.js +361 -0
- package/dist/compilerCP.d.ts +1 -0
- package/dist/compilerCP.js +175 -0
- package/dist/config/constant.config.d.ts +27 -0
- package/dist/config/constant.config.js +30 -0
- package/dist/config/dir.config.d.ts +3 -0
- package/dist/config/dir.config.js +16 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +454 -0
- package/dist/packs/index.d.ts +14 -0
- package/dist/packs/index.js +31 -0
- package/dist/packs/mp-pack/index.d.ts +3 -0
- package/dist/packs/mp-pack/index.js +32 -0
- package/dist/packs/webpack/dev-server/index.d.ts +3 -0
- package/dist/packs/webpack/dev-server/index.js +64 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +32 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +23 -0
- package/dist/packs/webpack/dev-server/lib/openChrome.applescript +78 -0
- package/dist/packs/webpack/index.d.ts +3 -0
- package/dist/packs/webpack/index.js +92 -0
- package/dist/packs/webpack/webpack.d.ts +21 -0
- package/dist/packs/webpack/webpack.js +79 -0
- package/dist/presets/babel.d.ts +8 -0
- package/dist/presets/babel.js +59 -0
- package/dist/presets/common.d.ts +4 -0
- package/dist/presets/common.js +48 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +46 -0
- package/dist/presets/configs/minigame/assets/index.d.ts +3 -0
- package/dist/presets/configs/minigame/assets/index.js +65 -0
- package/dist/presets/configs/minigame/service/index.d.ts +3 -0
- package/dist/presets/configs/minigame/service/index.js +34 -0
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +35 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -0
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +32 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +12 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +132 -0
- package/dist/presets/configs/miniprogram/assets/index.d.ts +4 -0
- package/dist/presets/configs/miniprogram/assets/index.js +47 -0
- package/dist/presets/configs/miniprogram/render/component.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/component.js +47 -0
- package/dist/presets/configs/miniprogram/render/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/render/index.js +71 -0
- package/dist/presets/configs/miniprogram/render/render.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/render.js +49 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +8 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +55 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +163 -0
- package/dist/presets/configs/miniprogram/service/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/service/index.js +72 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +66 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +65 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.js +95 -0
- package/dist/presets/loaders/mg-entry-loader.d.ts +1 -0
- package/dist/presets/loaders/mg-entry-loader.js +27 -0
- package/dist/presets/loaders/mini-style-loader.d.ts +1 -0
- package/dist/presets/loaders/mini-style-loader.js +72 -0
- package/dist/presets/loaders/mp-entry-loader.d.ts +1 -0
- package/dist/presets/loaders/mp-entry-loader.js +196 -0
- package/dist/presets/loaders/sjs-loader/index.d.ts +12 -0
- package/dist/presets/loaders/sjs-loader/index.js +605 -0
- package/dist/presets/loaders/sjs-loader/scope.d.ts +36 -0
- package/dist/presets/loaders/sjs-loader/scope.js +122 -0
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +2 -0
- package/dist/presets/loaders/sjs-loader/tranform.js +31 -0
- package/dist/presets/loaders/wxss-loader.d.ts +1 -0
- package/dist/presets/loaders/wxss-loader.js +77 -0
- package/dist/presets/plugins/InjectorPlugin.d.ts +7 -0
- package/dist/presets/plugins/InjectorPlugin.js +14 -0
- package/dist/presets/prod.d.ts +4 -0
- package/dist/presets/prod.js +80 -0
- package/dist/types/index.d.ts +118 -0
- package/dist/types/index.js +13 -0
- package/dist/utils/asyncWebpack.d.ts +3 -0
- package/dist/utils/asyncWebpack.js +38 -0
- package/dist/utils/common.d.ts +8 -0
- package/dist/utils/common.js +36 -0
- package/dist/utils/const.d.ts +27 -0
- package/dist/utils/const.js +47 -0
- package/dist/utils/css.d.ts +2 -0
- package/dist/utils/css.js +41 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/file.d.ts +2 -0
- package/dist/utils/file.js +67 -0
- package/dist/utils/getSuffixName.d.ts +3 -0
- package/dist/utils/getSuffixName.js +18 -0
- package/dist/utils/loader-utils.d.ts +15 -0
- package/dist/utils/loader-utils.js +59 -0
- package/dist/utils/postcssRpx2Vw.d.ts +12 -0
- package/dist/utils/postcssRpx2Vw.js +35 -0
- package/dist/utils/project.d.ts +27 -0
- package/dist/utils/project.js +164 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/tagTransformMap.d.ts +35 -0
- package/dist/utils/tagTransformMap.js +38 -0
- package/dist/utils/utils.d.ts +7 -0
- package/dist/utils/utils.js +50 -0
- package/dist/utils/zip.d.ts +28 -0
- package/dist/utils/zip.js +287 -0
- package/package.json +6 -6
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const fs_extra_1 = __importStar(require("fs-extra"));
|
|
27
|
+
const path_1 = __importStar(require("path"));
|
|
28
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
29
|
+
const loader_utils_1 = require("../../utils/loader-utils");
|
|
30
|
+
const getSuffixName_1 = require("../../utils/getSuffixName");
|
|
31
|
+
function genComponentLoaderScript(project, context, opts) {
|
|
32
|
+
const { pkg, root, mode, compPath } = opts;
|
|
33
|
+
const { projectMiniprogramPath, jsonDependencies = [] } = project;
|
|
34
|
+
const componentsMap = project.getComponentsMap();
|
|
35
|
+
const entries = [];
|
|
36
|
+
for (const file of jsonDependencies) {
|
|
37
|
+
context.addDependency(file);
|
|
38
|
+
}
|
|
39
|
+
let name = 'XHS_COMPONENTS';
|
|
40
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
41
|
+
name = `XHS_COMPONENTS_${root}`;
|
|
42
|
+
}
|
|
43
|
+
// v2
|
|
44
|
+
if (mode === 'v2') {
|
|
45
|
+
return `
|
|
46
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
|
|
47
|
+
;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, getSuffixName_1.getMlSuffixName)()}`))}')
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
// v1和v0
|
|
51
|
+
Object.keys(componentsMap).forEach(compPath => {
|
|
52
|
+
const push = () => entries.push(`;globalThis['${name}'].default['${compPath}'] = () => require('${(0, loader_utils_1.formatPath)(path_1.default.join(projectMiniprogramPath, `${compPath}.${(0, getSuffixName_1.getMlSuffixName)()}`))}')`);
|
|
53
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
|
|
54
|
+
push();
|
|
55
|
+
}
|
|
56
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG && project.isFileInMainPkg(compPath)) {
|
|
57
|
+
push();
|
|
58
|
+
}
|
|
59
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG && compPath.startsWith(`${root}/`)) {
|
|
60
|
+
push();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return `
|
|
64
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
|
|
65
|
+
;${entries.join('\n ')}
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
const genRenderLoaderScript = (project, context, opts) => {
|
|
69
|
+
const { projectMiniprogramPath, appJSON, jsonDependencies } = project;
|
|
70
|
+
const { pkg, mode } = opts;
|
|
71
|
+
const isFull = pkg === 'full';
|
|
72
|
+
for (const file of jsonDependencies) {
|
|
73
|
+
context.addDependency(file);
|
|
74
|
+
}
|
|
75
|
+
const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
|
|
76
|
+
const appCssExist = (0, fs_extra_1.existsSync)(appCssPath);
|
|
77
|
+
const resourcePath = (0, loader_utils_1.formatPath)(context.resourcePath);
|
|
78
|
+
const path = (0, loader_utils_1.formatPath)(resourcePath.replace(`${projectMiniprogramPath}/`, '').replace(`.${(0, getSuffixName_1.getMlSuffixName)()}`, ''));
|
|
79
|
+
const subPackage = (appJSON.subPackages || []).find(subPack => !!subPack.pages.find(page => page.path === path));
|
|
80
|
+
const enableLazyCodeLoading = mode === 'v2';
|
|
81
|
+
// 资源文件
|
|
82
|
+
const resources = (0, loader_utils_1.getResourceUris)({
|
|
83
|
+
appCssExist,
|
|
84
|
+
subPackage,
|
|
85
|
+
enableLazyCodeLoading
|
|
86
|
+
});
|
|
87
|
+
// 开启了按需注入,注入依赖组件
|
|
88
|
+
if (enableLazyCodeLoading) {
|
|
89
|
+
const isIndependent = (subPackage === null || subPackage === void 0 ? void 0 : subPackage.independent) || false;
|
|
90
|
+
const dependsTree = project.getPageDependComponentPaths(path, isIndependent);
|
|
91
|
+
const subPackagesPrefix = (appJSON.subPackages || []).map(sub => sub.root);
|
|
92
|
+
const depends = [];
|
|
93
|
+
for (let i = 0; i < dependsTree.length; i++) {
|
|
94
|
+
let uri = dependsTree[i];
|
|
95
|
+
const subRoot = subPackagesPrefix.find(subRoot => uri.startsWith(`${subRoot}/`));
|
|
96
|
+
if (subRoot) {
|
|
97
|
+
uri = `${subRoot}/${uri}`;
|
|
98
|
+
}
|
|
99
|
+
depends.push(uri);
|
|
100
|
+
}
|
|
101
|
+
return `
|
|
102
|
+
import Component from '${resourcePath}';
|
|
103
|
+
globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)}, ${JSON.stringify(depends)})
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
return `
|
|
107
|
+
import Component from '${resourcePath}';
|
|
108
|
+
globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)})
|
|
109
|
+
`;
|
|
110
|
+
};
|
|
111
|
+
function genServiceLoderScript(project, context, opts) {
|
|
112
|
+
const { appJSON, legacyAppJSON, projectMiniprogramPath, jsonDependencies } = project;
|
|
113
|
+
const { pkg, root } = opts;
|
|
114
|
+
const modules = [];
|
|
115
|
+
let name = 'XHS_SERVICE';
|
|
116
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
117
|
+
name = `XHS_SERVICE_${root}`;
|
|
118
|
+
}
|
|
119
|
+
for (const file of jsonDependencies) {
|
|
120
|
+
context.addDependency(file);
|
|
121
|
+
}
|
|
122
|
+
const addAppJs = () => {
|
|
123
|
+
if (fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.js`) ||
|
|
124
|
+
fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.ts`)) {
|
|
125
|
+
modules.unshift(`;globalThis['${name}'].default['app'] = require('${(0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/app`)}')`);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
|
|
129
|
+
addAppJs();
|
|
130
|
+
for (const page of legacyAppJSON.pages) {
|
|
131
|
+
const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
|
|
132
|
+
modules.push(`;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
137
|
+
addAppJs();
|
|
138
|
+
}
|
|
139
|
+
for (const page of legacyAppJSON.pages) {
|
|
140
|
+
const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${page.path}`);
|
|
141
|
+
const content = `;globalThis['${name}'].default['${page.path}'] = () => require('${resourcePath}')`;
|
|
142
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
143
|
+
const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
144
|
+
if (subPackageRoots.every(root => !page.path.startsWith(`${root}/`))) {
|
|
145
|
+
modules.push(content);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
149
|
+
if (page.path.startsWith(`${root}/`)) {
|
|
150
|
+
modules.push(content);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
Object.keys(appJSON.componentsMap).forEach(compPath => {
|
|
156
|
+
const resourcePath = (0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/${compPath}`);
|
|
157
|
+
const content = `;globalThis['${name}'].default['${compPath}'] = () => require('${resourcePath}')`;
|
|
158
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
|
|
159
|
+
modules.push(content);
|
|
160
|
+
}
|
|
161
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.MAIN_PKG) {
|
|
162
|
+
const subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
|
|
163
|
+
if (subPackageRoots.every(root => !compPath.startsWith(`${root}/`))) {
|
|
164
|
+
modules.push(content);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (pkg === xhs_mp_pack_1.CONSTANTS.SUB_PKG) {
|
|
168
|
+
if (compPath.startsWith(`${root}/`)) {
|
|
169
|
+
modules.push(content);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const runtimeJSON = pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG ? legacyAppJSON : appJSON;
|
|
174
|
+
return `;globalThis['__MP_APP_JSON__'] = ${JSON.stringify(runtimeJSON)};
|
|
175
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} }))
|
|
176
|
+
${modules.join('\n ')}
|
|
177
|
+
`;
|
|
178
|
+
}
|
|
179
|
+
function entryLoader() {
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
const options = this.getOptions();
|
|
182
|
+
const { type } = options;
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
const handelrs = {
|
|
185
|
+
render: genRenderLoaderScript,
|
|
186
|
+
component: genComponentLoaderScript,
|
|
187
|
+
service: genServiceLoderScript
|
|
188
|
+
};
|
|
189
|
+
const handler = handelrs[type];
|
|
190
|
+
if (!handler) {
|
|
191
|
+
throw new Error(`not found loader handler of ${type}`);
|
|
192
|
+
}
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
return handler(this._compiler.project, this, options);
|
|
195
|
+
}
|
|
196
|
+
module.exports = entryLoader;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Span } from '@swc/core';
|
|
2
|
+
export declare const SJS_HELPER = "_sjs$";
|
|
3
|
+
declare function sjsCompiler(code: any, onRequire: (s: string) => string): {
|
|
4
|
+
code: string;
|
|
5
|
+
map: string | undefined;
|
|
6
|
+
legacyCode: string;
|
|
7
|
+
errors: {
|
|
8
|
+
message: string;
|
|
9
|
+
span: Span;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export default sjsCompiler;
|