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.
Files changed (118) hide show
  1. package/dist/bin/xhs-mp-cli-build.d.ts +2 -0
  2. package/dist/bin/xhs-mp-cli-build.js +40 -0
  3. package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
  4. package/dist/bin/xhs-mp-cli-dev.js +59 -0
  5. package/dist/bin/xhs-mp-cli.d.ts +2 -0
  6. package/dist/bin/xhs-mp-cli.js +16 -0
  7. package/dist/compiler.d.ts +76 -0
  8. package/dist/compiler.js +361 -0
  9. package/dist/compilerCP.d.ts +1 -0
  10. package/dist/compilerCP.js +175 -0
  11. package/dist/config/constant.config.d.ts +27 -0
  12. package/dist/config/constant.config.js +30 -0
  13. package/dist/config/dir.config.d.ts +3 -0
  14. package/dist/config/dir.config.js +16 -0
  15. package/dist/index.d.ts +84 -0
  16. package/dist/index.js +454 -0
  17. package/dist/packs/index.d.ts +14 -0
  18. package/dist/packs/index.js +31 -0
  19. package/dist/packs/mp-pack/index.d.ts +3 -0
  20. package/dist/packs/mp-pack/index.js +32 -0
  21. package/dist/packs/webpack/dev-server/index.d.ts +3 -0
  22. package/dist/packs/webpack/dev-server/index.js +64 -0
  23. package/dist/packs/webpack/dev-server/lib/ensurePort.d.ts +2 -0
  24. package/dist/packs/webpack/dev-server/lib/ensurePort.js +32 -0
  25. package/dist/packs/webpack/dev-server/lib/openBrowser.d.ts +2 -0
  26. package/dist/packs/webpack/dev-server/lib/openBrowser.js +23 -0
  27. package/dist/packs/webpack/dev-server/lib/openChrome.applescript +78 -0
  28. package/dist/packs/webpack/index.d.ts +3 -0
  29. package/dist/packs/webpack/index.js +92 -0
  30. package/dist/packs/webpack/webpack.d.ts +21 -0
  31. package/dist/packs/webpack/webpack.js +79 -0
  32. package/dist/presets/babel.d.ts +8 -0
  33. package/dist/presets/babel.js +59 -0
  34. package/dist/presets/common.d.ts +4 -0
  35. package/dist/presets/common.js +48 -0
  36. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +10 -0
  37. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +46 -0
  38. package/dist/presets/configs/minigame/assets/index.d.ts +3 -0
  39. package/dist/presets/configs/minigame/assets/index.js +65 -0
  40. package/dist/presets/configs/minigame/service/index.d.ts +3 -0
  41. package/dist/presets/configs/minigame/service/index.js +34 -0
  42. package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +8 -0
  43. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +35 -0
  44. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +9 -0
  45. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -0
  46. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +10 -0
  47. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +32 -0
  48. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +12 -0
  49. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +132 -0
  50. package/dist/presets/configs/miniprogram/assets/index.d.ts +4 -0
  51. package/dist/presets/configs/miniprogram/assets/index.js +47 -0
  52. package/dist/presets/configs/miniprogram/render/component.d.ts +3 -0
  53. package/dist/presets/configs/miniprogram/render/component.js +47 -0
  54. package/dist/presets/configs/miniprogram/render/index.d.ts +5 -0
  55. package/dist/presets/configs/miniprogram/render/index.js +71 -0
  56. package/dist/presets/configs/miniprogram/render/render.d.ts +3 -0
  57. package/dist/presets/configs/miniprogram/render/render.js +49 -0
  58. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +8 -0
  59. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +55 -0
  60. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
  61. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +163 -0
  62. package/dist/presets/configs/miniprogram/service/index.d.ts +5 -0
  63. package/dist/presets/configs/miniprogram/service/index.js +72 -0
  64. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +8 -0
  65. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +66 -0
  66. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +9 -0
  67. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +65 -0
  68. package/dist/presets/index.d.ts +2 -0
  69. package/dist/presets/index.js +95 -0
  70. package/dist/presets/loaders/mg-entry-loader.d.ts +1 -0
  71. package/dist/presets/loaders/mg-entry-loader.js +27 -0
  72. package/dist/presets/loaders/mini-style-loader.d.ts +1 -0
  73. package/dist/presets/loaders/mini-style-loader.js +72 -0
  74. package/dist/presets/loaders/mp-entry-loader.d.ts +1 -0
  75. package/dist/presets/loaders/mp-entry-loader.js +196 -0
  76. package/dist/presets/loaders/sjs-loader/index.d.ts +12 -0
  77. package/dist/presets/loaders/sjs-loader/index.js +605 -0
  78. package/dist/presets/loaders/sjs-loader/scope.d.ts +36 -0
  79. package/dist/presets/loaders/sjs-loader/scope.js +122 -0
  80. package/dist/presets/loaders/sjs-loader/tranform.d.ts +2 -0
  81. package/dist/presets/loaders/sjs-loader/tranform.js +31 -0
  82. package/dist/presets/loaders/wxss-loader.d.ts +1 -0
  83. package/dist/presets/loaders/wxss-loader.js +77 -0
  84. package/dist/presets/plugins/InjectorPlugin.d.ts +7 -0
  85. package/dist/presets/plugins/InjectorPlugin.js +14 -0
  86. package/dist/presets/prod.d.ts +4 -0
  87. package/dist/presets/prod.js +80 -0
  88. package/dist/types/index.d.ts +118 -0
  89. package/dist/types/index.js +13 -0
  90. package/dist/utils/asyncWebpack.d.ts +3 -0
  91. package/dist/utils/asyncWebpack.js +38 -0
  92. package/dist/utils/common.d.ts +8 -0
  93. package/dist/utils/common.js +36 -0
  94. package/dist/utils/const.d.ts +27 -0
  95. package/dist/utils/const.js +47 -0
  96. package/dist/utils/css.d.ts +2 -0
  97. package/dist/utils/css.js +41 -0
  98. package/dist/utils/depenedHelper.d.ts +31 -0
  99. package/dist/utils/depenedHelper.js +89 -0
  100. package/dist/utils/file.d.ts +2 -0
  101. package/dist/utils/file.js +67 -0
  102. package/dist/utils/getSuffixName.d.ts +3 -0
  103. package/dist/utils/getSuffixName.js +18 -0
  104. package/dist/utils/loader-utils.d.ts +15 -0
  105. package/dist/utils/loader-utils.js +59 -0
  106. package/dist/utils/postcssRpx2Vw.d.ts +12 -0
  107. package/dist/utils/postcssRpx2Vw.js +35 -0
  108. package/dist/utils/project.d.ts +27 -0
  109. package/dist/utils/project.js +164 -0
  110. package/dist/utils/projectConfig.d.ts +1 -0
  111. package/dist/utils/projectConfig.js +20 -0
  112. package/dist/utils/tagTransformMap.d.ts +35 -0
  113. package/dist/utils/tagTransformMap.js +38 -0
  114. package/dist/utils/utils.d.ts +7 -0
  115. package/dist/utils/utils.js +50 -0
  116. package/dist/utils/zip.d.ts +28 -0
  117. package/dist/utils/zip.js +287 -0
  118. package/package.json +6 -6
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const packs_1 = require("./packs");
13
+ let globalConfig = JSON.parse(process.argv[2]);
14
+ let hadWatchBuilt = false;
15
+ let projectCompiler;
16
+ /* 发送消息给父进程 */
17
+ const sendToMaster = (method, data = {}) => {
18
+ var _a;
19
+ (_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, JSON.stringify(Object.assign({ method }, data)));
20
+ };
21
+ const tryGC = () => {
22
+ if (global.gc) {
23
+ global.gc();
24
+ }
25
+ };
26
+ function formatWebpackMessages(err, stats) {
27
+ if (err) {
28
+ return { errors: [err.message], warnings: [] };
29
+ }
30
+ const json = stats.toJson({ warnings: true, errors: true, all: false });
31
+ const formattedErrors = json.errors.map(item => item.message);
32
+ const formattedWarnings = json.warnings.map(item => item.message);
33
+ const result = { errors: formattedErrors, warnings: formattedWarnings };
34
+ return result;
35
+ }
36
+ const handlers = {
37
+ runWatch: (msg) => __awaiter(void 0, void 0, void 0, function* () {
38
+ const { uuid, data } = msg;
39
+ if (!projectCompiler) {
40
+ projectCompiler = (0, packs_1.createCompiler)(data);
41
+ }
42
+ sendToMaster('run watch start');
43
+ const { err, stats } = (yield projectCompiler.watch({
44
+ scene: data.scene
45
+ }, (err, stats) => {
46
+ var _a;
47
+ console.log('file change...');
48
+ // 修改文件时构建
49
+ const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
50
+ if (hasError) {
51
+ sendToMaster('emitCompileStats', {
52
+ stats: formatWebpackMessages(err, stats)
53
+ });
54
+ return;
55
+ }
56
+ sendToMaster('compileFinishWhenFileChange');
57
+ }));
58
+ console.log('it is watching...');
59
+ const hasError = err || stats.hasErrors();
60
+ if (hasError) {
61
+ sendToMaster('callback', {
62
+ uuid,
63
+ success: false,
64
+ stats: formatWebpackMessages(err, stats)
65
+ });
66
+ }
67
+ else {
68
+ hadWatchBuilt = true;
69
+ sendToMaster('callback', {
70
+ uuid,
71
+ success: true
72
+ });
73
+ }
74
+ }),
75
+ changeCompileOptions(msg) {
76
+ const { data } = msg;
77
+ projectCompiler === null || projectCompiler === void 0 ? void 0 : projectCompiler.changeCompileOptions(data);
78
+ },
79
+ activatePkgs: (msg) => __awaiter(void 0, void 0, void 0, function* () {
80
+ var _a, _b, _c;
81
+ const { uuid, data: { compilePkgs } } = msg;
82
+ console.log('run activate start', compilePkgs);
83
+ const { err, stats } = (yield ((_b = (_a = projectCompiler).activatePkgs) === null || _b === void 0 ? void 0 : _b.call(_a, compilePkgs)));
84
+ console.log('run activate finish', err, stats);
85
+ const hasError = err || ((_c = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _c === void 0 ? void 0 : _c.call(stats));
86
+ if (hasError) {
87
+ sendToMaster('callback', {
88
+ uuid,
89
+ success: false,
90
+ stats: formatWebpackMessages(err, stats)
91
+ });
92
+ }
93
+ else {
94
+ hadWatchBuilt = true;
95
+ sendToMaster('callback', {
96
+ uuid,
97
+ success: true
98
+ });
99
+ }
100
+ }),
101
+ runBuild: msg => {
102
+ console.log('sp run build', msg);
103
+ const { uuid, data } = msg;
104
+ if (!projectCompiler) {
105
+ projectCompiler = (0, packs_1.createCompiler)(data);
106
+ }
107
+ projectCompiler.on('progress', progress => {
108
+ sendToMaster('compilePercent', {
109
+ percentage: progress
110
+ });
111
+ });
112
+ projectCompiler.build((err, stats) => {
113
+ var _a;
114
+ const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
115
+ console.log('sp run build finish', stats);
116
+ if (hasError) {
117
+ const statsInfo = formatWebpackMessages(err, stats);
118
+ sendToMaster('callback', {
119
+ uuid,
120
+ success: false,
121
+ stats: statsInfo
122
+ });
123
+ return;
124
+ }
125
+ sendToMaster('callback', {
126
+ uuid,
127
+ success: true
128
+ });
129
+ tryGC();
130
+ });
131
+ },
132
+ runTask: (msg) => {
133
+ if (msg) {
134
+ globalConfig = Object.assign(Object.assign({}, globalConfig), msg);
135
+ }
136
+ const { uuid, data } = globalConfig;
137
+ if (data.action === 'dev') {
138
+ handlers.runWatch({ uuid, data });
139
+ }
140
+ else {
141
+ handlers.runBuild({ uuid, data });
142
+ }
143
+ },
144
+ close() {
145
+ var _a;
146
+ console.log('close');
147
+ (_a = projectCompiler === null || projectCompiler === void 0 ? void 0 : projectCompiler.close) === null || _a === void 0 ? void 0 : _a.call(projectCompiler, () => { });
148
+ projectCompiler = null;
149
+ }
150
+ };
151
+ process.on('message', (message) => {
152
+ let objData = {};
153
+ try {
154
+ objData = JSON.parse(message);
155
+ }
156
+ catch (error) {
157
+ // do something
158
+ }
159
+ const { uuid, method, data = {} } = objData;
160
+ if (!handlers[method]) {
161
+ return;
162
+ }
163
+ handlers[method](objData);
164
+ });
165
+ process.on('uncaughtException', error => {
166
+ console.error(error);
167
+ sendToMaster('emitCompileStats', {
168
+ stats: {
169
+ errors: [error.message]
170
+ }
171
+ });
172
+ });
173
+ process.on('disconnect', () => {
174
+ process.exit(-1);
175
+ });
@@ -0,0 +1,27 @@
1
+ export declare const MAIN_PKG_ROOT = "xhs-main";
2
+ export declare const COMPILER_TYPE: {
3
+ dev: string;
4
+ build: string;
5
+ legacy_dev: string;
6
+ legacy_build: string;
7
+ };
8
+ export declare const COMPILE_TYPE: {
9
+ mp: string;
10
+ component: string;
11
+ service: string;
12
+ render: string;
13
+ };
14
+ export declare const COMPILE_ENTRY: {
15
+ simulator: string;
16
+ preview: string;
17
+ remotedebug: string;
18
+ upload: string;
19
+ };
20
+ export declare const MiniMode: {
21
+ miniprogram: string;
22
+ minigame: string;
23
+ };
24
+ export declare const PKG_ROOT_SEP = "_XHSPKG_";
25
+ export declare const COMPILE_FULL_PKG = "xhs-full";
26
+ export declare const COMPILE_MAIN_PKG = "xhs-main";
27
+ export declare const COMPILE_SUB_PKG = "xhs-sub";
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COMPILE_SUB_PKG = exports.COMPILE_MAIN_PKG = exports.COMPILE_FULL_PKG = exports.PKG_ROOT_SEP = exports.MiniMode = exports.COMPILE_ENTRY = exports.COMPILE_TYPE = exports.COMPILER_TYPE = exports.MAIN_PKG_ROOT = void 0;
4
+ exports.MAIN_PKG_ROOT = 'xhs-main';
5
+ exports.COMPILER_TYPE = {
6
+ dev: 'dev',
7
+ build: 'build',
8
+ legacy_dev: 'legacy_dev',
9
+ legacy_build: 'legacy_build'
10
+ };
11
+ exports.COMPILE_TYPE = {
12
+ mp: 'mp',
13
+ component: 'component',
14
+ service: 'service',
15
+ render: 'render'
16
+ };
17
+ exports.COMPILE_ENTRY = {
18
+ simulator: 'simulator',
19
+ preview: 'preview',
20
+ remotedebug: 'remotedebug',
21
+ upload: 'upload'
22
+ };
23
+ exports.MiniMode = {
24
+ miniprogram: 'miniprogram',
25
+ minigame: 'minigame'
26
+ };
27
+ exports.PKG_ROOT_SEP = '_XHSPKG_';
28
+ exports.COMPILE_FULL_PKG = 'xhs-full';
29
+ exports.COMPILE_MAIN_PKG = 'xhs-main';
30
+ exports.COMPILE_SUB_PKG = 'xhs-sub';
@@ -0,0 +1,3 @@
1
+ export declare const baseDirPath: any;
2
+ export declare const mpCompileDirPath: any;
3
+ export declare const mpCompileCachePath: any;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.mpCompileCachePath = exports.mpCompileDirPath = exports.baseDirPath = void 0;
7
+ const utils_1 = require("../utils/utils");
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const os_1 = __importDefault(require("os"));
11
+ exports.baseDirPath = (0, utils_1.normalizePath)(path_1.default.join(os_1.default.tmpdir(), '@xhs-toolkit'));
12
+ fs_extra_1.default.ensureDirSync(exports.baseDirPath);
13
+ exports.mpCompileDirPath = (0, utils_1.normalizePath)(path_1.default.join(exports.baseDirPath, 'xhs-mp-baba'));
14
+ fs_extra_1.default.ensureDirSync(exports.mpCompileDirPath);
15
+ exports.mpCompileCachePath = (0, utils_1.normalizePath)(path_1.default.join(exports.baseDirPath, 'xhs-compile-cache'));
16
+ fs_extra_1.default.ensureDirSync(exports.mpCompileCachePath);
@@ -0,0 +1,84 @@
1
+ /// <reference types="node/events" />
2
+ import { COMPILE_ENTRY } from './config/constant.config';
3
+ import { Project } from 'xhs-mp-project';
4
+ import EventEmitter from 'events';
5
+ import { Logger } from 'xhs-mp-utils';
6
+ import { getProcessCompilerClass } from './compiler';
7
+ interface ILibFeatures {
8
+ supportV2?: boolean;
9
+ supportVdom?: boolean;
10
+ }
11
+ export { COMPILE_ENTRY, getProcessCompilerClass };
12
+ export type ICompileOpts = {
13
+ logger?: any;
14
+ compileDir?: string;
15
+ nodeJsPath?: string;
16
+ mpDevJsonPath?: string;
17
+ libFeatures?: ILibFeatures;
18
+ };
19
+ export type ICompilerProps = ({
20
+ projectPath: string;
21
+ } | {
22
+ project: Project;
23
+ }) & ICompileOpts;
24
+ interface ICompileBaseConfig {
25
+ compressJs: boolean;
26
+ enableSourcemap: boolean;
27
+ enableV2: boolean;
28
+ enableV1: boolean;
29
+ enableVDom: boolean;
30
+ }
31
+ type IMakePkgsReadyConfig = ICompileBaseConfig & {
32
+ compilePkgs: any;
33
+ };
34
+ type ICompilePkgsConfig = ICompileBaseConfig & {
35
+ compilePkgs: any;
36
+ };
37
+ type ICompileBuildConfig = ICompileBaseConfig & {
38
+ entryType: string;
39
+ };
40
+ export interface ICompileAndZipOptions {
41
+ entryType: string;
42
+ can_upload_ext_json?: boolean;
43
+ upload_app_id?: string;
44
+ pkgInfo?: {
45
+ version: string;
46
+ };
47
+ }
48
+ export interface ISubPackages {
49
+ root: string;
50
+ pages: string;
51
+ }
52
+ export declare class Compiler extends EventEmitter {
53
+ projectPath: string;
54
+ compilerProps: ICompilerProps;
55
+ project: Project;
56
+ compilerImplMap: {};
57
+ logger: Logger;
58
+ constructor(props: ICompilerProps);
59
+ createProject(props: any): any;
60
+ private getCompilerDir;
61
+ private initSimulatorCompiler;
62
+ private initBuildCompiler;
63
+ getUsingPackageType(entryType?: string): Promise<{
64
+ enableV1: boolean;
65
+ enableV2: boolean;
66
+ enableVDom: boolean;
67
+ }>;
68
+ private getCompilerType;
69
+ getDistDir(entryType?: string): string;
70
+ removeDistDir(entryType?: string): void;
71
+ getCacheDir(entryType?: string): string;
72
+ removeCacheDir(entryType?: string): void;
73
+ private createCompilerImpl;
74
+ private getComilerImpl;
75
+ makePkgsReady(config: IMakePkgsReadyConfig): Promise<void>;
76
+ reCompilePkgs(config: ICompilePkgsConfig): Promise<void>;
77
+ compileProject(config: ICompileBuildConfig): Promise<void>;
78
+ compileAndZip(opts: ICompileAndZipOptions): Promise<any>;
79
+ private zipWithFullPackageWithAppId;
80
+ private zipWithFullPackage;
81
+ private zipWithSubPackage;
82
+ close(entryType?: string): void;
83
+ kill(entryType?: string): void;
84
+ }