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

fix: disable ESM transpilation in NFT #786

Merged
merged 2 commits into from
Nov 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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