Skip to content
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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/aio-lib-runtime",
"version": "7.4.2",
"version": "7.5.0",
"license": "Apache-2.0",
"main": "src/index.js",
"bugs": {
Expand All @@ -14,7 +14,7 @@
"@adobe/aio-lib-core-logging": "^3",
"@adobe/aio-lib-core-networking": "^5",
"@adobe/aio-lib-env": "^3.0.0",
"archiver": "^7.0.1",
"archiver": "^8.0.0",
"dependency-tree": "^11.0.1",
"execa": "^4.0.3",
"folder-hash": "^4.0.4",
Expand All @@ -39,6 +39,7 @@
"@types/node-fetch": "^2.5.4",
"babel-runtime": "^6.26.0",
"codecov": "^3.5.0",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"eol": "^0.9.1",
"eslint": "^8.57.1",
Expand Down Expand Up @@ -70,7 +71,7 @@
"beautify": "eslint src test e2e --fix",
"test": "npm run unit-tests && npm run lint",
"typings": "jsdoc -t node_modules/tsd-jsdoc/dist -r src -d .",
"unit-tests": "jest --ci",
"unit-tests": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --ci",
"version": "npm run generate-docs && git add README.md"
}
}
7 changes: 4 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const yaml = require('js-yaml')
const { createFetch } = require('@adobe/aio-lib-core-networking')
const globby = require('globby')
const path = require('path')
const archiver = require('archiver')
// archiver 8 is ESM-only and exposes a class API; load it lazily via dynamic import from this CommonJS module
// this is a static list that comes from here: https://developer.adobe.com/runtime/docs/guides/reference/runtimes/
const SupportedRuntimes = ['sequence', 'blackbox', 'nodejs:10', 'nodejs:12', 'nodejs:14', 'nodejs:16', 'nodejs:18', 'nodejs:20', 'nodejs:22', 'nodejs:24', 'nodejs:26']
const { HttpProxyAgent } = require('http-proxy-agent')
Expand Down Expand Up @@ -451,8 +451,9 @@ function getActionEntryFile (pkgJsonPath) {
* @param {boolean} pathInZip internal path in zip
* @returns {Promise} returns with a blank promise when done
*/
function zip (filePath, out, pathInZip = false) {
async function zip (filePath, out, pathInZip = false) {
aioLogger.debug(`Creating zip of file/folder ${filePath}`)
const { ZipArchive } = await import('archiver') // eslint-disable-line node/no-unsupported-features/es-syntax

return new Promise((resolve, reject) => {
let stats
Expand All @@ -463,7 +464,7 @@ function zip (filePath, out, pathInZip = false) {
}

const stream = fs.createWriteStream(out)
const archive = archiver('zip', { zlib: { level: 9 } })
const archive = new ZipArchive({ zlib: { level: 9 } })
stream.on('close', () => resolve())
archive.pipe(stream)
archive.on('error', err => reject(err))
Expand Down
33 changes: 19 additions & 14 deletions test/__mocks__/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@ const mockArchive = () => {
return ret
}

const archiver = function (...args) {
mockConstructor(args)
return mockArchive()
// archiver 8 exposes a class API (`new ZipArchive(options)`); mock it as a class whose
// constructor returns the fake archive stream, preserving the previous mock behavior.
class ZipArchive {
constructor (...args) {
mockConstructor(args)
return mockArchive()
}
}

archiver.mockFile = mockFile
archiver.mockDirectory = mockDirectory
archiver.mockConstructor = mockConstructor
archiver.setFakeError = function (e) { fakeError = e }
archiver.mockReset = () => {
mockConstructor.mockReset()
mockDirectory.mockReset()
mockFile.mockReset()
fakeError = false
module.exports = {
ZipArchive,
mockFile,
mockDirectory,
mockConstructor,
setFakeError: function (e) { fakeError = e },
mockReset: () => {
mockConstructor.mockReset()
mockDirectory.mockReset()
mockFile.mockReset()
fakeError = false
}
}

module.exports = archiver
4 changes: 2 additions & 2 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const fs = require('fs-extra')
const cloneDeep = require('lodash.clonedeep')
const os = require('os')
const path = require('path')
const archiver = require('archiver')
const archiver = require('./__mocks__/archiver') // eslint-disable-line jest/no-mocks-import
const networking = require('@adobe/aio-lib-core-networking')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-lib-runtime:utils', { provider: 'debug', level: process.env.LOG_LEVEL })
networking.createFetch = jest.fn()
const mockFetch = jest.fn()
networking.createFetch.mockReturnValue(mockFetch)
jest.mock('archiver')
jest.unstable_mockModule('archiver', () => archiver)
jest.mock('@adobe/aio-lib-core-networking')
jest.mock('globby')

Expand Down
Loading