Skip to content

Commit

Permalink
fix: update azure SWA preset and update node versions detection (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Apr 7, 2022
1 parent b6f9e6f commit 19c784b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/presets/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@ async function writeRoutes (nitro) {
version: '2.0'
}

let nodeVersion = '16'
try {
const currentNodeVersion = fse.readJSONSync(join(nitro.options.rootDir, 'package.json')).engines.node
if (['16', '14'].includes(currentNodeVersion)) {
nodeVersion = currentNodeVersion
}
} catch {
const currentNodeVersion = process.versions.node.slice(0, 2)
if (['16', '14'].includes(currentNodeVersion)) {
nodeVersion = currentNodeVersion
}
}

const config = {
platform: {
apiRuntime: `node:${nodeVersion}`
},
routes: [],
navigationFallback: {
rewrite: '/api/server'
Expand Down Expand Up @@ -100,7 +116,9 @@ async function writeRoutes (nitro) {

await writeFile(resolve(nitro.options.output.serverDir, 'function.json'), JSON.stringify(functionDefinition))
await writeFile(resolve(nitro.options.output.serverDir, '../host.json'), JSON.stringify(host))
await writeFile(resolve(nitro.options.output.publicDir, 'staticwebapp.config.json'), JSON.stringify(config))
const stubPackageJson = resolve(nitro.options.output.serverDir, '../package.json')
await writeFile(stubPackageJson, JSON.stringify({ private: true }))
await writeFile(resolve(nitro.options.rootDir, 'staticwebapp.config.json'), JSON.stringify(config))
if (!indexFileExists) {
await writeFile(indexPath, '')
}
Expand Down
7 changes: 6 additions & 1 deletion src/presets/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ async function writeRoutes (nitro: Nitro) {
if (['16', '14'].includes(currentNodeVersion)) {
nodeVersion = currentNodeVersion
}
} catch { }
} catch {
const currentNodeVersion = process.versions.node.slice(0, 2)
if (['16', '14'].includes(currentNodeVersion)) {
nodeVersion = currentNodeVersion
}
}

const getPackageVersion = async (id) => {
const pkg = await readPackageJSON(id, { url: nitro.options.nodeModulesDirs })
Expand Down

0 comments on commit 19c784b

Please sign in to comment.