xhs-mp-compiler-cli 1.1.2 → 1.1.3
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/package.json +2 -2
- package/dist/bin/xhs-mp-cli-build.d.ts +0 -2
- package/dist/bin/xhs-mp-cli-build.js +0 -40
- package/dist/bin/xhs-mp-cli-dev.d.ts +0 -2
- package/dist/bin/xhs-mp-cli-dev.js +0 -59
- package/dist/bin/xhs-mp-cli.d.ts +0 -2
- package/dist/bin/xhs-mp-cli.js +0 -16
- package/dist/compiler.d.ts +0 -76
- package/dist/compiler.js +0 -361
- package/dist/compilerCP.d.ts +0 -1
- package/dist/compilerCP.js +0 -175
- package/dist/config/constant.config.d.ts +0 -27
- package/dist/config/constant.config.js +0 -30
- package/dist/config/dir.config.d.ts +0 -3
- package/dist/config/dir.config.js +0 -16
- package/dist/index.d.ts +0 -84
- package/dist/index.js +0 -454
- package/dist/packs/index.d.ts +0 -14
- package/dist/packs/index.js +0 -31
- package/dist/packs/mp-pack/index.d.ts +0 -3
- package/dist/packs/mp-pack/index.js +0 -32
- package/dist/packs/webpack/dev-server/index.d.ts +0 -3
- package/dist/packs/webpack/dev-server/index.js +0 -64
- package/dist/packs/webpack/dev-server/lib/ensurePort.d.ts +0 -2
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +0 -32
- package/dist/packs/webpack/dev-server/lib/openBrowser.d.ts +0 -2
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +0 -23
- package/dist/packs/webpack/dev-server/lib/openChrome.applescript +0 -78
- package/dist/packs/webpack/index.d.ts +0 -3
- package/dist/packs/webpack/index.js +0 -92
- package/dist/packs/webpack/webpack.d.ts +0 -21
- package/dist/packs/webpack/webpack.js +0 -79
- package/dist/presets/babel.d.ts +0 -8
- package/dist/presets/babel.js +0 -59
- package/dist/presets/common.d.ts +0 -4
- package/dist/presets/common.js +0 -48
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +0 -10
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +0 -46
- package/dist/presets/configs/minigame/assets/index.d.ts +0 -3
- package/dist/presets/configs/minigame/assets/index.js +0 -65
- package/dist/presets/configs/minigame/service/index.d.ts +0 -3
- package/dist/presets/configs/minigame/service/index.js +0 -34
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +0 -8
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +0 -35
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +0 -9
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +0 -69
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +0 -10
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +0 -32
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +0 -12
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +0 -132
- package/dist/presets/configs/miniprogram/assets/index.d.ts +0 -4
- package/dist/presets/configs/miniprogram/assets/index.js +0 -47
- package/dist/presets/configs/miniprogram/render/component.d.ts +0 -3
- package/dist/presets/configs/miniprogram/render/component.js +0 -47
- package/dist/presets/configs/miniprogram/render/index.d.ts +0 -5
- package/dist/presets/configs/miniprogram/render/index.js +0 -71
- package/dist/presets/configs/miniprogram/render/render.d.ts +0 -3
- package/dist/presets/configs/miniprogram/render/render.js +0 -49
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +0 -8
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +0 -55
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +0 -15
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +0 -163
- package/dist/presets/configs/miniprogram/service/index.d.ts +0 -5
- package/dist/presets/configs/miniprogram/service/index.js +0 -72
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +0 -8
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +0 -66
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +0 -9
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +0 -65
- package/dist/presets/index.d.ts +0 -2
- package/dist/presets/index.js +0 -95
- package/dist/presets/loaders/mg-entry-loader.d.ts +0 -1
- package/dist/presets/loaders/mg-entry-loader.js +0 -27
- package/dist/presets/loaders/mini-style-loader.d.ts +0 -1
- package/dist/presets/loaders/mini-style-loader.js +0 -72
- package/dist/presets/loaders/mp-entry-loader.d.ts +0 -1
- package/dist/presets/loaders/mp-entry-loader.js +0 -196
- package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
- package/dist/presets/loaders/sjs-loader/index.js +0 -605
- package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
- package/dist/presets/loaders/sjs-loader/scope.js +0 -122
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
- package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
- package/dist/presets/loaders/wxss-loader.d.ts +0 -1
- package/dist/presets/loaders/wxss-loader.js +0 -77
- package/dist/presets/plugins/InjectorPlugin.d.ts +0 -7
- package/dist/presets/plugins/InjectorPlugin.js +0 -14
- package/dist/presets/prod.d.ts +0 -4
- package/dist/presets/prod.js +0 -80
- package/dist/types/index.d.ts +0 -118
- package/dist/types/index.js +0 -13
- package/dist/utils/asyncWebpack.d.ts +0 -3
- package/dist/utils/asyncWebpack.js +0 -38
- package/dist/utils/common.d.ts +0 -8
- package/dist/utils/common.js +0 -36
- package/dist/utils/const.d.ts +0 -27
- package/dist/utils/const.js +0 -47
- package/dist/utils/css.d.ts +0 -2
- package/dist/utils/css.js +0 -41
- package/dist/utils/depenedHelper.d.ts +0 -31
- package/dist/utils/depenedHelper.js +0 -89
- package/dist/utils/file.d.ts +0 -2
- package/dist/utils/file.js +0 -67
- package/dist/utils/getSuffixName.d.ts +0 -3
- package/dist/utils/getSuffixName.js +0 -18
- package/dist/utils/loader-utils.d.ts +0 -15
- package/dist/utils/loader-utils.js +0 -59
- package/dist/utils/postcssRpx2Vw.d.ts +0 -12
- package/dist/utils/postcssRpx2Vw.js +0 -35
- package/dist/utils/project.d.ts +0 -27
- package/dist/utils/project.js +0 -164
- package/dist/utils/projectConfig.d.ts +0 -1
- package/dist/utils/projectConfig.js +0 -20
- package/dist/utils/tagTransformMap.d.ts +0 -35
- package/dist/utils/tagTransformMap.js +0 -38
- package/dist/utils/utils.d.ts +0 -7
- package/dist/utils/utils.js +0 -50
- package/dist/utils/zip.d.ts +0 -28
- package/dist/utils/zip.js +0 -287
|
@@ -1,196 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
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;
|