Skip to content

Commit

Permalink
respect minimum version constraints from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jun 20, 2024
1 parent fb75185 commit 1a83425
Show file tree
Hide file tree
Showing 6 changed files with 2,162 additions and 5 deletions.
30 changes: 27 additions & 3 deletions gdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class GDF {

get astroSSR() {
return !!(this.#pj.dependencies?.astro) &&
!!(this.#pj.dependencies?.['@astrojs/node'])
!!(this.#pj.dependencies?.['@astrojs/node'])
}

get astroStatic() {
Expand Down Expand Up @@ -441,9 +441,33 @@ export class GDF {

// what node version should be used?
get nodeVersion() {
const ltsVersion = '20.11.1'
const ltsVersion = '20.15.0'

return process.version.match(/\d+\.\d+\.\d+/)?.[0] || ltsVersion
let version = process.version.match(/\d+\.\d+\.\d+/)?.[0] || ltsVersion

if (this.#pj.engines?.node) {
// determine minimal version from package.json
let { node } = this.#pj.engines

Check failure on line 450 in gdf.js

View workflow job for this annotation

GitHub Actions / test

'node' is never reassigned. Use 'const' instead
let minversion = node.match(/\d+(\.\d+(\.\d+)?)?/)?.[0].split('.')

Check failure on line 451 in gdf.js

View workflow job for this annotation

GitHub Actions / test

'minversion' is never reassigned. Use 'const' instead
if (node.includes('>') && !node.includes("=")) {

Check failure on line 452 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
minversion.push(parseInt(minversion.pop()) + 1)
}

// ensure version is at least the minimum
version = version.split('.')
for (const i=0; i<version.length; i++) {

Check failure on line 458 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Operator '=' must be spaced

Check failure on line 458 in gdf.js

View workflow job for this annotation

GitHub Actions / test

Operator '<' must be spaced

Check failure on line 458 in gdf.js

View workflow job for this annotation

GitHub Actions / test

'i' is constant
if (minversion[i] > version[i]) {
version = minversion
break
} else if (minversion[i] < version[i]) {
break
}
}

version = version.join('.')
}

return version
}

// what bun version should be used?
Expand Down
6 changes: 6 additions & 0 deletions test/base/version/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.git
/node_modules
.dockerignore
.env
Dockerfile
fly.toml
39 changes: 39 additions & 0 deletions test/base/version/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=100
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link package-lock.json package.json ./
RUN npm ci

# Copy application code
COPY --link . .


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "npm", "run", "start" ]
Loading

0 comments on commit 1a83425

Please sign in to comment.