@weapp-core/init 6.0.1 → 6.0.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +423 -98
  2. package/dist/index.js +926 -924
  3. package/package.json +7 -6
package/dist/index.d.ts CHANGED
@@ -1,157 +1,482 @@
1
- import { PackageJson, TSConfig } from 'pkg-types';
2
- import { set } from '@weapp-core/shared';
1
+ import { set } from "@weapp-core/shared";
3
2
 
3
+ //#region ../../node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.d.mts
4
+ type StripEnums<T extends Record<string, any>> = { [K in keyof T]: T[K] extends boolean ? T[K] : T[K] extends string ? T[K] : T[K] extends object ? T[K] : T[K] extends Array<any> ? T[K] : T[K] extends undefined ? undefined : any };
5
+ interface TSConfig {
6
+ compilerOptions?: StripEnums<CompilerOptions>;
7
+ exclude?: string[];
8
+ compileOnSave?: boolean;
9
+ extends?: string | string[];
10
+ files?: string[];
11
+ include?: string[];
12
+ typeAcquisition?: TypeAcquisition;
13
+ references?: {
14
+ path: string;
15
+ }[];
16
+ }
17
+ /**
18
+ * Defines a TSConfig structure.
19
+ * @param tsconfig - The contents of `tsconfig.json` as an object. See {@link TSConfig}.
20
+ * @returns the same `tsconfig.json` object.
21
+ */
22
+ interface PackageJson {
23
+ /**
24
+ * The name is what your thing is called.
25
+ * Some rules:
26
+ * - The name must be less than or equal to 214 characters. This includes the scope for scoped packages.
27
+ * - The name can’t start with a dot or an underscore.
28
+ * - New packages must not have uppercase letters in the name.
29
+ * - The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can’t contain any non-URL-safe characters.
30
+ */
31
+ name?: string;
32
+ /**
33
+ * Version must be parseable by `node-semver`, which is bundled with npm as a dependency. (`npm install semver` to use it yourself.)
34
+ */
35
+ version?: string;
36
+ /**
37
+ * Put a description in it. It’s a string. This helps people discover your package, as it’s listed in `npm search`.
38
+ */
39
+ description?: string;
40
+ /**
41
+ * Put keywords in it. It’s an array of strings. This helps people discover your package as it’s listed in `npm search`.
42
+ */
43
+ keywords?: string[];
44
+ /**
45
+ * The url to the project homepage.
46
+ */
47
+ homepage?: string;
48
+ /**
49
+ * The url to your project’s issue tracker and / or the email address to which issues should be reported. These are helpful for people who encounter issues with your package.
50
+ */
51
+ bugs?: string | {
52
+ url?: string;
53
+ email?: string;
54
+ };
55
+ /**
56
+ * You should specify a license for your package so that people know how they are permitted to use it, and any restrictions you’re placing on it.
57
+ */
58
+ license?: string;
59
+ /**
60
+ * Specify the place where your code lives. This is helpful for people who want to contribute. If the git repo is on GitHub, then the `npm docs` command will be able to find you.
61
+ * For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same shortcut syntax you use for npm install:
62
+ */
63
+ repository?: string | {
64
+ type: string;
65
+ url: string;
66
+ /**
67
+ * If the `package.json` for your package is not in the root directory (for example if it is part of a monorepo), you can specify the directory in which it lives:
68
+ */
69
+ directory?: string;
70
+ };
71
+ /**
72
+ * The `scripts` field is a dictionary containing script commands that are run at various times in the lifecycle of your package.
73
+ */
74
+ scripts?: PackageJsonScripts;
75
+ /**
76
+ * If you set `"private": true` in your package.json, then npm will refuse to publish it.
77
+ */
78
+ private?: boolean;
79
+ /**
80
+ * The “author” is one person.
81
+ */
82
+ author?: PackageJsonPerson;
83
+ /**
84
+ * “contributors” is an array of people.
85
+ */
86
+ contributors?: PackageJsonPerson[];
87
+ /**
88
+ * An object containing a URL that provides up-to-date information
89
+ * about ways to help fund development of your package,
90
+ * a string URL, or an array of objects and string URLs
91
+ */
92
+ funding?: PackageJsonFunding | PackageJsonFunding[];
93
+ /**
94
+ * The optional `files` field is an array of file patterns that describes the entries to be included when your package is installed as a dependency. File patterns follow a similar syntax to `.gitignore`, but reversed: including a file, directory, or glob pattern (`*`, `**\/*`, and such) will make it so that file is included in the tarball when it’s packed. Omitting the field will make it default to `["*"]`, which means it will include all files.
95
+ */
96
+ files?: string[];
97
+ /**
98
+ * The main field is a module ID that is the primary entry point to your program. That is, if your package is named `foo`, and a user installs it, and then does `require("foo")`, then your main module’s exports object will be returned.
99
+ * This should be a module ID relative to the root of your package folder.
100
+ * For most modules, it makes the most sense to have a main script and often not much else.
101
+ */
102
+ main?: string;
103
+ /**
104
+ * If your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren’t available in Node.js modules. (e.g. window)
105
+ */
106
+ browser?: string | Record<string, string | false>;
107
+ /**
108
+ * The `unpkg` field is used to specify the URL to a UMD module for your package. This is used by default in the unpkg.com CDN service.
109
+ */
110
+ unpkg?: string;
111
+ /**
112
+ * A map of command name to local file name. On install, npm will symlink that file into `prefix/bin` for global installs, or `./node_modules/.bin/` for local installs.
113
+ */
114
+ bin?: string | Record<string, string>;
115
+ /**
116
+ * Specify either a single file or an array of filenames to put in place for the `man` program to find.
117
+ */
118
+ man?: string | string[];
119
+ /**
120
+ * Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.
121
+ */
122
+ dependencies?: Record<string, string>;
123
+ /**
124
+ * If someone is planning on downloading and using your module in their program, then they probably don’t want or need to download and build the external test or documentation framework that you use.
125
+ * In this case, it’s best to map these additional items in a `devDependencies` object.
126
+ */
127
+ devDependencies?: Record<string, string>;
128
+ /**
129
+ * If a dependency can be used, but you would like npm to proceed if it cannot be found or fails to install, then you may put it in the `optionalDependencies` object. This is a map of package name to version or url, just like the `dependencies` object. The difference is that build failures do not cause installation to fail.
130
+ */
131
+ optionalDependencies?: Record<string, string>;
132
+ /**
133
+ * In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a `require` of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation.
134
+ */
135
+ peerDependencies?: Record<string, string>;
136
+ /**
137
+ * TypeScript typings, typically ending by `.d.ts`.
138
+ */
139
+ types?: string;
140
+ /**
141
+ * This field is synonymous with `types`.
142
+ */
143
+ typings?: string;
144
+ /**
145
+ * Non-Standard Node.js alternate entry-point to main.
146
+ * An initial implementation for supporting CJS packages (from main), and use module for ESM modules.
147
+ */
148
+ module?: string;
149
+ /**
150
+ * Make main entry-point be loaded as an ESM module, support "export" syntax instead of "require"
151
+ *
152
+ * Docs:
153
+ * - https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_package_json_type_field
154
+ *
155
+ * @default 'commonjs'
156
+ * @since Node.js v14
157
+ */
158
+ type?: "module" | "commonjs";
159
+ /**
160
+ * Alternate and extensible alternative to "main" entry point.
161
+ *
162
+ * When using `{type: "module"}`, any ESM module file MUST end with `.mjs` extension.
163
+ *
164
+ * Docs:
165
+ * - https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_exports_sugar
166
+ *
167
+ * @since Node.js v12.7
168
+ */
169
+ exports?: PackageJsonExports;
170
+ /**
171
+ * Docs:
172
+ * - https://nodejs.org/api/packages.html#imports
173
+ */
174
+ imports?: Record<string, string | Record<string, string>>;
175
+ /**
176
+ * The field is used to define a set of sub-packages (or workspaces) within a monorepo.
177
+ *
178
+ * This field is an array of glob patterns or an object with specific configurations for managing
179
+ * multiple packages in a single repository.
180
+ */
181
+ workspaces?: string[] | {
182
+ /**
183
+ * Workspace package paths. Glob patterns are supported.
184
+ */
185
+ packages?: string[];
186
+ /**
187
+ * Packages to block from hoisting to the workspace root.
188
+ * Uses glob patterns to match module paths in the dependency tree.
189
+ *
190
+ * Docs:
191
+ * - https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
192
+ */
193
+ nohoist?: string[];
194
+ };
195
+ /**
196
+ * The field is used to specify different TypeScript declaration files for
197
+ * different versions of TypeScript, allowing for version-specific type definitions.
198
+ */
199
+ typesVersions?: Record<string, Record<string, string[]>>;
200
+ /**
201
+ * You can specify which operating systems your module will run on:
202
+ * ```json
203
+ * {
204
+ * "os": ["darwin", "linux"]
205
+ * }
206
+ * ```
207
+ * You can also block instead of allowing operating systems, just prepend the blocked os with a '!':
208
+ * ```json
209
+ * {
210
+ * "os": ["!win32"]
211
+ * }
212
+ * ```
213
+ * The host operating system is determined by `process.platform`
214
+ * It is allowed to both block and allow an item, although there isn't any good reason to do this.
215
+ */
216
+ os?: string[];
217
+ /**
218
+ * If your code only runs on certain cpu architectures, you can specify which ones.
219
+ * ```json
220
+ * {
221
+ * "cpu": ["x64", "ia32"]
222
+ * }
223
+ * ```
224
+ * Like the `os` option, you can also block architectures:
225
+ * ```json
226
+ * {
227
+ * "cpu": ["!arm", "!mips"]
228
+ * }
229
+ * ```
230
+ * The host architecture is determined by `process.arch`
231
+ */
232
+ cpu?: string[];
233
+ /**
234
+ * This is a set of config values that will be used at publish-time.
235
+ */
236
+ publishConfig?: {
237
+ /**
238
+ * The registry that will be used if the package is published.
239
+ */
240
+ registry?: string;
241
+ /**
242
+ * The tag that will be used if the package is published.
243
+ */
244
+ tag?: string;
245
+ /**
246
+ * The access level that will be used if the package is published.
247
+ */
248
+ access?: "public" | "restricted";
249
+ /**
250
+ * **pnpm-only**
251
+ *
252
+ * By default, for portability reasons, no files except those listed in
253
+ * the bin field will be marked as executable in the resulting package
254
+ * archive. The executableFiles field lets you declare additional fields
255
+ * that must have the executable flag (+x) set even if
256
+ * they aren't directly accessible through the bin field.
257
+ */
258
+ executableFiles?: string[];
259
+ /**
260
+ * **pnpm-only**
261
+ *
262
+ * You also can use the field `publishConfig.directory` to customize
263
+ * the published subdirectory relative to the current `package.json`.
264
+ *
265
+ * It is expected to have a modified version of the current package in
266
+ * the specified directory (usually using third party build tools).
267
+ */
268
+ directory?: string;
269
+ /**
270
+ * **pnpm-only**
271
+ *
272
+ * When set to `true`, the project will be symlinked from the
273
+ * `publishConfig.directory` location during local development.
274
+ * @default true
275
+ */
276
+ linkDirectory?: boolean;
277
+ } & Pick<PackageJson, "bin" | "main" | "exports" | "types" | "typings" | "module" | "browser" | "unpkg" | "typesVersions" | "os" | "cpu">;
278
+ /**
279
+ * See: https://nodejs.org/api/packages.html#packagemanager
280
+ * This field defines which package manager is expected to be used when working on the current project.
281
+ * Should be of the format: `<name>@<version>[#hash]`
282
+ */
283
+ packageManager?: string;
284
+ [key: string]: any;
285
+ }
286
+ /**
287
+ * See: https://docs.npmjs.com/cli/v11/using-npm/scripts#pre--post-scripts
288
+ */
289
+ type PackageJsonScriptWithPreAndPost<S extends string> = S | `${"pre" | "post"}${S}`;
290
+ /**
291
+ * See: https://docs.npmjs.com/cli/v11/using-npm/scripts#life-cycle-operation-order
292
+ */
293
+ type PackageJsonNpmLifeCycleScripts = "dependencies" | "prepublishOnly" | PackageJsonScriptWithPreAndPost<"install" | "pack" | "prepare" | "publish" | "restart" | "start" | "stop" | "test" | "version">;
294
+ /**
295
+ * See: https://pnpm.io/scripts#lifecycle-scripts
296
+ */
297
+ type PackageJsonPnpmLifeCycleScripts = "pnpm:devPreinstall";
298
+ type PackageJsonCommonScripts = "build" | "coverage" | "deploy" | "dev" | "format" | "lint" | "preview" | "release" | "typecheck" | "watch";
299
+ type PackageJsonScriptName = PackageJsonCommonScripts | PackageJsonNpmLifeCycleScripts | PackageJsonPnpmLifeCycleScripts | (string & {});
300
+ type PackageJsonScripts = { [P in PackageJsonScriptName]?: string };
301
+ /**
302
+ * A “person” is an object with a “name” field and optionally “url” and “email”. Or you can shorten that all into a single string, and npm will parse it for you.
303
+ */
304
+ type PackageJsonPerson = string | {
305
+ name: string;
306
+ email?: string;
307
+ url?: string;
308
+ };
309
+ type PackageJsonFunding = string | {
310
+ url: string;
311
+ type?: string;
312
+ };
313
+ type PackageJsonExportKey = "." | "import" | "require" | "types" | "node" | "browser" | "default" | (string & {});
314
+ type PackageJsonExportsObject = { [P in PackageJsonExportKey]?: string | PackageJsonExportsObject | Array<string | PackageJsonExportsObject> };
315
+ type PackageJsonExports = string | PackageJsonExportsObject | Array<string | PackageJsonExportsObject>;
316
+ /**
317
+ * Defines a PackageJson structure.
318
+ * @param pkg - The `package.json` content as an object. See {@link PackageJson}.
319
+ * @returns the same `package.json` object.
320
+ */
321
+ //#endregion
322
+ //#region src/types.d.ts
4
323
  /**
5
324
  * @description set-value 的写入方法签名
6
325
  */
