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

Commit

Permalink
fix: use unixify for checkIsInternalFunction, config, bundler, module…
Browse files Browse the repository at this point in the history
… and resolve
  • Loading branch information
khendrikse committed Jan 11, 2023
1 parent 2325485 commit 731567f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/runtimes/node/bundlers/esbuild/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { basename, dirname, extname, resolve, join } from 'path'

import { build, Metafile } from '@netlify/esbuild'
import { tmpName } from 'tmp-promise'
import unixify from 'unixify'

import type { FunctionConfig } from '../../../../config.js'
import { FeatureFlags } from '../../../../feature_flags.js'
Expand Down Expand Up @@ -89,7 +90,7 @@ export const bundleJsFile = async function ({
// esbuild will format `sources` relative to the sourcemap file, which lives
// in `destFolder`. We use `sourceRoot` to establish that relation. They are
// URLs, not paths, so even on Windows they should use forward slashes.
const sourceRoot = targetDirectory.replace(/\\/g, '/')
const sourceRoot = unixify(targetDirectory)

// Configuring the output format of esbuild. The `includedFiles` array we get
// here contains additional paths to include with the bundle, like the path
Expand Down
5 changes: 2 additions & 3 deletions src/runtimes/node/bundlers/zisi/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { pathExists } from 'path-exists'
// @ts-expect-error types are wrong
import { async as asyncResolve } from 'resolve'
import semver from 'semver'
import unixify from 'unixify'

// The types do not include the mjs api of resolve
const resolveLib = asyncResolve as typeof import('resolve')

const require = createRequire(import.meta.url)

const BACKSLASH_REGEXP = /\\/g

// Find the path to a module's `package.json`
// We need to use `resolve` instead of `require.resolve()` because:
// - it is async
Expand Down Expand Up @@ -107,7 +106,7 @@ const resolvePackageFallback = async function (moduleName: string, baseDirs: str
const isPackageDir = async function (moduleName: string, dir: string) {
// Need to use `endsWith()` to take into account `@scope/package`.
// Backslashes need to be converted for Windows.
if (!dir.replace(BACKSLASH_REGEXP, '/').endsWith(moduleName) || !(await pathExists(`${dir}/package.json`))) {
if (!unixify(dir).endsWith(moduleName) || !(await pathExists(`${dir}/package.json`))) {
return
}

Expand Down
7 changes: 3 additions & 4 deletions src/runtimes/node/utils/module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import requirePackageName from 'require-package-name'

// Windows path normalization
const BACKSLASH_REGEXP = /\\/g
import unixify from 'unixify'

// When doing require("moduleName/file/path"), only keep `moduleName`
export const getModuleName = function (dependency: string): string {
const dependencyA = dependency.replace(BACKSLASH_REGEXP, '/')
// Windows path normalization
const dependencyA = unixify(dependency)
const moduleName = requirePackageName(dependencyA)

return moduleName
Expand Down
9 changes: 3 additions & 6 deletions src/utils/check_is_internal_function.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { FUNCTIONS_INTERNAL_DIR } from '../runtimes/constants.js'
import unixify from 'unixify'

export const checkIsInternalFunction = (srcDir = '') => {
const BACKSLASH_REGEXP = /\\/g
import { FUNCTIONS_INTERNAL_DIR } from '../runtimes/constants.js'

// Backslashes need to be converted for Windows.
return srcDir?.replace(BACKSLASH_REGEXP, '/').includes(FUNCTIONS_INTERNAL_DIR)
}
export const checkIsInternalFunction = (srcDir = '') => unixify(srcDir)?.includes(FUNCTIONS_INTERNAL_DIR)

0 comments on commit 731567f

Please sign in to comment.