From a1c7ec863cb7d5a7e33795a67881d0bfede3ea62 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Fri, 26 Apr 2024 18:33:47 +0530 Subject: [PATCH] feat: add dependency resolution for js projects --- compiled_starters/javascript/.gitignore | 1 + compiled_starters/javascript/README.md | 2 +- compiled_starters/javascript/codecrafters.yml | 4 ++-- compiled_starters/javascript/package-lock.json | 14 ++++++++++++++ compiled_starters/javascript/package.json | 15 +++++++++++++++ dockerfiles/nodejs-21.Dockerfile | 15 +++++++++++++++ solutions/javascript/01-init/code/.gitignore | 1 + solutions/javascript/01-init/code/README.md | 2 +- .../javascript/01-init/code/codecrafters.yml | 4 ++-- .../javascript/01-init/code/package-lock.json | 14 ++++++++++++++ solutions/javascript/01-init/code/package.json | 15 +++++++++++++++ starter-repository-definitions.yml | 8 +++++++- starter_templates/codecrafters.yml | 4 ++-- starter_templates/javascript/.gitignore | 1 + starter_templates/javascript/package-lock.json | 14 ++++++++++++++ starter_templates/javascript/package.json | 15 +++++++++++++++ 16 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 compiled_starters/javascript/.gitignore create mode 100644 compiled_starters/javascript/package-lock.json create mode 100644 compiled_starters/javascript/package.json create mode 100644 dockerfiles/nodejs-21.Dockerfile create mode 100644 solutions/javascript/01-init/code/.gitignore create mode 100644 solutions/javascript/01-init/code/package-lock.json create mode 100644 solutions/javascript/01-init/code/package.json create mode 100644 starter_templates/javascript/.gitignore create mode 100644 starter_templates/javascript/package-lock.json create mode 100644 starter_templates/javascript/package.json diff --git a/compiled_starters/javascript/.gitignore b/compiled_starters/javascript/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/compiled_starters/javascript/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/compiled_starters/javascript/README.md b/compiled_starters/javascript/README.md index 4175bd8..a19674d 100644 --- a/compiled_starters/javascript/README.md +++ b/compiled_starters/javascript/README.md @@ -32,7 +32,7 @@ Time to move on to the next stage! Note: This section is for stages 2 and beyond. -1. Ensure you have `node (18)` installed locally +1. Ensure you have `node (21)` installed locally 1. Run `./your_grep.sh` to run your program, which is implemented in `app/main.js`. 1. Commit your changes and run `git push origin master` to submit your solution diff --git a/compiled_starters/javascript/codecrafters.yml b/compiled_starters/javascript/codecrafters.yml index 3621dd6..e61c476 100644 --- a/compiled_starters/javascript/codecrafters.yml +++ b/compiled_starters/javascript/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the JavaScript version used to run your code # on Codecrafters. # -# Available versions: nodejs-18 -language_pack: nodejs-18 +# Available versions: nodejs-21 +language_pack: nodejs-21 diff --git a/compiled_starters/javascript/package-lock.json b/compiled_starters/javascript/package-lock.json new file mode 100644 index 0000000..2c5a5b0 --- /dev/null +++ b/compiled_starters/javascript/package-lock.json @@ -0,0 +1,14 @@ + +{ + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "license": "MIT" + } + } +} \ No newline at end of file diff --git a/compiled_starters/javascript/package.json b/compiled_starters/javascript/package.json new file mode 100644 index 0000000..25f8751 --- /dev/null +++ b/compiled_starters/javascript/package.json @@ -0,0 +1,15 @@ +{ + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "description": "Build your own Grep challenge, from CodeCrafters", + "main": "main.js", + "scripts": { + "dev": "node app/main.js" + }, + "keywords": [ + "build-your-own-x" + ], + "author": "", + "license": "MIT", + "dependencies": {} +} \ No newline at end of file diff --git a/dockerfiles/nodejs-21.Dockerfile b/dockerfiles/nodejs-21.Dockerfile new file mode 100644 index 0000000..435b41e --- /dev/null +++ b/dockerfiles/nodejs-21.Dockerfile @@ -0,0 +1,15 @@ +FROM node:21.7-alpine3.19 + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,package-lock.json" + +WORKDIR /app + +COPY package.json ./ +COPY package-lock.json ./ + +# If dependencies in the package lock do not match those in package.json, instead of updating the package lock, npm ci will exit with an error. +RUN npm ci + +RUN mkdir -p /app-cached +# If the node_modules directory exists, move it to /app-cached +RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi diff --git a/solutions/javascript/01-init/code/.gitignore b/solutions/javascript/01-init/code/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/solutions/javascript/01-init/code/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/solutions/javascript/01-init/code/README.md b/solutions/javascript/01-init/code/README.md index 4175bd8..a19674d 100644 --- a/solutions/javascript/01-init/code/README.md +++ b/solutions/javascript/01-init/code/README.md @@ -32,7 +32,7 @@ Time to move on to the next stage! Note: This section is for stages 2 and beyond. -1. Ensure you have `node (18)` installed locally +1. Ensure you have `node (21)` installed locally 1. Run `./your_grep.sh` to run your program, which is implemented in `app/main.js`. 1. Commit your changes and run `git push origin master` to submit your solution diff --git a/solutions/javascript/01-init/code/codecrafters.yml b/solutions/javascript/01-init/code/codecrafters.yml index 3621dd6..e61c476 100644 --- a/solutions/javascript/01-init/code/codecrafters.yml +++ b/solutions/javascript/01-init/code/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the JavaScript version used to run your code # on Codecrafters. # -# Available versions: nodejs-18 -language_pack: nodejs-18 +# Available versions: nodejs-21 +language_pack: nodejs-21 diff --git a/solutions/javascript/01-init/code/package-lock.json b/solutions/javascript/01-init/code/package-lock.json new file mode 100644 index 0000000..2c5a5b0 --- /dev/null +++ b/solutions/javascript/01-init/code/package-lock.json @@ -0,0 +1,14 @@ + +{ + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "license": "MIT" + } + } +} \ No newline at end of file diff --git a/solutions/javascript/01-init/code/package.json b/solutions/javascript/01-init/code/package.json new file mode 100644 index 0000000..25f8751 --- /dev/null +++ b/solutions/javascript/01-init/code/package.json @@ -0,0 +1,15 @@ +{ + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "description": "Build your own Grep challenge, from CodeCrafters", + "main": "main.js", + "scripts": { + "dev": "node app/main.js" + }, + "keywords": [ + "build-your-own-x" + ], + "author": "", + "license": "MIT", + "dependencies": {} +} \ No newline at end of file diff --git a/starter-repository-definitions.yml b/starter-repository-definitions.yml index c1b02d6..49d3847 100644 --- a/starter-repository-definitions.yml +++ b/starter-repository-definitions.yml @@ -132,14 +132,20 @@ target: README.md - source: starter_templates/codecrafters.yml target: codecrafters.yml + - source: starter_templates/javascript/package.json + target: package.json + - source: starter_templates/javascript/package-lock.json + target: package-lock.json - source: starter_templates/javascript/app/main.js target: app/main.js - source: starter_templates/javascript/your_grep.sh target: your_grep.sh - source: starter_templates/.gitattributes target: .gitattributes + - source: starter_templates/javascript/.gitignore + target: .gitignore template_attributes: - required_executable: "node (18)" + required_executable: "node (21)" user_editable_file: "app/main.js" - language: csharp diff --git a/starter_templates/codecrafters.yml b/starter_templates/codecrafters.yml index cdfe5aa..c5f4bc2 100644 --- a/starter_templates/codecrafters.yml +++ b/starter_templates/codecrafters.yml @@ -24,8 +24,8 @@ language_pack: go-1.22 language_pack: php-7.4 {{/ language_is_php }} {{# language_is_javascript }} -# Available versions: nodejs-18 -language_pack: nodejs-18 +# Available versions: nodejs-21 +language_pack: nodejs-21 {{/ language_is_javascript }} {{# language_is_c }} # Available versions: c-9.2 diff --git a/starter_templates/javascript/.gitignore b/starter_templates/javascript/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/starter_templates/javascript/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/starter_templates/javascript/package-lock.json b/starter_templates/javascript/package-lock.json new file mode 100644 index 0000000..2c5a5b0 --- /dev/null +++ b/starter_templates/javascript/package-lock.json @@ -0,0 +1,14 @@ + +{ + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "license": "MIT" + } + } +} \ No newline at end of file diff --git a/starter_templates/javascript/package.json b/starter_templates/javascript/package.json new file mode 100644 index 0000000..25f8751 --- /dev/null +++ b/starter_templates/javascript/package.json @@ -0,0 +1,15 @@ +{ + "name": "@codecrafters/build-your-own-grep", + "version": "1.0.0", + "description": "Build your own Grep challenge, from CodeCrafters", + "main": "main.js", + "scripts": { + "dev": "node app/main.js" + }, + "keywords": [ + "build-your-own-x" + ], + "author": "", + "license": "MIT", + "dependencies": {} +} \ No newline at end of file