Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve deno tasks by integrating wireit features #26462

Open
PatrickJS opened this issue Oct 22, 2024 · 2 comments
Open

Improve deno tasks by integrating wireit features #26462

PatrickJS opened this issue Oct 22, 2024 · 2 comments
Labels
suggestion suggestions for new features (yet to be agreed) task runner related to deno task

Comments

@PatrickJS
Copy link

PatrickJS commented Oct 22, 2024

We learned a lot from node/npm and the value of npm tasks. Ultimately it won over the other tasks managers because a lot of the work was moved over to bundlers (webpack and now vite) but as we add more code and moved to mono repo tooling we still need all the advanced task management features we lost.

Wireit developed by Google shows us yet another example of providing everything we learned from mono repo tooling and caching tasks. And I propose we increase the scope of deno tasks to merge this api. And can technically be backwards compatible by simply adding an object or not

{
  "tasks": {
    "build": "tsc",
    "bundle": {
      "command": "rollup -c",
      "dependencies": ["build"]
    }
  }
}

https://github.com/google/wireit

here is an example of tasks in one of my nodejs projects

  "scripts": {
    "------- NODE VERSION -------": "",
    "__NODE_VERSION_CHECK__": "node -e \"if (parseInt(process.versions.node.split('.')[0]) < 20) { console.error('Node.js version 20.17.0 or higher is required.'); process.exit(1); }\"",
    "__PACKAGE_LOCK_CHECK__": "node -e \"const fs = require('fs'); fs.access('scripts/sharp.mjs', fs.constants.F_OK, (err) => { if (!err) { require('child_process').execSync('node --disable-warning=ExperimentalWarning scripts/sharp.mjs', { stdio: 'inherit' }); } });\"",
    "preinstall": "npm run __NODE_VERSION_CHECK__",
    "postinstall": "npm run __PACKAGE_LOCK_CHECK__",
    "predev": "npm run __NODE_VERSION_CHECK__",
    "prestart": "npm run __NODE_VERSION_CHECK__",
    "------- BUILD SCRIPTS -------": "",
    "build": "qwik build",
    "build.client": "node --env-file=.env ./node_modules/.bin/vite build",
    "build.preview": "node --env-file=.env ./node_modules/.bin/vite build --ssr src/entry.preview.tsx",
    "build.serverless": "node --env-file=.env ./node_modules/.bin/vite build -c adapters/lambda/vite.config.ts",
    "build.lambda": "npm run clean && npm run build.client && npm run build.serverless",
    "build.hono": "node --env-file=.env ./node_modules/.bin/vite build --ssr src/entry_aws-ecs.tsx",
    "build.ecs": "npm run clean && npm run build.client && npm run build.hono",
    "build.all": "npm run clean && npm run build.client",
    "clean": "npx rimraf dist",
    "ci.prebuild": "node scripts/remove-ci-mode-comment.mjs",
    "------- DEPLOYMENT SCRIPTS -------": "",
    "predeploy": "npm rum build.all",
    "deploy": "aws s3 cp dist/ s3://${VITE_S3_BUCKET_PATH}/${VITE_S3_FOLDER_PATH} --recursive",
    "deploy.folder": "node --env-file=.env -e \"console.log('my folder:', process.env.VITE_S3_BUCKET_PATH + '/' + process.env.VITE_S3_FOLDER_PATH)\"",
    "------- DEVELOPMENT SCRIPTS -------": "",
    "dev": "DEV_MODE=true VITE_CJS_TRACE=true node --env-file=.env ./node_modules/.bin/vite --host --mode ssr",
    "prelocal.lambda": "cp index.mjs dist",
    "local": "npm run local.lambda",
    "local.hono": "PORT=3008 npm run start.hono",
    "local.lambda": "node --env-file=.env ./local-lambda.mjs",
    "serve": "npm run build.lambda && node --env-file=.env ./node_modules/.bin/serverless offline",
    "dev.debug": "node --inspect-brk ./node_modules/.bin/vite --mode ssr --force",
    "------- RUN SCRIPTS -------": "",
    "start.hono": "node --env-file=.env ./dist/server/entry_aws-ecs.js",
    "------- FORMATTING & LINTING -------": "",
    "fmt": "prettier --write .",
    "fmt.check": "prettier --check .",
    "lint": "eslint \"src/**/*.ts*\"",
    "lint.fix": "eslint \"src/**/*.ts*\" --fix",
    "types": "tsc --incremental --noEmit",
    "------- PREVIEW  -------": "",
    "preview": "npm run build.preview && node --env-file=.env ./node_modules/.bin/vite preview --host --open",
    "start": "node --env-file=.env ./node_modules/.bin/vite --open --mode ssr",
    "------- TESTING -------": "",
    "test": "node --env-file=.env ./node_modules/.bin/vite components --run",
    "test.type.e2e": "npm run types && npm run test.e2e",
    "test.e2e": "node --env-file=.env ./node_modules/.bin/playwright test",
    "test.e2e.ui": "node --env-file=.env ./node_modules/.bin/playwright test --ui",
    "test.report": "node --env-file=.env ./node_modules/.bin/playwright show-report",
    "test.unit": "node --env-file=.env ./node_modules/.bin/vite components",
    "test.vitest": "node --env-file=.env ./node_modules/.bin/vitest",
    "test.unit.ui": "node --env-file=.env ./node_modules/.bin/vite --ui components",
    "------- MISC SCRIPTS -------": "",
    "qwik": "node --env-file=.env ./node_modules/.bin/qwik",
    "-----------------------------": ""
  },

