Skip to content

Commit d41dd21

Browse files
committed
fix(node-modules-util): fix ts type parsing error for 'alipay-sdk'
1 parent 690df32 commit d41dd21

File tree

8 files changed

+53
-9
lines changed

8 files changed

+53
-9
lines changed

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ services:
4242
volumes:
4343
- /var/run/docker.sock:/var/run/docker.sock:ro
4444
- ./packages/system-server:/app
45-
- ./packages/cloud-function:/app/node_modules/cloud-function-engine:ro
4645
- ./packages/database-proxy:/app/node_modules/database-proxy:ro
4746
- ./packages/database-ql:/app/node_modules/database-ql:ro
4847
- ./packages/database-ql:/app/node_modules/database-proxy/node_modules/database-ql:ro
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rm -rf ../app-service/node_modules/node-modules-utils/dist
2+
rm -rf ../app-service/node_modules/node-modules-utils/src
3+
cp -r dist ../app-service/node_modules/node-modules-utils/dist
4+
cp -r src ../app-service/node_modules/node-modules-utils/src
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rm -rf ../system-server/node_modules/cloud-function-engine/dist
2+
rm -rf ../system-server/node_modules/cloud-function-engine/src
3+
cp -r dist ../system-server/node_modules/cloud-function-engine/dist
4+
cp -r src ../system-server/node_modules/cloud-function-engine/src

packages/node-modules-utils/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
"build": "tsc",
2424
"watch": "tsc -w",
2525
"test": "npx mocha tests/**test.js",
26-
"prepublishOnly": "npm run build"
26+
"prepublishOnly": "npm run build",
27+
"copy2app": "sh copy2app.sh",
28+
"copy2sys": "sh copy2sys.sh",
29+
"copy4dev": "sh copy2app.sh && sh copy2sys.sh"
2730
},
2831
"bugs": {
2932
"url": "https://github.com/Maslow/less-framework/issues"

packages/node-modules-utils/src/declaration.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,29 @@ export class PackageDeclaration extends PackageInfo {
100100
* 2. 如果未读取到,则指定 package.json#main 所在目录 下的 index.d.ts 为 typings
101101
*/
102102
async resolveTypingsEntryPath() {
103+
104+
let defaultFilename = 'index.d.ts'
105+
const entryStat = await this.exists(this.entryFile)
106+
if (entryStat.isFile()) {
107+
const { name } = path.parse(this.entryFile)
108+
defaultFilename = `${name}.d.ts`
109+
}
110+
111+
const defaultTypings = path.join(this.entryPath, defaultFilename)
103112
const typings = this.info?.typings || this.info?.types
104113

105-
const defaultTypings = path.join(this.entryPath, 'index.d.ts')
106114
if (!typings) {
107115
return defaultTypings
108116
}
109117

110-
111118
const typingFile = path.join(this.rootPath, typings)
112119
const stat = await this.exists(typingFile)
113120
if (!stat) {
114121
return defaultTypings
115122
}
116123

117124
if (stat.isDirectory()) {
118-
return path.join(typingFile, 'index.d.ts')
125+
return path.join(typingFile, defaultFilename)
119126
}
120127

121128
return typingFile

packages/node-modules-utils/src/package.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export class PackageInfo {
1919
*/
2020
rootPath: string
2121

22+
/**
23+
* entry file
24+
* 为 main / module 指定的入口文件
25+
*/
26+
entryFile: string
27+
2228
/**
2329
* entry path
2430
* 为 main / module 指定的入口文件所在目录
@@ -38,10 +44,10 @@ export class PackageInfo {
3844
}
3945

4046
get dependencyNames(): string[] {
41-
if(!this.dependencies) return []
47+
if (!this.dependencies) return []
4248
return Object.keys(this.dependencies)
4349
}
44-
50+
4551
/**
4652
* common entry file
4753
*/
@@ -124,6 +130,7 @@ export class PackageInfo {
124130
entryPath = path.dirname(entryPath)
125131
}
126132

133+
this.entryFile = entryFile
127134
this.entryPath = entryPath
128135
}
129136

@@ -164,7 +171,7 @@ export class PackageInfo {
164171
* 文件或文件是否存在
165172
* @param p
166173
*/
167-
async exists(p: string) {
174+
async exists(p: string) {
168175
try {
169176
const stat = await fse.stat(p)
170177
return stat

packages/node-modules-utils/tests/declare.test.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('npm-util(unit): Package Declaration Load', () => {
3737
})
3838

3939
/**
40-
* load from self package: less-api-database
40+
* load from self package: database-proxy
4141
*/
4242
it('load d.ts of database-proxy (typings)', async () => {
4343
const pkg = new PackageDeclaration('database-proxy', nmp)
@@ -46,5 +46,17 @@ describe('npm-util(unit): Package Declaration Load', () => {
4646

4747
assert.strictEqual(pkg.name, 'database-proxy')
4848
assert.ok(pkg.declarations.length > 0)
49+
})
50+
51+
/**
52+
* load from self package: alipay-sdk
53+
*/
54+
it('load d.ts of alipay-sdk (typings)', async () => {
55+
const pkg = new PackageDeclaration('alipay-sdk', nmp)
56+
await pkg.load()
57+
// console.log(pkg)
58+
59+
assert.strictEqual(pkg.name, 'alipay-sdk')
60+
assert.ok(pkg.declarations.length > 0)
4961
})
5062
})

packages/node-modules-utils/tests/parse.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,12 @@ describe('npm-util(unit): Package parse', () => {
4949
// console.log(pkg)
5050
assert.strictEqual(pkg.name, '@types/express')
5151
})
52+
53+
54+
it('get pkg dir: alipay-sdk', async () => {
55+
const pkg = new PackageInfo('alipay-sdk', nmp)
56+
await pkg.parsePackageInfo()
57+
// console.log(pkg)
58+
assert.strictEqual(pkg.name, 'alipay-sdk')
59+
})
5260
})

0 commit comments

Comments
 (0)