From 7750a71f6b7b3109adf038db9f4180baf9e03ec0 Mon Sep 17 00:00:00 2001 From: Robin Quintero Date: Tue, 22 Oct 2024 17:57:47 -0500 Subject: [PATCH] feat(build): #1378 deprecate makenodejs - Deprecate `makeNodeJsModules` and `makeNodeJsEnvironment`. Signed-off-by: Robin Quintero --- docs/src/api/builtins/utilities.md | 21 -- docs/src/api/extensions/node.js.md | 202 ------------------ makes/utils/makeNodeJsLock/entrypoint.sh | 24 --- makes/utils/makeNodeJsLock/main.nix | 10 - src/args/agnostic.nix | 3 - src/args/lint-git-commit-msg/default.nix | 16 +- src/args/lint-git-commit-msg/entrypoint.sh | 7 +- src/args/lint-with-ajv/builder.sh | 16 -- src/args/lint-with-ajv/default.nix | 24 +-- src/args/lint-with-ajv/entrypoint.sh | 20 ++ src/args/make-node-js-environment/default.nix | 28 --- src/args/make-node-js-modules/builder.sh | 17 -- src/args/make-node-js-modules/default.nix | 18 -- .../modules/format-markdown/default.nix | 16 +- .../modules/format-markdown/entrypoint.sh | 9 +- 15 files changed, 51 insertions(+), 380 deletions(-) delete mode 100644 docs/src/api/extensions/node.js.md delete mode 100644 makes/utils/makeNodeJsLock/entrypoint.sh delete mode 100644 makes/utils/makeNodeJsLock/main.nix delete mode 100644 src/args/lint-with-ajv/builder.sh create mode 100644 src/args/lint-with-ajv/entrypoint.sh delete mode 100644 src/args/make-node-js-environment/default.nix delete mode 100644 src/args/make-node-js-modules/builder.sh delete mode 100644 src/args/make-node-js-modules/default.nix diff --git a/docs/src/api/builtins/utilities.md b/docs/src/api/builtins/utilities.md index 77d0cd95..7b226d0e 100644 --- a/docs/src/api/builtins/utilities.md +++ b/docs/src/api/builtins/utilities.md @@ -2,27 +2,6 @@ Utilities provide an easy mechanism for calling functions from makes without having to specify them on any file. -## makeNodeJsLock - -You can generate a `package-lock.json` for -[makeNodeJsEnvironment](/api/extensions/node.js/#makenodejsenvironment) -like this: - -```bash -m github:fluidattacks/makes@24.09 /utils/makeNodeJsLock \ - "${node_js_version}" \ - "${package_json_dir}" \ - "${lockfile_version}" -``` - -- Supported `node_js_version`s are: `18`, `20` and `21`. -- `package_json_dir` is the **absolute path** to the directory that contains - the `package.json` file in your project. -- The `package-lock.json` file will be generated in the same directory that - contains the `package.json` file. -- The `lockfile_version` is an optional argument, defaults to `2` and can be - `1` or `2`. - ## makePythonLock You can generate a `poetry.lock` for diff --git a/docs/src/api/extensions/node.js.md b/docs/src/api/extensions/node.js.md deleted file mode 100644 index 79be87b8..00000000 --- a/docs/src/api/extensions/node.js.md +++ /dev/null @@ -1,202 +0,0 @@ -## makeNodeJsModules - -Cook the `node_modules` directory -for the given Node.js project -using [node2nix](https://github.com/svanderburg/node2nix). - -Types: - -- makeNodeJsModules (`function { ... } -> package`): - - name (`str`): - Custom name to assign to the build step, be creative, it helps in debugging. - - nodeJsVersion (`enum [ "18" "20" "21" ]`): - Node.js version to use. - - packageJson (`package`): - Path to the `package.json` of your project. - - packageLockJson (`package`): - Path to the `package-lock.json` of your project. - - packageOverrides (`Attrs`): Optional. - Override behaviors when building `node_modules`. - See [node2nix arguments](https://github.com/svanderburg/node2nix/blob/315e1b85a6761152f57a41ccea5e2570981ec670/nix/node-env.nix#L568) - for more. - -Example: - -=== "package.json" - - ```json - # /path/to/my/project/makes/example/package.json - { - "dependencies": { - "hello-world-npm": "*" - } - } - ``` - -=== "package-lock.json" - - ```json - # /path/to/my/project/makes/example/package-lock.json - { - "requires": true, - "lockfileVersion": 1, - "dependencies": { - "hello-world-npm": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/hello-world-npm/-/hello-world-npm-1.1.1.tgz", - "integrity": "sha1-JQgw7wAItDftk+a+WZk0ua0Lkwg=" - } - } - } - ``` - -=== "main.nix" - - ```nix - # /path/to/my/project/makes/example/main.nix - { - inputs, - makeNodeJsModules, - makeScript, - projectPath, - ... - }: - let - hello = makeNodeJsModules { - name = "hello-world-npm"; - nodeJsVersion = "21"; - packageJson = - projectPath "/path/to/my/project/makes/example/package.json"; - packageLockJson = - projectPath "/path/to/my/project/makes/example/package-lock.json"; - packageOverrides = { - # Ignore post-install scripts - npmFlags = "--ignore-scripts true"; - # Provide patchelf when building node_modules - buildInputs = [inputs.nixpkgs.patchelf]; - }; - }; - in - makeScript { - replace = { - __argHello__ = hello; - }; - entrypoint = '' - ls __argHello__ - ls __argHello__/lib - ''; - name = "example"; - } - ``` - -=== "Invocation" - - ```bash - $ m . /example - - /bin /lib - /node_modules - ``` - -## makeNodeJsEnvironment - -Setup a `makeNodeJsModules` in the environment -using `makeSearchPaths`. -It appends: - -- `node` to `PATH`. -- `node_modules/.bin` to `PATH`. -- `node_modules` to [NODE_PATH](https://nodejs.org/api/modules.html). - -Pre-requisites: -[Generating a package-lock.json](/api/builtins/utilities#makenodejslock) - -Types: - -- makeNodeJsEnvironment (`function { ... } -> package`): - - name (`str`): - Custom name to assign to the build step, be creative, it helps in debugging. - - nodeJsVersion (`enum [ "18" "20" "21" ]`): - Node.js version to use. - - packageJson (`package`): - Path to the `package.json` of your project. - - packageLockJson (`package`): - Path to the `package-lock.json` of your project. - - packageOverrides (`Attrs`): Optional. - Override behaviors when building `node_modules`. - See [node2nix arguments](https://github.com/svanderburg/node2nix/blob/315e1b85a6761152f57a41ccea5e2570981ec670/nix/node-env.nix#L568) - for more. - -Example: - -=== "package.json" - - ```json - # /path/to/my/project/makes/example/package.json - { - "dependencies": { - "hello-world-npm": "*" - } - } - ``` - -=== "package-lock.json" - - ```json - # /path/to/my/project/makes/example/package-lock.json - { - "requires": true, - "lockfileVersion": 1, - "dependencies": { - "hello-world-npm": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/hello-world-npm/-/hello-world-npm-1.1.1.tgz", - "integrity": "sha1-JQgw7wAItDftk+a+WZk0ua0Lkwg=" - } - } - } - ``` - -=== "main.nix" - - ```nix - # /path/to/my/project/makes/example/main.nix - { - makeNodeJsEnvironment, - makeScript, - ... - }: - let - hello = makeNodeJsEnvironment { - name = "hello-world-npm"; - nodeJsVersion = "21"; - packageJson = - projectPath "/path/to/my/project/makes/example/package.json"; - packageLockJson = - projectPath "/path/to/my/project/makes/example/package-lock.json"; - packageOverrides = { - # Ignore post-install scripts - npmFlags = "--ignore-scripts true"; - # Provide patchelf when building node_modules - buildInputs = [inputs.nixpkgs.patchelf]; - }; - }; - in - makeScript { - entrypoint = '' - hello-world-npm - ''; - name = "example"; - searchPaths = { - source = [ hello ]; - }; - } - ``` - -=== "Invocation" - - ```bash - $ m . /example - - Hello World NPM - ``` diff --git a/makes/utils/makeNodeJsLock/entrypoint.sh b/makes/utils/makeNodeJsLock/entrypoint.sh deleted file mode 100644 index fc1c9753..00000000 --- a/makes/utils/makeNodeJsLock/entrypoint.sh +++ /dev/null @@ -1,24 +0,0 @@ -# shellcheck shell=bash - -function main { - local node_js_version="${1}" - local package_json_dir="${2}" - local lockfile_version="${3:-2}" - local npm_install_args=( - --audit false - --ignore-scripts true - --package-lock-only - ) - - : && case "${node_js_version}" in - 18) npm=__argNode18__/bin/npm ;; - 20) npm=__argNode20__/bin/npm ;; - 21) npm=__argNode21__/bin/npm ;; - *) critical NodeJs version not supported: "${node_js_version}" ;; - esac \ - && pushd "${package_json_dir}" \ - && "${npm}" install "${npm_install_args[@]}" --lockfile-version "${lockfile_version}" \ - && popd || return 1 -} - -main "${@}" diff --git a/makes/utils/makeNodeJsLock/main.nix b/makes/utils/makeNodeJsLock/main.nix deleted file mode 100644 index 43fe5b92..00000000 --- a/makes/utils/makeNodeJsLock/main.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ __nixpkgs__, makeScript, ... }: -makeScript { - entrypoint = ./entrypoint.sh; - name = "make-node-js-lock"; - replace = { - __argNode18__ = __nixpkgs__.nodejs_18; - __argNode20__ = __nixpkgs__.nodejs_20; - __argNode21__ = __nixpkgs__.nodejs_21; - }; -} diff --git a/src/args/agnostic.nix b/src/args/agnostic.nix index 6d3ef3ee..baf98fe6 100644 --- a/src/args/agnostic.nix +++ b/src/args/agnostic.nix @@ -78,9 +78,6 @@ let makeEnvVars = import ./make-env-vars/default.nix self; makeEnvVarsForTerraform = import ./make-env-vars-for-terraform/default.nix self; - makeNodeJsEnvironment = - import ./make-node-js-environment/default.nix self; - makeNodeJsModules = import ./make-node-js-modules/default.nix self; makeNomadEnvironment = import ./make-nomad-environment/default.nix self; makePythonEnvironment = import ./make-python-environment/default.nix self; makePythonPoetryEnvironment = diff --git a/src/args/lint-git-commit-msg/default.nix b/src/args/lint-git-commit-msg/default.nix index 1d93c74a..adc5641d 100644 --- a/src/args/lint-git-commit-msg/default.nix +++ b/src/args/lint-git-commit-msg/default.nix @@ -1,13 +1,6 @@ -{ __nixpkgs__, makeNodeJsEnvironment, makeScript, ... }: +{ __nixpkgs__, makeScript, makeDerivation, makeSearchPaths, ... }: { branch, config, name, parser, src, }: -let - commitlint = makeNodeJsEnvironment { - name = "commitlint"; - nodeJsVersion = "21"; - packageJson = ./commitlint/package.json; - packageLockJson = ./commitlint/package-lock.json; - }; -in makeScript { +makeScript { name = "lint-git-commit-msg-for-${name}"; replace = { __argBranch__ = branch; @@ -15,9 +8,6 @@ in makeScript { __argParser__ = parser; __argSrc__ = src; }; - searchPaths = { - bin = [ __nixpkgs__.git ]; - source = [ commitlint ]; - }; + searchPaths = { bin = [ __nixpkgs__.git __nixpkgs__.nodejs_21 ]; }; entrypoint = ./entrypoint.sh; } diff --git a/src/args/lint-git-commit-msg/entrypoint.sh b/src/args/lint-git-commit-msg/entrypoint.sh index 8aee2c9e..8caeb0ac 100644 --- a/src/args/lint-git-commit-msg/entrypoint.sh +++ b/src/args/lint-git-commit-msg/entrypoint.sh @@ -8,8 +8,13 @@ function main { --parser-preset __argParser__ --config __argConfig__ ) + local commitlint_path="src/args/lint-git-commit-msg/commitlint" - cd __argSrc__ \ + pushd "${commitlint_path}" \ + && npm ci \ + && export PATH="${PWD}/node_modules/.bin:${PATH}" \ + && popd \ + && cd __argSrc__ \ && commit_diff="origin/${main_branch}..HEAD" \ && commit_hashes="$(git --no-pager log --pretty=%h "${commit_diff}")" \ && for commit_hash in ${commit_hashes}; do diff --git a/src/args/lint-with-ajv/builder.sh b/src/args/lint-with-ajv/builder.sh deleted file mode 100644 index bbd9c8b1..00000000 --- a/src/args/lint-with-ajv/builder.sh +++ /dev/null @@ -1,16 +0,0 @@ -# shellcheck shell=bash - -function main { - source "${envTargets}/template" local targets - - info "Compiling schema: ${envSchema}" \ - && ajv compile -s "${envSchema}" \ - && for target in "${targets[@]}"; do - info "Linting data: ${target}" \ - && ajv validate -s "${envSchema}" -d "${target}" \ - || return 1 - done \ - && touch "${out}" -} - -main "${@}" diff --git a/src/args/lint-with-ajv/default.nix b/src/args/lint-with-ajv/default.nix index 1ffe4d1a..4c0a0b94 100644 --- a/src/args/lint-with-ajv/default.nix +++ b/src/args/lint-with-ajv/default.nix @@ -1,20 +1,12 @@ -{ makeDerivation, makeNodeJsEnvironment, toBashArray, ... }: +{ __nixpkgs__, makeScript, projectPath, toBashArray, ... }: { name, schema, targets, }: -makeDerivation { - env = { - envSchema = schema; - envTargets = toBashArray targets; +makeScript { + replace = { + __argSchema__ = schema; + __argTargets__ = toBashArray targets; + __argAjvPath__ = projectPath "/src/args/lint-with-ajv/ajv-cli"; }; name = "lint-with-ajv-for-${name}"; - searchPaths = { - source = [ - (makeNodeJsEnvironment { - name = "ajv-cli"; - nodeJsVersion = "21"; - packageJson = ./ajv-cli/package.json; - packageLockJson = ./ajv-cli/package-lock.json; - }) - ]; - }; - builder = ./builder.sh; + searchPaths.bin = [ __nixpkgs__.nodejs_21 ]; + entrypoint = ./entrypoint.sh; } diff --git a/src/args/lint-with-ajv/entrypoint.sh b/src/args/lint-with-ajv/entrypoint.sh new file mode 100644 index 00000000..015302ea --- /dev/null +++ b/src/args/lint-with-ajv/entrypoint.sh @@ -0,0 +1,20 @@ +# shellcheck shell=bash + +function main { + source "${__argTargets__}/template" local targets + + pushd "${__argAjvPath__}" \ + && npm ci \ + && export PATH="${PWD}/node_modules/.bin:${PATH}" \ + && popd \ + && info "Compiling schema: ${__argSchema__}" \ + && ajv compile -s "${__argSchema__}" \ + && for target in "${targets[@]}"; do + info "Linting data: ${target}" \ + && ajv validate -s "${__argSchema__}" -d "${target}" \ + || return 1 + done \ + && touch "${out}" +} + +main "${@}" diff --git a/src/args/make-node-js-environment/default.nix b/src/args/make-node-js-environment/default.nix deleted file mode 100644 index d9eb6274..00000000 --- a/src/args/make-node-js-environment/default.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ __nixpkgs__, makeNodeJsModules, makeSearchPaths, ... }: -{ name, nodeJsVersion, packageJson, packageLockJson, packageOverrides ? { } -, searchPaths ? { }, }: -let - node = if nodeJsVersion == "18" then - __nixpkgs__.nodejs_18 - else if nodeJsVersion == "20" then - __nixpkgs__.nodejs_20 - else if nodeJsVersion == "21" then - __nixpkgs__.nodejs_21 - else - abort "Supported node versions are: 18, 20 and 21"; - - nodeModules = "${ - makeNodeJsModules { - inherit name; - inherit nodeJsVersion; - inherit packageJson; - inherit packageLockJson; - inherit packageOverrides; - } - }/lib/node_modules"; -in makeSearchPaths { - bin = [ node ]; - nodeBin = [ nodeModules ]; - nodeModule = [ nodeModules ]; - source = [ (makeSearchPaths searchPaths) ]; -} diff --git a/src/args/make-node-js-modules/builder.sh b/src/args/make-node-js-modules/builder.sh deleted file mode 100644 index 19efd134..00000000 --- a/src/args/make-node-js-modules/builder.sh +++ /dev/null @@ -1,17 +0,0 @@ -# shellcheck shell=bash - -function main { - : && mkdir -p "${out}" \ - && pushd "${out}" \ - && copy "${envPackageJson}" package.json \ - && copy "${envPackageLockJson}" package-lock.json \ - && node2nix \ - --development \ - --input package.json \ - --lock package-lock.json \ - --pkg-name "nodejs_${envNodeJsVersion}" \ - --include-peer-dependencies \ - && sed -i -e 's/dontNpmInstall ? false/dontNpmInstall ? true/g' node-env.nix # https://github.com/svanderburg/node2nix/issues/134#issuecomment-475809875 -} - -main "${@}" diff --git a/src/args/make-node-js-modules/default.nix b/src/args/make-node-js-modules/default.nix deleted file mode 100644 index c737ceb8..00000000 --- a/src/args/make-node-js-modules/default.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ __nixpkgs__, makeDerivation, ... }: -{ name, nodeJsVersion, packageJson, packageLockJson, packageOverrides ? { }, }: -let - node2NixLock = makeDerivation { - builder = ./builder.sh; - env = { - envPackageJson = packageJson; - envPackageLockJson = packageLockJson; - envNodeJsVersion = nodeJsVersion; - }; - name = "make-node2nix-lock-for-${name}"; - searchPaths.bin = - [ __nixpkgs__.git __nixpkgs__.gnused __nixpkgs__.node2nix ]; - }; - nodePackages = import node2NixLock { pkgs = __nixpkgs__; }; - nodePackagesOverriden = - nodePackages.nodeDependencies.override packageOverrides; -in nodePackagesOverriden diff --git a/src/evaluator/modules/format-markdown/default.nix b/src/evaluator/modules/format-markdown/default.nix index baf9b736..5db6b8e9 100644 --- a/src/evaluator/modules/format-markdown/default.nix +++ b/src/evaluator/modules/format-markdown/default.nix @@ -1,5 +1,4 @@ -{ __nixpkgs__, attrsOptional, isLinux, makeNodeJsEnvironment, makeScript -, toBashArray, ... }: +{ __nixpkgs__, attrsOptional, isLinux, makeScript, toBashArray, ... }: { config, lib, ... }: { options = { formatMarkdown = { @@ -24,14 +23,11 @@ }; name = "format-markdown"; searchPaths = { - bin = [ __nixpkgs__.git __nixpkgs__.gnugrep __nixpkgs__.gnused ]; - source = [ - (makeNodeJsEnvironment { - name = "doctoc"; - nodeJsVersion = "21"; - packageJson = ./doctoc/package.json; - packageLockJson = ./doctoc/package-lock.json; - }) + bin = [ + __nixpkgs__.git + __nixpkgs__.gnugrep + __nixpkgs__.gnused + __nixpkgs__.nodejs_21 ]; }; entrypoint = ./entrypoint.sh; diff --git a/src/evaluator/modules/format-markdown/entrypoint.sh b/src/evaluator/modules/format-markdown/entrypoint.sh index e0f9ea62..39eb5190 100644 --- a/src/evaluator/modules/format-markdown/entrypoint.sh +++ b/src/evaluator/modules/format-markdown/entrypoint.sh @@ -5,7 +5,14 @@ function main { source __argDoctocArgs__/template local doctoc_args local tmp - info Formatting Markdown code \ + local doctoc_path="src/evaluator/modules/format-markdown/doctoc" + + pushd "${doctoc_path}" \ + && info Installing doctoc \ + && npm ci \ + && export PATH="${doctoc_path}/node_modules/.bin:${PATH}" \ + && popd \ + && info Formatting Markdown code \ && tmp=$(mktemp) \ && for path in "${targets[@]}"; do info Formatting "${path}" \