7
326
  interface SetMethod {
8
- (path: set.InputType, value: any, options?: set.Options): void;
327
+ (path: set.InputType, value: any, options?: set.Options): void;
9
328
  }
10
329
  /**
11
330
  * @description 共享更新参数
12
331
  */
13
332
  interface SharedUpdateOptions {
14
- root: string;
15
- dest?: string;
16
- write?: boolean;
17
- cb?: (set: SetMethod) => void;
333
+ root: string;
334
+ dest?: string;
335
+ write?: boolean;
336
+ cb?: (set: SetMethod) => void;
18
337
  }
19
338
  /**
20
339
  * @description project.config 更新参数
21
340
  */
22
341
  interface UpdateProjectConfigOptions extends SharedUpdateOptions {
23
- filename?: string;
342
+ filename?: string;
24
343
  }
25
344
  /**
26
345
  * @description package.json 更新参数
27
346
  */
28
347
  interface UpdatePackageJsonOptions extends SharedUpdateOptions {
29
- command?: 'weapp-vite';
30
- filename?: string;
348
+ command?: 'weapp-vite';
349
+ filename?: string;
31
350
  }
32
351
  /**
33
352
  * @description project.config.json 的核心字段类型
34
353
  */
35
354
  interface ProjectConfig {
36
- miniprogramRoot?: string;
37
- srcMiniprogramRoot?: string;
38
- setting: {
39
- packNpmManually: boolean;
40
- packNpmRelationList: {
41
- packageJsonPath: string;
42
- miniprogramNpmDistDir: string;
43
- }[];
44
- };
355
+ miniprogramRoot?: string;
356
+ srcMiniprogramRoot?: string;
357
+ setting: {
358
+ packNpmManually: boolean;
359
+ packNpmRelationList: {
360
+ packageJsonPath: string;
361
+ miniprogramNpmDistDir: string;
362
+ }[];
363
+ };
45
364
  }
