From 518f2d5d88c8af5370c68010f2ca447e7587038e Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Mon, 24 Mar 2025 21:17:52 +0800 Subject: [PATCH] Fix locales building (#5693) * always release locales seems to have been broken for a while * make script more verbose * try to fix script * fix again * fix building of locales --- .github/workflows/release.yml | 5 +--- bin/build-bundle.mjs | 16 ++++++++++- private/upload-to-cdn/index.js | 49 +++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3af5f99e..918fb54ea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -93,10 +93,7 @@ jobs: EDGLY_KEY: ${{secrets.EDGLY_KEY}} EDGLY_SECRET: ${{secrets.EDGLY_SECRET}} - name: Upload `@uppy/locales` to CDN if it was released - run: - git diff --exit-code --quiet HEAD^ -- - packages/@uppy/locales/package.json ||corepack yarn run uploadcdn - @uppy/locales + run: corepack yarn run uploadcdn @uppy/locales env: EDGLY_KEY: ${{secrets.EDGLY_KEY}} EDGLY_SECRET: ${{secrets.EDGLY_SECRET}} diff --git a/bin/build-bundle.mjs b/bin/build-bundle.mjs index 19f7a63f8..de673deab 100644 --- a/bin/build-bundle.mjs +++ b/bin/build-bundle.mjs @@ -32,6 +32,15 @@ function buildBundle (srcFile, bundleFile, { minify = true, standalone = '', plu await fs.mkdir(new URL('./uppy/dist', PACKAGES_ROOT), { recursive: true }) +await fs.mkdir(new URL('./@uppy/locales/dist', PACKAGES_ROOT), { recursive: true }) + +const locales = (await fs.readdir(new URL('./@uppy/locales/lib', PACKAGES_ROOT))).flatMap((file) => { + if (file.endsWith('.js')) { + return [file.replace(/\.js$/, '')] + } + return [] +}); + const methods = [ buildBundle( './packages/uppy/src/bundle.ts', @@ -43,7 +52,12 @@ const methods = [ './packages/uppy/dist/uppy.min.js', { standalone: 'Uppy', format: 'iife' }, ), -] + ...locales.map((locale) => buildBundle( + `./packages/@uppy/locales/lib/${locale}.js`, + `./packages/@uppy/locales/dist/${locale}.min.js`, + { standalone: `Uppy Locale ${locale}`, format: 'iife' }, + )), +]; // Add BUNDLE-README.MD methods.push( diff --git a/private/upload-to-cdn/index.js b/private/upload-to-cdn/index.js index 40a7ae35f..8a40a4523 100755 --- a/private/upload-to-cdn/index.js +++ b/private/upload-to-cdn/index.js @@ -49,8 +49,10 @@ from npm and filtering it down to package/dist/ files. * @returns a Map, filename → content */ async function getRemoteDistFiles (packageName, version) { + const package = `${packageName}@${version}` + console.log('Using npm package', package) const files = new Map() - const tarball = await pacote.tarball.stream(`${packageName}@${version}`, stream => pipeline(stream, new tar.Parse())) + const tarball = await pacote.tarball.stream(package, stream => pipeline(stream, new tar.Parse())) tarball.on('entry', (readEntry) => { if (readEntry.path.startsWith('package/dist/')) { @@ -74,18 +76,34 @@ async function getRemoteDistFiles (packageName, version) { * Get local dist/ files by asking npm-packlist what files would be added * to an npm package during publish, and filtering those down to just dist/ files. * - * @param {string} packagePath Base file path of the package, eg. ./packages/@uppy/locales + * @param {string} packageName Name of package, eg. @uppy/locales * @returns a Map, filename → content */ -async function getLocalDistFiles (packagePath) { +async function getLocalDistFiles (packageName) { + // Base file path of the package, eg. ./packages/@uppy/locales + const packagePath = path.join(__dirname, '..', '..', 'packages', packageName) + + console.log('Making local package from', packagePath) + + const prefix = 'dist' + const files = (await packlist({ path: packagePath })) - .filter(f => f.startsWith('dist/')) - .map(f => f.replace(/^dist\//, '')) + .flatMap((f) => { + const prefixSlash = `${prefix}/` + + if (f.startsWith(prefixSlash)) { + const name = f.split(prefixSlash)[1] + if (name.length > 0) { + return [name] + } + } + return [] + }) const entries = await Promise.all( files.map(async (f) => [ f, - await readFile(path.join(packagePath, 'dist', f)), + await readFile(path.join(packagePath, prefix, f)), ]), ) @@ -118,6 +136,8 @@ async function main (packageName, version) { }) const remote = !!version + + console.log('Using', remote ? 'Remote' : 'Local', 'build') if (!remote) { // eslint-disable-next-line import/no-dynamic-require, global-require, no-param-reassign version = require(`../../packages/${packageName}/package.json`).version @@ -131,10 +151,6 @@ async function main (packageName, version) { await delay(3000) } - const packagePath = remote - ? `${packageName}@${version}` - : path.join(__dirname, '..', '..', 'packages', packageName) - // uppy → releases/uppy/ // @uppy/robodog → releases/uppy/robodog/ // @uppy/locales → releases/uppy/locales/ @@ -142,11 +158,11 @@ async function main (packageName, version) { ? packageName.replace(/^@/, '') : 'uppy' - const outputPath = path.posix.join(dirName, `v${version}`) + const s3Dir = path.posix.join(dirName, `v${version}`) const { Contents: existing } = await s3Client.send(new ListObjectsV2Command({ Bucket: AWS_BUCKET, - Prefix: outputPath, + Prefix: s3Dir, })) if (existing?.length > 0) { @@ -160,10 +176,11 @@ async function main (packageName, version) { const files = remote ? await getRemoteDistFiles(packageName, version) - : await getLocalDistFiles(packagePath) + : await getLocalDistFiles(packageName) if (packageName === 'uppy') { - // Create downloadable zip archive + console.log('Creating downloadable zip archive') + const zip = new AdmZip() for (const [filename, buffer] of files.entries()) { zip.addFile(filename, buffer) @@ -172,8 +189,10 @@ async function main (packageName, version) { files.set(`uppy-v${version}.zip`, zip.toBuffer()) } + if (files.size === 0) console.warn('No files to upload') + for (const [filename, buffer] of files.entries()) { - const key = path.posix.join(outputPath, filename) + const key = path.posix.join(s3Dir, filename) console.log(`pushing s3://${AWS_BUCKET}/${key}`) await s3Client.send(new PutObjectCommand({ Bucket: AWS_BUCKET,