@weapp-core/init 6.0.26 → 6.1.0
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/index.d.ts +0 -14
- package/dist/index.js +19 -37
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { set } from "@weapp-core/shared";
|
|
2
|
-
//#region src/types.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* @description set-value 的写入方法签名
|
|
5
4
|
*/
|
|
@@ -42,8 +41,6 @@ interface ProjectConfig {
|
|
|
42
41
|
}[];
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/context.d.ts
|
|
47
44
|
type JsonPrimitive = string | number | boolean | null;
|
|
48
45
|
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
49
46
|
interface JsonObject {
|
|
@@ -85,8 +82,6 @@ interface Context {
|
|
|
85
82
|
tsconfigNode: ContextDocument<TsConfigData>;
|
|
86
83
|
dts: ContextDocument<string>;
|
|
87
84
|
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/configFiles.d.ts
|
|
90
85
|
export declare function initViteConfigFile(options: SharedUpdateOptions): Promise<string>;
|
|
91
86
|
export declare function initTsDtsFile(options: SharedUpdateOptions): Promise<string>;
|
|
92
87
|
export declare function initTsJsonFiles(options: SharedUpdateOptions): Promise<{
|
|
@@ -163,26 +158,18 @@ export declare function initTsJsonFiles(options: SharedUpdateOptions): Promise<{
|
|
|
163
158
|
include: string[];
|
|
164
159
|
};
|
|
165
160
|
}>;
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/packageJson.d.ts
|
|
168
161
|
/**
|
|
169
162
|
* @description 创建或更新 package.json
|
|
170
163
|
*/
|
|
171
164
|
export declare function createOrUpdatePackageJson(options: UpdatePackageJsonOptions): Promise<PackageJsonData>;
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/projectConfig.d.ts
|
|
174
165
|
/**
|
|
175
166
|
* @description 创建或更新 project.config.json
|
|
176
167
|
*/
|
|
177
168
|
export declare function createOrUpdateProjectConfig(options: UpdateProjectConfigOptions): Promise<ProjectConfig>;
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region src/state.d.ts
|
|
180
169
|
/**
|
|
181
170
|
* @description 重置全局上下文
|
|
182
171
|
*/
|
|
183
172
|
export declare function resetContext(): void;
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/index.d.ts
|
|
186
173
|
/**
|
|
187
174
|
* @description 初始化项目配置(project.config、package.json、tsconfig、vite.config 等)
|
|
188
175
|
*/
|
|
@@ -190,5 +177,4 @@ export declare function initConfig(options: {
|
|
|
190
177
|
root?: string;
|
|
191
178
|
command?: 'weapp-vite';
|
|
192
179
|
}): Promise<Context>;
|
|
193
|
-
//#endregion
|
|
194
180
|
export type { Context };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import logger from "@weapp-core/logger";
|
|
|
3
3
|
import { fs } from "@weapp-core/shared/node";
|
|
4
4
|
import { defu, get, set } from "@weapp-core/shared";
|
|
5
5
|
import https from "node:https";
|
|
6
|
-
|
|
6
|
+
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
7
7
|
let _lazyMatch = () => {
|
|
8
8
|
var __lib__ = (() => {
|
|
9
9
|
var m = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, q = (r, e) => {
|
|
@@ -431,8 +431,7 @@ const _path = {
|
|
|
431
431
|
sep: "/",
|
|
432
432
|
toNamespacedPath
|
|
433
433
|
};
|
|
434
|
-
|
|
435
|
-
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
|
|
434
|
+
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
|
|
436
435
|
const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
|
|
437
436
|
const _platforms = {
|
|
438
437
|
posix: void 0,
|
|
@@ -448,8 +447,7 @@ const mix = (del = delimiter) => {
|
|
|
448
447
|
};
|
|
449
448
|
const posix = /* @__PURE__ */ mix(":");
|
|
450
449
|
const win32 = /* @__PURE__ */ mix(";");
|
|
451
|
-
|
|
452
|
-
//#region src/context.ts
|
|
450
|
+
// src/context.ts
|
|
453
451
|
function createDocument() {
|
|
454
452
|
return {
|
|
455
453
|
name: "",
|
|
@@ -473,8 +471,7 @@ function createContext() {
|
|
|
473
471
|
dts: createDocument()
|
|
474
472
|
};
|
|
475
473
|
}
|
|
476
|
-
|
|
477
|
-
//#region src/state.ts
|
|
474
|
+
// src/state.ts
|
|
478
475
|
/**
|
|
479
476
|
* @description 全局上下文(用于 init 过程中的状态存储)
|
|
480
477
|
*/
|
|
@@ -494,8 +491,7 @@ function resetContext() {
|
|
|
494
491
|
Object.assign(ctx.tsconfigNode, next.tsconfigNode);
|
|
495
492
|
Object.assign(ctx.dts, next.dts);
|
|
496
493
|
}
|
|
497
|
-
|
|
498
|
-
//#region src/tsconfigJson.ts
|
|
494
|
+
// src/tsconfigJson.ts
|
|
499
495
|
function normalizeManagedSrcRoot(srcRoot) {
|
|
500
496
|
return srcRoot === "." ? ".." : `../${srcRoot}`;
|
|
501
497
|
}
|
|
@@ -657,8 +653,7 @@ function getDefaultTsconfigServerJson() {
|
|
|
657
653
|
files: []
|
|
658
654
|
};
|
|
659
655
|
}
|
|
660
|
-
|
|
661
|
-
//#region src/tsDts.ts
|
|
656
|
+
// src/tsDts.ts
|
|
662
657
|
/**
|
|
663
658
|
* @description 生成默认的 env.d.ts 模板
|
|
664
659
|
*/
|
|
@@ -666,8 +661,7 @@ function getDefaultTsDts() {
|
|
|
666
661
|
return `/// <reference types="weapp-vite/client" />
|
|
667
662
|
`;
|
|
668
663
|
}
|
|
669
|
-
|
|
670
|
-
//#region src/utils/fs.ts
|
|
664
|
+
// src/utils/fs.ts
|
|
671
665
|
/**
|
|
672
666
|
* @description 文件读取错误
|
|
673
667
|
*/
|
|
@@ -736,8 +730,7 @@ async function writeFile(filepath, contents) {
|
|
|
736
730
|
throw new FsWriteError(filepath, error);
|
|
737
731
|
}
|
|
738
732
|
}
|
|
739
|
-
|
|
740
|
-
//#region src/utils/path.ts
|
|
733
|
+
// src/utils/path.ts
|
|
741
734
|
/**
|
|
742
735
|
* @description 根据输出目录配置解析最终输出路径
|
|
743
736
|
*/
|
|
@@ -745,8 +738,7 @@ function resolveOutputPath(root, dest, fallback) {
|
|
|
745
738
|
if (!dest) return fallback;
|
|
746
739
|
return posix.isAbsolute(dest) ? dest : posix.resolve(root, dest);
|
|
747
740
|
}
|
|
748
|
-
|
|
749
|
-
//#region src/viteConfig.ts
|
|
741
|
+
// src/viteConfig.ts
|
|
750
742
|
/**
|
|
751
743
|
* @description 生成默认的 vite.config.ts 模板
|
|
752
744
|
*/
|
|
@@ -761,8 +753,7 @@ ${srcRoot === "src" ? " // weapp-vite options" : ` srcRoot: '${srcRoot}',`
|
|
|
761
753
|
})
|
|
762
754
|
`;
|
|
763
755
|
}
|
|
764
|
-
|
|
765
|
-
//#region src/configFiles.ts
|
|
756
|
+
// src/configFiles.ts
|
|
766
757
|
async function initViteConfigFile(options) {
|
|
767
758
|
const { root, dest, write = true } = options;
|
|
768
759
|
const packageType = ctx.packageJson.value?.type ?? "module";
|
|
@@ -849,11 +840,9 @@ async function initTsJsonFiles(options) {
|
|
|
849
840
|
tsconfigNode
|
|
850
841
|
};
|
|
851
842
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
//#endregion
|
|
856
|
-
//#region src/npm.ts
|
|
843
|
+
// ../../packages/weapp-vite/package.json
|
|
844
|
+
var version = "7.7.0";
|
|
845
|
+
// src/npm.ts
|
|
857
846
|
/**
|
|
858
847
|
* @description 从 npm registry 获取包的最新版本号
|
|
859
848
|
*/
|
|
@@ -894,8 +883,7 @@ async function latestVersion(packageName, prefix = "^", fetch = getLatestVersion
|
|
|
894
883
|
return null;
|
|
895
884
|
}
|
|
896
885
|
}
|
|
897
|
-
|
|
898
|
-
//#region src/packageJson.ts
|
|
886
|
+
// src/packageJson.ts
|
|
899
887
|
const FALLBACK_DEP_VERSIONS = {
|
|
900
888
|
"miniprogram-api-typings": "^4.1.0",
|
|
901
889
|
"typescript": "^5.9.2",
|
|
@@ -970,8 +958,7 @@ async function createOrUpdatePackageJson(options) {
|
|
|
970
958
|
throw error;
|
|
971
959
|
}
|
|
972
960
|
}
|
|
973
|
-
|
|
974
|
-
//#region src/projectConfig.ts
|
|
961
|
+
// src/projectConfig.ts
|
|
975
962
|
function applyProjectConfigDefaults(projectConfig) {
|
|
976
963
|
set(projectConfig, "miniprogramRoot", "dist/");
|
|
977
964
|
set(projectConfig, "srcMiniprogramRoot", "dist/");
|
|
@@ -1057,8 +1044,7 @@ async function createOrUpdateProjectConfig(options) {
|
|
|
1057
1044
|
throw error;
|
|
1058
1045
|
}
|
|
1059
1046
|
}
|
|
1060
|
-
|
|
1061
|
-
//#region src/projectLayout.ts
|
|
1047
|
+
// src/projectLayout.ts
|
|
1062
1048
|
const TRAILING_SLASH_RE = /\/+$/u;
|
|
1063
1049
|
const LEADING_DOT_SLASH_RE = /^\.\//u;
|
|
1064
1050
|
function normalizeRelativeDir(value) {
|
|
@@ -1088,8 +1074,7 @@ async function resolveProjectSrcRoot(root, projectConfig) {
|
|
|
1088
1074
|
for (const candidate of candidates) if (await hasAppJson(root, candidate)) return candidate;
|
|
1089
1075
|
return "src";
|
|
1090
1076
|
}
|
|
1091
|
-
|
|
1092
|
-
//#region src/gitignore.ts
|
|
1077
|
+
// src/gitignore.ts
|
|
1093
1078
|
const DEFAULT_GITIGNORE = `# dependencies
|
|
1094
1079
|
node_modules
|
|
1095
1080
|
.pnp
|
|
@@ -1162,8 +1147,7 @@ function mergeGitignore(existing) {
|
|
|
1162
1147
|
}
|
|
1163
1148
|
return ensureTrailingNewline(trimTrailingBlankLines(merged).join("\n"));
|
|
1164
1149
|
}
|
|
1165
|
-
|
|
1166
|
-
//#region src/updateGitignore.ts
|
|
1150
|
+
// src/updateGitignore.ts
|
|
1167
1151
|
async function updateGitIgnore(options) {
|
|
1168
1152
|
const { root, dest, write = true } = options;
|
|
1169
1153
|
const outputPath = resolveOutputPath(root, dest, posix.resolve(root, ".gitignore"));
|
|
@@ -1175,8 +1159,7 @@ async function updateGitIgnore(options) {
|
|
|
1175
1159
|
}
|
|
1176
1160
|
return merged;
|
|
1177
1161
|
}
|
|
1178
|
-
|
|
1179
|
-
//#region src/index.ts
|
|
1162
|
+
// src/index.ts
|
|
1180
1163
|
/**
|
|
1181
1164
|
* @description 初始化项目配置(project.config、package.json、tsconfig、vite.config 等)
|
|
1182
1165
|
*/
|
|
@@ -1196,5 +1179,4 @@ async function initConfig(options) {
|
|
|
1196
1179
|
}
|
|
1197
1180
|
return ctx;
|
|
1198
1181
|
}
|
|
1199
|
-
//#endregion
|
|
1200
1182
|
export { createOrUpdatePackageJson, createOrUpdateProjectConfig, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, resetContext };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/init",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.0
|
|
4
|
+
"version": "6.1.0",
|
|
5
5
|
"description": "Project initialization utilities for weapp-vite mini-program applications.",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
46
|
"engines": {
|
|
47
|
-
"node": "^
|
|
47
|
+
"node": "^22.23.4 || ^24.22.1 || >=26.12.1"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public",
|
|
51
51
|
"registry": "https://registry.npmjs.org"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@weapp-core/logger": "3.
|
|
55
|
-
"@weapp-core/shared": "3.
|
|
54
|
+
"@weapp-core/logger": "3.2.0",
|
|
55
|
+
"@weapp-core/shared": "3.4.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"dev": "tsdown -w --sourcemap",
|