mock up version with only "dependencies" feature

{
  "scripts": {
    "------- BUILD SCRIPTS -------": "",
    "clean": "npx rimraf dist",
    "build:client": "vite build",
    "build:preview": "vite build --ssr src/entry.preview.tsx",
    "build:serverless": "vite build -c adapters/lambda/vite.config.ts",
    "build:hono": "vite build --ssr src/entry_aws-ecs.tsx",
    "build": {
      "dependencies": ["clean", "build:client"]
    },
    "build:lambda": {
      "dependencies": ["clean", "build:client", "build:serverless"]
    },
    "build:ecs": {
      "dependencies": ["clean", "build:client", "build:hono"]
    },

    "------- DEPLOYMENT SCRIPTS -------": "",
    "deploy": {
      "dependencies": ["build", "deploy:s3"]
    },
    "deploy:s3": "aws s3 cp dist/ s3://${VITE_S3_BUCKET_PATH}/${VITE_S3_FOLDER_PATH} --recursive",
    "deploy:folder": "node -e \"console.log('my folder:', process.env.VITE_S3_BUCKET_PATH + '/' + process.env.VITE_S3_FOLDER_PATH)\"",

    "------- DEVELOPMENT SCRIPTS -------": "",
    "dev": "DEV_MODE=true VITE_CJS_TRACE=true vite --host --mode ssr",
    "dev:debug": "node --inspect-brk vite --mode ssr --force",
    "local:lambda": {
      "command": "node ./local-lambda.mjs",
      "dependencies": ["build:lambda", "copy:lambda-index"]
    },
    "copy:lambda-index": "cp index.mjs dist",
    "local:hono": "PORT=3008 npm run start:hono",
    "serve": {
      "command": "serverless offline",
      "dependencies": ["build:lambda"]
    },

    "------- RUN SCRIPTS -------": "",
    "start:hono": "node ./dist/server/entry_aws-ecs.js",

    "------- FORMATTING & LINTING -------": "",
    "fmt": "prettier --write .",
    "fmt:check": "prettier --check .",
    "lint": "eslint \"src/**/*.ts*\"",
    "lint:fix": "eslint \"src/**/*.ts*\" --fix",
    "types": "tsc --incremental --noEmit",

    "------- PREVIEW  -------": "",
    "preview": {
      "command": "vite preview --host --open",
      "dependencies": ["build:preview"]
    },
    "start": "vite --open --mode ssr",

    "------- TESTING -------": "",
    "test": "vite components --run",
    "test:e2e": "playwright test",
    "test:e2e:ui": "playwright test --ui",
    "test:report": "playwright show-report",
    "test:unit": "vite components",
    "test:vitest": "vitest",
    "test:unit:ui": "vite --ui components",
    "test:type:e2e": {
      "dependencies": ["types", "test:e2e"]
    },

    "------- MISC SCRIPTS -------": "",
    "qwik": "qwik"
  }
}

here's a version with more wireit features

