Skip to content

Commit

Permalink
feat(vite-node): include debug
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 13, 2022
1 parent 00e5e39 commit ed3374f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 103 deletions.
2 changes: 2 additions & 0 deletions packages/vite-node/package.json
Expand Up @@ -66,9 +66,11 @@
"kolorist": "^1.5.1",
"mlly": "^0.5.2",
"pathe": "^0.2.0",
"debug": "^4.3.4",
"vite": "^2.9.8"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"cac": "^6.7.12",
"rollup": "^2.72.1"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/vite-node/src/client.ts
Expand Up @@ -3,9 +3,13 @@ import { fileURLToPath, pathToFileURL } from 'url'
import vm from 'vm'
import { dirname, extname, isAbsolute, resolve } from 'pathe'
import { isNodeBuiltin } from 'mlly'
import createDebug from 'debug'
import { isPrimitive, normalizeModuleId, normalizeRequestId, slash, toFilePath } from './utils'
import type { ModuleCache, ViteNodeRunnerOptions } from './types'

const debugExecute = createDebug('vite-node:client:execute')
const debugNative = createDebug('vite-node:client:native')

export const DEFAULT_REQUEST_STUBS = {
'/@vite/client': {
injectQuery: (id: string) => id,
Expand Down Expand Up @@ -146,6 +150,7 @@ export class ViteNodeRunner {
// eslint-disable-next-line prefer-const
let { code: transformed, externalize } = await this.options.fetchModule(id)
if (externalize) {
debugNative(externalize)
const mod = await this.interopedImport(externalize)
this.moduleCache.set(fsPath, { exports: mod })
return mod
Expand Down Expand Up @@ -194,6 +199,9 @@ export class ViteNodeRunner {
__dirname: dirname(__filename),
})

debugExecute(__filename)

// remove shebang
if (transformed[0] === '#')
transformed = transformed.replace(/^\#\!.*/, s => ' '.repeat(s.length))

Expand Down
5 changes: 5 additions & 0 deletions packages/vite-node/src/server.ts
@@ -1,11 +1,14 @@
import { join } from 'pathe'
import type { TransformResult, ViteDevServer } from 'vite'
import createDebug from 'debug'
import type { FetchResult, RawSourceMap, ViteNodeResolveId, ViteNodeServerOptions } from './types'
import { shouldExternalize } from './externalize'
import { toFilePath, withInlineSourcemap } from './utils'

export * from './externalize'

const debugRequest = createDebug('vite-node:server:request')

// store the original reference to avoid it been mocked
const RealDate = Date

Expand Down Expand Up @@ -104,6 +107,8 @@ export class ViteNodeServer {
}

private async _transformRequest(id: string) {
debugRequest(id)

let result: TransformResult | null = null

if (this.getTransformMode(id) === 'web') {
Expand Down
72 changes: 72 additions & 0 deletions packages/vitest/LICENSE.md
Expand Up @@ -427,6 +427,33 @@ Repository: git@github.com:moxystudio/node-cross-spawn.git
---------------------------------------

## debug
License: MIT
By: Josh Junon, TJ Holowaychuk, Nathan Rajlich, Andrew Rhyne
Repository: git://github.com/debug-js/debug.git

> (The MIT License)
>
> Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
> Copyright (c) 2018-2021 Josh Junon
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software
> and associated documentation files (the 'Software'), to deal in the Software without restriction,
> including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
> and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
> subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial
> portions of the Software.
>
> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
> LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
> WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## diff
License: BSD-3-Clause
Repository: git://github.com/kpdecker/jsdiff.git
Expand Down Expand Up @@ -1267,6 +1294,34 @@ Repository: unjs/mlly
---------------------------------------

## ms
License: MIT
Repository: zeit/ms

> The MIT License (MIT)
>
> Copyright (c) 2016 Zeit, Inc.
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
---------------------------------------

## natural-compare
License: MIT
By: Lauri Rooden
Expand Down Expand Up @@ -1892,6 +1947,23 @@ Repository: sindresorhus/strip-final-newline
---------------------------------------

## supports-color
License: MIT
By: Sindre Sorhus
Repository: chalk/supports-color

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## to-regex-range
License: MIT
By: Jon Schlinkert, Rouven Weßling
Expand Down

0 comments on commit ed3374f

Please sign in to comment.