46
-
365
+ //#endregion
366
+ //#region src/context.d.ts
47
367
  /**
48
368
  * @description init 过程中单个文件的上下文结构
49
369
  */
50
370
  interface ContextDocument<T> {
51
- name: string;
52
- path: string;
53
- value: T | null;
371
+ name: string;
372
+ path: string;
373
+ value: T | null;
54
374
  }
55
375
  /**
56
376
  * @description init 过程的上下文容器
57
377
  */
58
378
  interface Context {
59
- projectConfig: ContextDocument<ProjectConfig>;
60
- packageJson: ContextDocument<PackageJson>;
61
- viteConfig: ContextDocument<string>;
62
- tsconfig: ContextDocument<TSConfig>;
63
- tsconfigApp: ContextDocument<TSConfig>;
64
- tsconfigNode: ContextDocument<TSConfig>;
65
- dts: ContextDocument<string>;
379
+ projectConfig: ContextDocument<ProjectConfig>;
380
+ packageJson: ContextDocument<PackageJson>;
381
+ viteConfig: ContextDocument<string>;
382
+ tsconfig: ContextDocument<TSConfig>;
383
+ tsconfigApp: ContextDocument<TSConfig>;
384
+ tsconfigNode: ContextDocument<TSConfig>;
385
+ dts: ContextDocument<string>;
66
386
  }
