Skip to content

Commit

Permalink
fix: run deno with --no-config (#128)
Browse files Browse the repository at this point in the history
* fix: run `deno` with `--no-config`

* chore: fix typo

* chore: use `del`

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
eduardoboucas and kodiakhq[bot] committed Sep 19, 2022
1 parent 45cf3b2 commit c5ee57c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion node/formats/eszip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const bundleESZIP = async ({
functions,
importMapURL: importMap.toDataURL(),
}
const flags = ['--allow-all']
const flags = ['--allow-all', '--no-config']

if (!debug) {
flags.push('--quiet')
Expand Down
2 changes: 1 addition & 1 deletion node/formats/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const bundleJS = async ({
const stage2Path = await generateStage2({ distDirectory, functions, fileName: `${buildID}-pre.js` })
const extension = '.js'
const jsBundlePath = join(distDirectory, `${buildID}${extension}`)
const flags = [`--import-map=${importMap.toDataURL()}`]
const flags = [`--import-map=${importMap.toDataURL()}`, '--no-config']

if (!debug) {
flags.push('--quiet')
Expand Down
1 change: 1 addition & 0 deletions node/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const serve = async ({
'--unstable',
`--import-map=${importMap.toDataURL()}`,
'--v8-flags=--disallow-code-generation-from-strings',
'--no-config',
]

if (certificatePath) {
Expand Down
62 changes: 62 additions & 0 deletions test/node/bundler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { promises as fs } from 'fs'
import { join, resolve } from 'path'
import process from 'process'
import { fileURLToPath, pathToFileURL } from 'url'

import test from 'ava'
import del from 'del'
import tmp from 'tmp-promise'

import { BundleError } from '../../node/bundle_error.js'
Expand Down Expand Up @@ -223,3 +225,63 @@ test('Supports import maps with relative paths', async (t) => {

await fs.rmdir(tmpDir.path, { recursive: true })
})

test.serial('Ignores any user-defined `deno.json` files', async (t) => {
const fixtureDir = join(fixturesDir, 'project_1')
const tmpDir = await tmp.dir()
const declarations = [
{
function: 'func1',
path: '/func1',
},
]

// Creating an import map file that rewires the URL of the Deno registry to
// an invalid location.
const importMapFile = await tmp.file()
const importMap = {
imports: {
'https://deno.land/': 'https://black.hole/',
},
}

await fs.writeFile(importMapFile.path, JSON.stringify(importMap))

// Deno configuration files need to be in the current working directory.
// There's not a great way for us to set the working directory of the `deno`
// process that we'll run, so our best bet is to write the file to whatever
// is the current working directory now and then clean it up.
const denoConfigPath = join(process.cwd(), 'deno.json')
const denoConfig = {
importMap: importMapFile.path,
}

// Let's ensure we're not overwriting a `deno.json` file that happens to be
// in the current working directory.
await t.throwsAsync(
() => fs.access(denoConfigPath),
{ code: 'ENOENT' },
`The file at '${denoConfigPath} would be overwritten by this test. Please move the file to a different location and try again.'`,
)

await fs.writeFile(denoConfigPath, JSON.stringify(denoConfig))

await t.notThrowsAsync(() =>
bundle([join(fixtureDir, 'functions')], tmpDir.path, declarations, {
basePath: fixturesDir,
featureFlags: {
edge_functions_produce_eszip: true,
},
importMaps: [
{
baseURL: pathToFileURL(join(fixturesDir, 'import-map.json')),
imports: {
'alias:helper': pathToFileURL(join(fixturesDir, 'helper.ts')).toString(),
},
},
],
}),
)

await del([tmpDir.path, denoConfigPath, importMapFile.path], { force: true })
})
1 change: 0 additions & 1 deletion test/node/stage_2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { pathToFileURL } from 'url'
import test from 'ava'
import del from 'del'
import { execa } from 'execa'
import semver from 'semver'
import tmp from 'tmp-promise'

import { getLocalEntryPoint } from '../../node/formats/javascript.js'
Expand Down

0 comments on commit c5ee57c

Please sign in to comment.