Skip to content

Commit

Permalink
fix(js): do not generate package.json file for non-buildable js libra…
Browse files Browse the repository at this point in the history
…ries in non-ts solution setup
  • Loading branch information
leosvelperez committed Jan 16, 2025
1 parent d0078d0 commit fbb9b8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/js/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,19 @@ describe('lib', () => {
});
});

describe('--bundler=none', () => {
it('should not generate a package.json when bundler is none', async () => {
await libraryGenerator(tree, {
...defaultOptions,
directory: 'my-lib',
bundler: 'none',
unitTestRunner: 'none',
});

expect(tree.exists('my-lib/package.json')).toBe(false);
});
});

describe('--minimal', () => {
it('should generate a README.md when minimal is set to false', async () => {
await libraryGenerator(tree, {
Expand Down Expand Up @@ -1602,14 +1615,7 @@ describe('lib', () => {
},
}
`);
expect(readJson(tree, 'my-lib/package.json')).toMatchInlineSnapshot(`
{
"dependencies": {},
"name": "@proj/my-lib",
"private": true,
"version": "0.0.1",
}
`);
expect(tree.exists('my-lib/package.json')).toBe(false);
});
});

Expand Down
7 changes: 7 additions & 0 deletions packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,13 @@ function createFiles(tree: Tree, options: NormalizedLibraryGeneratorOptions) {
};
return json;
});
} else if (
!options.isUsingTsSolutionConfig &&
options.useProjectJson &&
(!options.bundler || options.bundler === 'none') &&
!(options.projectRoot === '.')
) {
tree.delete(packageJsonPath);
}

if (options.minimal && !(options.projectRoot === '.')) {
Expand Down

0 comments on commit fbb9b8a

Please sign in to comment.