67
-
387
+ //#endregion
388
+ //#region src/configFiles.d.ts
68
389
  declare function initViteConfigFile(options: SharedUpdateOptions): Promise<string>;
69
390
  declare function initTsDtsFile(options: SharedUpdateOptions): Promise<string>;
70
391
  declare function initTsJsonFiles(options: SharedUpdateOptions): Promise<{
71
- tsconfig: {
72
- references: {
73
- path: string;
74
- }[];
75
- files: never[];
392
+ tsconfig: {
393
+ references: {
394
+ path: string;
395
+ }[];
396
+ files: never[];
397
+ };
398
+ tsconfigApp: {
399
+ compilerOptions: {
400
+ tsBuildInfoFile: string;
401
+ target: string;
402
+ lib: string[];
403
+ jsx: string;
404
+ module: string;
405
+ moduleResolution: string;
406
+ moduleDetection: string;
407
+ baseUrl: string;
408
+ paths: {
409
+ '@/*': string[];
410
+ };
411
+ resolveJsonModule: boolean;
412
+ types: string[];
413
+ allowImportingTsExtensions: boolean;
414
+ allowJs: boolean;
415
+ allowSyntheticDefaultImports: boolean;
416
+ esModuleInterop: boolean;
417
+ isolatedModules: boolean;
418
+ strict: boolean;
419
+ noFallthroughCasesInSwitch: boolean;
420
+ noUnusedLocals: boolean;
421
+ noUnusedParameters: boolean;
422
+ noEmit: boolean;
423
+ verbatimModuleSyntax: boolean;
424
+ noUncheckedSideEffectImports: boolean;
425
+ erasableSyntaxOnly: boolean;
426
+ skipLibCheck: boolean;
76
427
  };
77
- tsconfigApp: {
78
- compilerOptions: {
79
- tsBuildInfoFile: string;
80
- target: string;
81
- lib: string[];
82
- jsx: string;
83
- module: string;
84
- moduleResolution: string;
85
- moduleDetection: string;
86
- baseUrl: string;
87
- paths: {
88
- '@/*': string[];
89
- };
90
- resolveJsonModule: boolean;
91
- types: string[];
92
- allowImportingTsExtensions: boolean;
93
- allowJs: boolean;
94
- allowSyntheticDefaultImports: boolean;
95
- esModuleInterop: boolean;
96
- isolatedModules: boolean;
97
- strict: boolean;
98
- noFallthroughCasesInSwitch: boolean;
99
- noUnusedLocals: boolean;
100
- noUnusedParameters: boolean;
101
- noEmit: boolean;
102
- verbatimModuleSyntax: boolean;
103
- noUncheckedSideEffectImports: boolean;
104
- erasableSyntaxOnly: boolean;
105
- skipLibCheck: boolean;
106
- };
107
- include: string[];
108
- };
109
- tsconfigNode: {
110
- compilerOptions: {
111
- tsBuildInfoFile: string;
112
- target: string;
113
- lib: string[];
114
- module: string;
115
- moduleResolution: string;
116
- moduleDetection: string;
117
- types: string[];
118
- allowImportingTsExtensions: boolean;
119
- resolveJsonModule: boolean;
120
- verbatimModuleSyntax: boolean;
121
- strict: boolean;
122
- noFallthroughCasesInSwitch: boolean;
123
- noUnusedLocals: boolean;
124
- noUnusedParameters: boolean;
125
- noEmit: boolean;
126
- noUncheckedSideEffectImports: boolean;
127
- erasableSyntaxOnly: boolean;
128
- skipLibCheck: boolean;
129
- };
130
- include: string[];
428
+ include: string[];
429
+ };
430
+ tsconfigNode: {
431
+ compilerOptions: {
432
+ tsBuildInfoFile: string;
433
+ target: string;
434
+ lib: string[];
435
+ module: string;
436
+ moduleResolution: string;
437
+ moduleDetection: string;
438
+ types: string[];
439
+ allowImportingTsExtensions: boolean;
440
+ resolveJsonModule: boolean;
441
+ verbatimModuleSyntax: boolean;
442
+ strict: boolean;
443
+ noFallthroughCasesInSwitch: boolean;
444
+ noUnusedLocals: boolean;
445
+ noUnusedParameters: boolean;
446
+ noEmit: boolean;
447
+ noUncheckedSideEffectImports: boolean;
448
+ erasableSyntaxOnly: boolean;
449
+ skipLibCheck: boolean;
131
450
  };
451
+ include: string[];
452
+ };
132
453
  }>;
133
-
454
+ //#endregion
455
+ //#region src/packageJson.d.ts
134
456
  /**
135
457
  * @description 创建或更新 package.json
136
458
  */
137
459
  declare function createOrUpdatePackageJson(options: UpdatePackageJsonOptions): Promise<PackageJson>;
138
-
460
+ //#endregion
461
+ //#region src/projectConfig.d.ts
139
462
  /**
140
463
  * @description 创建或更新 project.config.json
141
464
  */
142
465
  declare function createOrUpdateProjectConfig(options: UpdateProjectConfigOptions): Promise<ProjectConfig>;
143
-
466
+ //#endregion
467
+ //#region src/state.d.ts
144
468
  /**
145
469
  * @description 重置全局上下文
146
470
  */
147
471
  declare function resetContext(): void;
148
-
472
+ //#endregion
473
+ //#region src/index.d.ts
149
474
  /**
150
475
  * @description 初始化项目配置(project.config、package.json、tsconfig、vite.config 等)
151
476
  */
152
477
  declare function initConfig(options: {
153
- root?: string;
154
- command?: 'weapp-vite';
478
+ root?: string;
479
+ command?: 'weapp-vite';
155
480
  }): Promise<Context>;
156
-
157
- export { type Context, createOrUpdatePackageJson, createOrUpdateProjectConfig, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, resetContext };
481
+ //#endregion
482
+ export { type Context, createOrUpdatePackageJson, createOrUpdateProjectConfig, initConfig, initTsDtsFile, initTsJsonFiles, initViteConfigFile, resetContext };