diff --git a/packages/blerf/src/commands/build.ts b/packages/blerf/src/commands/build.ts index 786c717..c040f46 100644 --- a/packages/blerf/src/commands/build.ts +++ b/packages/blerf/src/commands/build.ts @@ -179,6 +179,7 @@ export class BuildEnumerator extends PackageEnumerator { const packageJson = this.readPackageJson(packageJsonPath); this.rewriteProjectReferencesFullPath(path.resolve(this.artifactBuildPath), packageJson.dependencies, packages); this.rewriteProjectReferencesFullPath(path.resolve(this.artifactBuildPath), packageJson.devDependencies, packages); + this.trimPackageJson(packageJson); fs.writeFileSync(packageJsonPath, stringifyPackage(packageJson), 'utf8'); tar.create({ file: targetTarPath, cwd: tempPath, gzip: true, sync: true, }, ["package"]); diff --git a/packages/blerf/src/commands/bundle.ts b/packages/blerf/src/commands/bundle.ts index 324ca58..f7190f5 100644 --- a/packages/blerf/src/commands/bundle.ts +++ b/packages/blerf/src/commands/bundle.ts @@ -23,9 +23,7 @@ export class BundleEnumerator extends PackageEnumerator { } protected async processPackage(packagePath: string, packageJson: any, packages: PackagesType): Promise { - console.log("blerf: bundling node_modules"); - - // NOTE: assuming file name of tarball; can also get it from the output of npm pack + console.log("blerf: bundling", packageJson.name); const tempPath = fs.mkdtempSync(path.join(os.tmpdir(), "blerf-")); const artifactPackTarPath = path.join(this.artifactPackPath, packageJson.name + "-" + packageJson.version + ".tgz"); const artifactTarPath = path.join(this.artifactDeployPath, packageJson.name + "-" + packageJson.version + ".tgz"); diff --git a/packages/blerf/src/commands/pack.ts b/packages/blerf/src/commands/pack.ts index 5d690f2..8461d09 100644 --- a/packages/blerf/src/commands/pack.ts +++ b/packages/blerf/src/commands/pack.ts @@ -24,46 +24,36 @@ export class PackEnumerator extends PackageEnumerator { } protected async processPackage(packagePath: string, packageJson: any, packages: PackagesType): Promise { + console.log("blerf: packing and patching", packageJson.name); childProcess.execSync("npm pack", {stdio: 'inherit', cwd: packagePath}); - console.log("blerf: patching project references"); - - // NOTE: assuming file name of tarball; can also get it from the output of npm pack const sourcePackageTarPath = path.join(packagePath, packageJson.name + "-" + packageJson.version + ".tgz"); const tempPath = fs.mkdtempSync(path.join(os.tmpdir(), "blerf-")); - const artifactPackTarPath = path.join(this.artifactPackPath, packageJson.name + "-" + packageJson.version + ".tgz"); fs.mkdirSync(this.artifactPackPath, { recursive: true }); try { tar.extract({ file: sourcePackageTarPath, cwd: tempPath, sync: true }); - this.patchPackageJson(packagePath, path.join(tempPath, "package", "package.json"), path.resolve(this.artifactPackPath), packages); + + const packageJsonPath = path.join(tempPath, "package", "package.json"); + const packageJson = this.readPackageJson(packageJsonPath); if (this.isDeploy) { + const artifactPackFullPath = path.resolve(this.artifactPackPath); + this.rewriteProjectReferencesFullPathVersion(artifactPackFullPath, packageJson.dependencies, packages); + this.rewriteProjectReferencesFullPathVersion(artifactPackFullPath, packageJson.devDependencies, packages); fs.copyFileSync(path.join(packagePath, "package-lock.json"), path.join(tempPath, "package", "package-lock.json")); + } else { + this.rewriteProjectReferencesVersion(packageJson.dependencies, packages); + this.rewriteProjectReferencesVersion(packageJson.devDependencies, packages); } + + this.trimPackageJson(packageJson); + fs.writeFileSync(packageJsonPath, stringifyPackage(packageJson), 'utf8'); tar.create({ file: artifactPackTarPath, cwd: tempPath, gzip: true, sync: true, }, ["package"]); } finally { fs.unlinkSync(sourcePackageTarPath); this.rimraf(tempPath); } } - - private patchPackageJson(packagePath: string, packageJsonPath: string, artifactPackFullPath: string, packages: PackagesType) { - // Resolve all file:-based dependencies to explicit versions - const packageJson = this.readPackageJson(packageJsonPath); - if (this.isDeploy) { - this.rewriteProjectReferencesFullPathVersion(artifactPackFullPath, packageJson.dependencies, packages); - this.rewriteProjectReferencesFullPathVersion(artifactPackFullPath, packageJson.devDependencies, packages); - } else { - this.rewriteProjectReferencesVersion(packageJson.dependencies, packages); - this.rewriteProjectReferencesVersion(packageJson.devDependencies, packages); - } - - // Remove stuff not needed in "binary" packge - delete packageJson.scripts; - delete packageJson.blerf; - delete packageJson.devDependencies; - fs.writeFileSync(packageJsonPath, stringifyPackage(packageJson), 'utf8'); - } } diff --git a/packages/blerf/src/packageEnumerator.ts b/packages/blerf/src/packageEnumerator.ts index 832f16c..4c64120 100644 --- a/packages/blerf/src/packageEnumerator.ts +++ b/packages/blerf/src/packageEnumerator.ts @@ -166,5 +166,13 @@ export abstract class PackageEnumerator { } } + protected trimPackageJson(packageJson: any) { + // Remove stuff not needed in "binary" packge + // TODO: remove everything except known keys + delete packageJson.scripts; + delete packageJson.blerf; + delete packageJson.devDependencies; + } + protected abstract async processPackage(packagePath: string, packageJson: any, packages: PackagesType): Promise; }