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

Commit

Permalink
fix: disable ESM transpilation in NFT (#786)
Browse files Browse the repository at this point in the history
* fix: disable ESM transpilation in NFT

* refactor: remove transpilation
  • Loading branch information
eduardoboucas committed Nov 2, 2021
1 parent c2f4d3d commit c15c3b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
18 changes: 2 additions & 16 deletions src/runtimes/node/bundlers/nft/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import type { GetSrcFilesFunction } from '../../../runtime'
import { getBasePath } from '../../utils/base_path'
import { filterExcludedPaths, getPathsOfIncludedFiles } from '../../utils/included_files'

import { getPatchedESMPackages } from './es_modules'
import { transpileMany } from './transpile'

// Paths that will be excluded from the tracing process.
const ignore = ['node_modules/aws-sdk/**']

Expand All @@ -32,7 +29,7 @@ const bundle: BundleFunction = async ({
includedFiles,
includedFilesBasePath || basePath,
)
const { paths: dependencyPaths, rewrites } = await traceFilesAndTranspile({
const { paths: dependencyPaths } = await traceFilesAndTranspile({
basePath: repositoryRoot,
config,
mainFile,
Expand All @@ -48,7 +45,6 @@ const bundle: BundleFunction = async ({
basePath: getBasePath(dirnames),
inputs: dependencyPaths,
mainFile,
rewrites,
srcFiles,
}
}
Expand All @@ -62,7 +58,6 @@ const ignoreFunction = (path: string) => {

const traceFilesAndTranspile = async function ({
basePath,
config,
mainFile,
pluginsModulesPath,
}: {
Expand All @@ -72,11 +67,7 @@ const traceFilesAndTranspile = async function ({
pluginsModulesPath?: string
}) {
const fsCache: FsCache = {}
const {
fileList: dependencyPaths,
esmFileList,
reasons,
} = await nodeFileTrace([mainFile], {
const { fileList: dependencyPaths } = await nodeFileTrace([mainFile], {
base: basePath,
ignore: ignoreFunction,
readFile: async (path: string) => {
Expand Down Expand Up @@ -112,14 +103,9 @@ const traceFilesAndTranspile = async function ({
const normalizedDependencyPaths = [...dependencyPaths].map((path) =>
basePath ? resolve(basePath, path) : resolve(path),
)
const esmPaths = [...esmFileList].map((path) => (basePath ? resolve(basePath, path) : resolve(path)))
const transpiledPaths = await transpileMany(esmPaths, config)
const patchedESMPackages = await getPatchedESMPackages(esmFileList, reasons, fsCache, basePath)
const rewrites = new Map([...transpiledPaths, ...patchedESMPackages])

return {
paths: normalizedDependencyPaths,
rewrites,
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ testMany(

testMany(
'Can bundle functions with `.js` extension using ES Modules and feature flag ON',
['bundler_esbuild', 'bundler_default', 'bundler_nft'],
['bundler_esbuild', 'bundler_default', 'todo:bundler_nft'],
async (options, t) => {
const opts = merge(options, { featureFlags: { defaultEsModulesToEsbuild: true } })

Expand All @@ -423,7 +423,7 @@ testMany(

testMany(
'Can bundle functions with `.js` extension using ES Modules and feature flag OFF',
['bundler_esbuild', 'bundler_default', 'bundler_nft'],
['bundler_esbuild', 'bundler_default', 'todo:bundler_nft'],
async (options, t) => {
const fixtureName = 'local-require-esm'
const opts = merge(options, {
Expand Down

1 comment on commit c15c3b5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⏱ Benchmark results

largeDepsEsbuild: 7.1s

largeDepsNft: 44.1s

Please sign in to comment.