Skip to content

Commit

Permalink
chore: improvements for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed Dec 25, 2024
1 parent de26501 commit 42b615a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
8 changes: 6 additions & 2 deletions apps/site/components/Downloads/Release/ReleaseCodeBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { INSTALLATION_METHODS } from '@/util/downloadUtils';
import LinkWithArrow from './LinkWithArrow';

// Creates a minimal JavaScript interpreter for parsing the JavaScript code from the snippets
// Note: that the code runs inside a sandboxed environment and cannot interact with any code outside of the sandbox
// It also does not have access to any Global or Window objects, nor it can execute code on the end-user's browser
// It also only allows a return statement for a string and it forces the return value to also be a string and only be used
// by Shiki to render the highlighted syntax. Hence XSS attacks or JavaScript injections are not possible.
const interpreter = createSval({}, 'script');

const parseSnippet = (s: string, releaseContext: ReleaseContextType) => {
Expand All @@ -27,7 +31,7 @@ const parseSnippet = (s: string, releaseContext: ReleaseContextType) => {
interpreter.run(`exports.content = \`${s}\``);

// Sets the parsed raw string to be used by the JSX CodeBox
return interpreter.exports.content;
return String(interpreter.exports.content);
};

const ReleaseCodeBox: FC = () => {
Expand All @@ -54,7 +58,7 @@ const ReleaseCodeBox: FC = () => {

return parseSnippet(
// Bundles the Platform and Package Manager snippets
`${platformSnippet?.content ?? ''}${packageManagerSnippet?.content ?? ''}`,
`${platformSnippet?.content ?? ''}\n${packageManagerSnippet?.content ?? ''}`,
// Passes a partial state of only the things we need to the parser
{ release, platform, os } as ReleaseContextType
);
Expand Down
5 changes: 4 additions & 1 deletion apps/site/snippets/en/download/docker.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
# Pull the Node.js Docker image:
docker pull node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'}

# Create a Node.js container and start a Shell session:
docker run -it --rm --entrypoint sh node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'}

# Verify the Node.js version:
docker run node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'} node -v # Should print "${props.release.versionWithPrefix}".
node -v # Should print "${props.release.versionWithPrefix}".
6 changes: 1 addition & 5 deletions apps/site/snippets/en/download/npm.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@

# Verify the Node.js version:
${props.platform === 'DOCKER' ?
`docker run node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'} npm -v # Should print "${props.release.npm}".` :
`npm -v # Should print "${props.release.npm}".`
}
npm -v # Should print "${props.release.npm}".
6 changes: 1 addition & 5 deletions apps/site/snippets/en/download/pnpm.bash
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@

# Download and install "pnpm":
${props.os === 'WIN' ?
'corepack enable pnpm' :
'curl -fsSL https://get.pnpm.io/install.sh | sh -'
}

# Verify "pnpm" version:
${props.platform === 'DOCKER' ?
`docker run node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'} pnpm -v` :
'pnpm -v'
}
pnpm -v
6 changes: 1 addition & 5 deletions apps/site/snippets/en/download/yarn.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@

# Download and install "Yarn":
corepack enable yarn

# Verify "Yarn" version:
${props.platform === 'DOCKER' ?
`docker run node:${props.release.major}-${props.release.major >= 4 ? 'alpine' : 'slim'} yarn -v` :
'yarn -v'
}
yarn -v

0 comments on commit 42b615a

Please sign in to comment.