Skip to content

Commit

Permalink
feat: enable to remove shebang
Browse files Browse the repository at this point in the history
  • Loading branch information
togami2864 committed May 1, 2022
1 parent ac9645c commit e0210a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/vite-node/src/cli.ts
Expand Up @@ -3,6 +3,7 @@ import { dim, red } from 'kolorist'
import { createServer } from 'vite'
import { ViteNodeServer } from './server'
import { ViteNodeRunner } from './client'
import { RemoveShebangPlugin } from './plugins/removeShebang'

const argv = minimist(process.argv.slice(2), {
'alias': {
Expand Down Expand Up @@ -70,6 +71,7 @@ async function run(options: CliOptions = {}) {
logLevel: 'error',
configFile: options.config,
root: options.root,
plugins: [RemoveShebangPlugin()],
})
await server.pluginContainer.buildStart({})

Expand Down
13 changes: 13 additions & 0 deletions packages/vite-node/src/plugins/removeShebang.ts
@@ -0,0 +1,13 @@
import type { Plugin } from 'vite'

// issue #1175:remove shebeng from code (most often #!/usr/bin/env node)
// vite recognizes the shebang as a comment and needs to be removed because it causes a parse error.
export const RemoveShebangPlugin = (): Plugin => {
return {
name: 'vitest:remove-shebang-plugin',
enforce: 'pre',
transform(code) {
return code.replace(/^\#\!.*/, '')
},
}
}

0 comments on commit e0210a4

Please sign in to comment.