Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow bypass update version #18

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ A shared package for create-rspack, create-rsbuild, create-rspress and create-rs
npm add create-rstack -D
```

## Example
## Examples

See: [create-rsbuild](https://github.com/web-infra-dev/rsbuild/tree/main/packages/create-rsbuild).
| Project | Link |
| ------- | -------------------------------------------------------------------------------------------- |
| Rsbuild | [create-rsbuild](https://github.com/web-infra-dev/rsbuild/tree/main/packages/create-rsbuild) |
| Rslib | [create-rslib](https://github.com/web-infra-dev/rslib/tree/main/packages/create-rslib) |

![image](https://github.com/user-attachments/assets/2dda3501-720c-4151-bd3e-5e038dca9e68)


## License

[MIT](./LICENSE).
24 changes: 16 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ export function mergePackageJson(targetPackage: string, extraPackage: string) {
* Copy files from one folder to another.
* @param from Source folder
* @param to Destination folder
* @param version Version to update in package.json
* @param packageName Name to update in package.json
* @param version - Optional. The version to update in the package.json. If not provided, version will not be updated.
* @param name - Optional. The name to update in the package.json. If not provided, name will not be updated.
* @param isMergePackageJson Merge package.json files
* @param skipFiles Files to skip
*/
Expand All @@ -330,7 +330,7 @@ export function copyFolder({
}: {
from: string;
to: string;
version: string;
version?: string;
packageName?: string;
isMergePackageJson?: boolean;
skipFiles?: string[];
Expand Down Expand Up @@ -383,17 +383,25 @@ const isStableVersion = (version: string) => {
);
};

/**
* Updates the package.json file at the specified path with the provided version and name.
*
* @param pkgJsonPath - The file path to the package.json file.
* @param version - Optional. The version to update in the package.json. If not provided, version will not be updated.
* @param name - Optional. The name to update in the package.json. If not provided, name will not be updated.
*/
const updatePackageJson = (
pkgJsonPath: string,
version: string,
version?: string,
name?: string,
) => {
let content = fs.readFileSync(pkgJsonPath, 'utf-8');

// Lock the version if it is not stable
const targetVersion = isStableVersion(version) ? `^${version}` : version;

content = content.replace(/workspace:\*/g, targetVersion);
if (typeof version === 'string') {
// Lock the version if it is not stable
const targetVersion = isStableVersion(version) ? `^${version}` : version;
content = content.replace(/workspace:\*/g, targetVersion);
}

const pkg = JSON.parse(content);

Expand Down