Skip to content

Commit

Permalink
Add optionalDependencies support for deploy (#59)
Browse files Browse the repository at this point in the history
* Add optionalDependencies support for deploy

* 2.2.7
  • Loading branch information
dumganhar authored Feb 23, 2024
1 parent 0f613c4 commit f35fefc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cocos/ccbuild",
"version": "2.2.6",
"version": "2.2.7",
"description": "The next generation of build tool for Cocos engine.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const pkgName2Main = {};
const pkgName2Types = {};
const filesToCopy = [];
const allDeps = {};
const allOptionalDeps = {};

pkgFileList.forEach(pkgFile => {
const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
const pkgName = pkg.name;
Expand Down Expand Up @@ -56,6 +58,15 @@ pkgFileList.forEach(pkgFile => {
allDeps[dep] = depVersion;
}

for (const dep in pkg.optionalDependencies) {
const depVersion = pkg.optionalDependencies[dep];
if (dep in allOptionalDeps && allOptionalDeps[dep] !== depVersion) {
console.warn(`optional package '${pkgName}' has different dep version of package '${dep}', which is '${depVersion}'`);
continue;
}
allOptionalDeps[dep] = depVersion;
}

});

// copy files
Expand Down Expand Up @@ -132,6 +143,7 @@ console.log('generate package.json');
const rootPkgFile = ps.join(rootDir, 'package.json');
const rootPkg = JSON.parse(fs.readFileSync(rootPkgFile, 'utf8'));
rootPkg.dependencies = allDeps;
rootPkg.optionalDependencies = allOptionalDeps;
delete rootPkg.devDependencies;
delete rootPkg.scripts;
for (const dep in rootPkg.dependencies) {
Expand Down

0 comments on commit f35fefc

Please sign in to comment.