Skip to content

Commit bc52b44

Browse files
committed
feat: update typescript version and enable strict compiler option
1 parent 6dac234 commit bc52b44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+691
-475
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'ice-npm-utils': minor
3+
'@ice/create-pkg': minor
4+
'@ice/pkg': minor
5+
---
6+
7+
feat: update typescript version and enable strict compiler option

packages/create-pkg/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"build": "rm -rf lib && tsc"
3030
},
3131
"devDependencies": {
32+
"@types/inquirer": "^9.0.9",
33+
"@types/validate-npm-package-name": "^4.0.2",
3234
"typescript": "catalog:"
3335
},
3436
"dependencies": {

packages/create-pkg/src/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function create(dirPath: string, dirname: string, options: CliOptions): Pr
7474

7575
const tempDir = path.join(dirPath, '.tmp');
7676

77-
let templateNpmName = options.template;
77+
let templateNpmName = options.template!;
7878
if (!templateNpmName) {
7979
templateNpmName = await inquireTemplateNpmName(options.workspace);
8080
}

packages/ice-npm-utils/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
"license": "MIT",
3131
"devDependencies": {
3232
"typescript": "catalog:",
33-
"vitest": "catalog:"
33+
"vitest": "catalog:",
34+
"@types/node": "^17.0.45",
35+
"@types/fs-extra": "^9.0.13",
36+
"@types/semver": "^7.7.1",
37+
"@types/mkdirp": "^1.0.2",
38+
"@types/tar": "^6.0.0",
39+
"@types/url-join": "^4.0.0"
3440
}
3541
}

packages/ice-npm-utils/src/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import axios from 'axios';
99
import urlJoin from 'url-join';
1010

1111
import type { AxiosResponse } from 'axios';
12+
import { Readable } from 'stream';
1213

