From 815371bf701c64869eebbf7799ed33a426eddb9d Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Sat, 29 Jun 2024 10:47:44 -0300 Subject: [PATCH] Build the zip artifact in dist/ instead of dist/[browser] (#120) --- programs/cli/spec/build.spec.ts | 21 +++++++++++---------- programs/develop/steps/generateZip.ts | 7 +++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/programs/cli/spec/build.spec.ts b/programs/cli/spec/build.spec.ts index f6e327c8..11cdef99 100644 --- a/programs/cli/spec/build.spec.ts +++ b/programs/cli/spec/build.spec.ts @@ -6,6 +6,7 @@ // ╚═════╝╚══════╝╚═╝ import path from 'path' +import fs from 'fs' import {ALL_TEMPLATES, DEFAULT_TEMPLATE, BROWSERS} from './fixtures/constants' import { extensionProgram, @@ -93,14 +94,18 @@ describe('extension build', () => { `builds and zips the source files of an extension created via "$name" template`, async (template) => { const extensionPath = path.join(__dirname, 'fixtures', template.name) + const outputPath = path.join( + __dirname, + 'fixtures', + template.name, + 'dist' + ) await extensionProgram(`build ${extensionPath} --zip-source`) expect( - distFileExists( - template.name, - BROWSERS[0], - `${template.name}-1.0-source.zip` + fs.existsSync( + path.join(outputPath, `${template.name}-1.0-source.zip`) ) ).toBeTruthy() }, @@ -108,7 +113,7 @@ describe('extension build', () => { ) it.each([DEFAULT_TEMPLATE])( - `builds and zips the source files of an extension created via "$name" template with a custom output name using the --zip-filename flag`, + `builds and zips the distribution files of an extension created via "$name" template with a custom output name using the --zip-filename flag`, async (template) => { const extensionPath = path.join(__dirname, 'fixtures', template.name) @@ -117,11 +122,7 @@ describe('extension build', () => { ) expect( - distFileExists( - template.name, - BROWSERS[0], - `${template.name}-nice.zip` - ) + distFileExists(template.name, BROWSERS[0], `${template.name}-nice.zip`) ).toBeTruthy() }, 50000 diff --git a/programs/develop/steps/generateZip.ts b/programs/develop/steps/generateZip.ts index ba85f1d4..61b7c89a 100644 --- a/programs/develop/steps/generateZip.ts +++ b/programs/develop/steps/generateZip.ts @@ -72,7 +72,8 @@ export default function generateZip( {browser = 'chrome', ...options}: BuildOptions ) { try { - const outputDir = path.join(projectDir, 'dist', browser) + const distDir = path.join(projectDir, 'dist') + const outputDir = path.join(distDir, browser) // We collect data from the projectDir if the user wants to zip the source files. const dataDir = options.zipSource ? projectDir : outputDir const manifest: Record = require( @@ -80,8 +81,10 @@ export default function generateZip( ) const name = getPackageName(manifest, options) const ext = getExtensionExtension(browser) + // Dist zips are stored in dist/[browser]/[name].zip const distZipPath = path.join(outputDir, `${name}.${ext}`) - const sourceZipPath = path.join(outputDir, `${name}-source.${ext}`) + // Source zips are stored in dist/[name]-source.zip + const sourceZipPath = path.join(distDir, `${name}-source.${ext}`) const capitalizedBrowser = capitalizeBrowserName(browser) if (options.zipSource) {