Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
feat: include resolved included_files in response of zipFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed May 30, 2022
1 parent eecd8ed commit 55429b0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/runtimes/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GetSrcFilesFunction, Runtime, ZipFunction } from '../runtime.js'
import { getBundler, getDefaultBundler } from './bundlers/index.js'
import { findFunctionsInPaths, findFunctionInPath } from './finder.js'
import { findISCDeclarationsInPath } from './in_source_config/index.js'
import { getFilteredPathsOfIncludedFiles } from './utils/included_files.js'
import { createAliases as createPluginsModulesPathAliases, getPluginsModulesPath } from './utils/plugin_modules_path.js'
import { zipNodeJs } from './utils/zip.js'

Expand Down Expand Up @@ -108,6 +109,10 @@ const zipFunction: ZipFunction = async function ({
bundlerWarnings,
config,
inputs,
includedFiles: await getFilteredPathsOfIncludedFiles(
config.includedFiles || [],
config.includedFilesBasePath || basePath,
),
inSourceConfig,
nativeNodeModules,
nodeModulesWithDynamicImports,
Expand Down
9 changes: 9 additions & 0 deletions src/runtimes/node/utils/included_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export const filterExcludedPaths = (paths: string[], exclude: string[] = []) =>
return excludedPaths
}

export const getFilteredPathsOfIncludedFiles = async (
includedFiles: string[],
basePath?: string,
): Promise<string[]> => {
const { exclude, paths } = await getPathsOfIncludedFiles(includedFiles, basePath)

return filterExcludedPaths(paths, exclude)
}

export const getPathsOfIncludedFiles = async (
includedFiles: string[],
basePath?: string,
Expand Down
1 change: 1 addition & 0 deletions src/runtimes/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface ZipFunctionResult {
bundlerWarnings?: object[]
config: FunctionConfig
inputs?: string[]
includedFiles?: string[]
inSourceConfig?: ISCValues
nativeNodeModules?: object
nodeModulesWithDynamicImports?: string[]
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,24 @@ testMany(
},
)

testMany('Includes includedFiles in the response of zipFunction', ['bundler_default'], async (options, t) => {
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test2' })
const mainFile = join(FIXTURES_DIR, 'node-module-next-image', 'function', 'function.js')
const result = await zipFunction(mainFile, tmpDir, {
...options,
basePath: join(FIXTURES_DIR, 'node-module-next-image'),
config: {
'*': {
nodeBundler: undefined,
includedFiles: ['included/*.js'],
},
},
})

t.true(Array.isArray(result.includedFiles))
t.true(/node-module-next-image[/\\]included[/\\]abc\.js/.test(result.includedFiles[0]))
})

// We persist `package.json` as `package.json.txt` in git. Otherwise ESLint
// tries to load when linting sibling JavaScript files. In this test, we
// temporarily rename it to an actual `package.json`.
Expand Down

0 comments on commit 55429b0

Please sign in to comment.