1314
/**
1415
* 获取指定 npm 包版本的 tarball
@@ -17,11 +18,11 @@ function getNpmTarball(npm: string, version?: string, registry?: string): Promis
1718
return getNpmInfo(npm, registry).then((json: any) => {
1819
if (!semver.valid(version)) {
1920
// support beta or other tag
20-
version = json['dist-tags'][version] || json['dist-tags'].latest;
21+
version = json['dist-tags'][version!] || json['dist-tags'].latest;
2122
}
2223

23-
if (semver.valid(version) && json.versions && json.versions[version] && json.versions[version].dist) {
24-
return json.versions[version].dist.tarball;
24+
if (semver.valid(version) && json.versions && json.versions[version!] && json.versions[version!].dist) {
25+
return json.versions[version!].dist.tarball;
2526
}
2627

2728
return Promise.reject(new Error(`没有在 ${registry} 源上找到 ${npm}@${version} 包`));
@@ -35,7 +36,7 @@ function getAndExtractTarball(
3536
destDir: string,
3637
tarball: string,
3738

38-
progressFunc = (state) => {},
39+
progressFunc = (_: any) => {},
3940
formatFilename = (filename: string): string => {
4041
// 为了兼容
4142
if (filename === '_package.json') {
@@ -46,9 +47,9 @@ function getAndExtractTarball(
4647
},
4748
): Promise<string[]> {
4849
return new Promise((resolve, reject) => {
49-
const allFiles = [];
50-
const allWriteStream = [];
51-
const dirCollector = [];
50+
const allFiles: string[] = [];
51+
const allWriteStream: Array<Promise<boolean>> = [];
52+
const dirCollector: string[] = [];
5253

5354
axios({
5455
url: tarball,
@@ -60,8 +61,7 @@ function getAndExtractTarball(
6061
}).then((response) => {
6162
const totalLength = Number(response.headers['content-length']);
6263
let downloadLength = 0;
63-
response.data
64-
// @ts-ignore
64+
(response.data as Readable)
6565
.on('data', (chunk) => {
6666
downloadLength += chunk.length;
6767
progressFunc({
@@ -70,8 +70,8 @@ function getAndExtractTarball(
7070
})
7171
// @ts-ignore
7272
.pipe(zlib.Unzip())
73-
// @ts-ignore
7473
.pipe(new tar.Parse())
74+
// @ts-ignore
7575
.on('entry', (entry) => {
7676
if (entry.type === 'Directory') {
7777
entry.resume();
@@ -149,7 +149,7 @@ function getSatisfiesVersions(npm: string, range: string, registry?: string) {
149149
return versions
150150
.filter((version) => semver.satisfies(version, range))
151151
.sort((a, b) => {
152-
return semver.gt(b, a);
152+
return +semver.gt(b, a);
153153
});
154154
});
155155
}
@@ -186,7 +186,7 @@ function getNpmLatestSemverVersion(npm: string, baseVersion: string, registry?:
186186
*
187187
* @param {String} npm
188188
*/
189-
function getLatestVersion(npm, registry?: string): Promise<string> {
189+
function getLatestVersion(npm: string, registry?: string): Promise<string> {
190190
return getNpmInfo(npm, registry).then((data) => {
191191
if (!data['dist-tags'] || !data['dist-tags'].latest) {
192192
console.error('没有 latest 版本号', data);
@@ -199,7 +199,7 @@ function getLatestVersion(npm, registry?: string): Promise<string> {
199199
}
200200

201201
function isAliNpm(npmName?: string): boolean {
202-
return /^(@alife|@ali|@alipay|@kaola)\//.test(npmName);
202+
return npmName ? /^(@alife|@ali|@alipay|@kaola)\//.test(npmName) : false;
203203
}
204204

205205
function getNpmRegistry(npmName = ''): string {

packages/pkg/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@
7070
"rollup-plugin-visualizer": "^5.12.0",
7171
"semver": "^7.5.2",
7272
"tsc-alias": "1.8.13",
73-
"typescript": "^4.9.5",
73+
"typescript": "^5.0.0",
7474
"zod": "^3.24.2",
7575
"zod-validation-error": "^3.4.0"
7676
},
7777
"devDependencies": {
7878
"@types/babel__core": "^7.1.20",
79+
"@types/debug": "^4.1.12",
7980
"@types/fs-extra": "^9.0.13",
8081
"@types/node": "^17.0.2",
8182
"@types/semver": "^7.7.1",

packages/pkg/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { fileURLToPath } from 'node:url';
2-
import consola from 'consola';
2+
import { consola } from 'consola';
33
import { cac } from 'cac';
44
import { readFileSync } from 'node:fs';
55
import { join, dirname } from 'node:path';

packages/pkg/src/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default async function build(context: Context) {
2525
});
2626

2727
// Empty outputDir before run the task.
28-
const outputDirs = taskConfigs.map((config) => config.outputDir).filter(Boolean);
28+
const outputDirs = taskConfigs.map((config) => String(config.outputDir)).filter(Boolean);
2929
outputDirs.forEach((outputDir) => fse.emptyDirSync(outputDir));
3030

3131
const tasks = getTaskRunners(buildTasks, context);

packages/pkg/src/commands/start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import consola from 'consola';
1+
import { consola } from 'consola';
22
import { createBatchChangeHandler, createWatcher } from '../helpers/watcher.js';
33
import type { OutputResult, Context, WatchChangedFile, BuildTask } from '../types.js';
44
import { RunnerLinerTerminalReporter } from '../helpers/runnerReporter.js';

packages/pkg/src/core/create.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CommandArgs, Context as BuildScriptContext } from 'build-scripts';
1+
import { CommandArgs, Context as BuildScriptContext, PluginList } from 'build-scripts';
22
import type { ICommandFn } from 'build-scripts/lib/Service.js';
33
import { Context, CustomFormatTaskCreator, ExtendsPluginAPI, TaskConfig, UserConfig } from '../types.js';
44
import taskRegisterPlugin from '../plugins/component.js';
@@ -55,9 +55,9 @@ export async function createCore(options: CreatePkgOptions) {
5555
rootDir: options.rootDir,
5656
commandArgs: options.commandArgs,
5757
configFile: options.userConfigFile,
58-
plugins: [taskRegisterPlugin],
58+
plugins: [taskRegisterPlugin] as PluginList,
5959
extendsPluginAPI,
60-
});
60+
}) as Context;
6161

6262
if (options.userConfig) {
6363
ctx.userConfig = {
@@ -69,7 +69,7 @@ export async function createCore(options: CreatePkgOptions) {
6969
}
7070

7171
const core: PkgCore = {
72-
ctx,
72+
ctx: ctx as Context,
7373
async run() {
7474
await commandHandler(ctx);
7575
},

0 commit comments

Comments
 (0)