deno icon indicating copy to clipboard operation
deno copied to clipboard

Improve deno tasks by integrating wireit features

Open PatrickJS opened this issue 1 year ago • 0 comments

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

PatrickJS avatar Oct 22 '24 00:10 PatrickJS