Skip to content

Commit 1fc3035

Browse files
committed
refactor: 备份文件合并到dist目录
1 parent f3f0005 commit 1fc3035

File tree

6 files changed

+10
-17
lines changed

6 files changed

+10
-17
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ node_modules/
22
.idea/
33
TODO
44
dist/
5-
backup/
65
.npmrc
76
coverage/
87
.DS_Store

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"access": "public"
5252
},
5353
"files": [
54-
"backup",
5554
"adapters",
5655
"dist",
5756
"LICENSE",

scripts/build-success.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set -ex
44

55
echo '{"type":"module"}' > dist/esm/package.json
66

7-
mkdir -p backup/esm
8-
cp dist/index.js backup/index.js
9-
cp dist/index.d.ts backup/index.d.ts
10-
cp dist/esm/index.js backup/esm/index.js
7+
cp dist/index.js dist/backup-index.js
8+
cp dist/index.d.ts dist/backup-index.d.ts
9+
cp dist/esm/index.js dist/esm/backup-index.js

src/lib/rebuild-dist.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ export const rebuildDist = async (
88
classNames: string[],
99
) => {
1010
const distDir = path.join(root, 'dist');
11-
const backupDir = path.join(root, 'backup');
1211

1312
{
14-
let backupDTS = await readFile(path.join(backupDir, 'index.d.ts'), 'utf8');
13+
let backupDTS = await readFile(path.join(distDir, 'backup-index.d.ts'), 'utf8');
1514
backupDTS += `\n${dtsContent}\nexport { ${classNames.join(', ')} };`;
1615
await writeFile(path.join(distDir, 'index.d.ts'), backupDTS);
1716
}
1817

1918
{
20-
let backupCJS = await readFile(path.join(backupDir, 'index.js'), 'utf8');
19+
let backupCJS = await readFile(path.join(distDir, 'backup-index.js'), 'utf8');
2120
backupCJS = backupCJS.replace(
2221
'0 && (module.exports = {',
2322
`${jsContent}\n0 && (module.exports = {\n${classNames.join(',')},`,
@@ -30,7 +29,7 @@ export const rebuildDist = async (
3029
}
3130

3231
{
33-
let backupESM = await readFile(path.join(backupDir, 'esm', 'index.js'), 'utf8');
32+
let backupESM = await readFile(path.join(distDir, 'esm', 'backup-index.js'), 'utf8');
3433
backupESM += `\n${jsContent}\nexport { ${classNames.join(', ')} };`;
3534
await writeFile(path.join(distDir, 'esm', 'index.js'), backupESM);
3635
}

test/bin.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { beforeAll, expect, test } from 'vitest';
77
beforeAll(async () => {
88
try {
99
await rm('dist', { recursive: true });
10-
await rm('backup', { recursive: true });
1110
} catch {}
1211
execSync('pnpm build', { encoding: 'utf8', stdio: 'inherit' });
1312
}, 15_000);

test/lib/rebuild-dist.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
import { beforeAll, expect, test } from 'vitest';
44
import { rebuildDist } from '../../src/lib/rebuild-dist';
55
import tsup from 'tsup';
6+
import { execSync } from 'node:child_process';
67

78
const root = path.resolve('test', 'fixtures');
89
const dtsContent = 'declare const foo = { bar: "baz" };';
@@ -17,12 +18,9 @@ beforeAll(async () => {
1718
dts: true,
1819
legacyOutput: true,
1920
});
20-
await tsup.build({
21-
entry: ['test/fixtures/index.ts'],
22-
outDir: 'test/fixtures/backup',
23-
sourcemap: true,
24-
dts: true,
25-
legacyOutput: true,
21+
22+
execSync(`sh ${process.cwd()}/scripts/build-success.sh`, {
23+
cwd: path.join(path.dirname(import.meta.dirname), 'fixtures'),
2624
});
2725
});
2826

0 commit comments

Comments
 (0)