diff --git a/package-lock.json b/package-lock.json index e9e658827..2b4059328 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@babel/parser": "^7.15.7", "@netlify/esbuild": "^0.13.6", - "@vercel/nft": "^0.15.1", + "@vercel/nft": "^0.17.0", "archiver": "^5.3.0", "array-flat-polyfill": "^1.0.1", "common-path-prefix": "^3.0.0", @@ -1482,9 +1482,9 @@ } }, "node_modules/@vercel/nft": { - "version": "0.15.1", - "resolved": "https://registry.npmjs.org/@vercel/nft/-/nft-0.15.1.tgz", - "integrity": "sha512-ehD1bgCG9sZliAHku2fc1L+jKLad4wS+9HHWiIs4HT4SysA/JFSXRrfWuA+INumzuaFqrOKs3vQeLVhZ4o8lTw==", + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/@vercel/nft/-/nft-0.17.0.tgz", + "integrity": "sha512-dXz4RAODHpEPl1Yfzk1UfVpZfqhY9O80FdI9sF/Hw2bXWj5022U9Z46VpdNYe8pDluSuQv/JUo/ZP4/OcsfDRw==", "dependencies": { "@mapbox/node-pre-gyp": "^1.0.5", "acorn": "^8.3.0", @@ -13687,9 +13687,9 @@ } }, "@vercel/nft": { - "version": "0.15.1", - "resolved": "https://registry.npmjs.org/@vercel/nft/-/nft-0.15.1.tgz", - "integrity": "sha512-ehD1bgCG9sZliAHku2fc1L+jKLad4wS+9HHWiIs4HT4SysA/JFSXRrfWuA+INumzuaFqrOKs3vQeLVhZ4o8lTw==", + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/@vercel/nft/-/nft-0.17.0.tgz", + "integrity": "sha512-dXz4RAODHpEPl1Yfzk1UfVpZfqhY9O80FdI9sF/Hw2bXWj5022U9Z46VpdNYe8pDluSuQv/JUo/ZP4/OcsfDRw==", "requires": { "@mapbox/node-pre-gyp": "^1.0.5", "acorn": "^8.3.0", diff --git a/package.json b/package.json index cd4dd3368..5ff3a00bb 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dependencies": { "@babel/parser": "^7.15.7", "@netlify/esbuild": "^0.13.6", - "@vercel/nft": "^0.15.1", + "@vercel/nft": "^0.17.0", "archiver": "^5.3.0", "array-flat-polyfill": "^1.0.1", "common-path-prefix": "^3.0.0", diff --git a/src/runtimes/node/bundlers/nft/index.ts b/src/runtimes/node/bundlers/nft/index.ts index 9d80dd9d4..70fe20196 100644 --- a/src/runtimes/node/bundlers/nft/index.ts +++ b/src/runtimes/node/bundlers/nft/index.ts @@ -49,13 +49,16 @@ const bundle: BundleFunction = async ({ const filteredIncludedPaths = filterExcludedPaths([...dependencyPaths, ...includedFilePaths], excludedPaths) const dirnames = filteredIncludedPaths.map((filePath) => normalize(dirname(filePath))).sort() + // Sorting the array to make the checksum deterministic. + const srcFiles = [...filteredIncludedPaths, ...transpilation.keys()].sort() + return { aliases: transpilation, basePath: getBasePath(dirnames), cleanupFunction, inputs: dependencyPaths, mainFile, - srcFiles: [...filteredIncludedPaths, ...transpilation.keys()], + srcFiles, } } @@ -113,7 +116,9 @@ const traceFilesAndTranspile = async function ({ } }, }) - const normalizedDependencyPaths = dependencyPaths.map((path) => (basePath ? resolve(basePath, path) : resolve(path))) + const normalizedDependencyPaths = [...dependencyPaths].map((path) => + basePath ? resolve(basePath, path) : resolve(path), + ) // We look at the cache object to find any paths corresponding to ESM files. const esmPaths = [...(cache.analysisCache?.entries() || [])].filter(([, { isESM }]) => isESM).map(([path]) => path) @@ -150,7 +155,9 @@ const getSrcFiles: GetSrcFilesFunction = async function ({ basePath, config, mai includedFilesBasePath, ) const { fileList: dependencyPaths } = await nodeFileTrace([mainFile], { base: basePath, ignore: ignoreFunction }) - const normalizedDependencyPaths = dependencyPaths.map((path) => (basePath ? resolve(basePath, path) : resolve(path))) + const normalizedDependencyPaths = [...dependencyPaths].map((path) => + basePath ? resolve(basePath, path) : resolve(path), + ) const includedPaths = filterExcludedPaths([...normalizedDependencyPaths, ...includedFilePaths], excludedPaths) return includedPaths diff --git a/tests/main.js b/tests/main.js index 424bed3ab..e6bae7113 100644 --- a/tests/main.js +++ b/tests/main.js @@ -781,46 +781,45 @@ testMany( basePath: fixtureDir, }) const bundler = options.config['*'].nodeBundler - const functions = await listFunctionsFiles(fixtureDir, opts) - const sortedFunctions = sortOn(functions, 'mainFile') - t.deepEqual( - sortedFunctions, - [ - { name: 'five', mainFile: 'five/index.ts', runtime: 'js', extension: '.ts', srcFile: 'five/index.ts' }, - - bundler === 'nft' && { - name: 'five', - mainFile: 'five/index.ts', - runtime: 'js', - extension: '.ts', - srcFile: 'five/util.ts', - }, + const files = await listFunctionsFiles(fixtureDir, opts) + const sortedFiles = sortOn(files, ['mainFile', 'srcFile']) + const expectedFiles = [ + { name: 'five', mainFile: 'five/index.ts', runtime: 'js', extension: '.ts', srcFile: 'five/index.ts' }, + + bundler === 'nft' && { + name: 'five', + mainFile: 'five/index.ts', + runtime: 'js', + extension: '.ts', + srcFile: 'five/util.ts', + }, - { - name: 'four', - mainFile: 'four.js/four.js.js', - runtime: 'js', - extension: '.js', - srcFile: 'four.js/four.js.js', - }, - { name: 'one', mainFile: 'one/index.js', runtime: 'js', extension: '.js', srcFile: 'one/index.js' }, - { name: 'test', mainFile: 'test', runtime: 'go', extension: '', srcFile: 'test' }, - { name: 'test', mainFile: 'test.js', runtime: 'js', extension: '.js', srcFile: 'test.js' }, - { name: 'test', mainFile: 'test.zip', runtime: 'js', extension: '.zip', srcFile: 'test.zip' }, - - (bundler === undefined || bundler === 'nft') && { - name: 'two', - mainFile: 'two/two.js', - runtime: 'js', - extension: '.json', - srcFile: 'two/three.json', - }, + { + name: 'four', + mainFile: 'four.js/four.js.js', + runtime: 'js', + extension: '.js', + srcFile: 'four.js/four.js.js', + }, + { name: 'one', mainFile: 'one/index.js', runtime: 'js', extension: '.js', srcFile: 'one/index.js' }, + { name: 'test', mainFile: 'test', runtime: 'go', extension: '', srcFile: 'test' }, + { name: 'test', mainFile: 'test.js', runtime: 'js', extension: '.js', srcFile: 'test.js' }, + { name: 'test', mainFile: 'test.zip', runtime: 'js', extension: '.zip', srcFile: 'test.zip' }, + + (bundler === undefined || bundler === 'nft') && { + name: 'two', + mainFile: 'two/two.js', + runtime: 'js', + extension: '.json', + srcFile: 'two/three.json', + }, - { name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js', srcFile: 'two/two.js' }, - ] - .filter(Boolean) - .map(normalizeFiles.bind(null, fixtureDir)), - ) + { name: 'two', mainFile: 'two/two.js', runtime: 'js', extension: '.js', srcFile: 'two/two.js' }, + ] + .filter(Boolean) + .map(normalizeFiles.bind(null, fixtureDir)) + + t.deepEqual(sortedFiles, sortOn(expectedFiles, ['mainFile', 'srcFile'])) }, )