Skip to content

Commit 5b08f12

Browse files
committed
chore: 构建增加 manifest
1 parent a013f75 commit 5b08f12

File tree

4 files changed

+150
-2
lines changed

4 files changed

+150
-2
lines changed

bin/run.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node --no-warnings=ExperimentalWarning --experimental-specifier-resolution=node
1+
#!/usr/bin/env node
22

33
import { execute } from '@oclif/core'
44

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"/oclif.manifest.json"
2626
],
2727
"scripts": {
28-
"build": "rm -rf dist && tsc -b",
28+
"build": "rm -rf dist && tsc -b && node ./scripts/babel.js && oclif manifest",
2929
"prepare": "husky"
3030
},
3131
"oclif": {
@@ -55,6 +55,7 @@
5555
"ora": "^8.0.1"
5656
},
5757
"devDependencies": {
58+
"@babel/core": "^7.24.4",
5859
"@commitlint/cli": "^19.2.2",
5960
"@commitlint/config-conventional": "^19.2.2",
6061
"@ianvs/prettier-plugin-sort-imports": "^4.2.1",
@@ -65,6 +66,7 @@
6566
"eslint-config-oclif": "^5.1.3",
6667
"eslint-config-oclif-typescript": "^3.1.6",
6768
"eslint-config-prettier": "^9.1.0",
69+
"glob": "^10.3.12",
6870
"husky": "^9.0.11",
6971
"lint-staged": "^15.2.2",
7072
"oclif": "^4.8.5",

pnpm-lock.yaml

+109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/babel.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { transformFileAsync } from "@babel/core";
2+
import { glob } from 'glob';
3+
import fs from 'node:fs';
4+
import path from 'node:path';
5+
6+
const files = await glob('./dist/**/*.js');
7+
const transformImportSourcePlugin = {
8+
visitor: {
9+
ImportDeclaration(params, context) {
10+
const { value } = params.node.source;
11+
12+
if (value.startsWith('./') || value.startsWith('../')) {
13+
const absolutePath = path.join(context.filename, '..', value + '.js');
14+
15+
if (fs.existsSync(absolutePath)) {
16+
params.node.source.value += '.js';
17+
} else {
18+
const absolutePath = path.join(context.filename, '..', value, 'index.js');
19+
20+
if (fs.existsSync(absolutePath)) {
21+
params.node.source.value += '/index.js';
22+
}
23+
}
24+
}
25+
}
26+
}
27+
};
28+
29+
for (const file of files) {
30+
const filePath = path.join(import.meta.url, '..', '..', file).slice(5);
31+
const result = await transformFileAsync(filePath, {
32+
plugins: [transformImportSourcePlugin]
33+
});
34+
35+
await fs.promises.writeFile(filePath, result.code);
36+
}
37+

0 commit comments

Comments
 (0)