{
  "scripts": {
    "------- BUILD SCRIPTS -------": "",
    "clean": {
      "command": {
        "default": "rm -rf dist",
        "win32": "if exist dist rmdir /s /q dist"
      }
    },
    "build:client": {
      "command": "vite build",
      "files": ["src/**/*"],
      "output": ["dist/**/*"],
      "cache": true
    },
    "build:preview": {
      "command": "vite build --ssr src/entry.preview.tsx",
      "files": ["src/**/*", "src/entry.preview.tsx"],
      "output": ["dist/**/*"],
      "cache": true
    },
    "build:serverless": {
      "command": "vite build -c adapters/lambda/vite.config.ts",
      "files": ["src/**/*", "adapters/lambda/vite.config.ts"],
      "output": ["dist/**/*"],
      "cache": true
    },
    "build:hono": {
      "command": "vite build --ssr src/entry_aws-ecs.tsx",
      "files": ["src/**/*", "src/entry_aws-ecs.tsx"],
      "output": ["dist/**/*"],
      "cache": true
    },
    "build": {
      "dependencies": ["clean", "build:client"],
      "cascade": true
    },
    "build:lambda": {
      "dependencies": ["build:serverless"]
    },
    "build:ecs": {
      "dependencies": ["build:hono"]
    },
    "build:all": {
      "dependencies": ["build:client", "build:serverless", "build:hono"],
      "parallel": true
    },

    "------- DEPLOYMENT SCRIPTS -------": "",
    "deploy": {
      "dependencies": ["build", "deploy:s3"]
    },
    "deploy:s3": "aws s3 cp dist/ s3://${VITE_S3_BUCKET_PATH}/${VITE_S3_FOLDER_PATH} --recursive",
    "deploy:folder": "node -e \"console.log('my folder:', process.env.VITE_S3_BUCKET_PATH + '/' + process.env.VITE_S3_FOLDER_PATH)\"",

    "------- DEVELOPMENT SCRIPTS -------": "",
    "dev": {
      "command": "vite --host --mode ssr",
      "env": {
        "DEV_MODE": "true",
        "VITE_CJS_TRACE": "true"
      },
      "service": true,
      "watch": {
        "files": ["src/**/*"],
        "ignore": ["**/*.test.ts"]
      }
    },
    "dev:debug": "node --inspect-brk vite --mode ssr --force",
    "local:lambda": {
      "command": "node ./local-lambda.mjs",
      "dependencies": ["build:lambda", "copy:lambda-index"]
    },
    "copy:lambda-index": "cp index.mjs dist",
    "local:hono": "PORT=3008 npm run start:hono",
    "serve": {
      "command": "serverless offline",
      "dependencies": ["build:lambda"],
      "service": true
    },

    "------- RUN SCRIPTS -------": "",
    "start:hono": "node ./dist/server/entry_aws-ecs.js",

    "------- FORMATTING & LINTING -------": "",
    "fmt": "prettier --write .",
    "fmt:check": "prettier --check .",
    "lint": "eslint \"src/**/*.ts*\"",
    "lint:fix": "eslint \"src/**/*.ts*\" --fix",
    "types": {
      "command": "tsc --incremental --noEmit",
      "files": ["src/**/*.ts", "src/**/*.tsx"],
      "output": [],
      "cache": true
    },

    "------- PREVIEW  -------": "",
    "preview": {
      "command": "vite preview --host --open",
      "dependencies": ["build:preview"]
    },
    "start": "vite --open --mode ssr",

    "------- TESTING -------": "",
    "test": "vite components --run",
    "test:e2e": "playwright test",
    "test:e2e:ui": "playwright test --ui",
    "test:report": "playwright show-report",
    "test:unit": "vite components",
    "test:vitest": "vitest",
    "test:unit:ui": "vite --ui components",
    "test:type:e2e": {
      "dependencies": ["types", "test:e2e"]
    },

    "------- MISC SCRIPTS -------": "",
    "qwik": "qwik"
  }
}

while we don't need everything in wireit right away. I think simply adding dep tracking will go a long way and the local/remote caching with github actions or if the developer is on deno-deploy then ideally deno-deploy can offer this remote caching for longer than the github-action cache limits. If deno already has a better task manager than npm that will be huge for everyone migrating from nodejs to deno2

@bartlomieju bartlomieju added suggestion suggestions for new features (yet to be agreed) task runner related to deno task labels Oct 22, 2024
@bartlomieju bartlomieju added this to the 2.1.0 milestone Oct 24, 2024
bartlomieju added a commit that referenced this issue Nov 19, 2024
This commit adds support for "dependencies" in `deno task` subcommand:
```jsonc
{
    "tasks": {
        "build": "deno run -RW build.ts",
        "generate": "deno run -RW generate.ts",
        "serve": {
            "command": "deno run -RN server.ts",
            "dependencies": ["build", "generate"]
        }
    }
}
```
Executing `deno task serve` will first execute `build` and `generate`
tasks (in parallel) and once both complete the `serve` task will be executed.

Number of tasks run in parallel is equal to the no of cores on the
machine, and respects `DENO_JOBS` env var if one is specified.

Part of #26462

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
@bartlomieju
Copy link
Member

With #26467 landed this is now partially addressed. I will close this issue later and open more focused issues for remaining features.

@thoroc
Copy link

thoroc commented Dec 13, 2024

Sorry to shime here a bit late; I have tried wireit and nx as task manager are concerned, and since Deno offers a deno.json file at the workspace level, it would be great if the task could be defined on a per workspace level. I am conscious this is adding a level of complexity to the whole dependency tree of tasks though.

Apologies I have just looked at the 2.1 release notes: https://deno.com/blog/v2.1#workspace-support, and this is included. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion suggestions for new features (yet to be agreed) task runner related to deno task
Projects
None yet
Development

No branches or pull requests

4 participants