Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update azure SWA preset and update node versions detection #43

Merged
merged 3 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't engines.node optional? Are we doing try/catch to ignore this?

Copy link
Member Author

@danielroe danielroe Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and also if the file doesn't exist. Implementation from https://github.com/unjs/nitropack/blob/305c49853d514ceb00342107a7affdbd9500f5f2/src/presets/firebase.ts#L57-L65.

But maybe might be better to just grab from process?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of falling back to process.versions :)

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