Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass zipGo property to ZISI #4058

Merged
merged 2 commits into from
Jan 19, 2022
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
5 changes: 4 additions & 1 deletion packages/build/src/plugins_core/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const normalizeFunctionConfig = ({ buildDir, functionConfig = {}, isRunningLocal
includedFiles: functionConfig.included_files,
includedFilesBasePath: buildDir,
ignoredNodeModules: functionConfig.ignored_node_modules,
schedule: functionConfig.schedule,
Copy link
Contributor

@ehmicky ehmicky Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be added to @netlify/config too?

  • export const FUNCTION_CONFIG_PROPERTIES = new Set([
    'directory',
    'external_node_modules',
    'ignored_node_modules',
    'included_files',
    'node_bundler',
    'schedule',
    ])
  • And
    {
    property: 'functions.*.directory',
    check: (value, key, prevPath) => prevPath[1] === FUNCTIONS_CONFIG_WILDCARD_ALL,
    message: 'must be defined on the main `functions` object.',
    example: () => ({
    functions: { directory: 'my-functions' },
    }),
    },
  • Potentially also
    const normalizeFiles = function (fixtureDir, { name, mainFile, runtime, extension, srcFile, schedule }) {
    const mainFileA = normalize(`${fixtureDir}/${mainFile}`)
    const srcFileA = srcFile === undefined ? {} : { srcFile: normalize(`${fixtureDir}/${srcFile}`) }
    return { name, mainFile: mainFileA, runtime, extension, schedule, ...srcFileA }
    }

Edit: Oops, disregard this comment. I realized this configuration is only set by us, not by users. 👍


// When the user selects esbuild as the Node bundler, we still want to use
// the legacy ZISI bundler as a fallback. Rather than asking the user to
Expand All @@ -37,7 +38,9 @@ const normalizeFunctionConfig = ({ buildDir, functionConfig = {}, isRunningLocal
// build process.
rustTargetDirectory: isRunningLocally ? undefined : resolve(buildDir, '.netlify', 'rust-functions-cache', '[name]'),

schedule: functionConfig.schedule,
// Go functions should be zipped only when building locally. When running in
// buildbot, the Go API client will handle the zipping.
zipGo: isRunningLocally ? true : undefined,
})

const getZisiParameters = ({
Expand Down
19 changes: 13 additions & 6 deletions packages/build/tests/core/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ test.serial(`Doesn't fail build for ES module function if feature flag is off`,
t.false(callArgs[2].featureFlags.defaultEsModulesToEsbuild)
})

test.serial('Passes the right base path properties to zip-it-and-ship-it', async (t) => {
test.serial('Passes the right properties to zip-it-and-ship-it', async (t) => {
// eslint-disable-next-line import/no-named-as-default-member
const mockZipFunctions = sinon.stub().resolves()
// eslint-disable-next-line import/no-named-as-default-member
Expand All @@ -343,17 +343,24 @@ test.serial('Passes the right base path properties to zip-it-and-ship-it', async
const fixtureDir = join(FIXTURES_DIR, fixtureName)

await runFixture(t, fixtureName, { snapshot: false })
await runFixture(t, fixtureName, { flags: { mode: 'buildbot' }, snapshot: false })

stub.restore()

t.is(mockZipFunctions.callCount, 1)
t.is(mockZipFunctions.callCount, 2)

// eslint-disable-next-line prefer-destructuring
const params1 = mockZipFunctions.firstCall.args[2]

t.is(params1.basePath, fixtureDir)
t.true(params1.config['*'].zipGo)
t.is(params1.config['*'].includedFilesBasePath, fixtureDir)
t.is(params1.repositoryRoot, fixtureDir)

// eslint-disable-next-line prefer-destructuring
const { basePath, config, repositoryRoot } = mockZipFunctions.firstCall.args[2]
const params2 = mockZipFunctions.secondCall.args[2]

t.is(basePath, fixtureDir)
t.is(config['*'].includedFilesBasePath, fixtureDir)
t.is(repositoryRoot, fixtureDir)
t.is(params2.config['*'].zipGo, undefined)
})

/* eslint-disable max-statements, no-magic-numbers */
Expand Down