Skip to content

Commit c16bb1d

Browse files
authored
Update nodejs examples (#1087)
## Summary Update nodejs examples. Add pnpm example as well. ## How was it tested? devbox shell in each example
1 parent bd7edd5 commit c16bb1d

File tree

12 files changed

+67
-18
lines changed

12 files changed

+67
-18
lines changed

examples/development/nodejs/nodejs-npm/devbox.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
],
55
"shell": {
66
"init_hook": [
7-
"npm install",
8-
"npm run start"
9-
]
7+
"npm install"
8+
],
9+
"scripts": {
10+
"run_test": "npm run start"
11+
}
1012
}
11-
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"packages": [
3+
"nodejs@18",
4+
"nodePackages.pnpm@latest"
5+
],
6+
"shell": {
7+
"init_hook": [
8+
"pnpm install"
9+
],
10+
"scripts": {
11+
"run_test": "pnpm run start"
12+
}
13+
}
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const NODE_MAJOR_VERSION = process.versions.node.split('.')[0];
2+
if (!NODE_MAJOR_VERSION) {
3+
throw new Error('Node is not installed properly');
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "nodejs-pnpm",
3+
"main": "index.js",
4+
"scripts": {
5+
"build": "echo building...",
6+
"start": "node index.js"
7+
},
8+
"dependencies": {}
9+
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
"packages": [
3-
4-
"nodePackages.typescript"
3+
54
],
65
"shell": {
7-
"init_hook": null
6+
"init_hook": [
7+
"npm install",
8+
"npm run build"
9+
],
10+
"scripts": {
11+
"run_test": "npm run start"
12+
}
813
}
9-
}
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var NODE_MAJOR_VERSION = process.versions.node.split('.')[0];
2+
if (NODE_MAJOR_VERSION !== "18") {
3+
throw new Error('Node version is not 18');
4+
}

examples/development/nodejs/nodejs-typescript/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
2-
"name": "nodejs-18",
2+
"name": "nodejs-typescript",
33
"main": "index.js",
4+
"scripts": {
5+
"build": "tsc index.ts --outfile index.js",
6+
"start": "node index.js"
7+
},
48
"devDependencies": {
59
"@types/node": "^18.7.18",
610
"typescript": "^4.6.4"
711
},
812
"engines": {
913
"node": ">=18"
1014
}
11-
}
15+
}

examples/development/nodejs/nodejs-typescript/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"compilerOptions": {
55
/* Visit https://aka.ms/tsconfig to read more about this file */
66
/* Language and Environment */
7-
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
7+
"target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
88
/* Modules */
99
"module": "commonjs", /* Specify what module code is generated. */
1010
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */

examples/development/nodejs/nodejs-yarn/devbox.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
55
],
66
"shell": {
7-
"init_hook": null
7+
"init_hook": [
8+
"yarn install"
9+
],
10+
"scripts": {
11+
"run_test": "yarn start"
12+
}
813
}
9-
}
14+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "nodejs-yarn",
33
"main": "index.js",
4+
"license": "MIT",
45
"scripts": {
5-
"build": "echo 'building...'",
6-
"start": "echo 'starting...'"
6+
"build": "echo building...",
7+
"start": "node index.js"
78
},
89
"dependencies": {}
9-
}
10+
}

internal/templates/templates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var templates = map[string]string{
4141
"nginx": "examples/servers/nginx/",
4242
"nim": "examples/development/nim/spinnytest/",
4343
"node-npm": "examples/development/nodejs/nodejs-npm/",
44+
"node-pnpm": "examples/development/nodejs/nodejs-pnpm/",
4445
"node-typescript": "examples/development/nodejs/nodejs-typescript/",
4546
"node-yarn": "examples/development/nodejs/nodejs-yarn/",
4647
"php": "examples/development/php/php8.1/",

0 commit comments

Comments
 (0)