Skip to content

Commit a1bbd55

Browse files
authored
Merge pull request #38 from sontx/fix-wrong-init-packagejson
Fix wrong package.json place when init
2 parents bf3b43e + bd49895 commit a1bbd55

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/deps/src/npm-package.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export class NpmPackage {
3535
}
3636

3737
private async addDep(packageName: string, args?: string) {
38-
return await execAsync(`npm install ${packageName} --package-lock=false ${args ?? ''}`.trim(), { cwd: this.workingDir });
38+
return await execAsync(`npm install ${packageName} --package-lock=false ${args ?? ''}`.trim(), {
39+
cwd: this.workingDir,
40+
});
3941
}
4042

4143
private async installDeps(args?: string) {
@@ -86,8 +88,8 @@ export class NpmPackage {
8688
const packageJson: PackageJson = {
8789
name: this.name,
8890
type: 'module',
89-
main: `${this.name}.js`,
91+
main: `${this.name}.mjs`,
9092
};
91-
await fs.promises.writeFile('package.json', JSON.stringify(packageJson, null, 2));
93+
await fs.promises.writeFile(path.join(this.workingDir, 'package.json'), JSON.stringify(packageJson, null, 2));
9294
}
9395
}

packages/deps/tests/npm-package.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs';
2+
import path from 'node:path';
23
import { NpmPackage } from '@src/npm-package';
34
import { expect } from '@jest/globals';
45

@@ -43,8 +44,8 @@ describe('NpmPackage', () => {
4344
await npmPackage.install();
4445

4546
expect(writeFileMock).toHaveBeenCalledWith(
46-
'package.json',
47-
JSON.stringify({ name: 'letrun', type: 'module', main: 'letrun.js' }, null, 2),
47+
path.join(workingDir, 'package.json'),
48+
JSON.stringify({ name: 'letrun', type: 'module', main: 'letrun.mjs' }, null, 2),
4849
);
4950
expect(installDeps).toHaveBeenCalledTimes(1);
5051
});

0 commit comments

Comments
 (0)