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

feat: add sourcemap support to NFT #818

Merged
merged 3 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"nyc": "^15.0.0",
"sinon": "^12.0.0",
"sort-on": "^4.1.1",
"source-map-support": "^0.5.20",
"throat": "^6.0.1",
"typescript": "^4.4.3"
},
Expand Down
1 change: 1 addition & 0 deletions src/runtimes/node/bundlers/nft/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const transpile = async (path: string, config: FunctionConfig) => {
format: 'cjs',
logLevel: 'error',
platform: 'node',
sourcemap: Boolean(config.nodeSourcemap),
target: [nodeTarget],
write: false,
})
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/esm-throwing-error/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parserOptions": { "sourceType": "module" }
}
5 changes: 5 additions & 0 deletions tests/fixtures/esm-throwing-error/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const handler = () => {
throw new Error('uh-oh')
}

export { handler }
28 changes: 28 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const sortOn = require('sort-on')
const { dir: getTmpDir, tmpName } = require('tmp-promise')
const unixify = require('unixify')

require('source-map-support').install()

// We must require this file first because we need to stub it before the main
// functions are required.
// eslint-disable-next-line import/order
Expand Down Expand Up @@ -2350,3 +2352,29 @@ testMany(
files.every(({ size }) => Number.isInteger(size) && size > 0)
},
)

test('Generates a sourcemap for any transpiled files when `nodeSourcemap: true`', async (t) => {
const fixtureName = 'esm-throwing-error'
const basePath = join(FIXTURES_DIR, fixtureName)
const { files } = await zipFixture(t, fixtureName, {
opts: {
archiveFormat: 'none',
basePath,
config: { '*': { nodeBundler: 'nft', nodeSourcemap: true } },
featureFlags: { nftTranspile: true },
},
})
const func = require(join(files[0].path, 'function.js'))

try {
func.handler()

t.fail()
} catch (error) {
const filePath = join(files[0].path, 'src', 'tests', 'fixtures', fixtureName, 'function.js')

// Asserts that the line/column of the error match the position of the
// original source file, not the transpiled one.
t.true(error.stack.includes(`${filePath}:2:9`))
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

}
})